@streamflow/stream 5.6.2 → 5.6.4-alpha.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/__tests__/aptos/streamClient.spec.d.ts +1 -0
- package/dist/__tests__/aptos/streamClient.spec.js +161 -0
- package/dist/__tests__/common/GenericStreamClient.spec.d.ts +1 -0
- package/dist/__tests__/common/GenericStreamClient.spec.js +44 -0
- package/dist/aptos/StreamClient.d.ts +51 -0
- package/dist/aptos/StreamClient.js +391 -0
- package/dist/aptos/constants.d.ts +8 -0
- package/dist/aptos/constants.js +28 -0
- package/dist/aptos/index.d.ts +2 -0
- package/dist/aptos/index.js +24 -0
- package/dist/aptos/types.d.ts +97 -0
- package/dist/aptos/types.js +76 -0
- package/dist/aptos/utils.d.ts +1 -0
- package/dist/aptos/utils.js +12 -0
- package/dist/aptos/wallet.d.ts +9 -0
- package/dist/aptos/wallet.js +89 -0
- package/dist/common/BaseStreamClient.d.ts +13 -0
- package/dist/common/BaseStreamClient.js +13 -0
- package/dist/common/GenericStreamClient.d.ts +93 -0
- package/dist/common/GenericStreamClient.js +114 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +4 -0
- package/dist/common/contractUtils.d.ts +47 -0
- package/dist/common/contractUtils.js +55 -0
- package/dist/common/types.d.ts +252 -0
- package/dist/common/types.js +165 -0
- package/dist/common/utils.d.ts +22 -0
- package/dist/common/utils.js +101 -0
- package/dist/evm/StreamClient.d.ts +30 -0
- package/dist/evm/StreamClient.js +461 -0
- package/dist/evm/abi.d.ts +111 -0
- package/dist/evm/abi.js +1257 -0
- package/dist/evm/constants.d.ts +20 -0
- package/dist/evm/constants.js +39 -0
- package/dist/evm/ercAbi.d.ts +39 -0
- package/dist/evm/ercAbi.js +224 -0
- package/dist/evm/index.d.ts +2 -0
- package/dist/evm/index.js +24 -0
- package/dist/evm/types.d.ts +93 -0
- package/dist/evm/types.js +75 -0
- package/dist/evm/utils.d.ts +1 -0
- package/dist/evm/utils.js +12 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +41 -0
- package/dist/solana/StreamClient.d.ts +72 -0
- package/dist/solana/StreamClient.js +927 -0
- package/dist/solana/constants.d.ts +22 -0
- package/dist/solana/constants.js +50 -0
- package/dist/solana/index.d.ts +7 -0
- package/dist/solana/index.js +43 -0
- package/dist/solana/instructionTypes.d.ts +96 -0
- package/dist/solana/instructionTypes.js +2 -0
- package/dist/solana/instructions.d.ts +139 -0
- package/dist/solana/instructions.js +407 -0
- package/dist/solana/layout.d.ts +27 -0
- package/dist/solana/layout.js +170 -0
- package/dist/solana/timelockIDL.d.ts +22 -0
- package/dist/solana/timelockIDL.js +422 -0
- package/dist/solana/types.d.ts +292 -0
- package/dist/solana/types.js +81 -0
- package/dist/solana/utils.d.ts +44 -0
- package/dist/solana/utils.js +313 -0
- package/dist/sui/StreamClient.d.ts +79 -0
- package/dist/sui/StreamClient.js +571 -0
- package/dist/sui/constants.d.ts +10 -0
- package/dist/sui/constants.js +43 -0
- package/dist/sui/index.d.ts +2 -0
- package/dist/sui/index.js +23 -0
- package/dist/sui/types.d.ts +141 -0
- package/dist/sui/types.js +102 -0
- package/dist/sui/utils.d.ts +2 -0
- package/dist/sui/utils.js +29 -0
- package/dist/sui/wallet.d.ts +11 -0
- package/dist/sui/wallet.js +75 -0
- package/package.json +2 -2
|
@@ -0,0 +1,571 @@
|
|
|
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 (_) 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
90
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
91
|
+
};
|
|
92
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
93
|
+
var bn_js_1 = __importDefault(require("bn.js"));
|
|
94
|
+
var client_1 = require("@mysten/sui.js/client");
|
|
95
|
+
var transactions_1 = require("@mysten/sui.js/transactions");
|
|
96
|
+
var utils_1 = require("@mysten/sui.js/utils");
|
|
97
|
+
var BaseStreamClient_1 = require("../common/BaseStreamClient");
|
|
98
|
+
var types_1 = require("../common/types");
|
|
99
|
+
var constants_1 = require("../common/constants");
|
|
100
|
+
var constants_2 = require("./constants");
|
|
101
|
+
var types_2 = require("./types");
|
|
102
|
+
var utils_2 = require("./utils");
|
|
103
|
+
var wallet_1 = require("./wallet");
|
|
104
|
+
var SuiStreamClient = /** @class */ (function (_super) {
|
|
105
|
+
__extends(SuiStreamClient, _super);
|
|
106
|
+
function SuiStreamClient(clusterUrl, cluster, ids) {
|
|
107
|
+
if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
|
|
108
|
+
var _this = _super.call(this) || this;
|
|
109
|
+
_this.programId = (ids === null || ids === void 0 ? void 0 : ids.program) ? ids.program : constants_2.SUI_PROGRAM_IDS[cluster];
|
|
110
|
+
_this.configId = (ids === null || ids === void 0 ? void 0 : ids.config) ? ids.config : constants_2.SUI_CONFIG_IDS[cluster];
|
|
111
|
+
_this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable : constants_2.SUI_FEE_TABLE_IDS[cluster];
|
|
112
|
+
_this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
113
|
+
return _this;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates a new stream/vesting contract.
|
|
117
|
+
*/
|
|
118
|
+
SuiStreamClient.prototype.create = function (streamData, _a) {
|
|
119
|
+
var senderWallet = _a.senderWallet;
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
+
var wallet, _b, txb, _c, digest, events;
|
|
122
|
+
return __generator(this, function (_d) {
|
|
123
|
+
switch (_d.label) {
|
|
124
|
+
case 0:
|
|
125
|
+
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
126
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, __assign(__assign({}, streamData), { recipients: [__assign({}, streamData)] }))];
|
|
127
|
+
case 1:
|
|
128
|
+
_b = __read.apply(void 0, [_d.sent(), 1]), txb = _b[0];
|
|
129
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
130
|
+
transactionBlock: txb,
|
|
131
|
+
options: { showEvents: true },
|
|
132
|
+
})];
|
|
133
|
+
case 2:
|
|
134
|
+
_c = _d.sent(), digest = _c.digest, events = _c.events;
|
|
135
|
+
return [2 /*return*/, {
|
|
136
|
+
ixs: [],
|
|
137
|
+
txId: digest,
|
|
138
|
+
metadataId: events[0].parsedJson.address,
|
|
139
|
+
}];
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Creates multiple stream/vesting contracts.
|
|
146
|
+
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
147
|
+
*/
|
|
148
|
+
SuiStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
|
|
149
|
+
var _b;
|
|
150
|
+
var senderWallet = _a.senderWallet;
|
|
151
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
+
var wallet, _c, txb, firstIndex, txs, metadatas, metadataToRecipient, errors, _d, digest, events_1, effects_1, e_1, errorInfo_1;
|
|
153
|
+
return __generator(this, function (_e) {
|
|
154
|
+
switch (_e.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
157
|
+
return [4 /*yield*/, this.generateCreateBlock(wallet.address, multipleStreamData)];
|
|
158
|
+
case 1:
|
|
159
|
+
_c = __read.apply(void 0, [_e.sent(), 2]), txb = _c[0], firstIndex = _c[1];
|
|
160
|
+
txs = [];
|
|
161
|
+
metadatas = [];
|
|
162
|
+
metadataToRecipient = {};
|
|
163
|
+
errors = [];
|
|
164
|
+
_e.label = 2;
|
|
165
|
+
case 2:
|
|
166
|
+
_e.trys.push([2, 4, , 5]);
|
|
167
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
168
|
+
transactionBlock: txb,
|
|
169
|
+
options: { showEffects: true, showEvents: true },
|
|
170
|
+
})];
|
|
171
|
+
case 3:
|
|
172
|
+
_d = _e.sent(), digest = _d.digest, events_1 = _d.events, effects_1 = _d.effects;
|
|
173
|
+
txs.push(digest);
|
|
174
|
+
if (effects_1.status.status === "failure") {
|
|
175
|
+
multipleStreamData.recipients.forEach(function (recipient) {
|
|
176
|
+
var _a;
|
|
177
|
+
errors.push({
|
|
178
|
+
error: (_a = effects_1.status.error) !== null && _a !== void 0 ? _a : "Unknown error!",
|
|
179
|
+
recipient: recipient.recipient,
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
multipleStreamData.recipients.forEach(function (recipient, index) {
|
|
185
|
+
var metadataId = events_1[index].parsedJson.address;
|
|
186
|
+
metadatas.push(metadataId);
|
|
187
|
+
metadataToRecipient[metadataId] = recipient;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return [3 /*break*/, 5];
|
|
191
|
+
case 4:
|
|
192
|
+
e_1 = _e.sent();
|
|
193
|
+
errorInfo_1 = (0, utils_2.extractSuiErrorInfo)((_b = e_1.toString()) !== null && _b !== void 0 ? _b : "Unknown error!");
|
|
194
|
+
multipleStreamData.recipients.forEach(function (recipient, index) {
|
|
195
|
+
var _a;
|
|
196
|
+
if (errorInfo_1.index === undefined ||
|
|
197
|
+
errorInfo_1.index < index + firstIndex ||
|
|
198
|
+
errorInfo_1.index >= multipleStreamData.recipients.length + firstIndex ||
|
|
199
|
+
errorInfo_1.index === index + firstIndex) {
|
|
200
|
+
errors.push({
|
|
201
|
+
error: errorInfo_1.text,
|
|
202
|
+
recipient: recipient.recipient,
|
|
203
|
+
contractErrorCode: (_a = errorInfo_1.parsed) === null || _a === void 0 ? void 0 : _a.name,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return [3 /*break*/, 5];
|
|
208
|
+
case 5: return [2 /*return*/, {
|
|
209
|
+
txs: txs,
|
|
210
|
+
metadatas: metadatas,
|
|
211
|
+
metadataToRecipient: metadataToRecipient,
|
|
212
|
+
errors: errors,
|
|
213
|
+
}];
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Attempts withdrawing from the specified stream.
|
|
220
|
+
*/
|
|
221
|
+
SuiStreamClient.prototype.withdraw = function (withdrawData, _a) {
|
|
222
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
223
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
224
|
+
var wallet, txb, digest;
|
|
225
|
+
return __generator(this, function (_b) {
|
|
226
|
+
switch (_b.label) {
|
|
227
|
+
case 0:
|
|
228
|
+
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
229
|
+
txb = new transactions_1.TransactionBlock();
|
|
230
|
+
txb.moveCall({
|
|
231
|
+
target: "".concat(this.programId, "::protocol::withdraw"),
|
|
232
|
+
typeArguments: [tokenId],
|
|
233
|
+
arguments: [
|
|
234
|
+
txb.object(withdrawData.id),
|
|
235
|
+
txb.object(this.configId),
|
|
236
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
237
|
+
txb.pure(withdrawData.amount.toString()),
|
|
238
|
+
],
|
|
239
|
+
});
|
|
240
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
241
|
+
transactionBlock: txb,
|
|
242
|
+
})];
|
|
243
|
+
case 1:
|
|
244
|
+
digest = (_b.sent()).digest;
|
|
245
|
+
return [2 /*return*/, {
|
|
246
|
+
ixs: [],
|
|
247
|
+
txId: digest,
|
|
248
|
+
}];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Attempts canceling the specified stream.
|
|
255
|
+
*/
|
|
256
|
+
SuiStreamClient.prototype.cancel = function (cancelData, _a) {
|
|
257
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
258
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
259
|
+
var wallet, txb, digest;
|
|
260
|
+
return __generator(this, function (_b) {
|
|
261
|
+
switch (_b.label) {
|
|
262
|
+
case 0:
|
|
263
|
+
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
264
|
+
txb = new transactions_1.TransactionBlock();
|
|
265
|
+
txb.moveCall({
|
|
266
|
+
target: "".concat(this.programId, "::protocol::cancel"),
|
|
267
|
+
typeArguments: [tokenId],
|
|
268
|
+
arguments: [
|
|
269
|
+
txb.object(cancelData.id),
|
|
270
|
+
txb.object(this.configId),
|
|
271
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
272
|
+
],
|
|
273
|
+
});
|
|
274
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
275
|
+
transactionBlock: txb,
|
|
276
|
+
})];
|
|
277
|
+
case 1:
|
|
278
|
+
digest = (_b.sent()).digest;
|
|
279
|
+
return [2 /*return*/, {
|
|
280
|
+
ixs: [],
|
|
281
|
+
txId: digest,
|
|
282
|
+
}];
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
289
|
+
*/
|
|
290
|
+
SuiStreamClient.prototype.transfer = function (transferData, _a) {
|
|
291
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
292
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
293
|
+
var wallet, txb, digest;
|
|
294
|
+
return __generator(this, function (_b) {
|
|
295
|
+
switch (_b.label) {
|
|
296
|
+
case 0:
|
|
297
|
+
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
298
|
+
txb = new transactions_1.TransactionBlock();
|
|
299
|
+
txb.moveCall({
|
|
300
|
+
target: "".concat(this.programId, "::protocol::transfer"),
|
|
301
|
+
typeArguments: [tokenId],
|
|
302
|
+
arguments: [txb.object(transferData.id), txb.pure(transferData.newRecipient)],
|
|
303
|
+
});
|
|
304
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
305
|
+
transactionBlock: txb,
|
|
306
|
+
})];
|
|
307
|
+
case 1:
|
|
308
|
+
digest = (_b.sent()).digest;
|
|
309
|
+
return [2 /*return*/, {
|
|
310
|
+
ixs: [],
|
|
311
|
+
txId: digest,
|
|
312
|
+
}];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* Tops up stream account with specified amount.
|
|
319
|
+
*/
|
|
320
|
+
SuiStreamClient.prototype.topup = function (topupData, _a) {
|
|
321
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
322
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
323
|
+
var wallet, txb, coins, coinObject, digest;
|
|
324
|
+
return __generator(this, function (_b) {
|
|
325
|
+
switch (_b.label) {
|
|
326
|
+
case 0:
|
|
327
|
+
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
328
|
+
txb = new transactions_1.TransactionBlock();
|
|
329
|
+
return [4 /*yield*/, this.getAllCoins(wallet.address, tokenId)];
|
|
330
|
+
case 1:
|
|
331
|
+
coins = _b.sent();
|
|
332
|
+
coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins);
|
|
333
|
+
txb.moveCall({
|
|
334
|
+
target: "".concat(this.programId, "::protocol::topup"),
|
|
335
|
+
typeArguments: [tokenId],
|
|
336
|
+
arguments: [
|
|
337
|
+
txb.object(topupData.id),
|
|
338
|
+
txb.object(this.configId),
|
|
339
|
+
coinObject,
|
|
340
|
+
txb.gas,
|
|
341
|
+
txb.pure(topupData.amount.toString()),
|
|
342
|
+
],
|
|
343
|
+
});
|
|
344
|
+
this.returnSplittedCoinObject(txb, tokenId, coins, coinObject);
|
|
345
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
346
|
+
transactionBlock: txb,
|
|
347
|
+
})];
|
|
348
|
+
case 2:
|
|
349
|
+
digest = (_b.sent()).digest;
|
|
350
|
+
return [2 /*return*/, {
|
|
351
|
+
ixs: [],
|
|
352
|
+
txId: digest,
|
|
353
|
+
}];
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Fetch stream data by its id (address).
|
|
360
|
+
*/
|
|
361
|
+
SuiStreamClient.prototype.getOne = function (_a) {
|
|
362
|
+
var id = _a.id;
|
|
363
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
364
|
+
var response, content;
|
|
365
|
+
return __generator(this, function (_b) {
|
|
366
|
+
switch (_b.label) {
|
|
367
|
+
case 0: return [4 /*yield*/, this.client.getObject({
|
|
368
|
+
id: id,
|
|
369
|
+
options: {
|
|
370
|
+
showContent: true,
|
|
371
|
+
},
|
|
372
|
+
})];
|
|
373
|
+
case 1:
|
|
374
|
+
response = _b.sent();
|
|
375
|
+
if (!response.data) {
|
|
376
|
+
throw new Error("Contract with id ".concat(id, " could not be found!"));
|
|
377
|
+
}
|
|
378
|
+
content = response.data.content;
|
|
379
|
+
if (content.dataType !== "moveObject") {
|
|
380
|
+
throw new Error("Not a Move Object!");
|
|
381
|
+
}
|
|
382
|
+
return [2 /*return*/, new types_2.Contract(content.fields, "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT")];
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
};
|
|
387
|
+
SuiStreamClient.prototype.get = function () {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
389
|
+
return __generator(this, function (_a) {
|
|
390
|
+
throw new Error("Get all method is not supported for Sui chain!");
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
/**
|
|
395
|
+
* Attempts updating the stream auto withdrawal params and amount per period
|
|
396
|
+
*/
|
|
397
|
+
SuiStreamClient.prototype.update = function (updateData, _a) {
|
|
398
|
+
var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
|
|
399
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
400
|
+
var wallet, txb, digest;
|
|
401
|
+
return __generator(this, function (_b) {
|
|
402
|
+
switch (_b.label) {
|
|
403
|
+
case 0:
|
|
404
|
+
wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
|
|
405
|
+
txb = new transactions_1.TransactionBlock();
|
|
406
|
+
txb.moveCall({
|
|
407
|
+
target: "".concat(this.programId, "::protocol::update"),
|
|
408
|
+
typeArguments: [tokenId],
|
|
409
|
+
arguments: [
|
|
410
|
+
txb.object(updateData.id),
|
|
411
|
+
txb.object(this.configId),
|
|
412
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
413
|
+
txb.gas,
|
|
414
|
+
txb.pure(updateData.enableAutomaticWithdrawal !== undefined
|
|
415
|
+
? [updateData.enableAutomaticWithdrawal]
|
|
416
|
+
: [], "vector<bool>"),
|
|
417
|
+
txb.pure(updateData.withdrawFrequency !== undefined
|
|
418
|
+
? [updateData.withdrawFrequency.toString()]
|
|
419
|
+
: [], "vector<u64>"),
|
|
420
|
+
txb.pure(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : [], "vector<u64>"),
|
|
421
|
+
],
|
|
422
|
+
});
|
|
423
|
+
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
424
|
+
transactionBlock: txb,
|
|
425
|
+
})];
|
|
426
|
+
case 1:
|
|
427
|
+
digest = (_b.sent()).digest;
|
|
428
|
+
return [2 /*return*/, {
|
|
429
|
+
ixs: [],
|
|
430
|
+
txId: digest,
|
|
431
|
+
}];
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
SuiStreamClient.prototype.extractErrorCode = function (err) {
|
|
437
|
+
var _a, _b;
|
|
438
|
+
var errorInfo = (0, utils_2.extractSuiErrorInfo)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!");
|
|
439
|
+
return ((_b = errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.parsed) === null || _b === void 0 ? void 0 : _b.name) || null;
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* Returns StreamClient protocol program ID.
|
|
443
|
+
*/
|
|
444
|
+
SuiStreamClient.prototype.getProgramId = function () {
|
|
445
|
+
return this.programId;
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* Utility function to generate Transaction Block to create streams
|
|
449
|
+
*/
|
|
450
|
+
SuiStreamClient.prototype.generateCreateBlock = function (walletAddress, multipleStreamData) {
|
|
451
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
452
|
+
var coins, totalAmount, txb, coinObject, firstIndex;
|
|
453
|
+
var _this = this;
|
|
454
|
+
return __generator(this, function (_a) {
|
|
455
|
+
switch (_a.label) {
|
|
456
|
+
case 0: return [4 /*yield*/, this.getAllCoins(walletAddress, multipleStreamData.tokenId)];
|
|
457
|
+
case 1:
|
|
458
|
+
coins = _a.sent();
|
|
459
|
+
totalAmount = multipleStreamData.recipients
|
|
460
|
+
.map(function (recipiient) { return recipiient.amount; })
|
|
461
|
+
.reduce(function (prev, current) { return current.add(prev); });
|
|
462
|
+
txb = new transactions_1.TransactionBlock();
|
|
463
|
+
coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins);
|
|
464
|
+
coins = [coins[0]];
|
|
465
|
+
firstIndex = null;
|
|
466
|
+
multipleStreamData.recipients.forEach(function (recipient) {
|
|
467
|
+
var result = txb.moveCall({
|
|
468
|
+
target: "".concat(_this.programId, "::protocol::create"),
|
|
469
|
+
typeArguments: [multipleStreamData.tokenId],
|
|
470
|
+
arguments: [
|
|
471
|
+
txb.object(_this.configId),
|
|
472
|
+
txb.object(_this.feeTableId),
|
|
473
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
474
|
+
coinObject,
|
|
475
|
+
txb.gas,
|
|
476
|
+
txb.pure(recipient.amount.toString()),
|
|
477
|
+
txb.pure(multipleStreamData.period),
|
|
478
|
+
txb.pure(recipient.amountPerPeriod.toString()),
|
|
479
|
+
txb.pure(multipleStreamData.start),
|
|
480
|
+
txb.pure(recipient.cliffAmount.toString()),
|
|
481
|
+
txb.pure(multipleStreamData.cancelableBySender),
|
|
482
|
+
txb.pure(multipleStreamData.cancelableByRecipient),
|
|
483
|
+
txb.pure(multipleStreamData.transferableBySender),
|
|
484
|
+
txb.pure(multipleStreamData.transferableByRecipient),
|
|
485
|
+
txb.pure(multipleStreamData.canTopup),
|
|
486
|
+
txb.pure(!!multipleStreamData.canPause),
|
|
487
|
+
txb.pure(!!multipleStreamData.canUpdateRate),
|
|
488
|
+
txb.pure(!!multipleStreamData.automaticWithdrawal),
|
|
489
|
+
txb.pure(multipleStreamData.withdrawalFrequency || 0),
|
|
490
|
+
txb.pure(recipient.name),
|
|
491
|
+
txb.pure(recipient.recipient),
|
|
492
|
+
txb.pure(multipleStreamData.partner || walletAddress),
|
|
493
|
+
],
|
|
494
|
+
});
|
|
495
|
+
if (result.kind === "Result" && firstIndex === null) {
|
|
496
|
+
firstIndex = result.index;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
|
|
500
|
+
return [2 /*return*/, [txb, firstIndex]];
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
};
|
|
505
|
+
/**
|
|
506
|
+
* Returns all coins owned by a Wallet
|
|
507
|
+
* @param walletAddress wallet address
|
|
508
|
+
* @param coinType coin type
|
|
509
|
+
* @returns Array of Coin Structs
|
|
510
|
+
*/
|
|
511
|
+
SuiStreamClient.prototype.getAllCoins = function (walletAddress, coinType) {
|
|
512
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
513
|
+
var coinsResponse, coins;
|
|
514
|
+
return __generator(this, function (_a) {
|
|
515
|
+
switch (_a.label) {
|
|
516
|
+
case 0: return [4 /*yield*/, this.client.getCoins({
|
|
517
|
+
owner: walletAddress,
|
|
518
|
+
coinType: coinType,
|
|
519
|
+
})];
|
|
520
|
+
case 1:
|
|
521
|
+
coinsResponse = _a.sent();
|
|
522
|
+
coins = coinsResponse.data;
|
|
523
|
+
_a.label = 2;
|
|
524
|
+
case 2:
|
|
525
|
+
if (!coinsResponse.hasNextPage) return [3 /*break*/, 4];
|
|
526
|
+
return [4 /*yield*/, this.client.getCoins({
|
|
527
|
+
owner: walletAddress,
|
|
528
|
+
coinType: coinType,
|
|
529
|
+
cursor: coinsResponse.nextCursor,
|
|
530
|
+
})];
|
|
531
|
+
case 3:
|
|
532
|
+
coinsResponse = _a.sent();
|
|
533
|
+
coins.push.apply(coins, __spreadArray([], __read(coinsResponse.data), false));
|
|
534
|
+
return [3 /*break*/, 2];
|
|
535
|
+
case 4: return [2 /*return*/, coins];
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Utility function to split Coin object and use splitted object for stream operations.
|
|
542
|
+
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
543
|
+
* This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
|
|
544
|
+
* @param txb current transanction block
|
|
545
|
+
* @param amount minimal amount of coins requried
|
|
546
|
+
* @param coinType coin type
|
|
547
|
+
* @param coins array of owned coins of the same type
|
|
548
|
+
* @returns Coin Object to use in a Move Call
|
|
549
|
+
*/
|
|
550
|
+
SuiStreamClient.prototype.splitCoinObjectForAmount = function (txb, amount, coinType, coins) {
|
|
551
|
+
var coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
552
|
+
if (coins.length > 1) {
|
|
553
|
+
txb.mergeCoins(coinObject, coins.slice(1).map(function (item) { return txb.object(item.coinObjectId); }));
|
|
554
|
+
}
|
|
555
|
+
var sum = amount.mul(new bn_js_1.default(constants_1.BASE_FEE)).div(new bn_js_1.default(1000000));
|
|
556
|
+
return txb.splitCoins(coinObject, [txb.pure(sum.toString())])[0];
|
|
557
|
+
};
|
|
558
|
+
/**
|
|
559
|
+
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
560
|
+
* @param txb current transanction block
|
|
561
|
+
* @param coinType coin type
|
|
562
|
+
* @param coinObject splitted object
|
|
563
|
+
* @param coins array of objects used in
|
|
564
|
+
*/
|
|
565
|
+
SuiStreamClient.prototype.returnSplittedCoinObject = function (txb, coinType, coins, coinObject) {
|
|
566
|
+
var firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
567
|
+
txb.mergeCoins(firstCoinObject, [coinObject]);
|
|
568
|
+
};
|
|
569
|
+
return SuiStreamClient;
|
|
570
|
+
}(BaseStreamClient_1.BaseStreamClient));
|
|
571
|
+
exports.default = SuiStreamClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ICluster } from "../common/types";
|
|
2
|
+
export declare const SUI_PROGRAM_IDS: Record<ICluster, string>;
|
|
3
|
+
export declare const SUI_CONFIG_IDS: Record<ICluster, string>;
|
|
4
|
+
export declare const SUI_FEE_TABLE_IDS: Record<ICluster, string>;
|
|
5
|
+
export declare const SUI_ERROR_MATCH_REGEX: RegExp;
|
|
6
|
+
export declare const SUI_MODULE_ERROR_MAP: {
|
|
7
|
+
[key: string]: {
|
|
8
|
+
[key: number]: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SUI_MODULE_ERROR_MAP = exports.SUI_ERROR_MATCH_REGEX = exports.SUI_FEE_TABLE_IDS = exports.SUI_CONFIG_IDS = exports.SUI_PROGRAM_IDS = void 0;
|
|
5
|
+
var types_1 = require("../common/types");
|
|
6
|
+
// TODO: remove Devnet and Local addresses as they are not deployed, they are just a copy Testnet values
|
|
7
|
+
exports.SUI_PROGRAM_IDS = (_a = {},
|
|
8
|
+
_a[types_1.ICluster.Mainnet] = "0xa283fd6b45f1103176e7ae27e870c89df7c8783b15345e2b13faa81ec25c4fa6",
|
|
9
|
+
_a[types_1.ICluster.Devnet] = "0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a",
|
|
10
|
+
_a[types_1.ICluster.Testnet] = "0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a",
|
|
11
|
+
_a[types_1.ICluster.Local] = "0xf1916c119a6c917d4b36f96ffc0443930745789f3126a716e05a62223c48993a",
|
|
12
|
+
_a);
|
|
13
|
+
exports.SUI_CONFIG_IDS = (_b = {},
|
|
14
|
+
_b[types_1.ICluster.Mainnet] = "0x6cf6760b64245b8d23ef57c28ddceb6adbd540a23a509fef29b82237da4ab87b",
|
|
15
|
+
_b[types_1.ICluster.Devnet] = "0x9cdb344873cd2995cab624f192fbe0b358e136c33acbdf7523916e32f24df44b",
|
|
16
|
+
_b[types_1.ICluster.Testnet] = "0x9cdb344873cd2995cab624f192fbe0b358e136c33acbdf7523916e32f24df44b",
|
|
17
|
+
_b[types_1.ICluster.Local] = "0x9cdb344873cd2995cab624f192fbe0b358e136c33acbdf7523916e32f24df44b",
|
|
18
|
+
_b);
|
|
19
|
+
exports.SUI_FEE_TABLE_IDS = (_c = {},
|
|
20
|
+
_c[types_1.ICluster.Mainnet] = "0xad9b75399632583fb9fcae6b5bcca34e6542ab3bedb630ecbd3f15cb1cc48dbe",
|
|
21
|
+
_c[types_1.ICluster.Devnet] = "0xf3661941207b5027fb4b85a74ca5a9fd1389fb57a8f2c57bd312b950e7d48012",
|
|
22
|
+
_c[types_1.ICluster.Testnet] = "0xf3661941207b5027fb4b85a74ca5a9fd1389fb57a8f2c57bd312b950e7d48012",
|
|
23
|
+
_c[types_1.ICluster.Local] = "0xf3661941207b5027fb4b85a74ca5a9fd1389fb57a8f2c57bd312b950e7d48012",
|
|
24
|
+
_c);
|
|
25
|
+
exports.SUI_ERROR_MATCH_REGEX = /MoveAbort\(MoveLocation \{ module: ModuleId \{ address: (\w+), name: Identifier\("([\w_]+)"\) }, function: \d+, instruction: \d+, function_name: Some\("([\w_]+)"\) }, (\d+)\) in command (\d+)/;
|
|
26
|
+
exports.SUI_MODULE_ERROR_MAP = {
|
|
27
|
+
protocol: {
|
|
28
|
+
1: types_1.ContractErrorCode.ECONTRACT_NOT_INIT,
|
|
29
|
+
2: types_1.ContractErrorCode.EBAD_AMOUNT,
|
|
30
|
+
3: types_1.ContractErrorCode.ENO_PERMISSIONS,
|
|
31
|
+
4: types_1.ContractErrorCode.EBADINPUT,
|
|
32
|
+
5: types_1.ContractErrorCode.ECLOSED,
|
|
33
|
+
6: types_1.ContractErrorCode.EBAD_INPUT_AMOUNT_PER_PERIOD,
|
|
34
|
+
8: types_1.ContractErrorCode.EBAD_INPUT_UPDATE_RATE,
|
|
35
|
+
9: types_1.ContractErrorCode.EBAD_INPUT_CLIFF_AMOUNT,
|
|
36
|
+
10: types_1.ContractErrorCode.EBAD_INPUT_PERIOD,
|
|
37
|
+
11: types_1.ContractErrorCode.EBAD_INPUT_START,
|
|
38
|
+
13: types_1.ContractErrorCode.EBAD_INSUFFICIENT_WITHDRAWAL_FEES,
|
|
39
|
+
14: types_1.ContractErrorCode.EBAD_INSUFFICIENT_AMOUNT,
|
|
40
|
+
15: types_1.ContractErrorCode.EPAUSED,
|
|
41
|
+
16: types_1.ContractErrorCode.ENOTPAUSED,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.SuiStreamClient = void 0;
|
|
21
|
+
var StreamClient_1 = require("./StreamClient");
|
|
22
|
+
Object.defineProperty(exports, "SuiStreamClient", { enumerable: true, get: function () { return __importDefault(StreamClient_1).default; } });
|
|
23
|
+
__exportStar(require("./types"), exports);
|