@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.
Files changed (63) hide show
  1. package/cli/src/index.d.ts +1 -0
  2. package/cli/src/index.js +304 -0
  3. package/package.json +1 -0
  4. package/sdk/src/_generated/_dependencies/source/0x1/ascii/structs.d.ts +92 -0
  5. package/sdk/src/_generated/_dependencies/source/0x1/ascii/structs.js +289 -0
  6. package/sdk/src/_generated/_dependencies/source/0x1/index.d.ts +3 -0
  7. package/sdk/src/_generated/_dependencies/source/0x1/index.js +6 -0
  8. package/sdk/src/_generated/_dependencies/source/0x1/option/structs.d.ts +52 -0
  9. package/sdk/src/_generated/_dependencies/source/0x1/option/structs.js +180 -0
  10. package/sdk/src/_generated/_dependencies/source/0x1/string/structs.d.ts +50 -0
  11. package/sdk/src/_generated/_dependencies/source/0x1/string/structs.js +167 -0
  12. package/sdk/src/_generated/_dependencies/source/0x1/type-name/structs.d.ts +53 -0
  13. package/sdk/src/_generated/_dependencies/source/0x1/type-name/structs.js +144 -0
  14. package/sdk/src/_generated/_dependencies/source/0x2/bag/structs.d.ts +61 -0
  15. package/sdk/src/_generated/_dependencies/source/0x2/bag/structs.js +149 -0
  16. package/sdk/src/_generated/_dependencies/source/0x2/balance/structs.d.ts +88 -0
  17. package/sdk/src/_generated/_dependencies/source/0x2/balance/structs.js +291 -0
  18. package/sdk/src/_generated/_dependencies/source/0x2/coin/structs.d.ts +460 -0
  19. package/sdk/src/_generated/_dependencies/source/0x2/coin/structs.js +1045 -0
  20. package/sdk/src/_generated/_dependencies/source/0x2/index.d.ts +3 -0
  21. package/sdk/src/_generated/_dependencies/source/0x2/index.js +6 -0
  22. package/sdk/src/_generated/_dependencies/source/0x2/object/structs.d.ts +92 -0
  23. package/sdk/src/_generated/_dependencies/source/0x2/object/structs.js +270 -0
  24. package/sdk/src/_generated/_dependencies/source/0x2/sui/structs.d.ts +46 -0
  25. package/sdk/src/_generated/_dependencies/source/0x2/sui/structs.js +142 -0
  26. package/sdk/src/_generated/_dependencies/source/0x2/table/structs.d.ts +61 -0
  27. package/sdk/src/_generated/_dependencies/source/0x2/table/structs.js +163 -0
  28. package/sdk/src/_generated/_dependencies/source/0x2/url/structs.d.ts +53 -0
  29. package/sdk/src/_generated/_dependencies/source/0x2/url/structs.js +143 -0
  30. package/sdk/src/_generated/_dependencies/source/0x2/vec-map/structs.d.ts +111 -0
  31. package/sdk/src/_generated/_dependencies/source/0x2/vec-map/structs.js +325 -0
  32. package/sdk/src/_generated/_dependencies/source/0x3/index.d.ts +3 -0
  33. package/sdk/src/_generated/_dependencies/source/0x3/index.js +6 -0
  34. package/sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs.d.ts +487 -0
  35. package/sdk/src/_generated/_dependencies/source/0x3/staking-pool/structs.js +915 -0
  36. package/sdk/src/_generated/_framework/reified.d.ts +108 -0
  37. package/sdk/src/_generated/_framework/reified.js +240 -0
  38. package/sdk/src/_generated/_framework/util.d.ts +35 -0
  39. package/sdk/src/_generated/_framework/util.js +334 -0
  40. package/sdk/src/_generated/_framework/vector.d.ts +35 -0
  41. package/sdk/src/_generated/_framework/vector.js +77 -0
  42. package/sdk/src/_generated/liquid_staking/cell/structs.d.ts +54 -0
  43. package/sdk/src/_generated/liquid_staking/cell/structs.js +156 -0
  44. package/sdk/src/_generated/liquid_staking/fees/functions.d.ts +51 -0
  45. package/sdk/src/_generated/liquid_staking/fees/functions.js +130 -0
  46. package/sdk/src/_generated/liquid_staking/fees/structs.d.ts +165 -0
  47. package/sdk/src/_generated/liquid_staking/fees/structs.js +307 -0
  48. package/sdk/src/_generated/liquid_staking/index.d.ts +4 -0
  49. package/sdk/src/_generated/liquid_staking/index.js +10 -0
  50. package/sdk/src/_generated/liquid_staking/liquid-staking/functions.d.ts +88 -0
  51. package/sdk/src/_generated/liquid_staking/liquid-staking/functions.js +199 -0
  52. package/sdk/src/_generated/liquid_staking/liquid-staking/structs.d.ts +955 -0
  53. package/sdk/src/_generated/liquid_staking/liquid-staking/structs.js +1477 -0
  54. package/sdk/src/_generated/liquid_staking/storage/structs.d.ts +358 -0
  55. package/sdk/src/_generated/liquid_staking/storage/structs.js +365 -0
  56. package/sdk/src/_generated/liquid_staking/version/structs.d.ts +46 -0
  57. package/sdk/src/_generated/liquid_staking/version/structs.js +143 -0
  58. package/sdk/src/_generated/liquid_staking/weight/functions.d.ts +19 -0
  59. package/sdk/src/_generated/liquid_staking/weight/functions.js +44 -0
  60. package/sdk/src/_generated/liquid_staking/weight/structs.d.ts +205 -0
  61. package/sdk/src/_generated/liquid_staking/weight/structs.js +332 -0
  62. package/sdk/src/index.d.ts +44 -0
  63. package/sdk/src/index.js +234 -0
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.String = exports.Char = void 0;
36
+ exports.isChar = isChar;
37
+ exports.isString = isString;
38
+ const reified = __importStar(require("../../../../_framework/reified"));
39
+ const reified_1 = require("../../../../_framework/reified");
40
+ const util_1 = require("../../../../_framework/util");
41
+ const index_1 = require("../index");
42
+ const bcs_1 = require("@mysten/sui/bcs");
43
+ const utils_1 = require("@mysten/sui/utils");
44
+ /* ============================== Char =============================== */
45
+ function isChar(type) {
46
+ type = (0, util_1.compressSuiType)(type);
47
+ return type === `${index_1.PKG_V10}::ascii::Char`;
48
+ }
49
+ class Char {
50
+ constructor(typeArgs, fields) {
51
+ this.__StructClass = true;
52
+ this.$typeName = Char.$typeName;
53
+ this.$isPhantom = Char.$isPhantom;
54
+ this.$fullTypeName = (0, util_1.composeSuiType)(Char.$typeName, ...typeArgs);
55
+ this.$typeArgs = typeArgs;
56
+ this.byte = fields.byte;
57
+ }
58
+ static reified() {
59
+ return {
60
+ typeName: Char.$typeName,
61
+ fullTypeName: (0, util_1.composeSuiType)(Char.$typeName, ...[]),
62
+ typeArgs: [],
63
+ isPhantom: Char.$isPhantom,
64
+ reifiedTypeArgs: [],
65
+ fromFields: (fields) => Char.fromFields(fields),
66
+ fromFieldsWithTypes: (item) => Char.fromFieldsWithTypes(item),
67
+ fromBcs: (data) => Char.fromBcs(data),
68
+ bcs: Char.bcs,
69
+ fromJSONField: (field) => Char.fromJSONField(field),
70
+ fromJSON: (json) => Char.fromJSON(json),
71
+ fromSuiParsedData: (content) => Char.fromSuiParsedData(content),
72
+ fromSuiObjectData: (content) => Char.fromSuiObjectData(content),
73
+ fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Char.fetch(client, id); }),
74
+ new: (fields) => {
75
+ return new Char([], fields);
76
+ },
77
+ kind: "StructClassReified",
78
+ };
79
+ }
80
+ static get r() {
81
+ return Char.reified();
82
+ }
83
+ static phantom() {
84
+ return (0, reified_1.phantom)(Char.reified());
85
+ }
86
+ static get p() {
87
+ return Char.phantom();
88
+ }
89
+ static get bcs() {
90
+ return bcs_1.bcs.struct("Char", {
91
+ byte: bcs_1.bcs.u8(),
92
+ });
93
+ }
94
+ static fromFields(fields) {
95
+ return Char.reified().new({ byte: (0, reified_1.decodeFromFields)("u8", fields.byte) });
96
+ }
97
+ static fromFieldsWithTypes(item) {
98
+ if (!isChar(item.type)) {
99
+ throw new Error("not a Char type");
100
+ }
101
+ return Char.reified().new({
102
+ byte: (0, reified_1.decodeFromFieldsWithTypes)("u8", item.fields.byte),
103
+ });
104
+ }
105
+ static fromBcs(data) {
106
+ return Char.fromFields(Char.bcs.parse(data));
107
+ }
108
+ toJSONField() {
109
+ return {
110
+ byte: this.byte,
111
+ };
112
+ }
113
+ toJSON() {
114
+ return Object.assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
115
+ }
116
+ static fromJSONField(field) {
117
+ return Char.reified().new({ byte: (0, reified_1.decodeFromJSONField)("u8", field.byte) });
118
+ }
119
+ static fromJSON(json) {
120
+ if (json.$typeName !== Char.$typeName) {
121
+ throw new Error("not a WithTwoGenerics json object");
122
+ }
123
+ return Char.fromJSONField(json);
124
+ }
125
+ static fromSuiParsedData(content) {
126
+ if (content.dataType !== "moveObject") {
127
+ throw new Error("not an object");
128
+ }
129
+ if (!isChar(content.type)) {
130
+ throw new Error(`object at ${content.fields.id} is not a Char object`);
131
+ }
132
+ return Char.fromFieldsWithTypes(content);
133
+ }
134
+ static fromSuiObjectData(data) {
135
+ if (data.bcs) {
136
+ if (data.bcs.dataType !== "moveObject" || !isChar(data.bcs.type)) {
137
+ throw new Error(`object at is not a Char object`);
138
+ }
139
+ return Char.fromBcs((0, utils_1.fromB64)(data.bcs.bcsBytes));
140
+ }
141
+ if (data.content) {
142
+ return Char.fromSuiParsedData(data.content);
143
+ }
144
+ throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
145
+ }
146
+ static fetch(client, id) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ var _a, _b;
149
+ const res = yield client.getObject({ id, options: { showBcs: true } });
150
+ if (res.error) {
151
+ throw new Error(`error fetching Char object at id ${id}: ${res.error.code}`);
152
+ }
153
+ if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
154
+ !isChar(res.data.bcs.type)) {
155
+ throw new Error(`object at id ${id} is not a Char object`);
156
+ }
157
+ return Char.fromSuiObjectData(res.data);
158
+ });
159
+ }
160
+ }
161
+ exports.Char = Char;
162
+ Char.$typeName = `${index_1.PKG_V10}::ascii::Char`;
163
+ Char.$numTypeParams = 0;
164
+ Char.$isPhantom = [];
165
+ /* ============================== String =============================== */
166
+ function isString(type) {
167
+ type = (0, util_1.compressSuiType)(type);
168
+ return type === `${index_1.PKG_V10}::ascii::String`;
169
+ }
170
+ class String {
171
+ constructor(typeArgs, fields) {
172
+ this.__StructClass = true;
173
+ this.$typeName = String.$typeName;
174
+ this.$isPhantom = String.$isPhantom;
175
+ this.$fullTypeName = (0, util_1.composeSuiType)(String.$typeName, ...typeArgs);
176
+ this.$typeArgs = typeArgs;
177
+ this.bytes = fields.bytes;
178
+ }
179
+ static reified() {
180
+ return {
181
+ typeName: String.$typeName,
182
+ fullTypeName: (0, util_1.composeSuiType)(String.$typeName, ...[]),
183
+ typeArgs: [],
184
+ isPhantom: String.$isPhantom,
185
+ reifiedTypeArgs: [],
186
+ fromFields: (fields) => String.fromFields(fields),
187
+ fromFieldsWithTypes: (item) => String.fromFieldsWithTypes(item),
188
+ fromBcs: (data) => String.fromBcs(data),
189
+ bcs: String.bcs,
190
+ fromJSONField: (field) => String.fromJSONField(field),
191
+ fromJSON: (json) => String.fromJSON(json),
192
+ fromSuiParsedData: (content) => String.fromSuiParsedData(content),
193
+ fromSuiObjectData: (content) => String.fromSuiObjectData(content),
194
+ fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return String.fetch(client, id); }),
195
+ new: (fields) => {
196
+ return new String([], fields);
197
+ },
198
+ kind: "StructClassReified",
199
+ };
200
+ }
201
+ static get r() {
202
+ return String.reified();
203
+ }
204
+ static phantom() {
205
+ return (0, reified_1.phantom)(String.reified());
206
+ }
207
+ static get p() {
208
+ return String.phantom();
209
+ }
210
+ static get bcs() {
211
+ return bcs_1.bcs.struct("String", {
212
+ bytes: bcs_1.bcs.vector(bcs_1.bcs.u8()),
213
+ });
214
+ }
215
+ static fromFields(fields) {
216
+ return String.reified().new({
217
+ bytes: (0, reified_1.decodeFromFields)(reified.vector("u8"), fields.bytes),
218
+ });
219
+ }
220
+ static fromFieldsWithTypes(item) {
221
+ if (!isString(item.type)) {
222
+ throw new Error("not a String type");
223
+ }
224
+ return String.reified().new({
225
+ bytes: (0, reified_1.decodeFromFieldsWithTypes)(reified.vector("u8"), item.fields.bytes),
226
+ });
227
+ }
228
+ static fromBcs(data) {
229
+ return String.fromFields(String.bcs.parse(data));
230
+ }
231
+ toJSONField() {
232
+ return {
233
+ bytes: (0, reified_1.fieldToJSON)(`vector<u8>`, this.bytes),
234
+ };
235
+ }
236
+ toJSON() {
237
+ return Object.assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
238
+ }
239
+ static fromJSONField(field) {
240
+ return String.reified().new({
241
+ bytes: (0, reified_1.decodeFromJSONField)(reified.vector("u8"), field.bytes),
242
+ });
243
+ }
244
+ static fromJSON(json) {
245
+ if (json.$typeName !== String.$typeName) {
246
+ throw new Error("not a WithTwoGenerics json object");
247
+ }
248
+ return String.fromJSONField(json);
249
+ }
250
+ static fromSuiParsedData(content) {
251
+ if (content.dataType !== "moveObject") {
252
+ throw new Error("not an object");
253
+ }
254
+ if (!isString(content.type)) {
255
+ throw new Error(`object at ${content.fields.id} is not a String object`);
256
+ }
257
+ return String.fromFieldsWithTypes(content);
258
+ }
259
+ static fromSuiObjectData(data) {
260
+ if (data.bcs) {
261
+ if (data.bcs.dataType !== "moveObject" || !isString(data.bcs.type)) {
262
+ throw new Error(`object at is not a String object`);
263
+ }
264
+ return String.fromBcs((0, utils_1.fromB64)(data.bcs.bcsBytes));
265
+ }
266
+ if (data.content) {
267
+ return String.fromSuiParsedData(data.content);
268
+ }
269
+ throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
270
+ }
271
+ static fetch(client, id) {
272
+ return __awaiter(this, void 0, void 0, function* () {
273
+ var _a, _b;
274
+ const res = yield client.getObject({ id, options: { showBcs: true } });
275
+ if (res.error) {
276
+ throw new Error(`error fetching String object at id ${id}: ${res.error.code}`);
277
+ }
278
+ if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
279
+ !isString(res.data.bcs.type)) {
280
+ throw new Error(`object at id ${id} is not a String object`);
281
+ }
282
+ return String.fromSuiObjectData(res.data);
283
+ });
284
+ }
285
+ }
286
+ exports.String = String;
287
+ String.$typeName = `${index_1.PKG_V10}::ascii::String`;
288
+ String.$numTypeParams = 0;
289
+ String.$isPhantom = [];
@@ -0,0 +1,3 @@
1
+ export declare const PACKAGE_ID = "0x1";
2
+ export declare const PUBLISHED_AT = "0x1";
3
+ export declare const PKG_V10 = "0x1";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PKG_V10 = exports.PUBLISHED_AT = exports.PACKAGE_ID = void 0;
4
+ exports.PACKAGE_ID = "0x1";
5
+ exports.PUBLISHED_AT = "0x1";
6
+ exports.PKG_V10 = "0x1";
@@ -0,0 +1,52 @@
1
+ import * as reified from "../../../../_framework/reified";
2
+ import { PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument } from "../../../../_framework/reified";
3
+ import { FieldsWithTypes } from "../../../../_framework/util";
4
+ import { Vector } from "../../../../_framework/vector";
5
+ import { PKG_V10 } from "../index";
6
+ import { BcsType } from "@mysten/sui/bcs";
7
+ import { SuiClient, SuiObjectData, SuiParsedData } from "@mysten/sui/client";
8
+ export declare function isOption(type: string): boolean;
9
+ export interface OptionFields<Element extends TypeArgument> {
10
+ vec: ToField<Vector<Element>>;
11
+ }
12
+ export type OptionReified<Element extends TypeArgument> = Reified<Option<Element>, OptionFields<Element>>;
13
+ export declare class Option<Element extends TypeArgument> implements StructClass {
14
+ __StructClass: true;
15
+ static readonly $typeName = "0x1::option::Option";
16
+ static readonly $numTypeParams = 1;
17
+ static readonly $isPhantom: readonly [false];
18
+ __inner: Element;
19
+ readonly $typeName = "0x1::option::Option";
20
+ readonly $fullTypeName: `${typeof PKG_V10}::option::Option<${ToTypeStr<Element>}>`;
21
+ readonly $typeArgs: [ToTypeStr<Element>];
22
+ readonly $isPhantom: readonly [false];
23
+ readonly vec: ToField<Vector<Element>>;
24
+ private constructor();
25
+ static reified<Element extends Reified<TypeArgument, any>>(Element: Element): OptionReified<ToTypeArgument<Element>>;
26
+ static get r(): typeof Option.reified;
27
+ static phantom<Element extends Reified<TypeArgument, any>>(Element: Element): PhantomReified<ToTypeStr<Option<ToTypeArgument<Element>>>>;
28
+ static get p(): typeof Option.phantom;
29
+ static get bcs(): <Element extends BcsType<any>>(Element: Element) => BcsType<{
30
+ vec: any[];
31
+ }, {
32
+ vec: Iterable<any> & {
33
+ length: number;
34
+ };
35
+ }>;
36
+ static fromFields<Element extends Reified<TypeArgument, any>>(typeArg: Element, fields: Record<string, any>): Option<ToTypeArgument<Element>>;
37
+ static fromFieldsWithTypes<Element extends Reified<TypeArgument, any>>(typeArg: Element, item: FieldsWithTypes): Option<ToTypeArgument<Element>>;
38
+ static fromBcs<Element extends Reified<TypeArgument, any>>(typeArg: Element, data: Uint8Array): Option<ToTypeArgument<Element>>;
39
+ toJSONField(): {
40
+ vec: reified.ToJSON<Element>[];
41
+ };
42
+ toJSON(): {
43
+ vec: reified.ToJSON<Element>[];
44
+ $typeName: string;
45
+ $typeArgs: [reified.ToTypeStr<Element>];
46
+ };
47
+ static fromJSONField<Element extends Reified<TypeArgument, any>>(typeArg: Element, field: any): Option<ToTypeArgument<Element>>;
48
+ static fromJSON<Element extends Reified<TypeArgument, any>>(typeArg: Element, json: Record<string, any>): Option<ToTypeArgument<Element>>;
49
+ static fromSuiParsedData<Element extends Reified<TypeArgument, any>>(typeArg: Element, content: SuiParsedData): Option<ToTypeArgument<Element>>;
50
+ static fromSuiObjectData<Element extends Reified<TypeArgument, any>>(typeArg: Element, data: SuiObjectData): Option<ToTypeArgument<Element>>;
51
+ static fetch<Element extends Reified<TypeArgument, any>>(client: SuiClient, typeArg: Element, id: string): Promise<Option<ToTypeArgument<Element>>>;
52
+ }
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.Option = void 0;
36
+ exports.isOption = isOption;
37
+ const reified = __importStar(require("../../../../_framework/reified"));
38
+ const reified_1 = require("../../../../_framework/reified");
39
+ const util_1 = require("../../../../_framework/util");
40
+ const index_1 = require("../index");
41
+ const bcs_1 = require("@mysten/sui/bcs");
42
+ const utils_1 = require("@mysten/sui/utils");
43
+ /* ============================== Option =============================== */
44
+ function isOption(type) {
45
+ type = (0, util_1.compressSuiType)(type);
46
+ return type.startsWith(`${index_1.PKG_V10}::option::Option` + "<");
47
+ }
48
+ class Option {
49
+ constructor(typeArgs, fields) {
50
+ this.__StructClass = true;
51
+ this.__inner = null; // for type checking in reified.ts
52
+ this.$typeName = Option.$typeName;
53
+ this.$isPhantom = Option.$isPhantom;
54
+ this.$fullTypeName = (0, util_1.composeSuiType)(Option.$typeName, ...typeArgs);
55
+ this.$typeArgs = typeArgs;
56
+ this.vec = fields.vec;
57
+ }
58
+ static reified(Element) {
59
+ return {
60
+ typeName: Option.$typeName,
61
+ fullTypeName: (0, util_1.composeSuiType)(Option.$typeName, ...[(0, reified_1.extractType)(Element)]),
62
+ typeArgs: [(0, reified_1.extractType)(Element)],
63
+ isPhantom: Option.$isPhantom,
64
+ reifiedTypeArgs: [Element],
65
+ fromFields: (fields) => Option.fromFields(Element, fields),
66
+ fromFieldsWithTypes: (item) => Option.fromFieldsWithTypes(Element, item),
67
+ fromBcs: (data) => Option.fromBcs(Element, data),
68
+ bcs: Option.bcs((0, reified_1.toBcs)(Element)),
69
+ fromJSONField: (field) => Option.fromJSONField(Element, field),
70
+ fromJSON: (json) => Option.fromJSON(Element, json),
71
+ fromSuiParsedData: (content) => Option.fromSuiParsedData(Element, content),
72
+ fromSuiObjectData: (content) => Option.fromSuiObjectData(Element, content),
73
+ fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Option.fetch(client, Element, id); }),
74
+ new: (fields) => {
75
+ return new Option([(0, reified_1.extractType)(Element)], fields);
76
+ },
77
+ kind: "StructClassReified",
78
+ };
79
+ }
80
+ static get r() {
81
+ return Option.reified;
82
+ }
83
+ static phantom(Element) {
84
+ return (0, reified_1.phantom)(Option.reified(Element));
85
+ }
86
+ static get p() {
87
+ return Option.phantom;
88
+ }
89
+ static get bcs() {
90
+ return (Element) => bcs_1.bcs.struct(`Option<${Element.name}>`, {
91
+ vec: bcs_1.bcs.vector(Element),
92
+ });
93
+ }
94
+ static fromFields(typeArg, fields) {
95
+ return Option.reified(typeArg).new({
96
+ vec: (0, reified_1.decodeFromFields)(reified.vector(typeArg), fields.vec),
97
+ });
98
+ }
99
+ static fromFieldsWithTypes(typeArg, item) {
100
+ if (!isOption(item.type)) {
101
+ throw new Error("not a Option type");
102
+ }
103
+ (0, reified_1.assertFieldsWithTypesArgsMatch)(item, [typeArg]);
104
+ return Option.reified(typeArg).new({
105
+ vec: (0, reified_1.decodeFromFieldsWithTypes)(reified.vector(typeArg), item.fields.vec),
106
+ });
107
+ }
108
+ static fromBcs(typeArg, data) {
109
+ const typeArgs = [typeArg];
110
+ return Option.fromFields(typeArg, Option.bcs((0, reified_1.toBcs)(typeArgs[0])).parse(data));
111
+ }
112
+ toJSONField() {
113
+ return {
114
+ vec: (0, reified_1.fieldToJSON)(`vector<${this.$typeArgs[0]}>`, this.vec),
115
+ };
116
+ }
117
+ toJSON() {
118
+ return Object.assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
119
+ }
120
+ static fromJSONField(typeArg, field) {
121
+ return Option.reified(typeArg).new({
122
+ vec: (0, reified_1.decodeFromJSONField)(reified.vector(typeArg), field.vec),
123
+ });
124
+ }
125
+ static fromJSON(typeArg, json) {
126
+ if (json.$typeName !== Option.$typeName) {
127
+ throw new Error("not a WithTwoGenerics json object");
128
+ }
129
+ (0, reified_1.assertReifiedTypeArgsMatch)((0, util_1.composeSuiType)(Option.$typeName, (0, reified_1.extractType)(typeArg)), json.$typeArgs, [typeArg]);
130
+ return Option.fromJSONField(typeArg, json);
131
+ }
132
+ static fromSuiParsedData(typeArg, content) {
133
+ if (content.dataType !== "moveObject") {
134
+ throw new Error("not an object");
135
+ }
136
+ if (!isOption(content.type)) {
137
+ throw new Error(`object at ${content.fields.id} is not a Option object`);
138
+ }
139
+ return Option.fromFieldsWithTypes(typeArg, content);
140
+ }
141
+ static fromSuiObjectData(typeArg, data) {
142
+ if (data.bcs) {
143
+ if (data.bcs.dataType !== "moveObject" || !isOption(data.bcs.type)) {
144
+ throw new Error(`object at is not a Option object`);
145
+ }
146
+ const gotTypeArgs = (0, util_1.parseTypeName)(data.bcs.type).typeArgs;
147
+ if (gotTypeArgs.length !== 1) {
148
+ throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`);
149
+ }
150
+ const gotTypeArg = (0, util_1.compressSuiType)(gotTypeArgs[0]);
151
+ const expectedTypeArg = (0, util_1.compressSuiType)((0, reified_1.extractType)(typeArg));
152
+ if (gotTypeArg !== (0, util_1.compressSuiType)((0, reified_1.extractType)(typeArg))) {
153
+ throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
154
+ }
155
+ return Option.fromBcs(typeArg, (0, utils_1.fromB64)(data.bcs.bcsBytes));
156
+ }
157
+ if (data.content) {
158
+ return Option.fromSuiParsedData(typeArg, data.content);
159
+ }
160
+ throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
161
+ }
162
+ static fetch(client, typeArg, id) {
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ var _a, _b;
165
+ const res = yield client.getObject({ id, options: { showBcs: true } });
166
+ if (res.error) {
167
+ throw new Error(`error fetching Option object at id ${id}: ${res.error.code}`);
168
+ }
169
+ if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
170
+ !isOption(res.data.bcs.type)) {
171
+ throw new Error(`object at id ${id} is not a Option object`);
172
+ }
173
+ return Option.fromSuiObjectData(typeArg, res.data);
174
+ });
175
+ }
176
+ }
177
+ exports.Option = Option;
178
+ Option.$typeName = `${index_1.PKG_V10}::option::Option`;
179
+ Option.$numTypeParams = 1;
180
+ Option.$isPhantom = [false];
@@ -0,0 +1,50 @@
1
+ import * as reified from "../../../../_framework/reified";
2
+ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
3
+ import { FieldsWithTypes } from "../../../../_framework/util";
4
+ import { Vector } from "../../../../_framework/vector";
5
+ import { PKG_V10 } from "../index";
6
+ import { SuiClient, SuiObjectData, SuiParsedData } from "@mysten/sui/client";
7
+ export declare function isString(type: string): boolean;
8
+ export interface StringFields {
9
+ bytes: ToField<Vector<"u8">>;
10
+ }
11
+ export type StringReified = Reified<String, StringFields>;
12
+ export declare class String implements StructClass {
13
+ __StructClass: true;
14
+ static readonly $typeName = "0x1::string::String";
15
+ static readonly $numTypeParams = 0;
16
+ static readonly $isPhantom: readonly [];
17
+ readonly $typeName = "0x1::string::String";
18
+ readonly $fullTypeName: `${typeof PKG_V10}::string::String`;
19
+ readonly $typeArgs: [];
20
+ readonly $isPhantom: readonly [];
21
+ readonly bytes: ToField<Vector<"u8">>;
22
+ private constructor();
23
+ static reified(): StringReified;
24
+ static get r(): reified.StructClassReified<String, StringFields>;
25
+ static phantom(): PhantomReified<ToTypeStr<String>>;
26
+ static get p(): reified.PhantomReified<"0x1::string::String">;
27
+ static get bcs(): import("@mysten/sui/bcs").BcsType<{
28
+ bytes: number[];
29
+ }, {
30
+ bytes: Iterable<number> & {
31
+ length: number;
32
+ };
33
+ }>;
34
+ static fromFields(fields: Record<string, any>): String;
35
+ static fromFieldsWithTypes(item: FieldsWithTypes): String;
36
+ static fromBcs(data: Uint8Array): String;
37
+ toJSONField(): {
38
+ bytes: number[];
39
+ };
40
+ toJSON(): {
41
+ bytes: number[];
42
+ $typeName: string;
43
+ $typeArgs: [];
44
+ };
45
+ static fromJSONField(field: any): String;
46
+ static fromJSON(json: Record<string, any>): String;
47
+ static fromSuiParsedData(content: SuiParsedData): String;
48
+ static fromSuiObjectData(data: SuiObjectData): String;
49
+ static fetch(client: SuiClient, id: string): Promise<String>;
50
+ }