@suilend/sdk 12.7.0 → 13.0.0-next.g122801a

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 (86) hide show
  1. package/_generated/_dependencies/pyth-2/price-identifier/structs.d.ts +46 -0
  2. package/_generated/_dependencies/{source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e → pyth-2}/price-identifier/structs.js +45 -25
  3. package/_generated/_dependencies/std/ascii/structs.d.ts +100 -0
  4. package/_generated/_dependencies/{source/0x1 → std}/ascii/structs.js +153 -103
  5. package/_generated/_dependencies/{source/0x1 → std}/option/structs.d.ts +29 -21
  6. package/_generated/_dependencies/std/option/structs.js +155 -0
  7. package/_generated/_dependencies/std/type-name/structs.d.ts +65 -0
  8. package/_generated/_dependencies/{source/0x1 → std}/type-name/structs.js +49 -22
  9. package/_generated/_dependencies/sui/bag/structs.d.ts +75 -0
  10. package/_generated/_dependencies/sui/bag/structs.js +154 -0
  11. package/_generated/_dependencies/{source/0x2 → sui}/balance/structs.d.ts +80 -60
  12. package/_generated/_dependencies/sui/balance/structs.js +306 -0
  13. package/_generated/_dependencies/sui/object/structs.d.ts +104 -0
  14. package/_generated/_dependencies/{source/0x2 → sui}/object/structs.js +98 -46
  15. package/_generated/_dependencies/{source/0x2 → sui}/object-table/structs.d.ts +37 -30
  16. package/_generated/_dependencies/sui/object-table/structs.js +164 -0
  17. package/_generated/_envs/index.d.ts +3 -0
  18. package/_generated/_envs/index.js +18 -0
  19. package/_generated/_envs/mainnet.d.ts +2 -0
  20. package/_generated/_envs/mainnet.js +490 -0
  21. package/_generated/_framework/env.d.ts +137 -0
  22. package/_generated/_framework/env.js +261 -0
  23. package/_generated/_framework/reified.d.ts +68 -36
  24. package/_generated/_framework/reified.js +110 -98
  25. package/_generated/_framework/util.d.ts +4 -4
  26. package/_generated/_framework/util.js +82 -79
  27. package/_generated/_framework/vector.d.ts +11 -9
  28. package/_generated/_framework/vector.js +10 -10
  29. package/_generated/suilend/cell/structs.d.ts +24 -22
  30. package/_generated/suilend/cell/structs.js +68 -24
  31. package/_generated/suilend/decimal/structs.d.ts +28 -24
  32. package/_generated/suilend/decimal/structs.js +45 -24
  33. package/_generated/suilend/index.d.ts +5 -6
  34. package/_generated/suilend/index.js +10 -19
  35. package/_generated/suilend/lending-market/functions.d.ts +1123 -149
  36. package/_generated/suilend/lending-market/functions.js +1121 -207
  37. package/_generated/suilend/lending-market/structs.d.ts +985 -1290
  38. package/_generated/suilend/lending-market/structs.js +2482 -1282
  39. package/_generated/suilend/lending-market-registry/functions.d.ts +32 -3
  40. package/_generated/suilend/lending-market-registry/functions.js +30 -6
  41. package/_generated/suilend/liquidity-mining/structs.d.ts +200 -333
  42. package/_generated/suilend/liquidity-mining/structs.js +449 -319
  43. package/_generated/suilend/obligation/structs.d.ts +406 -918
  44. package/_generated/suilend/obligation/structs.js +786 -596
  45. package/_generated/suilend/rate-limiter/functions.d.ts +134 -15
  46. package/_generated/suilend/rate-limiter/functions.js +139 -21
  47. package/_generated/suilend/rate-limiter/structs.d.ts +72 -80
  48. package/_generated/suilend/rate-limiter/structs.js +98 -48
  49. package/_generated/suilend/reserve/structs.d.ts +611 -904
  50. package/_generated/suilend/reserve/structs.js +1528 -736
  51. package/_generated/suilend/reserve-config/functions.d.ts +718 -96
  52. package/_generated/suilend/reserve-config/functions.js +751 -157
  53. package/_generated/suilend/reserve-config/structs.d.ts +148 -163
  54. package/_generated/suilend/reserve-config/structs.js +260 -94
  55. package/client.d.ts +2 -2
  56. package/client.js +22 -39
  57. package/lib/initialize.d.ts +617 -83
  58. package/lib/initialize.js +151 -48
  59. package/lib/proCompatible.js +5 -5
  60. package/package.json +1 -1
  61. package/parsers/lendingMarket.d.ts +9 -9
  62. package/parsers/obligation.d.ts +14 -14
  63. package/parsers/obligation.js +4 -4
  64. package/parsers/rateLimiter.d.ts +1 -1
  65. package/parsers/reserve.d.ts +12 -12
  66. package/parsers/reserve.js +2 -2
  67. package/strategies.d.ts +14 -14
  68. package/utils/obligation.d.ts +3 -0
  69. package/utils/obligation.js +10 -0
  70. package/utils/simulate.d.ts +1 -1
  71. package/utils/simulate.js +5 -5
  72. package/_generated/_dependencies/source/0x1/ascii/structs.d.ts +0 -84
  73. package/_generated/_dependencies/source/0x1/index.d.ts +0 -3
  74. package/_generated/_dependencies/source/0x1/index.js +0 -3
  75. package/_generated/_dependencies/source/0x1/option/structs.js +0 -110
  76. package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +0 -47
  77. package/_generated/_dependencies/source/0x2/bag/structs.d.ts +0 -52
  78. package/_generated/_dependencies/source/0x2/bag/structs.js +0 -113
  79. package/_generated/_dependencies/source/0x2/balance/structs.js +0 -210
  80. package/_generated/_dependencies/source/0x2/index.d.ts +0 -3
  81. package/_generated/_dependencies/source/0x2/index.js +0 -3
  82. package/_generated/_dependencies/source/0x2/object/structs.d.ts +0 -82
  83. package/_generated/_dependencies/source/0x2/object-table/structs.js +0 -115
  84. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.d.ts +0 -4
  85. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +0 -4
  86. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +0 -46
@@ -0,0 +1,46 @@
1
+ import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
2
+ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from '../../../_framework/reified';
3
+ import { FieldsWithTypes } from '../../../_framework/util';
4
+ import { Vector } from '../../../_framework/vector';
5
+ export declare function isPriceIdentifier(type: string): boolean;
6
+ export interface PriceIdentifierFields {
7
+ bytes: ToField<Vector<'u8'>>;
8
+ }
9
+ export type PriceIdentifierReified = Reified<PriceIdentifier, PriceIdentifierFields>;
10
+ export type PriceIdentifierJSONField = {
11
+ bytes: number[];
12
+ };
13
+ export type PriceIdentifierJSON = {
14
+ $typeName: typeof PriceIdentifier.$typeName;
15
+ $typeArgs: [];
16
+ } & PriceIdentifierJSONField;
17
+ export declare class PriceIdentifier implements StructClass {
18
+ __StructClass: true;
19
+ static get $typeName(): `${string}::price_identifier::PriceIdentifier`;
20
+ static readonly $numTypeParams = 0;
21
+ static readonly $isPhantom: readonly [];
22
+ readonly $typeName: typeof PriceIdentifier.$typeName;
23
+ readonly $fullTypeName: `${string}::price_identifier::PriceIdentifier`;
24
+ readonly $typeArgs: [];
25
+ readonly $isPhantom: typeof PriceIdentifier.$isPhantom;
26
+ readonly bytes: ToField<Vector<'u8'>>;
27
+ private constructor();
28
+ static reified(): PriceIdentifierReified;
29
+ static get r(): PriceIdentifierReified;
30
+ static phantom(): PhantomReified<ToTypeStr<PriceIdentifier>>;
31
+ static get p(): PhantomReified<ToTypeStr<PriceIdentifier>>;
32
+ private static instantiateBcs;
33
+ private static cachedBcs;
34
+ static get bcs(): ReturnType<typeof PriceIdentifier.instantiateBcs>;
35
+ static fromFields(fields: Record<string, any>): PriceIdentifier;
36
+ static fromFieldsWithTypes(item: FieldsWithTypes): PriceIdentifier;
37
+ static fromBcs(data: Uint8Array): PriceIdentifier;
38
+ toJSONField(): PriceIdentifierJSONField;
39
+ toJSON(): PriceIdentifierJSON;
40
+ static fromJSONField(field: any): PriceIdentifier;
41
+ static fromJSON(json: Record<string, any>): PriceIdentifier;
42
+ static fromCoreObject(obj: SuiClientTypes.Object<{
43
+ content: true;
44
+ }>): PriceIdentifier;
45
+ static fetch(client: ClientWithCoreApi, id: string): Promise<PriceIdentifier>;
46
+ }
@@ -1,16 +1,18 @@
1
- import * as reified from "../../../../_framework/reified.js";
2
- import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom, } from "../../../../_framework/reified.js";
3
- import { composeSuiType, compressSuiType, } from "../../../../_framework/util.js";
4
- import { PKG_V1 } from "../index.js";
5
- import { bcs } from "@mysten/sui/bcs";
1
+ import { bcs } from '@mysten/sui/bcs';
2
+ import { getTypeOrigin } from '../../../_envs/index.js';
3
+ import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom, vector, } from '../../../_framework/reified.js';
4
+ import { composeSuiType, compressSuiType } from '../../../_framework/util.js';
6
5
  /* ============================== PriceIdentifier =============================== */
7
6
  export function isPriceIdentifier(type) {
8
7
  type = compressSuiType(type);
9
- return type === `${PKG_V1}::price_identifier::PriceIdentifier`;
8
+ return type
9
+ === `${getTypeOrigin('pyth-2', 'price_identifier::PriceIdentifier')}::price_identifier::PriceIdentifier`;
10
10
  }
11
11
  export class PriceIdentifier {
12
12
  __StructClass = true;
13
- static $typeName = `${PKG_V1}::price_identifier::PriceIdentifier`;
13
+ static get $typeName() {
14
+ return `${getTypeOrigin('pyth-2', 'price_identifier::PriceIdentifier')}::price_identifier::PriceIdentifier`;
15
+ }
14
16
  static $numTypeParams = 0;
15
17
  static $isPhantom = [];
16
18
  $typeName = PriceIdentifier.$typeName;
@@ -24,23 +26,29 @@ export class PriceIdentifier {
24
26
  this.bytes = fields.bytes;
25
27
  }
26
28
  static reified() {
29
+ const reifiedBcs = PriceIdentifier.bcs;
27
30
  return {
28
- typeName: PriceIdentifier.$typeName,
29
- fullTypeName: composeSuiType(PriceIdentifier.$typeName, ...[]),
31
+ get typeName() {
32
+ return PriceIdentifier.$typeName;
33
+ },
34
+ get fullTypeName() {
35
+ return composeSuiType(PriceIdentifier.$typeName, ...[]);
36
+ },
30
37
  typeArgs: [],
31
38
  isPhantom: PriceIdentifier.$isPhantom,
32
39
  reifiedTypeArgs: [],
33
40
  fromFields: (fields) => PriceIdentifier.fromFields(fields),
34
41
  fromFieldsWithTypes: (item) => PriceIdentifier.fromFieldsWithTypes(item),
35
- fromBcs: (data) => PriceIdentifier.fromBcs(data),
36
- bcs: PriceIdentifier.bcs,
42
+ fromBcs: (data) => PriceIdentifier.fromFields(reifiedBcs.parse(data)),
43
+ bcs: reifiedBcs,
37
44
  fromJSONField: (field) => PriceIdentifier.fromJSONField(field),
38
45
  fromJSON: (json) => PriceIdentifier.fromJSON(json),
46
+ fromCoreObject: (obj) => PriceIdentifier.fromCoreObject(obj),
39
47
  fetch: async (client, id) => PriceIdentifier.fetch(client, id),
40
48
  new: (fields) => {
41
49
  return new PriceIdentifier([], fields);
42
50
  },
43
- kind: "StructClassReified",
51
+ kind: 'StructClassReified',
44
52
  };
45
53
  }
46
54
  static get r() {
@@ -52,22 +60,29 @@ export class PriceIdentifier {
52
60
  static get p() {
53
61
  return PriceIdentifier.phantom();
54
62
  }
55
- static get bcs() {
56
- return bcs.struct("PriceIdentifier", {
63
+ static instantiateBcs() {
64
+ return bcs.struct('PriceIdentifier', {
57
65
  bytes: bcs.vector(bcs.u8()),
58
66
  });
59
67
  }
68
+ static cachedBcs = null;
69
+ static get bcs() {
70
+ if (!PriceIdentifier.cachedBcs) {
71
+ PriceIdentifier.cachedBcs = PriceIdentifier.instantiateBcs();
72
+ }
73
+ return PriceIdentifier.cachedBcs;
74
+ }
60
75
  static fromFields(fields) {
61
76
  return PriceIdentifier.reified().new({
62
- bytes: decodeFromFields(reified.vector("u8"), fields.bytes),
77
+ bytes: decodeFromFields(vector('u8'), fields.bytes),
63
78
  });
64
79
  }
65
80
  static fromFieldsWithTypes(item) {
66
81
  if (!isPriceIdentifier(item.type)) {
67
- throw new Error("not a PriceIdentifier type");
82
+ throw new Error('not a PriceIdentifier type');
68
83
  }
69
84
  return PriceIdentifier.reified().new({
70
- bytes: decodeFromFieldsWithTypes(reified.vector("u8"), item.fields.bytes),
85
+ bytes: decodeFromFieldsWithTypes(vector('u8'), item.fields.bytes),
71
86
  });
72
87
  }
73
88
  static fromBcs(data) {
@@ -79,25 +94,30 @@ export class PriceIdentifier {
79
94
  };
80
95
  }
81
96
  toJSON() {
82
- return {
83
- $typeName: this.$typeName,
84
- $typeArgs: this.$typeArgs,
85
- ...this.toJSONField(),
86
- };
97
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
87
98
  }
88
99
  static fromJSONField(field) {
89
100
  return PriceIdentifier.reified().new({
90
- bytes: decodeFromJSONField(reified.vector("u8"), field.bytes),
101
+ bytes: decodeFromJSONField(vector('u8'), field.bytes),
91
102
  });
92
103
  }
93
104
  static fromJSON(json) {
94
105
  if (json.$typeName !== PriceIdentifier.$typeName) {
95
- throw new Error("not a WithTwoGenerics json object");
106
+ throw new Error(`not a PriceIdentifier json object: expected '${PriceIdentifier.$typeName}' but got '${json.$typeName}'`);
96
107
  }
97
108
  return PriceIdentifier.fromJSONField(json);
98
109
  }
110
+ static fromCoreObject(obj) {
111
+ if (!isPriceIdentifier(obj.type)) {
112
+ throw new Error(`object at ${obj.objectId} is not a PriceIdentifier object`);
113
+ }
114
+ return PriceIdentifier.fromBcs(obj.content);
115
+ }
99
116
  static async fetch(client, id) {
100
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
117
+ const { object } = await client.core.getObject({
118
+ objectId: id,
119
+ include: { content: true },
120
+ });
101
121
  if (!isPriceIdentifier(object.type)) {
102
122
  throw new Error(`object at id ${id} is not a PriceIdentifier object`);
103
123
  }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * The `ASCII` module defines basic string and char newtypes in Move that verify
3
+ * that characters are valid ASCII, and that strings consist of only valid ASCII characters.
4
+ */
5
+ import type { ClientWithCoreApi, SuiClientTypes } from '@mysten/sui/client';
6
+ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from '../../../_framework/reified';
7
+ import { FieldsWithTypes } from '../../../_framework/util';
8
+ import { Vector } from '../../../_framework/vector';
9
+ export declare function isString(type: string): boolean;
10
+ export interface StringFields {
11
+ bytes: ToField<Vector<'u8'>>;
12
+ }
13
+ export type StringReified = Reified<String, StringFields>;
14
+ export type StringJSONField = {
15
+ bytes: number[];
16
+ };
17
+ export type StringJSON = {
18
+ $typeName: typeof String.$typeName;
19
+ $typeArgs: [];
20
+ } & StringJSONField;
21
+ /**
22
+ * The `String` struct holds a vector of bytes that all represent
23
+ * valid ASCII characters. Note that these ASCII characters may not all
24
+ * be printable. To determine if a `String` contains only "printable"
25
+ * characters you should use the `all_characters_printable` predicate
26
+ * defined in this module.
27
+ */
28
+ export declare class String implements StructClass {
29
+ __StructClass: true;
30
+ static readonly $typeName: `0x1::ascii::String`;
31
+ static readonly $numTypeParams = 0;
32
+ static readonly $isPhantom: readonly [];
33
+ readonly $typeName: typeof String.$typeName;
34
+ readonly $fullTypeName: `0x1::ascii::String`;
35
+ readonly $typeArgs: [];
36
+ readonly $isPhantom: typeof String.$isPhantom;
37
+ readonly bytes: ToField<Vector<'u8'>>;
38
+ private constructor();
39
+ static reified(): StringReified;
40
+ static get r(): StringReified;
41
+ static phantom(): PhantomReified<ToTypeStr<String>>;
42
+ static get p(): PhantomReified<ToTypeStr<String>>;
43
+ private static instantiateBcs;
44
+ private static cachedBcs;
45
+ static get bcs(): ReturnType<typeof String.instantiateBcs>;
46
+ static fromFields(fields: Record<string, any>): String;
47
+ static fromFieldsWithTypes(item: FieldsWithTypes): String;
48
+ static fromBcs(data: Uint8Array): String;
49
+ toJSONField(): StringJSONField;
50
+ toJSON(): StringJSON;
51
+ static fromJSONField(field: any): String;
52
+ static fromJSON(json: Record<string, any>): String;
53
+ static fromCoreObject(obj: SuiClientTypes.Object<{
54
+ content: true;
55
+ }>): String;
56
+ static fetch(client: ClientWithCoreApi, id: string): Promise<String>;
57
+ }
58
+ export declare function isChar(type: string): boolean;
59
+ export interface CharFields {
60
+ byte: ToField<'u8'>;
61
+ }
62
+ export type CharReified = Reified<Char, CharFields>;
63
+ export type CharJSONField = {
64
+ byte: number;
65
+ };
66
+ export type CharJSON = {
67
+ $typeName: typeof Char.$typeName;
68
+ $typeArgs: [];
69
+ } & CharJSONField;
70
+ /** An ASCII character. */
71
+ export declare class Char implements StructClass {
72
+ __StructClass: true;
73
+ static readonly $typeName: `0x1::ascii::Char`;
74
+ static readonly $numTypeParams = 0;
75
+ static readonly $isPhantom: readonly [];
76
+ readonly $typeName: typeof Char.$typeName;
77
+ readonly $fullTypeName: `0x1::ascii::Char`;
78
+ readonly $typeArgs: [];
79
+ readonly $isPhantom: typeof Char.$isPhantom;
80
+ readonly byte: ToField<'u8'>;
81
+ private constructor();
82
+ static reified(): CharReified;
83
+ static get r(): CharReified;
84
+ static phantom(): PhantomReified<ToTypeStr<Char>>;
85
+ static get p(): PhantomReified<ToTypeStr<Char>>;
86
+ private static instantiateBcs;
87
+ private static cachedBcs;
88
+ static get bcs(): ReturnType<typeof Char.instantiateBcs>;
89
+ static fromFields(fields: Record<string, any>): Char;
90
+ static fromFieldsWithTypes(item: FieldsWithTypes): Char;
91
+ static fromBcs(data: Uint8Array): Char;
92
+ toJSONField(): CharJSONField;
93
+ toJSON(): CharJSON;
94
+ static fromJSONField(field: any): Char;
95
+ static fromJSON(json: Record<string, any>): Char;
96
+ static fromCoreObject(obj: SuiClientTypes.Object<{
97
+ content: true;
98
+ }>): Char;
99
+ static fetch(client: ClientWithCoreApi, id: string): Promise<Char>;
100
+ }
@@ -1,203 +1,253 @@
1
- import * as reified from "../../../../_framework/reified.js";
2
- import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom, } from "../../../../_framework/reified.js";
3
- import { composeSuiType, compressSuiType, } from "../../../../_framework/util.js";
4
- import { PKG_V13 } from "../index.js";
5
- import { bcs } from "@mysten/sui/bcs";
6
- /* ============================== Char =============================== */
7
- export function isChar(type) {
1
+ /**
2
+ * The `ASCII` module defines basic string and char newtypes in Move that verify
3
+ * that characters are valid ASCII, and that strings consist of only valid ASCII characters.
4
+ */
5
+ import { bcs } from '@mysten/sui/bcs';
6
+ import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom, vector, } from '../../../_framework/reified.js';
7
+ import { composeSuiType, compressSuiType } from '../../../_framework/util.js';
8
+ /* ============================== String =============================== */
9
+ export function isString(type) {
8
10
  type = compressSuiType(type);
9
- return type === `${PKG_V13}::ascii::Char`;
11
+ return type === `0x1::ascii::String`;
10
12
  }
11
- export class Char {
13
+ /**
14
+ * The `String` struct holds a vector of bytes that all represent
15
+ * valid ASCII characters. Note that these ASCII characters may not all
16
+ * be printable. To determine if a `String` contains only "printable"
17
+ * characters you should use the `all_characters_printable` predicate
18
+ * defined in this module.
19
+ */
20
+ export class String {
12
21
  __StructClass = true;
13
- static $typeName = `${PKG_V13}::ascii::Char`;
22
+ static $typeName = `0x1::ascii::String`;
14
23
  static $numTypeParams = 0;
15
24
  static $isPhantom = [];
16
- $typeName = Char.$typeName;
25
+ $typeName = String.$typeName;
17
26
  $fullTypeName;
18
27
  $typeArgs;
19
- $isPhantom = Char.$isPhantom;
20
- byte;
28
+ $isPhantom = String.$isPhantom;
29
+ bytes;
21
30
  constructor(typeArgs, fields) {
22
- this.$fullTypeName = composeSuiType(Char.$typeName, ...typeArgs);
31
+ this.$fullTypeName = composeSuiType(String.$typeName, ...typeArgs);
23
32
  this.$typeArgs = typeArgs;
24
- this.byte = fields.byte;
33
+ this.bytes = fields.bytes;
25
34
  }
26
35
  static reified() {
36
+ const reifiedBcs = String.bcs;
27
37
  return {
28
- typeName: Char.$typeName,
29
- fullTypeName: composeSuiType(Char.$typeName, ...[]),
38
+ get typeName() {
39
+ return String.$typeName;
40
+ },
41
+ get fullTypeName() {
42
+ return composeSuiType(String.$typeName, ...[]);
43
+ },
30
44
  typeArgs: [],
31
- isPhantom: Char.$isPhantom,
45
+ isPhantom: String.$isPhantom,
32
46
  reifiedTypeArgs: [],
33
- fromFields: (fields) => Char.fromFields(fields),
34
- fromFieldsWithTypes: (item) => Char.fromFieldsWithTypes(item),
35
- fromBcs: (data) => Char.fromBcs(data),
36
- bcs: Char.bcs,
37
- fromJSONField: (field) => Char.fromJSONField(field),
38
- fromJSON: (json) => Char.fromJSON(json),
39
- fetch: async (client, id) => Char.fetch(client, id),
47
+ fromFields: (fields) => String.fromFields(fields),
48
+ fromFieldsWithTypes: (item) => String.fromFieldsWithTypes(item),
49
+ fromBcs: (data) => String.fromFields(reifiedBcs.parse(data)),
50
+ bcs: reifiedBcs,
51
+ fromJSONField: (field) => String.fromJSONField(field),
52
+ fromJSON: (json) => String.fromJSON(json),
53
+ fromCoreObject: (obj) => String.fromCoreObject(obj),
54
+ fetch: async (client, id) => String.fetch(client, id),
40
55
  new: (fields) => {
41
- return new Char([], fields);
56
+ return new String([], fields);
42
57
  },
43
- kind: "StructClassReified",
58
+ kind: 'StructClassReified',
44
59
  };
45
60
  }
46
61
  static get r() {
47
- return Char.reified();
62
+ return String.reified();
48
63
  }
49
64
  static phantom() {
50
- return phantom(Char.reified());
65
+ return phantom(String.reified());
51
66
  }
52
67
  static get p() {
53
- return Char.phantom();
68
+ return String.phantom();
54
69
  }
55
- static get bcs() {
56
- return bcs.struct("Char", {
57
- byte: bcs.u8(),
70
+ static instantiateBcs() {
71
+ return bcs.struct('String', {
72
+ bytes: bcs.vector(bcs.u8()),
58
73
  });
59
74
  }
75
+ static cachedBcs = null;
76
+ static get bcs() {
77
+ if (!String.cachedBcs) {
78
+ String.cachedBcs = String.instantiateBcs();
79
+ }
80
+ return String.cachedBcs;
81
+ }
60
82
  static fromFields(fields) {
61
- return Char.reified().new({ byte: decodeFromFields("u8", fields.byte) });
83
+ return String.reified().new({
84
+ bytes: decodeFromFields(vector('u8'), fields.bytes),
85
+ });
62
86
  }
63
87
  static fromFieldsWithTypes(item) {
64
- if (!isChar(item.type)) {
65
- throw new Error("not a Char type");
88
+ if (!isString(item.type)) {
89
+ throw new Error('not a String type');
66
90
  }
67
- return Char.reified().new({
68
- byte: decodeFromFieldsWithTypes("u8", item.fields.byte),
91
+ return String.reified().new({
92
+ bytes: decodeFromFieldsWithTypes(vector('u8'), item.fields.bytes),
69
93
  });
70
94
  }
71
95
  static fromBcs(data) {
72
- return Char.fromFields(Char.bcs.parse(data));
96
+ return String.fromFields(String.bcs.parse(data));
73
97
  }
74
98
  toJSONField() {
75
99
  return {
76
- byte: this.byte,
100
+ bytes: fieldToJSON(`vector<u8>`, this.bytes),
77
101
  };
78
102
  }
79
103
  toJSON() {
80
- return {
81
- $typeName: this.$typeName,
82
- $typeArgs: this.$typeArgs,
83
- ...this.toJSONField(),
84
- };
104
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
85
105
  }
86
106
  static fromJSONField(field) {
87
- return Char.reified().new({ byte: decodeFromJSONField("u8", field.byte) });
107
+ return String.reified().new({
108
+ bytes: decodeFromJSONField(vector('u8'), field.bytes),
109
+ });
88
110
  }
89
111
  static fromJSON(json) {
90
- if (json.$typeName !== Char.$typeName) {
91
- throw new Error("not a WithTwoGenerics json object");
112
+ if (json.$typeName !== String.$typeName) {
113
+ throw new Error(`not a String json object: expected '${String.$typeName}' but got '${json.$typeName}'`);
92
114
  }
93
- return Char.fromJSONField(json);
115
+ return String.fromJSONField(json);
116
+ }
117
+ static fromCoreObject(obj) {
118
+ if (!isString(obj.type)) {
119
+ throw new Error(`object at ${obj.objectId} is not a String object`);
120
+ }
121
+ return String.fromBcs(obj.content);
94
122
  }
95
123
  static async fetch(client, id) {
96
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
97
- if (!isChar(object.type)) {
98
- throw new Error(`object at id ${id} is not a Char object`);
124
+ const { object } = await client.core.getObject({
125
+ objectId: id,
126
+ include: { content: true },
127
+ });
128
+ if (!isString(object.type)) {
129
+ throw new Error(`object at id ${id} is not a String object`);
99
130
  }
100
- return Char.fromBcs(object.content);
131
+ return String.fromBcs(object.content);
101
132
  }
102
133
  }
103
- /* ============================== String =============================== */
104
- export function isString(type) {
134
+ /* ============================== Char =============================== */
135
+ export function isChar(type) {
105
136
  type = compressSuiType(type);
106
- return type === `${PKG_V13}::ascii::String`;
137
+ return type === `0x1::ascii::Char`;
107
138
  }
108
- export class String {
139
+ /** An ASCII character. */
140
+ export class Char {
109
141
  __StructClass = true;
110
- static $typeName = `${PKG_V13}::ascii::String`;
142
+ static $typeName = `0x1::ascii::Char`;
111
143
  static $numTypeParams = 0;
112
144
  static $isPhantom = [];
113
- $typeName = String.$typeName;
145
+ $typeName = Char.$typeName;
114
146
  $fullTypeName;
115
147
  $typeArgs;
116
- $isPhantom = String.$isPhantom;
117
- bytes;
148
+ $isPhantom = Char.$isPhantom;
149
+ byte;
118
150
  constructor(typeArgs, fields) {
119
- this.$fullTypeName = composeSuiType(String.$typeName, ...typeArgs);
151
+ this.$fullTypeName = composeSuiType(Char.$typeName, ...typeArgs);
120
152
  this.$typeArgs = typeArgs;
121
- this.bytes = fields.bytes;
153
+ this.byte = fields.byte;
122
154
  }
123
155
  static reified() {
156
+ const reifiedBcs = Char.bcs;
124
157
  return {
125
- typeName: String.$typeName,
126
- fullTypeName: composeSuiType(String.$typeName, ...[]),
158
+ get typeName() {
159
+ return Char.$typeName;
160
+ },
161
+ get fullTypeName() {
162
+ return composeSuiType(Char.$typeName, ...[]);
163
+ },
127
164
  typeArgs: [],
128
- isPhantom: String.$isPhantom,
165
+ isPhantom: Char.$isPhantom,
129
166
  reifiedTypeArgs: [],
130
- fromFields: (fields) => String.fromFields(fields),
131
- fromFieldsWithTypes: (item) => String.fromFieldsWithTypes(item),
132
- fromBcs: (data) => String.fromBcs(data),
133
- bcs: String.bcs,
134
- fromJSONField: (field) => String.fromJSONField(field),
135
- fromJSON: (json) => String.fromJSON(json),
136
- fetch: async (client, id) => String.fetch(client, id),
167
+ fromFields: (fields) => Char.fromFields(fields),
168
+ fromFieldsWithTypes: (item) => Char.fromFieldsWithTypes(item),
169
+ fromBcs: (data) => Char.fromFields(reifiedBcs.parse(data)),
170
+ bcs: reifiedBcs,
171
+ fromJSONField: (field) => Char.fromJSONField(field),
172
+ fromJSON: (json) => Char.fromJSON(json),
173
+ fromCoreObject: (obj) => Char.fromCoreObject(obj),
174
+ fetch: async (client, id) => Char.fetch(client, id),
137
175
  new: (fields) => {
138
- return new String([], fields);
176
+ return new Char([], fields);
139
177
  },
140
- kind: "StructClassReified",
178
+ kind: 'StructClassReified',
141
179
  };
142
180
  }
143
181
  static get r() {
144
- return String.reified();
182
+ return Char.reified();
145
183
  }
146
184
  static phantom() {
147
- return phantom(String.reified());
185
+ return phantom(Char.reified());
148
186
  }
149
187
  static get p() {
150
- return String.phantom();
188
+ return Char.phantom();
151
189
  }
152
- static get bcs() {
153
- return bcs.struct("String", {
154
- bytes: bcs.vector(bcs.u8()),
190
+ static instantiateBcs() {
191
+ return bcs.struct('Char', {
192
+ byte: bcs.u8(),
155
193
  });
156
194
  }
195
+ static cachedBcs = null;
196
+ static get bcs() {
197
+ if (!Char.cachedBcs) {
198
+ Char.cachedBcs = Char.instantiateBcs();
199
+ }
200
+ return Char.cachedBcs;
201
+ }
157
202
  static fromFields(fields) {
158
- return String.reified().new({
159
- bytes: decodeFromFields(reified.vector("u8"), fields.bytes),
203
+ return Char.reified().new({
204
+ byte: decodeFromFields('u8', fields.byte),
160
205
  });
161
206
  }
162
207
  static fromFieldsWithTypes(item) {
163
- if (!isString(item.type)) {
164
- throw new Error("not a String type");
208
+ if (!isChar(item.type)) {
209
+ throw new Error('not a Char type');
165
210
  }
166
- return String.reified().new({
167
- bytes: decodeFromFieldsWithTypes(reified.vector("u8"), item.fields.bytes),
211
+ return Char.reified().new({
212
+ byte: decodeFromFieldsWithTypes('u8', item.fields.byte),
168
213
  });
169
214
  }
170
215
  static fromBcs(data) {
171
- return String.fromFields(String.bcs.parse(data));
216
+ return Char.fromFields(Char.bcs.parse(data));
172
217
  }
173
218
  toJSONField() {
174
219
  return {
175
- bytes: fieldToJSON(`vector<u8>`, this.bytes),
220
+ byte: this.byte,
176
221
  };
177
222
  }
178
223
  toJSON() {
179
- return {
180
- $typeName: this.$typeName,
181
- $typeArgs: this.$typeArgs,
182
- ...this.toJSONField(),
183
- };
224
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
184
225
  }
185
226
  static fromJSONField(field) {
186
- return String.reified().new({
187
- bytes: decodeFromJSONField(reified.vector("u8"), field.bytes),
227
+ return Char.reified().new({
228
+ byte: decodeFromJSONField('u8', field.byte),
188
229
  });
189
230
  }
190
231
  static fromJSON(json) {
191
- if (json.$typeName !== String.$typeName) {
192
- throw new Error("not a WithTwoGenerics json object");
232
+ if (json.$typeName !== Char.$typeName) {
233
+ throw new Error(`not a Char json object: expected '${Char.$typeName}' but got '${json.$typeName}'`);
193
234
  }
194
- return String.fromJSONField(json);
235
+ return Char.fromJSONField(json);
236
+ }
237
+ static fromCoreObject(obj) {
238
+ if (!isChar(obj.type)) {
239
+ throw new Error(`object at ${obj.objectId} is not a Char object`);
240
+ }
241
+ return Char.fromBcs(obj.content);
195
242
  }
196
243
  static async fetch(client, id) {
197
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
198
- if (!isString(object.type)) {
199
- throw new Error(`object at id ${id} is not a String object`);
244
+ const { object } = await client.core.getObject({
245
+ objectId: id,
246
+ include: { content: true },
247
+ });
248
+ if (!isChar(object.type)) {
249
+ throw new Error(`object at id ${id} is not a Char object`);
200
250
  }
201
- return String.fromBcs(object.content);
251
+ return Char.fromBcs(object.content);
202
252
  }
203
253
  }