@suilend/sdk 2.0.3 → 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
|
@@ -12,7 +12,6 @@ import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, field
|
|
|
12
12
|
import { composeSuiType, compressSuiType, } from "../../../../_framework/util";
|
|
13
13
|
import { PKG_V1 } from "../index";
|
|
14
14
|
import { bcs } from "@mysten/sui/bcs";
|
|
15
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
16
15
|
/* ============================== PriceIdentifier =============================== */
|
|
17
16
|
export function isPriceIdentifier(type) {
|
|
18
17
|
type = compressSuiType(type);
|
|
@@ -40,8 +39,6 @@ export class PriceIdentifier {
|
|
|
40
39
|
bcs: PriceIdentifier.bcs,
|
|
41
40
|
fromJSONField: (field) => PriceIdentifier.fromJSONField(field),
|
|
42
41
|
fromJSON: (json) => PriceIdentifier.fromJSON(json),
|
|
43
|
-
fromSuiParsedData: (content) => PriceIdentifier.fromSuiParsedData(content),
|
|
44
|
-
fromSuiObjectData: (content) => PriceIdentifier.fromSuiObjectData(content),
|
|
45
42
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return PriceIdentifier.fetch(client, id); }),
|
|
46
43
|
new: (fields) => {
|
|
47
44
|
return new PriceIdentifier([], fields);
|
|
@@ -98,40 +95,13 @@ export class PriceIdentifier {
|
|
|
98
95
|
}
|
|
99
96
|
return PriceIdentifier.fromJSONField(json);
|
|
100
97
|
}
|
|
101
|
-
static fromSuiParsedData(content) {
|
|
102
|
-
if (content.dataType !== "moveObject") {
|
|
103
|
-
throw new Error("not an object");
|
|
104
|
-
}
|
|
105
|
-
if (!isPriceIdentifier(content.type)) {
|
|
106
|
-
throw new Error(`object at ${content.fields.id} is not a PriceIdentifier object`);
|
|
107
|
-
}
|
|
108
|
-
return PriceIdentifier.fromFieldsWithTypes(content);
|
|
109
|
-
}
|
|
110
|
-
static fromSuiObjectData(data) {
|
|
111
|
-
if (data.bcs) {
|
|
112
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
113
|
-
!isPriceIdentifier(data.bcs.type)) {
|
|
114
|
-
throw new Error(`object at is not a PriceIdentifier object`);
|
|
115
|
-
}
|
|
116
|
-
return PriceIdentifier.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
117
|
-
}
|
|
118
|
-
if (data.content) {
|
|
119
|
-
return PriceIdentifier.fromSuiParsedData(data.content);
|
|
120
|
-
}
|
|
121
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
122
|
-
}
|
|
123
98
|
static fetch(client, id) {
|
|
124
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (res.error) {
|
|
128
|
-
throw new Error(`error fetching PriceIdentifier object at id ${id}: ${res.error.code}`);
|
|
129
|
-
}
|
|
130
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
131
|
-
!isPriceIdentifier(res.data.bcs.type)) {
|
|
100
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
101
|
+
if (!isPriceIdentifier(object.type)) {
|
|
132
102
|
throw new Error(`object at id ${id} is not a PriceIdentifier object`);
|
|
133
103
|
}
|
|
134
|
-
return PriceIdentifier.
|
|
104
|
+
return PriceIdentifier.fromBcs(object.content);
|
|
135
105
|
});
|
|
136
106
|
}
|
|
137
107
|
}
|
|
@@ -3,7 +3,7 @@ import { FieldsWithTypes } from "../../../../_framework/util";
|
|
|
3
3
|
import { UID } from "../../0x2/object/structs";
|
|
4
4
|
import { PKG_V1 } from "../index";
|
|
5
5
|
import { PriceFeed } from "../price-feed/structs";
|
|
6
|
-
import {
|
|
6
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
7
7
|
export declare function isPriceInfo(type: string): boolean;
|
|
8
8
|
export interface PriceInfoFields {
|
|
9
9
|
attestationTime: ToField<"u64">;
|
|
@@ -28,38 +28,38 @@ export declare class PriceInfo implements StructClass {
|
|
|
28
28
|
static get r(): import("../../../../_framework/reified").StructClassReified<PriceInfo, PriceInfoFields>;
|
|
29
29
|
static phantom(): PhantomReified<ToTypeStr<PriceInfo>>;
|
|
30
30
|
static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price_info::PriceInfo">;
|
|
31
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
32
|
-
attestation_time: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
33
|
-
arrival_time: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
34
|
-
price_feed: import("@mysten/bcs").BcsStruct<{
|
|
35
|
-
price_identifier: import("@mysten/bcs").BcsStruct<{
|
|
36
|
-
bytes: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
31
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
32
|
+
attestation_time: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
33
|
+
arrival_time: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
34
|
+
price_feed: import("@mysten/sui/bcs").BcsStruct<{
|
|
35
|
+
price_identifier: import("@mysten/sui/bcs").BcsStruct<{
|
|
36
|
+
bytes: import("@mysten/sui/bcs").BcsType<number[], Iterable<number> & {
|
|
37
37
|
length: number;
|
|
38
38
|
}, string>;
|
|
39
39
|
}, string>;
|
|
40
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
41
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
42
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
43
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
40
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
41
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
42
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
43
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
44
44
|
}, string>;
|
|
45
|
-
conf: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
46
|
-
expo: import("@mysten/bcs").BcsStruct<{
|
|
47
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
48
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
45
|
+
conf: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
46
|
+
expo: import("@mysten/sui/bcs").BcsStruct<{
|
|
47
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
48
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
49
49
|
}, string>;
|
|
50
|
-
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
50
|
+
timestamp: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
51
51
|
}, string>;
|
|
52
|
-
ema_price: import("@mysten/bcs").BcsStruct<{
|
|
53
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
54
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
55
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
52
|
+
ema_price: import("@mysten/sui/bcs").BcsStruct<{
|
|
53
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
54
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
55
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
56
56
|
}, string>;
|
|
57
|
-
conf: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
58
|
-
expo: import("@mysten/bcs").BcsStruct<{
|
|
59
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
60
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
57
|
+
conf: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
58
|
+
expo: import("@mysten/sui/bcs").BcsStruct<{
|
|
59
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
60
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
61
61
|
}, string>;
|
|
62
|
-
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
62
|
+
timestamp: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
63
63
|
}, string>;
|
|
64
64
|
}, string>;
|
|
65
65
|
}, string>;
|
|
@@ -136,9 +136,7 @@ export declare class PriceInfo implements StructClass {
|
|
|
136
136
|
};
|
|
137
137
|
static fromJSONField(field: any): PriceInfo;
|
|
138
138
|
static fromJSON(json: Record<string, any>): PriceInfo;
|
|
139
|
-
static
|
|
140
|
-
static fromSuiObjectData(data: SuiObjectData): PriceInfo;
|
|
141
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<PriceInfo>;
|
|
139
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<PriceInfo>;
|
|
142
140
|
}
|
|
143
141
|
export declare function isPriceInfoObject(type: string): boolean;
|
|
144
142
|
export interface PriceInfoObjectFields {
|
|
@@ -162,44 +160,44 @@ export declare class PriceInfoObject implements StructClass {
|
|
|
162
160
|
static get r(): import("../../../../_framework/reified").StructClassReified<PriceInfoObject, PriceInfoObjectFields>;
|
|
163
161
|
static phantom(): PhantomReified<ToTypeStr<PriceInfoObject>>;
|
|
164
162
|
static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price_info::PriceInfoObject">;
|
|
165
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
166
|
-
id: import("@mysten/bcs").BcsStruct<{
|
|
167
|
-
id: import("@mysten/bcs").BcsStruct<{
|
|
168
|
-
bytes: import("@mysten/bcs").BcsType<string, string, string>;
|
|
163
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
164
|
+
id: import("@mysten/sui/bcs").BcsStruct<{
|
|
165
|
+
id: import("@mysten/sui/bcs").BcsStruct<{
|
|
166
|
+
bytes: import("@mysten/sui/bcs").BcsType<string, string, string>;
|
|
169
167
|
}, string>;
|
|
170
168
|
}, string>;
|
|
171
|
-
price_info: import("@mysten/bcs").BcsStruct<{
|
|
172
|
-
attestation_time: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
173
|
-
arrival_time: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
174
|
-
price_feed: import("@mysten/bcs").BcsStruct<{
|
|
175
|
-
price_identifier: import("@mysten/bcs").BcsStruct<{
|
|
176
|
-
bytes: import("@mysten/bcs").BcsType<number[], Iterable<number> & {
|
|
169
|
+
price_info: import("@mysten/sui/bcs").BcsStruct<{
|
|
170
|
+
attestation_time: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
171
|
+
arrival_time: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
172
|
+
price_feed: import("@mysten/sui/bcs").BcsStruct<{
|
|
173
|
+
price_identifier: import("@mysten/sui/bcs").BcsStruct<{
|
|
174
|
+
bytes: import("@mysten/sui/bcs").BcsType<number[], Iterable<number> & {
|
|
177
175
|
length: number;
|
|
178
176
|
}, string>;
|
|
179
177
|
}, string>;
|
|
180
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
181
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
182
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
183
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
178
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
179
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
180
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
181
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
184
182
|
}, string>;
|
|
185
|
-
conf: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
186
|
-
expo: import("@mysten/bcs").BcsStruct<{
|
|
187
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
188
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
183
|
+
conf: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
184
|
+
expo: import("@mysten/sui/bcs").BcsStruct<{
|
|
185
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
186
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
189
187
|
}, string>;
|
|
190
|
-
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
188
|
+
timestamp: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
191
189
|
}, string>;
|
|
192
|
-
ema_price: import("@mysten/bcs").BcsStruct<{
|
|
193
|
-
price: import("@mysten/bcs").BcsStruct<{
|
|
194
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
195
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
190
|
+
ema_price: import("@mysten/sui/bcs").BcsStruct<{
|
|
191
|
+
price: import("@mysten/sui/bcs").BcsStruct<{
|
|
192
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
193
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
196
194
|
}, string>;
|
|
197
|
-
conf: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
198
|
-
expo: import("@mysten/bcs").BcsStruct<{
|
|
199
|
-
negative: import("@mysten/bcs").BcsType<boolean, boolean, "bool">;
|
|
200
|
-
magnitude: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
195
|
+
conf: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
196
|
+
expo: import("@mysten/sui/bcs").BcsStruct<{
|
|
197
|
+
negative: import("@mysten/sui/bcs").BcsType<boolean, boolean, "bool">;
|
|
198
|
+
magnitude: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
201
199
|
}, string>;
|
|
202
|
-
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
200
|
+
timestamp: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
203
201
|
}, string>;
|
|
204
202
|
}, string>;
|
|
205
203
|
}, string>;
|
|
@@ -283,7 +281,5 @@ export declare class PriceInfoObject implements StructClass {
|
|
|
283
281
|
};
|
|
284
282
|
static fromJSONField(field: any): PriceInfoObject;
|
|
285
283
|
static fromJSON(json: Record<string, any>): PriceInfoObject;
|
|
286
|
-
static
|
|
287
|
-
static fromSuiObjectData(data: SuiObjectData): PriceInfoObject;
|
|
288
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<PriceInfoObject>;
|
|
284
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<PriceInfoObject>;
|
|
289
285
|
}
|
|
@@ -13,7 +13,6 @@ import { UID } from "../../0x2/object/structs";
|
|
|
13
13
|
import { PKG_V1 } from "../index";
|
|
14
14
|
import { PriceFeed } from "../price-feed/structs";
|
|
15
15
|
import { bcs } from "@mysten/sui/bcs";
|
|
16
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
17
16
|
/* ============================== PriceInfo =============================== */
|
|
18
17
|
export function isPriceInfo(type) {
|
|
19
18
|
type = compressSuiType(type);
|
|
@@ -43,8 +42,6 @@ export class PriceInfo {
|
|
|
43
42
|
bcs: PriceInfo.bcs,
|
|
44
43
|
fromJSONField: (field) => PriceInfo.fromJSONField(field),
|
|
45
44
|
fromJSON: (json) => PriceInfo.fromJSON(json),
|
|
46
|
-
fromSuiParsedData: (content) => PriceInfo.fromSuiParsedData(content),
|
|
47
|
-
fromSuiObjectData: (content) => PriceInfo.fromSuiObjectData(content),
|
|
48
45
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return PriceInfo.fetch(client, id); }),
|
|
49
46
|
new: (fields) => {
|
|
50
47
|
return new PriceInfo([], fields);
|
|
@@ -111,39 +108,13 @@ export class PriceInfo {
|
|
|
111
108
|
}
|
|
112
109
|
return PriceInfo.fromJSONField(json);
|
|
113
110
|
}
|
|
114
|
-
static fromSuiParsedData(content) {
|
|
115
|
-
if (content.dataType !== "moveObject") {
|
|
116
|
-
throw new Error("not an object");
|
|
117
|
-
}
|
|
118
|
-
if (!isPriceInfo(content.type)) {
|
|
119
|
-
throw new Error(`object at ${content.fields.id} is not a PriceInfo object`);
|
|
120
|
-
}
|
|
121
|
-
return PriceInfo.fromFieldsWithTypes(content);
|
|
122
|
-
}
|
|
123
|
-
static fromSuiObjectData(data) {
|
|
124
|
-
if (data.bcs) {
|
|
125
|
-
if (data.bcs.dataType !== "moveObject" || !isPriceInfo(data.bcs.type)) {
|
|
126
|
-
throw new Error(`object at is not a PriceInfo object`);
|
|
127
|
-
}
|
|
128
|
-
return PriceInfo.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
129
|
-
}
|
|
130
|
-
if (data.content) {
|
|
131
|
-
return PriceInfo.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 PriceInfo 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
|
-
!isPriceInfo(res.data.bcs.type)) {
|
|
113
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
114
|
+
if (!isPriceInfo(object.type)) {
|
|
144
115
|
throw new Error(`object at id ${id} is not a PriceInfo object`);
|
|
145
116
|
}
|
|
146
|
-
return PriceInfo.
|
|
117
|
+
return PriceInfo.fromBcs(object.content);
|
|
147
118
|
});
|
|
148
119
|
}
|
|
149
120
|
}
|
|
@@ -178,8 +149,6 @@ export class PriceInfoObject {
|
|
|
178
149
|
bcs: PriceInfoObject.bcs,
|
|
179
150
|
fromJSONField: (field) => PriceInfoObject.fromJSONField(field),
|
|
180
151
|
fromJSON: (json) => PriceInfoObject.fromJSON(json),
|
|
181
|
-
fromSuiParsedData: (content) => PriceInfoObject.fromSuiParsedData(content),
|
|
182
|
-
fromSuiObjectData: (content) => PriceInfoObject.fromSuiObjectData(content),
|
|
183
152
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return PriceInfoObject.fetch(client, id); }),
|
|
184
153
|
new: (fields) => {
|
|
185
154
|
return new PriceInfoObject([], fields);
|
|
@@ -241,40 +210,13 @@ export class PriceInfoObject {
|
|
|
241
210
|
}
|
|
242
211
|
return PriceInfoObject.fromJSONField(json);
|
|
243
212
|
}
|
|
244
|
-
static fromSuiParsedData(content) {
|
|
245
|
-
if (content.dataType !== "moveObject") {
|
|
246
|
-
throw new Error("not an object");
|
|
247
|
-
}
|
|
248
|
-
if (!isPriceInfoObject(content.type)) {
|
|
249
|
-
throw new Error(`object at ${content.fields.id} is not a PriceInfoObject object`);
|
|
250
|
-
}
|
|
251
|
-
return PriceInfoObject.fromFieldsWithTypes(content);
|
|
252
|
-
}
|
|
253
|
-
static fromSuiObjectData(data) {
|
|
254
|
-
if (data.bcs) {
|
|
255
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
256
|
-
!isPriceInfoObject(data.bcs.type)) {
|
|
257
|
-
throw new Error(`object at is not a PriceInfoObject object`);
|
|
258
|
-
}
|
|
259
|
-
return PriceInfoObject.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
260
|
-
}
|
|
261
|
-
if (data.content) {
|
|
262
|
-
return PriceInfoObject.fromSuiParsedData(data.content);
|
|
263
|
-
}
|
|
264
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
265
|
-
}
|
|
266
213
|
static fetch(client, id) {
|
|
267
214
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (res.error) {
|
|
271
|
-
throw new Error(`error fetching PriceInfoObject object at id ${id}: ${res.error.code}`);
|
|
272
|
-
}
|
|
273
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
274
|
-
!isPriceInfoObject(res.data.bcs.type)) {
|
|
215
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
216
|
+
if (!isPriceInfoObject(object.type)) {
|
|
275
217
|
throw new Error(`object at id ${id} is not a PriceInfoObject object`);
|
|
276
218
|
}
|
|
277
|
-
return PriceInfoObject.
|
|
219
|
+
return PriceInfoObject.fromBcs(object.content);
|
|
278
220
|
});
|
|
279
221
|
}
|
|
280
222
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BcsType } from "@mysten/sui/bcs";
|
|
2
2
|
import { FieldsWithTypes } from "./util";
|
|
3
|
-
import {
|
|
3
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
4
4
|
export { vector } from "./vector";
|
|
5
5
|
export interface StructClass {
|
|
6
6
|
readonly $typeName: string;
|
|
@@ -35,9 +35,7 @@ export interface StructClassReified<T extends StructClass, Fields> {
|
|
|
35
35
|
fromBcs(data: Uint8Array): T;
|
|
36
36
|
fromJSONField: (field: any) => T;
|
|
37
37
|
fromJSON: (json: Record<string, any>) => T;
|
|
38
|
-
|
|
39
|
-
fromSuiObjectData: (data: SuiObjectData) => T;
|
|
40
|
-
fetch: (client: SuiJsonRpcClient, id: string) => Promise<T>;
|
|
38
|
+
fetch: (client: SuiGrpcClient, id: string) => Promise<T>;
|
|
41
39
|
new: (fields: Fields) => T;
|
|
42
40
|
kind: "StructClassReified";
|
|
43
41
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
1
2
|
import { Reified, ToField, ToTypeArgument, ToTypeStr, TypeArgument, VectorClass, VectorClassReified } from "./reified";
|
|
2
3
|
import { FieldsWithTypes } from "./util";
|
|
3
4
|
export type VectorElements<T extends TypeArgument> = Array<ToField<T>>;
|
|
@@ -15,18 +16,7 @@ export declare class Vector<T extends TypeArgument> implements VectorClass {
|
|
|
15
16
|
constructor(typeArgs: [ToTypeStr<T>], elements: VectorElements<T>);
|
|
16
17
|
static reified<T extends Reified<TypeArgument, any>>(T: T): VectorReified<ToTypeArgument<T>>;
|
|
17
18
|
static get r(): typeof Vector.reified;
|
|
18
|
-
static get bcs():
|
|
19
|
-
<T extends import("@mysten/bcs").BcsType<any>, Name extends string = `vector<${T["name"]}>`>(type: T, options?: import("@mysten/bcs").BcsTypeOptions<import("@mysten/bcs").InferBcsType<T>[], Iterable<import("@mysten/bcs").InferBcsInput<T>> & {
|
|
20
|
-
length: number;
|
|
21
|
-
}, Name>): import("@mysten/bcs").BcsType<import("@mysten/bcs").InferBcsType<T>[], Iterable<import("@mysten/bcs").InferBcsInput<T>> & {
|
|
22
|
-
length: number;
|
|
23
|
-
}, Name>;
|
|
24
|
-
<T, Input, Name extends string = string>(type: import("@mysten/bcs").BcsType<T, Input, Name>, options?: import("@mysten/bcs").BcsTypeOptions<T[], Iterable<Input> & {
|
|
25
|
-
length: number;
|
|
26
|
-
}, `vector<${Name}>`>): import("@mysten/bcs").BcsType<T[], Iterable<Input> & {
|
|
27
|
-
length: number;
|
|
28
|
-
}, `vector<${Name}>`>;
|
|
29
|
-
};
|
|
19
|
+
static get bcs(): typeof bcs.vector;
|
|
30
20
|
static fromFields<T extends Reified<TypeArgument, any>>(typeArg: T, elements: any[]): Vector<ToTypeArgument<T>>;
|
|
31
21
|
static fromFieldsWithTypes<T extends Reified<TypeArgument, any>>(typeArg: T, item: FieldsWithTypes): Vector<ToTypeArgument<T>>;
|
|
32
22
|
static fromBcs<T extends Reified<TypeArgument, any>>(typeArg: T, data: Uint8Array): Vector<ToTypeArgument<T>>;
|
|
@@ -3,7 +3,7 @@ import { PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeSt
|
|
|
3
3
|
import { FieldsWithTypes } from "../../_framework/util";
|
|
4
4
|
import { PKG_V1 } from "../index";
|
|
5
5
|
import { BcsType } from "@mysten/sui/bcs";
|
|
6
|
-
import {
|
|
6
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
7
7
|
export declare function isCell(type: string): boolean;
|
|
8
8
|
export interface CellFields<Element extends TypeArgument> {
|
|
9
9
|
element: ToField<Option<Element>>;
|
|
@@ -24,12 +24,8 @@ export declare class Cell<Element extends TypeArgument> implements StructClass {
|
|
|
24
24
|
static get r(): typeof Cell.reified;
|
|
25
25
|
static phantom<Element extends Reified<TypeArgument, any>>(Element: Element): PhantomReified<ToTypeStr<Cell<ToTypeArgument<Element>>>>;
|
|
26
26
|
static get p(): typeof Cell.phantom;
|
|
27
|
-
static get bcs(): <Element extends BcsType<any>>(Element: Element) => import("@mysten/bcs").BcsStruct<{
|
|
28
|
-
element:
|
|
29
|
-
vec: BcsType<import("@mysten/bcs").InferBcsType<Element>[], Iterable<import("@mysten/bcs").InferBcsInput<Element>> & {
|
|
30
|
-
length: number;
|
|
31
|
-
}, string>;
|
|
32
|
-
}, string>;
|
|
27
|
+
static get bcs(): <Element extends BcsType<any>>(Element: Element) => import("@mysten/sui/bcs").BcsStruct<{
|
|
28
|
+
element: BcsType<any, any, string>;
|
|
33
29
|
}, string>;
|
|
34
30
|
static fromFields<Element extends Reified<TypeArgument, any>>(typeArg: Element, fields: Record<string, any>): Cell<ToTypeArgument<Element>>;
|
|
35
31
|
static fromFieldsWithTypes<Element extends Reified<TypeArgument, any>>(typeArg: Element, item: FieldsWithTypes): Cell<ToTypeArgument<Element>>;
|
|
@@ -44,7 +40,5 @@ export declare class Cell<Element extends TypeArgument> implements StructClass {
|
|
|
44
40
|
};
|
|
45
41
|
static fromJSONField<Element extends Reified<TypeArgument, any>>(typeArg: Element, field: any): Cell<ToTypeArgument<Element>>;
|
|
46
42
|
static fromJSON<Element extends Reified<TypeArgument, any>>(typeArg: Element, json: Record<string, any>): Cell<ToTypeArgument<Element>>;
|
|
47
|
-
static
|
|
48
|
-
static fromSuiObjectData<Element extends Reified<TypeArgument, any>>(typeArg: Element, data: SuiObjectData): Cell<ToTypeArgument<Element>>;
|
|
49
|
-
static fetch<Element extends Reified<TypeArgument, any>>(client: SuiJsonRpcClient, typeArg: Element, id: string): Promise<Cell<ToTypeArgument<Element>>>;
|
|
43
|
+
static fetch<Element extends Reified<TypeArgument, any>>(client: SuiGrpcClient, typeArg: Element, id: string): Promise<Cell<ToTypeArgument<Element>>>;
|
|
50
44
|
}
|
|
@@ -9,10 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { Option } from "../../_dependencies/source/0x1/option/structs";
|
|
11
11
|
import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs, } from "../../_framework/reified";
|
|
12
|
-
import { composeSuiType, compressSuiType,
|
|
12
|
+
import { composeSuiType, compressSuiType, } from "../../_framework/util";
|
|
13
13
|
import { PKG_V1 } from "../index";
|
|
14
14
|
import { bcs } from "@mysten/sui/bcs";
|
|
15
|
-
import { fromBase64 } from "@mysten/sui/utils";
|
|
16
15
|
/* ============================== Cell =============================== */
|
|
17
16
|
export function isCell(type) {
|
|
18
17
|
type = compressSuiType(type);
|
|
@@ -40,8 +39,6 @@ export class Cell {
|
|
|
40
39
|
bcs: Cell.bcs(toBcs(Element)),
|
|
41
40
|
fromJSONField: (field) => Cell.fromJSONField(Element, field),
|
|
42
41
|
fromJSON: (json) => Cell.fromJSON(Element, json),
|
|
43
|
-
fromSuiParsedData: (content) => Cell.fromSuiParsedData(Element, content),
|
|
44
|
-
fromSuiObjectData: (content) => Cell.fromSuiObjectData(Element, content),
|
|
45
42
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Cell.fetch(client, Element, id); }),
|
|
46
43
|
new: (fields) => {
|
|
47
44
|
return new Cell([extractType(Element)], fields);
|
|
@@ -101,48 +98,13 @@ export class Cell {
|
|
|
101
98
|
assertReifiedTypeArgsMatch(composeSuiType(Cell.$typeName, extractType(typeArg)), json.$typeArgs, [typeArg]);
|
|
102
99
|
return Cell.fromJSONField(typeArg, json);
|
|
103
100
|
}
|
|
104
|
-
static fromSuiParsedData(typeArg, content) {
|
|
105
|
-
if (content.dataType !== "moveObject") {
|
|
106
|
-
throw new Error("not an object");
|
|
107
|
-
}
|
|
108
|
-
if (!isCell(content.type)) {
|
|
109
|
-
throw new Error(`object at ${content.fields.id} is not a Cell object`);
|
|
110
|
-
}
|
|
111
|
-
return Cell.fromFieldsWithTypes(typeArg, content);
|
|
112
|
-
}
|
|
113
|
-
static fromSuiObjectData(typeArg, data) {
|
|
114
|
-
if (data.bcs) {
|
|
115
|
-
if (data.bcs.dataType !== "moveObject" || !isCell(data.bcs.type)) {
|
|
116
|
-
throw new Error(`object at is not a Cell object`);
|
|
117
|
-
}
|
|
118
|
-
const gotTypeArgs = parseTypeName(data.bcs.type).typeArgs;
|
|
119
|
-
if (gotTypeArgs.length !== 1) {
|
|
120
|
-
throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`);
|
|
121
|
-
}
|
|
122
|
-
const gotTypeArg = compressSuiType(gotTypeArgs[0]);
|
|
123
|
-
const expectedTypeArg = compressSuiType(extractType(typeArg));
|
|
124
|
-
if (gotTypeArg !== compressSuiType(extractType(typeArg))) {
|
|
125
|
-
throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
126
|
-
}
|
|
127
|
-
return Cell.fromBcs(typeArg, fromBase64(data.bcs.bcsBytes));
|
|
128
|
-
}
|
|
129
|
-
if (data.content) {
|
|
130
|
-
return Cell.fromSuiParsedData(typeArg, data.content);
|
|
131
|
-
}
|
|
132
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
133
|
-
}
|
|
134
101
|
static fetch(client, typeArg, id) {
|
|
135
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (res.error) {
|
|
139
|
-
throw new Error(`error fetching Cell object at id ${id}: ${res.error.code}`);
|
|
140
|
-
}
|
|
141
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
142
|
-
!isCell(res.data.bcs.type)) {
|
|
103
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
104
|
+
if (!isCell(object.type)) {
|
|
143
105
|
throw new Error(`object at id ${id} is not a Cell object`);
|
|
144
106
|
}
|
|
145
|
-
return Cell.
|
|
107
|
+
return Cell.fromBcs(typeArg, object.content);
|
|
146
108
|
});
|
|
147
109
|
}
|
|
148
110
|
}
|
|
@@ -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 isDecimal(type: string): boolean;
|
|
6
6
|
export interface DecimalFields {
|
|
7
7
|
value: ToField<"u256">;
|
|
@@ -22,8 +22,8 @@ export declare class Decimal implements StructClass {
|
|
|
22
22
|
static get r(): import("../../_framework/reified").StructClassReified<Decimal, DecimalFields>;
|
|
23
23
|
static phantom(): PhantomReified<ToTypeStr<Decimal>>;
|
|
24
24
|
static get p(): PhantomReified<"0x1f54a9a2d71799553197e9ea24557797c6398d6a65f2d4d3818c9304b75d5e21::decimal::Decimal" | "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::decimal::Decimal">;
|
|
25
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
26
|
-
value: import("@mysten/bcs").BcsType<string, string | number | bigint, "u256">;
|
|
25
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
26
|
+
value: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u256">;
|
|
27
27
|
}, string>;
|
|
28
28
|
static fromFields(fields: Record<string, any>): Decimal;
|
|
29
29
|
static fromFieldsWithTypes(item: FieldsWithTypes): Decimal;
|
|
@@ -38,7 +38,5 @@ export declare class Decimal implements StructClass {
|
|
|
38
38
|
};
|
|
39
39
|
static fromJSONField(field: any): Decimal;
|
|
40
40
|
static fromJSON(json: Record<string, any>): Decimal;
|
|
41
|
-
static
|
|
42
|
-
static fromSuiObjectData(data: SuiObjectData): Decimal;
|
|
43
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<Decimal>;
|
|
41
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<Decimal>;
|
|
44
42
|
}
|
|
@@ -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
|
/* ============================== Decimal =============================== */
|
|
16
15
|
export function isDecimal(type) {
|
|
17
16
|
type = compressSuiType(type);
|
|
@@ -39,8 +38,6 @@ export class Decimal {
|
|
|
39
38
|
bcs: Decimal.bcs,
|
|
40
39
|
fromJSONField: (field) => Decimal.fromJSONField(field),
|
|
41
40
|
fromJSON: (json) => Decimal.fromJSON(json),
|
|
42
|
-
fromSuiParsedData: (content) => Decimal.fromSuiParsedData(content),
|
|
43
|
-
fromSuiObjectData: (content) => Decimal.fromSuiObjectData(content),
|
|
44
41
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Decimal.fetch(client, id); }),
|
|
45
42
|
new: (fields) => {
|
|
46
43
|
return new Decimal([], fields);
|
|
@@ -97,39 +94,13 @@ export class Decimal {
|
|
|
97
94
|
}
|
|
98
95
|
return Decimal.fromJSONField(json);
|
|
99
96
|
}
|
|
100
|
-
static fromSuiParsedData(content) {
|
|
101
|
-
if (content.dataType !== "moveObject") {
|
|
102
|
-
throw new Error("not an object");
|
|
103
|
-
}
|
|
104
|
-
if (!isDecimal(content.type)) {
|
|
105
|
-
throw new Error(`object at ${content.fields.id} is not a Decimal object`);
|
|
106
|
-
}
|
|
107
|
-
return Decimal.fromFieldsWithTypes(content);
|
|
108
|
-
}
|
|
109
|
-
static fromSuiObjectData(data) {
|
|
110
|
-
if (data.bcs) {
|
|
111
|
-
if (data.bcs.dataType !== "moveObject" || !isDecimal(data.bcs.type)) {
|
|
112
|
-
throw new Error(`object at is not a Decimal object`);
|
|
113
|
-
}
|
|
114
|
-
return Decimal.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
115
|
-
}
|
|
116
|
-
if (data.content) {
|
|
117
|
-
return Decimal.fromSuiParsedData(data.content);
|
|
118
|
-
}
|
|
119
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
120
|
-
}
|
|
121
97
|
static fetch(client, id) {
|
|
122
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (res.error) {
|
|
126
|
-
throw new Error(`error fetching Decimal object at id ${id}: ${res.error.code}`);
|
|
127
|
-
}
|
|
128
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
129
|
-
!isDecimal(res.data.bcs.type)) {
|
|
99
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
100
|
+
if (!isDecimal(object.type)) {
|
|
130
101
|
throw new Error(`object at id ${id} is not a Decimal object`);
|
|
131
102
|
}
|
|
132
|
-
return Decimal.
|
|
103
|
+
return Decimal.fromBcs(object.content);
|
|
133
104
|
});
|
|
134
105
|
}
|
|
135
106
|
}
|