@suilend/sdk 1.1.21 → 1.1.23

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 (45) hide show
  1. package/_generated/_dependencies/source/0x1/ascii/structs.js +3 -3
  2. package/_generated/_dependencies/source/0x1/option/structs.d.ts +1 -1
  3. package/_generated/_dependencies/source/0x1/option/structs.js +2 -2
  4. package/_generated/_dependencies/source/0x1/type-name/structs.js +2 -2
  5. package/_generated/_dependencies/source/0x2/bag/structs.js +2 -2
  6. package/_generated/_dependencies/source/0x2/balance/structs.js +3 -3
  7. package/_generated/_dependencies/source/0x2/object/structs.js +3 -3
  8. package/_generated/_dependencies/source/0x2/object-table/structs.js +2 -2
  9. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.d.ts +52 -0
  10. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +148 -0
  11. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.d.ts +89 -0
  12. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +162 -0
  13. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.d.ts +158 -0
  14. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +157 -0
  15. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +2 -2
  16. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.d.ts +360 -0
  17. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +290 -0
  18. package/_generated/_framework/reified.js +10 -10
  19. package/_generated/_framework/util.d.ts +5 -11
  20. package/_generated/_framework/util.js +12 -13
  21. package/_generated/_framework/vector.d.ts +1 -1
  22. package/_generated/_framework/vector.js +2 -2
  23. package/_generated/suilend/cell/structs.d.ts +1 -1
  24. package/_generated/suilend/cell/structs.js +2 -2
  25. package/_generated/suilend/decimal/structs.js +2 -2
  26. package/_generated/suilend/index.js +2 -2
  27. package/_generated/suilend/lending-market/functions.js +40 -41
  28. package/_generated/suilend/lending-market/structs.js +15 -15
  29. package/_generated/suilend/lending-market-registry/functions.js +2 -3
  30. package/_generated/suilend/liquidity-mining/structs.js +6 -6
  31. package/_generated/suilend/obligation/structs.js +7 -7
  32. package/_generated/suilend/rate-limiter/functions.js +6 -7
  33. package/_generated/suilend/rate-limiter/structs.js +3 -3
  34. package/_generated/suilend/reserve/structs.js +10 -10
  35. package/_generated/suilend/reserve-config/functions.js +39 -40
  36. package/_generated/suilend/reserve-config/structs.js +3 -3
  37. package/client.d.ts +11 -9
  38. package/client.js +86 -83
  39. package/package.json +1 -1
  40. package/parsers/lendingMarket.d.ts +2 -2
  41. package/parsers/obligation.d.ts +4 -4
  42. package/parsers/reserve.d.ts +2 -2
  43. package/utils/events.js +3 -3
  44. package/utils/index.js +10 -2
  45. package/utils/obligation.js +5 -6
@@ -32,7 +32,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.String = exports.isString = exports.Char = exports.isChar = void 0;
35
+ exports.String = exports.Char = void 0;
36
+ exports.isChar = isChar;
37
+ exports.isString = isString;
36
38
  const reified = __importStar(require("../../../../_framework/reified"));
37
39
  const reified_1 = require("../../../../_framework/reified");
38
40
  const util_1 = require("../../../../_framework/util");
@@ -44,7 +46,6 @@ function isChar(type) {
44
46
  type = (0, util_1.compressSuiType)(type);
45
47
  return type === `${index_1.PKG_V11}::ascii::Char`;
46
48
  }
47
- exports.isChar = isChar;
48
49
  class Char {
49
50
  constructor(typeArgs, fields) {
50
51
  this.__StructClass = true;
@@ -166,7 +167,6 @@ function isString(type) {
166
167
  type = (0, util_1.compressSuiType)(type);
167
168
  return type === `${index_1.PKG_V11}::ascii::String`;
168
169
  }
169
- exports.isString = isString;
170
170
  class String {
171
171
  constructor(typeArgs, fields) {
172
172
  this.__StructClass = true;
@@ -26,7 +26,7 @@ export declare class Option<Element extends TypeArgument> implements StructClass
26
26
  static get r(): typeof Option.reified;
27
27
  static phantom<Element extends Reified<TypeArgument, any>>(Element: Element): PhantomReified<ToTypeStr<Option<ToTypeArgument<Element>>>>;
28
28
  static get p(): typeof Option.phantom;
29
- static get bcs(): <Element extends BcsType<any, any>>(Element: Element) => BcsType<{
29
+ static get bcs(): <Element extends BcsType<any>>(Element: Element) => BcsType<{
30
30
  vec: any[];
31
31
  }, {
32
32
  vec: Iterable<any> & {
@@ -32,7 +32,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Option = exports.isOption = void 0;
35
+ exports.Option = void 0;
36
+ exports.isOption = isOption;
36
37
  const reified = __importStar(require("../../../../_framework/reified"));
37
38
  const reified_1 = require("../../../../_framework/reified");
38
39
  const util_1 = require("../../../../_framework/util");
@@ -44,7 +45,6 @@ function isOption(type) {
44
45
  type = (0, util_1.compressSuiType)(type);
45
46
  return type.startsWith(`${index_1.PKG_V11}::option::Option` + "<");
46
47
  }
47
- exports.isOption = isOption;
48
48
  class Option {
49
49
  constructor(typeArgs, fields) {
50
50
  this.__StructClass = true;
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.TypeName = exports.isTypeName = void 0;
12
+ exports.TypeName = void 0;
13
+ exports.isTypeName = isTypeName;
13
14
  const reified_1 = require("../../../../_framework/reified");
14
15
  const util_1 = require("../../../../_framework/util");
15
16
  const structs_1 = require("../ascii/structs");
@@ -21,7 +22,6 @@ function isTypeName(type) {
21
22
  type = (0, util_1.compressSuiType)(type);
22
23
  return type === `${index_1.PKG_V11}::type_name::TypeName`;
23
24
  }
24
- exports.isTypeName = isTypeName;
25
25
  class TypeName {
26
26
  constructor(typeArgs, fields) {
27
27
  this.__StructClass = true;
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Bag = exports.isBag = void 0;
12
+ exports.Bag = void 0;
13
+ exports.isBag = isBag;
13
14
  const reified_1 = require("../../../../_framework/reified");
14
15
  const util_1 = require("../../../../_framework/util");
15
16
  const index_1 = require("../index");
@@ -21,7 +22,6 @@ function isBag(type) {
21
22
  type = (0, util_1.compressSuiType)(type);
22
23
  return type === `${index_1.PKG_V28}::bag::Bag`;
23
24
  }
24
- exports.isBag = isBag;
25
25
  class Bag {
26
26
  constructor(typeArgs, fields) {
27
27
  this.__StructClass = true;
@@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Supply = exports.isSupply = exports.Balance = exports.isBalance = void 0;
12
+ exports.Supply = exports.Balance = void 0;
13
+ exports.isBalance = isBalance;
14
+ exports.isSupply = isSupply;
13
15
  const reified_1 = require("../../../../_framework/reified");
14
16
  const util_1 = require("../../../../_framework/util");
15
17
  const index_1 = require("../index");
@@ -20,7 +22,6 @@ function isBalance(type) {
20
22
  type = (0, util_1.compressSuiType)(type);
21
23
  return type.startsWith(`${index_1.PKG_V28}::balance::Balance` + "<");
22
24
  }
23
- exports.isBalance = isBalance;
24
25
  class Balance {
25
26
  constructor(typeArgs, fields) {
26
27
  this.__StructClass = true;
@@ -157,7 +158,6 @@ function isSupply(type) {
157
158
  type = (0, util_1.compressSuiType)(type);
158
159
  return type.startsWith(`${index_1.PKG_V28}::balance::Supply` + "<");
159
160
  }
160
- exports.isSupply = isSupply;
161
161
  class Supply {
162
162
  constructor(typeArgs, fields) {
163
163
  this.__StructClass = true;
@@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UID = exports.isUID = exports.ID = exports.isID = void 0;
12
+ exports.UID = exports.ID = void 0;
13
+ exports.isID = isID;
14
+ exports.isUID = isUID;
13
15
  const reified_1 = require("../../../../_framework/reified");
14
16
  const util_1 = require("../../../../_framework/util");
15
17
  const index_1 = require("../index");
@@ -20,7 +22,6 @@ function isID(type) {
20
22
  type = (0, util_1.compressSuiType)(type);
21
23
  return type === `${index_1.PKG_V28}::object::ID`;
22
24
  }
23
- exports.isID = isID;
24
25
  class ID {
25
26
  constructor(typeArgs, fields) {
26
27
  this.__StructClass = true;
@@ -150,7 +151,6 @@ function isUID(type) {
150
151
  type = (0, util_1.compressSuiType)(type);
151
152
  return type === `${index_1.PKG_V28}::object::UID`;
152
153
  }
153
- exports.isUID = isUID;
154
154
  class UID {
155
155
  constructor(typeArgs, fields) {
156
156
  this.__StructClass = true;
@@ -9,7 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ObjectTable = exports.isObjectTable = void 0;
12
+ exports.ObjectTable = void 0;
13
+ exports.isObjectTable = isObjectTable;
13
14
  const reified_1 = require("../../../../_framework/reified");
14
15
  const util_1 = require("../../../../_framework/util");
15
16
  const index_1 = require("../index");
@@ -21,7 +22,6 @@ function isObjectTable(type) {
21
22
  type = (0, util_1.compressSuiType)(type);
22
23
  return type.startsWith(`${index_1.PKG_V28}::object_table::ObjectTable` + "<");
23
24
  }
24
- exports.isObjectTable = isObjectTable;
25
25
  class ObjectTable {
26
26
  constructor(typeArgs, fields) {
27
27
  this.__StructClass = true;
@@ -0,0 +1,52 @@
1
+ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
2
+ import { FieldsWithTypes } from "../../../../_framework/util";
3
+ import { PKG_V1 } from "../index";
4
+ import { SuiClient, SuiObjectData, SuiParsedData } from "@mysten/sui/client";
5
+ export declare function isI64(type: string): boolean;
6
+ export interface I64Fields {
7
+ negative: ToField<"bool">;
8
+ magnitude: ToField<"u64">;
9
+ }
10
+ export type I64Reified = Reified<I64, I64Fields>;
11
+ export declare class I64 implements StructClass {
12
+ __StructClass: true;
13
+ static readonly $typeName = "0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::i64::I64";
14
+ static readonly $numTypeParams = 0;
15
+ static readonly $isPhantom: readonly [];
16
+ readonly $typeName = "0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::i64::I64";
17
+ readonly $fullTypeName: `${typeof PKG_V1}::i64::I64`;
18
+ readonly $typeArgs: [];
19
+ readonly $isPhantom: readonly [];
20
+ readonly negative: ToField<"bool">;
21
+ readonly magnitude: ToField<"u64">;
22
+ private constructor();
23
+ static reified(): I64Reified;
24
+ static get r(): import("../../../../_framework/reified").StructClassReified<I64, I64Fields>;
25
+ static phantom(): PhantomReified<ToTypeStr<I64>>;
26
+ static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::i64::I64">;
27
+ static get bcs(): import("@mysten/sui/bcs").BcsType<{
28
+ negative: boolean;
29
+ magnitude: string;
30
+ }, {
31
+ negative: boolean;
32
+ magnitude: string | number | bigint;
33
+ }>;
34
+ static fromFields(fields: Record<string, any>): I64;
35
+ static fromFieldsWithTypes(item: FieldsWithTypes): I64;
36
+ static fromBcs(data: Uint8Array): I64;
37
+ toJSONField(): {
38
+ negative: boolean;
39
+ magnitude: string;
40
+ };
41
+ toJSON(): {
42
+ negative: boolean;
43
+ magnitude: string;
44
+ $typeName: string;
45
+ $typeArgs: [];
46
+ };
47
+ static fromJSONField(field: any): I64;
48
+ static fromJSON(json: Record<string, any>): I64;
49
+ static fromSuiParsedData(content: SuiParsedData): I64;
50
+ static fromSuiObjectData(data: SuiObjectData): I64;
51
+ static fetch(client: SuiClient, id: string): Promise<I64>;
52
+ }
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.I64 = void 0;
13
+ exports.isI64 = isI64;
14
+ const reified_1 = require("../../../../_framework/reified");
15
+ const util_1 = require("../../../../_framework/util");
16
+ const index_1 = require("../index");
17
+ const bcs_1 = require("@mysten/sui/bcs");
18
+ const utils_1 = require("@mysten/sui/utils");
19
+ /* ============================== I64 =============================== */
20
+ function isI64(type) {
21
+ type = (0, util_1.compressSuiType)(type);
22
+ return type === `${index_1.PKG_V1}::i64::I64`;
23
+ }
24
+ class I64 {
25
+ constructor(typeArgs, fields) {
26
+ this.__StructClass = true;
27
+ this.$typeName = I64.$typeName;
28
+ this.$isPhantom = I64.$isPhantom;
29
+ this.$fullTypeName = (0, util_1.composeSuiType)(I64.$typeName, ...typeArgs);
30
+ this.$typeArgs = typeArgs;
31
+ this.negative = fields.negative;
32
+ this.magnitude = fields.magnitude;
33
+ }
34
+ static reified() {
35
+ return {
36
+ typeName: I64.$typeName,
37
+ fullTypeName: (0, util_1.composeSuiType)(I64.$typeName, ...[]),
38
+ typeArgs: [],
39
+ isPhantom: I64.$isPhantom,
40
+ reifiedTypeArgs: [],
41
+ fromFields: (fields) => I64.fromFields(fields),
42
+ fromFieldsWithTypes: (item) => I64.fromFieldsWithTypes(item),
43
+ fromBcs: (data) => I64.fromBcs(data),
44
+ bcs: I64.bcs,
45
+ fromJSONField: (field) => I64.fromJSONField(field),
46
+ fromJSON: (json) => I64.fromJSON(json),
47
+ fromSuiParsedData: (content) => I64.fromSuiParsedData(content),
48
+ fromSuiObjectData: (content) => I64.fromSuiObjectData(content),
49
+ fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return I64.fetch(client, id); }),
50
+ new: (fields) => {
51
+ return new I64([], fields);
52
+ },
53
+ kind: "StructClassReified",
54
+ };
55
+ }
56
+ static get r() {
57
+ return I64.reified();
58
+ }
59
+ static phantom() {
60
+ return (0, reified_1.phantom)(I64.reified());
61
+ }
62
+ static get p() {
63
+ return I64.phantom();
64
+ }
65
+ static get bcs() {
66
+ return bcs_1.bcs.struct("I64", {
67
+ negative: bcs_1.bcs.bool(),
68
+ magnitude: bcs_1.bcs.u64(),
69
+ });
70
+ }
71
+ static fromFields(fields) {
72
+ return I64.reified().new({
73
+ negative: (0, reified_1.decodeFromFields)("bool", fields.negative),
74
+ magnitude: (0, reified_1.decodeFromFields)("u64", fields.magnitude),
75
+ });
76
+ }
77
+ static fromFieldsWithTypes(item) {
78
+ if (!isI64(item.type)) {
79
+ throw new Error("not a I64 type");
80
+ }
81
+ return I64.reified().new({
82
+ negative: (0, reified_1.decodeFromFieldsWithTypes)("bool", item.fields.negative),
83
+ magnitude: (0, reified_1.decodeFromFieldsWithTypes)("u64", item.fields.magnitude),
84
+ });
85
+ }
86
+ static fromBcs(data) {
87
+ return I64.fromFields(I64.bcs.parse(data));
88
+ }
89
+ toJSONField() {
90
+ return {
91
+ negative: this.negative,
92
+ magnitude: this.magnitude.toString(),
93
+ };
94
+ }
95
+ toJSON() {
96
+ return Object.assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
97
+ }
98
+ static fromJSONField(field) {
99
+ return I64.reified().new({
100
+ negative: (0, reified_1.decodeFromJSONField)("bool", field.negative),
101
+ magnitude: (0, reified_1.decodeFromJSONField)("u64", field.magnitude),
102
+ });
103
+ }
104
+ static fromJSON(json) {
105
+ if (json.$typeName !== I64.$typeName) {
106
+ throw new Error("not a WithTwoGenerics json object");
107
+ }
108
+ return I64.fromJSONField(json);
109
+ }
110
+ static fromSuiParsedData(content) {
111
+ if (content.dataType !== "moveObject") {
112
+ throw new Error("not an object");
113
+ }
114
+ if (!isI64(content.type)) {
115
+ throw new Error(`object at ${content.fields.id} is not a I64 object`);
116
+ }
117
+ return I64.fromFieldsWithTypes(content);
118
+ }
119
+ static fromSuiObjectData(data) {
120
+ if (data.bcs) {
121
+ if (data.bcs.dataType !== "moveObject" || !isI64(data.bcs.type)) {
122
+ throw new Error(`object at is not a I64 object`);
123
+ }
124
+ return I64.fromBcs((0, utils_1.fromB64)(data.bcs.bcsBytes));
125
+ }
126
+ if (data.content) {
127
+ return I64.fromSuiParsedData(data.content);
128
+ }
129
+ throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
130
+ }
131
+ static fetch(client, id) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ var _a, _b;
134
+ const res = yield client.getObject({ id, options: { showBcs: true } });
135
+ if (res.error) {
136
+ throw new Error(`error fetching I64 object at id ${id}: ${res.error.code}`);
137
+ }
138
+ if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" || !isI64(res.data.bcs.type)) {
139
+ throw new Error(`object at id ${id} is not a I64 object`);
140
+ }
141
+ return I64.fromSuiObjectData(res.data);
142
+ });
143
+ }
144
+ }
145
+ exports.I64 = I64;
146
+ I64.$typeName = `${index_1.PKG_V1}::i64::I64`;
147
+ I64.$numTypeParams = 0;
148
+ I64.$isPhantom = [];
@@ -0,0 +1,89 @@
1
+ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
2
+ import { FieldsWithTypes } from "../../../../_framework/util";
3
+ import { I64 } from "../i64/structs";
4
+ import { PKG_V1 } from "../index";
5
+ import { SuiClient, SuiObjectData, SuiParsedData } from "@mysten/sui/client";
6
+ export declare function isPrice(type: string): boolean;
7
+ export interface PriceFields {
8
+ price: ToField<I64>;
9
+ conf: ToField<"u64">;
10
+ expo: ToField<I64>;
11
+ timestamp: ToField<"u64">;
12
+ }
13
+ export type PriceReified = Reified<Price, PriceFields>;
14
+ export declare class Price implements StructClass {
15
+ __StructClass: true;
16
+ static readonly $typeName = "0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price::Price";
17
+ static readonly $numTypeParams = 0;
18
+ static readonly $isPhantom: readonly [];
19
+ readonly $typeName = "0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price::Price";
20
+ readonly $fullTypeName: `${typeof PKG_V1}::price::Price`;
21
+ readonly $typeArgs: [];
22
+ readonly $isPhantom: readonly [];
23
+ readonly price: ToField<I64>;
24
+ readonly conf: ToField<"u64">;
25
+ readonly expo: ToField<I64>;
26
+ readonly timestamp: ToField<"u64">;
27
+ private constructor();
28
+ static reified(): PriceReified;
29
+ static get r(): import("../../../../_framework/reified").StructClassReified<Price, PriceFields>;
30
+ static phantom(): PhantomReified<ToTypeStr<Price>>;
31
+ static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price::Price">;
32
+ static get bcs(): import("@mysten/sui/bcs").BcsType<{
33
+ price: {
34
+ negative: boolean;
35
+ magnitude: string;
36
+ };
37
+ conf: string;
38
+ expo: {
39
+ negative: boolean;
40
+ magnitude: string;
41
+ };
42
+ timestamp: string;
43
+ }, {
44
+ price: {
45
+ negative: boolean;
46
+ magnitude: string | number | bigint;
47
+ };
48
+ conf: string | number | bigint;
49
+ expo: {
50
+ negative: boolean;
51
+ magnitude: string | number | bigint;
52
+ };
53
+ timestamp: string | number | bigint;
54
+ }>;
55
+ static fromFields(fields: Record<string, any>): Price;
56
+ static fromFieldsWithTypes(item: FieldsWithTypes): Price;
57
+ static fromBcs(data: Uint8Array): Price;
58
+ toJSONField(): {
59
+ price: {
60
+ negative: boolean;
61
+ magnitude: string;
62
+ };
63
+ conf: string;
64
+ expo: {
65
+ negative: boolean;
66
+ magnitude: string;
67
+ };
68
+ timestamp: string;
69
+ };
70
+ toJSON(): {
71
+ price: {
72
+ negative: boolean;
73
+ magnitude: string;
74
+ };
75
+ conf: string;
76
+ expo: {
77
+ negative: boolean;
78
+ magnitude: string;
79
+ };
80
+ timestamp: string;
81
+ $typeName: string;
82
+ $typeArgs: [];
83
+ };
84
+ static fromJSONField(field: any): Price;
85
+ static fromJSON(json: Record<string, any>): Price;
86
+ static fromSuiParsedData(content: SuiParsedData): Price;
87
+ static fromSuiObjectData(data: SuiObjectData): Price;
88
+ static fetch(client: SuiClient, id: string): Promise<Price>;
89
+ }
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Price = void 0;
13
+ exports.isPrice = isPrice;
14
+ const reified_1 = require("../../../../_framework/reified");
15
+ const util_1 = require("../../../../_framework/util");
16
+ const structs_1 = require("../i64/structs");
17
+ const index_1 = require("../index");
18
+ const bcs_1 = require("@mysten/sui/bcs");
19
+ const utils_1 = require("@mysten/sui/utils");
20
+ /* ============================== Price =============================== */
21
+ function isPrice(type) {
22
+ type = (0, util_1.compressSuiType)(type);
23
+ return type === `${index_1.PKG_V1}::price::Price`;
24
+ }
25
+ class Price {
26
+ constructor(typeArgs, fields) {
27
+ this.__StructClass = true;
28
+ this.$typeName = Price.$typeName;
29
+ this.$isPhantom = Price.$isPhantom;
30
+ this.$fullTypeName = (0, util_1.composeSuiType)(Price.$typeName, ...typeArgs);
31
+ this.$typeArgs = typeArgs;
32
+ this.price = fields.price;
33
+ this.conf = fields.conf;
34
+ this.expo = fields.expo;
35
+ this.timestamp = fields.timestamp;
36
+ }
37
+ static reified() {
38
+ return {
39
+ typeName: Price.$typeName,
40
+ fullTypeName: (0, util_1.composeSuiType)(Price.$typeName, ...[]),
41
+ typeArgs: [],
42
+ isPhantom: Price.$isPhantom,
43
+ reifiedTypeArgs: [],
44
+ fromFields: (fields) => Price.fromFields(fields),
45
+ fromFieldsWithTypes: (item) => Price.fromFieldsWithTypes(item),
46
+ fromBcs: (data) => Price.fromBcs(data),
47
+ bcs: Price.bcs,
48
+ fromJSONField: (field) => Price.fromJSONField(field),
49
+ fromJSON: (json) => Price.fromJSON(json),
50
+ fromSuiParsedData: (content) => Price.fromSuiParsedData(content),
51
+ fromSuiObjectData: (content) => Price.fromSuiObjectData(content),
52
+ fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Price.fetch(client, id); }),
53
+ new: (fields) => {
54
+ return new Price([], fields);
55
+ },
56
+ kind: "StructClassReified",
57
+ };
58
+ }
59
+ static get r() {
60
+ return Price.reified();
61
+ }
62
+ static phantom() {
63
+ return (0, reified_1.phantom)(Price.reified());
64
+ }
65
+ static get p() {
66
+ return Price.phantom();
67
+ }
68
+ static get bcs() {
69
+ return bcs_1.bcs.struct("Price", {
70
+ price: structs_1.I64.bcs,
71
+ conf: bcs_1.bcs.u64(),
72
+ expo: structs_1.I64.bcs,
73
+ timestamp: bcs_1.bcs.u64(),
74
+ });
75
+ }
76
+ static fromFields(fields) {
77
+ return Price.reified().new({
78
+ price: (0, reified_1.decodeFromFields)(structs_1.I64.reified(), fields.price),
79
+ conf: (0, reified_1.decodeFromFields)("u64", fields.conf),
80
+ expo: (0, reified_1.decodeFromFields)(structs_1.I64.reified(), fields.expo),
81
+ timestamp: (0, reified_1.decodeFromFields)("u64", fields.timestamp),
82
+ });
83
+ }
84
+ static fromFieldsWithTypes(item) {
85
+ if (!isPrice(item.type)) {
86
+ throw new Error("not a Price type");
87
+ }
88
+ return Price.reified().new({
89
+ price: (0, reified_1.decodeFromFieldsWithTypes)(structs_1.I64.reified(), item.fields.price),
90
+ conf: (0, reified_1.decodeFromFieldsWithTypes)("u64", item.fields.conf),
91
+ expo: (0, reified_1.decodeFromFieldsWithTypes)(structs_1.I64.reified(), item.fields.expo),
92
+ timestamp: (0, reified_1.decodeFromFieldsWithTypes)("u64", item.fields.timestamp),
93
+ });
94
+ }
95
+ static fromBcs(data) {
96
+ return Price.fromFields(Price.bcs.parse(data));
97
+ }
98
+ toJSONField() {
99
+ return {
100
+ price: this.price.toJSONField(),
101
+ conf: this.conf.toString(),
102
+ expo: this.expo.toJSONField(),
103
+ timestamp: this.timestamp.toString(),
104
+ };
105
+ }
106
+ toJSON() {
107
+ return Object.assign({ $typeName: this.$typeName, $typeArgs: this.$typeArgs }, this.toJSONField());
108
+ }
109
+ static fromJSONField(field) {
110
+ return Price.reified().new({
111
+ price: (0, reified_1.decodeFromJSONField)(structs_1.I64.reified(), field.price),
112
+ conf: (0, reified_1.decodeFromJSONField)("u64", field.conf),
113
+ expo: (0, reified_1.decodeFromJSONField)(structs_1.I64.reified(), field.expo),
114
+ timestamp: (0, reified_1.decodeFromJSONField)("u64", field.timestamp),
115
+ });
116
+ }
117
+ static fromJSON(json) {
118
+ if (json.$typeName !== Price.$typeName) {
119
+ throw new Error("not a WithTwoGenerics json object");
120
+ }
121
+ return Price.fromJSONField(json);
122
+ }
123
+ static fromSuiParsedData(content) {
124
+ if (content.dataType !== "moveObject") {
125
+ throw new Error("not an object");
126
+ }
127
+ if (!isPrice(content.type)) {
128
+ throw new Error(`object at ${content.fields.id} is not a Price object`);
129
+ }
130
+ return Price.fromFieldsWithTypes(content);
131
+ }
132
+ static fromSuiObjectData(data) {
133
+ if (data.bcs) {
134
+ if (data.bcs.dataType !== "moveObject" || !isPrice(data.bcs.type)) {
135
+ throw new Error(`object at is not a Price object`);
136
+ }
137
+ return Price.fromBcs((0, utils_1.fromB64)(data.bcs.bcsBytes));
138
+ }
139
+ if (data.content) {
140
+ return Price.fromSuiParsedData(data.content);
141
+ }
142
+ throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
143
+ }
144
+ static fetch(client, id) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ var _a, _b;
147
+ const res = yield client.getObject({ id, options: { showBcs: true } });
148
+ if (res.error) {
149
+ throw new Error(`error fetching Price object at id ${id}: ${res.error.code}`);
150
+ }
151
+ if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
152
+ !isPrice(res.data.bcs.type)) {
153
+ throw new Error(`object at id ${id} is not a Price object`);
154
+ }
155
+ return Price.fromSuiObjectData(res.data);
156
+ });
157
+ }
158
+ }
159
+ exports.Price = Price;
160
+ Price.$typeName = `${index_1.PKG_V1}::price::Price`;
161
+ Price.$numTypeParams = 0;
162
+ Price.$isPhantom = [];