@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,16 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
/** Sui object identifiers */
|
|
2
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
3
|
+
import { fromHex, toHex } from '@mysten/sui/utils';
|
|
4
|
+
import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom, } from '../../../_framework/reified.js';
|
|
5
|
+
import { composeSuiType, compressSuiType } from '../../../_framework/util.js';
|
|
6
6
|
/* ============================== ID =============================== */
|
|
7
7
|
export function isID(type) {
|
|
8
8
|
type = compressSuiType(type);
|
|
9
|
-
return type ===
|
|
9
|
+
return type === `0x2::object::ID`;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* An object ID. This is used to reference Sui Objects.
|
|
13
|
+
* This is *not* guaranteed to be globally unique--anyone can create an `ID` from a `UID` or
|
|
14
|
+
* from an object, and ID's can be freely copied and dropped.
|
|
15
|
+
* Here, the values are not globally unique because there can be multiple values of type `ID`
|
|
16
|
+
* with the same underlying bytes. For example, `object::id(&obj)` can be called as many times
|
|
17
|
+
* as you want for a given `obj`, and each `ID` value will be identical.
|
|
18
|
+
*/
|
|
11
19
|
export class ID {
|
|
12
20
|
__StructClass = true;
|
|
13
|
-
static $typeName =
|
|
21
|
+
static $typeName = `0x2::object::ID`;
|
|
14
22
|
static $numTypeParams = 0;
|
|
15
23
|
static $isPhantom = [];
|
|
16
24
|
$typeName = ID.$typeName;
|
|
@@ -24,23 +32,29 @@ export class ID {
|
|
|
24
32
|
this.bytes = fields.bytes;
|
|
25
33
|
}
|
|
26
34
|
static reified() {
|
|
35
|
+
const reifiedBcs = ID.bcs;
|
|
27
36
|
return {
|
|
28
|
-
typeName
|
|
29
|
-
|
|
37
|
+
get typeName() {
|
|
38
|
+
return ID.$typeName;
|
|
39
|
+
},
|
|
40
|
+
get fullTypeName() {
|
|
41
|
+
return composeSuiType(ID.$typeName, ...[]);
|
|
42
|
+
},
|
|
30
43
|
typeArgs: [],
|
|
31
44
|
isPhantom: ID.$isPhantom,
|
|
32
45
|
reifiedTypeArgs: [],
|
|
33
46
|
fromFields: (fields) => ID.fromFields(fields),
|
|
34
47
|
fromFieldsWithTypes: (item) => ID.fromFieldsWithTypes(item),
|
|
35
|
-
fromBcs: (data) => ID.
|
|
36
|
-
bcs:
|
|
48
|
+
fromBcs: (data) => ID.fromFields(reifiedBcs.parse(data)),
|
|
49
|
+
bcs: reifiedBcs,
|
|
37
50
|
fromJSONField: (field) => ID.fromJSONField(field),
|
|
38
51
|
fromJSON: (json) => ID.fromJSON(json),
|
|
52
|
+
fromCoreObject: (obj) => ID.fromCoreObject(obj),
|
|
39
53
|
fetch: async (client, id) => ID.fetch(client, id),
|
|
40
54
|
new: (fields) => {
|
|
41
55
|
return new ID([], fields);
|
|
42
56
|
},
|
|
43
|
-
kind:
|
|
57
|
+
kind: 'StructClassReified',
|
|
44
58
|
};
|
|
45
59
|
}
|
|
46
60
|
static get r() {
|
|
@@ -52,27 +66,32 @@ export class ID {
|
|
|
52
66
|
static get p() {
|
|
53
67
|
return ID.phantom();
|
|
54
68
|
}
|
|
55
|
-
static
|
|
56
|
-
return bcs.struct(
|
|
57
|
-
bytes: bcs
|
|
58
|
-
.bytes(32)
|
|
59
|
-
.transform({
|
|
69
|
+
static instantiateBcs() {
|
|
70
|
+
return bcs.struct('ID', {
|
|
71
|
+
bytes: bcs.bytes(32).transform({
|
|
60
72
|
input: (val) => fromHex(val),
|
|
61
73
|
output: (val) => toHex(val),
|
|
62
74
|
}),
|
|
63
75
|
});
|
|
64
76
|
}
|
|
77
|
+
static cachedBcs = null;
|
|
78
|
+
static get bcs() {
|
|
79
|
+
if (!ID.cachedBcs) {
|
|
80
|
+
ID.cachedBcs = ID.instantiateBcs();
|
|
81
|
+
}
|
|
82
|
+
return ID.cachedBcs;
|
|
83
|
+
}
|
|
65
84
|
static fromFields(fields) {
|
|
66
85
|
return ID.reified().new({
|
|
67
|
-
bytes: decodeFromFields(
|
|
86
|
+
bytes: decodeFromFields('address', fields.bytes),
|
|
68
87
|
});
|
|
69
88
|
}
|
|
70
89
|
static fromFieldsWithTypes(item) {
|
|
71
90
|
if (!isID(item.type)) {
|
|
72
|
-
throw new Error(
|
|
91
|
+
throw new Error('not a ID type');
|
|
73
92
|
}
|
|
74
93
|
return ID.reified().new({
|
|
75
|
-
bytes: decodeFromFieldsWithTypes(
|
|
94
|
+
bytes: decodeFromFieldsWithTypes('address', item.fields.bytes),
|
|
76
95
|
});
|
|
77
96
|
}
|
|
78
97
|
static fromBcs(data) {
|
|
@@ -84,25 +103,30 @@ export class ID {
|
|
|
84
103
|
};
|
|
85
104
|
}
|
|
86
105
|
toJSON() {
|
|
87
|
-
return {
|
|
88
|
-
$typeName: this.$typeName,
|
|
89
|
-
$typeArgs: this.$typeArgs,
|
|
90
|
-
...this.toJSONField(),
|
|
91
|
-
};
|
|
106
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
92
107
|
}
|
|
93
108
|
static fromJSONField(field) {
|
|
94
109
|
return ID.reified().new({
|
|
95
|
-
bytes: decodeFromJSONField(
|
|
110
|
+
bytes: decodeFromJSONField('address', field.bytes),
|
|
96
111
|
});
|
|
97
112
|
}
|
|
98
113
|
static fromJSON(json) {
|
|
99
114
|
if (json.$typeName !== ID.$typeName) {
|
|
100
|
-
throw new Error(
|
|
115
|
+
throw new Error(`not a ID json object: expected '${ID.$typeName}' but got '${json.$typeName}'`);
|
|
101
116
|
}
|
|
102
117
|
return ID.fromJSONField(json);
|
|
103
118
|
}
|
|
119
|
+
static fromCoreObject(obj) {
|
|
120
|
+
if (!isID(obj.type)) {
|
|
121
|
+
throw new Error(`object at ${obj.objectId} is not a ID object`);
|
|
122
|
+
}
|
|
123
|
+
return ID.fromBcs(obj.content);
|
|
124
|
+
}
|
|
104
125
|
static async fetch(client, id) {
|
|
105
|
-
const { object } = await client.getObject({
|
|
126
|
+
const { object } = await client.core.getObject({
|
|
127
|
+
objectId: id,
|
|
128
|
+
include: { content: true },
|
|
129
|
+
});
|
|
106
130
|
if (!isID(object.type)) {
|
|
107
131
|
throw new Error(`object at id ${id} is not a ID object`);
|
|
108
132
|
}
|
|
@@ -112,11 +136,19 @@ export class ID {
|
|
|
112
136
|
/* ============================== UID =============================== */
|
|
113
137
|
export function isUID(type) {
|
|
114
138
|
type = compressSuiType(type);
|
|
115
|
-
return type ===
|
|
139
|
+
return type === `0x2::object::UID`;
|
|
116
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Globally unique IDs that define an object's ID in storage. Any Sui Object, that is a struct
|
|
143
|
+
* with the `key` ability, must have `id: UID` as its first field.
|
|
144
|
+
* These are globally unique in the sense that no two values of type `UID` are ever equal, in
|
|
145
|
+
* other words for any two values `id1: UID` and `id2: UID`, `id1` != `id2`.
|
|
146
|
+
* This is a privileged type that can only be derived from a `TxContext`.
|
|
147
|
+
* `UID` doesn't have the `drop` ability, so deleting a `UID` requires a call to `delete`.
|
|
148
|
+
*/
|
|
117
149
|
export class UID {
|
|
118
150
|
__StructClass = true;
|
|
119
|
-
static $typeName =
|
|
151
|
+
static $typeName = `0x2::object::UID`;
|
|
120
152
|
static $numTypeParams = 0;
|
|
121
153
|
static $isPhantom = [];
|
|
122
154
|
$typeName = UID.$typeName;
|
|
@@ -130,23 +162,29 @@ export class UID {
|
|
|
130
162
|
this.id = fields.id;
|
|
131
163
|
}
|
|
132
164
|
static reified() {
|
|
165
|
+
const reifiedBcs = UID.bcs;
|
|
133
166
|
return {
|
|
134
|
-
typeName
|
|
135
|
-
|
|
167
|
+
get typeName() {
|
|
168
|
+
return UID.$typeName;
|
|
169
|
+
},
|
|
170
|
+
get fullTypeName() {
|
|
171
|
+
return composeSuiType(UID.$typeName, ...[]);
|
|
172
|
+
},
|
|
136
173
|
typeArgs: [],
|
|
137
174
|
isPhantom: UID.$isPhantom,
|
|
138
175
|
reifiedTypeArgs: [],
|
|
139
176
|
fromFields: (fields) => UID.fromFields(fields),
|
|
140
177
|
fromFieldsWithTypes: (item) => UID.fromFieldsWithTypes(item),
|
|
141
|
-
fromBcs: (data) => UID.
|
|
142
|
-
bcs:
|
|
178
|
+
fromBcs: (data) => UID.fromFields(reifiedBcs.parse(data)),
|
|
179
|
+
bcs: reifiedBcs,
|
|
143
180
|
fromJSONField: (field) => UID.fromJSONField(field),
|
|
144
181
|
fromJSON: (json) => UID.fromJSON(json),
|
|
182
|
+
fromCoreObject: (obj) => UID.fromCoreObject(obj),
|
|
145
183
|
fetch: async (client, id) => UID.fetch(client, id),
|
|
146
184
|
new: (fields) => {
|
|
147
185
|
return new UID([], fields);
|
|
148
186
|
},
|
|
149
|
-
kind:
|
|
187
|
+
kind: 'StructClassReified',
|
|
150
188
|
};
|
|
151
189
|
}
|
|
152
190
|
static get r() {
|
|
@@ -158,17 +196,26 @@ export class UID {
|
|
|
158
196
|
static get p() {
|
|
159
197
|
return UID.phantom();
|
|
160
198
|
}
|
|
161
|
-
static
|
|
162
|
-
return bcs.struct(
|
|
199
|
+
static instantiateBcs() {
|
|
200
|
+
return bcs.struct('UID', {
|
|
163
201
|
id: ID.bcs,
|
|
164
202
|
});
|
|
165
203
|
}
|
|
204
|
+
static cachedBcs = null;
|
|
205
|
+
static get bcs() {
|
|
206
|
+
if (!UID.cachedBcs) {
|
|
207
|
+
UID.cachedBcs = UID.instantiateBcs();
|
|
208
|
+
}
|
|
209
|
+
return UID.cachedBcs;
|
|
210
|
+
}
|
|
166
211
|
static fromFields(fields) {
|
|
167
|
-
return UID.reified().new({
|
|
212
|
+
return UID.reified().new({
|
|
213
|
+
id: decodeFromFields(ID.reified(), fields.id),
|
|
214
|
+
});
|
|
168
215
|
}
|
|
169
216
|
static fromFieldsWithTypes(item) {
|
|
170
217
|
if (!isUID(item.type)) {
|
|
171
|
-
throw new Error(
|
|
218
|
+
throw new Error('not a UID type');
|
|
172
219
|
}
|
|
173
220
|
return UID.reified().new({
|
|
174
221
|
id: decodeFromFieldsWithTypes(ID.reified(), item.fields.id),
|
|
@@ -183,11 +230,7 @@ export class UID {
|
|
|
183
230
|
};
|
|
184
231
|
}
|
|
185
232
|
toJSON() {
|
|
186
|
-
return {
|
|
187
|
-
$typeName: this.$typeName,
|
|
188
|
-
$typeArgs: this.$typeArgs,
|
|
189
|
-
...this.toJSONField(),
|
|
190
|
-
};
|
|
233
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
191
234
|
}
|
|
192
235
|
static fromJSONField(field) {
|
|
193
236
|
return UID.reified().new({
|
|
@@ -196,12 +239,21 @@ export class UID {
|
|
|
196
239
|
}
|
|
197
240
|
static fromJSON(json) {
|
|
198
241
|
if (json.$typeName !== UID.$typeName) {
|
|
199
|
-
throw new Error(
|
|
242
|
+
throw new Error(`not a UID json object: expected '${UID.$typeName}' but got '${json.$typeName}'`);
|
|
200
243
|
}
|
|
201
244
|
return UID.fromJSONField(json);
|
|
202
245
|
}
|
|
246
|
+
static fromCoreObject(obj) {
|
|
247
|
+
if (!isUID(obj.type)) {
|
|
248
|
+
throw new Error(`object at ${obj.objectId} is not a UID object`);
|
|
249
|
+
}
|
|
250
|
+
return UID.fromBcs(obj.content);
|
|
251
|
+
}
|
|
203
252
|
static async fetch(client, id) {
|
|
204
|
-
const { object } = await client.getObject({
|
|
253
|
+
const { object } = await client.core.getObject({
|
|
254
|
+
objectId: id,
|
|
255
|
+
include: { content: true },
|
|
256
|
+
});
|
|
205
257
|
if (!isUID(object.type)) {
|
|
206
258
|
throw new Error(`object at id ${id} is not a UID object`);
|
|
207
259
|
}
|
|
@@ -1,52 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Similar to `sui::table`, an `ObjectTable<K, V>` is a map-like collection. But unlike
|
|
3
|
+
* `sui::table`, the values bound to these dynamic fields _must_ be objects themselves. This allows
|
|
4
|
+
* for the objects to still exist within in storage, which may be important for external tools.
|
|
5
|
+
* The difference is otherwise not observable from within Move.
|
|
6
|
+
*/
|
|
7
|
+
import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
|
|
8
|
+
import { PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr } from '../../../_framework/reified';
|
|
9
|
+
import { FieldsWithTypes } from '../../../_framework/util';
|
|
10
|
+
import { UID } from '../object/structs';
|
|
6
11
|
export declare function isObjectTable(type: string): boolean;
|
|
7
12
|
export interface ObjectTableFields<K extends PhantomTypeArgument, V extends PhantomTypeArgument> {
|
|
13
|
+
/** the ID of this table */
|
|
8
14
|
id: ToField<UID>;
|
|
9
|
-
|
|
15
|
+
/** the number of key-value pairs in the table */
|
|
16
|
+
size: ToField<'u64'>;
|
|
10
17
|
}
|
|
11
18
|
export type ObjectTableReified<K extends PhantomTypeArgument, V extends PhantomTypeArgument> = Reified<ObjectTable<K, V>, ObjectTableFields<K, V>>;
|
|
19
|
+
export type ObjectTableJSONField<K extends PhantomTypeArgument, V extends PhantomTypeArgument> = {
|
|
20
|
+
id: string;
|
|
21
|
+
size: string;
|
|
22
|
+
};
|
|
23
|
+
export type ObjectTableJSON<K extends PhantomTypeArgument, V extends PhantomTypeArgument> = {
|
|
24
|
+
$typeName: typeof ObjectTable.$typeName;
|
|
25
|
+
$typeArgs: [PhantomToTypeStr<K>, PhantomToTypeStr<V>];
|
|
26
|
+
} & ObjectTableJSONField<K, V>;
|
|
12
27
|
export declare class ObjectTable<K extends PhantomTypeArgument, V extends PhantomTypeArgument> implements StructClass {
|
|
13
28
|
__StructClass: true;
|
|
14
|
-
static readonly $typeName
|
|
29
|
+
static readonly $typeName: `0x2::object_table::ObjectTable`;
|
|
15
30
|
static readonly $numTypeParams = 2;
|
|
16
31
|
static readonly $isPhantom: readonly [true, true];
|
|
17
|
-
readonly $typeName
|
|
18
|
-
readonly $fullTypeName:
|
|
32
|
+
readonly $typeName: typeof ObjectTable.$typeName;
|
|
33
|
+
readonly $fullTypeName: `0x2::object_table::ObjectTable<${PhantomToTypeStr<K>}, ${PhantomToTypeStr<V>}>`;
|
|
19
34
|
readonly $typeArgs: [PhantomToTypeStr<K>, PhantomToTypeStr<V>];
|
|
20
|
-
readonly $isPhantom:
|
|
35
|
+
readonly $isPhantom: typeof ObjectTable.$isPhantom;
|
|
36
|
+
/** the ID of this table */
|
|
21
37
|
readonly id: ToField<UID>;
|
|
22
|
-
|
|
38
|
+
/** the number of key-value pairs in the table */
|
|
39
|
+
readonly size: ToField<'u64'>;
|
|
23
40
|
private constructor();
|
|
24
41
|
static reified<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(K: K, V: V): ObjectTableReified<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
25
42
|
static get r(): typeof ObjectTable.reified;
|
|
26
43
|
static phantom<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(K: K, V: V): PhantomReified<ToTypeStr<ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>>>;
|
|
27
44
|
static get p(): typeof ObjectTable.phantom;
|
|
28
|
-
static
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
bytes: import("@mysten/bcs").BcsType<string, string, string>;
|
|
32
|
-
}, string>;
|
|
33
|
-
}, string>;
|
|
34
|
-
size: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
35
|
-
}, string>;
|
|
45
|
+
private static instantiateBcs;
|
|
46
|
+
private static cachedBcs;
|
|
47
|
+
static get bcs(): ReturnType<typeof ObjectTable.instantiateBcs>;
|
|
36
48
|
static fromFields<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], fields: Record<string, any>): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
37
49
|
static fromFieldsWithTypes<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], item: FieldsWithTypes): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
38
50
|
static fromBcs<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], data: Uint8Array): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
39
|
-
toJSONField():
|
|
40
|
-
|
|
41
|
-
size: string;
|
|
42
|
-
};
|
|
43
|
-
toJSON(): {
|
|
44
|
-
id: string;
|
|
45
|
-
size: string;
|
|
46
|
-
$typeName: string;
|
|
47
|
-
$typeArgs: [PhantomToTypeStr<K>, PhantomToTypeStr<V>];
|
|
48
|
-
};
|
|
51
|
+
toJSONField(): ObjectTableJSONField<K, V>;
|
|
52
|
+
toJSON(): ObjectTableJSON<K, V>;
|
|
49
53
|
static fromJSONField<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], field: any): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
50
54
|
static fromJSON<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], json: Record<string, any>): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
51
|
-
static
|
|
55
|
+
static fromCoreObject<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], obj: SuiClientTypes.Object<{
|
|
56
|
+
content: true;
|
|
57
|
+
}>): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
58
|
+
static fetch<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(client: ClientWithCoreApi, typeArgs: [K, V], id: string): Promise<ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>>;
|
|
52
59
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Similar to `sui::table`, an `ObjectTable<K, V>` is a map-like collection. But unlike
|
|
3
|
+
* `sui::table`, the values bound to these dynamic fields _must_ be objects themselves. This allows
|
|
4
|
+
* for the objects to still exist within in storage, which may be important for external tools.
|
|
5
|
+
* The difference is otherwise not observable from within Move.
|
|
6
|
+
*/
|
|
7
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
8
|
+
import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, } from '../../../_framework/reified.js';
|
|
9
|
+
import { composeSuiType, compressSuiType, parseTypeName, } from '../../../_framework/util.js';
|
|
10
|
+
import { UID } from '../object/structs.js';
|
|
11
|
+
/* ============================== ObjectTable =============================== */
|
|
12
|
+
export function isObjectTable(type) {
|
|
13
|
+
type = compressSuiType(type);
|
|
14
|
+
return type.startsWith(`0x2::object_table::ObjectTable` + '<');
|
|
15
|
+
}
|
|
16
|
+
export class ObjectTable {
|
|
17
|
+
__StructClass = true;
|
|
18
|
+
static $typeName = `0x2::object_table::ObjectTable`;
|
|
19
|
+
static $numTypeParams = 2;
|
|
20
|
+
static $isPhantom = [true, true];
|
|
21
|
+
$typeName = ObjectTable.$typeName;
|
|
22
|
+
$fullTypeName;
|
|
23
|
+
$typeArgs;
|
|
24
|
+
$isPhantom = ObjectTable.$isPhantom;
|
|
25
|
+
/** the ID of this table */
|
|
26
|
+
id;
|
|
27
|
+
/** the number of key-value pairs in the table */
|
|
28
|
+
size;
|
|
29
|
+
constructor(typeArgs, fields) {
|
|
30
|
+
this.$fullTypeName = composeSuiType(ObjectTable.$typeName, ...typeArgs);
|
|
31
|
+
this.$typeArgs = typeArgs;
|
|
32
|
+
this.id = fields.id;
|
|
33
|
+
this.size = fields.size;
|
|
34
|
+
}
|
|
35
|
+
static reified(K, V) {
|
|
36
|
+
const reifiedBcs = ObjectTable.bcs;
|
|
37
|
+
return {
|
|
38
|
+
get typeName() {
|
|
39
|
+
return ObjectTable.$typeName;
|
|
40
|
+
},
|
|
41
|
+
get fullTypeName() {
|
|
42
|
+
return composeSuiType(ObjectTable.$typeName, ...[extractType(K), extractType(V)]);
|
|
43
|
+
},
|
|
44
|
+
get typeArgs() {
|
|
45
|
+
return [extractType(K), extractType(V)];
|
|
46
|
+
},
|
|
47
|
+
isPhantom: ObjectTable.$isPhantom,
|
|
48
|
+
reifiedTypeArgs: [K, V],
|
|
49
|
+
fromFields: (fields) => ObjectTable.fromFields([K, V], fields),
|
|
50
|
+
fromFieldsWithTypes: (item) => ObjectTable.fromFieldsWithTypes([K, V], item),
|
|
51
|
+
fromBcs: (data) => ObjectTable.fromFields([K, V], reifiedBcs.parse(data)),
|
|
52
|
+
bcs: reifiedBcs,
|
|
53
|
+
fromJSONField: (field) => ObjectTable.fromJSONField([K, V], field),
|
|
54
|
+
fromJSON: (json) => ObjectTable.fromJSON([K, V], json),
|
|
55
|
+
fromCoreObject: (obj) => ObjectTable.fromCoreObject([K, V], obj),
|
|
56
|
+
fetch: async (client, id) => ObjectTable.fetch(client, [K, V], id),
|
|
57
|
+
new: (fields) => {
|
|
58
|
+
return new ObjectTable([extractType(K), extractType(V)], fields);
|
|
59
|
+
},
|
|
60
|
+
kind: 'StructClassReified',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
static get r() {
|
|
64
|
+
return ObjectTable.reified;
|
|
65
|
+
}
|
|
66
|
+
static phantom(K, V) {
|
|
67
|
+
return phantom(ObjectTable.reified(K, V));
|
|
68
|
+
}
|
|
69
|
+
static get p() {
|
|
70
|
+
return ObjectTable.phantom;
|
|
71
|
+
}
|
|
72
|
+
static instantiateBcs() {
|
|
73
|
+
return bcs.struct('ObjectTable', {
|
|
74
|
+
id: UID.bcs,
|
|
75
|
+
size: bcs.u64(),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
static cachedBcs = null;
|
|
79
|
+
static get bcs() {
|
|
80
|
+
if (!ObjectTable.cachedBcs) {
|
|
81
|
+
ObjectTable.cachedBcs = ObjectTable.instantiateBcs();
|
|
82
|
+
}
|
|
83
|
+
return ObjectTable.cachedBcs;
|
|
84
|
+
}
|
|
85
|
+
static fromFields(typeArgs, fields) {
|
|
86
|
+
return ObjectTable.reified(typeArgs[0], typeArgs[1]).new({
|
|
87
|
+
id: decodeFromFields(UID.reified(), fields.id),
|
|
88
|
+
size: decodeFromFields('u64', fields.size),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
static fromFieldsWithTypes(typeArgs, item) {
|
|
92
|
+
if (!isObjectTable(item.type)) {
|
|
93
|
+
throw new Error('not a ObjectTable type');
|
|
94
|
+
}
|
|
95
|
+
assertFieldsWithTypesArgsMatch(item, typeArgs);
|
|
96
|
+
return ObjectTable.reified(typeArgs[0], typeArgs[1]).new({
|
|
97
|
+
id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
|
|
98
|
+
size: decodeFromFieldsWithTypes('u64', item.fields.size),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
static fromBcs(typeArgs, data) {
|
|
102
|
+
return ObjectTable.fromFields(typeArgs, ObjectTable.bcs.parse(data));
|
|
103
|
+
}
|
|
104
|
+
toJSONField() {
|
|
105
|
+
return {
|
|
106
|
+
id: this.id,
|
|
107
|
+
size: this.size.toString(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
toJSON() {
|
|
111
|
+
return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
|
|
112
|
+
}
|
|
113
|
+
static fromJSONField(typeArgs, field) {
|
|
114
|
+
return ObjectTable.reified(typeArgs[0], typeArgs[1]).new({
|
|
115
|
+
id: decodeFromJSONField(UID.reified(), field.id),
|
|
116
|
+
size: decodeFromJSONField('u64', field.size),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
static fromJSON(typeArgs, json) {
|
|
120
|
+
if (json.$typeName !== ObjectTable.$typeName) {
|
|
121
|
+
throw new Error(`not a ObjectTable json object: expected '${ObjectTable.$typeName}' but got '${json.$typeName}'`);
|
|
122
|
+
}
|
|
123
|
+
assertReifiedTypeArgsMatch(composeSuiType(ObjectTable.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
|
|
124
|
+
return ObjectTable.fromJSONField(typeArgs, json);
|
|
125
|
+
}
|
|
126
|
+
static fromCoreObject(typeArgs, obj) {
|
|
127
|
+
if (!isObjectTable(obj.type)) {
|
|
128
|
+
throw new Error(`object at ${obj.objectId} is not a ObjectTable object`);
|
|
129
|
+
}
|
|
130
|
+
const gotTypeArgs = parseTypeName(obj.type).typeArgs;
|
|
131
|
+
if (gotTypeArgs.length !== 2) {
|
|
132
|
+
throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
|
|
133
|
+
}
|
|
134
|
+
for (let i = 0; i < 2; i++) {
|
|
135
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
136
|
+
const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
|
|
137
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
138
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return ObjectTable.fromBcs(typeArgs, obj.content);
|
|
142
|
+
}
|
|
143
|
+
static async fetch(client, typeArgs, id) {
|
|
144
|
+
const { object } = await client.core.getObject({
|
|
145
|
+
objectId: id,
|
|
146
|
+
include: { content: true },
|
|
147
|
+
});
|
|
148
|
+
if (!isObjectTable(object.type)) {
|
|
149
|
+
throw new Error(`object at id ${id} is not a ObjectTable object`);
|
|
150
|
+
}
|
|
151
|
+
const gotTypeArgs = parseTypeName(object.type).typeArgs;
|
|
152
|
+
if (gotTypeArgs.length !== 2) {
|
|
153
|
+
throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
|
|
154
|
+
}
|
|
155
|
+
for (let i = 0; i < 2; i++) {
|
|
156
|
+
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
157
|
+
const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
|
|
158
|
+
if (gotTypeArg !== expectedTypeArg) {
|
|
159
|
+
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return ObjectTable.fromBcs(typeArgs, object.content);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from './mainnet';
|
|
2
|
+
export { cloneEnv, getActiveEnv, getActiveEnvName, getDependencyConfig, getEnv, getOriginalId, getPackageConfig, getPublishedAt, getRegisteredEnvs, getTypeOrigin, getTypeOriginAddresses, getTypeOriginAddressesFor, setActiveEnv, setActiveEnvWithConfig, } from '../_framework/env';
|
|
3
|
+
export type { EnvConfig, PackageConfig } from '../_framework/env';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Re-export environment configs
|
|
2
|
+
export * from './mainnet.js';
|
|
3
|
+
// Import internal functions and env configs
|
|
4
|
+
import { registerEnv, setActiveEnv } from '../_framework/env.js';
|
|
5
|
+
import { mainnetEnv } from './mainnet.js';
|
|
6
|
+
// Applied by apply-env-guard.js after codegen; regeneration drops it.
|
|
7
|
+
if (process.env.NEXT_PUBLIC_SUILEND_USE_BETA_MARKET === 'true') {
|
|
8
|
+
throw new Error('NEXT_PUBLIC_SUILEND_USE_BETA_MARKET is set, but @suilend/sdk only targets mainnet. Unset it rather than send beta transactions to mainnet.');
|
|
9
|
+
}
|
|
10
|
+
// Initialize environments (runs once on first import)
|
|
11
|
+
let initialized = false;
|
|
12
|
+
if (!initialized) {
|
|
13
|
+
registerEnv('mainnet', mainnetEnv);
|
|
14
|
+
setActiveEnv('mainnet');
|
|
15
|
+
initialized = true;
|
|
16
|
+
}
|
|
17
|
+
// Re-export public API from _framework/env
|
|
18
|
+
export { cloneEnv, getActiveEnv, getActiveEnvName, getDependencyConfig, getEnv, getOriginalId, getPackageConfig, getPublishedAt, getRegisteredEnvs, getTypeOrigin, getTypeOriginAddresses, getTypeOriginAddressesFor, setActiveEnv, setActiveEnvWithConfig, } from '../_framework/env.js';
|