@suilend/sdk 2.0.4 → 3.0.1
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/source/0x1/ascii/structs.d.ts +7 -11
- package/_generated/_dependencies/source/0x1/ascii/structs.js +6 -63
- package/_generated/_dependencies/source/0x1/option/structs.d.ts +3 -9
- package/_generated/_dependencies/source/0x1/option/structs.js +4 -42
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +5 -7
- package/_generated/_dependencies/source/0x1/type-name/structs.js +3 -32
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +7 -9
- package/_generated/_dependencies/source/0x2/bag/structs.js +3 -31
- package/_generated/_dependencies/source/0x2/balance/structs.d.ts +7 -11
- package/_generated/_dependencies/source/0x2/balance/structs.js +7 -82
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +8 -12
- package/_generated/_dependencies/source/0x2/object/structs.js +7 -61
- package/_generated/_dependencies/source/0x2/object-table/structs.d.ts +7 -9
- package/_generated/_dependencies/source/0x2/object-table/structs.js +4 -44
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.d.ts +5 -7
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +3 -31
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.d.ts +11 -13
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +3 -32
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.d.ts +23 -25
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +3 -32
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +4 -6
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +3 -33
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.d.ts +55 -59
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +6 -64
- package/_generated/_framework/reified.d.ts +2 -4
- package/_generated/_framework/vector.d.ts +2 -12
- package/_generated/suilend/cell/structs.d.ts +4 -10
- package/_generated/suilend/cell/structs.js +4 -42
- package/_generated/suilend/decimal/structs.d.ts +4 -6
- package/_generated/suilend/decimal/structs.js +3 -32
- package/_generated/suilend/lending-market/structs.d.ts +152 -392
- package/_generated/suilend/lending-market/structs.js +50 -548
- package/_generated/suilend/liquidity-mining/structs.d.ts +50 -158
- package/_generated/suilend/liquidity-mining/structs.js +16 -169
- package/_generated/suilend/obligation/structs.d.ts +108 -148
- package/_generated/suilend/obligation/structs.js +23 -232
- package/_generated/suilend/rate-limiter/structs.d.ts +15 -19
- package/_generated/suilend/rate-limiter/structs.js +6 -64
- package/_generated/suilend/reserve/structs.d.ts +138 -362
- package/_generated/suilend/reserve/structs.js +29 -327
- package/_generated/suilend/reserve-config/structs.d.ts +33 -37
- package/_generated/suilend/reserve-config/structs.js +6 -65
- package/client.d.ts +8 -8
- package/client.js +55 -88
- package/lib/initialize.d.ts +29 -28
- package/lib/initialize.js +16 -12
- package/lib/liquidityMining.d.ts +3 -3
- package/lib/pythAdapter.d.ts +9 -0
- package/lib/pythAdapter.js +121 -0
- package/lib/strategyOwnerCap.d.ts +12 -7
- package/lib/strategyOwnerCap.js +159 -156
- package/margin/margin/admin_cap.d.ts +2 -2
- package/margin/margin/deps/std/type_name.d.ts +1 -1
- package/margin/margin/deps/sui/vec_set.d.ts +3 -5
- package/margin/margin/deps/suilend/lending_market.d.ts +2 -2
- package/margin/margin/market.d.ts +21 -38
- package/margin/margin/position.d.ts +47 -47
- package/margin/margin/router.d.ts +5 -5
- package/margin/margin/version.d.ts +1 -1
- package/package.json +1 -1
- package/parsers/lendingMarket.d.ts +6 -6
- package/parsers/obligation.d.ts +8 -8
- package/parsers/reserve.d.ts +8 -8
- package/strategies.d.ts +38 -21
- package/strategies.js +239 -79
- package/swap/quote.d.ts +1 -9
- package/swap/quote.js +1 -52
- package/swap/transaction.d.ts +2 -4
- package/swap/transaction.js +9 -25
- package/utils/events.d.ts +6 -5
- package/utils/events.js +11 -8
- package/utils/obligation.d.ts +6 -5
- package/utils/obligation.js +118 -117
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
|
|
2
2
|
import { FieldsWithTypes } from "../../../../_framework/util";
|
|
3
3
|
import { PKG_V30 } from "../index";
|
|
4
|
-
import {
|
|
4
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
5
5
|
export declare function isID(type: string): boolean;
|
|
6
6
|
export interface IDFields {
|
|
7
7
|
bytes: ToField<"address">;
|
|
@@ -22,8 +22,8 @@ export declare class ID implements StructClass {
|
|
|
22
22
|
static get r(): import("../../../../_framework/reified").StructClassReified<ID, IDFields>;
|
|
23
23
|
static phantom(): PhantomReified<ToTypeStr<ID>>;
|
|
24
24
|
static get p(): PhantomReified<"0x2::object::ID">;
|
|
25
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
26
|
-
bytes: import("@mysten/bcs").BcsType<string, string, string>;
|
|
25
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
26
|
+
bytes: import("@mysten/sui/bcs").BcsType<string, string, string>;
|
|
27
27
|
}, string>;
|
|
28
28
|
static fromFields(fields: Record<string, any>): ID;
|
|
29
29
|
static fromFieldsWithTypes(item: FieldsWithTypes): ID;
|
|
@@ -38,9 +38,7 @@ export declare class ID implements StructClass {
|
|
|
38
38
|
};
|
|
39
39
|
static fromJSONField(field: any): ID;
|
|
40
40
|
static fromJSON(json: Record<string, any>): ID;
|
|
41
|
-
static
|
|
42
|
-
static fromSuiObjectData(data: SuiObjectData): ID;
|
|
43
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<ID>;
|
|
41
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<ID>;
|
|
44
42
|
}
|
|
45
43
|
export declare function isUID(type: string): boolean;
|
|
46
44
|
export interface UIDFields {
|
|
@@ -62,9 +60,9 @@ export declare class UID implements StructClass {
|
|
|
62
60
|
static get r(): import("../../../../_framework/reified").StructClassReified<UID, UIDFields>;
|
|
63
61
|
static phantom(): PhantomReified<ToTypeStr<UID>>;
|
|
64
62
|
static get p(): PhantomReified<"0x2::object::UID">;
|
|
65
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
66
|
-
id: import("@mysten/bcs").BcsStruct<{
|
|
67
|
-
bytes: import("@mysten/bcs").BcsType<string, string, string>;
|
|
63
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
64
|
+
id: import("@mysten/sui/bcs").BcsStruct<{
|
|
65
|
+
bytes: import("@mysten/sui/bcs").BcsType<string, string, string>;
|
|
68
66
|
}, string>;
|
|
69
67
|
}, string>;
|
|
70
68
|
static fromFields(fields: Record<string, any>): UID;
|
|
@@ -80,7 +78,5 @@ export declare class UID implements StructClass {
|
|
|
80
78
|
};
|
|
81
79
|
static fromJSONField(field: any): UID;
|
|
82
80
|
static fromJSON(json: Record<string, any>): UID;
|
|
83
|
-
static
|
|
84
|
-
static fromSuiObjectData(data: SuiObjectData): UID;
|
|
85
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<UID>;
|
|
81
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<UID>;
|
|
86
82
|
}
|
|
@@ -11,7 +11,7 @@ import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phant
|
|
|
11
11
|
import { composeSuiType, compressSuiType, } from "../../../../_framework/util";
|
|
12
12
|
import { PKG_V30 } from "../index";
|
|
13
13
|
import { bcs } from "@mysten/sui/bcs";
|
|
14
|
-
import {
|
|
14
|
+
import { fromHex, toHex } from "@mysten/sui/utils";
|
|
15
15
|
/* ============================== ID =============================== */
|
|
16
16
|
export function isID(type) {
|
|
17
17
|
type = compressSuiType(type);
|
|
@@ -39,8 +39,6 @@ export class ID {
|
|
|
39
39
|
bcs: ID.bcs,
|
|
40
40
|
fromJSONField: (field) => ID.fromJSONField(field),
|
|
41
41
|
fromJSON: (json) => ID.fromJSON(json),
|
|
42
|
-
fromSuiParsedData: (content) => ID.fromSuiParsedData(content),
|
|
43
|
-
fromSuiObjectData: (content) => ID.fromSuiObjectData(content),
|
|
44
42
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return ID.fetch(client, id); }),
|
|
45
43
|
new: (fields) => {
|
|
46
44
|
return new ID([], fields);
|
|
@@ -102,38 +100,13 @@ export class ID {
|
|
|
102
100
|
}
|
|
103
101
|
return ID.fromJSONField(json);
|
|
104
102
|
}
|
|
105
|
-
static fromSuiParsedData(content) {
|
|
106
|
-
if (content.dataType !== "moveObject") {
|
|
107
|
-
throw new Error("not an object");
|
|
108
|
-
}
|
|
109
|
-
if (!isID(content.type)) {
|
|
110
|
-
throw new Error(`object at ${content.fields.id} is not a ID object`);
|
|
111
|
-
}
|
|
112
|
-
return ID.fromFieldsWithTypes(content);
|
|
113
|
-
}
|
|
114
|
-
static fromSuiObjectData(data) {
|
|
115
|
-
if (data.bcs) {
|
|
116
|
-
if (data.bcs.dataType !== "moveObject" || !isID(data.bcs.type)) {
|
|
117
|
-
throw new Error(`object at is not a ID object`);
|
|
118
|
-
}
|
|
119
|
-
return ID.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
120
|
-
}
|
|
121
|
-
if (data.content) {
|
|
122
|
-
return ID.fromSuiParsedData(data.content);
|
|
123
|
-
}
|
|
124
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
125
|
-
}
|
|
126
103
|
static fetch(client, id) {
|
|
127
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (res.error) {
|
|
131
|
-
throw new Error(`error fetching ID object at id ${id}: ${res.error.code}`);
|
|
132
|
-
}
|
|
133
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" || !isID(res.data.bcs.type)) {
|
|
105
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
106
|
+
if (!isID(object.type)) {
|
|
134
107
|
throw new Error(`object at id ${id} is not a ID object`);
|
|
135
108
|
}
|
|
136
|
-
return ID.
|
|
109
|
+
return ID.fromBcs(object.content);
|
|
137
110
|
});
|
|
138
111
|
}
|
|
139
112
|
}
|
|
@@ -167,8 +140,6 @@ export class UID {
|
|
|
167
140
|
bcs: UID.bcs,
|
|
168
141
|
fromJSONField: (field) => UID.fromJSONField(field),
|
|
169
142
|
fromJSON: (json) => UID.fromJSON(json),
|
|
170
|
-
fromSuiParsedData: (content) => UID.fromSuiParsedData(content),
|
|
171
|
-
fromSuiObjectData: (content) => UID.fromSuiObjectData(content),
|
|
172
143
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return UID.fetch(client, id); }),
|
|
173
144
|
new: (fields) => {
|
|
174
145
|
return new UID([], fields);
|
|
@@ -223,38 +194,13 @@ export class UID {
|
|
|
223
194
|
}
|
|
224
195
|
return UID.fromJSONField(json);
|
|
225
196
|
}
|
|
226
|
-
static fromSuiParsedData(content) {
|
|
227
|
-
if (content.dataType !== "moveObject") {
|
|
228
|
-
throw new Error("not an object");
|
|
229
|
-
}
|
|
230
|
-
if (!isUID(content.type)) {
|
|
231
|
-
throw new Error(`object at ${content.fields.id} is not a UID object`);
|
|
232
|
-
}
|
|
233
|
-
return UID.fromFieldsWithTypes(content);
|
|
234
|
-
}
|
|
235
|
-
static fromSuiObjectData(data) {
|
|
236
|
-
if (data.bcs) {
|
|
237
|
-
if (data.bcs.dataType !== "moveObject" || !isUID(data.bcs.type)) {
|
|
238
|
-
throw new Error(`object at is not a UID object`);
|
|
239
|
-
}
|
|
240
|
-
return UID.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
241
|
-
}
|
|
242
|
-
if (data.content) {
|
|
243
|
-
return UID.fromSuiParsedData(data.content);
|
|
244
|
-
}
|
|
245
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
246
|
-
}
|
|
247
197
|
static fetch(client, id) {
|
|
248
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (res.error) {
|
|
252
|
-
throw new Error(`error fetching UID object at id ${id}: ${res.error.code}`);
|
|
253
|
-
}
|
|
254
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" || !isUID(res.data.bcs.type)) {
|
|
199
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
200
|
+
if (!isUID(object.type)) {
|
|
255
201
|
throw new Error(`object at id ${id} is not a UID object`);
|
|
256
202
|
}
|
|
257
|
-
return UID.
|
|
203
|
+
return UID.fromBcs(object.content);
|
|
258
204
|
});
|
|
259
205
|
}
|
|
260
206
|
}
|
|
@@ -2,7 +2,7 @@ import { PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructC
|
|
|
2
2
|
import { FieldsWithTypes } from "../../../../_framework/util";
|
|
3
3
|
import { PKG_V30 } from "../index";
|
|
4
4
|
import { UID } from "../object/structs";
|
|
5
|
-
import {
|
|
5
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
6
6
|
export declare function isObjectTable(type: string): boolean;
|
|
7
7
|
export interface ObjectTableFields<K extends PhantomTypeArgument, V extends PhantomTypeArgument> {
|
|
8
8
|
id: ToField<UID>;
|
|
@@ -25,13 +25,13 @@ export declare class ObjectTable<K extends PhantomTypeArgument, V extends Phanto
|
|
|
25
25
|
static get r(): typeof ObjectTable.reified;
|
|
26
26
|
static phantom<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(K: K, V: V): PhantomReified<ToTypeStr<ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>>>;
|
|
27
27
|
static get p(): typeof ObjectTable.phantom;
|
|
28
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
29
|
-
id: import("@mysten/bcs").BcsStruct<{
|
|
30
|
-
id: import("@mysten/bcs").BcsStruct<{
|
|
31
|
-
bytes: import("@mysten/bcs").BcsType<string, string, string>;
|
|
28
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
29
|
+
id: import("@mysten/sui/bcs").BcsStruct<{
|
|
30
|
+
id: import("@mysten/sui/bcs").BcsStruct<{
|
|
31
|
+
bytes: import("@mysten/sui/bcs").BcsType<string, string, string>;
|
|
32
32
|
}, string>;
|
|
33
33
|
}, string>;
|
|
34
|
-
size: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
34
|
+
size: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
35
35
|
}, string>;
|
|
36
36
|
static fromFields<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], fields: Record<string, any>): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
37
37
|
static fromFieldsWithTypes<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], item: FieldsWithTypes): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
@@ -48,7 +48,5 @@ export declare class ObjectTable<K extends PhantomTypeArgument, V extends Phanto
|
|
|
48
48
|
};
|
|
49
49
|
static fromJSONField<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], field: any): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
50
50
|
static fromJSON<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], json: Record<string, any>): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
51
|
-
static
|
|
52
|
-
static fromSuiObjectData<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(typeArgs: [K, V], data: SuiObjectData): ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>;
|
|
53
|
-
static fetch<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(client: SuiJsonRpcClient, typeArgs: [K, V], id: string): Promise<ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>>;
|
|
51
|
+
static fetch<K extends PhantomReified<PhantomTypeArgument>, V extends PhantomReified<PhantomTypeArgument>>(client: SuiGrpcClient, typeArgs: [K, V], id: string): Promise<ObjectTable<ToPhantomTypeArgument<K>, ToPhantomTypeArgument<V>>>;
|
|
54
52
|
}
|
|
@@ -8,11 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, } from "../../../../_framework/reified";
|
|
11
|
-
import { composeSuiType, compressSuiType,
|
|
11
|
+
import { composeSuiType, compressSuiType, } from "../../../../_framework/util";
|
|
12
12
|
import { PKG_V30 } from "../index";
|
|
13
13
|
import { UID } from "../object/structs";
|
|
14
14
|
import { bcs } from "@mysten/sui/bcs";
|
|
15
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
16
15
|
/* ============================== ObjectTable =============================== */
|
|
17
16
|
export function isObjectTable(type) {
|
|
18
17
|
type = compressSuiType(type);
|
|
@@ -41,8 +40,6 @@ export class ObjectTable {
|
|
|
41
40
|
bcs: ObjectTable.bcs,
|
|
42
41
|
fromJSONField: (field) => ObjectTable.fromJSONField([K, V], field),
|
|
43
42
|
fromJSON: (json) => ObjectTable.fromJSON([K, V], json),
|
|
44
|
-
fromSuiParsedData: (content) => ObjectTable.fromSuiParsedData([K, V], content),
|
|
45
|
-
fromSuiObjectData: (content) => ObjectTable.fromSuiObjectData([K, V], content),
|
|
46
43
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return ObjectTable.fetch(client, [K, V], id); }),
|
|
47
44
|
new: (fields) => {
|
|
48
45
|
return new ObjectTable([extractType(K), extractType(V)], fields);
|
|
@@ -106,50 +103,13 @@ export class ObjectTable {
|
|
|
106
103
|
assertReifiedTypeArgsMatch(composeSuiType(ObjectTable.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
|
|
107
104
|
return ObjectTable.fromJSONField(typeArgs, json);
|
|
108
105
|
}
|
|
109
|
-
static fromSuiParsedData(typeArgs, content) {
|
|
110
|
-
if (content.dataType !== "moveObject") {
|
|
111
|
-
throw new Error("not an object");
|
|
112
|
-
}
|
|
113
|
-
if (!isObjectTable(content.type)) {
|
|
114
|
-
throw new Error(`object at ${content.fields.id} is not a ObjectTable object`);
|
|
115
|
-
}
|
|
116
|
-
return ObjectTable.fromFieldsWithTypes(typeArgs, content);
|
|
117
|
-
}
|
|
118
|
-
static fromSuiObjectData(typeArgs, data) {
|
|
119
|
-
if (data.bcs) {
|
|
120
|
-
if (data.bcs.dataType !== "moveObject" || !isObjectTable(data.bcs.type)) {
|
|
121
|
-
throw new Error(`object at is not a ObjectTable object`);
|
|
122
|
-
}
|
|
123
|
-
const gotTypeArgs = parseTypeName(data.bcs.type).typeArgs;
|
|
124
|
-
if (gotTypeArgs.length !== 2) {
|
|
125
|
-
throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`);
|
|
126
|
-
}
|
|
127
|
-
for (let i = 0; i < 2; i++) {
|
|
128
|
-
const gotTypeArg = compressSuiType(gotTypeArgs[i]);
|
|
129
|
-
const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
|
|
130
|
-
if (gotTypeArg !== expectedTypeArg) {
|
|
131
|
-
throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return ObjectTable.fromBcs(typeArgs, fromBase64(data.bcs.bcsBytes));
|
|
135
|
-
}
|
|
136
|
-
if (data.content) {
|
|
137
|
-
return ObjectTable.fromSuiParsedData(typeArgs, data.content);
|
|
138
|
-
}
|
|
139
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
140
|
-
}
|
|
141
106
|
static fetch(client, typeArgs, id) {
|
|
142
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (res.error) {
|
|
146
|
-
throw new Error(`error fetching ObjectTable object at id ${id}: ${res.error.code}`);
|
|
147
|
-
}
|
|
148
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
149
|
-
!isObjectTable(res.data.bcs.type)) {
|
|
108
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
109
|
+
if (!isObjectTable(object.type)) {
|
|
150
110
|
throw new Error(`object at id ${id} is not a ObjectTable object`);
|
|
151
111
|
}
|
|
152
|
-
return ObjectTable.
|
|
112
|
+
return ObjectTable.fromBcs(typeArgs, object.content);
|
|
153
113
|
});
|
|
154
114
|
}
|
|
155
115
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../../../_framework/reified";
|
|
2
2
|
import { FieldsWithTypes } from "../../../../_framework/util";
|
|
3
3
|
import { PKG_V1 } from "../index";
|
|
4
|
-
import {
|
|
4
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
5
5
|
export declare function isI64(type: string): boolean;
|
|
6
6
|
export interface I64Fields {
|
|
7
7
|
negative: ToField<"bool">;
|
|
@@ -24,9 +24,9 @@ export declare class I64 implements StructClass {
|
|
|
24
24
|
static get r(): import("../../../../_framework/reified").StructClassReified<I64, I64Fields>;
|
|
25
25
|
static phantom(): PhantomReified<ToTypeStr<I64>>;
|
|
26
26
|
static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::i64::I64">;
|
|
27
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
28
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
29
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
27
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
28
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
29
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
30
30
|
}, string>;
|
|
31
31
|
static fromFields(fields: Record<string, any>): I64;
|
|
32
32
|
static fromFieldsWithTypes(item: FieldsWithTypes): I64;
|
|
@@ -43,7 +43,5 @@ export declare class I64 implements StructClass {
|
|
|
43
43
|
};
|
|
44
44
|
static fromJSONField(field: any): I64;
|
|
45
45
|
static fromJSON(json: Record<string, any>): I64;
|
|
46
|
-
static
|
|
47
|
-
static fromSuiObjectData(data: SuiObjectData): I64;
|
|
48
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<I64>;
|
|
46
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<I64>;
|
|
49
47
|
}
|
|
@@ -11,7 +11,6 @@ import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phant
|
|
|
11
11
|
import { composeSuiType, compressSuiType, } from "../../../../_framework/util";
|
|
12
12
|
import { PKG_V1 } from "../index";
|
|
13
13
|
import { bcs } from "@mysten/sui/bcs";
|
|
14
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
15
14
|
/* ============================== I64 =============================== */
|
|
16
15
|
export function isI64(type) {
|
|
17
16
|
type = compressSuiType(type);
|
|
@@ -40,8 +39,6 @@ export class I64 {
|
|
|
40
39
|
bcs: I64.bcs,
|
|
41
40
|
fromJSONField: (field) => I64.fromJSONField(field),
|
|
42
41
|
fromJSON: (json) => I64.fromJSON(json),
|
|
43
|
-
fromSuiParsedData: (content) => I64.fromSuiParsedData(content),
|
|
44
|
-
fromSuiObjectData: (content) => I64.fromSuiObjectData(content),
|
|
45
42
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return I64.fetch(client, id); }),
|
|
46
43
|
new: (fields) => {
|
|
47
44
|
return new I64([], fields);
|
|
@@ -103,38 +100,13 @@ export class I64 {
|
|
|
103
100
|
}
|
|
104
101
|
return I64.fromJSONField(json);
|
|
105
102
|
}
|
|
106
|
-
static fromSuiParsedData(content) {
|
|
107
|
-
if (content.dataType !== "moveObject") {
|
|
108
|
-
throw new Error("not an object");
|
|
109
|
-
}
|
|
110
|
-
if (!isI64(content.type)) {
|
|
111
|
-
throw new Error(`object at ${content.fields.id} is not a I64 object`);
|
|
112
|
-
}
|
|
113
|
-
return I64.fromFieldsWithTypes(content);
|
|
114
|
-
}
|
|
115
|
-
static fromSuiObjectData(data) {
|
|
116
|
-
if (data.bcs) {
|
|
117
|
-
if (data.bcs.dataType !== "moveObject" || !isI64(data.bcs.type)) {
|
|
118
|
-
throw new Error(`object at is not a I64 object`);
|
|
119
|
-
}
|
|
120
|
-
return I64.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
121
|
-
}
|
|
122
|
-
if (data.content) {
|
|
123
|
-
return I64.fromSuiParsedData(data.content);
|
|
124
|
-
}
|
|
125
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
126
|
-
}
|
|
127
103
|
static fetch(client, id) {
|
|
128
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (res.error) {
|
|
132
|
-
throw new Error(`error fetching I64 object at id ${id}: ${res.error.code}`);
|
|
133
|
-
}
|
|
134
|
-
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)) {
|
|
105
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
106
|
+
if (!isI64(object.type)) {
|
|
135
107
|
throw new Error(`object at id ${id} is not a I64 object`);
|
|
136
108
|
}
|
|
137
|
-
return I64.
|
|
109
|
+
return I64.fromBcs(object.content);
|
|
138
110
|
});
|
|
139
111
|
}
|
|
140
112
|
}
|
|
@@ -2,7 +2,7 @@ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../
|
|
|
2
2
|
import { FieldsWithTypes } from "../../../../_framework/util";
|
|
3
3
|
import { I64 } from "../i64/structs";
|
|
4
4
|
import { PKG_V1 } from "../index";
|
|
5
|
-
import {
|
|
5
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
6
6
|
export declare function isPrice(type: string): boolean;
|
|
7
7
|
export interface PriceFields {
|
|
8
8
|
price: ToField<I64>;
|
|
@@ -29,17 +29,17 @@ export declare class Price implements StructClass {
|
|
|
29
29
|
static get r(): import("../../../../_framework/reified").StructClassReified<Price, PriceFields>;
|
|
30
30
|
static phantom(): PhantomReified<ToTypeStr<Price>>;
|
|
31
31
|
static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price::Price">;
|
|
32
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
33
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
34
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
35
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
32
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
33
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
34
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
35
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
36
36
|
}, string>;
|
|
37
|
-
conf: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
38
|
-
expo: import("@mysten/bcs").BcsStruct<{
|
|
39
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
40
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
37
|
+
conf: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
38
|
+
expo: import("@mysten/sui/bcs").BcsStruct<{
|
|
39
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
40
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
41
41
|
}, string>;
|
|
42
|
-
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
42
|
+
timestamp: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
43
43
|
}, string>;
|
|
44
44
|
static fromFields(fields: Record<string, any>): Price;
|
|
45
45
|
static fromFieldsWithTypes(item: FieldsWithTypes): Price;
|
|
@@ -72,7 +72,5 @@ export declare class Price implements StructClass {
|
|
|
72
72
|
};
|
|
73
73
|
static fromJSONField(field: any): Price;
|
|
74
74
|
static fromJSON(json: Record<string, any>): Price;
|
|
75
|
-
static
|
|
76
|
-
static fromSuiObjectData(data: SuiObjectData): Price;
|
|
77
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<Price>;
|
|
75
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<Price>;
|
|
78
76
|
}
|
|
@@ -12,7 +12,6 @@ import { composeSuiType, compressSuiType, } from "../../../../_framework/util";
|
|
|
12
12
|
import { I64 } from "../i64/structs";
|
|
13
13
|
import { PKG_V1 } from "../index";
|
|
14
14
|
import { bcs } from "@mysten/sui/bcs";
|
|
15
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
16
15
|
/* ============================== Price =============================== */
|
|
17
16
|
export function isPrice(type) {
|
|
18
17
|
type = compressSuiType(type);
|
|
@@ -43,8 +42,6 @@ export class Price {
|
|
|
43
42
|
bcs: Price.bcs,
|
|
44
43
|
fromJSONField: (field) => Price.fromJSONField(field),
|
|
45
44
|
fromJSON: (json) => Price.fromJSON(json),
|
|
46
|
-
fromSuiParsedData: (content) => Price.fromSuiParsedData(content),
|
|
47
|
-
fromSuiObjectData: (content) => Price.fromSuiObjectData(content),
|
|
48
45
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Price.fetch(client, id); }),
|
|
49
46
|
new: (fields) => {
|
|
50
47
|
return new Price([], fields);
|
|
@@ -116,39 +113,13 @@ export class Price {
|
|
|
116
113
|
}
|
|
117
114
|
return Price.fromJSONField(json);
|
|
118
115
|
}
|
|
119
|
-
static fromSuiParsedData(content) {
|
|
120
|
-
if (content.dataType !== "moveObject") {
|
|
121
|
-
throw new Error("not an object");
|
|
122
|
-
}
|
|
123
|
-
if (!isPrice(content.type)) {
|
|
124
|
-
throw new Error(`object at ${content.fields.id} is not a Price object`);
|
|
125
|
-
}
|
|
126
|
-
return Price.fromFieldsWithTypes(content);
|
|
127
|
-
}
|
|
128
|
-
static fromSuiObjectData(data) {
|
|
129
|
-
if (data.bcs) {
|
|
130
|
-
if (data.bcs.dataType !== "moveObject" || !isPrice(data.bcs.type)) {
|
|
131
|
-
throw new Error(`object at is not a Price object`);
|
|
132
|
-
}
|
|
133
|
-
return Price.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
134
|
-
}
|
|
135
|
-
if (data.content) {
|
|
136
|
-
return Price.fromSuiParsedData(data.content);
|
|
137
|
-
}
|
|
138
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
139
|
-
}
|
|
140
116
|
static fetch(client, id) {
|
|
141
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (res.error) {
|
|
145
|
-
throw new Error(`error fetching Price object at id ${id}: ${res.error.code}`);
|
|
146
|
-
}
|
|
147
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
148
|
-
!isPrice(res.data.bcs.type)) {
|
|
118
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
119
|
+
if (!isPrice(object.type)) {
|
|
149
120
|
throw new Error(`object at id ${id} is not a Price object`);
|
|
150
121
|
}
|
|
151
|
-
return Price.
|
|
122
|
+
return Price.fromBcs(object.content);
|
|
152
123
|
});
|
|
153
124
|
}
|
|
154
125
|
}
|
|
@@ -3,7 +3,7 @@ import { FieldsWithTypes } from "../../../../_framework/util";
|
|
|
3
3
|
import { PKG_V1 } from "../index";
|
|
4
4
|
import { PriceIdentifier } from "../price-identifier/structs";
|
|
5
5
|
import { Price } from "../price/structs";
|
|
6
|
-
import {
|
|
6
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
7
7
|
export declare function isPriceFeed(type: string): boolean;
|
|
8
8
|
export interface PriceFeedFields {
|
|
9
9
|
priceIdentifier: ToField<PriceIdentifier>;
|
|
@@ -28,35 +28,35 @@ export declare class PriceFeed implements StructClass {
|
|
|
28
28
|
static get r(): import("../../../../_framework/reified").StructClassReified<PriceFeed, PriceFeedFields>;
|
|
29
29
|
static phantom(): PhantomReified<ToTypeStr<PriceFeed>>;
|
|
30
30
|
static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price_feed::PriceFeed">;
|
|
31
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
32
|
-
price_identifier: import("@mysten/bcs").BcsStruct<{
|
|
33
|
-
bytes: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
31
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
32
|
+
price_identifier: import("@mysten/sui/bcs").BcsStruct<{
|
|
33
|
+
bytes: import("@mysten/sui/bcs").BcsType<number[], Iterable<number> & {
|
|
34
34
|
length: number;
|
|
35
35
|
}, string>;
|
|
36
36
|
}, string>;
|
|
37
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
38
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
39
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
40
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
37
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
38
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
39
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
40
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
41
41
|
}, string>;
|
|
42
|
-
conf: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
43
|
-
expo: import("@mysten/bcs").BcsStruct<{
|
|
44
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
45
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
42
|
+
conf: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
43
|
+
expo: import("@mysten/sui/bcs").BcsStruct<{
|
|
44
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
45
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
46
46
|
}, string>;
|
|
47
|
-
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
47
|
+
timestamp: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
48
48
|
}, string>;
|
|
49
|
-
ema_price: import("@mysten/bcs").BcsStruct<{
|
|
50
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
51
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
52
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
49
|
+
ema_price: import("@mysten/sui/bcs").BcsStruct<{
|
|
50
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
51
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
52
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
53
53
|
}, string>;
|
|
54
|
-
conf: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
55
|
-
expo: import("@mysten/bcs").BcsStruct<{
|
|
56
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
57
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
54
|
+
conf: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
55
|
+
expo: import("@mysten/sui/bcs").BcsStruct<{
|
|
56
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
57
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
58
58
|
}, string>;
|
|
59
|
-
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
59
|
+
timestamp: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
60
60
|
}, string>;
|
|
61
61
|
}, string>;
|
|
62
62
|
static fromFields(fields: Record<string, any>): PriceFeed;
|
|
@@ -124,7 +124,5 @@ export declare class PriceFeed implements StructClass {
|
|
|
124
124
|
};
|
|
125
125
|
static fromJSONField(field: any): PriceFeed;
|
|
126
126
|
static fromJSON(json: Record<string, any>): PriceFeed;
|
|
127
|
-
static
|
|
128
|
-
static fromSuiObjectData(data: SuiObjectData): PriceFeed;
|
|
129
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<PriceFeed>;
|
|
127
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<PriceFeed>;
|
|
130
128
|
}
|
|
@@ -13,7 +13,6 @@ import { PKG_V1 } from "../index";
|
|
|
13
13
|
import { PriceIdentifier } from "../price-identifier/structs";
|
|
14
14
|
import { Price } from "../price/structs";
|
|
15
15
|
import { bcs } from "@mysten/sui/bcs";
|
|
16
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
17
16
|
/* ============================== PriceFeed =============================== */
|
|
18
17
|
export function isPriceFeed(type) {
|
|
19
18
|
type = compressSuiType(type);
|
|
@@ -43,8 +42,6 @@ export class PriceFeed {
|
|
|
43
42
|
bcs: PriceFeed.bcs,
|
|
44
43
|
fromJSONField: (field) => PriceFeed.fromJSONField(field),
|
|
45
44
|
fromJSON: (json) => PriceFeed.fromJSON(json),
|
|
46
|
-
fromSuiParsedData: (content) => PriceFeed.fromSuiParsedData(content),
|
|
47
|
-
fromSuiObjectData: (content) => PriceFeed.fromSuiObjectData(content),
|
|
48
45
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return PriceFeed.fetch(client, id); }),
|
|
49
46
|
new: (fields) => {
|
|
50
47
|
return new PriceFeed([], fields);
|
|
@@ -111,39 +108,13 @@ export class PriceFeed {
|
|
|
111
108
|
}
|
|
112
109
|
return PriceFeed.fromJSONField(json);
|
|
113
110
|
}
|
|
114
|
-
static fromSuiParsedData(content) {
|
|
115
|
-
if (content.dataType !== "moveObject") {
|
|
116
|
-
throw new Error("not an object");
|
|
117
|
-
}
|
|
118
|
-
if (!isPriceFeed(content.type)) {
|
|
119
|
-
throw new Error(`object at ${content.fields.id} is not a PriceFeed object`);
|
|
120
|
-
}
|
|
121
|
-
return PriceFeed.fromFieldsWithTypes(content);
|
|
122
|
-
}
|
|
123
|
-
static fromSuiObjectData(data) {
|
|
124
|
-
if (data.bcs) {
|
|
125
|
-
if (data.bcs.dataType !== "moveObject" || !isPriceFeed(data.bcs.type)) {
|
|
126
|
-
throw new Error(`object at is not a PriceFeed object`);
|
|
127
|
-
}
|
|
128
|
-
return PriceFeed.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
129
|
-
}
|
|
130
|
-
if (data.content) {
|
|
131
|
-
return PriceFeed.fromSuiParsedData(data.content);
|
|
132
|
-
}
|
|
133
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
134
|
-
}
|
|
135
111
|
static fetch(client, id) {
|
|
136
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (res.error) {
|
|
140
|
-
throw new Error(`error fetching PriceFeed object at id ${id}: ${res.error.code}`);
|
|
141
|
-
}
|
|
142
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
143
|
-
!isPriceFeed(res.data.bcs.type)) {
|
|
113
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
114
|
+
if (!isPriceFeed(object.type)) {
|
|
144
115
|
throw new Error(`object at id ${id} is not a PriceFeed object`);
|
|
145
116
|
}
|
|
146
|
-
return PriceFeed.
|
|
117
|
+
return PriceFeed.fromBcs(object.content);
|
|
147
118
|
});
|
|
148
119
|
}
|
|
149
120
|
}
|
|
@@ -3,7 +3,7 @@ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../
|
|
|
3
3
|
import { FieldsWithTypes } from "../../../../_framework/util";
|
|
4
4
|
import { Vector } from "../../../../_framework/vector";
|
|
5
5
|
import { PKG_V1 } from "../index";
|
|
6
|
-
import {
|
|
6
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
7
7
|
export declare function isPriceIdentifier(type: string): boolean;
|
|
8
8
|
export interface PriceIdentifierFields {
|
|
9
9
|
bytes: ToField<Vector<"u8">>;
|
|
@@ -24,8 +24,8 @@ export declare class PriceIdentifier implements StructClass {
|
|
|
24
24
|
static get r(): reified.StructClassReified<PriceIdentifier, PriceIdentifierFields>;
|
|
25
25
|
static phantom(): PhantomReified<ToTypeStr<PriceIdentifier>>;
|
|
26
26
|
static get p(): reified.PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price_identifier::PriceIdentifier">;
|
|
27
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
28
|
-
bytes: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
27
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
28
|
+
bytes: import("@mysten/sui/bcs").BcsType<number[], Iterable<number> & {
|
|
29
29
|
length: number;
|
|
30
30
|
}, string>;
|
|
31
31
|
}, string>;
|
|
@@ -42,7 +42,5 @@ export declare class PriceIdentifier implements StructClass {
|
|
|
42
42
|
};
|
|
43
43
|
static fromJSONField(field: any): PriceIdentifier;
|
|
44
44
|
static fromJSON(json: Record<string, any>): PriceIdentifier;
|
|
45
|
-
static
|
|
46
|
-
static fromSuiObjectData(data: SuiObjectData): PriceIdentifier;
|
|
47
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<PriceIdentifier>;
|
|
45
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<PriceIdentifier>;
|
|
48
46
|
}
|