@suilend/sdk 12.7.0 → 13.0.0-next.g803bba0
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/_generated/_dependencies/pyth-2/price-identifier/structs.d.ts +46 -0
- package/_generated/_dependencies/{source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e → pyth-2}/price-identifier/structs.js +45 -25
- package/_generated/_dependencies/std/ascii/structs.d.ts +100 -0
- package/_generated/_dependencies/{source/0x1 → std}/ascii/structs.js +153 -103
- package/_generated/_dependencies/{source/0x1 → std}/option/structs.d.ts +29 -21
- package/_generated/_dependencies/std/option/structs.js +155 -0
- package/_generated/_dependencies/std/type-name/structs.d.ts +65 -0
- package/_generated/_dependencies/{source/0x1 → std}/type-name/structs.js +49 -22
- package/_generated/_dependencies/sui/bag/structs.d.ts +75 -0
- package/_generated/_dependencies/sui/bag/structs.js +154 -0
- package/_generated/_dependencies/{source/0x2 → sui}/balance/structs.d.ts +80 -60
- package/_generated/_dependencies/sui/balance/structs.js +306 -0
- package/_generated/_dependencies/sui/object/structs.d.ts +104 -0
- package/_generated/_dependencies/{source/0x2 → sui}/object/structs.js +98 -46
- package/_generated/_dependencies/{source/0x2 → sui}/object-table/structs.d.ts +37 -30
- package/_generated/_dependencies/sui/object-table/structs.js +164 -0
- package/_generated/_envs/index.d.ts +3 -0
- package/_generated/_envs/index.js +18 -0
- package/_generated/_envs/mainnet.d.ts +2 -0
- package/_generated/_envs/mainnet.js +490 -0
- package/_generated/_framework/env.d.ts +137 -0
- package/_generated/_framework/env.js +261 -0
- package/_generated/_framework/reified.d.ts +68 -36
- package/_generated/_framework/reified.js +110 -98
- package/_generated/_framework/util.d.ts +4 -4
- package/_generated/_framework/util.js +82 -79
- package/_generated/_framework/vector.d.ts +11 -9
- package/_generated/_framework/vector.js +10 -10
- package/_generated/suilend/cell/structs.d.ts +24 -22
- package/_generated/suilend/cell/structs.js +68 -24
- package/_generated/suilend/decimal/structs.d.ts +28 -24
- package/_generated/suilend/decimal/structs.js +45 -24
- package/_generated/suilend/index.d.ts +5 -6
- package/_generated/suilend/index.js +10 -19
- package/_generated/suilend/lending-market/functions.d.ts +1123 -149
- package/_generated/suilend/lending-market/functions.js +1121 -207
- package/_generated/suilend/lending-market/structs.d.ts +985 -1290
- package/_generated/suilend/lending-market/structs.js +2482 -1282
- package/_generated/suilend/lending-market-registry/functions.d.ts +32 -3
- package/_generated/suilend/lending-market-registry/functions.js +30 -6
- package/_generated/suilend/liquidity-mining/structs.d.ts +200 -333
- package/_generated/suilend/liquidity-mining/structs.js +449 -319
- package/_generated/suilend/obligation/structs.d.ts +406 -918
- package/_generated/suilend/obligation/structs.js +786 -596
- package/_generated/suilend/rate-limiter/functions.d.ts +134 -15
- package/_generated/suilend/rate-limiter/functions.js +139 -21
- package/_generated/suilend/rate-limiter/structs.d.ts +72 -80
- package/_generated/suilend/rate-limiter/structs.js +98 -48
- package/_generated/suilend/reserve/structs.d.ts +611 -904
- package/_generated/suilend/reserve/structs.js +1528 -736
- package/_generated/suilend/reserve-config/functions.d.ts +718 -96
- package/_generated/suilend/reserve-config/functions.js +751 -157
- package/_generated/suilend/reserve-config/structs.d.ts +148 -163
- package/_generated/suilend/reserve-config/structs.js +260 -94
- package/client.d.ts +2 -2
- package/client.js +22 -39
- package/lib/initialize.d.ts +76 -76
- package/lib/initialize.js +10 -10
- package/lib/proCompatible.js +5 -5
- package/package.json +1 -1
- package/parsers/lendingMarket.d.ts +9 -9
- package/parsers/obligation.d.ts +14 -14
- package/parsers/obligation.js +4 -4
- package/parsers/rateLimiter.d.ts +1 -1
- package/parsers/reserve.d.ts +12 -12
- package/parsers/reserve.js +2 -2
- package/strategies.d.ts +14 -14
- package/utils/simulate.d.ts +1 -1
- package/utils/simulate.js +5 -5
- package/_generated/_dependencies/source/0x1/ascii/structs.d.ts +0 -84
- package/_generated/_dependencies/source/0x1/index.d.ts +0 -3
- package/_generated/_dependencies/source/0x1/index.js +0 -3
- package/_generated/_dependencies/source/0x1/option/structs.js +0 -110
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +0 -47
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +0 -52
- package/_generated/_dependencies/source/0x2/bag/structs.js +0 -113
- package/_generated/_dependencies/source/0x2/balance/structs.js +0 -210
- package/_generated/_dependencies/source/0x2/index.d.ts +0 -3
- package/_generated/_dependencies/source/0x2/index.js +0 -3
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +0 -82
- package/_generated/_dependencies/source/0x2/object-table/structs.js +0 -115
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.d.ts +0 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +0 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +0 -46
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { bcs } from
|
|
2
|
-
export function splitGenericParameters(str, genericSeparators = [
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
export function splitGenericParameters(str, genericSeparators = ['<', '>']) {
|
|
3
3
|
const [left, right] = genericSeparators;
|
|
4
4
|
const tok = [];
|
|
5
|
-
let word =
|
|
5
|
+
let word = '';
|
|
6
6
|
let nestedAngleBrackets = 0;
|
|
7
7
|
for (let i = 0; i < str.length; i++) {
|
|
8
8
|
const char = str[i];
|
|
@@ -12,9 +12,9 @@ export function splitGenericParameters(str, genericSeparators = ["<", ">"]) {
|
|
|
12
12
|
if (char === right) {
|
|
13
13
|
nestedAngleBrackets--;
|
|
14
14
|
}
|
|
15
|
-
if (nestedAngleBrackets === 0 && char ===
|
|
15
|
+
if (nestedAngleBrackets === 0 && char === ',') {
|
|
16
16
|
tok.push(word.trim());
|
|
17
|
-
word =
|
|
17
|
+
word = '';
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
20
|
word += char;
|
|
@@ -23,10 +23,10 @@ export function splitGenericParameters(str, genericSeparators = ["<", ">"]) {
|
|
|
23
23
|
return tok;
|
|
24
24
|
}
|
|
25
25
|
export function parseTypeName(name) {
|
|
26
|
-
if (typeof name !==
|
|
26
|
+
if (typeof name !== 'string') {
|
|
27
27
|
throw new Error(`Illegal type passed as a name of the type: ${name}`);
|
|
28
28
|
}
|
|
29
|
-
const [left, right] = [
|
|
29
|
+
const [left, right] = ['<', '>'];
|
|
30
30
|
const l_bound = name.indexOf(left);
|
|
31
31
|
const r_bound = Array.from(name).reverse().indexOf(right);
|
|
32
32
|
// if there are no generics - exit gracefully.
|
|
@@ -38,52 +38,55 @@ export function parseTypeName(name) {
|
|
|
38
38
|
throw new Error(`Unclosed generic in name '${name}'`);
|
|
39
39
|
}
|
|
40
40
|
const typeName = name.slice(0, l_bound);
|
|
41
|
-
const typeArgs = splitGenericParameters(name.slice(l_bound + 1, name.length - r_bound - 1), [
|
|
41
|
+
const typeArgs = splitGenericParameters(name.slice(l_bound + 1, name.length - r_bound - 1), [
|
|
42
|
+
left,
|
|
43
|
+
right,
|
|
44
|
+
]);
|
|
42
45
|
return { typeName, typeArgs };
|
|
43
46
|
}
|
|
44
47
|
export function isTransactionArgument(arg) {
|
|
45
|
-
if (!arg || typeof arg !==
|
|
48
|
+
if (!arg || typeof arg !== 'object' || Array.isArray(arg)) {
|
|
46
49
|
return false;
|
|
47
50
|
}
|
|
48
|
-
return
|
|
49
|
-
"Input" in arg ||
|
|
50
|
-
"Result" in arg ||
|
|
51
|
-
"NestedResult" in arg);
|
|
51
|
+
return 'GasCoin' in arg || 'Input' in arg || 'Result' in arg || 'NestedResult' in arg;
|
|
52
52
|
}
|
|
53
53
|
export function obj(tx, arg) {
|
|
54
54
|
return isTransactionArgument(arg) ? arg : tx.object(arg);
|
|
55
55
|
}
|
|
56
56
|
export function pure(tx, arg, type) {
|
|
57
57
|
if (isTransactionArgument(arg)) {
|
|
58
|
+
if (typeof arg === 'function') {
|
|
59
|
+
throw new Error('Transaction plugins are not supported');
|
|
60
|
+
}
|
|
58
61
|
return obj(tx, arg);
|
|
59
62
|
}
|
|
60
63
|
function getBcsForType(type) {
|
|
61
64
|
const { typeName, typeArgs } = parseTypeName(type);
|
|
62
65
|
switch (typeName) {
|
|
63
|
-
case
|
|
66
|
+
case 'bool':
|
|
64
67
|
return bcs.Bool;
|
|
65
|
-
case
|
|
68
|
+
case 'u8':
|
|
66
69
|
return bcs.U8;
|
|
67
|
-
case
|
|
70
|
+
case 'u16':
|
|
68
71
|
return bcs.U16;
|
|
69
|
-
case
|
|
72
|
+
case 'u32':
|
|
70
73
|
return bcs.U32;
|
|
71
|
-
case
|
|
74
|
+
case 'u64':
|
|
72
75
|
return bcs.U64;
|
|
73
|
-
case
|
|
76
|
+
case 'u128':
|
|
74
77
|
return bcs.U128;
|
|
75
|
-
case
|
|
78
|
+
case 'u256':
|
|
76
79
|
return bcs.U256;
|
|
77
|
-
case
|
|
80
|
+
case 'address':
|
|
78
81
|
return bcs.Address;
|
|
79
|
-
case
|
|
80
|
-
case
|
|
82
|
+
case '0x1::string::String':
|
|
83
|
+
case '0x1::ascii::String':
|
|
81
84
|
return bcs.String;
|
|
82
|
-
case
|
|
85
|
+
case '0x2::object::ID':
|
|
83
86
|
return bcs.Address;
|
|
84
|
-
case
|
|
87
|
+
case '0x1::option::Option':
|
|
85
88
|
return bcs.option(getBcsForType(typeArgs[0]));
|
|
86
|
-
case
|
|
89
|
+
case 'vector':
|
|
87
90
|
return bcs.vector(getBcsForType(typeArgs[0]));
|
|
88
91
|
default:
|
|
89
92
|
throw new Error(`invalid primitive type ${type}`);
|
|
@@ -91,7 +94,7 @@ export function pure(tx, arg, type) {
|
|
|
91
94
|
}
|
|
92
95
|
function hasUndefinedOrNull(items) {
|
|
93
96
|
for (const item of items) {
|
|
94
|
-
if (typeof item ===
|
|
97
|
+
if (typeof item === 'undefined' || item === null) {
|
|
95
98
|
return true;
|
|
96
99
|
}
|
|
97
100
|
if (Array.isArray(item)) {
|
|
@@ -107,10 +110,10 @@ export function pure(tx, arg, type) {
|
|
|
107
110
|
continue;
|
|
108
111
|
}
|
|
109
112
|
switch (typeof item) {
|
|
110
|
-
case
|
|
111
|
-
case
|
|
112
|
-
case
|
|
113
|
-
case
|
|
113
|
+
case 'string':
|
|
114
|
+
case 'number':
|
|
115
|
+
case 'bigint':
|
|
116
|
+
case 'boolean':
|
|
114
117
|
continue;
|
|
115
118
|
default:
|
|
116
119
|
return false;
|
|
@@ -124,10 +127,10 @@ export function pure(tx, arg, type) {
|
|
|
124
127
|
for (const item of items) {
|
|
125
128
|
if (!Array.isArray(item)) {
|
|
126
129
|
switch (typeof item) {
|
|
127
|
-
case
|
|
128
|
-
case
|
|
129
|
-
case
|
|
130
|
-
case
|
|
130
|
+
case 'string':
|
|
131
|
+
case 'number':
|
|
132
|
+
case 'bigint':
|
|
133
|
+
case 'boolean':
|
|
131
134
|
return true;
|
|
132
135
|
default:
|
|
133
136
|
continue;
|
|
@@ -140,15 +143,15 @@ export function pure(tx, arg, type) {
|
|
|
140
143
|
// handle some cases when TransactionArgument is nested within a vector or option
|
|
141
144
|
const { typeName, typeArgs } = parseTypeName(type);
|
|
142
145
|
switch (typeName) {
|
|
143
|
-
case
|
|
146
|
+
case '0x1::option::Option':
|
|
144
147
|
if (arg === null) {
|
|
145
|
-
return tx.pure.option(
|
|
148
|
+
return tx.pure.option('bool', null); // 'bool' is arbitrary
|
|
146
149
|
}
|
|
147
150
|
if (consistsOnlyOfPrimitiveValues([arg])) {
|
|
148
151
|
return tx.pure(getBcsForType(type).serialize(arg));
|
|
149
152
|
}
|
|
150
153
|
if (hasPrimitiveValues([arg])) {
|
|
151
|
-
throw new Error(
|
|
154
|
+
throw new Error('mixing primitive and TransactionArgument values is not supported');
|
|
152
155
|
}
|
|
153
156
|
// wrap it with some
|
|
154
157
|
return tx.moveCall({
|
|
@@ -156,21 +159,21 @@ export function pure(tx, arg, type) {
|
|
|
156
159
|
typeArguments: [typeArgs[0]],
|
|
157
160
|
arguments: [pure(tx, arg, typeArgs[0])],
|
|
158
161
|
});
|
|
159
|
-
case
|
|
162
|
+
case 'vector':
|
|
160
163
|
if (!Array.isArray(arg)) {
|
|
161
|
-
throw new Error(
|
|
164
|
+
throw new Error('expected an array for vector type');
|
|
162
165
|
}
|
|
163
166
|
if (arg.length === 0) {
|
|
164
167
|
return tx.pure(bcs.vector(bcs.Bool).serialize([])); // bcs.Bool is arbitrary
|
|
165
168
|
}
|
|
166
169
|
if (hasUndefinedOrNull(arg)) {
|
|
167
|
-
throw new Error(
|
|
170
|
+
throw new Error('the provided array contains undefined or null values');
|
|
168
171
|
}
|
|
169
172
|
if (consistsOnlyOfPrimitiveValues(arg)) {
|
|
170
173
|
return tx.pure(getBcsForType(type).serialize(arg));
|
|
171
174
|
}
|
|
172
175
|
if (hasPrimitiveValues(arg)) {
|
|
173
|
-
throw new Error(
|
|
176
|
+
throw new Error('mixing primitive and TransactionArgument values is not supported');
|
|
174
177
|
}
|
|
175
178
|
return tx.makeMoveVec({
|
|
176
179
|
type: typeArgs[0],
|
|
@@ -208,11 +211,11 @@ export function generic(tx, type, arg) {
|
|
|
208
211
|
}
|
|
209
212
|
else {
|
|
210
213
|
const { typeName, typeArgs } = parseTypeName(type);
|
|
211
|
-
if (typeName ===
|
|
214
|
+
if (typeName === 'vector' && Array.isArray(arg)) {
|
|
212
215
|
const itemType = typeArgs[0];
|
|
213
216
|
return tx.makeMoveVec({
|
|
214
217
|
type: itemType,
|
|
215
|
-
elements: arg.map(
|
|
218
|
+
elements: arg.map(item => obj(tx, item)),
|
|
216
219
|
});
|
|
217
220
|
}
|
|
218
221
|
else {
|
|
@@ -221,8 +224,8 @@ export function generic(tx, type, arg) {
|
|
|
221
224
|
}
|
|
222
225
|
}
|
|
223
226
|
export function vector(tx, itemType, items) {
|
|
224
|
-
if (typeof items ===
|
|
225
|
-
throw new Error(
|
|
227
|
+
if (typeof items === 'function') {
|
|
228
|
+
throw new Error('Transaction plugins are not supported');
|
|
226
229
|
}
|
|
227
230
|
if (typeArgIsPure(itemType)) {
|
|
228
231
|
return pure(tx, items, `vector<${itemType}>`);
|
|
@@ -232,8 +235,8 @@ export function vector(tx, itemType, items) {
|
|
|
232
235
|
}
|
|
233
236
|
else {
|
|
234
237
|
const { typeName: itemTypeName, typeArgs: itemTypeArgs } = parseTypeName(itemType);
|
|
235
|
-
if (itemTypeName ===
|
|
236
|
-
const elements = items.map(
|
|
238
|
+
if (itemTypeName === '0x1::option::Option') {
|
|
239
|
+
const elements = items.map(item => option(tx, itemTypeArgs[0], item));
|
|
237
240
|
return tx.makeMoveVec({
|
|
238
241
|
type: itemType,
|
|
239
242
|
elements,
|
|
@@ -248,23 +251,23 @@ export function vector(tx, itemType, items) {
|
|
|
248
251
|
export function typeArgIsPure(type) {
|
|
249
252
|
const { typeName, typeArgs } = parseTypeName(type);
|
|
250
253
|
switch (typeName) {
|
|
251
|
-
case
|
|
252
|
-
case
|
|
253
|
-
case
|
|
254
|
-
case
|
|
255
|
-
case
|
|
256
|
-
case
|
|
257
|
-
case
|
|
258
|
-
case
|
|
259
|
-
case
|
|
254
|
+
case 'bool':
|
|
255
|
+
case 'u8':
|
|
256
|
+
case 'u16':
|
|
257
|
+
case 'u32':
|
|
258
|
+
case 'u64':
|
|
259
|
+
case 'u128':
|
|
260
|
+
case 'u256':
|
|
261
|
+
case 'address':
|
|
262
|
+
case 'signer':
|
|
260
263
|
return true;
|
|
261
|
-
case
|
|
264
|
+
case 'vector':
|
|
262
265
|
return typeArgIsPure(typeArgs[0]);
|
|
263
|
-
case
|
|
264
|
-
case
|
|
265
|
-
case
|
|
266
|
+
case '0x1::string::String':
|
|
267
|
+
case '0x1::ascii::String':
|
|
268
|
+
case '0x2::object::ID':
|
|
266
269
|
return true;
|
|
267
|
-
case
|
|
270
|
+
case '0x1::option::Option':
|
|
268
271
|
return typeArgIsPure(typeArgs[0]);
|
|
269
272
|
default:
|
|
270
273
|
return false;
|
|
@@ -272,37 +275,37 @@ export function typeArgIsPure(type) {
|
|
|
272
275
|
}
|
|
273
276
|
export function compressSuiAddress(addr) {
|
|
274
277
|
// remove leading zeros
|
|
275
|
-
const stripped = addr.split(
|
|
278
|
+
const stripped = addr.split('0x').join('');
|
|
276
279
|
for (let i = 0; i < stripped.length; i++) {
|
|
277
|
-
if (stripped[i] !==
|
|
280
|
+
if (stripped[i] !== '0') {
|
|
278
281
|
return `0x${stripped.substring(i)}`;
|
|
279
282
|
}
|
|
280
283
|
}
|
|
281
|
-
return
|
|
284
|
+
return '0x0';
|
|
282
285
|
}
|
|
283
286
|
// Recursively removes leading zeros from a type.
|
|
284
287
|
// e.g. `0x00000002::module::Name<0x00001::a::C>` -> `0x2::module::Name<0x1::a::C>`
|
|
285
288
|
export function compressSuiType(type) {
|
|
286
289
|
const { typeName, typeArgs } = parseTypeName(type);
|
|
287
290
|
switch (typeName) {
|
|
288
|
-
case
|
|
289
|
-
case
|
|
290
|
-
case
|
|
291
|
-
case
|
|
292
|
-
case
|
|
293
|
-
case
|
|
294
|
-
case
|
|
295
|
-
case
|
|
296
|
-
case
|
|
291
|
+
case 'bool':
|
|
292
|
+
case 'u8':
|
|
293
|
+
case 'u16':
|
|
294
|
+
case 'u32':
|
|
295
|
+
case 'u64':
|
|
296
|
+
case 'u128':
|
|
297
|
+
case 'u256':
|
|
298
|
+
case 'address':
|
|
299
|
+
case 'signer':
|
|
297
300
|
return typeName;
|
|
298
|
-
case
|
|
301
|
+
case 'vector':
|
|
299
302
|
return `vector<${compressSuiType(typeArgs[0])}>`;
|
|
300
303
|
default: {
|
|
301
|
-
const tok = typeName.split(
|
|
304
|
+
const tok = typeName.split('::');
|
|
302
305
|
tok[0] = compressSuiAddress(tok[0]);
|
|
303
|
-
const compressedName = tok.join(
|
|
306
|
+
const compressedName = tok.join('::');
|
|
304
307
|
if (typeArgs.length > 0) {
|
|
305
|
-
return `${compressedName}<${typeArgs.map(
|
|
308
|
+
return `${compressedName}<${typeArgs.map(typeArg => compressSuiType(typeArg)).join(',')}>`;
|
|
306
309
|
}
|
|
307
310
|
else {
|
|
308
311
|
return compressedName;
|
|
@@ -312,7 +315,7 @@ export function compressSuiType(type) {
|
|
|
312
315
|
}
|
|
313
316
|
export function composeSuiType(typeName, ...typeArgs) {
|
|
314
317
|
if (typeArgs.length > 0) {
|
|
315
|
-
return `${typeName}<${typeArgs.join(
|
|
318
|
+
return `${typeName}<${typeArgs.join(', ')}>`;
|
|
316
319
|
}
|
|
317
320
|
else {
|
|
318
321
|
return typeName;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { bcs } from
|
|
2
|
-
import { Reified, ToField, ToTypeArgument, ToTypeStr, TypeArgument, VectorClass, VectorClassReified } from
|
|
3
|
-
import { FieldsWithTypes } from
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
import { Reified, ToField, ToJSON, ToTypeArgument, ToTypeStr, TypeArgument, VectorClass, VectorClassReified } from './reified';
|
|
3
|
+
import { FieldsWithTypes } from './util';
|
|
4
4
|
export type VectorElements<T extends TypeArgument> = Array<ToField<T>>;
|
|
5
5
|
export type VectorReified<T extends TypeArgument> = VectorClassReified<Vector<T>, VectorElements<T>>;
|
|
6
|
+
export type VectorJSONField<T extends TypeArgument> = ToJSON<T>[];
|
|
7
|
+
export type VectorJSON<T extends TypeArgument> = {
|
|
8
|
+
$typeName: 'vector';
|
|
9
|
+
$typeArgs: [ToTypeStr<T>];
|
|
10
|
+
elements: VectorJSONField<T>;
|
|
11
|
+
};
|
|
6
12
|
export declare class Vector<T extends TypeArgument> implements VectorClass {
|
|
7
13
|
__VectorClass: true;
|
|
8
14
|
static readonly $typeName = "vector";
|
|
@@ -20,12 +26,8 @@ export declare class Vector<T extends TypeArgument> implements VectorClass {
|
|
|
20
26
|
static fromFields<T extends Reified<TypeArgument, any>>(typeArg: T, elements: any[]): Vector<ToTypeArgument<T>>;
|
|
21
27
|
static fromFieldsWithTypes<T extends Reified<TypeArgument, any>>(typeArg: T, item: FieldsWithTypes): Vector<ToTypeArgument<T>>;
|
|
22
28
|
static fromBcs<T extends Reified<TypeArgument, any>>(typeArg: T, data: Uint8Array): Vector<ToTypeArgument<T>>;
|
|
23
|
-
toJSONField():
|
|
24
|
-
toJSON():
|
|
25
|
-
$typeName: string;
|
|
26
|
-
$typeArgs: [ToTypeStr<T>];
|
|
27
|
-
elements: import("./reified").ToJSON<T>[];
|
|
28
|
-
};
|
|
29
|
+
toJSONField(): VectorJSONField<T>;
|
|
30
|
+
toJSON(): VectorJSON<T>;
|
|
29
31
|
static fromJSONField<T extends Reified<TypeArgument, any>>(typeArg: T, field: any[]): Vector<ToTypeArgument<T>>;
|
|
30
32
|
static fromJSON<T extends Reified<TypeArgument, any>>(typeArg: T, json: any): Vector<ToTypeArgument<T>>;
|
|
31
33
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { bcs } from
|
|
2
|
-
import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType,
|
|
3
|
-
import { composeSuiType } from
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, toBcs, } from './reified.js';
|
|
3
|
+
import { composeSuiType } from './util.js';
|
|
4
4
|
export class Vector {
|
|
5
5
|
__VectorClass = true;
|
|
6
|
-
static $typeName =
|
|
6
|
+
static $typeName = 'vector';
|
|
7
7
|
static $numTypeParams = 1;
|
|
8
8
|
static $isPhantom = [false];
|
|
9
|
-
$typeName =
|
|
9
|
+
$typeName = 'vector';
|
|
10
10
|
$fullTypeName;
|
|
11
11
|
$typeArgs;
|
|
12
12
|
$isPhantom = [false];
|
|
@@ -32,7 +32,7 @@ export class Vector {
|
|
|
32
32
|
new: (elements) => {
|
|
33
33
|
return new Vector([extractType(T)], elements);
|
|
34
34
|
},
|
|
35
|
-
kind:
|
|
35
|
+
kind: 'VectorClassReified',
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
static get r() {
|
|
@@ -42,7 +42,7 @@ export class Vector {
|
|
|
42
42
|
return bcs.vector;
|
|
43
43
|
}
|
|
44
44
|
static fromFields(typeArg, elements) {
|
|
45
|
-
return Vector.reified(typeArg).new(elements.map(
|
|
45
|
+
return Vector.reified(typeArg).new(elements.map(element => decodeFromFields(typeArg, element)));
|
|
46
46
|
}
|
|
47
47
|
static fromFieldsWithTypes(typeArg, item) {
|
|
48
48
|
return Vector.reified(typeArg).new(item.map((field) => decodeFromFieldsWithTypes(typeArg, field)));
|
|
@@ -51,7 +51,7 @@ export class Vector {
|
|
|
51
51
|
return Vector.fromFields(typeArg, Vector.bcs(toBcs(typeArg)).parse(data));
|
|
52
52
|
}
|
|
53
53
|
toJSONField() {
|
|
54
|
-
return this.elements.map(
|
|
54
|
+
return this.elements.map(element => fieldToJSON(this.$typeArgs[0], element));
|
|
55
55
|
}
|
|
56
56
|
toJSON() {
|
|
57
57
|
return {
|
|
@@ -61,11 +61,11 @@ export class Vector {
|
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
63
|
static fromJSONField(typeArg, field) {
|
|
64
|
-
return Vector.reified(typeArg).new(field.map(
|
|
64
|
+
return Vector.reified(typeArg).new(field.map(field => decodeFromJSONField(typeArg, field)));
|
|
65
65
|
}
|
|
66
66
|
static fromJSON(typeArg, json) {
|
|
67
67
|
if (json.$typeName !== Vector.$typeName) {
|
|
68
|
-
throw new Error(
|
|
68
|
+
throw new Error('not a vector json object');
|
|
69
69
|
}
|
|
70
70
|
return Vector.fromJSONField(typeArg, json.elements);
|
|
71
71
|
}
|
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { BcsType } from "@mysten/sui/bcs";
|
|
6
|
-
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
1
|
+
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
2
|
+
import { Option } from '../../_dependencies/std/option/structs';
|
|
3
|
+
import { PhantomReified, Reified, StructClass, ToField, ToJSON, ToTypeArgument, ToTypeStr, TypeArgument } from '../../_framework/reified';
|
|
4
|
+
import { FieldsWithTypes } from '../../_framework/util';
|
|
7
5
|
export declare function isCell(type: string): boolean;
|
|
8
6
|
export interface CellFields<Element extends TypeArgument> {
|
|
9
7
|
element: ToField<Option<Element>>;
|
|
10
8
|
}
|
|
11
9
|
export type CellReified<Element extends TypeArgument> = Reified<Cell<Element>, CellFields<Element>>;
|
|
10
|
+
export type CellJSONField<Element extends TypeArgument> = {
|
|
11
|
+
element: ToJSON<Element> | null;
|
|
12
|
+
};
|
|
13
|
+
export type CellJSON<Element extends TypeArgument> = {
|
|
14
|
+
$typeName: typeof Cell.$typeName;
|
|
15
|
+
$typeArgs: [ToTypeStr<Element>];
|
|
16
|
+
} & CellJSONField<Element>;
|
|
12
17
|
export declare class Cell<Element extends TypeArgument> implements StructClass {
|
|
13
18
|
__StructClass: true;
|
|
14
|
-
static
|
|
19
|
+
static get $typeName(): `${string}::cell::Cell`;
|
|
15
20
|
static readonly $numTypeParams = 1;
|
|
16
21
|
static readonly $isPhantom: readonly [false];
|
|
17
|
-
readonly $typeName:
|
|
18
|
-
readonly $fullTypeName: `${
|
|
22
|
+
readonly $typeName: typeof Cell.$typeName;
|
|
23
|
+
readonly $fullTypeName: `${string}::cell::Cell<${ToTypeStr<Element>}>`;
|
|
19
24
|
readonly $typeArgs: [ToTypeStr<Element>];
|
|
20
|
-
readonly $isPhantom:
|
|
25
|
+
readonly $isPhantom: typeof Cell.$isPhantom;
|
|
21
26
|
readonly element: ToField<Option<Element>>;
|
|
22
27
|
private constructor();
|
|
23
28
|
static reified<Element extends Reified<TypeArgument, any>>(Element: Element): CellReified<ToTypeArgument<Element>>;
|
|
24
29
|
static get r(): typeof Cell.reified;
|
|
25
30
|
static phantom<Element extends Reified<TypeArgument, any>>(Element: Element): PhantomReified<ToTypeStr<Cell<ToTypeArgument<Element>>>>;
|
|
26
31
|
static get p(): typeof Cell.phantom;
|
|
27
|
-
static
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
private static instantiateBcs;
|
|
33
|
+
private static cachedBcs;
|
|
34
|
+
static get bcs(): ReturnType<typeof Cell.instantiateBcs>;
|
|
30
35
|
static fromFields<Element extends Reified<TypeArgument, any>>(typeArg: Element, fields: Record<string, any>): Cell<ToTypeArgument<Element>>;
|
|
31
36
|
static fromFieldsWithTypes<Element extends Reified<TypeArgument, any>>(typeArg: Element, item: FieldsWithTypes): Cell<ToTypeArgument<Element>>;
|
|
32
37
|
static fromBcs<Element extends Reified<TypeArgument, any>>(typeArg: Element, data: Uint8Array): Cell<ToTypeArgument<Element>>;
|
|
33
|
-
toJSONField():
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
toJSON(): {
|
|
37
|
-
element: import("../../_framework/reified").ToJSON<Element> | null;
|
|
38
|
-
$typeName: string;
|
|
39
|
-
$typeArgs: [ToTypeStr<Element>];
|
|
40
|
-
};
|
|
38
|
+
toJSONField(): CellJSONField<Element>;
|
|
39
|
+
toJSON(): CellJSON<Element>;
|
|
41
40
|
static fromJSONField<Element extends Reified<TypeArgument, any>>(typeArg: Element, field: any): Cell<ToTypeArgument<Element>>;
|
|
42
41
|
static fromJSON<Element extends Reified<TypeArgument, any>>(typeArg: Element, json: Record<string, any>): Cell<ToTypeArgument<Element>>;
|
|
43
|
-
static
|
|
42
|
+
static fromCoreObject<Element extends Reified<TypeArgument, any>>(typeArg: Element, obj: SuiClientTypes.Object<{
|
|
43
|
+
content: true;
|
|
44
|
+
}>): Cell<ToTypeArgument<Element>>;
|
|
45
|
+
static fetch<Element extends Reified<TypeArgument, any>>(client: ClientWithCoreApi, typeArg: Element, id: string): Promise<Cell<ToTypeArgument<Element>>>;
|
|
44
46
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
import { Option } from '../../_dependencies/std/option/structs.js';
|
|
3
|
+
import { getTypeOrigin } from '../../_envs/index.js';
|
|
4
|
+
import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs, } from '../../_framework/reified.js';
|
|
5
|
+
import { composeSuiType, compressSuiType, parseTypeName, } from '../../_framework/util.js';
|
|
6
6
|
/* ============================== Cell =============================== */
|
|
7
7
|
export function isCell(type) {
|
|
8
8
|
type = compressSuiType(type);
|
|
9
|
-
return type.startsWith(`${
|
|
9
|
+
return type.startsWith(`${getTypeOrigin('suilend', 'cell::Cell')}::cell::Cell` + '<');
|
|
10
10
|
}
|
|
11
11
|
export class Cell {
|
|
12
12
|
__StructClass = true;
|
|
13
|
-
static $typeName
|
|
13
|
+
static get $typeName() {
|
|
14
|
+
return `${getTypeOrigin('suilend', 'cell::Cell')}::cell::Cell`;
|
|
15
|
+
}
|
|
14
16
|
static $numTypeParams = 1;
|
|
15
17
|
static $isPhantom = [false];
|
|
16
18
|
$typeName = Cell.$typeName;
|
|
@@ -24,23 +26,31 @@ export class Cell {
|
|
|
24
26
|
this.element = fields.element;
|
|
25
27
|
}
|
|
26
28
|
static reified(Element) {
|
|
29
|
+
const reifiedBcs = Cell.bcs(toBcs(Element));
|
|
27
30
|
return {
|
|
28
|
-
typeName
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
get typeName() {
|
|
32
|
+
return Cell.$typeName;
|
|
33
|
+
},
|
|
34
|
+
get fullTypeName() {
|
|
35
|
+
return composeSuiType(Cell.$typeName, ...[extractType(Element)]);
|
|
36
|
+
},
|
|
37
|
+
get typeArgs() {
|
|
38
|
+
return [extractType(Element)];
|
|
39
|
+
},
|
|
31
40
|
isPhantom: Cell.$isPhantom,
|
|
32
41
|
reifiedTypeArgs: [Element],
|
|
33
42
|
fromFields: (fields) => Cell.fromFields(Element, fields),
|
|
34
43
|
fromFieldsWithTypes: (item) => Cell.fromFieldsWithTypes(Element, item),
|
|
35
|
-
fromBcs: (data) => Cell.
|
|
36
|
-
bcs:
|
|
44
|
+
fromBcs: (data) => Cell.fromFields(Element, reifiedBcs.parse(data)),
|
|
45
|
+
bcs: reifiedBcs,
|
|
37
46
|
fromJSONField: (field) => Cell.fromJSONField(Element, field),
|
|
38
47
|
fromJSON: (json) => Cell.fromJSON(Element, json),
|
|
48
|
+
fromCoreObject: (obj) => Cell.fromCoreObject(Element, obj),
|
|
39
49
|
fetch: async (client, id) => Cell.fetch(client, Element, id),
|
|
40
50
|
new: (fields) => {
|
|
41
51
|
return new Cell([extractType(Element)], fields);
|
|
42
52
|
},
|
|
43
|
-
kind:
|
|
53
|
+
kind: 'StructClassReified',
|
|
44
54
|
};
|
|
45
55
|
}
|
|
46
56
|
static get r() {
|
|
@@ -52,11 +62,18 @@ export class Cell {
|
|
|
52
62
|
static get p() {
|
|
53
63
|
return Cell.phantom;
|
|
54
64
|
}
|
|
55
|
-
static
|
|
65
|
+
static instantiateBcs() {
|
|
56
66
|
return (Element) => bcs.struct(`Cell<${Element.name}>`, {
|
|
57
67
|
element: Option.bcs(Element),
|
|
58
68
|
});
|
|
59
69
|
}
|
|
70
|
+
static cachedBcs = null;
|
|
71
|
+
static get bcs() {
|
|
72
|
+
if (!Cell.cachedBcs) {
|
|
73
|
+
Cell.cachedBcs = Cell.instantiateBcs();
|
|
74
|
+
}
|
|
75
|
+
return Cell.cachedBcs;
|
|
76
|
+
}
|
|
60
77
|
static fromFields(typeArg, fields) {
|
|
61
78
|
return Cell.reified(typeArg).new({
|
|
62
79
|
element: decodeFromFields(Option.reified(typeArg), fields.element),
|
|
@@ -64,7 +81,7 @@ export class Cell {
|
|
|
64
81
|
}
|
|
65
82
|
static fromFieldsWithTypes(typeArg, item) {
|
|
66
83
|
if (!isCell(item.type)) {
|
|
67
|
-
throw new Error(
|
|
84
|
+
throw new Error('not a Cell type');
|
|
68
85
|
}
|
|
69
86
|
assertFieldsWithTypesArgsMatch(item, [typeArg]);
|
|
70
87
|
return Cell.reified(typeArg).new({
|
|
@@ -73,7 +90,7 @@ export class Cell {
|
|
|
73
90
|
}
|
|
74
91
|
static fromBcs(typeArg, data) {
|
|
75
92
|
const typeArgs = [typeArg];
|
|
76
|
-
return Cell.fromFields(typeArg, Cell.bcs(toBcs(
|
|
93
|
+
return Cell.fromFields(typeArg, Cell.bcs(toBcs(typeArg)).parse(data));
|
|
77
94
|
}
|
|
78
95
|
toJSONField() {
|
|
79
96
|
return {
|
|
@@ -81,11 +98,7 @@ export class Cell {
|
|
|
81
98
|
};
|
|
82
99
|
}
|
|
83
100
|
toJSON() {
|
|
84
|
-
return {
|
|
85
|
-
$typeName: this.$typeName,
|
|
86
|
-
$typeArgs: this.$typeArgs,
|
|
87
|
-
...this.toJSONField(),
|
|
88
|
-
};
|
|
101
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
89
102
|
}
|
|
90
103
|
static fromJSONField(typeArg, field) {
|
|
91
104
|
return Cell.reified(typeArg).new({
|
|
@@ -94,16 +107,47 @@ export class Cell {
|
|
|
94
107
|
}
|
|
95
108
|
static fromJSON(typeArg, json) {
|
|
96
109
|
if (json.$typeName !== Cell.$typeName) {
|
|
97
|
-
throw new Error(
|
|
110
|
+
throw new Error(`not a Cell json object: expected '${Cell.$typeName}' but got '${json.$typeName}'`);
|
|
98
111
|
}
|
|
99
|
-
assertReifiedTypeArgsMatch(composeSuiType(Cell.$typeName, extractType(typeArg)), json.$typeArgs, [typeArg]);
|
|
112
|
+
assertReifiedTypeArgsMatch(composeSuiType(Cell.$typeName, ...[extractType(typeArg)]), json.$typeArgs, [typeArg]);
|
|
100
113
|
return Cell.fromJSONField(typeArg, json);
|
|
101
114
|
}
|
|
115
|
+
static fromCoreObject(typeArg, obj) {
|
|
116
|
+
if (!isCell(obj.type)) {
|
|
117
|
+
throw new Error(`object at ${obj.objectId} is not a Cell object`);
|
|
118
|
+
}
|
|
119
|
+
const gotTypeArgs = parseTypeName(obj.type).typeArgs;
|
|
120
|
+
if (gotTypeArgs.length !== 1) {
|
|
121
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
122
|
+
}
|
|
123
|
+
for (let i = 0; i < 1; i++) {
|
|
124
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
125
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
126
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
127
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return Cell.fromBcs(typeArg, obj.content);
|
|
131
|
+
}
|
|
102
132
|
static async fetch(client, typeArg, id) {
|
|
103
|
-
const { object } = await client.getObject({
|
|
133
|
+
const { object } = await client.core.getObject({
|
|
134
|
+
objectId: id,
|
|
135
|
+
include: { content: true },
|
|
136
|
+
});
|
|
104
137
|
if (!isCell(object.type)) {
|
|
105
138
|
throw new Error(`object at id ${id} is not a Cell object`);
|
|
106
139
|
}
|
|
140
|
+
const gotTypeArgs = parseTypeName(object.type).typeArgs;
|
|
141
|
+
if (gotTypeArgs.length !== 1) {
|
|
142
|
+
throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
|
|
143
|
+
}
|
|
144
|
+
for (let i = 0; i < 1; i++) {
|
|
145
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
146
|
+
const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
|
|
147
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
148
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
107
151
|
return Cell.fromBcs(typeArg, object.content);
|
|
108
152
|
}
|
|
109
153
|
}
|