@streamflow/stream 7.0.0-alpha.3 → 7.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/__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/types.js +17 -26
- 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 +1 -1
- package/dist/cjs/common/contractUtils.js +12 -13
- package/dist/cjs/common/utils.js +21 -66
- package/dist/cjs/evm/StreamClient.js +198 -456
- package/dist/cjs/evm/constants.js +19 -20
- package/dist/cjs/evm/types.js +14 -23
- package/dist/cjs/evm/utils.js +2 -2
- package/dist/cjs/solana/StreamClient.js +592 -1090
- package/dist/cjs/solana/constants.js +9 -10
- package/dist/cjs/solana/instructions.js +60 -65
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/types.js +14 -24
- package/dist/cjs/solana/utils.js +48 -136
- package/dist/cjs/sui/StreamClient.js +325 -571
- package/dist/cjs/sui/constants.js +19 -20
- package/dist/cjs/sui/types.js +17 -51
- package/dist/cjs/sui/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +13 -63
- package/package.json +4 -4
|
@@ -1,407 +1,203 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_this.programId = programId ? programId : constants_js_1.APTOS_PROGRAM_IDS[cluster];
|
|
96
|
-
_this.maxGas = maxGas;
|
|
97
|
-
_this.client = new aptos_1.AptosClient(clusterUrl);
|
|
98
|
-
return _this;
|
|
3
|
+
const aptos_1 = require("aptos");
|
|
4
|
+
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
5
|
+
const types_js_1 = require("../common/types.js");
|
|
6
|
+
const constants_js_1 = require("./constants.js");
|
|
7
|
+
const types_js_2 = require("./types.js");
|
|
8
|
+
const wallet_js_1 = require("./wallet.js");
|
|
9
|
+
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const constants_js_2 = require("../common/constants.js");
|
|
11
|
+
class AptosStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
12
|
+
constructor(clusterUrl, cluster = types_js_1.ICluster.Mainnet, maxGas = "10000", programId) {
|
|
13
|
+
super();
|
|
14
|
+
this.programId = programId ? programId : constants_js_1.APTOS_PROGRAM_IDS[cluster];
|
|
15
|
+
this.maxGas = maxGas;
|
|
16
|
+
this.client = new aptos_1.AptosClient(clusterUrl);
|
|
99
17
|
}
|
|
100
18
|
/**
|
|
101
19
|
* Creates a new stream/vesting contract.
|
|
102
20
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
|
|
113
|
-
case 1:
|
|
114
|
-
hash = _c.sent();
|
|
115
|
-
return [2 /*return*/, { ixs: [payload], txId: hash, metadataId: metadataId }];
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
};
|
|
21
|
+
async create(streamData, { senderWallet }) {
|
|
22
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
23
|
+
const [metadataId, payload] = this.generateMultiPayloads({
|
|
24
|
+
...streamData,
|
|
25
|
+
recipients: [{ ...streamData }],
|
|
26
|
+
}, wallet)[0];
|
|
27
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
28
|
+
return { ixs: [payload], txId: hash, metadataId };
|
|
29
|
+
}
|
|
120
30
|
/**
|
|
121
31
|
* Creates multiple stream/vesting contracts.
|
|
122
32
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
recipient: recipient.recipient,
|
|
156
|
-
});
|
|
157
|
-
return [3 /*break*/, 6];
|
|
158
|
-
case 5:
|
|
159
|
-
metadatas.push(metadataId);
|
|
160
|
-
metadataToRecipient[metadataId] = recipient;
|
|
161
|
-
return [7 /*endfinally*/];
|
|
162
|
-
case 6:
|
|
163
|
-
i++;
|
|
164
|
-
return [3 /*break*/, 1];
|
|
165
|
-
case 7: return [2 /*return*/, {
|
|
166
|
-
txs: txs,
|
|
167
|
-
metadatas: metadatas,
|
|
168
|
-
metadataToRecipient: metadataToRecipient,
|
|
169
|
-
errors: errors,
|
|
170
|
-
}];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
};
|
|
33
|
+
async createMultiple(multipleStreamData, { senderWallet }) {
|
|
34
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
35
|
+
const payloads = this.generateMultiPayloads(multipleStreamData, wallet);
|
|
36
|
+
const txs = [];
|
|
37
|
+
const metadatas = [];
|
|
38
|
+
const metadataToRecipient = {};
|
|
39
|
+
const errors = [];
|
|
40
|
+
for (let i = 0; i < payloads.length; i++) {
|
|
41
|
+
const [metadataId, payload] = payloads[i];
|
|
42
|
+
const recipient = multipleStreamData.recipients[i];
|
|
43
|
+
try {
|
|
44
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
45
|
+
txs.push(hash);
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
errors.push({
|
|
49
|
+
error: e?.toString() ?? "Unknown error!",
|
|
50
|
+
recipient: recipient.recipient,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
metadatas.push(metadataId);
|
|
55
|
+
metadataToRecipient[metadataId] = recipient;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
txs,
|
|
60
|
+
metadatas,
|
|
61
|
+
metadataToRecipient,
|
|
62
|
+
errors,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
175
65
|
/**
|
|
176
66
|
* Attempts withdrawing from the specified stream.
|
|
177
67
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
type_arguments: [tokenId],
|
|
190
|
-
arguments: [id, amount.toString()],
|
|
191
|
-
};
|
|
192
|
-
wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
193
|
-
return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
|
|
194
|
-
case 1:
|
|
195
|
-
hash = _d.sent();
|
|
196
|
-
return [2 /*return*/, { ixs: [payload], txId: hash }];
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
};
|
|
68
|
+
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
69
|
+
const payload = {
|
|
70
|
+
type: "withdraw",
|
|
71
|
+
function: `${this.programId}::protocol::withdraw`,
|
|
72
|
+
type_arguments: [tokenId],
|
|
73
|
+
arguments: [id, amount.toString()],
|
|
74
|
+
};
|
|
75
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
76
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
77
|
+
return { ixs: [payload], txId: hash };
|
|
78
|
+
}
|
|
201
79
|
/**
|
|
202
80
|
* Attempts canceling the specified stream.
|
|
203
81
|
*/
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
arguments: [cancelData.id],
|
|
216
|
-
};
|
|
217
|
-
wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
218
|
-
return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
|
|
219
|
-
case 1:
|
|
220
|
-
hash = _b.sent();
|
|
221
|
-
return [2 /*return*/, { ixs: [payload], txId: hash }];
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
};
|
|
82
|
+
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
83
|
+
const payload = {
|
|
84
|
+
type: "cancel",
|
|
85
|
+
function: `${this.programId}::protocol::cancel`,
|
|
86
|
+
type_arguments: [tokenId],
|
|
87
|
+
arguments: [cancelData.id],
|
|
88
|
+
};
|
|
89
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
90
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
91
|
+
return { ixs: [payload], txId: hash };
|
|
92
|
+
}
|
|
226
93
|
/**
|
|
227
94
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
228
95
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
arguments: [transferData.id, transferData.newRecipient],
|
|
241
|
-
};
|
|
242
|
-
wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
243
|
-
return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
|
|
244
|
-
case 1:
|
|
245
|
-
hash = _b.sent();
|
|
246
|
-
return [2 /*return*/, { ixs: [payload], txId: hash }];
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
};
|
|
96
|
+
async transfer(transferData, { senderWallet, tokenId }) {
|
|
97
|
+
const payload = {
|
|
98
|
+
type: "transfer",
|
|
99
|
+
function: `${this.programId}::protocol::transfer`,
|
|
100
|
+
type_arguments: [tokenId],
|
|
101
|
+
arguments: [transferData.id, transferData.newRecipient],
|
|
102
|
+
};
|
|
103
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
104
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
105
|
+
return { ixs: [payload], txId: hash };
|
|
106
|
+
}
|
|
251
107
|
/**
|
|
252
108
|
* Tops up stream account with specified amount.
|
|
253
109
|
*/
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
arguments: [topupData.id, topupData.amount.toString()],
|
|
266
|
-
};
|
|
267
|
-
wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
268
|
-
return [4 /*yield*/, wallet.signAndSubmitTransaction(payload)];
|
|
269
|
-
case 1:
|
|
270
|
-
hash = _b.sent();
|
|
271
|
-
return [2 /*return*/, { ixs: [payload], txId: hash }];
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
};
|
|
110
|
+
async topup(topupData, { senderWallet, tokenId }) {
|
|
111
|
+
const payload = {
|
|
112
|
+
type: "topup",
|
|
113
|
+
function: `${this.programId}::protocol::topup`,
|
|
114
|
+
type_arguments: [tokenId],
|
|
115
|
+
arguments: [topupData.id, topupData.amount.toString()],
|
|
116
|
+
};
|
|
117
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
118
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
119
|
+
return { ixs: [payload], txId: hash };
|
|
120
|
+
}
|
|
276
121
|
/**
|
|
277
122
|
* Fetch stream data by its id (address).
|
|
278
123
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
|
|
294
|
-
tokenId = (_b = tokenIdMatch === null || tokenIdMatch === void 0 ? void 0 : tokenIdMatch[1]) !== null && _b !== void 0 ? _b : "";
|
|
295
|
-
data = contract.data;
|
|
296
|
-
return [2 /*return*/, new types_js_2.Contract(data, tokenId)];
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
};
|
|
301
|
-
AptosStreamClient.prototype.get = function () {
|
|
302
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
303
|
-
return __generator(this, function (_a) {
|
|
304
|
-
throw new Error("Get all method is not supported for Aptos chain!");
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
};
|
|
124
|
+
async getOne({ id }) {
|
|
125
|
+
const contractResources = await this.client.getAccountResources(id);
|
|
126
|
+
const contract = contractResources.find((r) => r.type.includes("protocol::Contract"));
|
|
127
|
+
if (!contract) {
|
|
128
|
+
throw new Error(`Contract with id ${id} could not be found!`);
|
|
129
|
+
}
|
|
130
|
+
const tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
|
|
131
|
+
const tokenId = tokenIdMatch?.[1] ?? "";
|
|
132
|
+
const { data } = contract;
|
|
133
|
+
return new types_js_2.Contract(data, tokenId);
|
|
134
|
+
}
|
|
135
|
+
async get() {
|
|
136
|
+
throw new Error("Get all method is not supported for Aptos chain!");
|
|
137
|
+
}
|
|
308
138
|
/**
|
|
309
139
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
310
140
|
*/
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
};
|
|
338
|
-
AptosStreamClient.prototype.getFees = function (_a) {
|
|
339
|
-
var address = _a.address;
|
|
340
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
341
|
-
var resource, data, value;
|
|
342
|
-
return __generator(this, function (_b) {
|
|
343
|
-
switch (_b.label) {
|
|
344
|
-
case 0: return [4 /*yield*/, this.client.getAccountResource(this.programId, "".concat(this.programId, "::fees::FeeTable"))];
|
|
345
|
-
case 1:
|
|
346
|
-
resource = _b.sent();
|
|
347
|
-
data = resource.data;
|
|
348
|
-
return [4 /*yield*/, this.client.getTableItem(data.values.handle, {
|
|
349
|
-
key_type: "address",
|
|
350
|
-
key: address,
|
|
351
|
-
value_type: "u64",
|
|
352
|
-
})];
|
|
353
|
-
case 2:
|
|
354
|
-
value = _b.sent();
|
|
355
|
-
if (!value) {
|
|
356
|
-
return [2 /*return*/, null];
|
|
357
|
-
}
|
|
358
|
-
return [2 /*return*/, { streamflowFee: Number(value) / 100, partnerFee: 0 }];
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
};
|
|
363
|
-
AptosStreamClient.prototype.getDefaultStreamflowFee = function () {
|
|
364
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
365
|
-
var resource;
|
|
366
|
-
return __generator(this, function (_a) {
|
|
367
|
-
switch (_a.label) {
|
|
368
|
-
case 0: return [4 /*yield*/, this.client.getAccountResource(this.programId, "".concat(this.programId, "::admin::ConfigV2"))];
|
|
369
|
-
case 1:
|
|
370
|
-
resource = _a.sent();
|
|
371
|
-
return [2 /*return*/, Number(resource.data.streamflow_fees) / 100];
|
|
372
|
-
}
|
|
373
|
-
});
|
|
141
|
+
async update(updateData, { senderWallet, tokenId }) {
|
|
142
|
+
const wallet = new wallet_js_1.AptosWalletWrapper(senderWallet, this.client);
|
|
143
|
+
const payload = {
|
|
144
|
+
type: "update",
|
|
145
|
+
function: `${this.programId}::protocol::update`,
|
|
146
|
+
type_arguments: [tokenId],
|
|
147
|
+
arguments: [
|
|
148
|
+
updateData.id,
|
|
149
|
+
updateData.enableAutomaticWithdrawal ? [true] : [],
|
|
150
|
+
updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
|
|
151
|
+
updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
const hash = await wallet.signAndSubmitTransaction(payload);
|
|
155
|
+
return { ixs: [payload], txId: hash };
|
|
156
|
+
}
|
|
157
|
+
async getFees({ address }) {
|
|
158
|
+
const resource = await this.client.getAccountResource(this.programId, `${this.programId}::fees::FeeTable`);
|
|
159
|
+
const data = resource.data;
|
|
160
|
+
const value = await this.client.getTableItem(data.values.handle, {
|
|
161
|
+
key_type: "address",
|
|
162
|
+
key: address,
|
|
163
|
+
value_type: "u64",
|
|
374
164
|
});
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
return
|
|
379
|
-
}
|
|
165
|
+
if (!value) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return { streamflowFee: Number(value) / 100, partnerFee: 0 };
|
|
169
|
+
}
|
|
170
|
+
async getDefaultStreamflowFee() {
|
|
171
|
+
const resource = await this.client.getAccountResource(this.programId, `${this.programId}::admin::ConfigV2`);
|
|
172
|
+
return Number(resource.data.streamflow_fees) / 100;
|
|
173
|
+
}
|
|
174
|
+
extractErrorCode(err) {
|
|
175
|
+
return (0, utils_js_1.extractAptosErrorCode)(err.toString() ?? "Unknown error!");
|
|
176
|
+
}
|
|
380
177
|
/**
|
|
381
178
|
* Returns StreamClient protocol program ID.
|
|
382
179
|
*/
|
|
383
|
-
|
|
180
|
+
getProgramId() {
|
|
384
181
|
return this.programId;
|
|
385
|
-
}
|
|
386
|
-
|
|
182
|
+
}
|
|
183
|
+
getMaxGas() {
|
|
387
184
|
return { max_gas_amount: this.maxGas };
|
|
388
|
-
}
|
|
185
|
+
}
|
|
389
186
|
// Utility function to prepare transaction payloads for multiple recipients.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
var encoder = new TextEncoder();
|
|
187
|
+
generateMultiPayloads(multipleStreamData, wallet) {
|
|
188
|
+
return multipleStreamData.recipients.map((recipient) => {
|
|
189
|
+
const acc = new aptos_1.AptosAccount(); // Generate random address as seeds for deriving "escrow" account
|
|
190
|
+
const seeds = acc.address();
|
|
191
|
+
const encoder = new TextEncoder();
|
|
396
192
|
// A workaround to pass a String in seeds because different wallets seem
|
|
397
193
|
// to serialize vector<u8> differently and String should be safer that Uin8Array
|
|
398
|
-
|
|
399
|
-
|
|
194
|
+
const actualSeeds = encoder.encode(seeds.hex());
|
|
195
|
+
const metadataId = aptos_1.AptosAccount.getResourceAccountAddress(wallet.address, actualSeeds);
|
|
400
196
|
return [
|
|
401
197
|
metadataId.toString(),
|
|
402
198
|
{
|
|
403
199
|
type: "create",
|
|
404
|
-
function:
|
|
200
|
+
function: `${this.programId}::protocol::create`,
|
|
405
201
|
type_arguments: [multipleStreamData.tokenId],
|
|
406
202
|
arguments: [
|
|
407
203
|
seeds.hex(),
|
|
@@ -425,7 +221,6 @@ var AptosStreamClient = /** @class */ (function (_super) {
|
|
|
425
221
|
},
|
|
426
222
|
];
|
|
427
223
|
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
}(BaseStreamClient_js_1.BaseStreamClient));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
431
226
|
exports.default = AptosStreamClient;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.APTOS_MODULE_ERROR_MAP = exports.APTOS_ERROR_MATCH_REGEX = exports.APTOS_PROGRAM_IDS = void 0;
|
|
5
|
-
|
|
6
|
-
exports.APTOS_PROGRAM_IDS =
|
|
7
|
-
|
|
4
|
+
const types_js_1 = require("../common/types.js");
|
|
5
|
+
exports.APTOS_PROGRAM_IDS = {
|
|
6
|
+
[types_js_1.ICluster.Mainnet]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
8
7
|
// TODO: Add a correct programID for Test net
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
[types_js_1.ICluster.Devnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
9
|
+
[types_js_1.ICluster.Testnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
|
|
10
|
+
[types_js_1.ICluster.Local]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
|
|
11
|
+
};
|
|
13
12
|
exports.APTOS_ERROR_MATCH_REGEX = /Move abort in [a-z0-9]+::([^:]+): ([A-Z_]+)/;
|
|
14
13
|
exports.APTOS_MODULE_ERROR_MAP = {
|
|
15
14
|
protocol: {
|