@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
|
@@ -11,12 +11,12 @@ import * as reified from "../../_framework/reified";
|
|
|
11
11
|
import { TypeName } from "../../_dependencies/source/0x1/type-name/structs";
|
|
12
12
|
import { ID, UID } from "../../_dependencies/source/0x2/object/structs";
|
|
13
13
|
import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, } from "../../_framework/reified";
|
|
14
|
-
import { composeSuiType, compressSuiType,
|
|
14
|
+
import { composeSuiType, compressSuiType, } from "../../_framework/util";
|
|
15
15
|
import { Decimal } from "../decimal/structs";
|
|
16
16
|
import { PKG_V1, PKG_V11 } from "../index";
|
|
17
17
|
import { UserRewardManager } from "../liquidity-mining/structs";
|
|
18
18
|
import { bcs } from "@mysten/sui/bcs";
|
|
19
|
-
import {
|
|
19
|
+
import { fromHex, toHex } from "@mysten/sui/utils";
|
|
20
20
|
/* ============================== Borrow =============================== */
|
|
21
21
|
export function isBorrow(type) {
|
|
22
22
|
type = compressSuiType(type);
|
|
@@ -49,8 +49,6 @@ export class Borrow {
|
|
|
49
49
|
bcs: Borrow.bcs,
|
|
50
50
|
fromJSONField: (field) => Borrow.fromJSONField(field),
|
|
51
51
|
fromJSON: (json) => Borrow.fromJSON(json),
|
|
52
|
-
fromSuiParsedData: (content) => Borrow.fromSuiParsedData(content),
|
|
53
|
-
fromSuiObjectData: (content) => Borrow.fromSuiObjectData(content),
|
|
54
52
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Borrow.fetch(client, id); }),
|
|
55
53
|
new: (fields) => {
|
|
56
54
|
return new Borrow([], fields);
|
|
@@ -132,39 +130,13 @@ export class Borrow {
|
|
|
132
130
|
}
|
|
133
131
|
return Borrow.fromJSONField(json);
|
|
134
132
|
}
|
|
135
|
-
static fromSuiParsedData(content) {
|
|
136
|
-
if (content.dataType !== "moveObject") {
|
|
137
|
-
throw new Error("not an object");
|
|
138
|
-
}
|
|
139
|
-
if (!isBorrow(content.type)) {
|
|
140
|
-
throw new Error(`object at ${content.fields.id} is not a Borrow object`);
|
|
141
|
-
}
|
|
142
|
-
return Borrow.fromFieldsWithTypes(content);
|
|
143
|
-
}
|
|
144
|
-
static fromSuiObjectData(data) {
|
|
145
|
-
if (data.bcs) {
|
|
146
|
-
if (data.bcs.dataType !== "moveObject" || !isBorrow(data.bcs.type)) {
|
|
147
|
-
throw new Error(`object at is not a Borrow object`);
|
|
148
|
-
}
|
|
149
|
-
return Borrow.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
150
|
-
}
|
|
151
|
-
if (data.content) {
|
|
152
|
-
return Borrow.fromSuiParsedData(data.content);
|
|
153
|
-
}
|
|
154
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
155
|
-
}
|
|
156
133
|
static fetch(client, id) {
|
|
157
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (res.error) {
|
|
161
|
-
throw new Error(`error fetching Borrow object at id ${id}: ${res.error.code}`);
|
|
162
|
-
}
|
|
163
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
164
|
-
!isBorrow(res.data.bcs.type)) {
|
|
135
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
136
|
+
if (!isBorrow(object.type)) {
|
|
165
137
|
throw new Error(`object at id ${id} is not a Borrow object`);
|
|
166
138
|
}
|
|
167
|
-
return Borrow.
|
|
139
|
+
return Borrow.fromBcs(object.content);
|
|
168
140
|
});
|
|
169
141
|
}
|
|
170
142
|
}
|
|
@@ -203,8 +175,6 @@ export class BorrowRecord {
|
|
|
203
175
|
bcs: BorrowRecord.bcs,
|
|
204
176
|
fromJSONField: (field) => BorrowRecord.fromJSONField(field),
|
|
205
177
|
fromJSON: (json) => BorrowRecord.fromJSON(json),
|
|
206
|
-
fromSuiParsedData: (content) => BorrowRecord.fromSuiParsedData(content),
|
|
207
|
-
fromSuiObjectData: (content) => BorrowRecord.fromSuiObjectData(content),
|
|
208
178
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return BorrowRecord.fetch(client, id); }),
|
|
209
179
|
new: (fields) => {
|
|
210
180
|
return new BorrowRecord([], fields);
|
|
@@ -286,40 +256,13 @@ export class BorrowRecord {
|
|
|
286
256
|
}
|
|
287
257
|
return BorrowRecord.fromJSONField(json);
|
|
288
258
|
}
|
|
289
|
-
static fromSuiParsedData(content) {
|
|
290
|
-
if (content.dataType !== "moveObject") {
|
|
291
|
-
throw new Error("not an object");
|
|
292
|
-
}
|
|
293
|
-
if (!isBorrowRecord(content.type)) {
|
|
294
|
-
throw new Error(`object at ${content.fields.id} is not a BorrowRecord object`);
|
|
295
|
-
}
|
|
296
|
-
return BorrowRecord.fromFieldsWithTypes(content);
|
|
297
|
-
}
|
|
298
|
-
static fromSuiObjectData(data) {
|
|
299
|
-
if (data.bcs) {
|
|
300
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
301
|
-
!isBorrowRecord(data.bcs.type)) {
|
|
302
|
-
throw new Error(`object at is not a BorrowRecord object`);
|
|
303
|
-
}
|
|
304
|
-
return BorrowRecord.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
305
|
-
}
|
|
306
|
-
if (data.content) {
|
|
307
|
-
return BorrowRecord.fromSuiParsedData(data.content);
|
|
308
|
-
}
|
|
309
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
310
|
-
}
|
|
311
259
|
static fetch(client, id) {
|
|
312
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
if (res.error) {
|
|
316
|
-
throw new Error(`error fetching BorrowRecord object at id ${id}: ${res.error.code}`);
|
|
317
|
-
}
|
|
318
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
319
|
-
!isBorrowRecord(res.data.bcs.type)) {
|
|
261
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
262
|
+
if (!isBorrowRecord(object.type)) {
|
|
320
263
|
throw new Error(`object at id ${id} is not a BorrowRecord object`);
|
|
321
264
|
}
|
|
322
|
-
return BorrowRecord.
|
|
265
|
+
return BorrowRecord.fromBcs(object.content);
|
|
323
266
|
});
|
|
324
267
|
}
|
|
325
268
|
}
|
|
@@ -358,8 +301,6 @@ export class Deposit {
|
|
|
358
301
|
bcs: Deposit.bcs,
|
|
359
302
|
fromJSONField: (field) => Deposit.fromJSONField(field),
|
|
360
303
|
fromJSON: (json) => Deposit.fromJSON(json),
|
|
361
|
-
fromSuiParsedData: (content) => Deposit.fromSuiParsedData(content),
|
|
362
|
-
fromSuiObjectData: (content) => Deposit.fromSuiObjectData(content),
|
|
363
304
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Deposit.fetch(client, id); }),
|
|
364
305
|
new: (fields) => {
|
|
365
306
|
return new Deposit([], fields);
|
|
@@ -441,39 +382,13 @@ export class Deposit {
|
|
|
441
382
|
}
|
|
442
383
|
return Deposit.fromJSONField(json);
|
|
443
384
|
}
|
|
444
|
-
static fromSuiParsedData(content) {
|
|
445
|
-
if (content.dataType !== "moveObject") {
|
|
446
|
-
throw new Error("not an object");
|
|
447
|
-
}
|
|
448
|
-
if (!isDeposit(content.type)) {
|
|
449
|
-
throw new Error(`object at ${content.fields.id} is not a Deposit object`);
|
|
450
|
-
}
|
|
451
|
-
return Deposit.fromFieldsWithTypes(content);
|
|
452
|
-
}
|
|
453
|
-
static fromSuiObjectData(data) {
|
|
454
|
-
if (data.bcs) {
|
|
455
|
-
if (data.bcs.dataType !== "moveObject" || !isDeposit(data.bcs.type)) {
|
|
456
|
-
throw new Error(`object at is not a Deposit object`);
|
|
457
|
-
}
|
|
458
|
-
return Deposit.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
459
|
-
}
|
|
460
|
-
if (data.content) {
|
|
461
|
-
return Deposit.fromSuiParsedData(data.content);
|
|
462
|
-
}
|
|
463
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
464
|
-
}
|
|
465
385
|
static fetch(client, id) {
|
|
466
386
|
return __awaiter(this, void 0, void 0, function* () {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (res.error) {
|
|
470
|
-
throw new Error(`error fetching Deposit object at id ${id}: ${res.error.code}`);
|
|
471
|
-
}
|
|
472
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
473
|
-
!isDeposit(res.data.bcs.type)) {
|
|
387
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
388
|
+
if (!isDeposit(object.type)) {
|
|
474
389
|
throw new Error(`object at id ${id} is not a Deposit object`);
|
|
475
390
|
}
|
|
476
|
-
return Deposit.
|
|
391
|
+
return Deposit.fromBcs(object.content);
|
|
477
392
|
});
|
|
478
393
|
}
|
|
479
394
|
}
|
|
@@ -512,8 +427,6 @@ export class DepositRecord {
|
|
|
512
427
|
bcs: DepositRecord.bcs,
|
|
513
428
|
fromJSONField: (field) => DepositRecord.fromJSONField(field),
|
|
514
429
|
fromJSON: (json) => DepositRecord.fromJSON(json),
|
|
515
|
-
fromSuiParsedData: (content) => DepositRecord.fromSuiParsedData(content),
|
|
516
|
-
fromSuiObjectData: (content) => DepositRecord.fromSuiObjectData(content),
|
|
517
430
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return DepositRecord.fetch(client, id); }),
|
|
518
431
|
new: (fields) => {
|
|
519
432
|
return new DepositRecord([], fields);
|
|
@@ -595,40 +508,13 @@ export class DepositRecord {
|
|
|
595
508
|
}
|
|
596
509
|
return DepositRecord.fromJSONField(json);
|
|
597
510
|
}
|
|
598
|
-
static fromSuiParsedData(content) {
|
|
599
|
-
if (content.dataType !== "moveObject") {
|
|
600
|
-
throw new Error("not an object");
|
|
601
|
-
}
|
|
602
|
-
if (!isDepositRecord(content.type)) {
|
|
603
|
-
throw new Error(`object at ${content.fields.id} is not a DepositRecord object`);
|
|
604
|
-
}
|
|
605
|
-
return DepositRecord.fromFieldsWithTypes(content);
|
|
606
|
-
}
|
|
607
|
-
static fromSuiObjectData(data) {
|
|
608
|
-
if (data.bcs) {
|
|
609
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
610
|
-
!isDepositRecord(data.bcs.type)) {
|
|
611
|
-
throw new Error(`object at is not a DepositRecord object`);
|
|
612
|
-
}
|
|
613
|
-
return DepositRecord.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
614
|
-
}
|
|
615
|
-
if (data.content) {
|
|
616
|
-
return DepositRecord.fromSuiParsedData(data.content);
|
|
617
|
-
}
|
|
618
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
619
|
-
}
|
|
620
511
|
static fetch(client, id) {
|
|
621
512
|
return __awaiter(this, void 0, void 0, function* () {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
if (res.error) {
|
|
625
|
-
throw new Error(`error fetching DepositRecord object at id ${id}: ${res.error.code}`);
|
|
626
|
-
}
|
|
627
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
628
|
-
!isDepositRecord(res.data.bcs.type)) {
|
|
513
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
514
|
+
if (!isDepositRecord(object.type)) {
|
|
629
515
|
throw new Error(`object at id ${id} is not a DepositRecord object`);
|
|
630
516
|
}
|
|
631
|
-
return DepositRecord.
|
|
517
|
+
return DepositRecord.fromBcs(object.content);
|
|
632
518
|
});
|
|
633
519
|
}
|
|
634
520
|
}
|
|
@@ -662,8 +548,6 @@ export class ExistStaleOracles {
|
|
|
662
548
|
bcs: ExistStaleOracles.bcs,
|
|
663
549
|
fromJSONField: (field) => ExistStaleOracles.fromJSONField(field),
|
|
664
550
|
fromJSON: (json) => ExistStaleOracles.fromJSON(json),
|
|
665
|
-
fromSuiParsedData: (content) => ExistStaleOracles.fromSuiParsedData(content),
|
|
666
|
-
fromSuiObjectData: (content) => ExistStaleOracles.fromSuiObjectData(content),
|
|
667
551
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return ExistStaleOracles.fetch(client, id); }),
|
|
668
552
|
new: (fields) => {
|
|
669
553
|
return new ExistStaleOracles([], fields);
|
|
@@ -720,40 +604,13 @@ export class ExistStaleOracles {
|
|
|
720
604
|
}
|
|
721
605
|
return ExistStaleOracles.fromJSONField(json);
|
|
722
606
|
}
|
|
723
|
-
static fromSuiParsedData(content) {
|
|
724
|
-
if (content.dataType !== "moveObject") {
|
|
725
|
-
throw new Error("not an object");
|
|
726
|
-
}
|
|
727
|
-
if (!isExistStaleOracles(content.type)) {
|
|
728
|
-
throw new Error(`object at ${content.fields.id} is not a ExistStaleOracles object`);
|
|
729
|
-
}
|
|
730
|
-
return ExistStaleOracles.fromFieldsWithTypes(content);
|
|
731
|
-
}
|
|
732
|
-
static fromSuiObjectData(data) {
|
|
733
|
-
if (data.bcs) {
|
|
734
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
735
|
-
!isExistStaleOracles(data.bcs.type)) {
|
|
736
|
-
throw new Error(`object at is not a ExistStaleOracles object`);
|
|
737
|
-
}
|
|
738
|
-
return ExistStaleOracles.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
739
|
-
}
|
|
740
|
-
if (data.content) {
|
|
741
|
-
return ExistStaleOracles.fromSuiParsedData(data.content);
|
|
742
|
-
}
|
|
743
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
744
|
-
}
|
|
745
607
|
static fetch(client, id) {
|
|
746
608
|
return __awaiter(this, void 0, void 0, function* () {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
if (res.error) {
|
|
750
|
-
throw new Error(`error fetching ExistStaleOracles object at id ${id}: ${res.error.code}`);
|
|
751
|
-
}
|
|
752
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
753
|
-
!isExistStaleOracles(res.data.bcs.type)) {
|
|
609
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
610
|
+
if (!isExistStaleOracles(object.type)) {
|
|
754
611
|
throw new Error(`object at id ${id} is not a ExistStaleOracles object`);
|
|
755
612
|
}
|
|
756
|
-
return ExistStaleOracles.
|
|
613
|
+
return ExistStaleOracles.fromBcs(object.content);
|
|
757
614
|
});
|
|
758
615
|
}
|
|
759
616
|
}
|
|
@@ -802,8 +659,6 @@ export class Obligation {
|
|
|
802
659
|
bcs: Obligation.bcs,
|
|
803
660
|
fromJSONField: (field) => Obligation.fromJSONField(P, field),
|
|
804
661
|
fromJSON: (json) => Obligation.fromJSON(P, json),
|
|
805
|
-
fromSuiParsedData: (content) => Obligation.fromSuiParsedData(P, content),
|
|
806
|
-
fromSuiObjectData: (content) => Obligation.fromSuiObjectData(P, content),
|
|
807
662
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return Obligation.fetch(client, P, id); }),
|
|
808
663
|
new: (fields) => {
|
|
809
664
|
return new Obligation([extractType(P)], fields);
|
|
@@ -932,48 +787,13 @@ export class Obligation {
|
|
|
932
787
|
assertReifiedTypeArgsMatch(composeSuiType(Obligation.$typeName, extractType(typeArg)), json.$typeArgs, [typeArg]);
|
|
933
788
|
return Obligation.fromJSONField(typeArg, json);
|
|
934
789
|
}
|
|
935
|
-
static fromSuiParsedData(typeArg, content) {
|
|
936
|
-
if (content.dataType !== "moveObject") {
|
|
937
|
-
throw new Error("not an object");
|
|
938
|
-
}
|
|
939
|
-
if (!isObligation(content.type)) {
|
|
940
|
-
throw new Error(`object at ${content.fields.id} is not a Obligation object`);
|
|
941
|
-
}
|
|
942
|
-
return Obligation.fromFieldsWithTypes(typeArg, content);
|
|
943
|
-
}
|
|
944
|
-
static fromSuiObjectData(typeArg, data) {
|
|
945
|
-
if (data.bcs) {
|
|
946
|
-
if (data.bcs.dataType !== "moveObject" || !isObligation(data.bcs.type)) {
|
|
947
|
-
throw new Error(`object at is not a Obligation object`);
|
|
948
|
-
}
|
|
949
|
-
const gotTypeArgs = parseTypeName(data.bcs.type).typeArgs;
|
|
950
|
-
if (gotTypeArgs.length !== 1) {
|
|
951
|
-
throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`);
|
|
952
|
-
}
|
|
953
|
-
const gotTypeArg = compressSuiType(gotTypeArgs[0]);
|
|
954
|
-
const expectedTypeArg = compressSuiType(extractType(typeArg));
|
|
955
|
-
if (gotTypeArg !== compressSuiType(extractType(typeArg))) {
|
|
956
|
-
throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
|
|
957
|
-
}
|
|
958
|
-
return Obligation.fromBcs(typeArg, fromBase64(data.bcs.bcsBytes));
|
|
959
|
-
}
|
|
960
|
-
if (data.content) {
|
|
961
|
-
return Obligation.fromSuiParsedData(typeArg, data.content);
|
|
962
|
-
}
|
|
963
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
964
|
-
}
|
|
965
790
|
static fetch(client, typeArg, id) {
|
|
966
791
|
return __awaiter(this, void 0, void 0, function* () {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
if (res.error) {
|
|
970
|
-
throw new Error(`error fetching Obligation object at id ${id}: ${res.error.code}`);
|
|
971
|
-
}
|
|
972
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
973
|
-
!isObligation(res.data.bcs.type)) {
|
|
792
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
793
|
+
if (!isObligation(object.type)) {
|
|
974
794
|
throw new Error(`object at id ${id} is not a Obligation object`);
|
|
975
795
|
}
|
|
976
|
-
return Obligation.
|
|
796
|
+
return Obligation.fromBcs(typeArg, object.content);
|
|
977
797
|
});
|
|
978
798
|
}
|
|
979
799
|
}
|
|
@@ -1021,8 +841,6 @@ export class ObligationDataEvent {
|
|
|
1021
841
|
bcs: ObligationDataEvent.bcs,
|
|
1022
842
|
fromJSONField: (field) => ObligationDataEvent.fromJSONField(field),
|
|
1023
843
|
fromJSON: (json) => ObligationDataEvent.fromJSON(json),
|
|
1024
|
-
fromSuiParsedData: (content) => ObligationDataEvent.fromSuiParsedData(content),
|
|
1025
|
-
fromSuiObjectData: (content) => ObligationDataEvent.fromSuiObjectData(content),
|
|
1026
844
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return ObligationDataEvent.fetch(client, id); }),
|
|
1027
845
|
new: (fields) => {
|
|
1028
846
|
return new ObligationDataEvent([], fields);
|
|
@@ -1154,40 +972,13 @@ export class ObligationDataEvent {
|
|
|
1154
972
|
}
|
|
1155
973
|
return ObligationDataEvent.fromJSONField(json);
|
|
1156
974
|
}
|
|
1157
|
-
static fromSuiParsedData(content) {
|
|
1158
|
-
if (content.dataType !== "moveObject") {
|
|
1159
|
-
throw new Error("not an object");
|
|
1160
|
-
}
|
|
1161
|
-
if (!isObligationDataEvent(content.type)) {
|
|
1162
|
-
throw new Error(`object at ${content.fields.id} is not a ObligationDataEvent object`);
|
|
1163
|
-
}
|
|
1164
|
-
return ObligationDataEvent.fromFieldsWithTypes(content);
|
|
1165
|
-
}
|
|
1166
|
-
static fromSuiObjectData(data) {
|
|
1167
|
-
if (data.bcs) {
|
|
1168
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
1169
|
-
!isObligationDataEvent(data.bcs.type)) {
|
|
1170
|
-
throw new Error(`object at is not a ObligationDataEvent object`);
|
|
1171
|
-
}
|
|
1172
|
-
return ObligationDataEvent.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
1173
|
-
}
|
|
1174
|
-
if (data.content) {
|
|
1175
|
-
return ObligationDataEvent.fromSuiParsedData(data.content);
|
|
1176
|
-
}
|
|
1177
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
1178
|
-
}
|
|
1179
975
|
static fetch(client, id) {
|
|
1180
976
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
if (res.error) {
|
|
1184
|
-
throw new Error(`error fetching ObligationDataEvent object at id ${id}: ${res.error.code}`);
|
|
1185
|
-
}
|
|
1186
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
1187
|
-
!isObligationDataEvent(res.data.bcs.type)) {
|
|
977
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
978
|
+
if (!isObligationDataEvent(object.type)) {
|
|
1188
979
|
throw new Error(`object at id ${id} is not a ObligationDataEvent object`);
|
|
1189
980
|
}
|
|
1190
|
-
return ObligationDataEvent.
|
|
981
|
+
return ObligationDataEvent.fromBcs(object.content);
|
|
1191
982
|
});
|
|
1192
983
|
}
|
|
1193
984
|
}
|
|
@@ -2,7 +2,7 @@ import { PhantomReified, Reified, StructClass, ToField, ToTypeStr } from "../../
|
|
|
2
2
|
import { FieldsWithTypes } from "../../_framework/util";
|
|
3
3
|
import { Decimal } from "../decimal/structs";
|
|
4
4
|
import { PKG_V1 } from "../index";
|
|
5
|
-
import {
|
|
5
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
6
6
|
export declare function isRateLimiter(type: string): boolean;
|
|
7
7
|
export interface RateLimiterFields {
|
|
8
8
|
config: ToField<RateLimiterConfig>;
|
|
@@ -29,17 +29,17 @@ export declare class RateLimiter implements StructClass {
|
|
|
29
29
|
static get r(): import("../../_framework/reified").StructClassReified<RateLimiter, RateLimiterFields>;
|
|
30
30
|
static phantom(): PhantomReified<ToTypeStr<RateLimiter>>;
|
|
31
31
|
static get p(): PhantomReified<"0x1f54a9a2d71799553197e9ea24557797c6398d6a65f2d4d3818c9304b75d5e21::rate_limiter::RateLimiter" | "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::rate_limiter::RateLimiter">;
|
|
32
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
33
|
-
config: import("@mysten/bcs").BcsStruct<{
|
|
34
|
-
window_duration: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
35
|
-
max_outflow: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
32
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
33
|
+
config: import("@mysten/sui/bcs").BcsStruct<{
|
|
34
|
+
window_duration: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
35
|
+
max_outflow: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
36
36
|
}, string>;
|
|
37
|
-
prev_qty: import("@mysten/bcs").BcsStruct<{
|
|
38
|
-
value: import("@mysten/bcs").BcsType<string, string | number | bigint, "u256">;
|
|
37
|
+
prev_qty: import("@mysten/sui/bcs").BcsStruct<{
|
|
38
|
+
value: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u256">;
|
|
39
39
|
}, string>;
|
|
40
|
-
window_start: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
41
|
-
cur_qty: import("@mysten/bcs").BcsStruct<{
|
|
42
|
-
value: import("@mysten/bcs").BcsType<string, string | number | bigint, "u256">;
|
|
40
|
+
window_start: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
41
|
+
cur_qty: import("@mysten/sui/bcs").BcsStruct<{
|
|
42
|
+
value: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u256">;
|
|
43
43
|
}, string>;
|
|
44
44
|
}, string>;
|
|
45
45
|
static fromFields(fields: Record<string, any>): RateLimiter;
|
|
@@ -75,9 +75,7 @@ export declare class RateLimiter implements StructClass {
|
|
|
75
75
|
};
|
|
76
76
|
static fromJSONField(field: any): RateLimiter;
|
|
77
77
|
static fromJSON(json: Record<string, any>): RateLimiter;
|
|
78
|
-
static
|
|
79
|
-
static fromSuiObjectData(data: SuiObjectData): RateLimiter;
|
|
80
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<RateLimiter>;
|
|
78
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<RateLimiter>;
|
|
81
79
|
}
|
|
82
80
|
export declare function isRateLimiterConfig(type: string): boolean;
|
|
83
81
|
export interface RateLimiterConfigFields {
|
|
@@ -101,9 +99,9 @@ export declare class RateLimiterConfig implements StructClass {
|
|
|
101
99
|
static get r(): import("../../_framework/reified").StructClassReified<RateLimiterConfig, RateLimiterConfigFields>;
|
|
102
100
|
static phantom(): PhantomReified<ToTypeStr<RateLimiterConfig>>;
|
|
103
101
|
static get p(): PhantomReified<"0x1f54a9a2d71799553197e9ea24557797c6398d6a65f2d4d3818c9304b75d5e21::rate_limiter::RateLimiterConfig" | "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::rate_limiter::RateLimiterConfig">;
|
|
104
|
-
static get bcs(): import("@mysten/bcs").BcsStruct<{
|
|
105
|
-
window_duration: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
106
|
-
max_outflow: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
102
|
+
static get bcs(): import("@mysten/sui/bcs").BcsStruct<{
|
|
103
|
+
window_duration: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
104
|
+
max_outflow: import("@mysten/sui/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
107
105
|
}, string>;
|
|
108
106
|
static fromFields(fields: Record<string, any>): RateLimiterConfig;
|
|
109
107
|
static fromFieldsWithTypes(item: FieldsWithTypes): RateLimiterConfig;
|
|
@@ -120,7 +118,5 @@ export declare class RateLimiterConfig implements StructClass {
|
|
|
120
118
|
};
|
|
121
119
|
static fromJSONField(field: any): RateLimiterConfig;
|
|
122
120
|
static fromJSON(json: Record<string, any>): RateLimiterConfig;
|
|
123
|
-
static
|
|
124
|
-
static fromSuiObjectData(data: SuiObjectData): RateLimiterConfig;
|
|
125
|
-
static fetch(client: SuiJsonRpcClient, id: string): Promise<RateLimiterConfig>;
|
|
121
|
+
static fetch(client: SuiGrpcClient, id: string): Promise<RateLimiterConfig>;
|
|
126
122
|
}
|
|
@@ -12,7 +12,6 @@ import { composeSuiType, compressSuiType, } from "../../_framework/util";
|
|
|
12
12
|
import { Decimal } from "../decimal/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
|
/* ============================== RateLimiter =============================== */
|
|
17
16
|
export function isRateLimiter(type) {
|
|
18
17
|
type = compressSuiType(type);
|
|
@@ -43,8 +42,6 @@ export class RateLimiter {
|
|
|
43
42
|
bcs: RateLimiter.bcs,
|
|
44
43
|
fromJSONField: (field) => RateLimiter.fromJSONField(field),
|
|
45
44
|
fromJSON: (json) => RateLimiter.fromJSON(json),
|
|
46
|
-
fromSuiParsedData: (content) => RateLimiter.fromSuiParsedData(content),
|
|
47
|
-
fromSuiObjectData: (content) => RateLimiter.fromSuiObjectData(content),
|
|
48
45
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return RateLimiter.fetch(client, id); }),
|
|
49
46
|
new: (fields) => {
|
|
50
47
|
return new RateLimiter([], fields);
|
|
@@ -116,39 +113,13 @@ export class RateLimiter {
|
|
|
116
113
|
}
|
|
117
114
|
return RateLimiter.fromJSONField(json);
|
|
118
115
|
}
|
|
119
|
-
static fromSuiParsedData(content) {
|
|
120
|
-
if (content.dataType !== "moveObject") {
|
|
121
|
-
throw new Error("not an object");
|
|
122
|
-
}
|
|
123
|
-
if (!isRateLimiter(content.type)) {
|
|
124
|
-
throw new Error(`object at ${content.fields.id} is not a RateLimiter object`);
|
|
125
|
-
}
|
|
126
|
-
return RateLimiter.fromFieldsWithTypes(content);
|
|
127
|
-
}
|
|
128
|
-
static fromSuiObjectData(data) {
|
|
129
|
-
if (data.bcs) {
|
|
130
|
-
if (data.bcs.dataType !== "moveObject" || !isRateLimiter(data.bcs.type)) {
|
|
131
|
-
throw new Error(`object at is not a RateLimiter object`);
|
|
132
|
-
}
|
|
133
|
-
return RateLimiter.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
134
|
-
}
|
|
135
|
-
if (data.content) {
|
|
136
|
-
return RateLimiter.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 RateLimiter 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
|
-
!isRateLimiter(res.data.bcs.type)) {
|
|
118
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
119
|
+
if (!isRateLimiter(object.type)) {
|
|
149
120
|
throw new Error(`object at id ${id} is not a RateLimiter object`);
|
|
150
121
|
}
|
|
151
|
-
return RateLimiter.
|
|
122
|
+
return RateLimiter.fromBcs(object.content);
|
|
152
123
|
});
|
|
153
124
|
}
|
|
154
125
|
}
|
|
@@ -183,8 +154,6 @@ export class RateLimiterConfig {
|
|
|
183
154
|
bcs: RateLimiterConfig.bcs,
|
|
184
155
|
fromJSONField: (field) => RateLimiterConfig.fromJSONField(field),
|
|
185
156
|
fromJSON: (json) => RateLimiterConfig.fromJSON(json),
|
|
186
|
-
fromSuiParsedData: (content) => RateLimiterConfig.fromSuiParsedData(content),
|
|
187
|
-
fromSuiObjectData: (content) => RateLimiterConfig.fromSuiObjectData(content),
|
|
188
157
|
fetch: (client, id) => __awaiter(this, void 0, void 0, function* () { return RateLimiterConfig.fetch(client, id); }),
|
|
189
158
|
new: (fields) => {
|
|
190
159
|
return new RateLimiterConfig([], fields);
|
|
@@ -246,40 +215,13 @@ export class RateLimiterConfig {
|
|
|
246
215
|
}
|
|
247
216
|
return RateLimiterConfig.fromJSONField(json);
|
|
248
217
|
}
|
|
249
|
-
static fromSuiParsedData(content) {
|
|
250
|
-
if (content.dataType !== "moveObject") {
|
|
251
|
-
throw new Error("not an object");
|
|
252
|
-
}
|
|
253
|
-
if (!isRateLimiterConfig(content.type)) {
|
|
254
|
-
throw new Error(`object at ${content.fields.id} is not a RateLimiterConfig object`);
|
|
255
|
-
}
|
|
256
|
-
return RateLimiterConfig.fromFieldsWithTypes(content);
|
|
257
|
-
}
|
|
258
|
-
static fromSuiObjectData(data) {
|
|
259
|
-
if (data.bcs) {
|
|
260
|
-
if (data.bcs.dataType !== "moveObject" ||
|
|
261
|
-
!isRateLimiterConfig(data.bcs.type)) {
|
|
262
|
-
throw new Error(`object at is not a RateLimiterConfig object`);
|
|
263
|
-
}
|
|
264
|
-
return RateLimiterConfig.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
265
|
-
}
|
|
266
|
-
if (data.content) {
|
|
267
|
-
return RateLimiterConfig.fromSuiParsedData(data.content);
|
|
268
|
-
}
|
|
269
|
-
throw new Error("Both `bcs` and `content` fields are missing from the data. Include `showBcs` or `showContent` in the request.");
|
|
270
|
-
}
|
|
271
218
|
static fetch(client, id) {
|
|
272
219
|
return __awaiter(this, void 0, void 0, function* () {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (res.error) {
|
|
276
|
-
throw new Error(`error fetching RateLimiterConfig object at id ${id}: ${res.error.code}`);
|
|
277
|
-
}
|
|
278
|
-
if (((_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.bcs) === null || _b === void 0 ? void 0 : _b.dataType) !== "moveObject" ||
|
|
279
|
-
!isRateLimiterConfig(res.data.bcs.type)) {
|
|
220
|
+
const { object } = yield client.getObject({ objectId: id, include: { content: true } });
|
|
221
|
+
if (!isRateLimiterConfig(object.type)) {
|
|
280
222
|
throw new Error(`object at id ${id} is not a RateLimiterConfig object`);
|
|
281
223
|
}
|
|
282
|
-
return RateLimiterConfig.
|
|
224
|
+
return RateLimiterConfig.fromBcs(object.content);
|
|
283
225
|
});
|
|
284
226
|
}
|
|
285
227
|
}
|