@suilend/springsui-cli 1.0.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/cli/src/index.d.ts +1 -0
- package/cli/src/index.js +304 -0
- package/package.json +1 -0
- package/sdk/src/_generated/_dependencies/source/0x1/ascii/structs.d.ts +92 -0
- package/sdk/src/_generated/_dependencies/source/0x1/ascii/structs.js +289 -0
- package/sdk/src/_generated/_dependencies/source/0x1/index.d.ts +3 -0
- package/sdk/src/_generated/_dependencies/source/0x1/index.js +6 -0
- package/sdk/src/_generated/_dependencies/source/0x1/option/structs.d.ts +52 -0
- package/sdk/src/_generated/_dependencies/source/0x1/option/structs.js +180 -0
- package/sdk/src/_generated/_dependencies/source/0x1/string/structs.d.ts +50 -0
- package/sdk/src/_generated/_dependencies/source/0x1/string/structs.js +167 -0
- package/sdk/src/_generated/_dependencies/source/0x1/type-name/structs.d.ts +53 -0
- package/sdk/src/_generated/_dependencies/source/0x1/type-name/structs.js +144 -0
- package/sdk/src/_generated/_dependencies/source/0x2/bag/structs.d.ts +61 -0
- package/sdk/src/_generated/_dependencies/source/0x2/bag/structs.js +149 -0
- package/sdk/src/_generated/_dependencies/source/0x2/balance/structs.d.ts +88 -0
- package/sdk/src/_generated/_dependencies/source/0x2/balance/structs.js +291 -0
- package/sdk/src/_generated/_dependencies/source/0x2/coin/structs.d.ts +460 -0
- package/sdk/src/_generated/_dependencies/source/0x2/coin/structs.js +1045 -0
- package/sdk/src/_generated/_dependencies/source/0x2/index.d.ts +3 -0
- package/sdk/src/_generated/_dependencies/source/0x2/index.js +6 -0
- package/sdk/src/_generated/_dependencies/source/0x2/object/structs.d.ts +92 -0
- package/sdk/src/_generated/_dependencies/source/0x2/object/structs.js +270 -0
- package/sdk/src/_generated/_dependencies/source/0x2/sui/structs.d.ts +46 -0
- package/sdk/src/_generated/_dependencies/source/0x2/sui/structs.js +142 -0
- package/sdk/src/_generated/_dependencies/source/0x2/table/structs.d.ts +61 -0
- package/sdk/src/_generated/_dependencies/source/0x2/table/structs.js +163 -0
- package/sdk/src/_generated/_dependencies/source/0x2/url/structs.d.ts +53 -0
- package/sdk/src/_generated/_dependencies/source/0x2/url/structs.js +143 -0
- package/sdk/src/_generated/_dependencies/source/0x2/vec-map/structs.d.ts +111 -0
- package/sdk/src/_generated/_dependencies/source/0x2/vec-map/structs.js +325 -0
- package/sdk/src/_generated/_dependencies/source/0x3/index.d.ts +3 -0
- package/sdk/src/_generated/_dependencies/source/0x3/index.js +6 -0
- package/sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs.d.ts +487 -0
- package/sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs.js +915 -0
- package/sdk/src/_generated/_framework/reified.d.ts +108 -0
- package/sdk/src/_generated/_framework/reified.js +240 -0
- package/sdk/src/_generated/_framework/util.d.ts +35 -0
- package/sdk/src/_generated/_framework/util.js +334 -0
- package/sdk/src/_generated/_framework/vector.d.ts +35 -0
- package/sdk/src/_generated/_framework/vector.js +77 -0
- package/sdk/src/_generated/liquid_staking/cell/structs.d.ts +54 -0
- package/sdk/src/_generated/liquid_staking/cell/structs.js +156 -0
- package/sdk/src/_generated/liquid_staking/fees/functions.d.ts +51 -0
- package/sdk/src/_generated/liquid_staking/fees/functions.js +130 -0
- package/sdk/src/_generated/liquid_staking/fees/structs.d.ts +165 -0
- package/sdk/src/_generated/liquid_staking/fees/structs.js +307 -0
- package/sdk/src/_generated/liquid_staking/index.d.ts +4 -0
- package/sdk/src/_generated/liquid_staking/index.js +10 -0
- package/sdk/src/_generated/liquid_staking/liquid-staking/functions.d.ts +88 -0
- package/sdk/src/_generated/liquid_staking/liquid-staking/functions.js +199 -0
- package/sdk/src/_generated/liquid_staking/liquid-staking/structs.d.ts +955 -0
- package/sdk/src/_generated/liquid_staking/liquid-staking/structs.js +1477 -0
- package/sdk/src/_generated/liquid_staking/storage/structs.d.ts +358 -0
- package/sdk/src/_generated/liquid_staking/storage/structs.js +365 -0
- package/sdk/src/_generated/liquid_staking/version/structs.d.ts +46 -0
- package/sdk/src/_generated/liquid_staking/version/structs.js +143 -0
- package/sdk/src/_generated/liquid_staking/weight/functions.d.ts +19 -0
- package/sdk/src/_generated/liquid_staking/weight/functions.js +44 -0
- package/sdk/src/_generated/liquid_staking/weight/structs.d.ts +205 -0
- package/sdk/src/_generated/liquid_staking/weight/structs.js +332 -0
- package/sdk/src/index.d.ts +44 -0
- package/sdk/src/index.js +234 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitGenericParameters = splitGenericParameters;
|
|
4
|
+
exports.parseTypeName = parseTypeName;
|
|
5
|
+
exports.isTransactionArgument = isTransactionArgument;
|
|
6
|
+
exports.obj = obj;
|
|
7
|
+
exports.pure = pure;
|
|
8
|
+
exports.option = option;
|
|
9
|
+
exports.generic = generic;
|
|
10
|
+
exports.vector = vector;
|
|
11
|
+
exports.typeArgIsPure = typeArgIsPure;
|
|
12
|
+
exports.compressSuiAddress = compressSuiAddress;
|
|
13
|
+
exports.compressSuiType = compressSuiType;
|
|
14
|
+
exports.composeSuiType = composeSuiType;
|
|
15
|
+
const bcs_1 = require("@mysten/sui/bcs");
|
|
16
|
+
function splitGenericParameters(str, genericSeparators = ["<", ">"]) {
|
|
17
|
+
const [left, right] = genericSeparators;
|
|
18
|
+
const tok = [];
|
|
19
|
+
let word = "";
|
|
20
|
+
let nestedAngleBrackets = 0;
|
|
21
|
+
for (let i = 0; i < str.length; i++) {
|
|
22
|
+
const char = str[i];
|
|
23
|
+
if (char === left) {
|
|
24
|
+
nestedAngleBrackets++;
|
|
25
|
+
}
|
|
26
|
+
if (char === right) {
|
|
27
|
+
nestedAngleBrackets--;
|
|
28
|
+
}
|
|
29
|
+
if (nestedAngleBrackets === 0 && char === ",") {
|
|
30
|
+
tok.push(word.trim());
|
|
31
|
+
word = "";
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
word += char;
|
|
35
|
+
}
|
|
36
|
+
tok.push(word.trim());
|
|
37
|
+
return tok;
|
|
38
|
+
}
|
|
39
|
+
function parseTypeName(name) {
|
|
40
|
+
if (typeof name !== "string") {
|
|
41
|
+
throw new Error(`Illegal type passed as a name of the type: ${name}`);
|
|
42
|
+
}
|
|
43
|
+
const [left, right] = ["<", ">"];
|
|
44
|
+
const l_bound = name.indexOf(left);
|
|
45
|
+
const r_bound = Array.from(name).reverse().indexOf(right);
|
|
46
|
+
// if there are no generics - exit gracefully.
|
|
47
|
+
if (l_bound === -1 && r_bound === -1) {
|
|
48
|
+
return { typeName: name, typeArgs: [] };
|
|
49
|
+
}
|
|
50
|
+
// if one of the bounds is not defined - throw an Error.
|
|
51
|
+
if (l_bound === -1 || r_bound === -1) {
|
|
52
|
+
throw new Error(`Unclosed generic in name '${name}'`);
|
|
53
|
+
}
|
|
54
|
+
const typeName = name.slice(0, l_bound);
|
|
55
|
+
const typeArgs = splitGenericParameters(name.slice(l_bound + 1, name.length - r_bound - 1), [left, right]);
|
|
56
|
+
return { typeName, typeArgs };
|
|
57
|
+
}
|
|
58
|
+
function isTransactionArgument(arg) {
|
|
59
|
+
if (!arg || typeof arg !== "object" || Array.isArray(arg)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return ("GasCoin" in arg ||
|
|
63
|
+
"Input" in arg ||
|
|
64
|
+
"Result" in arg ||
|
|
65
|
+
"NestedResult" in arg);
|
|
66
|
+
}
|
|
67
|
+
function obj(tx, arg) {
|
|
68
|
+
return isTransactionArgument(arg) ? arg : tx.object(arg);
|
|
69
|
+
}
|
|
70
|
+
function pure(tx, arg, type) {
|
|
71
|
+
if (isTransactionArgument(arg)) {
|
|
72
|
+
return obj(tx, arg);
|
|
73
|
+
}
|
|
74
|
+
function getBcsForType(type) {
|
|
75
|
+
const { typeName, typeArgs } = parseTypeName(type);
|
|
76
|
+
switch (typeName) {
|
|
77
|
+
case "bool":
|
|
78
|
+
return bcs_1.bcs.Bool;
|
|
79
|
+
case "u8":
|
|
80
|
+
return bcs_1.bcs.U8;
|
|
81
|
+
case "u16":
|
|
82
|
+
return bcs_1.bcs.U16;
|
|
83
|
+
case "u32":
|
|
84
|
+
return bcs_1.bcs.U32;
|
|
85
|
+
case "u64":
|
|
86
|
+
return bcs_1.bcs.U64;
|
|
87
|
+
case "u128":
|
|
88
|
+
return bcs_1.bcs.U128;
|
|
89
|
+
case "u256":
|
|
90
|
+
return bcs_1.bcs.U256;
|
|
91
|
+
case "address":
|
|
92
|
+
return bcs_1.bcs.Address;
|
|
93
|
+
case "0x1::string::String":
|
|
94
|
+
case "0x1::ascii::String":
|
|
95
|
+
return bcs_1.bcs.String;
|
|
96
|
+
case "0x2::object::ID":
|
|
97
|
+
return bcs_1.bcs.Address;
|
|
98
|
+
case "0x1::option::Option":
|
|
99
|
+
return bcs_1.bcs.option(getBcsForType(typeArgs[0]));
|
|
100
|
+
case "vector":
|
|
101
|
+
return bcs_1.bcs.vector(getBcsForType(typeArgs[0]));
|
|
102
|
+
default:
|
|
103
|
+
throw new Error(`invalid primitive type ${type}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function hasUndefinedOrNull(items) {
|
|
107
|
+
for (const item of items) {
|
|
108
|
+
if (typeof item === "undefined" || item === null) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(item)) {
|
|
112
|
+
return hasUndefinedOrNull(item);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
function consistsOnlyOfPrimitiveValues(items) {
|
|
118
|
+
for (const item of items) {
|
|
119
|
+
if (!Array.isArray(item)) {
|
|
120
|
+
if (item === null) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
switch (typeof item) {
|
|
124
|
+
case "string":
|
|
125
|
+
case "number":
|
|
126
|
+
case "bigint":
|
|
127
|
+
case "boolean":
|
|
128
|
+
continue;
|
|
129
|
+
default:
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return consistsOnlyOfPrimitiveValues(item);
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
function hasPrimitiveValues(items) {
|
|
138
|
+
for (const item of items) {
|
|
139
|
+
if (!Array.isArray(item)) {
|
|
140
|
+
switch (typeof item) {
|
|
141
|
+
case "string":
|
|
142
|
+
case "number":
|
|
143
|
+
case "bigint":
|
|
144
|
+
case "boolean":
|
|
145
|
+
return true;
|
|
146
|
+
default:
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return hasPrimitiveValues(item);
|
|
151
|
+
}
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
// handle some cases when TransactionArgument is nested within a vector or option
|
|
155
|
+
const { typeName, typeArgs } = parseTypeName(type);
|
|
156
|
+
switch (typeName) {
|
|
157
|
+
case "0x1::option::Option":
|
|
158
|
+
if (arg === null) {
|
|
159
|
+
return tx.pure.option("bool", null); // 'bool' is arbitrary
|
|
160
|
+
}
|
|
161
|
+
if (consistsOnlyOfPrimitiveValues([arg])) {
|
|
162
|
+
return tx.pure(getBcsForType(type).serialize(arg));
|
|
163
|
+
}
|
|
164
|
+
if (hasPrimitiveValues([arg])) {
|
|
165
|
+
throw new Error("mixing primitive and TransactionArgument values is not supported");
|
|
166
|
+
}
|
|
167
|
+
// wrap it with some
|
|
168
|
+
return tx.moveCall({
|
|
169
|
+
target: `0x1::option::some`,
|
|
170
|
+
typeArguments: [typeArgs[0]],
|
|
171
|
+
arguments: [pure(tx, arg, typeArgs[0])],
|
|
172
|
+
});
|
|
173
|
+
case "vector":
|
|
174
|
+
if (!Array.isArray(arg)) {
|
|
175
|
+
throw new Error("expected an array for vector type");
|
|
176
|
+
}
|
|
177
|
+
if (arg.length === 0) {
|
|
178
|
+
return tx.pure(bcs_1.bcs.vector(bcs_1.bcs.Bool).serialize([])); // bcs.Bool is arbitrary
|
|
179
|
+
}
|
|
180
|
+
if (hasUndefinedOrNull(arg)) {
|
|
181
|
+
throw new Error("the provided array contains undefined or null values");
|
|
182
|
+
}
|
|
183
|
+
if (consistsOnlyOfPrimitiveValues(arg)) {
|
|
184
|
+
return tx.pure(getBcsForType(type).serialize(arg));
|
|
185
|
+
}
|
|
186
|
+
if (hasPrimitiveValues(arg)) {
|
|
187
|
+
throw new Error("mixing primitive and TransactionArgument values is not supported");
|
|
188
|
+
}
|
|
189
|
+
return tx.makeMoveVec({
|
|
190
|
+
type: typeArgs[0],
|
|
191
|
+
elements: arg,
|
|
192
|
+
});
|
|
193
|
+
default:
|
|
194
|
+
return tx.pure(getBcsForType(type).serialize(arg));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function option(tx, type, arg) {
|
|
198
|
+
if (isTransactionArgument(arg)) {
|
|
199
|
+
return arg;
|
|
200
|
+
}
|
|
201
|
+
if (typeArgIsPure(type)) {
|
|
202
|
+
return pure(tx, arg, `0x1::option::Option<${type}>`);
|
|
203
|
+
}
|
|
204
|
+
if (arg === null) {
|
|
205
|
+
return tx.moveCall({
|
|
206
|
+
target: `0x1::option::none`,
|
|
207
|
+
typeArguments: [type],
|
|
208
|
+
arguments: [],
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
// wrap it with some
|
|
212
|
+
const val = generic(tx, type, arg);
|
|
213
|
+
return tx.moveCall({
|
|
214
|
+
target: `0x1::option::some`,
|
|
215
|
+
typeArguments: [type],
|
|
216
|
+
arguments: [val],
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
function generic(tx, type, arg) {
|
|
220
|
+
if (typeArgIsPure(type)) {
|
|
221
|
+
return pure(tx, arg, type);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
const { typeName, typeArgs } = parseTypeName(type);
|
|
225
|
+
if (typeName === "vector" && Array.isArray(arg)) {
|
|
226
|
+
const itemType = typeArgs[0];
|
|
227
|
+
return tx.makeMoveVec({
|
|
228
|
+
type: itemType,
|
|
229
|
+
elements: arg.map((item) => obj(tx, item)),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
return obj(tx, arg);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function vector(tx, itemType, items) {
|
|
238
|
+
if (typeof items === "function") {
|
|
239
|
+
throw new Error("Transaction plugins are not supported");
|
|
240
|
+
}
|
|
241
|
+
if (typeArgIsPure(itemType)) {
|
|
242
|
+
return pure(tx, items, `vector<${itemType}>`);
|
|
243
|
+
}
|
|
244
|
+
else if (isTransactionArgument(items)) {
|
|
245
|
+
return items;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
const { typeName: itemTypeName, typeArgs: itemTypeArgs } = parseTypeName(itemType);
|
|
249
|
+
if (itemTypeName === "0x1::option::Option") {
|
|
250
|
+
const elements = items.map((item) => option(tx, itemTypeArgs[0], item));
|
|
251
|
+
return tx.makeMoveVec({
|
|
252
|
+
type: itemType,
|
|
253
|
+
elements,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return tx.makeMoveVec({
|
|
257
|
+
type: itemType,
|
|
258
|
+
elements: items,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function typeArgIsPure(type) {
|
|
263
|
+
const { typeName, typeArgs } = parseTypeName(type);
|
|
264
|
+
switch (typeName) {
|
|
265
|
+
case "bool":
|
|
266
|
+
case "u8":
|
|
267
|
+
case "u16":
|
|
268
|
+
case "u32":
|
|
269
|
+
case "u64":
|
|
270
|
+
case "u128":
|
|
271
|
+
case "u256":
|
|
272
|
+
case "address":
|
|
273
|
+
case "signer":
|
|
274
|
+
return true;
|
|
275
|
+
case "vector":
|
|
276
|
+
return typeArgIsPure(typeArgs[0]);
|
|
277
|
+
case "0x1::string::String":
|
|
278
|
+
case "0x1::ascii::String":
|
|
279
|
+
case "0x2::object::ID":
|
|
280
|
+
return true;
|
|
281
|
+
case "0x1::option::Option":
|
|
282
|
+
return typeArgIsPure(typeArgs[0]);
|
|
283
|
+
default:
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function compressSuiAddress(addr) {
|
|
288
|
+
// remove leading zeros
|
|
289
|
+
const stripped = addr.split("0x").join("");
|
|
290
|
+
for (let i = 0; i < stripped.length; i++) {
|
|
291
|
+
if (stripped[i] !== "0") {
|
|
292
|
+
return `0x${stripped.substring(i)}`;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return "0x0";
|
|
296
|
+
}
|
|
297
|
+
// Recursively removes leading zeros from a type.
|
|
298
|
+
// e.g. `0x00000002::module::Name<0x00001::a::C>` -> `0x2::module::Name<0x1::a::C>`
|
|
299
|
+
function compressSuiType(type) {
|
|
300
|
+
const { typeName, typeArgs } = parseTypeName(type);
|
|
301
|
+
switch (typeName) {
|
|
302
|
+
case "bool":
|
|
303
|
+
case "u8":
|
|
304
|
+
case "u16":
|
|
305
|
+
case "u32":
|
|
306
|
+
case "u64":
|
|
307
|
+
case "u128":
|
|
308
|
+
case "u256":
|
|
309
|
+
case "address":
|
|
310
|
+
case "signer":
|
|
311
|
+
return typeName;
|
|
312
|
+
case "vector":
|
|
313
|
+
return `vector<${compressSuiType(typeArgs[0])}>`;
|
|
314
|
+
default: {
|
|
315
|
+
const tok = typeName.split("::");
|
|
316
|
+
tok[0] = compressSuiAddress(tok[0]);
|
|
317
|
+
const compressedName = tok.join("::");
|
|
318
|
+
if (typeArgs.length > 0) {
|
|
319
|
+
return `${compressedName}<${typeArgs.map((typeArg) => compressSuiType(typeArg)).join(",")}>`;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
return compressedName;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function composeSuiType(typeName, ...typeArgs) {
|
|
328
|
+
if (typeArgs.length > 0) {
|
|
329
|
+
return `${typeName}<${typeArgs.join(", ")}>`;
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
return typeName;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Reified, ToField, ToTypeArgument, ToTypeStr, TypeArgument, VectorClass, VectorClassReified } from "./reified";
|
|
2
|
+
import { FieldsWithTypes } from "./util";
|
|
3
|
+
export type VectorElements<T extends TypeArgument> = Array<ToField<T>>;
|
|
4
|
+
export type VectorReified<T extends TypeArgument> = VectorClassReified<Vector<T>, VectorElements<T>>;
|
|
5
|
+
export declare class Vector<T extends TypeArgument> implements VectorClass {
|
|
6
|
+
__VectorClass: true;
|
|
7
|
+
static readonly $typeName = "vector";
|
|
8
|
+
static readonly $numTypeParams = 1;
|
|
9
|
+
static readonly $isPhantom: readonly [false];
|
|
10
|
+
readonly $typeName = "vector";
|
|
11
|
+
readonly $fullTypeName: `vector<${ToTypeStr<T>}>`;
|
|
12
|
+
readonly $typeArgs: [ToTypeStr<T>];
|
|
13
|
+
readonly $isPhantom: readonly [false];
|
|
14
|
+
readonly elements: Array<ToField<T>>;
|
|
15
|
+
constructor(typeArgs: [ToTypeStr<T>], elements: VectorElements<T>);
|
|
16
|
+
static reified<T extends Reified<TypeArgument, any>>(T: T): VectorReified<ToTypeArgument<T>>;
|
|
17
|
+
static get r(): typeof Vector.reified;
|
|
18
|
+
static get bcs(): <T, Input>(type: import("@mysten/sui/bcs").BcsType<T, Input>, options?: import("@mysten/sui/bcs").BcsTypeOptions<T[], Iterable<Input> & {
|
|
19
|
+
length: number;
|
|
20
|
+
}>) => import("@mysten/sui/bcs").BcsType<T[], Iterable<Input> & {
|
|
21
|
+
length: number;
|
|
22
|
+
}>;
|
|
23
|
+
static fromFields<T extends Reified<TypeArgument, any>>(typeArg: T, elements: any[]): Vector<ToTypeArgument<T>>;
|
|
24
|
+
static fromFieldsWithTypes<T extends Reified<TypeArgument, any>>(typeArg: T, item: FieldsWithTypes): Vector<ToTypeArgument<T>>;
|
|
25
|
+
static fromBcs<T extends Reified<TypeArgument, any>>(typeArg: T, data: Uint8Array): Vector<ToTypeArgument<T>>;
|
|
26
|
+
toJSONField(): import("./reified").ToJSON<T>[];
|
|
27
|
+
toJSON(): {
|
|
28
|
+
$typeName: string;
|
|
29
|
+
$typeArgs: [ToTypeStr<T>];
|
|
30
|
+
elements: import("./reified").ToJSON<T>[];
|
|
31
|
+
};
|
|
32
|
+
static fromJSONField<T extends Reified<TypeArgument, any>>(typeArg: T, field: any[]): Vector<ToTypeArgument<T>>;
|
|
33
|
+
static fromJSON<T extends Reified<TypeArgument, any>>(typeArg: T, json: any): Vector<ToTypeArgument<T>>;
|
|
34
|
+
}
|
|
35
|
+
export declare function vector<T extends Reified<TypeArgument, any>>(T: T): VectorClassReified<Vector<ToTypeArgument<T>>, VectorElements<ToTypeArgument<T>>>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Vector = void 0;
|
|
4
|
+
exports.vector = vector;
|
|
5
|
+
const bcs_1 = require("@mysten/sui/bcs");
|
|
6
|
+
const reified_1 = require("./reified");
|
|
7
|
+
const util_1 = require("./util");
|
|
8
|
+
class Vector {
|
|
9
|
+
constructor(typeArgs, elements) {
|
|
10
|
+
this.__VectorClass = true;
|
|
11
|
+
this.$typeName = "vector";
|
|
12
|
+
this.$isPhantom = [false];
|
|
13
|
+
this.$fullTypeName = (0, util_1.composeSuiType)(this.$typeName, ...typeArgs);
|
|
14
|
+
this.$typeArgs = typeArgs;
|
|
15
|
+
this.elements = elements;
|
|
16
|
+
}
|
|
17
|
+
static reified(T) {
|
|
18
|
+
return {
|
|
19
|
+
typeName: Vector.$typeName,
|
|
20
|
+
fullTypeName: (0, util_1.composeSuiType)(Vector.$typeName, ...[(0, reified_1.extractType)(T)]),
|
|
21
|
+
typeArgs: [(0, reified_1.extractType)(T)],
|
|
22
|
+
isPhantom: Vector.$isPhantom,
|
|
23
|
+
reifiedTypeArgs: [T],
|
|
24
|
+
fromFields: (elements) => Vector.fromFields(T, elements),
|
|
25
|
+
fromFieldsWithTypes: (item) => Vector.fromFieldsWithTypes(T, item),
|
|
26
|
+
fromBcs: (data) => Vector.fromBcs(T, data),
|
|
27
|
+
bcs: Vector.bcs((0, reified_1.toBcs)(T)),
|
|
28
|
+
fromJSONField: (field) => Vector.fromJSONField(T, field),
|
|
29
|
+
fromJSON: (json) => Vector.fromJSON(T, json),
|
|
30
|
+
new: (elements) => {
|
|
31
|
+
return new Vector([(0, reified_1.extractType)(T)], elements);
|
|
32
|
+
},
|
|
33
|
+
kind: "VectorClassReified",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
static get r() {
|
|
37
|
+
return Vector.reified;
|
|
38
|
+
}
|
|
39
|
+
static get bcs() {
|
|
40
|
+
return bcs_1.bcs.vector;
|
|
41
|
+
}
|
|
42
|
+
static fromFields(typeArg, elements) {
|
|
43
|
+
return Vector.reified(typeArg).new(elements.map((element) => (0, reified_1.decodeFromFields)(typeArg, element)));
|
|
44
|
+
}
|
|
45
|
+
static fromFieldsWithTypes(typeArg, item) {
|
|
46
|
+
return Vector.reified(typeArg).new(item.map((field) => (0, reified_1.decodeFromFieldsWithTypes)(typeArg, field)));
|
|
47
|
+
}
|
|
48
|
+
static fromBcs(typeArg, data) {
|
|
49
|
+
return Vector.fromFields(typeArg, Vector.bcs((0, reified_1.toBcs)(typeArg)).parse(data));
|
|
50
|
+
}
|
|
51
|
+
toJSONField() {
|
|
52
|
+
return this.elements.map((element) => (0, reified_1.fieldToJSON)(this.$typeArgs[0], element));
|
|
53
|
+
}
|
|
54
|
+
toJSON() {
|
|
55
|
+
return {
|
|
56
|
+
$typeName: this.$typeName,
|
|
57
|
+
$typeArgs: this.$typeArgs,
|
|
58
|
+
elements: this.toJSONField(),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
static fromJSONField(typeArg, field) {
|
|
62
|
+
return Vector.reified(typeArg).new(field.map((field) => (0, reified_1.decodeFromJSONField)(typeArg, field)));
|
|
63
|
+
}
|
|
64
|
+
static fromJSON(typeArg, json) {
|
|
65
|
+
if (json.$typeName !== Vector.$typeName) {
|
|
66
|
+
throw new Error("not a vector json object");
|
|
67
|
+
}
|
|
68
|
+
return Vector.fromJSONField(typeArg, json.elements);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.Vector = Vector;
|
|
72
|
+
Vector.$typeName = "vector";
|
|
73
|
+
Vector.$numTypeParams = 1;
|
|
74
|
+
Vector.$isPhantom = [false];
|
|
75
|
+
function vector(T) {
|
|
76
|
+
return Vector.r(T);
|
|
77
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Option } from "../../_dependencies/source/0x1/option/structs";
|
|
2
|
+
import { PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument } from "../../_framework/reified";
|
|
3
|
+
import { FieldsWithTypes } from "../../_framework/util";
|
|
4
|
+
import { PKG_V1 } from "../index";
|
|
5
|
+
import { BcsType } from "@mysten/sui/bcs";
|
|
6
|
+
import { SuiClient, SuiObjectData, SuiParsedData } from "@mysten/sui/client";
|
|
7
|
+
export declare function isCell(type: string): boolean;
|
|
8
|
+
export interface CellFields<Element extends TypeArgument> {
|
|
9
|
+
element: ToField<Option<Element>>;
|
|
10
|
+
}
|
|
11
|
+
export type CellReified<Element extends TypeArgument> = Reified<Cell<Element>, CellFields<Element>>;
|
|
12
|
+
export declare class Cell<Element extends TypeArgument> implements StructClass {
|
|
13
|
+
__StructClass: true;
|
|
14
|
+
static readonly $typeName = "0xcfbcad8e0444ca85ad7ee28054585d12a7487bdbd83569ded988ca13441bf16e::cell::Cell";
|
|
15
|
+
static readonly $numTypeParams = 1;
|
|
16
|
+
static readonly $isPhantom: readonly [false];
|
|
17
|
+
readonly $typeName = "0xcfbcad8e0444ca85ad7ee28054585d12a7487bdbd83569ded988ca13441bf16e::cell::Cell";
|
|
18
|
+
readonly $fullTypeName: `${typeof PKG_V1}::cell::Cell<${ToTypeStr<Element>}>`;
|
|
19
|
+
readonly $typeArgs: [ToTypeStr<Element>];
|
|
20
|
+
readonly $isPhantom: readonly [false];
|
|
21
|
+
readonly element: ToField<Option<Element>>;
|
|
22
|
+
private constructor();
|
|
23
|
+
static reified<Element extends Reified<TypeArgument, any>>(Element: Element): CellReified<ToTypeArgument<Element>>;
|
|
24
|
+
static get r(): typeof Cell.reified;
|
|
25
|
+
static phantom<Element extends Reified<TypeArgument, any>>(Element: Element): PhantomReified<ToTypeStr<Cell<ToTypeArgument<Element>>>>;
|
|
26
|
+
static get p(): typeof Cell.phantom;
|
|
27
|
+
static get bcs(): <Element extends BcsType<any>>(Element: Element) => BcsType<{
|
|
28
|
+
element: {
|
|
29
|
+
vec: any[];
|
|
30
|
+
};
|
|
31
|
+
}, {
|
|
32
|
+
element: {
|
|
33
|
+
vec: Iterable<any> & {
|
|
34
|
+
length: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
static fromFields<Element extends Reified<TypeArgument, any>>(typeArg: Element, fields: Record<string, any>): Cell<ToTypeArgument<Element>>;
|
|
39
|
+
static fromFieldsWithTypes<Element extends Reified<TypeArgument, any>>(typeArg: Element, item: FieldsWithTypes): Cell<ToTypeArgument<Element>>;
|
|
40
|
+
static fromBcs<Element extends Reified<TypeArgument, any>>(typeArg: Element, data: Uint8Array): Cell<ToTypeArgument<Element>>;
|
|
41
|
+
toJSONField(): {
|
|
42
|
+
element: import("../../_framework/reified").ToJSON<Element> | null;
|
|
43
|
+
};
|
|
44
|
+
toJSON(): {
|
|
45
|
+
element: import("../../_framework/reified").ToJSON<Element> | null;
|
|
46
|
+
$typeName: string;
|
|
47
|
+
$typeArgs: [ToTypeStr<Element>];
|
|
48
|
+
};
|
|
49
|
+
static fromJSONField<Element extends Reified<TypeArgument, any>>(typeArg: Element, field: any): Cell<ToTypeArgument<Element>>;
|
|
50
|
+
static fromJSON<Element extends Reified<TypeArgument, any>>(typeArg: Element, json: Record<string, any>): Cell<ToTypeArgument<Element>>;
|
|
51
|
+
static fromSuiParsedData<Element extends Reified<TypeArgument, any>>(typeArg: Element, content: SuiParsedData): Cell<ToTypeArgument<Element>>;
|
|
52
|
+
static fromSuiObjectData<Element extends Reified<TypeArgument, any>>(typeArg: Element, data: SuiObjectData): Cell<ToTypeArgument<Element>>;
|
|
53
|
+
static fetch<Element extends Reified<TypeArgument, any>>(client: SuiClient, typeArg: Element, id: string): Promise<Cell<ToTypeArgument<Element>>>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Cell = void 0;
|
|
13
|
+
exports.isCell = isCell;
|
|
14
|
+
const structs_1 = require("../../_dependencies/source/0x1/option/structs");
|
|
15
|
+
const reified_1 = require("../../_framework/reified");
|
|
16
|
+
const util_1 = require("../../_framework/util");
|
|
17
|
+
const index_1 = require("../index");
|
|
18
|
+
const bcs_1 = require("@mysten/sui/bcs");
|
|
19
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
20
|
+
/* ============================== Cell =============================== */
|
|
21
|
+
function isCell(type) {
|
|
22
|
+
type = (0, util_1.compressSuiType)(type);
|
|
23
|
+
return type.startsWith(`${index_1.PKG_V1}::cell::Cell` + "<");
|
|
24
|
+
}
|
|
25
|
+
class Cell {
|
|
26
|
+
constructor(typeArgs, fields) {
|
|
27
|
+
this.__StructClass = true;
|
|
28
|
+
this.$typeName = Cell.$typeName;
|
|
29
|
+
this.$isPhantom = Cell.$isPhantom;
|
|
30
|
+
this.$fullTypeName = (0, util_1.composeSuiType)(Cell.$typeName, ...typeArgs);
|
|
31
|
+
this.$typeArgs = typeArgs;
|
|
32
|
+
this.element = fields.element;
|
|
33
|
+
}
|
|
34
|
+
static reified(Element) {
|
|
35
|
+
return {
|
|
36
|
+
typeName: Cell.$typeName,
|
|
37
|
+
fullTypeName: (0, util_1.composeSuiType)(Cell.$typeName, ...[(0, reified_1.extractType)(Element)]),
|
|
38
|
+
typeArgs: [(0, reified_1.extractType)(Element)],
|
|
39
|
+
isPhantom: Cell.$isPhantom,
|
|
40
|
+
reifiedTypeArgs: [Element],
|
|
41
|
+
fromFields: (fields) => Cell.fromFields(Element, fields),
|
|
42
|
+
fromFieldsWithTypes: (item) => Cell.fromFieldsWithTypes(Element, item),
|
|
43
|
+
fromBcs: (data) => Cell.fromBcs(Element, data),
|
|
44
|
+
bcs: Cell.bcs((0, reified_1.toBcs)(Element)),
|
|
45
|
+
fromJSONField: (field) => Cell.fromJSONField(Element, field),
|
|
46
|
+
fromJSON: (json) => Cell.fromJSON(Element, json),
|
|
47
|
+
fromSuiParsedData: (content) => Cell.fromSuiParsedData(Element, content),
|
|
48
|
+
fromSuiObjectData: (content) => Cell.fromSuiObjectData(Element, content),
|
|
49
|
+
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Cell.fetch(client, Element, id); }),
|
|
50
|
+
new: (fields) => {
|
|
51
|
+
return new Cell([(0, reified_1.extractType)(Element)], fields);
|
|
52
|
+
},
|
|
53
|
+
kind: "StructClassReified",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
static get r() {
|
|
57
|
+
return Cell.reified;
|
|
58
|
+
}
|
|
59
|
+
static phantom(Element) {
|
|
60
|
+
return (0, reified_1.phantom)(Cell.reified(Element));
|
|
61
|
+
}
|
|
62
|
+
static get p() {
|
|
63
|
+
return Cell.phantom;
|
|
64
|
+
}
|
|
65
|
+
static get bcs() {
|
|
66
|
+
return (Element) => bcs_1.bcs.struct(`Cell<${Element.name}>`, {
|
|
67
|
+
element: structs_1.Option.bcs(Element),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
static fromFields(typeArg, fields) {
|
|
71
|
+
return Cell.reified(typeArg).new({
|
|
72
|
+
element: (0, reified_1.decodeFromFields)(structs_1.Option.reified(typeArg), fields.element),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
static fromFieldsWithTypes(typeArg, item) {
|
|
76
|
+
if (!isCell(item.type)) {
|
|
77
|
+
throw new Error("not a Cell type");
|
|
78
|
+
}
|
|
79
|
+
(0, reified_1.assertFieldsWithTypesArgsMatch)(item, [typeArg]);
|
|
80
|
+
return Cell.reified(typeArg).new({
|
|
81
|
+
element: (0, reified_1.decodeFromFieldsWithTypes)(structs_1.Option.reified(typeArg), item.fields.element),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
static fromBcs(typeArg, data) {
|
|
85
|
+
const typeArgs = [typeArg];
|
|
86
|
+
return Cell.fromFields(typeArg, Cell.bcs((0, reified_1.toBcs)(typeArgs[0])).parse(data));
|
|
87
|
+
}
|
|
88
|
+
toJSONField() {
|
|
89
|
+
return {
|
|
90
|
+
element: (0, reified_1.fieldToJSON)(`${structs_1.Option.$typeName}<${this.$typeArgs[0]}>`, this.element),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
toJSON() {
|
|
94
|
+
return Object.assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
|
|
95
|
+
}
|
|
96
|
+
static fromJSONField(typeArg, field) {
|
|
97
|
+
return Cell.reified(typeArg).new({
|
|
98
|
+
element: (0, reified_1.decodeFromJSONField)(structs_1.Option.reified(typeArg), field.element),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
static fromJSON(typeArg, json) {
|
|
102
|
+
if (json.$typeName !== Cell.$typeName) {
|
|
103
|
+
throw new Error("not a WithTwoGenerics json object");
|
|
104
|
+
}
|
|
105
|
+
(0, reified_1.assertReifiedTypeArgsMatch)((0, util_1.composeSuiType)(Cell.$typeName, (0, reified_1.extractType)(typeArg)), json.$typeArgs, [typeArg]);
|
|
106
|
+
return Cell.fromJSONField(typeArg, json);
|
|
107
|
+
}
|
|
108
|
+
static fromSuiParsedData(typeArg, content) {
|
|
109
|
+
if (content.dataType !== "moveObject") {
|
|
110
|
+
throw new Error("not an object");
|
|
111
|
+
}
|
|
112
|
+
if (!isCell(content.type)) {
|
|
113
|
+
throw new Error(`object at ${content.fields.id} is not a Cell object`);
|
|
114
|
+
}
|
|
115
|
+
return Cell.fromFieldsWithTypes(typeArg, content);
|
|
116
|
+
}
|
|
117
|
+
static fromSuiObjectData(typeArg, data) {
|
|
118
|
+
if (data.bcs) {
|
|
119
|
+
if (data.bcs.dataType !== "moveObject" || !isCell(data.bcs.type)) {
|
|
120
|
+
throw new Error(`object at is not a Cell object`);
|
|
121
|
+
}
|
|
122
|
+
const gotTypeArgs = (0, util_1.parseTypeName)(data.bcs.type).typeArgs;
|
|
123
|
+
if (gotTypeArgs.length !== 1) {
|
|
124
|
+
throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`);
|
|
125
|
+
}
|
|
126
|
+
const gotTypeArg = (0, util_1.compressSuiType)(gotTypeArgs[0]);
|
|
127
|
+
const expectedTypeArg = (0, util_1.compressSuiType)((0, reified_1.extractType)(typeArg));
|
|
128
|
+
if (gotTypeArg !== (0, util_1.compressSuiType)((0, reified_1.extractType)(typeArg))) {
|
|
129
|
+
throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
130
|
+
}
|
|
131
|
+
return Cell.fromBcs(typeArg, (0, utils_1.fromB64)(data.bcs.bcsBytes));
|
|
132
|
+
}
|
|
133
|
+
if (data.content) {
|
|
134
|
+
return Cell.fromSuiParsedData(typeArg, data.content);
|
|
135
|
+
}
|
|
136
|
+
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
137
|
+
}
|
|
138
|
+
static fetch(client, typeArg, id) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
var _a, _b;
|
|
141
|
+
const res = yield client.getObject({ id, options: { showBcs: true } });
|
|
142
|
+
if (res.error) {
|
|
143
|
+
throw new Error(`error fetching Cell object at id ${id}: ${res.error.code}`);
|
|
144
|
+
}
|
|
145
|
+
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
146
|
+
!isCell(res.data.bcs.type)) {
|
|
147
|
+
throw new Error(`object at id ${id} is not a Cell object`);
|
|
148
|
+
}
|
|
149
|
+
return Cell.fromSuiObjectData(typeArg, res.data);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.Cell = Cell;
|
|
154
|
+
Cell.$typeName = `${index_1.PKG_V1}::cell::Cell`;
|
|
155
|
+
Cell.$numTypeParams = 1;
|
|
156
|
+
Cell.$isPhantom = [false];
|