@suilend/sdk 1.1.99 → 2.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 -7
- package/_generated/_dependencies/source/0x1/ascii/structs.js +35 -75
- package/_generated/_dependencies/source/0x1/index.js +3 -6
- package/_generated/_dependencies/source/0x1/option/structs.d.ts +3 -3
- package/_generated/_dependencies/source/0x1/option/structs.js +31 -69
- package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +5 -5
- package/_generated/_dependencies/source/0x1/type-name/structs.js +20 -25
- package/_generated/_dependencies/source/0x2/bag/structs.d.ts +7 -7
- package/_generated/_dependencies/source/0x2/bag/structs.js +24 -29
- package/_generated/_dependencies/source/0x2/balance/structs.d.ts +7 -7
- package/_generated/_dependencies/source/0x2/balance/structs.js +49 -56
- package/_generated/_dependencies/source/0x2/index.js +3 -6
- package/_generated/_dependencies/source/0x2/object/structs.d.ts +8 -8
- package/_generated/_dependencies/source/0x2/object/structs.js +34 -41
- package/_generated/_dependencies/source/0x2/object-table/structs.d.ts +7 -7
- package/_generated/_dependencies/source/0x2/object-table/structs.js +31 -36
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.d.ts +5 -5
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/i64/structs.js +23 -28
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +4 -7
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.d.ts +11 -11
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price/structs.js +32 -37
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.d.ts +23 -23
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-feed/structs.js +29 -34
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +4 -4
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js +21 -59
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.d.ts +55 -55
- package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-info/structs.js +46 -53
- package/_generated/_framework/reified.d.ts +2 -2
- package/_generated/_framework/reified.js +27 -40
- package/_generated/_framework/util.js +26 -40
- package/_generated/_framework/vector.d.ts +4 -4
- package/_generated/_framework/vector.js +16 -21
- package/_generated/suilend/cell/structs.d.ts +4 -4
- package/_generated/suilend/cell/structs.js +31 -36
- package/_generated/suilend/decimal/structs.d.ts +4 -4
- package/_generated/suilend/decimal/structs.js +19 -24
- package/_generated/suilend/index.js +8 -12
- package/_generated/suilend/lending-market/functions.d.ts +1 -0
- package/_generated/suilend/lending-market/functions.js +271 -302
- package/_generated/suilend/lending-market/structs.d.ts +146 -146
- package/_generated/suilend/lending-market/structs.js +549 -617
- package/_generated/suilend/lending-market-registry/functions.js +7 -11
- package/_generated/suilend/liquidity-mining/structs.d.ts +50 -50
- package/_generated/suilend/liquidity-mining/structs.js +159 -205
- package/_generated/suilend/obligation/structs.d.ts +106 -106
- package/_generated/suilend/obligation/structs.js +313 -363
- package/_generated/suilend/rate-limiter/functions.js +23 -31
- package/_generated/suilend/rate-limiter/structs.d.ts +15 -15
- package/_generated/suilend/rate-limiter/structs.js +49 -56
- package/_generated/suilend/reserve/structs.d.ts +139 -139
- package/_generated/suilend/reserve/structs.js +397 -451
- package/_generated/suilend/reserve-config/functions.js +149 -190
- package/_generated/suilend/reserve-config/structs.d.ts +33 -33
- package/_generated/suilend/reserve-config/structs.js +109 -149
- package/api/events.js +1 -5
- package/api/index.js +1 -17
- package/client.d.ts +10 -10
- package/client.js +118 -128
- package/index.js +7 -23
- package/lib/constants.js +3 -9
- package/lib/index.js +5 -21
- package/lib/initialize.d.ts +3 -3
- package/lib/initialize.js +103 -140
- package/lib/liquidityMining.d.ts +3 -3
- package/lib/liquidityMining.js +57 -72
- package/lib/pyth.js +9 -14
- package/lib/strategyOwnerCap.js +106 -119
- package/lib/transactions.js +2 -7
- package/lib/types.js +4 -7
- package/mmt.js +2 -5
- package/package.json +1 -1
- package/parsers/apiReserveAssetDataEvent.js +25 -33
- package/parsers/index.js +5 -21
- package/parsers/lendingMarket.d.ts +1 -1
- package/parsers/lendingMarket.js +12 -19
- package/parsers/obligation.js +19 -26
- package/parsers/rateLimiter.js +11 -19
- package/parsers/reserve.d.ts +1 -1
- package/parsers/reserve.js +42 -85
- package/strategies.d.ts +11 -11
- package/strategies.js +547 -586
- package/swap/index.js +2 -18
- package/swap/quote.js +57 -65
- package/swap/transaction.d.ts +2 -2
- package/swap/transaction.js +40 -35
- package/utils/events.d.ts +3 -3
- package/utils/events.js +18 -35
- package/utils/index.js +16 -40
- package/utils/obligation.d.ts +4 -4
- package/utils/obligation.js +17 -60
- package/utils/simulate.js +118 -143
|
@@ -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 { SuiJsonRpcClient, SuiObjectData, SuiParsedData } from "@mysten/sui/jsonRpc";
|
|
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/
|
|
32
|
-
attestation_time: import("@mysten/
|
|
33
|
-
arrival_time: import("@mysten/
|
|
34
|
-
price_feed: import("@mysten/
|
|
35
|
-
price_identifier: import("@mysten/
|
|
36
|
-
bytes: import("@mysten/
|
|
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> & {
|
|
37
37
|
length: number;
|
|
38
38
|
}, string>;
|
|
39
39
|
}, string>;
|
|
40
|
-
price: import("@mysten/
|
|
41
|
-
price: import("@mysten/
|
|
42
|
-
negative: import("@mysten/
|
|
43
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
44
44
|
}, string>;
|
|
45
|
-
conf: import("@mysten/
|
|
46
|
-
expo: import("@mysten/
|
|
47
|
-
negative: import("@mysten/
|
|
48
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
49
49
|
}, string>;
|
|
50
|
-
timestamp: import("@mysten/
|
|
50
|
+
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
51
51
|
}, string>;
|
|
52
|
-
ema_price: import("@mysten/
|
|
53
|
-
price: import("@mysten/
|
|
54
|
-
negative: import("@mysten/
|
|
55
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
56
56
|
}, string>;
|
|
57
|
-
conf: import("@mysten/
|
|
58
|
-
expo: import("@mysten/
|
|
59
|
-
negative: import("@mysten/
|
|
60
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
61
61
|
}, string>;
|
|
62
|
-
timestamp: import("@mysten/
|
|
62
|
+
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
63
63
|
}, string>;
|
|
64
64
|
}, string>;
|
|
65
65
|
}, string>;
|
|
@@ -138,7 +138,7 @@ export declare class PriceInfo implements StructClass {
|
|
|
138
138
|
static fromJSON(json: Record<string, any>): PriceInfo;
|
|
139
139
|
static fromSuiParsedData(content: SuiParsedData): PriceInfo;
|
|
140
140
|
static fromSuiObjectData(data: SuiObjectData): PriceInfo;
|
|
141
|
-
static fetch(client:
|
|
141
|
+
static fetch(client: SuiJsonRpcClient, id: string): Promise<PriceInfo>;
|
|
142
142
|
}
|
|
143
143
|
export declare function isPriceInfoObject(type: string): boolean;
|
|
144
144
|
export interface PriceInfoObjectFields {
|
|
@@ -162,44 +162,44 @@ export declare class PriceInfoObject implements StructClass {
|
|
|
162
162
|
static get r(): import("../../../../_framework/reified").StructClassReified<PriceInfoObject, PriceInfoObjectFields>;
|
|
163
163
|
static phantom(): PhantomReified<ToTypeStr<PriceInfoObject>>;
|
|
164
164
|
static get p(): PhantomReified<"0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e::price_info::PriceInfoObject">;
|
|
165
|
-
static get bcs(): import("@mysten/
|
|
166
|
-
id: import("@mysten/
|
|
167
|
-
id: import("@mysten/
|
|
168
|
-
bytes: import("@mysten/
|
|
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>;
|
|
169
169
|
}, string>;
|
|
170
170
|
}, string>;
|
|
171
|
-
price_info: import("@mysten/
|
|
172
|
-
attestation_time: import("@mysten/
|
|
173
|
-
arrival_time: import("@mysten/
|
|
174
|
-
price_feed: import("@mysten/
|
|
175
|
-
price_identifier: import("@mysten/
|
|
176
|
-
bytes: import("@mysten/
|
|
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> & {
|
|
177
177
|
length: number;
|
|
178
178
|
}, string>;
|
|
179
179
|
}, string>;
|
|
180
|
-
price: import("@mysten/
|
|
181
|
-
price: import("@mysten/
|
|
182
|
-
negative: import("@mysten/
|
|
183
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
184
184
|
}, string>;
|
|
185
|
-
conf: import("@mysten/
|
|
186
|
-
expo: import("@mysten/
|
|
187
|
-
negative: import("@mysten/
|
|
188
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
189
189
|
}, string>;
|
|
190
|
-
timestamp: import("@mysten/
|
|
190
|
+
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
191
191
|
}, string>;
|
|
192
|
-
ema_price: import("@mysten/
|
|
193
|
-
price: import("@mysten/
|
|
194
|
-
negative: import("@mysten/
|
|
195
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
196
196
|
}, string>;
|
|
197
|
-
conf: import("@mysten/
|
|
198
|
-
expo: import("@mysten/
|
|
199
|
-
negative: import("@mysten/
|
|
200
|
-
magnitude: import("@mysten/
|
|
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">;
|
|
201
201
|
}, string>;
|
|
202
|
-
timestamp: import("@mysten/
|
|
202
|
+
timestamp: import("@mysten/bcs").BcsType<string, string | number | bigint, "u64">;
|
|
203
203
|
}, string>;
|
|
204
204
|
}, string>;
|
|
205
205
|
}, string>;
|
|
@@ -285,5 +285,5 @@ export declare class PriceInfoObject implements StructClass {
|
|
|
285
285
|
static fromJSON(json: Record<string, any>): PriceInfoObject;
|
|
286
286
|
static fromSuiParsedData(content: SuiParsedData): PriceInfoObject;
|
|
287
287
|
static fromSuiObjectData(data: SuiObjectData): PriceInfoObject;
|
|
288
|
-
static fetch(client:
|
|
288
|
+
static fetch(client: SuiJsonRpcClient, id: string): Promise<PriceInfoObject>;
|
|
289
289
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,28 +7,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const index_1 = require("../index");
|
|
19
|
-
const structs_2 = require("../price-feed/structs");
|
|
20
|
-
const bcs_1 = require("@mysten/sui/bcs");
|
|
21
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
10
|
+
import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom, } from "../../../../_framework/reified";
|
|
11
|
+
import { composeSuiType, compressSuiType, } from "../../../../_framework/util";
|
|
12
|
+
import { UID } from "../../0x2/object/structs";
|
|
13
|
+
import { PKG_V1 } from "../index";
|
|
14
|
+
import { PriceFeed } from "../price-feed/structs";
|
|
15
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
16
|
+
import { fromBase64 } from "@mysten/sui/utils";
|
|
22
17
|
/* ============================== PriceInfo =============================== */
|
|
23
|
-
function isPriceInfo(type) {
|
|
24
|
-
type =
|
|
25
|
-
return type === `${
|
|
18
|
+
export function isPriceInfo(type) {
|
|
19
|
+
type = compressSuiType(type);
|
|
20
|
+
return type === `${PKG_V1}::price_info::PriceInfo`;
|
|
26
21
|
}
|
|
27
|
-
class PriceInfo {
|
|
22
|
+
export class PriceInfo {
|
|
28
23
|
constructor(typeArgs, fields) {
|
|
29
24
|
this.__StructClass = true;
|
|
30
25
|
this.$typeName = PriceInfo.$typeName;
|
|
31
26
|
this.$isPhantom = PriceInfo.$isPhantom;
|
|
32
|
-
this.$fullTypeName =
|
|
27
|
+
this.$fullTypeName = composeSuiType(PriceInfo.$typeName, ...typeArgs);
|
|
33
28
|
this.$typeArgs = typeArgs;
|
|
34
29
|
this.attestationTime = fields.attestationTime;
|
|
35
30
|
this.arrivalTime = fields.arrivalTime;
|
|
@@ -38,7 +33,7 @@ class PriceInfo {
|
|
|
38
33
|
static reified() {
|
|
39
34
|
return {
|
|
40
35
|
typeName: PriceInfo.$typeName,
|
|
41
|
-
fullTypeName:
|
|
36
|
+
fullTypeName: composeSuiType(PriceInfo.$typeName, ...[]),
|
|
42
37
|
typeArgs: [],
|
|
43
38
|
isPhantom: PriceInfo.$isPhantom,
|
|
44
39
|
reifiedTypeArgs: [],
|
|
@@ -61,23 +56,23 @@ class PriceInfo {
|
|
|
61
56
|
return PriceInfo.reified();
|
|
62
57
|
}
|
|
63
58
|
static phantom() {
|
|
64
|
-
return
|
|
59
|
+
return phantom(PriceInfo.reified());
|
|
65
60
|
}
|
|
66
61
|
static get p() {
|
|
67
62
|
return PriceInfo.phantom();
|
|
68
63
|
}
|
|
69
64
|
static get bcs() {
|
|
70
|
-
return
|
|
71
|
-
attestation_time:
|
|
72
|
-
arrival_time:
|
|
73
|
-
price_feed:
|
|
65
|
+
return bcs.struct("PriceInfo", {
|
|
66
|
+
attestation_time: bcs.u64(),
|
|
67
|
+
arrival_time: bcs.u64(),
|
|
68
|
+
price_feed: PriceFeed.bcs,
|
|
74
69
|
});
|
|
75
70
|
}
|
|
76
71
|
static fromFields(fields) {
|
|
77
72
|
return PriceInfo.reified().new({
|
|
78
|
-
attestationTime:
|
|
79
|
-
arrivalTime:
|
|
80
|
-
priceFeed:
|
|
73
|
+
attestationTime: decodeFromFields("u64", fields.attestation_time),
|
|
74
|
+
arrivalTime: decodeFromFields("u64", fields.arrival_time),
|
|
75
|
+
priceFeed: decodeFromFields(PriceFeed.reified(), fields.price_feed),
|
|
81
76
|
});
|
|
82
77
|
}
|
|
83
78
|
static fromFieldsWithTypes(item) {
|
|
@@ -85,9 +80,9 @@ class PriceInfo {
|
|
|
85
80
|
throw new Error("not a PriceInfo type");
|
|
86
81
|
}
|
|
87
82
|
return PriceInfo.reified().new({
|
|
88
|
-
attestationTime:
|
|
89
|
-
arrivalTime:
|
|
90
|
-
priceFeed:
|
|
83
|
+
attestationTime: decodeFromFieldsWithTypes("u64", item.fields.attestation_time),
|
|
84
|
+
arrivalTime: decodeFromFieldsWithTypes("u64", item.fields.arrival_time),
|
|
85
|
+
priceFeed: decodeFromFieldsWithTypes(PriceFeed.reified(), item.fields.price_feed),
|
|
91
86
|
});
|
|
92
87
|
}
|
|
93
88
|
static fromBcs(data) {
|
|
@@ -105,9 +100,9 @@ class PriceInfo {
|
|
|
105
100
|
}
|
|
106
101
|
static fromJSONField(field) {
|
|
107
102
|
return PriceInfo.reified().new({
|
|
108
|
-
attestationTime:
|
|
109
|
-
arrivalTime:
|
|
110
|
-
priceFeed:
|
|
103
|
+
attestationTime: decodeFromJSONField("u64", field.attestationTime),
|
|
104
|
+
arrivalTime: decodeFromJSONField("u64", field.arrivalTime),
|
|
105
|
+
priceFeed: decodeFromJSONField(PriceFeed.reified(), field.priceFeed),
|
|
111
106
|
});
|
|
112
107
|
}
|
|
113
108
|
static fromJSON(json) {
|
|
@@ -130,7 +125,7 @@ class PriceInfo {
|
|
|
130
125
|
if (data.bcs.dataType !== "moveObject" || !isPriceInfo(data.bcs.type)) {
|
|
131
126
|
throw new Error(`object at is not a PriceInfo object`);
|
|
132
127
|
}
|
|
133
|
-
return PriceInfo.fromBcs((
|
|
128
|
+
return PriceInfo.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
134
129
|
}
|
|
135
130
|
if (data.content) {
|
|
136
131
|
return PriceInfo.fromSuiParsedData(data.content);
|
|
@@ -152,21 +147,20 @@ class PriceInfo {
|
|
|
152
147
|
});
|
|
153
148
|
}
|
|
154
149
|
}
|
|
155
|
-
|
|
156
|
-
PriceInfo.$typeName = `${index_1.PKG_V1}::price_info::PriceInfo`;
|
|
150
|
+
PriceInfo.$typeName = `${PKG_V1}::price_info::PriceInfo`;
|
|
157
151
|
PriceInfo.$numTypeParams = 0;
|
|
158
152
|
PriceInfo.$isPhantom = [];
|
|
159
153
|
/* ============================== PriceInfoObject =============================== */
|
|
160
|
-
function isPriceInfoObject(type) {
|
|
161
|
-
type =
|
|
162
|
-
return type === `${
|
|
154
|
+
export function isPriceInfoObject(type) {
|
|
155
|
+
type = compressSuiType(type);
|
|
156
|
+
return type === `${PKG_V1}::price_info::PriceInfoObject`;
|
|
163
157
|
}
|
|
164
|
-
class PriceInfoObject {
|
|
158
|
+
export class PriceInfoObject {
|
|
165
159
|
constructor(typeArgs, fields) {
|
|
166
160
|
this.__StructClass = true;
|
|
167
161
|
this.$typeName = PriceInfoObject.$typeName;
|
|
168
162
|
this.$isPhantom = PriceInfoObject.$isPhantom;
|
|
169
|
-
this.$fullTypeName =
|
|
163
|
+
this.$fullTypeName = composeSuiType(PriceInfoObject.$typeName, ...typeArgs);
|
|
170
164
|
this.$typeArgs = typeArgs;
|
|
171
165
|
this.id = fields.id;
|
|
172
166
|
this.priceInfo = fields.priceInfo;
|
|
@@ -174,7 +168,7 @@ class PriceInfoObject {
|
|
|
174
168
|
static reified() {
|
|
175
169
|
return {
|
|
176
170
|
typeName: PriceInfoObject.$typeName,
|
|
177
|
-
fullTypeName:
|
|
171
|
+
fullTypeName: composeSuiType(PriceInfoObject.$typeName, ...[]),
|
|
178
172
|
typeArgs: [],
|
|
179
173
|
isPhantom: PriceInfoObject.$isPhantom,
|
|
180
174
|
reifiedTypeArgs: [],
|
|
@@ -197,21 +191,21 @@ class PriceInfoObject {
|
|
|
197
191
|
return PriceInfoObject.reified();
|
|
198
192
|
}
|
|
199
193
|
static phantom() {
|
|
200
|
-
return
|
|
194
|
+
return phantom(PriceInfoObject.reified());
|
|
201
195
|
}
|
|
202
196
|
static get p() {
|
|
203
197
|
return PriceInfoObject.phantom();
|
|
204
198
|
}
|
|
205
199
|
static get bcs() {
|
|
206
|
-
return
|
|
207
|
-
id:
|
|
200
|
+
return bcs.struct("PriceInfoObject", {
|
|
201
|
+
id: UID.bcs,
|
|
208
202
|
price_info: PriceInfo.bcs,
|
|
209
203
|
});
|
|
210
204
|
}
|
|
211
205
|
static fromFields(fields) {
|
|
212
206
|
return PriceInfoObject.reified().new({
|
|
213
|
-
id:
|
|
214
|
-
priceInfo:
|
|
207
|
+
id: decodeFromFields(UID.reified(), fields.id),
|
|
208
|
+
priceInfo: decodeFromFields(PriceInfo.reified(), fields.price_info),
|
|
215
209
|
});
|
|
216
210
|
}
|
|
217
211
|
static fromFieldsWithTypes(item) {
|
|
@@ -219,8 +213,8 @@ class PriceInfoObject {
|
|
|
219
213
|
throw new Error("not a PriceInfoObject type");
|
|
220
214
|
}
|
|
221
215
|
return PriceInfoObject.reified().new({
|
|
222
|
-
id:
|
|
223
|
-
priceInfo:
|
|
216
|
+
id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
|
|
217
|
+
priceInfo: decodeFromFieldsWithTypes(PriceInfo.reified(), item.fields.price_info),
|
|
224
218
|
});
|
|
225
219
|
}
|
|
226
220
|
static fromBcs(data) {
|
|
@@ -237,8 +231,8 @@ class PriceInfoObject {
|
|
|
237
231
|
}
|
|
238
232
|
static fromJSONField(field) {
|
|
239
233
|
return PriceInfoObject.reified().new({
|
|
240
|
-
id:
|
|
241
|
-
priceInfo:
|
|
234
|
+
id: decodeFromJSONField(UID.reified(), field.id),
|
|
235
|
+
priceInfo: decodeFromJSONField(PriceInfo.reified(), field.priceInfo),
|
|
242
236
|
});
|
|
243
237
|
}
|
|
244
238
|
static fromJSON(json) {
|
|
@@ -262,7 +256,7 @@ class PriceInfoObject {
|
|
|
262
256
|
!isPriceInfoObject(data.bcs.type)) {
|
|
263
257
|
throw new Error(`object at is not a PriceInfoObject object`);
|
|
264
258
|
}
|
|
265
|
-
return PriceInfoObject.fromBcs((
|
|
259
|
+
return PriceInfoObject.fromBcs(fromBase64(data.bcs.bcsBytes));
|
|
266
260
|
}
|
|
267
261
|
if (data.content) {
|
|
268
262
|
return PriceInfoObject.fromSuiParsedData(data.content);
|
|
@@ -284,7 +278,6 @@ class PriceInfoObject {
|
|
|
284
278
|
});
|
|
285
279
|
}
|
|
286
280
|
}
|
|
287
|
-
|
|
288
|
-
PriceInfoObject.$typeName = `${index_1.PKG_V1}::price_info::PriceInfoObject`;
|
|
281
|
+
PriceInfoObject.$typeName = `${PKG_V1}::price_info::PriceInfoObject`;
|
|
289
282
|
PriceInfoObject.$numTypeParams = 0;
|
|
290
283
|
PriceInfoObject.$isPhantom = [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BcsType } from "@mysten/sui/bcs";
|
|
2
2
|
import { FieldsWithTypes } from "./util";
|
|
3
|
-
import {
|
|
3
|
+
import { SuiJsonRpcClient, SuiParsedData, SuiObjectData } from "@mysten/sui/jsonRpc";
|
|
4
4
|
export { vector } from "./vector";
|
|
5
5
|
export interface StructClass {
|
|
6
6
|
readonly $typeName: string;
|
|
@@ -37,7 +37,7 @@ export interface StructClassReified<T extends StructClass, Fields> {
|
|
|
37
37
|
fromJSON: (json: Record<string, any>) => T;
|
|
38
38
|
fromSuiParsedData: (content: SuiParsedData) => T;
|
|
39
39
|
fromSuiObjectData: (data: SuiObjectData) => T;
|
|
40
|
-
fetch: (client:
|
|
40
|
+
fetch: (client: SuiJsonRpcClient, id: string) => Promise<T>;
|
|
41
41
|
new: (fields: Fields) => T;
|
|
42
42
|
kind: "StructClassReified";
|
|
43
43
|
}
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.phantom = phantom;
|
|
5
|
-
exports.toBcs = toBcs;
|
|
6
|
-
exports.extractType = extractType;
|
|
7
|
-
exports.decodeFromFields = decodeFromFields;
|
|
8
|
-
exports.decodeFromFieldsWithTypes = decodeFromFieldsWithTypes;
|
|
9
|
-
exports.assertReifiedTypeArgsMatch = assertReifiedTypeArgsMatch;
|
|
10
|
-
exports.assertFieldsWithTypesArgsMatch = assertFieldsWithTypesArgsMatch;
|
|
11
|
-
exports.fieldToJSON = fieldToJSON;
|
|
12
|
-
exports.decodeFromJSONField = decodeFromJSONField;
|
|
13
|
-
const bcs_1 = require("@mysten/sui/bcs");
|
|
14
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
15
|
-
const util_1 = require("./util");
|
|
1
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
2
|
+
import { fromHex, toHex } from "@mysten/sui/utils";
|
|
3
|
+
import { compressSuiType, parseTypeName } from "./util";
|
|
16
4
|
// for backwards compatibility
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function phantom(type) {
|
|
5
|
+
export { vector } from "./vector";
|
|
6
|
+
export function phantom(type) {
|
|
20
7
|
if (typeof type === "string") {
|
|
21
8
|
return {
|
|
22
9
|
phantomType: type,
|
|
@@ -30,33 +17,33 @@ function phantom(type) {
|
|
|
30
17
|
};
|
|
31
18
|
}
|
|
32
19
|
}
|
|
33
|
-
const Address =
|
|
34
|
-
input: (val) => (
|
|
35
|
-
output: (val) => (
|
|
20
|
+
const Address = bcs.bytes(32).transform({
|
|
21
|
+
input: (val) => fromHex(val),
|
|
22
|
+
output: (val) => toHex(val),
|
|
36
23
|
});
|
|
37
|
-
function toBcs(arg) {
|
|
24
|
+
export function toBcs(arg) {
|
|
38
25
|
switch (arg) {
|
|
39
26
|
case "bool":
|
|
40
|
-
return
|
|
27
|
+
return bcs.bool();
|
|
41
28
|
case "u8":
|
|
42
|
-
return
|
|
29
|
+
return bcs.u8();
|
|
43
30
|
case "u16":
|
|
44
|
-
return
|
|
31
|
+
return bcs.u16();
|
|
45
32
|
case "u32":
|
|
46
|
-
return
|
|
33
|
+
return bcs.u32();
|
|
47
34
|
case "u64":
|
|
48
|
-
return
|
|
35
|
+
return bcs.u64();
|
|
49
36
|
case "u128":
|
|
50
|
-
return
|
|
37
|
+
return bcs.u128();
|
|
51
38
|
case "u256":
|
|
52
|
-
return
|
|
39
|
+
return bcs.u256();
|
|
53
40
|
case "address":
|
|
54
41
|
return Address;
|
|
55
42
|
default:
|
|
56
43
|
return arg.bcs;
|
|
57
44
|
}
|
|
58
45
|
}
|
|
59
|
-
function extractType(reified) {
|
|
46
|
+
export function extractType(reified) {
|
|
60
47
|
switch (reified) {
|
|
61
48
|
case "u8":
|
|
62
49
|
case "u16":
|
|
@@ -78,7 +65,7 @@ function extractType(reified) {
|
|
|
78
65
|
}
|
|
79
66
|
throw new Error("unreachable");
|
|
80
67
|
}
|
|
81
|
-
function decodeFromFields(reified, field) {
|
|
68
|
+
export function decodeFromFields(reified, field) {
|
|
82
69
|
switch (reified) {
|
|
83
70
|
case "bool":
|
|
84
71
|
case "u8":
|
|
@@ -117,7 +104,7 @@ function decodeFromFields(reified, field) {
|
|
|
117
104
|
return reified.fromFields(field);
|
|
118
105
|
}
|
|
119
106
|
}
|
|
120
|
-
function decodeFromFieldsWithTypes(reified, item) {
|
|
107
|
+
export function decodeFromFieldsWithTypes(reified, item) {
|
|
121
108
|
switch (reified) {
|
|
122
109
|
case "bool":
|
|
123
110
|
case "u8":
|
|
@@ -154,23 +141,23 @@ function decodeFromFieldsWithTypes(reified, item) {
|
|
|
154
141
|
return reified.fromFieldsWithTypes(item);
|
|
155
142
|
}
|
|
156
143
|
}
|
|
157
|
-
function assertReifiedTypeArgsMatch(fullType, typeArgs, reifiedTypeArgs) {
|
|
144
|
+
export function assertReifiedTypeArgsMatch(fullType, typeArgs, reifiedTypeArgs) {
|
|
158
145
|
if (reifiedTypeArgs.length !== typeArgs.length) {
|
|
159
146
|
throw new Error(`provided item has mismatching number of type arguments ${fullType} (expected ${reifiedTypeArgs.length}, got ${typeArgs.length}))`);
|
|
160
147
|
}
|
|
161
148
|
for (let i = 0; i < typeArgs.length; i++) {
|
|
162
|
-
if (
|
|
163
|
-
|
|
149
|
+
if (compressSuiType(typeArgs[i]) !==
|
|
150
|
+
compressSuiType(extractType(reifiedTypeArgs[i]))) {
|
|
164
151
|
throw new Error(`provided item has mismatching type arguments ${fullType} (expected ${extractType(reifiedTypeArgs[i])}, got ${typeArgs[i]}))`);
|
|
165
152
|
}
|
|
166
153
|
}
|
|
167
154
|
}
|
|
168
|
-
function assertFieldsWithTypesArgsMatch(item, reifiedTypeArgs) {
|
|
169
|
-
const { typeArgs: itemTypeArgs } =
|
|
155
|
+
export function assertFieldsWithTypesArgsMatch(item, reifiedTypeArgs) {
|
|
156
|
+
const { typeArgs: itemTypeArgs } = parseTypeName(item.type);
|
|
170
157
|
assertReifiedTypeArgsMatch(item.type, itemTypeArgs, reifiedTypeArgs);
|
|
171
158
|
}
|
|
172
|
-
function fieldToJSON(type, field) {
|
|
173
|
-
const { typeName, typeArgs } =
|
|
159
|
+
export function fieldToJSON(type, field) {
|
|
160
|
+
const { typeName, typeArgs } = parseTypeName(type);
|
|
174
161
|
switch (typeName) {
|
|
175
162
|
case "bool":
|
|
176
163
|
return field;
|
|
@@ -204,7 +191,7 @@ function fieldToJSON(type, field) {
|
|
|
204
191
|
return field.toJSONField();
|
|
205
192
|
}
|
|
206
193
|
}
|
|
207
|
-
function decodeFromJSONField(typeArg, field) {
|
|
194
|
+
export function decodeFromJSONField(typeArg, field) {
|
|
208
195
|
switch (typeArg) {
|
|
209
196
|
case "bool":
|
|
210
197
|
case "u8":
|