@suilend/sdk 7.0.1 → 8.0.0

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.
@@ -1,229 +0,0 @@
1
- import { decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom, } from "../../../../_framework/reified.js";
2
- import { composeSuiType, compressSuiType, } from "../../../../_framework/util.js";
3
- import { UID } from "../../0x2/object/structs.js";
4
- import { PKG_V1 } from "../index.js";
5
- import { PriceFeed } from "../price-feed/structs.js";
6
- import { bcs } from "@mysten/sui/bcs";
7
- /* ============================== PriceInfo =============================== */
8
- export function isPriceInfo(type) {
9
- type = compressSuiType(type);
10
- return type === `${PKG_V1}::price_info::PriceInfo`;
11
- }
12
- export class PriceInfo {
13
- __StructClass = true;
14
- static $typeName = `${PKG_V1}::price_info::PriceInfo`;
15
- static $numTypeParams = 0;
16
- static $isPhantom = [];
17
- $typeName = PriceInfo.$typeName;
18
- $fullTypeName;
19
- $typeArgs;
20
- $isPhantom = PriceInfo.$isPhantom;
21
- attestationTime;
22
- arrivalTime;
23
- priceFeed;
24
- constructor(typeArgs, fields) {
25
- this.$fullTypeName = composeSuiType(PriceInfo.$typeName, ...typeArgs);
26
- this.$typeArgs = typeArgs;
27
- this.attestationTime = fields.attestationTime;
28
- this.arrivalTime = fields.arrivalTime;
29
- this.priceFeed = fields.priceFeed;
30
- }
31
- static reified() {
32
- return {
33
- typeName: PriceInfo.$typeName,
34
- fullTypeName: composeSuiType(PriceInfo.$typeName, ...[]),
35
- typeArgs: [],
36
- isPhantom: PriceInfo.$isPhantom,
37
- reifiedTypeArgs: [],
38
- fromFields: (fields) => PriceInfo.fromFields(fields),
39
- fromFieldsWithTypes: (item) => PriceInfo.fromFieldsWithTypes(item),
40
- fromBcs: (data) => PriceInfo.fromBcs(data),
41
- bcs: PriceInfo.bcs,
42
- fromJSONField: (field) => PriceInfo.fromJSONField(field),
43
- fromJSON: (json) => PriceInfo.fromJSON(json),
44
- fetch: async (client, id) => PriceInfo.fetch(client, id),
45
- new: (fields) => {
46
- return new PriceInfo([], fields);
47
- },
48
- kind: "StructClassReified",
49
- };
50
- }
51
- static get r() {
52
- return PriceInfo.reified();
53
- }
54
- static phantom() {
55
- return phantom(PriceInfo.reified());
56
- }
57
- static get p() {
58
- return PriceInfo.phantom();
59
- }
60
- static get bcs() {
61
- return bcs.struct("PriceInfo", {
62
- attestation_time: bcs.u64(),
63
- arrival_time: bcs.u64(),
64
- price_feed: PriceFeed.bcs,
65
- });
66
- }
67
- static fromFields(fields) {
68
- return PriceInfo.reified().new({
69
- attestationTime: decodeFromFields("u64", fields.attestation_time),
70
- arrivalTime: decodeFromFields("u64", fields.arrival_time),
71
- priceFeed: decodeFromFields(PriceFeed.reified(), fields.price_feed),
72
- });
73
- }
74
- static fromFieldsWithTypes(item) {
75
- if (!isPriceInfo(item.type)) {
76
- throw new Error("not a PriceInfo type");
77
- }
78
- return PriceInfo.reified().new({
79
- attestationTime: decodeFromFieldsWithTypes("u64", item.fields.attestation_time),
80
- arrivalTime: decodeFromFieldsWithTypes("u64", item.fields.arrival_time),
81
- priceFeed: decodeFromFieldsWithTypes(PriceFeed.reified(), item.fields.price_feed),
82
- });
83
- }
84
- static fromBcs(data) {
85
- return PriceInfo.fromFields(PriceInfo.bcs.parse(data));
86
- }
87
- toJSONField() {
88
- return {
89
- attestationTime: this.attestationTime.toString(),
90
- arrivalTime: this.arrivalTime.toString(),
91
- priceFeed: this.priceFeed.toJSONField(),
92
- };
93
- }
94
- toJSON() {
95
- return {
96
- $typeName: this.$typeName,
97
- $typeArgs: this.$typeArgs,
98
- ...this.toJSONField(),
99
- };
100
- }
101
- static fromJSONField(field) {
102
- return PriceInfo.reified().new({
103
- attestationTime: decodeFromJSONField("u64", field.attestationTime),
104
- arrivalTime: decodeFromJSONField("u64", field.arrivalTime),
105
- priceFeed: decodeFromJSONField(PriceFeed.reified(), field.priceFeed),
106
- });
107
- }
108
- static fromJSON(json) {
109
- if (json.$typeName !== PriceInfo.$typeName) {
110
- throw new Error("not a WithTwoGenerics json object");
111
- }
112
- return PriceInfo.fromJSONField(json);
113
- }
114
- static async fetch(client, id) {
115
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
116
- if (!isPriceInfo(object.type)) {
117
- throw new Error(`object at id ${id} is not a PriceInfo object`);
118
- }
119
- return PriceInfo.fromBcs(object.content);
120
- }
121
- }
122
- /* ============================== PriceInfoObject =============================== */
123
- export function isPriceInfoObject(type) {
124
- type = compressSuiType(type);
125
- return type === `${PKG_V1}::price_info::PriceInfoObject`;
126
- }
127
- export class PriceInfoObject {
128
- __StructClass = true;
129
- static $typeName = `${PKG_V1}::price_info::PriceInfoObject`;
130
- static $numTypeParams = 0;
131
- static $isPhantom = [];
132
- $typeName = PriceInfoObject.$typeName;
133
- $fullTypeName;
134
- $typeArgs;
135
- $isPhantom = PriceInfoObject.$isPhantom;
136
- id;
137
- priceInfo;
138
- constructor(typeArgs, fields) {
139
- this.$fullTypeName = composeSuiType(PriceInfoObject.$typeName, ...typeArgs);
140
- this.$typeArgs = typeArgs;
141
- this.id = fields.id;
142
- this.priceInfo = fields.priceInfo;
143
- }
144
- static reified() {
145
- return {
146
- typeName: PriceInfoObject.$typeName,
147
- fullTypeName: composeSuiType(PriceInfoObject.$typeName, ...[]),
148
- typeArgs: [],
149
- isPhantom: PriceInfoObject.$isPhantom,
150
- reifiedTypeArgs: [],
151
- fromFields: (fields) => PriceInfoObject.fromFields(fields),
152
- fromFieldsWithTypes: (item) => PriceInfoObject.fromFieldsWithTypes(item),
153
- fromBcs: (data) => PriceInfoObject.fromBcs(data),
154
- bcs: PriceInfoObject.bcs,
155
- fromJSONField: (field) => PriceInfoObject.fromJSONField(field),
156
- fromJSON: (json) => PriceInfoObject.fromJSON(json),
157
- fetch: async (client, id) => PriceInfoObject.fetch(client, id),
158
- new: (fields) => {
159
- return new PriceInfoObject([], fields);
160
- },
161
- kind: "StructClassReified",
162
- };
163
- }
164
- static get r() {
165
- return PriceInfoObject.reified();
166
- }
167
- static phantom() {
168
- return phantom(PriceInfoObject.reified());
169
- }
170
- static get p() {
171
- return PriceInfoObject.phantom();
172
- }
173
- static get bcs() {
174
- return bcs.struct("PriceInfoObject", {
175
- id: UID.bcs,
176
- price_info: PriceInfo.bcs,
177
- });
178
- }
179
- static fromFields(fields) {
180
- return PriceInfoObject.reified().new({
181
- id: decodeFromFields(UID.reified(), fields.id),
182
- priceInfo: decodeFromFields(PriceInfo.reified(), fields.price_info),
183
- });
184
- }
185
- static fromFieldsWithTypes(item) {
186
- if (!isPriceInfoObject(item.type)) {
187
- throw new Error("not a PriceInfoObject type");
188
- }
189
- return PriceInfoObject.reified().new({
190
- id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
191
- priceInfo: decodeFromFieldsWithTypes(PriceInfo.reified(), item.fields.price_info),
192
- });
193
- }
194
- static fromBcs(data) {
195
- return PriceInfoObject.fromFields(PriceInfoObject.bcs.parse(data));
196
- }
197
- toJSONField() {
198
- return {
199
- id: this.id,
200
- priceInfo: this.priceInfo.toJSONField(),
201
- };
202
- }
203
- toJSON() {
204
- return {
205
- $typeName: this.$typeName,
206
- $typeArgs: this.$typeArgs,
207
- ...this.toJSONField(),
208
- };
209
- }
210
- static fromJSONField(field) {
211
- return PriceInfoObject.reified().new({
212
- id: decodeFromJSONField(UID.reified(), field.id),
213
- priceInfo: decodeFromJSONField(PriceInfo.reified(), field.priceInfo),
214
- });
215
- }
216
- static fromJSON(json) {
217
- if (json.$typeName !== PriceInfoObject.$typeName) {
218
- throw new Error("not a WithTwoGenerics json object");
219
- }
220
- return PriceInfoObject.fromJSONField(json);
221
- }
222
- static async fetch(client, id) {
223
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
224
- if (!isPriceInfoObject(object.type)) {
225
- throw new Error(`object at id ${id} is not a PriceInfoObject object`);
226
- }
227
- return PriceInfoObject.fromBcs(object.content);
228
- }
229
- }