@suilend/sdk 12.7.0 → 13.0.0-next.g16373c6

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.
Files changed (88) hide show
  1. package/_generated/_dependencies/pyth-2/price-identifier/structs.d.ts +46 -0
  2. package/_generated/_dependencies/{source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e → pyth-2}/price-identifier/structs.js +45 -25
  3. package/_generated/_dependencies/std/ascii/structs.d.ts +100 -0
  4. package/_generated/_dependencies/{source/0x1 → std}/ascii/structs.js +153 -103
  5. package/_generated/_dependencies/{source/0x1 → std}/option/structs.d.ts +29 -21
  6. package/_generated/_dependencies/std/option/structs.js +155 -0
  7. package/_generated/_dependencies/std/type-name/structs.d.ts +65 -0
  8. package/_generated/_dependencies/{source/0x1 → std}/type-name/structs.js +49 -22
  9. package/_generated/_dependencies/sui/bag/structs.d.ts +75 -0
  10. package/_generated/_dependencies/sui/bag/structs.js +154 -0
  11. package/_generated/_dependencies/{source/0x2 → sui}/balance/structs.d.ts +80 -60
  12. package/_generated/_dependencies/sui/balance/structs.js +306 -0
  13. package/_generated/_dependencies/sui/object/structs.d.ts +104 -0
  14. package/_generated/_dependencies/{source/0x2 → sui}/object/structs.js +98 -46
  15. package/_generated/_dependencies/{source/0x2 → sui}/object-table/structs.d.ts +37 -30
  16. package/_generated/_dependencies/sui/object-table/structs.js +164 -0
  17. package/_generated/_envs/index.d.ts +3 -0
  18. package/_generated/_envs/index.js +18 -0
  19. package/_generated/_envs/mainnet.d.ts +2 -0
  20. package/_generated/_envs/mainnet.js +490 -0
  21. package/_generated/_framework/env.d.ts +137 -0
  22. package/_generated/_framework/env.js +261 -0
  23. package/_generated/_framework/reified.d.ts +68 -36
  24. package/_generated/_framework/reified.js +110 -98
  25. package/_generated/_framework/util.d.ts +4 -4
  26. package/_generated/_framework/util.js +82 -79
  27. package/_generated/_framework/vector.d.ts +11 -9
  28. package/_generated/_framework/vector.js +10 -10
  29. package/_generated/suilend/cell/structs.d.ts +24 -22
  30. package/_generated/suilend/cell/structs.js +68 -24
  31. package/_generated/suilend/decimal/structs.d.ts +28 -24
  32. package/_generated/suilend/decimal/structs.js +45 -24
  33. package/_generated/suilend/index.d.ts +5 -6
  34. package/_generated/suilend/index.js +10 -19
  35. package/_generated/suilend/lending-market/functions.d.ts +1123 -149
  36. package/_generated/suilend/lending-market/functions.js +1121 -207
  37. package/_generated/suilend/lending-market/structs.d.ts +985 -1290
  38. package/_generated/suilend/lending-market/structs.js +2482 -1282
  39. package/_generated/suilend/lending-market-registry/functions.d.ts +32 -3
  40. package/_generated/suilend/lending-market-registry/functions.js +30 -6
  41. package/_generated/suilend/liquidity-mining/structs.d.ts +200 -333
  42. package/_generated/suilend/liquidity-mining/structs.js +449 -319
  43. package/_generated/suilend/obligation/structs.d.ts +406 -918
  44. package/_generated/suilend/obligation/structs.js +786 -596
  45. package/_generated/suilend/rate-limiter/functions.d.ts +134 -15
  46. package/_generated/suilend/rate-limiter/functions.js +139 -21
  47. package/_generated/suilend/rate-limiter/structs.d.ts +72 -80
  48. package/_generated/suilend/rate-limiter/structs.js +98 -48
  49. package/_generated/suilend/reserve/structs.d.ts +706 -904
  50. package/_generated/suilend/reserve/structs.js +1798 -761
  51. package/_generated/suilend/reserve-config/functions.d.ts +718 -96
  52. package/_generated/suilend/reserve-config/functions.js +751 -157
  53. package/_generated/suilend/reserve-config/structs.d.ts +148 -163
  54. package/_generated/suilend/reserve-config/structs.js +260 -94
  55. package/client.d.ts +4 -2
  56. package/client.js +35 -39
  57. package/lib/initialize.d.ts +617 -83
  58. package/lib/initialize.js +151 -48
  59. package/lib/proCompatible.js +5 -5
  60. package/package.json +1 -1
  61. package/parsers/lendingMarket.d.ts +9 -9
  62. package/parsers/obligation.d.ts +14 -14
  63. package/parsers/obligation.js +4 -4
  64. package/parsers/rateLimiter.d.ts +1 -1
  65. package/parsers/reserve.d.ts +12 -12
  66. package/parsers/reserve.js +2 -2
  67. package/strategies.d.ts +14 -14
  68. package/utils/events.d.ts +20 -0
  69. package/utils/events.js +3 -1
  70. package/utils/obligation.d.ts +3 -0
  71. package/utils/obligation.js +10 -0
  72. package/utils/simulate.d.ts +13 -1
  73. package/utils/simulate.js +19 -5
  74. package/_generated/_dependencies/source/0x1/ascii/structs.d.ts +0 -84
  75. package/_generated/_dependencies/source/0x1/index.d.ts +0 -3
  76. package/_generated/_dependencies/source/0x1/index.js +0 -3
  77. package/_generated/_dependencies/source/0x1/option/structs.js +0 -110
  78. package/_generated/_dependencies/source/0x1/type-name/structs.d.ts +0 -47
  79. package/_generated/_dependencies/source/0x2/bag/structs.d.ts +0 -52
  80. package/_generated/_dependencies/source/0x2/bag/structs.js +0 -113
  81. package/_generated/_dependencies/source/0x2/balance/structs.js +0 -210
  82. package/_generated/_dependencies/source/0x2/index.d.ts +0 -3
  83. package/_generated/_dependencies/source/0x2/index.js +0 -3
  84. package/_generated/_dependencies/source/0x2/object/structs.d.ts +0 -82
  85. package/_generated/_dependencies/source/0x2/object-table/structs.js +0 -115
  86. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.d.ts +0 -4
  87. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/index.js +0 -4
  88. package/_generated/_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.d.ts +0 -46
@@ -1,126 +1,1369 @@
1
- import * as reified from "../../_framework/reified.js";
2
- import { TypeName } from "../../_dependencies/source/0x1/type-name/structs.js";
3
- import { Balance, Supply, } from "../../_dependencies/source/0x2/balance/structs.js";
4
- import { ID, UID } from "../../_dependencies/source/0x2/object/structs.js";
5
- import { PriceIdentifier } from "../../_dependencies/source/0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e/price-identifier/structs.js";
6
- import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, } from "../../_framework/reified.js";
7
- import { composeSuiType, compressSuiType, } from "../../_framework/util.js";
8
- import { Cell } from "../cell/structs.js";
9
- import { Decimal } from "../decimal/structs.js";
10
- import { PKG_V1, PKG_V8 } from "../index.js";
11
- import { PoolRewardManager } from "../liquidity-mining/structs.js";
12
- import { ReserveConfig } from "../reserve-config/structs.js";
13
- import { bcs } from "@mysten/sui/bcs";
14
- import { fromHex, toHex } from "@mysten/sui/utils";
1
+ /** The reserve module holds the coins of a certain type for a given lending market. */
2
+ import { bcs } from '@mysten/sui/bcs';
3
+ import { fromHex, toHex } from '@mysten/sui/utils';
4
+ import { PriceIdentifier } from '../../_dependencies/pyth-2/price-identifier/structs.js';
5
+ import { TypeName } from '../../_dependencies/std/type-name/structs.js';
6
+ import { Balance, Supply } from '../../_dependencies/sui/balance/structs.js';
7
+ import { ID, UID } from '../../_dependencies/sui/object/structs.js';
8
+ import { getTypeOrigin } from '../../_envs/index.js';
9
+ import { assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, } from '../../_framework/reified.js';
10
+ import { composeSuiType, compressSuiType, parseTypeName, } from '../../_framework/util.js';
11
+ import { Cell } from '../cell/structs.js';
12
+ import { Decimal } from '../decimal/structs.js';
13
+ import { PoolRewardManager } from '../liquidity-mining/structs.js';
14
+ import { ReserveConfig } from '../reserve-config/structs.js';
15
+ /* ============================== Reserve =============================== */
16
+ export function isReserve(type) {
17
+ type = compressSuiType(type);
18
+ return type.startsWith(`${getTypeOrigin('suilend', 'reserve::Reserve')}::reserve::Reserve` + '<');
19
+ }
20
+ export class Reserve {
21
+ __StructClass = true;
22
+ static get $typeName() {
23
+ return `${getTypeOrigin('suilend', 'reserve::Reserve')}::reserve::Reserve`;
24
+ }
25
+ static $numTypeParams = 1;
26
+ static $isPhantom = [true];
27
+ $typeName = Reserve.$typeName;
28
+ $fullTypeName;
29
+ $typeArgs;
30
+ $isPhantom = Reserve.$isPhantom;
31
+ id;
32
+ lendingMarketId;
33
+ arrayIndex;
34
+ coinType;
35
+ config;
36
+ mintDecimals;
37
+ priceIdentifier;
38
+ price;
39
+ smoothedPrice;
40
+ priceLastUpdateTimestampS;
41
+ availableAmount;
42
+ ctokenSupply;
43
+ borrowedAmount;
44
+ cumulativeBorrowRate;
45
+ interestLastUpdateTimestampS;
46
+ unclaimedSpreadFees;
47
+ /** unused */
48
+ attributedBorrowValue;
49
+ depositsPoolRewardManager;
50
+ borrowsPoolRewardManager;
51
+ constructor(typeArgs, fields) {
52
+ this.$fullTypeName = composeSuiType(Reserve.$typeName, ...typeArgs);
53
+ this.$typeArgs = typeArgs;
54
+ this.id = fields.id;
55
+ this.lendingMarketId = fields.lendingMarketId;
56
+ this.arrayIndex = fields.arrayIndex;
57
+ this.coinType = fields.coinType;
58
+ this.config = fields.config;
59
+ this.mintDecimals = fields.mintDecimals;
60
+ this.priceIdentifier = fields.priceIdentifier;
61
+ this.price = fields.price;
62
+ this.smoothedPrice = fields.smoothedPrice;
63
+ this.priceLastUpdateTimestampS = fields.priceLastUpdateTimestampS;
64
+ this.availableAmount = fields.availableAmount;
65
+ this.ctokenSupply = fields.ctokenSupply;
66
+ this.borrowedAmount = fields.borrowedAmount;
67
+ this.cumulativeBorrowRate = fields.cumulativeBorrowRate;
68
+ this.interestLastUpdateTimestampS = fields.interestLastUpdateTimestampS;
69
+ this.unclaimedSpreadFees = fields.unclaimedSpreadFees;
70
+ this.attributedBorrowValue = fields.attributedBorrowValue;
71
+ this.depositsPoolRewardManager = fields.depositsPoolRewardManager;
72
+ this.borrowsPoolRewardManager = fields.borrowsPoolRewardManager;
73
+ }
74
+ static reified(P) {
75
+ const reifiedBcs = Reserve.bcs;
76
+ return {
77
+ get typeName() {
78
+ return Reserve.$typeName;
79
+ },
80
+ get fullTypeName() {
81
+ return composeSuiType(Reserve.$typeName, ...[extractType(P)]);
82
+ },
83
+ get typeArgs() {
84
+ return [extractType(P)];
85
+ },
86
+ isPhantom: Reserve.$isPhantom,
87
+ reifiedTypeArgs: [P],
88
+ fromFields: (fields) => Reserve.fromFields(P, fields),
89
+ fromFieldsWithTypes: (item) => Reserve.fromFieldsWithTypes(P, item),
90
+ fromBcs: (data) => Reserve.fromFields(P, reifiedBcs.parse(data)),
91
+ bcs: reifiedBcs,
92
+ fromJSONField: (field) => Reserve.fromJSONField(P, field),
93
+ fromJSON: (json) => Reserve.fromJSON(P, json),
94
+ fromCoreObject: (obj) => Reserve.fromCoreObject(P, obj),
95
+ fetch: async (client, id) => Reserve.fetch(client, P, id),
96
+ new: (fields) => {
97
+ return new Reserve([extractType(P)], fields);
98
+ },
99
+ kind: 'StructClassReified',
100
+ };
101
+ }
102
+ static get r() {
103
+ return Reserve.reified;
104
+ }
105
+ static phantom(P) {
106
+ return phantom(Reserve.reified(P));
107
+ }
108
+ static get p() {
109
+ return Reserve.phantom;
110
+ }
111
+ static instantiateBcs() {
112
+ return bcs.struct('Reserve', {
113
+ id: UID.bcs,
114
+ lending_market_id: ID.bcs,
115
+ array_index: bcs.u64(),
116
+ coin_type: TypeName.bcs,
117
+ config: Cell.bcs(ReserveConfig.bcs),
118
+ mint_decimals: bcs.u8(),
119
+ price_identifier: PriceIdentifier.bcs,
120
+ price: Decimal.bcs,
121
+ smoothed_price: Decimal.bcs,
122
+ price_last_update_timestamp_s: bcs.u64(),
123
+ available_amount: bcs.u64(),
124
+ ctoken_supply: bcs.u64(),
125
+ borrowed_amount: Decimal.bcs,
126
+ cumulative_borrow_rate: Decimal.bcs,
127
+ interest_last_update_timestamp_s: bcs.u64(),
128
+ unclaimed_spread_fees: Decimal.bcs,
129
+ attributed_borrow_value: Decimal.bcs,
130
+ deposits_pool_reward_manager: PoolRewardManager.bcs,
131
+ borrows_pool_reward_manager: PoolRewardManager.bcs,
132
+ });
133
+ }
134
+ static cachedBcs = null;
135
+ static get bcs() {
136
+ if (!Reserve.cachedBcs) {
137
+ Reserve.cachedBcs = Reserve.instantiateBcs();
138
+ }
139
+ return Reserve.cachedBcs;
140
+ }
141
+ static fromFields(typeArg, fields) {
142
+ return Reserve.reified(typeArg).new({
143
+ id: decodeFromFields(UID.reified(), fields.id),
144
+ lendingMarketId: decodeFromFields(ID.reified(), fields.lending_market_id),
145
+ arrayIndex: decodeFromFields('u64', fields.array_index),
146
+ coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
147
+ config: decodeFromFields(Cell.reified(ReserveConfig.reified()), fields.config),
148
+ mintDecimals: decodeFromFields('u8', fields.mint_decimals),
149
+ priceIdentifier: decodeFromFields(PriceIdentifier.reified(), fields.price_identifier),
150
+ price: decodeFromFields(Decimal.reified(), fields.price),
151
+ smoothedPrice: decodeFromFields(Decimal.reified(), fields.smoothed_price),
152
+ priceLastUpdateTimestampS: decodeFromFields('u64', fields.price_last_update_timestamp_s),
153
+ availableAmount: decodeFromFields('u64', fields.available_amount),
154
+ ctokenSupply: decodeFromFields('u64', fields.ctoken_supply),
155
+ borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
156
+ cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
157
+ interestLastUpdateTimestampS: decodeFromFields('u64', fields.interest_last_update_timestamp_s),
158
+ unclaimedSpreadFees: decodeFromFields(Decimal.reified(), fields.unclaimed_spread_fees),
159
+ attributedBorrowValue: decodeFromFields(Decimal.reified(), fields.attributed_borrow_value),
160
+ depositsPoolRewardManager: decodeFromFields(PoolRewardManager.reified(), fields.deposits_pool_reward_manager),
161
+ borrowsPoolRewardManager: decodeFromFields(PoolRewardManager.reified(), fields.borrows_pool_reward_manager),
162
+ });
163
+ }
164
+ static fromFieldsWithTypes(typeArg, item) {
165
+ if (!isReserve(item.type)) {
166
+ throw new Error('not a Reserve type');
167
+ }
168
+ assertFieldsWithTypesArgsMatch(item, [typeArg]);
169
+ return Reserve.reified(typeArg).new({
170
+ id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
171
+ lendingMarketId: decodeFromFieldsWithTypes(ID.reified(), item.fields.lending_market_id),
172
+ arrayIndex: decodeFromFieldsWithTypes('u64', item.fields.array_index),
173
+ coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
174
+ config: decodeFromFieldsWithTypes(Cell.reified(ReserveConfig.reified()), item.fields.config),
175
+ mintDecimals: decodeFromFieldsWithTypes('u8', item.fields.mint_decimals),
176
+ priceIdentifier: decodeFromFieldsWithTypes(PriceIdentifier.reified(), item.fields.price_identifier),
177
+ price: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.price),
178
+ smoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price),
179
+ priceLastUpdateTimestampS: decodeFromFieldsWithTypes('u64', item.fields.price_last_update_timestamp_s),
180
+ availableAmount: decodeFromFieldsWithTypes('u64', item.fields.available_amount),
181
+ ctokenSupply: decodeFromFieldsWithTypes('u64', item.fields.ctoken_supply),
182
+ borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
183
+ cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
184
+ interestLastUpdateTimestampS: decodeFromFieldsWithTypes('u64', item.fields.interest_last_update_timestamp_s),
185
+ unclaimedSpreadFees: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unclaimed_spread_fees),
186
+ attributedBorrowValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.attributed_borrow_value),
187
+ depositsPoolRewardManager: decodeFromFieldsWithTypes(PoolRewardManager.reified(), item.fields.deposits_pool_reward_manager),
188
+ borrowsPoolRewardManager: decodeFromFieldsWithTypes(PoolRewardManager.reified(), item.fields.borrows_pool_reward_manager),
189
+ });
190
+ }
191
+ static fromBcs(typeArg, data) {
192
+ return Reserve.fromFields(typeArg, Reserve.bcs.parse(data));
193
+ }
194
+ toJSONField() {
195
+ return {
196
+ id: this.id,
197
+ lendingMarketId: this.lendingMarketId,
198
+ arrayIndex: this.arrayIndex.toString(),
199
+ coinType: this.coinType,
200
+ config: this.config.toJSONField(),
201
+ mintDecimals: this.mintDecimals,
202
+ priceIdentifier: this.priceIdentifier.toJSONField(),
203
+ price: this.price.toJSONField(),
204
+ smoothedPrice: this.smoothedPrice.toJSONField(),
205
+ priceLastUpdateTimestampS: this.priceLastUpdateTimestampS.toString(),
206
+ availableAmount: this.availableAmount.toString(),
207
+ ctokenSupply: this.ctokenSupply.toString(),
208
+ borrowedAmount: this.borrowedAmount.toJSONField(),
209
+ cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
210
+ interestLastUpdateTimestampS: this.interestLastUpdateTimestampS.toString(),
211
+ unclaimedSpreadFees: this.unclaimedSpreadFees.toJSONField(),
212
+ attributedBorrowValue: this.attributedBorrowValue.toJSONField(),
213
+ depositsPoolRewardManager: this.depositsPoolRewardManager.toJSONField(),
214
+ borrowsPoolRewardManager: this.borrowsPoolRewardManager.toJSONField(),
215
+ };
216
+ }
217
+ toJSON() {
218
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
219
+ }
220
+ static fromJSONField(typeArg, field) {
221
+ return Reserve.reified(typeArg).new({
222
+ id: decodeFromJSONField(UID.reified(), field.id),
223
+ lendingMarketId: decodeFromJSONField(ID.reified(), field.lendingMarketId),
224
+ arrayIndex: decodeFromJSONField('u64', field.arrayIndex),
225
+ coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
226
+ config: decodeFromJSONField(Cell.reified(ReserveConfig.reified()), field.config),
227
+ mintDecimals: decodeFromJSONField('u8', field.mintDecimals),
228
+ priceIdentifier: decodeFromJSONField(PriceIdentifier.reified(), field.priceIdentifier),
229
+ price: decodeFromJSONField(Decimal.reified(), field.price),
230
+ smoothedPrice: decodeFromJSONField(Decimal.reified(), field.smoothedPrice),
231
+ priceLastUpdateTimestampS: decodeFromJSONField('u64', field.priceLastUpdateTimestampS),
232
+ availableAmount: decodeFromJSONField('u64', field.availableAmount),
233
+ ctokenSupply: decodeFromJSONField('u64', field.ctokenSupply),
234
+ borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
235
+ cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
236
+ interestLastUpdateTimestampS: decodeFromJSONField('u64', field.interestLastUpdateTimestampS),
237
+ unclaimedSpreadFees: decodeFromJSONField(Decimal.reified(), field.unclaimedSpreadFees),
238
+ attributedBorrowValue: decodeFromJSONField(Decimal.reified(), field.attributedBorrowValue),
239
+ depositsPoolRewardManager: decodeFromJSONField(PoolRewardManager.reified(), field.depositsPoolRewardManager),
240
+ borrowsPoolRewardManager: decodeFromJSONField(PoolRewardManager.reified(), field.borrowsPoolRewardManager),
241
+ });
242
+ }
243
+ static fromJSON(typeArg, json) {
244
+ if (json.$typeName !== Reserve.$typeName) {
245
+ throw new Error(`not a Reserve json object: expected '${Reserve.$typeName}' but got '${json.$typeName}'`);
246
+ }
247
+ assertReifiedTypeArgsMatch(composeSuiType(Reserve.$typeName, ...[extractType(typeArg)]), json.$typeArgs, [typeArg]);
248
+ return Reserve.fromJSONField(typeArg, json);
249
+ }
250
+ static fromCoreObject(typeArg, obj) {
251
+ if (!isReserve(obj.type)) {
252
+ throw new Error(`object at ${obj.objectId} is not a Reserve object`);
253
+ }
254
+ const gotTypeArgs = parseTypeName(obj.type).typeArgs;
255
+ if (gotTypeArgs.length !== 1) {
256
+ throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
257
+ }
258
+ for (let i = 0; i < 1; i++) {
259
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
260
+ const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
261
+ if (gotTypeArg !== expectedTypeArg) {
262
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
263
+ }
264
+ }
265
+ return Reserve.fromBcs(typeArg, obj.content);
266
+ }
267
+ static async fetch(client, typeArg, id) {
268
+ const { object } = await client.core.getObject({
269
+ objectId: id,
270
+ include: { content: true },
271
+ });
272
+ if (!isReserve(object.type)) {
273
+ throw new Error(`object at id ${id} is not a Reserve object`);
274
+ }
275
+ const gotTypeArgs = parseTypeName(object.type).typeArgs;
276
+ if (gotTypeArgs.length !== 1) {
277
+ throw new Error(`type argument mismatch: expected 1 type arguments but got '${gotTypeArgs.length}'`);
278
+ }
279
+ for (let i = 0; i < 1; i++) {
280
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
281
+ const expectedTypeArg = compressSuiType(extractType([typeArg][i]));
282
+ if (gotTypeArg !== expectedTypeArg) {
283
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
284
+ }
285
+ }
286
+ return Reserve.fromBcs(typeArg, object.content);
287
+ }
288
+ }
289
+ /* ============================== CToken =============================== */
290
+ export function isCToken(type) {
291
+ type = compressSuiType(type);
292
+ return type.startsWith(`${getTypeOrigin('suilend', 'reserve::CToken')}::reserve::CToken` + '<');
293
+ }
294
+ /**
295
+ * Interest bearing token on the underlying Coin<T>. The ctoken can be redeemed for
296
+ * the underlying token + any interest earned.
297
+ */
298
+ export class CToken {
299
+ __StructClass = true;
300
+ static get $typeName() {
301
+ return `${getTypeOrigin('suilend', 'reserve::CToken')}::reserve::CToken`;
302
+ }
303
+ static $numTypeParams = 2;
304
+ static $isPhantom = [true, true];
305
+ $typeName = CToken.$typeName;
306
+ $fullTypeName;
307
+ $typeArgs;
308
+ $isPhantom = CToken.$isPhantom;
309
+ dummyField;
310
+ constructor(typeArgs, fields) {
311
+ this.$fullTypeName = composeSuiType(CToken.$typeName, ...typeArgs);
312
+ this.$typeArgs = typeArgs;
313
+ this.dummyField = fields.dummyField;
314
+ }
315
+ static reified(P, T) {
316
+ const reifiedBcs = CToken.bcs;
317
+ return {
318
+ get typeName() {
319
+ return CToken.$typeName;
320
+ },
321
+ get fullTypeName() {
322
+ return composeSuiType(CToken.$typeName, ...[extractType(P), extractType(T)]);
323
+ },
324
+ get typeArgs() {
325
+ return [extractType(P), extractType(T)];
326
+ },
327
+ isPhantom: CToken.$isPhantom,
328
+ reifiedTypeArgs: [P, T],
329
+ fromFields: (fields) => CToken.fromFields([P, T], fields),
330
+ fromFieldsWithTypes: (item) => CToken.fromFieldsWithTypes([P, T], item),
331
+ fromBcs: (data) => CToken.fromFields([P, T], reifiedBcs.parse(data)),
332
+ bcs: reifiedBcs,
333
+ fromJSONField: (field) => CToken.fromJSONField([P, T], field),
334
+ fromJSON: (json) => CToken.fromJSON([P, T], json),
335
+ fromCoreObject: (obj) => CToken.fromCoreObject([P, T], obj),
336
+ fetch: async (client, id) => CToken.fetch(client, [P, T], id),
337
+ new: (fields) => {
338
+ return new CToken([extractType(P), extractType(T)], fields);
339
+ },
340
+ kind: 'StructClassReified',
341
+ };
342
+ }
343
+ static get r() {
344
+ return CToken.reified;
345
+ }
346
+ static phantom(P, T) {
347
+ return phantom(CToken.reified(P, T));
348
+ }
349
+ static get p() {
350
+ return CToken.phantom;
351
+ }
352
+ static instantiateBcs() {
353
+ return bcs.struct('CToken', {
354
+ dummy_field: bcs.bool(),
355
+ });
356
+ }
357
+ static cachedBcs = null;
358
+ static get bcs() {
359
+ if (!CToken.cachedBcs) {
360
+ CToken.cachedBcs = CToken.instantiateBcs();
361
+ }
362
+ return CToken.cachedBcs;
363
+ }
364
+ static fromFields(typeArgs, fields) {
365
+ return CToken.reified(typeArgs[0], typeArgs[1]).new({
366
+ dummyField: decodeFromFields('bool', fields.dummy_field),
367
+ });
368
+ }
369
+ static fromFieldsWithTypes(typeArgs, item) {
370
+ if (!isCToken(item.type)) {
371
+ throw new Error('not a CToken type');
372
+ }
373
+ assertFieldsWithTypesArgsMatch(item, typeArgs);
374
+ return CToken.reified(typeArgs[0], typeArgs[1]).new({
375
+ dummyField: decodeFromFieldsWithTypes('bool', item.fields.dummy_field),
376
+ });
377
+ }
378
+ static fromBcs(typeArgs, data) {
379
+ return CToken.fromFields(typeArgs, CToken.bcs.parse(data));
380
+ }
381
+ toJSONField() {
382
+ return {
383
+ dummyField: this.dummyField,
384
+ };
385
+ }
386
+ toJSON() {
387
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
388
+ }
389
+ static fromJSONField(typeArgs, field) {
390
+ return CToken.reified(typeArgs[0], typeArgs[1]).new({
391
+ dummyField: decodeFromJSONField('bool', field.dummyField),
392
+ });
393
+ }
394
+ static fromJSON(typeArgs, json) {
395
+ if (json.$typeName !== CToken.$typeName) {
396
+ throw new Error(`not a CToken json object: expected '${CToken.$typeName}' but got '${json.$typeName}'`);
397
+ }
398
+ assertReifiedTypeArgsMatch(composeSuiType(CToken.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
399
+ return CToken.fromJSONField(typeArgs, json);
400
+ }
401
+ static fromCoreObject(typeArgs, obj) {
402
+ if (!isCToken(obj.type)) {
403
+ throw new Error(`object at ${obj.objectId} is not a CToken object`);
404
+ }
405
+ const gotTypeArgs = parseTypeName(obj.type).typeArgs;
406
+ if (gotTypeArgs.length !== 2) {
407
+ throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
408
+ }
409
+ for (let i = 0; i < 2; i++) {
410
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
411
+ const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
412
+ if (gotTypeArg !== expectedTypeArg) {
413
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
414
+ }
415
+ }
416
+ return CToken.fromBcs(typeArgs, obj.content);
417
+ }
418
+ static async fetch(client, typeArgs, id) {
419
+ const { object } = await client.core.getObject({
420
+ objectId: id,
421
+ include: { content: true },
422
+ });
423
+ if (!isCToken(object.type)) {
424
+ throw new Error(`object at id ${id} is not a CToken object`);
425
+ }
426
+ const gotTypeArgs = parseTypeName(object.type).typeArgs;
427
+ if (gotTypeArgs.length !== 2) {
428
+ throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
429
+ }
430
+ for (let i = 0; i < 2; i++) {
431
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
432
+ const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
433
+ if (gotTypeArg !== expectedTypeArg) {
434
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
435
+ }
436
+ }
437
+ return CToken.fromBcs(typeArgs, object.content);
438
+ }
439
+ }
440
+ /* ============================== LiquidityRequest =============================== */
441
+ export function isLiquidityRequest(type) {
442
+ type = compressSuiType(type);
443
+ return type.startsWith(`${getTypeOrigin('suilend', 'reserve::LiquidityRequest')}::reserve::LiquidityRequest` + '<');
444
+ }
445
+ /** A request to withdraw liquidity from the reserve. This is a hot potato object. */
446
+ export class LiquidityRequest {
447
+ __StructClass = true;
448
+ static get $typeName() {
449
+ return `${getTypeOrigin('suilend', 'reserve::LiquidityRequest')}::reserve::LiquidityRequest`;
450
+ }
451
+ static $numTypeParams = 2;
452
+ static $isPhantom = [true, true];
453
+ $typeName = LiquidityRequest.$typeName;
454
+ $fullTypeName;
455
+ $typeArgs;
456
+ $isPhantom = LiquidityRequest.$isPhantom;
457
+ amount;
458
+ fee;
459
+ constructor(typeArgs, fields) {
460
+ this.$fullTypeName = composeSuiType(LiquidityRequest.$typeName, ...typeArgs);
461
+ this.$typeArgs = typeArgs;
462
+ this.amount = fields.amount;
463
+ this.fee = fields.fee;
464
+ }
465
+ static reified(P, T) {
466
+ const reifiedBcs = LiquidityRequest.bcs;
467
+ return {
468
+ get typeName() {
469
+ return LiquidityRequest.$typeName;
470
+ },
471
+ get fullTypeName() {
472
+ return composeSuiType(LiquidityRequest.$typeName, ...[extractType(P), extractType(T)]);
473
+ },
474
+ get typeArgs() {
475
+ return [extractType(P), extractType(T)];
476
+ },
477
+ isPhantom: LiquidityRequest.$isPhantom,
478
+ reifiedTypeArgs: [P, T],
479
+ fromFields: (fields) => LiquidityRequest.fromFields([P, T], fields),
480
+ fromFieldsWithTypes: (item) => LiquidityRequest.fromFieldsWithTypes([P, T], item),
481
+ fromBcs: (data) => LiquidityRequest.fromFields([P, T], reifiedBcs.parse(data)),
482
+ bcs: reifiedBcs,
483
+ fromJSONField: (field) => LiquidityRequest.fromJSONField([P, T], field),
484
+ fromJSON: (json) => LiquidityRequest.fromJSON([P, T], json),
485
+ fromCoreObject: (obj) => LiquidityRequest.fromCoreObject([P, T], obj),
486
+ fetch: async (client, id) => LiquidityRequest.fetch(client, [P, T], id),
487
+ new: (fields) => {
488
+ return new LiquidityRequest([extractType(P), extractType(T)], fields);
489
+ },
490
+ kind: 'StructClassReified',
491
+ };
492
+ }
493
+ static get r() {
494
+ return LiquidityRequest.reified;
495
+ }
496
+ static phantom(P, T) {
497
+ return phantom(LiquidityRequest.reified(P, T));
498
+ }
499
+ static get p() {
500
+ return LiquidityRequest.phantom;
501
+ }
502
+ static instantiateBcs() {
503
+ return bcs.struct('LiquidityRequest', {
504
+ amount: bcs.u64(),
505
+ fee: bcs.u64(),
506
+ });
507
+ }
508
+ static cachedBcs = null;
509
+ static get bcs() {
510
+ if (!LiquidityRequest.cachedBcs) {
511
+ LiquidityRequest.cachedBcs = LiquidityRequest.instantiateBcs();
512
+ }
513
+ return LiquidityRequest.cachedBcs;
514
+ }
515
+ static fromFields(typeArgs, fields) {
516
+ return LiquidityRequest.reified(typeArgs[0], typeArgs[1]).new({
517
+ amount: decodeFromFields('u64', fields.amount),
518
+ fee: decodeFromFields('u64', fields.fee),
519
+ });
520
+ }
521
+ static fromFieldsWithTypes(typeArgs, item) {
522
+ if (!isLiquidityRequest(item.type)) {
523
+ throw new Error('not a LiquidityRequest type');
524
+ }
525
+ assertFieldsWithTypesArgsMatch(item, typeArgs);
526
+ return LiquidityRequest.reified(typeArgs[0], typeArgs[1]).new({
527
+ amount: decodeFromFieldsWithTypes('u64', item.fields.amount),
528
+ fee: decodeFromFieldsWithTypes('u64', item.fields.fee),
529
+ });
530
+ }
531
+ static fromBcs(typeArgs, data) {
532
+ return LiquidityRequest.fromFields(typeArgs, LiquidityRequest.bcs.parse(data));
533
+ }
534
+ toJSONField() {
535
+ return {
536
+ amount: this.amount.toString(),
537
+ fee: this.fee.toString(),
538
+ };
539
+ }
540
+ toJSON() {
541
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
542
+ }
543
+ static fromJSONField(typeArgs, field) {
544
+ return LiquidityRequest.reified(typeArgs[0], typeArgs[1]).new({
545
+ amount: decodeFromJSONField('u64', field.amount),
546
+ fee: decodeFromJSONField('u64', field.fee),
547
+ });
548
+ }
549
+ static fromJSON(typeArgs, json) {
550
+ if (json.$typeName !== LiquidityRequest.$typeName) {
551
+ throw new Error(`not a LiquidityRequest json object: expected '${LiquidityRequest.$typeName}' but got '${json.$typeName}'`);
552
+ }
553
+ assertReifiedTypeArgsMatch(composeSuiType(LiquidityRequest.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
554
+ return LiquidityRequest.fromJSONField(typeArgs, json);
555
+ }
556
+ static fromCoreObject(typeArgs, obj) {
557
+ if (!isLiquidityRequest(obj.type)) {
558
+ throw new Error(`object at ${obj.objectId} is not a LiquidityRequest object`);
559
+ }
560
+ const gotTypeArgs = parseTypeName(obj.type).typeArgs;
561
+ if (gotTypeArgs.length !== 2) {
562
+ throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
563
+ }
564
+ for (let i = 0; i < 2; i++) {
565
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
566
+ const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
567
+ if (gotTypeArg !== expectedTypeArg) {
568
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
569
+ }
570
+ }
571
+ return LiquidityRequest.fromBcs(typeArgs, obj.content);
572
+ }
573
+ static async fetch(client, typeArgs, id) {
574
+ const { object } = await client.core.getObject({
575
+ objectId: id,
576
+ include: { content: true },
577
+ });
578
+ if (!isLiquidityRequest(object.type)) {
579
+ throw new Error(`object at id ${id} is not a LiquidityRequest object`);
580
+ }
581
+ const gotTypeArgs = parseTypeName(object.type).typeArgs;
582
+ if (gotTypeArgs.length !== 2) {
583
+ throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
584
+ }
585
+ for (let i = 0; i < 2; i++) {
586
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
587
+ const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
588
+ if (gotTypeArg !== expectedTypeArg) {
589
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
590
+ }
591
+ }
592
+ return LiquidityRequest.fromBcs(typeArgs, object.content);
593
+ }
594
+ }
15
595
  /* ============================== BalanceKey =============================== */
16
596
  export function isBalanceKey(type) {
17
597
  type = compressSuiType(type);
18
- return type === `${PKG_V1}::reserve::BalanceKey`;
598
+ return type === `${getTypeOrigin('suilend', 'reserve::BalanceKey')}::reserve::BalanceKey`;
599
+ }
600
+ export class BalanceKey {
601
+ __StructClass = true;
602
+ static get $typeName() {
603
+ return `${getTypeOrigin('suilend', 'reserve::BalanceKey')}::reserve::BalanceKey`;
604
+ }
605
+ static $numTypeParams = 0;
606
+ static $isPhantom = [];
607
+ $typeName = BalanceKey.$typeName;
608
+ $fullTypeName;
609
+ $typeArgs;
610
+ $isPhantom = BalanceKey.$isPhantom;
611
+ dummyField;
612
+ constructor(typeArgs, fields) {
613
+ this.$fullTypeName = composeSuiType(BalanceKey.$typeName, ...typeArgs);
614
+ this.$typeArgs = typeArgs;
615
+ this.dummyField = fields.dummyField;
616
+ }
617
+ static reified() {
618
+ const reifiedBcs = BalanceKey.bcs;
619
+ return {
620
+ get typeName() {
621
+ return BalanceKey.$typeName;
622
+ },
623
+ get fullTypeName() {
624
+ return composeSuiType(BalanceKey.$typeName, ...[]);
625
+ },
626
+ typeArgs: [],
627
+ isPhantom: BalanceKey.$isPhantom,
628
+ reifiedTypeArgs: [],
629
+ fromFields: (fields) => BalanceKey.fromFields(fields),
630
+ fromFieldsWithTypes: (item) => BalanceKey.fromFieldsWithTypes(item),
631
+ fromBcs: (data) => BalanceKey.fromFields(reifiedBcs.parse(data)),
632
+ bcs: reifiedBcs,
633
+ fromJSONField: (field) => BalanceKey.fromJSONField(field),
634
+ fromJSON: (json) => BalanceKey.fromJSON(json),
635
+ fromCoreObject: (obj) => BalanceKey.fromCoreObject(obj),
636
+ fetch: async (client, id) => BalanceKey.fetch(client, id),
637
+ new: (fields) => {
638
+ return new BalanceKey([], fields);
639
+ },
640
+ kind: 'StructClassReified',
641
+ };
642
+ }
643
+ static get r() {
644
+ return BalanceKey.reified();
645
+ }
646
+ static phantom() {
647
+ return phantom(BalanceKey.reified());
648
+ }
649
+ static get p() {
650
+ return BalanceKey.phantom();
651
+ }
652
+ static instantiateBcs() {
653
+ return bcs.struct('BalanceKey', {
654
+ dummy_field: bcs.bool(),
655
+ });
656
+ }
657
+ static cachedBcs = null;
658
+ static get bcs() {
659
+ if (!BalanceKey.cachedBcs) {
660
+ BalanceKey.cachedBcs = BalanceKey.instantiateBcs();
661
+ }
662
+ return BalanceKey.cachedBcs;
663
+ }
664
+ static fromFields(fields) {
665
+ return BalanceKey.reified().new({
666
+ dummyField: decodeFromFields('bool', fields.dummy_field),
667
+ });
668
+ }
669
+ static fromFieldsWithTypes(item) {
670
+ if (!isBalanceKey(item.type)) {
671
+ throw new Error('not a BalanceKey type');
672
+ }
673
+ return BalanceKey.reified().new({
674
+ dummyField: decodeFromFieldsWithTypes('bool', item.fields.dummy_field),
675
+ });
676
+ }
677
+ static fromBcs(data) {
678
+ return BalanceKey.fromFields(BalanceKey.bcs.parse(data));
679
+ }
680
+ toJSONField() {
681
+ return {
682
+ dummyField: this.dummyField,
683
+ };
684
+ }
685
+ toJSON() {
686
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
687
+ }
688
+ static fromJSONField(field) {
689
+ return BalanceKey.reified().new({
690
+ dummyField: decodeFromJSONField('bool', field.dummyField),
691
+ });
692
+ }
693
+ static fromJSON(json) {
694
+ if (json.$typeName !== BalanceKey.$typeName) {
695
+ throw new Error(`not a BalanceKey json object: expected '${BalanceKey.$typeName}' but got '${json.$typeName}'`);
696
+ }
697
+ return BalanceKey.fromJSONField(json);
698
+ }
699
+ static fromCoreObject(obj) {
700
+ if (!isBalanceKey(obj.type)) {
701
+ throw new Error(`object at ${obj.objectId} is not a BalanceKey object`);
702
+ }
703
+ return BalanceKey.fromBcs(obj.content);
704
+ }
705
+ static async fetch(client, id) {
706
+ const { object } = await client.core.getObject({
707
+ objectId: id,
708
+ include: { content: true },
709
+ });
710
+ if (!isBalanceKey(object.type)) {
711
+ throw new Error(`object at id ${id} is not a BalanceKey object`);
712
+ }
713
+ return BalanceKey.fromBcs(object.content);
714
+ }
715
+ }
716
+ /* ============================== StakerKey =============================== */
717
+ export function isStakerKey(type) {
718
+ type = compressSuiType(type);
719
+ return type === `${getTypeOrigin('suilend', 'reserve::StakerKey')}::reserve::StakerKey`;
720
+ }
721
+ export class StakerKey {
722
+ __StructClass = true;
723
+ static get $typeName() {
724
+ return `${getTypeOrigin('suilend', 'reserve::StakerKey')}::reserve::StakerKey`;
725
+ }
726
+ static $numTypeParams = 0;
727
+ static $isPhantom = [];
728
+ $typeName = StakerKey.$typeName;
729
+ $fullTypeName;
730
+ $typeArgs;
731
+ $isPhantom = StakerKey.$isPhantom;
732
+ dummyField;
733
+ constructor(typeArgs, fields) {
734
+ this.$fullTypeName = composeSuiType(StakerKey.$typeName, ...typeArgs);
735
+ this.$typeArgs = typeArgs;
736
+ this.dummyField = fields.dummyField;
737
+ }
738
+ static reified() {
739
+ const reifiedBcs = StakerKey.bcs;
740
+ return {
741
+ get typeName() {
742
+ return StakerKey.$typeName;
743
+ },
744
+ get fullTypeName() {
745
+ return composeSuiType(StakerKey.$typeName, ...[]);
746
+ },
747
+ typeArgs: [],
748
+ isPhantom: StakerKey.$isPhantom,
749
+ reifiedTypeArgs: [],
750
+ fromFields: (fields) => StakerKey.fromFields(fields),
751
+ fromFieldsWithTypes: (item) => StakerKey.fromFieldsWithTypes(item),
752
+ fromBcs: (data) => StakerKey.fromFields(reifiedBcs.parse(data)),
753
+ bcs: reifiedBcs,
754
+ fromJSONField: (field) => StakerKey.fromJSONField(field),
755
+ fromJSON: (json) => StakerKey.fromJSON(json),
756
+ fromCoreObject: (obj) => StakerKey.fromCoreObject(obj),
757
+ fetch: async (client, id) => StakerKey.fetch(client, id),
758
+ new: (fields) => {
759
+ return new StakerKey([], fields);
760
+ },
761
+ kind: 'StructClassReified',
762
+ };
763
+ }
764
+ static get r() {
765
+ return StakerKey.reified();
766
+ }
767
+ static phantom() {
768
+ return phantom(StakerKey.reified());
769
+ }
770
+ static get p() {
771
+ return StakerKey.phantom();
772
+ }
773
+ static instantiateBcs() {
774
+ return bcs.struct('StakerKey', {
775
+ dummy_field: bcs.bool(),
776
+ });
777
+ }
778
+ static cachedBcs = null;
779
+ static get bcs() {
780
+ if (!StakerKey.cachedBcs) {
781
+ StakerKey.cachedBcs = StakerKey.instantiateBcs();
782
+ }
783
+ return StakerKey.cachedBcs;
784
+ }
785
+ static fromFields(fields) {
786
+ return StakerKey.reified().new({
787
+ dummyField: decodeFromFields('bool', fields.dummy_field),
788
+ });
789
+ }
790
+ static fromFieldsWithTypes(item) {
791
+ if (!isStakerKey(item.type)) {
792
+ throw new Error('not a StakerKey type');
793
+ }
794
+ return StakerKey.reified().new({
795
+ dummyField: decodeFromFieldsWithTypes('bool', item.fields.dummy_field),
796
+ });
797
+ }
798
+ static fromBcs(data) {
799
+ return StakerKey.fromFields(StakerKey.bcs.parse(data));
800
+ }
801
+ toJSONField() {
802
+ return {
803
+ dummyField: this.dummyField,
804
+ };
805
+ }
806
+ toJSON() {
807
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
808
+ }
809
+ static fromJSONField(field) {
810
+ return StakerKey.reified().new({
811
+ dummyField: decodeFromJSONField('bool', field.dummyField),
812
+ });
813
+ }
814
+ static fromJSON(json) {
815
+ if (json.$typeName !== StakerKey.$typeName) {
816
+ throw new Error(`not a StakerKey json object: expected '${StakerKey.$typeName}' but got '${json.$typeName}'`);
817
+ }
818
+ return StakerKey.fromJSONField(json);
819
+ }
820
+ static fromCoreObject(obj) {
821
+ if (!isStakerKey(obj.type)) {
822
+ throw new Error(`object at ${obj.objectId} is not a StakerKey object`);
823
+ }
824
+ return StakerKey.fromBcs(obj.content);
825
+ }
826
+ static async fetch(client, id) {
827
+ const { object } = await client.core.getObject({
828
+ objectId: id,
829
+ include: { content: true },
830
+ });
831
+ if (!isStakerKey(object.type)) {
832
+ throw new Error(`object at id ${id} is not a StakerKey object`);
833
+ }
834
+ return StakerKey.fromBcs(object.content);
835
+ }
836
+ }
837
+ /* ============================== ReservePauseKey =============================== */
838
+ export function isReservePauseKey(type) {
839
+ type = compressSuiType(type);
840
+ return type
841
+ === `${getTypeOrigin('suilend', 'reserve::ReservePauseKey')}::reserve::ReservePauseKey`;
842
+ }
843
+ export class ReservePauseKey {
844
+ __StructClass = true;
845
+ static get $typeName() {
846
+ return `${getTypeOrigin('suilend', 'reserve::ReservePauseKey')}::reserve::ReservePauseKey`;
847
+ }
848
+ static $numTypeParams = 0;
849
+ static $isPhantom = [];
850
+ $typeName = ReservePauseKey.$typeName;
851
+ $fullTypeName;
852
+ $typeArgs;
853
+ $isPhantom = ReservePauseKey.$isPhantom;
854
+ dummyField;
855
+ constructor(typeArgs, fields) {
856
+ this.$fullTypeName = composeSuiType(ReservePauseKey.$typeName, ...typeArgs);
857
+ this.$typeArgs = typeArgs;
858
+ this.dummyField = fields.dummyField;
859
+ }
860
+ static reified() {
861
+ const reifiedBcs = ReservePauseKey.bcs;
862
+ return {
863
+ get typeName() {
864
+ return ReservePauseKey.$typeName;
865
+ },
866
+ get fullTypeName() {
867
+ return composeSuiType(ReservePauseKey.$typeName, ...[]);
868
+ },
869
+ typeArgs: [],
870
+ isPhantom: ReservePauseKey.$isPhantom,
871
+ reifiedTypeArgs: [],
872
+ fromFields: (fields) => ReservePauseKey.fromFields(fields),
873
+ fromFieldsWithTypes: (item) => ReservePauseKey.fromFieldsWithTypes(item),
874
+ fromBcs: (data) => ReservePauseKey.fromFields(reifiedBcs.parse(data)),
875
+ bcs: reifiedBcs,
876
+ fromJSONField: (field) => ReservePauseKey.fromJSONField(field),
877
+ fromJSON: (json) => ReservePauseKey.fromJSON(json),
878
+ fromCoreObject: (obj) => ReservePauseKey.fromCoreObject(obj),
879
+ fetch: async (client, id) => ReservePauseKey.fetch(client, id),
880
+ new: (fields) => {
881
+ return new ReservePauseKey([], fields);
882
+ },
883
+ kind: 'StructClassReified',
884
+ };
885
+ }
886
+ static get r() {
887
+ return ReservePauseKey.reified();
888
+ }
889
+ static phantom() {
890
+ return phantom(ReservePauseKey.reified());
891
+ }
892
+ static get p() {
893
+ return ReservePauseKey.phantom();
894
+ }
895
+ static instantiateBcs() {
896
+ return bcs.struct('ReservePauseKey', {
897
+ dummy_field: bcs.bool(),
898
+ });
899
+ }
900
+ static cachedBcs = null;
901
+ static get bcs() {
902
+ if (!ReservePauseKey.cachedBcs) {
903
+ ReservePauseKey.cachedBcs = ReservePauseKey.instantiateBcs();
904
+ }
905
+ return ReservePauseKey.cachedBcs;
906
+ }
907
+ static fromFields(fields) {
908
+ return ReservePauseKey.reified().new({
909
+ dummyField: decodeFromFields('bool', fields.dummy_field),
910
+ });
911
+ }
912
+ static fromFieldsWithTypes(item) {
913
+ if (!isReservePauseKey(item.type)) {
914
+ throw new Error('not a ReservePauseKey type');
915
+ }
916
+ return ReservePauseKey.reified().new({
917
+ dummyField: decodeFromFieldsWithTypes('bool', item.fields.dummy_field),
918
+ });
919
+ }
920
+ static fromBcs(data) {
921
+ return ReservePauseKey.fromFields(ReservePauseKey.bcs.parse(data));
922
+ }
923
+ toJSONField() {
924
+ return {
925
+ dummyField: this.dummyField,
926
+ };
927
+ }
928
+ toJSON() {
929
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
930
+ }
931
+ static fromJSONField(field) {
932
+ return ReservePauseKey.reified().new({
933
+ dummyField: decodeFromJSONField('bool', field.dummyField),
934
+ });
935
+ }
936
+ static fromJSON(json) {
937
+ if (json.$typeName !== ReservePauseKey.$typeName) {
938
+ throw new Error(`not a ReservePauseKey json object: expected '${ReservePauseKey.$typeName}' but got '${json.$typeName}'`);
939
+ }
940
+ return ReservePauseKey.fromJSONField(json);
941
+ }
942
+ static fromCoreObject(obj) {
943
+ if (!isReservePauseKey(obj.type)) {
944
+ throw new Error(`object at ${obj.objectId} is not a ReservePauseKey object`);
945
+ }
946
+ return ReservePauseKey.fromBcs(obj.content);
947
+ }
948
+ static async fetch(client, id) {
949
+ const { object } = await client.core.getObject({
950
+ objectId: id,
951
+ include: { content: true },
952
+ });
953
+ if (!isReservePauseKey(object.type)) {
954
+ throw new Error(`object at id ${id} is not a ReservePauseKey object`);
955
+ }
956
+ return ReservePauseKey.fromBcs(object.content);
957
+ }
958
+ }
959
+ /* ============================== PriceGuardKey =============================== */
960
+ export function isPriceGuardKey(type) {
961
+ type = compressSuiType(type);
962
+ return type === `${getTypeOrigin('suilend', 'reserve::PriceGuardKey')}::reserve::PriceGuardKey`;
963
+ }
964
+ export class PriceGuardKey {
965
+ __StructClass = true;
966
+ static get $typeName() {
967
+ return `${getTypeOrigin('suilend', 'reserve::PriceGuardKey')}::reserve::PriceGuardKey`;
968
+ }
969
+ static $numTypeParams = 0;
970
+ static $isPhantom = [];
971
+ $typeName = PriceGuardKey.$typeName;
972
+ $fullTypeName;
973
+ $typeArgs;
974
+ $isPhantom = PriceGuardKey.$isPhantom;
975
+ dummyField;
976
+ constructor(typeArgs, fields) {
977
+ this.$fullTypeName = composeSuiType(PriceGuardKey.$typeName, ...typeArgs);
978
+ this.$typeArgs = typeArgs;
979
+ this.dummyField = fields.dummyField;
980
+ }
981
+ static reified() {
982
+ const reifiedBcs = PriceGuardKey.bcs;
983
+ return {
984
+ get typeName() {
985
+ return PriceGuardKey.$typeName;
986
+ },
987
+ get fullTypeName() {
988
+ return composeSuiType(PriceGuardKey.$typeName, ...[]);
989
+ },
990
+ typeArgs: [],
991
+ isPhantom: PriceGuardKey.$isPhantom,
992
+ reifiedTypeArgs: [],
993
+ fromFields: (fields) => PriceGuardKey.fromFields(fields),
994
+ fromFieldsWithTypes: (item) => PriceGuardKey.fromFieldsWithTypes(item),
995
+ fromBcs: (data) => PriceGuardKey.fromFields(reifiedBcs.parse(data)),
996
+ bcs: reifiedBcs,
997
+ fromJSONField: (field) => PriceGuardKey.fromJSONField(field),
998
+ fromJSON: (json) => PriceGuardKey.fromJSON(json),
999
+ fromCoreObject: (obj) => PriceGuardKey.fromCoreObject(obj),
1000
+ fetch: async (client, id) => PriceGuardKey.fetch(client, id),
1001
+ new: (fields) => {
1002
+ return new PriceGuardKey([], fields);
1003
+ },
1004
+ kind: 'StructClassReified',
1005
+ };
1006
+ }
1007
+ static get r() {
1008
+ return PriceGuardKey.reified();
1009
+ }
1010
+ static phantom() {
1011
+ return phantom(PriceGuardKey.reified());
1012
+ }
1013
+ static get p() {
1014
+ return PriceGuardKey.phantom();
1015
+ }
1016
+ static instantiateBcs() {
1017
+ return bcs.struct('PriceGuardKey', {
1018
+ dummy_field: bcs.bool(),
1019
+ });
1020
+ }
1021
+ static cachedBcs = null;
1022
+ static get bcs() {
1023
+ if (!PriceGuardKey.cachedBcs) {
1024
+ PriceGuardKey.cachedBcs = PriceGuardKey.instantiateBcs();
1025
+ }
1026
+ return PriceGuardKey.cachedBcs;
1027
+ }
1028
+ static fromFields(fields) {
1029
+ return PriceGuardKey.reified().new({
1030
+ dummyField: decodeFromFields('bool', fields.dummy_field),
1031
+ });
1032
+ }
1033
+ static fromFieldsWithTypes(item) {
1034
+ if (!isPriceGuardKey(item.type)) {
1035
+ throw new Error('not a PriceGuardKey type');
1036
+ }
1037
+ return PriceGuardKey.reified().new({
1038
+ dummyField: decodeFromFieldsWithTypes('bool', item.fields.dummy_field),
1039
+ });
1040
+ }
1041
+ static fromBcs(data) {
1042
+ return PriceGuardKey.fromFields(PriceGuardKey.bcs.parse(data));
1043
+ }
1044
+ toJSONField() {
1045
+ return {
1046
+ dummyField: this.dummyField,
1047
+ };
1048
+ }
1049
+ toJSON() {
1050
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
1051
+ }
1052
+ static fromJSONField(field) {
1053
+ return PriceGuardKey.reified().new({
1054
+ dummyField: decodeFromJSONField('bool', field.dummyField),
1055
+ });
1056
+ }
1057
+ static fromJSON(json) {
1058
+ if (json.$typeName !== PriceGuardKey.$typeName) {
1059
+ throw new Error(`not a PriceGuardKey json object: expected '${PriceGuardKey.$typeName}' but got '${json.$typeName}'`);
1060
+ }
1061
+ return PriceGuardKey.fromJSONField(json);
1062
+ }
1063
+ static fromCoreObject(obj) {
1064
+ if (!isPriceGuardKey(obj.type)) {
1065
+ throw new Error(`object at ${obj.objectId} is not a PriceGuardKey object`);
1066
+ }
1067
+ return PriceGuardKey.fromBcs(obj.content);
1068
+ }
1069
+ static async fetch(client, id) {
1070
+ const { object } = await client.core.getObject({
1071
+ objectId: id,
1072
+ include: { content: true },
1073
+ });
1074
+ if (!isPriceGuardKey(object.type)) {
1075
+ throw new Error(`object at id ${id} is not a PriceGuardKey object`);
1076
+ }
1077
+ return PriceGuardKey.fromBcs(object.content);
1078
+ }
1079
+ }
1080
+ /* ============================== ConfidenceKey =============================== */
1081
+ export function isConfidenceKey(type) {
1082
+ type = compressSuiType(type);
1083
+ return type === `${getTypeOrigin('suilend', 'reserve::ConfidenceKey')}::reserve::ConfidenceKey`;
1084
+ }
1085
+ export class ConfidenceKey {
1086
+ __StructClass = true;
1087
+ static get $typeName() {
1088
+ return `${getTypeOrigin('suilend', 'reserve::ConfidenceKey')}::reserve::ConfidenceKey`;
1089
+ }
1090
+ static $numTypeParams = 0;
1091
+ static $isPhantom = [];
1092
+ $typeName = ConfidenceKey.$typeName;
1093
+ $fullTypeName;
1094
+ $typeArgs;
1095
+ $isPhantom = ConfidenceKey.$isPhantom;
1096
+ dummyField;
1097
+ constructor(typeArgs, fields) {
1098
+ this.$fullTypeName = composeSuiType(ConfidenceKey.$typeName, ...typeArgs);
1099
+ this.$typeArgs = typeArgs;
1100
+ this.dummyField = fields.dummyField;
1101
+ }
1102
+ static reified() {
1103
+ const reifiedBcs = ConfidenceKey.bcs;
1104
+ return {
1105
+ get typeName() {
1106
+ return ConfidenceKey.$typeName;
1107
+ },
1108
+ get fullTypeName() {
1109
+ return composeSuiType(ConfidenceKey.$typeName, ...[]);
1110
+ },
1111
+ typeArgs: [],
1112
+ isPhantom: ConfidenceKey.$isPhantom,
1113
+ reifiedTypeArgs: [],
1114
+ fromFields: (fields) => ConfidenceKey.fromFields(fields),
1115
+ fromFieldsWithTypes: (item) => ConfidenceKey.fromFieldsWithTypes(item),
1116
+ fromBcs: (data) => ConfidenceKey.fromFields(reifiedBcs.parse(data)),
1117
+ bcs: reifiedBcs,
1118
+ fromJSONField: (field) => ConfidenceKey.fromJSONField(field),
1119
+ fromJSON: (json) => ConfidenceKey.fromJSON(json),
1120
+ fromCoreObject: (obj) => ConfidenceKey.fromCoreObject(obj),
1121
+ fetch: async (client, id) => ConfidenceKey.fetch(client, id),
1122
+ new: (fields) => {
1123
+ return new ConfidenceKey([], fields);
1124
+ },
1125
+ kind: 'StructClassReified',
1126
+ };
1127
+ }
1128
+ static get r() {
1129
+ return ConfidenceKey.reified();
1130
+ }
1131
+ static phantom() {
1132
+ return phantom(ConfidenceKey.reified());
1133
+ }
1134
+ static get p() {
1135
+ return ConfidenceKey.phantom();
1136
+ }
1137
+ static instantiateBcs() {
1138
+ return bcs.struct('ConfidenceKey', {
1139
+ dummy_field: bcs.bool(),
1140
+ });
1141
+ }
1142
+ static cachedBcs = null;
1143
+ static get bcs() {
1144
+ if (!ConfidenceKey.cachedBcs) {
1145
+ ConfidenceKey.cachedBcs = ConfidenceKey.instantiateBcs();
1146
+ }
1147
+ return ConfidenceKey.cachedBcs;
1148
+ }
1149
+ static fromFields(fields) {
1150
+ return ConfidenceKey.reified().new({
1151
+ dummyField: decodeFromFields('bool', fields.dummy_field),
1152
+ });
1153
+ }
1154
+ static fromFieldsWithTypes(item) {
1155
+ if (!isConfidenceKey(item.type)) {
1156
+ throw new Error('not a ConfidenceKey type');
1157
+ }
1158
+ return ConfidenceKey.reified().new({
1159
+ dummyField: decodeFromFieldsWithTypes('bool', item.fields.dummy_field),
1160
+ });
1161
+ }
1162
+ static fromBcs(data) {
1163
+ return ConfidenceKey.fromFields(ConfidenceKey.bcs.parse(data));
1164
+ }
1165
+ toJSONField() {
1166
+ return {
1167
+ dummyField: this.dummyField,
1168
+ };
1169
+ }
1170
+ toJSON() {
1171
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
1172
+ }
1173
+ static fromJSONField(field) {
1174
+ return ConfidenceKey.reified().new({
1175
+ dummyField: decodeFromJSONField('bool', field.dummyField),
1176
+ });
1177
+ }
1178
+ static fromJSON(json) {
1179
+ if (json.$typeName !== ConfidenceKey.$typeName) {
1180
+ throw new Error(`not a ConfidenceKey json object: expected '${ConfidenceKey.$typeName}' but got '${json.$typeName}'`);
1181
+ }
1182
+ return ConfidenceKey.fromJSONField(json);
1183
+ }
1184
+ static fromCoreObject(obj) {
1185
+ if (!isConfidenceKey(obj.type)) {
1186
+ throw new Error(`object at ${obj.objectId} is not a ConfidenceKey object`);
1187
+ }
1188
+ return ConfidenceKey.fromBcs(obj.content);
1189
+ }
1190
+ static async fetch(client, id) {
1191
+ const { object } = await client.core.getObject({
1192
+ objectId: id,
1193
+ include: { content: true },
1194
+ });
1195
+ if (!isConfidenceKey(object.type)) {
1196
+ throw new Error(`object at id ${id} is not a ConfidenceKey object`);
1197
+ }
1198
+ return ConfidenceKey.fromBcs(object.content);
1199
+ }
1200
+ }
1201
+ /* ============================== PriceGuard =============================== */
1202
+ export function isPriceGuard(type) {
1203
+ type = compressSuiType(type);
1204
+ return type === `${getTypeOrigin('suilend', 'reserve::PriceGuard')}::reserve::PriceGuard`;
19
1205
  }
20
- export class BalanceKey {
1206
+ /**
1207
+ * Bounds how far `price` and `smoothed_price` may move per
1208
+ * `min_update_interval_s`. Each anchor moves at most one band per interval and is
1209
+ * advanced to the clamped value, so repeating a refresh inside one PTB cannot walk
1210
+ * either price further than a single band.
1211
+ */
1212
+ export class PriceGuard {
21
1213
  __StructClass = true;
22
- static $typeName = `${PKG_V1}::reserve::BalanceKey`;
1214
+ static get $typeName() {
1215
+ return `${getTypeOrigin('suilend', 'reserve::PriceGuard')}::reserve::PriceGuard`;
1216
+ }
23
1217
  static $numTypeParams = 0;
24
1218
  static $isPhantom = [];
25
- $typeName = BalanceKey.$typeName;
1219
+ $typeName = PriceGuard.$typeName;
26
1220
  $fullTypeName;
27
1221
  $typeArgs;
28
- $isPhantom = BalanceKey.$isPhantom;
29
- dummyField;
1222
+ $isPhantom = PriceGuard.$isPhantom;
1223
+ maxPriceChangeBps;
1224
+ minUpdateIntervalS;
1225
+ priceAnchor;
1226
+ smoothedPriceAnchor;
1227
+ anchorTimestampS;
30
1228
  constructor(typeArgs, fields) {
31
- this.$fullTypeName = composeSuiType(BalanceKey.$typeName, ...typeArgs);
1229
+ this.$fullTypeName = composeSuiType(PriceGuard.$typeName, ...typeArgs);
32
1230
  this.$typeArgs = typeArgs;
33
- this.dummyField = fields.dummyField;
1231
+ this.maxPriceChangeBps = fields.maxPriceChangeBps;
1232
+ this.minUpdateIntervalS = fields.minUpdateIntervalS;
1233
+ this.priceAnchor = fields.priceAnchor;
1234
+ this.smoothedPriceAnchor = fields.smoothedPriceAnchor;
1235
+ this.anchorTimestampS = fields.anchorTimestampS;
34
1236
  }
35
1237
  static reified() {
1238
+ const reifiedBcs = PriceGuard.bcs;
36
1239
  return {
37
- typeName: BalanceKey.$typeName,
38
- fullTypeName: composeSuiType(BalanceKey.$typeName, ...[]),
1240
+ get typeName() {
1241
+ return PriceGuard.$typeName;
1242
+ },
1243
+ get fullTypeName() {
1244
+ return composeSuiType(PriceGuard.$typeName, ...[]);
1245
+ },
39
1246
  typeArgs: [],
40
- isPhantom: BalanceKey.$isPhantom,
1247
+ isPhantom: PriceGuard.$isPhantom,
41
1248
  reifiedTypeArgs: [],
42
- fromFields: (fields) => BalanceKey.fromFields(fields),
43
- fromFieldsWithTypes: (item) => BalanceKey.fromFieldsWithTypes(item),
44
- fromBcs: (data) => BalanceKey.fromBcs(data),
45
- bcs: BalanceKey.bcs,
46
- fromJSONField: (field) => BalanceKey.fromJSONField(field),
47
- fromJSON: (json) => BalanceKey.fromJSON(json),
48
- fetch: async (client, id) => BalanceKey.fetch(client, id),
1249
+ fromFields: (fields) => PriceGuard.fromFields(fields),
1250
+ fromFieldsWithTypes: (item) => PriceGuard.fromFieldsWithTypes(item),
1251
+ fromBcs: (data) => PriceGuard.fromFields(reifiedBcs.parse(data)),
1252
+ bcs: reifiedBcs,
1253
+ fromJSONField: (field) => PriceGuard.fromJSONField(field),
1254
+ fromJSON: (json) => PriceGuard.fromJSON(json),
1255
+ fromCoreObject: (obj) => PriceGuard.fromCoreObject(obj),
1256
+ fetch: async (client, id) => PriceGuard.fetch(client, id),
49
1257
  new: (fields) => {
50
- return new BalanceKey([], fields);
1258
+ return new PriceGuard([], fields);
51
1259
  },
52
- kind: "StructClassReified",
1260
+ kind: 'StructClassReified',
53
1261
  };
54
1262
  }
55
1263
  static get r() {
56
- return BalanceKey.reified();
1264
+ return PriceGuard.reified();
57
1265
  }
58
1266
  static phantom() {
59
- return phantom(BalanceKey.reified());
1267
+ return phantom(PriceGuard.reified());
60
1268
  }
61
1269
  static get p() {
62
- return BalanceKey.phantom();
1270
+ return PriceGuard.phantom();
1271
+ }
1272
+ static instantiateBcs() {
1273
+ return bcs.struct('PriceGuard', {
1274
+ max_price_change_bps: bcs.u64(),
1275
+ min_update_interval_s: bcs.u64(),
1276
+ price_anchor: Decimal.bcs,
1277
+ smoothed_price_anchor: Decimal.bcs,
1278
+ anchor_timestamp_s: bcs.u64(),
1279
+ });
63
1280
  }
1281
+ static cachedBcs = null;
64
1282
  static get bcs() {
65
- return bcs.struct("BalanceKey", {
66
- dummy_field: bcs.bool(),
67
- });
1283
+ if (!PriceGuard.cachedBcs) {
1284
+ PriceGuard.cachedBcs = PriceGuard.instantiateBcs();
1285
+ }
1286
+ return PriceGuard.cachedBcs;
68
1287
  }
69
1288
  static fromFields(fields) {
70
- return BalanceKey.reified().new({
71
- dummyField: decodeFromFields("bool", fields.dummy_field),
1289
+ return PriceGuard.reified().new({
1290
+ maxPriceChangeBps: decodeFromFields('u64', fields.max_price_change_bps),
1291
+ minUpdateIntervalS: decodeFromFields('u64', fields.min_update_interval_s),
1292
+ priceAnchor: decodeFromFields(Decimal.reified(), fields.price_anchor),
1293
+ smoothedPriceAnchor: decodeFromFields(Decimal.reified(), fields.smoothed_price_anchor),
1294
+ anchorTimestampS: decodeFromFields('u64', fields.anchor_timestamp_s),
72
1295
  });
73
1296
  }
74
1297
  static fromFieldsWithTypes(item) {
75
- if (!isBalanceKey(item.type)) {
76
- throw new Error("not a BalanceKey type");
1298
+ if (!isPriceGuard(item.type)) {
1299
+ throw new Error('not a PriceGuard type');
77
1300
  }
78
- return BalanceKey.reified().new({
79
- dummyField: decodeFromFieldsWithTypes("bool", item.fields.dummy_field),
1301
+ return PriceGuard.reified().new({
1302
+ maxPriceChangeBps: decodeFromFieldsWithTypes('u64', item.fields.max_price_change_bps),
1303
+ minUpdateIntervalS: decodeFromFieldsWithTypes('u64', item.fields.min_update_interval_s),
1304
+ priceAnchor: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.price_anchor),
1305
+ smoothedPriceAnchor: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price_anchor),
1306
+ anchorTimestampS: decodeFromFieldsWithTypes('u64', item.fields.anchor_timestamp_s),
80
1307
  });
81
1308
  }
82
1309
  static fromBcs(data) {
83
- return BalanceKey.fromFields(BalanceKey.bcs.parse(data));
1310
+ return PriceGuard.fromFields(PriceGuard.bcs.parse(data));
84
1311
  }
85
1312
  toJSONField() {
86
1313
  return {
87
- dummyField: this.dummyField,
1314
+ maxPriceChangeBps: this.maxPriceChangeBps.toString(),
1315
+ minUpdateIntervalS: this.minUpdateIntervalS.toString(),
1316
+ priceAnchor: this.priceAnchor.toJSONField(),
1317
+ smoothedPriceAnchor: this.smoothedPriceAnchor.toJSONField(),
1318
+ anchorTimestampS: this.anchorTimestampS.toString(),
88
1319
  };
89
1320
  }
90
1321
  toJSON() {
91
- return {
92
- $typeName: this.$typeName,
93
- $typeArgs: this.$typeArgs,
94
- ...this.toJSONField(),
95
- };
1322
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
96
1323
  }
97
1324
  static fromJSONField(field) {
98
- return BalanceKey.reified().new({
99
- dummyField: decodeFromJSONField("bool", field.dummyField),
1325
+ return PriceGuard.reified().new({
1326
+ maxPriceChangeBps: decodeFromJSONField('u64', field.maxPriceChangeBps),
1327
+ minUpdateIntervalS: decodeFromJSONField('u64', field.minUpdateIntervalS),
1328
+ priceAnchor: decodeFromJSONField(Decimal.reified(), field.priceAnchor),
1329
+ smoothedPriceAnchor: decodeFromJSONField(Decimal.reified(), field.smoothedPriceAnchor),
1330
+ anchorTimestampS: decodeFromJSONField('u64', field.anchorTimestampS),
100
1331
  });
101
1332
  }
102
1333
  static fromJSON(json) {
103
- if (json.$typeName !== BalanceKey.$typeName) {
104
- throw new Error("not a WithTwoGenerics json object");
1334
+ if (json.$typeName !== PriceGuard.$typeName) {
1335
+ throw new Error(`not a PriceGuard json object: expected '${PriceGuard.$typeName}' but got '${json.$typeName}'`);
105
1336
  }
106
- return BalanceKey.fromJSONField(json);
1337
+ return PriceGuard.fromJSONField(json);
1338
+ }
1339
+ static fromCoreObject(obj) {
1340
+ if (!isPriceGuard(obj.type)) {
1341
+ throw new Error(`object at ${obj.objectId} is not a PriceGuard object`);
1342
+ }
1343
+ return PriceGuard.fromBcs(obj.content);
107
1344
  }
108
1345
  static async fetch(client, id) {
109
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
110
- if (!isBalanceKey(object.type)) {
111
- throw new Error(`object at id ${id} is not a BalanceKey object`);
1346
+ const { object } = await client.core.getObject({
1347
+ objectId: id,
1348
+ include: { content: true },
1349
+ });
1350
+ if (!isPriceGuard(object.type)) {
1351
+ throw new Error(`object at id ${id} is not a PriceGuard object`);
112
1352
  }
113
- return BalanceKey.fromBcs(object.content);
1353
+ return PriceGuard.fromBcs(object.content);
114
1354
  }
115
1355
  }
116
1356
  /* ============================== Balances =============================== */
117
1357
  export function isBalances(type) {
118
1358
  type = compressSuiType(type);
119
- return type.startsWith(`${PKG_V1}::reserve::Balances` + "<");
1359
+ return type.startsWith(`${getTypeOrigin('suilend', 'reserve::Balances')}::reserve::Balances` + '<');
120
1360
  }
1361
+ /** Balances are stored in a dynamic field to avoid typing the Reserve with CoinType */
121
1362
  export class Balances {
122
1363
  __StructClass = true;
123
- static $typeName = `${PKG_V1}::reserve::Balances`;
1364
+ static get $typeName() {
1365
+ return `${getTypeOrigin('suilend', 'reserve::Balances')}::reserve::Balances`;
1366
+ }
124
1367
  static $numTypeParams = 2;
125
1368
  static $isPhantom = [true, true];
126
1369
  $typeName = Balances.$typeName;
@@ -142,23 +1385,31 @@ export class Balances {
142
1385
  this.depositedCtokens = fields.depositedCtokens;
143
1386
  }
144
1387
  static reified(P, T) {
1388
+ const reifiedBcs = Balances.bcs;
145
1389
  return {
146
- typeName: Balances.$typeName,
147
- fullTypeName: composeSuiType(Balances.$typeName, ...[extractType(P), extractType(T)]),
148
- typeArgs: [extractType(P), extractType(T)],
1390
+ get typeName() {
1391
+ return Balances.$typeName;
1392
+ },
1393
+ get fullTypeName() {
1394
+ return composeSuiType(Balances.$typeName, ...[extractType(P), extractType(T)]);
1395
+ },
1396
+ get typeArgs() {
1397
+ return [extractType(P), extractType(T)];
1398
+ },
149
1399
  isPhantom: Balances.$isPhantom,
150
1400
  reifiedTypeArgs: [P, T],
151
1401
  fromFields: (fields) => Balances.fromFields([P, T], fields),
152
1402
  fromFieldsWithTypes: (item) => Balances.fromFieldsWithTypes([P, T], item),
153
- fromBcs: (data) => Balances.fromBcs([P, T], data),
154
- bcs: Balances.bcs,
1403
+ fromBcs: (data) => Balances.fromFields([P, T], reifiedBcs.parse(data)),
1404
+ bcs: reifiedBcs,
155
1405
  fromJSONField: (field) => Balances.fromJSONField([P, T], field),
156
1406
  fromJSON: (json) => Balances.fromJSON([P, T], json),
1407
+ fromCoreObject: (obj) => Balances.fromCoreObject([P, T], obj),
157
1408
  fetch: async (client, id) => Balances.fetch(client, [P, T], id),
158
1409
  new: (fields) => {
159
1410
  return new Balances([extractType(P), extractType(T)], fields);
160
1411
  },
161
- kind: "StructClassReified",
1412
+ kind: 'StructClassReified',
162
1413
  };
163
1414
  }
164
1415
  static get r() {
@@ -170,8 +1421,8 @@ export class Balances {
170
1421
  static get p() {
171
1422
  return Balances.phantom;
172
1423
  }
173
- static get bcs() {
174
- return bcs.struct("Balances", {
1424
+ static instantiateBcs() {
1425
+ return bcs.struct('Balances', {
175
1426
  available_amount: Balance.bcs,
176
1427
  ctoken_supply: Supply.bcs,
177
1428
  fees: Balance.bcs,
@@ -179,26 +1430,33 @@ export class Balances {
179
1430
  deposited_ctokens: Balance.bcs,
180
1431
  });
181
1432
  }
1433
+ static cachedBcs = null;
1434
+ static get bcs() {
1435
+ if (!Balances.cachedBcs) {
1436
+ Balances.cachedBcs = Balances.instantiateBcs();
1437
+ }
1438
+ return Balances.cachedBcs;
1439
+ }
182
1440
  static fromFields(typeArgs, fields) {
183
1441
  return Balances.reified(typeArgs[0], typeArgs[1]).new({
184
1442
  availableAmount: decodeFromFields(Balance.reified(typeArgs[1]), fields.available_amount),
185
- ctokenSupply: decodeFromFields(Supply.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), fields.ctoken_supply),
1443
+ ctokenSupply: decodeFromFields(Supply.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), fields.ctoken_supply),
186
1444
  fees: decodeFromFields(Balance.reified(typeArgs[1]), fields.fees),
187
- ctokenFees: decodeFromFields(Balance.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), fields.ctoken_fees),
188
- depositedCtokens: decodeFromFields(Balance.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), fields.deposited_ctokens),
1445
+ ctokenFees: decodeFromFields(Balance.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), fields.ctoken_fees),
1446
+ depositedCtokens: decodeFromFields(Balance.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), fields.deposited_ctokens),
189
1447
  });
190
1448
  }
191
1449
  static fromFieldsWithTypes(typeArgs, item) {
192
1450
  if (!isBalances(item.type)) {
193
- throw new Error("not a Balances type");
1451
+ throw new Error('not a Balances type');
194
1452
  }
195
1453
  assertFieldsWithTypesArgsMatch(item, typeArgs);
196
1454
  return Balances.reified(typeArgs[0], typeArgs[1]).new({
197
1455
  availableAmount: decodeFromFieldsWithTypes(Balance.reified(typeArgs[1]), item.fields.available_amount),
198
- ctokenSupply: decodeFromFieldsWithTypes(Supply.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), item.fields.ctoken_supply),
1456
+ ctokenSupply: decodeFromFieldsWithTypes(Supply.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), item.fields.ctoken_supply),
199
1457
  fees: decodeFromFieldsWithTypes(Balance.reified(typeArgs[1]), item.fields.fees),
200
- ctokenFees: decodeFromFieldsWithTypes(Balance.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), item.fields.ctoken_fees),
201
- depositedCtokens: decodeFromFieldsWithTypes(Balance.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), item.fields.deposited_ctokens),
1458
+ ctokenFees: decodeFromFieldsWithTypes(Balance.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), item.fields.ctoken_fees),
1459
+ depositedCtokens: decodeFromFieldsWithTypes(Balance.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), item.fields.deposited_ctokens),
202
1460
  });
203
1461
  }
204
1462
  static fromBcs(typeArgs, data) {
@@ -213,280 +1471,75 @@ export class Balances {
213
1471
  depositedCtokens: this.depositedCtokens.toJSONField(),
214
1472
  };
215
1473
  }
216
- toJSON() {
217
- return {
218
- $typeName: this.$typeName,
219
- $typeArgs: this.$typeArgs,
220
- ...this.toJSONField(),
221
- };
222
- }
223
- static fromJSONField(typeArgs, field) {
224
- return Balances.reified(typeArgs[0], typeArgs[1]).new({
225
- availableAmount: decodeFromJSONField(Balance.reified(typeArgs[1]), field.availableAmount),
226
- ctokenSupply: decodeFromJSONField(Supply.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), field.ctokenSupply),
227
- fees: decodeFromJSONField(Balance.reified(typeArgs[1]), field.fees),
228
- ctokenFees: decodeFromJSONField(Balance.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), field.ctokenFees),
229
- depositedCtokens: decodeFromJSONField(Balance.reified(reified.phantom(CToken.reified(typeArgs[0], typeArgs[1]))), field.depositedCtokens),
230
- });
231
- }
232
- static fromJSON(typeArgs, json) {
233
- if (json.$typeName !== Balances.$typeName) {
234
- throw new Error("not a WithTwoGenerics json object");
235
- }
236
- assertReifiedTypeArgsMatch(composeSuiType(Balances.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
237
- return Balances.fromJSONField(typeArgs, json);
238
- }
239
- static async fetch(client, typeArgs, id) {
240
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
241
- if (!isBalances(object.type)) {
242
- throw new Error(`object at id ${id} is not a Balances object`);
243
- }
244
- return Balances.fromBcs(typeArgs, object.content);
245
- }
246
- }
247
- /* ============================== CToken =============================== */
248
- export function isCToken(type) {
249
- type = compressSuiType(type);
250
- return type.startsWith(`${PKG_V1}::reserve::CToken` + "<");
251
- }
252
- export class CToken {
253
- __StructClass = true;
254
- static $typeName = `${PKG_V1}::reserve::CToken`;
255
- static $numTypeParams = 2;
256
- static $isPhantom = [true, true];
257
- $typeName = CToken.$typeName;
258
- $fullTypeName;
259
- $typeArgs;
260
- $isPhantom = CToken.$isPhantom;
261
- dummyField;
262
- constructor(typeArgs, fields) {
263
- this.$fullTypeName = composeSuiType(CToken.$typeName, ...typeArgs);
264
- this.$typeArgs = typeArgs;
265
- this.dummyField = fields.dummyField;
266
- }
267
- static reified(P, T) {
268
- return {
269
- typeName: CToken.$typeName,
270
- fullTypeName: composeSuiType(CToken.$typeName, ...[extractType(P), extractType(T)]),
271
- typeArgs: [extractType(P), extractType(T)],
272
- isPhantom: CToken.$isPhantom,
273
- reifiedTypeArgs: [P, T],
274
- fromFields: (fields) => CToken.fromFields([P, T], fields),
275
- fromFieldsWithTypes: (item) => CToken.fromFieldsWithTypes([P, T], item),
276
- fromBcs: (data) => CToken.fromBcs([P, T], data),
277
- bcs: CToken.bcs,
278
- fromJSONField: (field) => CToken.fromJSONField([P, T], field),
279
- fromJSON: (json) => CToken.fromJSON([P, T], json),
280
- fetch: async (client, id) => CToken.fetch(client, [P, T], id),
281
- new: (fields) => {
282
- return new CToken([extractType(P), extractType(T)], fields);
283
- },
284
- kind: "StructClassReified",
285
- };
286
- }
287
- static get r() {
288
- return CToken.reified;
289
- }
290
- static phantom(P, T) {
291
- return phantom(CToken.reified(P, T));
292
- }
293
- static get p() {
294
- return CToken.phantom;
295
- }
296
- static get bcs() {
297
- return bcs.struct("CToken", {
298
- dummy_field: bcs.bool(),
299
- });
300
- }
301
- static fromFields(typeArgs, fields) {
302
- return CToken.reified(typeArgs[0], typeArgs[1]).new({
303
- dummyField: decodeFromFields("bool", fields.dummy_field),
304
- });
305
- }
306
- static fromFieldsWithTypes(typeArgs, item) {
307
- if (!isCToken(item.type)) {
308
- throw new Error("not a CToken type");
309
- }
310
- assertFieldsWithTypesArgsMatch(item, typeArgs);
311
- return CToken.reified(typeArgs[0], typeArgs[1]).new({
312
- dummyField: decodeFromFieldsWithTypes("bool", item.fields.dummy_field),
313
- });
314
- }
315
- static fromBcs(typeArgs, data) {
316
- return CToken.fromFields(typeArgs, CToken.bcs.parse(data));
317
- }
318
- toJSONField() {
319
- return {
320
- dummyField: this.dummyField,
321
- };
322
- }
323
- toJSON() {
324
- return {
325
- $typeName: this.$typeName,
326
- $typeArgs: this.$typeArgs,
327
- ...this.toJSONField(),
328
- };
329
- }
330
- static fromJSONField(typeArgs, field) {
331
- return CToken.reified(typeArgs[0], typeArgs[1]).new({
332
- dummyField: decodeFromJSONField("bool", field.dummyField),
333
- });
334
- }
335
- static fromJSON(typeArgs, json) {
336
- if (json.$typeName !== CToken.$typeName) {
337
- throw new Error("not a WithTwoGenerics json object");
338
- }
339
- assertReifiedTypeArgsMatch(composeSuiType(CToken.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
340
- return CToken.fromJSONField(typeArgs, json);
341
- }
342
- static async fetch(client, typeArgs, id) {
343
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
344
- if (!isCToken(object.type)) {
345
- throw new Error(`object at id ${id} is not a CToken object`);
346
- }
347
- return CToken.fromBcs(typeArgs, object.content);
348
- }
349
- }
350
- /* ============================== ClaimStakingRewardsEvent =============================== */
351
- export function isClaimStakingRewardsEvent(type) {
352
- type = compressSuiType(type);
353
- return type === `${PKG_V8}::reserve::ClaimStakingRewardsEvent`;
354
- }
355
- export class ClaimStakingRewardsEvent {
356
- __StructClass = true;
357
- static $typeName = `${PKG_V8}::reserve::ClaimStakingRewardsEvent`;
358
- static $numTypeParams = 0;
359
- static $isPhantom = [];
360
- $typeName = ClaimStakingRewardsEvent.$typeName;
361
- $fullTypeName;
362
- $typeArgs;
363
- $isPhantom = ClaimStakingRewardsEvent.$isPhantom;
364
- lendingMarketId;
365
- coinType;
366
- reserveId;
367
- amount;
368
- constructor(typeArgs, fields) {
369
- this.$fullTypeName = composeSuiType(ClaimStakingRewardsEvent.$typeName, ...typeArgs);
370
- this.$typeArgs = typeArgs;
371
- this.lendingMarketId = fields.lendingMarketId;
372
- this.coinType = fields.coinType;
373
- this.reserveId = fields.reserveId;
374
- this.amount = fields.amount;
375
- }
376
- static reified() {
377
- return {
378
- typeName: ClaimStakingRewardsEvent.$typeName,
379
- fullTypeName: composeSuiType(ClaimStakingRewardsEvent.$typeName, ...[]),
380
- typeArgs: [],
381
- isPhantom: ClaimStakingRewardsEvent.$isPhantom,
382
- reifiedTypeArgs: [],
383
- fromFields: (fields) => ClaimStakingRewardsEvent.fromFields(fields),
384
- fromFieldsWithTypes: (item) => ClaimStakingRewardsEvent.fromFieldsWithTypes(item),
385
- fromBcs: (data) => ClaimStakingRewardsEvent.fromBcs(data),
386
- bcs: ClaimStakingRewardsEvent.bcs,
387
- fromJSONField: (field) => ClaimStakingRewardsEvent.fromJSONField(field),
388
- fromJSON: (json) => ClaimStakingRewardsEvent.fromJSON(json),
389
- fetch: async (client, id) => ClaimStakingRewardsEvent.fetch(client, id),
390
- new: (fields) => {
391
- return new ClaimStakingRewardsEvent([], fields);
392
- },
393
- kind: "StructClassReified",
394
- };
395
- }
396
- static get r() {
397
- return ClaimStakingRewardsEvent.reified();
398
- }
399
- static phantom() {
400
- return phantom(ClaimStakingRewardsEvent.reified());
401
- }
402
- static get p() {
403
- return ClaimStakingRewardsEvent.phantom();
404
- }
405
- static get bcs() {
406
- return bcs.struct("ClaimStakingRewardsEvent", {
407
- lending_market_id: bcs
408
- .bytes(32)
409
- .transform({
410
- input: (val) => fromHex(val),
411
- output: (val) => toHex(val),
412
- }),
413
- coin_type: TypeName.bcs,
414
- reserve_id: bcs
415
- .bytes(32)
416
- .transform({
417
- input: (val) => fromHex(val),
418
- output: (val) => toHex(val),
419
- }),
420
- amount: bcs.u64(),
421
- });
422
- }
423
- static fromFields(fields) {
424
- return ClaimStakingRewardsEvent.reified().new({
425
- lendingMarketId: decodeFromFields("address", fields.lending_market_id),
426
- coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
427
- reserveId: decodeFromFields("address", fields.reserve_id),
428
- amount: decodeFromFields("u64", fields.amount),
429
- });
430
- }
431
- static fromFieldsWithTypes(item) {
432
- if (!isClaimStakingRewardsEvent(item.type)) {
433
- throw new Error("not a ClaimStakingRewardsEvent type");
434
- }
435
- return ClaimStakingRewardsEvent.reified().new({
436
- lendingMarketId: decodeFromFieldsWithTypes("address", item.fields.lending_market_id),
437
- coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
438
- reserveId: decodeFromFieldsWithTypes("address", item.fields.reserve_id),
439
- amount: decodeFromFieldsWithTypes("u64", item.fields.amount),
440
- });
441
- }
442
- static fromBcs(data) {
443
- return ClaimStakingRewardsEvent.fromFields(ClaimStakingRewardsEvent.bcs.parse(data));
444
- }
445
- toJSONField() {
446
- return {
447
- lendingMarketId: this.lendingMarketId,
448
- coinType: this.coinType.toJSONField(),
449
- reserveId: this.reserveId,
450
- amount: this.amount.toString(),
451
- };
452
- }
453
- toJSON() {
454
- return {
455
- $typeName: this.$typeName,
456
- $typeArgs: this.$typeArgs,
457
- ...this.toJSONField(),
458
- };
1474
+ toJSON() {
1475
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
459
1476
  }
460
- static fromJSONField(field) {
461
- return ClaimStakingRewardsEvent.reified().new({
462
- lendingMarketId: decodeFromJSONField("address", field.lendingMarketId),
463
- coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
464
- reserveId: decodeFromJSONField("address", field.reserveId),
465
- amount: decodeFromJSONField("u64", field.amount),
1477
+ static fromJSONField(typeArgs, field) {
1478
+ return Balances.reified(typeArgs[0], typeArgs[1]).new({
1479
+ availableAmount: decodeFromJSONField(Balance.reified(typeArgs[1]), field.availableAmount),
1480
+ ctokenSupply: decodeFromJSONField(Supply.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), field.ctokenSupply),
1481
+ fees: decodeFromJSONField(Balance.reified(typeArgs[1]), field.fees),
1482
+ ctokenFees: decodeFromJSONField(Balance.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), field.ctokenFees),
1483
+ depositedCtokens: decodeFromJSONField(Balance.reified(phantom(CToken.reified(typeArgs[0], typeArgs[1]))), field.depositedCtokens),
466
1484
  });
467
1485
  }
468
- static fromJSON(json) {
469
- if (json.$typeName !== ClaimStakingRewardsEvent.$typeName) {
470
- throw new Error("not a WithTwoGenerics json object");
1486
+ static fromJSON(typeArgs, json) {
1487
+ if (json.$typeName !== Balances.$typeName) {
1488
+ throw new Error(`not a Balances json object: expected '${Balances.$typeName}' but got '${json.$typeName}'`);
471
1489
  }
472
- return ClaimStakingRewardsEvent.fromJSONField(json);
1490
+ assertReifiedTypeArgsMatch(composeSuiType(Balances.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
1491
+ return Balances.fromJSONField(typeArgs, json);
473
1492
  }
474
- static async fetch(client, id) {
475
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
476
- if (!isClaimStakingRewardsEvent(object.type)) {
477
- throw new Error(`object at id ${id} is not a ClaimStakingRewardsEvent object`);
1493
+ static fromCoreObject(typeArgs, obj) {
1494
+ if (!isBalances(obj.type)) {
1495
+ throw new Error(`object at ${obj.objectId} is not a Balances object`);
478
1496
  }
479
- return ClaimStakingRewardsEvent.fromBcs(object.content);
1497
+ const gotTypeArgs = parseTypeName(obj.type).typeArgs;
1498
+ if (gotTypeArgs.length !== 2) {
1499
+ throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
1500
+ }
1501
+ for (let i = 0; i < 2; i++) {
1502
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
1503
+ const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
1504
+ if (gotTypeArg !== expectedTypeArg) {
1505
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
1506
+ }
1507
+ }
1508
+ return Balances.fromBcs(typeArgs, obj.content);
1509
+ }
1510
+ static async fetch(client, typeArgs, id) {
1511
+ const { object } = await client.core.getObject({
1512
+ objectId: id,
1513
+ include: { content: true },
1514
+ });
1515
+ if (!isBalances(object.type)) {
1516
+ throw new Error(`object at id ${id} is not a Balances object`);
1517
+ }
1518
+ const gotTypeArgs = parseTypeName(object.type).typeArgs;
1519
+ if (gotTypeArgs.length !== 2) {
1520
+ throw new Error(`type argument mismatch: expected 2 type arguments but got '${gotTypeArgs.length}'`);
1521
+ }
1522
+ for (let i = 0; i < 2; i++) {
1523
+ const gotTypeArg = compressSuiType(gotTypeArgs[i]);
1524
+ const expectedTypeArg = compressSuiType(extractType(typeArgs[i]));
1525
+ if (gotTypeArg !== expectedTypeArg) {
1526
+ throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`);
1527
+ }
1528
+ }
1529
+ return Balances.fromBcs(typeArgs, object.content);
480
1530
  }
481
1531
  }
482
1532
  /* ============================== InterestUpdateEvent =============================== */
483
1533
  export function isInterestUpdateEvent(type) {
484
1534
  type = compressSuiType(type);
485
- return type === `${PKG_V1}::reserve::InterestUpdateEvent`;
1535
+ return type
1536
+ === `${getTypeOrigin('suilend', 'reserve::InterestUpdateEvent')}::reserve::InterestUpdateEvent`;
486
1537
  }
487
1538
  export class InterestUpdateEvent {
488
1539
  __StructClass = true;
489
- static $typeName = `${PKG_V1}::reserve::InterestUpdateEvent`;
1540
+ static get $typeName() {
1541
+ return `${getTypeOrigin('suilend', 'reserve::InterestUpdateEvent')}::reserve::InterestUpdateEvent`;
1542
+ }
490
1543
  static $numTypeParams = 0;
491
1544
  static $isPhantom = [];
492
1545
  $typeName = InterestUpdateEvent.$typeName;
@@ -523,27 +1576,32 @@ export class InterestUpdateEvent {
523
1576
  this.supplyInterestEarned = fields.supplyInterestEarned;
524
1577
  this.borrowInterestPaidUsdEstimate = fields.borrowInterestPaidUsdEstimate;
525
1578
  this.protocolFeeUsdEstimate = fields.protocolFeeUsdEstimate;
526
- this.supplyInterestEarnedUsdEstimate =
527
- fields.supplyInterestEarnedUsdEstimate;
1579
+ this.supplyInterestEarnedUsdEstimate = fields.supplyInterestEarnedUsdEstimate;
528
1580
  }
529
1581
  static reified() {
1582
+ const reifiedBcs = InterestUpdateEvent.bcs;
530
1583
  return {
531
- typeName: InterestUpdateEvent.$typeName,
532
- fullTypeName: composeSuiType(InterestUpdateEvent.$typeName, ...[]),
1584
+ get typeName() {
1585
+ return InterestUpdateEvent.$typeName;
1586
+ },
1587
+ get fullTypeName() {
1588
+ return composeSuiType(InterestUpdateEvent.$typeName, ...[]);
1589
+ },
533
1590
  typeArgs: [],
534
1591
  isPhantom: InterestUpdateEvent.$isPhantom,
535
1592
  reifiedTypeArgs: [],
536
1593
  fromFields: (fields) => InterestUpdateEvent.fromFields(fields),
537
1594
  fromFieldsWithTypes: (item) => InterestUpdateEvent.fromFieldsWithTypes(item),
538
- fromBcs: (data) => InterestUpdateEvent.fromBcs(data),
539
- bcs: InterestUpdateEvent.bcs,
1595
+ fromBcs: (data) => InterestUpdateEvent.fromFields(reifiedBcs.parse(data)),
1596
+ bcs: reifiedBcs,
540
1597
  fromJSONField: (field) => InterestUpdateEvent.fromJSONField(field),
541
1598
  fromJSON: (json) => InterestUpdateEvent.fromJSON(json),
1599
+ fromCoreObject: (obj) => InterestUpdateEvent.fromCoreObject(obj),
542
1600
  fetch: async (client, id) => InterestUpdateEvent.fetch(client, id),
543
1601
  new: (fields) => {
544
1602
  return new InterestUpdateEvent([], fields);
545
1603
  },
546
- kind: "StructClassReified",
1604
+ kind: 'StructClassReified',
547
1605
  };
548
1606
  }
549
1607
  static get r() {
@@ -555,18 +1613,14 @@ export class InterestUpdateEvent {
555
1613
  static get p() {
556
1614
  return InterestUpdateEvent.phantom();
557
1615
  }
558
- static get bcs() {
559
- return bcs.struct("InterestUpdateEvent", {
560
- lending_market_id: bcs
561
- .bytes(32)
562
- .transform({
1616
+ static instantiateBcs() {
1617
+ return bcs.struct('InterestUpdateEvent', {
1618
+ lending_market_id: bcs.bytes(32).transform({
563
1619
  input: (val) => fromHex(val),
564
1620
  output: (val) => toHex(val),
565
1621
  }),
566
1622
  coin_type: TypeName.bcs,
567
- reserve_id: bcs
568
- .bytes(32)
569
- .transform({
1623
+ reserve_id: bcs.bytes(32).transform({
570
1624
  input: (val) => fromHex(val),
571
1625
  output: (val) => toHex(val),
572
1626
  }),
@@ -583,16 +1637,23 @@ export class InterestUpdateEvent {
583
1637
  supply_interest_earned_usd_estimate: Decimal.bcs,
584
1638
  });
585
1639
  }
1640
+ static cachedBcs = null;
1641
+ static get bcs() {
1642
+ if (!InterestUpdateEvent.cachedBcs) {
1643
+ InterestUpdateEvent.cachedBcs = InterestUpdateEvent.instantiateBcs();
1644
+ }
1645
+ return InterestUpdateEvent.cachedBcs;
1646
+ }
586
1647
  static fromFields(fields) {
587
1648
  return InterestUpdateEvent.reified().new({
588
- lendingMarketId: decodeFromFields("address", fields.lending_market_id),
1649
+ lendingMarketId: decodeFromFields('address', fields.lending_market_id),
589
1650
  coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
590
- reserveId: decodeFromFields("address", fields.reserve_id),
1651
+ reserveId: decodeFromFields('address', fields.reserve_id),
591
1652
  cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
592
- availableAmount: decodeFromFields("u64", fields.available_amount),
1653
+ availableAmount: decodeFromFields('u64', fields.available_amount),
593
1654
  borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
594
1655
  unclaimedSpreadFees: decodeFromFields(Decimal.reified(), fields.unclaimed_spread_fees),
595
- ctokenSupply: decodeFromFields("u64", fields.ctoken_supply),
1656
+ ctokenSupply: decodeFromFields('u64', fields.ctoken_supply),
596
1657
  borrowInterestPaid: decodeFromFields(Decimal.reified(), fields.borrow_interest_paid),
597
1658
  spreadFee: decodeFromFields(Decimal.reified(), fields.spread_fee),
598
1659
  supplyInterestEarned: decodeFromFields(Decimal.reified(), fields.supply_interest_earned),
@@ -603,17 +1664,17 @@ export class InterestUpdateEvent {
603
1664
  }
604
1665
  static fromFieldsWithTypes(item) {
605
1666
  if (!isInterestUpdateEvent(item.type)) {
606
- throw new Error("not a InterestUpdateEvent type");
1667
+ throw new Error('not a InterestUpdateEvent type');
607
1668
  }
608
1669
  return InterestUpdateEvent.reified().new({
609
- lendingMarketId: decodeFromFieldsWithTypes("address", item.fields.lending_market_id),
1670
+ lendingMarketId: decodeFromFieldsWithTypes('address', item.fields.lending_market_id),
610
1671
  coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
611
- reserveId: decodeFromFieldsWithTypes("address", item.fields.reserve_id),
1672
+ reserveId: decodeFromFieldsWithTypes('address', item.fields.reserve_id),
612
1673
  cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
613
- availableAmount: decodeFromFieldsWithTypes("u64", item.fields.available_amount),
1674
+ availableAmount: decodeFromFieldsWithTypes('u64', item.fields.available_amount),
614
1675
  borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
615
1676
  unclaimedSpreadFees: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unclaimed_spread_fees),
616
- ctokenSupply: decodeFromFieldsWithTypes("u64", item.fields.ctoken_supply),
1677
+ ctokenSupply: decodeFromFieldsWithTypes('u64', item.fields.ctoken_supply),
617
1678
  borrowInterestPaid: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrow_interest_paid),
618
1679
  spreadFee: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.spread_fee),
619
1680
  supplyInterestEarned: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_interest_earned),
@@ -628,7 +1689,7 @@ export class InterestUpdateEvent {
628
1689
  toJSONField() {
629
1690
  return {
630
1691
  lendingMarketId: this.lendingMarketId,
631
- coinType: this.coinType.toJSONField(),
1692
+ coinType: this.coinType,
632
1693
  reserveId: this.reserveId,
633
1694
  cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
634
1695
  availableAmount: this.availableAmount.toString(),
@@ -644,22 +1705,18 @@ export class InterestUpdateEvent {
644
1705
  };
645
1706
  }
646
1707
  toJSON() {
647
- return {
648
- $typeName: this.$typeName,
649
- $typeArgs: this.$typeArgs,
650
- ...this.toJSONField(),
651
- };
1708
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
652
1709
  }
653
1710
  static fromJSONField(field) {
654
1711
  return InterestUpdateEvent.reified().new({
655
- lendingMarketId: decodeFromJSONField("address", field.lendingMarketId),
1712
+ lendingMarketId: decodeFromJSONField('address', field.lendingMarketId),
656
1713
  coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
657
- reserveId: decodeFromJSONField("address", field.reserveId),
1714
+ reserveId: decodeFromJSONField('address', field.reserveId),
658
1715
  cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
659
- availableAmount: decodeFromJSONField("u64", field.availableAmount),
1716
+ availableAmount: decodeFromJSONField('u64', field.availableAmount),
660
1717
  borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
661
1718
  unclaimedSpreadFees: decodeFromJSONField(Decimal.reified(), field.unclaimedSpreadFees),
662
- ctokenSupply: decodeFromJSONField("u64", field.ctokenSupply),
1719
+ ctokenSupply: decodeFromJSONField('u64', field.ctokenSupply),
663
1720
  borrowInterestPaid: decodeFromJSONField(Decimal.reified(), field.borrowInterestPaid),
664
1721
  spreadFee: decodeFromJSONField(Decimal.reified(), field.spreadFee),
665
1722
  supplyInterestEarned: decodeFromJSONField(Decimal.reified(), field.supplyInterestEarned),
@@ -670,371 +1727,282 @@ export class InterestUpdateEvent {
670
1727
  }
671
1728
  static fromJSON(json) {
672
1729
  if (json.$typeName !== InterestUpdateEvent.$typeName) {
673
- throw new Error("not a WithTwoGenerics json object");
1730
+ throw new Error(`not a InterestUpdateEvent json object: expected '${InterestUpdateEvent.$typeName}' but got '${json.$typeName}'`);
674
1731
  }
675
1732
  return InterestUpdateEvent.fromJSONField(json);
676
1733
  }
1734
+ static fromCoreObject(obj) {
1735
+ if (!isInterestUpdateEvent(obj.type)) {
1736
+ throw new Error(`object at ${obj.objectId} is not a InterestUpdateEvent object`);
1737
+ }
1738
+ return InterestUpdateEvent.fromBcs(obj.content);
1739
+ }
677
1740
  static async fetch(client, id) {
678
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
1741
+ const { object } = await client.core.getObject({
1742
+ objectId: id,
1743
+ include: { content: true },
1744
+ });
679
1745
  if (!isInterestUpdateEvent(object.type)) {
680
1746
  throw new Error(`object at id ${id} is not a InterestUpdateEvent object`);
681
1747
  }
682
1748
  return InterestUpdateEvent.fromBcs(object.content);
683
1749
  }
684
1750
  }
685
- /* ============================== LiquidityRequest =============================== */
686
- export function isLiquidityRequest(type) {
1751
+ /* ============================== ReserveAssetDataEvent =============================== */
1752
+ export function isReserveAssetDataEvent(type) {
687
1753
  type = compressSuiType(type);
688
- return type.startsWith(`${PKG_V8}::reserve::LiquidityRequest` + "<");
1754
+ return type
1755
+ === `${getTypeOrigin('suilend', 'reserve::ReserveAssetDataEvent')}::reserve::ReserveAssetDataEvent`;
689
1756
  }
690
- export class LiquidityRequest {
1757
+ /**
1758
+ * Deprecated: this struct's layout is frozen by Sui's upgrade-compatibility check, since
1759
+ * it is already published on mainnet. Use `ReserveAssetDataEventV2` instead, which carries
1760
+ * every field here plus `conf`.
1761
+ */
1762
+ export class ReserveAssetDataEvent {
691
1763
  __StructClass = true;
692
- static $typeName = `${PKG_V8}::reserve::LiquidityRequest`;
693
- static $numTypeParams = 2;
694
- static $isPhantom = [true, true];
695
- $typeName = LiquidityRequest.$typeName;
696
- $fullTypeName;
697
- $typeArgs;
698
- $isPhantom = LiquidityRequest.$isPhantom;
699
- amount;
700
- fee;
701
- constructor(typeArgs, fields) {
702
- this.$fullTypeName = composeSuiType(LiquidityRequest.$typeName, ...typeArgs);
703
- this.$typeArgs = typeArgs;
704
- this.amount = fields.amount;
705
- this.fee = fields.fee;
706
- }
707
- static reified(P, T) {
708
- return {
709
- typeName: LiquidityRequest.$typeName,
710
- fullTypeName: composeSuiType(LiquidityRequest.$typeName, ...[extractType(P), extractType(T)]),
711
- typeArgs: [extractType(P), extractType(T)],
712
- isPhantom: LiquidityRequest.$isPhantom,
713
- reifiedTypeArgs: [P, T],
714
- fromFields: (fields) => LiquidityRequest.fromFields([P, T], fields),
715
- fromFieldsWithTypes: (item) => LiquidityRequest.fromFieldsWithTypes([P, T], item),
716
- fromBcs: (data) => LiquidityRequest.fromBcs([P, T], data),
717
- bcs: LiquidityRequest.bcs,
718
- fromJSONField: (field) => LiquidityRequest.fromJSONField([P, T], field),
719
- fromJSON: (json) => LiquidityRequest.fromJSON([P, T], json),
720
- fetch: async (client, id) => LiquidityRequest.fetch(client, [P, T], id),
721
- new: (fields) => {
722
- return new LiquidityRequest([extractType(P), extractType(T)], fields);
723
- },
724
- kind: "StructClassReified",
725
- };
726
- }
727
- static get r() {
728
- return LiquidityRequest.reified;
729
- }
730
- static phantom(P, T) {
731
- return phantom(LiquidityRequest.reified(P, T));
732
- }
733
- static get p() {
734
- return LiquidityRequest.phantom;
735
- }
736
- static get bcs() {
737
- return bcs.struct("LiquidityRequest", {
738
- amount: bcs.u64(),
739
- fee: bcs.u64(),
740
- });
741
- }
742
- static fromFields(typeArgs, fields) {
743
- return LiquidityRequest.reified(typeArgs[0], typeArgs[1]).new({
744
- amount: decodeFromFields("u64", fields.amount),
745
- fee: decodeFromFields("u64", fields.fee),
746
- });
747
- }
748
- static fromFieldsWithTypes(typeArgs, item) {
749
- if (!isLiquidityRequest(item.type)) {
750
- throw new Error("not a LiquidityRequest type");
751
- }
752
- assertFieldsWithTypesArgsMatch(item, typeArgs);
753
- return LiquidityRequest.reified(typeArgs[0], typeArgs[1]).new({
754
- amount: decodeFromFieldsWithTypes("u64", item.fields.amount),
755
- fee: decodeFromFieldsWithTypes("u64", item.fields.fee),
756
- });
757
- }
758
- static fromBcs(typeArgs, data) {
759
- return LiquidityRequest.fromFields(typeArgs, LiquidityRequest.bcs.parse(data));
760
- }
761
- toJSONField() {
762
- return {
763
- amount: this.amount.toString(),
764
- fee: this.fee.toString(),
765
- };
766
- }
767
- toJSON() {
768
- return {
769
- $typeName: this.$typeName,
770
- $typeArgs: this.$typeArgs,
771
- ...this.toJSONField(),
772
- };
773
- }
774
- static fromJSONField(typeArgs, field) {
775
- return LiquidityRequest.reified(typeArgs[0], typeArgs[1]).new({
776
- amount: decodeFromJSONField("u64", field.amount),
777
- fee: decodeFromJSONField("u64", field.fee),
778
- });
779
- }
780
- static fromJSON(typeArgs, json) {
781
- if (json.$typeName !== LiquidityRequest.$typeName) {
782
- throw new Error("not a WithTwoGenerics json object");
783
- }
784
- assertReifiedTypeArgsMatch(composeSuiType(LiquidityRequest.$typeName, ...typeArgs.map(extractType)), json.$typeArgs, typeArgs);
785
- return LiquidityRequest.fromJSONField(typeArgs, json);
786
- }
787
- static async fetch(client, typeArgs, id) {
788
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
789
- if (!isLiquidityRequest(object.type)) {
790
- throw new Error(`object at id ${id} is not a LiquidityRequest object`);
791
- }
792
- return LiquidityRequest.fromBcs(typeArgs, object.content);
1764
+ static get $typeName() {
1765
+ return `${getTypeOrigin('suilend', 'reserve::ReserveAssetDataEvent')}::reserve::ReserveAssetDataEvent`;
793
1766
  }
794
- }
795
- /* ============================== Reserve =============================== */
796
- export function isReserve(type) {
797
- type = compressSuiType(type);
798
- return type.startsWith(`${PKG_V1}::reserve::Reserve` + "<");
799
- }
800
- export class Reserve {
801
- __StructClass = true;
802
- static $typeName = `${PKG_V1}::reserve::Reserve`;
803
- static $numTypeParams = 1;
804
- static $isPhantom = [true];
805
- $typeName = Reserve.$typeName;
1767
+ static $numTypeParams = 0;
1768
+ static $isPhantom = [];
1769
+ $typeName = ReserveAssetDataEvent.$typeName;
806
1770
  $fullTypeName;
807
1771
  $typeArgs;
808
- $isPhantom = Reserve.$isPhantom;
809
- id;
1772
+ $isPhantom = ReserveAssetDataEvent.$isPhantom;
810
1773
  lendingMarketId;
811
- arrayIndex;
812
1774
  coinType;
813
- config;
814
- mintDecimals;
815
- priceIdentifier;
816
- price;
817
- smoothedPrice;
818
- priceLastUpdateTimestampS;
1775
+ reserveId;
819
1776
  availableAmount;
820
- ctokenSupply;
1777
+ supplyAmount;
821
1778
  borrowedAmount;
1779
+ availableAmountUsdEstimate;
1780
+ supplyAmountUsdEstimate;
1781
+ borrowedAmountUsdEstimate;
1782
+ borrowApr;
1783
+ supplyApr;
1784
+ ctokenSupply;
822
1785
  cumulativeBorrowRate;
823
- interestLastUpdateTimestampS;
824
- unclaimedSpreadFees;
825
- attributedBorrowValue;
826
- depositsPoolRewardManager;
827
- borrowsPoolRewardManager;
1786
+ price;
1787
+ smoothedPrice;
1788
+ priceLastUpdateTimestampS;
828
1789
  constructor(typeArgs, fields) {
829
- this.$fullTypeName = composeSuiType(Reserve.$typeName, ...typeArgs);
1790
+ this.$fullTypeName = composeSuiType(ReserveAssetDataEvent.$typeName, ...typeArgs);
830
1791
  this.$typeArgs = typeArgs;
831
- this.id = fields.id;
832
1792
  this.lendingMarketId = fields.lendingMarketId;
833
- this.arrayIndex = fields.arrayIndex;
834
1793
  this.coinType = fields.coinType;
835
- this.config = fields.config;
836
- this.mintDecimals = fields.mintDecimals;
837
- this.priceIdentifier = fields.priceIdentifier;
838
- this.price = fields.price;
839
- this.smoothedPrice = fields.smoothedPrice;
840
- this.priceLastUpdateTimestampS = fields.priceLastUpdateTimestampS;
1794
+ this.reserveId = fields.reserveId;
841
1795
  this.availableAmount = fields.availableAmount;
842
- this.ctokenSupply = fields.ctokenSupply;
1796
+ this.supplyAmount = fields.supplyAmount;
843
1797
  this.borrowedAmount = fields.borrowedAmount;
1798
+ this.availableAmountUsdEstimate = fields.availableAmountUsdEstimate;
1799
+ this.supplyAmountUsdEstimate = fields.supplyAmountUsdEstimate;
1800
+ this.borrowedAmountUsdEstimate = fields.borrowedAmountUsdEstimate;
1801
+ this.borrowApr = fields.borrowApr;
1802
+ this.supplyApr = fields.supplyApr;
1803
+ this.ctokenSupply = fields.ctokenSupply;
844
1804
  this.cumulativeBorrowRate = fields.cumulativeBorrowRate;
845
- this.interestLastUpdateTimestampS = fields.interestLastUpdateTimestampS;
846
- this.unclaimedSpreadFees = fields.unclaimedSpreadFees;
847
- this.attributedBorrowValue = fields.attributedBorrowValue;
848
- this.depositsPoolRewardManager = fields.depositsPoolRewardManager;
849
- this.borrowsPoolRewardManager = fields.borrowsPoolRewardManager;
1805
+ this.price = fields.price;
1806
+ this.smoothedPrice = fields.smoothedPrice;
1807
+ this.priceLastUpdateTimestampS = fields.priceLastUpdateTimestampS;
850
1808
  }
851
- static reified(P) {
1809
+ static reified() {
1810
+ const reifiedBcs = ReserveAssetDataEvent.bcs;
852
1811
  return {
853
- typeName: Reserve.$typeName,
854
- fullTypeName: composeSuiType(Reserve.$typeName, ...[extractType(P)]),
855
- typeArgs: [extractType(P)],
856
- isPhantom: Reserve.$isPhantom,
857
- reifiedTypeArgs: [P],
858
- fromFields: (fields) => Reserve.fromFields(P, fields),
859
- fromFieldsWithTypes: (item) => Reserve.fromFieldsWithTypes(P, item),
860
- fromBcs: (data) => Reserve.fromBcs(P, data),
861
- bcs: Reserve.bcs,
862
- fromJSONField: (field) => Reserve.fromJSONField(P, field),
863
- fromJSON: (json) => Reserve.fromJSON(P, json),
864
- fetch: async (client, id) => Reserve.fetch(client, P, id),
1812
+ get typeName() {
1813
+ return ReserveAssetDataEvent.$typeName;
1814
+ },
1815
+ get fullTypeName() {
1816
+ return composeSuiType(ReserveAssetDataEvent.$typeName, ...[]);
1817
+ },
1818
+ typeArgs: [],
1819
+ isPhantom: ReserveAssetDataEvent.$isPhantom,
1820
+ reifiedTypeArgs: [],
1821
+ fromFields: (fields) => ReserveAssetDataEvent.fromFields(fields),
1822
+ fromFieldsWithTypes: (item) => ReserveAssetDataEvent.fromFieldsWithTypes(item),
1823
+ fromBcs: (data) => ReserveAssetDataEvent.fromFields(reifiedBcs.parse(data)),
1824
+ bcs: reifiedBcs,
1825
+ fromJSONField: (field) => ReserveAssetDataEvent.fromJSONField(field),
1826
+ fromJSON: (json) => ReserveAssetDataEvent.fromJSON(json),
1827
+ fromCoreObject: (obj) => ReserveAssetDataEvent.fromCoreObject(obj),
1828
+ fetch: async (client, id) => ReserveAssetDataEvent.fetch(client, id),
865
1829
  new: (fields) => {
866
- return new Reserve([extractType(P)], fields);
1830
+ return new ReserveAssetDataEvent([], fields);
867
1831
  },
868
- kind: "StructClassReified",
1832
+ kind: 'StructClassReified',
869
1833
  };
870
1834
  }
871
1835
  static get r() {
872
- return Reserve.reified;
1836
+ return ReserveAssetDataEvent.reified();
873
1837
  }
874
- static phantom(P) {
875
- return phantom(Reserve.reified(P));
1838
+ static phantom() {
1839
+ return phantom(ReserveAssetDataEvent.reified());
876
1840
  }
877
1841
  static get p() {
878
- return Reserve.phantom;
1842
+ return ReserveAssetDataEvent.phantom();
879
1843
  }
880
- static get bcs() {
881
- return bcs.struct("Reserve", {
882
- id: UID.bcs,
883
- lending_market_id: ID.bcs,
884
- array_index: bcs.u64(),
1844
+ static instantiateBcs() {
1845
+ return bcs.struct('ReserveAssetDataEvent', {
1846
+ lending_market_id: bcs.bytes(32).transform({
1847
+ input: (val) => fromHex(val),
1848
+ output: (val) => toHex(val),
1849
+ }),
885
1850
  coin_type: TypeName.bcs,
886
- config: Cell.bcs(ReserveConfig.bcs),
887
- mint_decimals: bcs.u8(),
888
- price_identifier: PriceIdentifier.bcs,
889
- price: Decimal.bcs,
890
- smoothed_price: Decimal.bcs,
891
- price_last_update_timestamp_s: bcs.u64(),
892
- available_amount: bcs.u64(),
893
- ctoken_supply: bcs.u64(),
1851
+ reserve_id: bcs.bytes(32).transform({
1852
+ input: (val) => fromHex(val),
1853
+ output: (val) => toHex(val),
1854
+ }),
1855
+ available_amount: Decimal.bcs,
1856
+ supply_amount: Decimal.bcs,
894
1857
  borrowed_amount: Decimal.bcs,
895
- cumulative_borrow_rate: Decimal.bcs,
896
- interest_last_update_timestamp_s: bcs.u64(),
897
- unclaimed_spread_fees: Decimal.bcs,
898
- attributed_borrow_value: Decimal.bcs,
899
- deposits_pool_reward_manager: PoolRewardManager.bcs,
900
- borrows_pool_reward_manager: PoolRewardManager.bcs,
1858
+ available_amount_usd_estimate: Decimal.bcs,
1859
+ supply_amount_usd_estimate: Decimal.bcs,
1860
+ borrowed_amount_usd_estimate: Decimal.bcs,
1861
+ borrow_apr: Decimal.bcs,
1862
+ supply_apr: Decimal.bcs,
1863
+ ctoken_supply: bcs.u64(),
1864
+ cumulative_borrow_rate: Decimal.bcs,
1865
+ price: Decimal.bcs,
1866
+ smoothed_price: Decimal.bcs,
1867
+ price_last_update_timestamp_s: bcs.u64(),
901
1868
  });
902
1869
  }
903
- static fromFields(typeArg, fields) {
904
- return Reserve.reified(typeArg).new({
905
- id: decodeFromFields(UID.reified(), fields.id),
906
- lendingMarketId: decodeFromFields(ID.reified(), fields.lending_market_id),
907
- arrayIndex: decodeFromFields("u64", fields.array_index),
1870
+ static cachedBcs = null;
1871
+ static get bcs() {
1872
+ if (!ReserveAssetDataEvent.cachedBcs) {
1873
+ ReserveAssetDataEvent.cachedBcs = ReserveAssetDataEvent.instantiateBcs();
1874
+ }
1875
+ return ReserveAssetDataEvent.cachedBcs;
1876
+ }
1877
+ static fromFields(fields) {
1878
+ return ReserveAssetDataEvent.reified().new({
1879
+ lendingMarketId: decodeFromFields('address', fields.lending_market_id),
908
1880
  coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
909
- config: decodeFromFields(Cell.reified(ReserveConfig.reified()), fields.config),
910
- mintDecimals: decodeFromFields("u8", fields.mint_decimals),
911
- priceIdentifier: decodeFromFields(PriceIdentifier.reified(), fields.price_identifier),
912
- price: decodeFromFields(Decimal.reified(), fields.price),
913
- smoothedPrice: decodeFromFields(Decimal.reified(), fields.smoothed_price),
914
- priceLastUpdateTimestampS: decodeFromFields("u64", fields.price_last_update_timestamp_s),
915
- availableAmount: decodeFromFields("u64", fields.available_amount),
916
- ctokenSupply: decodeFromFields("u64", fields.ctoken_supply),
1881
+ reserveId: decodeFromFields('address', fields.reserve_id),
1882
+ availableAmount: decodeFromFields(Decimal.reified(), fields.available_amount),
1883
+ supplyAmount: decodeFromFields(Decimal.reified(), fields.supply_amount),
917
1884
  borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
1885
+ availableAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.available_amount_usd_estimate),
1886
+ supplyAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.supply_amount_usd_estimate),
1887
+ borrowedAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.borrowed_amount_usd_estimate),
1888
+ borrowApr: decodeFromFields(Decimal.reified(), fields.borrow_apr),
1889
+ supplyApr: decodeFromFields(Decimal.reified(), fields.supply_apr),
1890
+ ctokenSupply: decodeFromFields('u64', fields.ctoken_supply),
918
1891
  cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
919
- interestLastUpdateTimestampS: decodeFromFields("u64", fields.interest_last_update_timestamp_s),
920
- unclaimedSpreadFees: decodeFromFields(Decimal.reified(), fields.unclaimed_spread_fees),
921
- attributedBorrowValue: decodeFromFields(Decimal.reified(), fields.attributed_borrow_value),
922
- depositsPoolRewardManager: decodeFromFields(PoolRewardManager.reified(), fields.deposits_pool_reward_manager),
923
- borrowsPoolRewardManager: decodeFromFields(PoolRewardManager.reified(), fields.borrows_pool_reward_manager),
1892
+ price: decodeFromFields(Decimal.reified(), fields.price),
1893
+ smoothedPrice: decodeFromFields(Decimal.reified(), fields.smoothed_price),
1894
+ priceLastUpdateTimestampS: decodeFromFields('u64', fields.price_last_update_timestamp_s),
924
1895
  });
925
1896
  }
926
- static fromFieldsWithTypes(typeArg, item) {
927
- if (!isReserve(item.type)) {
928
- throw new Error("not a Reserve type");
1897
+ static fromFieldsWithTypes(item) {
1898
+ if (!isReserveAssetDataEvent(item.type)) {
1899
+ throw new Error('not a ReserveAssetDataEvent type');
929
1900
  }
930
- assertFieldsWithTypesArgsMatch(item, [typeArg]);
931
- return Reserve.reified(typeArg).new({
932
- id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id),
933
- lendingMarketId: decodeFromFieldsWithTypes(ID.reified(), item.fields.lending_market_id),
934
- arrayIndex: decodeFromFieldsWithTypes("u64", item.fields.array_index),
1901
+ return ReserveAssetDataEvent.reified().new({
1902
+ lendingMarketId: decodeFromFieldsWithTypes('address', item.fields.lending_market_id),
935
1903
  coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
936
- config: decodeFromFieldsWithTypes(Cell.reified(ReserveConfig.reified()), item.fields.config),
937
- mintDecimals: decodeFromFieldsWithTypes("u8", item.fields.mint_decimals),
938
- priceIdentifier: decodeFromFieldsWithTypes(PriceIdentifier.reified(), item.fields.price_identifier),
939
- price: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.price),
940
- smoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price),
941
- priceLastUpdateTimestampS: decodeFromFieldsWithTypes("u64", item.fields.price_last_update_timestamp_s),
942
- availableAmount: decodeFromFieldsWithTypes("u64", item.fields.available_amount),
943
- ctokenSupply: decodeFromFieldsWithTypes("u64", item.fields.ctoken_supply),
1904
+ reserveId: decodeFromFieldsWithTypes('address', item.fields.reserve_id),
1905
+ availableAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.available_amount),
1906
+ supplyAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_amount),
944
1907
  borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
1908
+ availableAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.available_amount_usd_estimate),
1909
+ supplyAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_amount_usd_estimate),
1910
+ borrowedAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount_usd_estimate),
1911
+ borrowApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrow_apr),
1912
+ supplyApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_apr),
1913
+ ctokenSupply: decodeFromFieldsWithTypes('u64', item.fields.ctoken_supply),
945
1914
  cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
946
- interestLastUpdateTimestampS: decodeFromFieldsWithTypes("u64", item.fields.interest_last_update_timestamp_s),
947
- unclaimedSpreadFees: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.unclaimed_spread_fees),
948
- attributedBorrowValue: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.attributed_borrow_value),
949
- depositsPoolRewardManager: decodeFromFieldsWithTypes(PoolRewardManager.reified(), item.fields.deposits_pool_reward_manager),
950
- borrowsPoolRewardManager: decodeFromFieldsWithTypes(PoolRewardManager.reified(), item.fields.borrows_pool_reward_manager),
1915
+ price: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.price),
1916
+ smoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price),
1917
+ priceLastUpdateTimestampS: decodeFromFieldsWithTypes('u64', item.fields.price_last_update_timestamp_s),
951
1918
  });
952
1919
  }
953
- static fromBcs(typeArg, data) {
954
- return Reserve.fromFields(typeArg, Reserve.bcs.parse(data));
1920
+ static fromBcs(data) {
1921
+ return ReserveAssetDataEvent.fromFields(ReserveAssetDataEvent.bcs.parse(data));
955
1922
  }
956
1923
  toJSONField() {
957
1924
  return {
958
- id: this.id,
959
1925
  lendingMarketId: this.lendingMarketId,
960
- arrayIndex: this.arrayIndex.toString(),
961
- coinType: this.coinType.toJSONField(),
962
- config: this.config.toJSONField(),
963
- mintDecimals: this.mintDecimals,
964
- priceIdentifier: this.priceIdentifier.toJSONField(),
1926
+ coinType: this.coinType,
1927
+ reserveId: this.reserveId,
1928
+ availableAmount: this.availableAmount.toJSONField(),
1929
+ supplyAmount: this.supplyAmount.toJSONField(),
1930
+ borrowedAmount: this.borrowedAmount.toJSONField(),
1931
+ availableAmountUsdEstimate: this.availableAmountUsdEstimate.toJSONField(),
1932
+ supplyAmountUsdEstimate: this.supplyAmountUsdEstimate.toJSONField(),
1933
+ borrowedAmountUsdEstimate: this.borrowedAmountUsdEstimate.toJSONField(),
1934
+ borrowApr: this.borrowApr.toJSONField(),
1935
+ supplyApr: this.supplyApr.toJSONField(),
1936
+ ctokenSupply: this.ctokenSupply.toString(),
1937
+ cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
965
1938
  price: this.price.toJSONField(),
966
1939
  smoothedPrice: this.smoothedPrice.toJSONField(),
967
1940
  priceLastUpdateTimestampS: this.priceLastUpdateTimestampS.toString(),
968
- availableAmount: this.availableAmount.toString(),
969
- ctokenSupply: this.ctokenSupply.toString(),
970
- borrowedAmount: this.borrowedAmount.toJSONField(),
971
- cumulativeBorrowRate: this.cumulativeBorrowRate.toJSONField(),
972
- interestLastUpdateTimestampS: this.interestLastUpdateTimestampS.toString(),
973
- unclaimedSpreadFees: this.unclaimedSpreadFees.toJSONField(),
974
- attributedBorrowValue: this.attributedBorrowValue.toJSONField(),
975
- depositsPoolRewardManager: this.depositsPoolRewardManager.toJSONField(),
976
- borrowsPoolRewardManager: this.borrowsPoolRewardManager.toJSONField(),
977
1941
  };
978
1942
  }
979
1943
  toJSON() {
980
- return {
981
- $typeName: this.$typeName,
982
- $typeArgs: this.$typeArgs,
983
- ...this.toJSONField(),
984
- };
1944
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
985
1945
  }
986
- static fromJSONField(typeArg, field) {
987
- return Reserve.reified(typeArg).new({
988
- id: decodeFromJSONField(UID.reified(), field.id),
989
- lendingMarketId: decodeFromJSONField(ID.reified(), field.lendingMarketId),
990
- arrayIndex: decodeFromJSONField("u64", field.arrayIndex),
1946
+ static fromJSONField(field) {
1947
+ return ReserveAssetDataEvent.reified().new({
1948
+ lendingMarketId: decodeFromJSONField('address', field.lendingMarketId),
991
1949
  coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
992
- config: decodeFromJSONField(Cell.reified(ReserveConfig.reified()), field.config),
993
- mintDecimals: decodeFromJSONField("u8", field.mintDecimals),
994
- priceIdentifier: decodeFromJSONField(PriceIdentifier.reified(), field.priceIdentifier),
995
- price: decodeFromJSONField(Decimal.reified(), field.price),
996
- smoothedPrice: decodeFromJSONField(Decimal.reified(), field.smoothedPrice),
997
- priceLastUpdateTimestampS: decodeFromJSONField("u64", field.priceLastUpdateTimestampS),
998
- availableAmount: decodeFromJSONField("u64", field.availableAmount),
999
- ctokenSupply: decodeFromJSONField("u64", field.ctokenSupply),
1950
+ reserveId: decodeFromJSONField('address', field.reserveId),
1951
+ availableAmount: decodeFromJSONField(Decimal.reified(), field.availableAmount),
1952
+ supplyAmount: decodeFromJSONField(Decimal.reified(), field.supplyAmount),
1000
1953
  borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
1954
+ availableAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.availableAmountUsdEstimate),
1955
+ supplyAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.supplyAmountUsdEstimate),
1956
+ borrowedAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.borrowedAmountUsdEstimate),
1957
+ borrowApr: decodeFromJSONField(Decimal.reified(), field.borrowApr),
1958
+ supplyApr: decodeFromJSONField(Decimal.reified(), field.supplyApr),
1959
+ ctokenSupply: decodeFromJSONField('u64', field.ctokenSupply),
1001
1960
  cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
1002
- interestLastUpdateTimestampS: decodeFromJSONField("u64", field.interestLastUpdateTimestampS),
1003
- unclaimedSpreadFees: decodeFromJSONField(Decimal.reified(), field.unclaimedSpreadFees),
1004
- attributedBorrowValue: decodeFromJSONField(Decimal.reified(), field.attributedBorrowValue),
1005
- depositsPoolRewardManager: decodeFromJSONField(PoolRewardManager.reified(), field.depositsPoolRewardManager),
1006
- borrowsPoolRewardManager: decodeFromJSONField(PoolRewardManager.reified(), field.borrowsPoolRewardManager),
1961
+ price: decodeFromJSONField(Decimal.reified(), field.price),
1962
+ smoothedPrice: decodeFromJSONField(Decimal.reified(), field.smoothedPrice),
1963
+ priceLastUpdateTimestampS: decodeFromJSONField('u64', field.priceLastUpdateTimestampS),
1007
1964
  });
1008
1965
  }
1009
- static fromJSON(typeArg, json) {
1010
- if (json.$typeName !== Reserve.$typeName) {
1011
- throw new Error("not a WithTwoGenerics json object");
1966
+ static fromJSON(json) {
1967
+ if (json.$typeName !== ReserveAssetDataEvent.$typeName) {
1968
+ throw new Error(`not a ReserveAssetDataEvent json object: expected '${ReserveAssetDataEvent.$typeName}' but got '${json.$typeName}'`);
1012
1969
  }
1013
- assertReifiedTypeArgsMatch(composeSuiType(Reserve.$typeName, extractType(typeArg)), json.$typeArgs, [typeArg]);
1014
- return Reserve.fromJSONField(typeArg, json);
1970
+ return ReserveAssetDataEvent.fromJSONField(json);
1015
1971
  }
1016
- static async fetch(client, typeArg, id) {
1017
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
1018
- if (!isReserve(object.type)) {
1019
- throw new Error(`object at id ${id} is not a Reserve object`);
1972
+ static fromCoreObject(obj) {
1973
+ if (!isReserveAssetDataEvent(obj.type)) {
1974
+ throw new Error(`object at ${obj.objectId} is not a ReserveAssetDataEvent object`);
1020
1975
  }
1021
- return Reserve.fromBcs(typeArg, object.content);
1976
+ return ReserveAssetDataEvent.fromBcs(obj.content);
1977
+ }
1978
+ static async fetch(client, id) {
1979
+ const { object } = await client.core.getObject({
1980
+ objectId: id,
1981
+ include: { content: true },
1982
+ });
1983
+ if (!isReserveAssetDataEvent(object.type)) {
1984
+ throw new Error(`object at id ${id} is not a ReserveAssetDataEvent object`);
1985
+ }
1986
+ return ReserveAssetDataEvent.fromBcs(object.content);
1022
1987
  }
1023
1988
  }
1024
- /* ============================== ReserveAssetDataEvent =============================== */
1025
- export function isReserveAssetDataEvent(type) {
1989
+ /* ============================== ReserveAssetDataEventV2 =============================== */
1990
+ export function isReserveAssetDataEventV2(type) {
1026
1991
  type = compressSuiType(type);
1027
- return type === `${PKG_V1}::reserve::ReserveAssetDataEvent`;
1992
+ return type
1993
+ === `${getTypeOrigin('suilend', 'reserve::ReserveAssetDataEventV2')}::reserve::ReserveAssetDataEventV2`;
1028
1994
  }
1029
- export class ReserveAssetDataEvent {
1995
+ export class ReserveAssetDataEventV2 {
1030
1996
  __StructClass = true;
1031
- static $typeName = `${PKG_V1}::reserve::ReserveAssetDataEvent`;
1997
+ static get $typeName() {
1998
+ return `${getTypeOrigin('suilend', 'reserve::ReserveAssetDataEventV2')}::reserve::ReserveAssetDataEventV2`;
1999
+ }
1032
2000
  static $numTypeParams = 0;
1033
2001
  static $isPhantom = [];
1034
- $typeName = ReserveAssetDataEvent.$typeName;
2002
+ $typeName = ReserveAssetDataEventV2.$typeName;
1035
2003
  $fullTypeName;
1036
2004
  $typeArgs;
1037
- $isPhantom = ReserveAssetDataEvent.$isPhantom;
2005
+ $isPhantom = ReserveAssetDataEventV2.$isPhantom;
1038
2006
  lendingMarketId;
1039
2007
  coinType;
1040
2008
  reserveId;
@@ -1051,8 +2019,9 @@ export class ReserveAssetDataEvent {
1051
2019
  price;
1052
2020
  smoothedPrice;
1053
2021
  priceLastUpdateTimestampS;
2022
+ conf;
1054
2023
  constructor(typeArgs, fields) {
1055
- this.$fullTypeName = composeSuiType(ReserveAssetDataEvent.$typeName, ...typeArgs);
2024
+ this.$fullTypeName = composeSuiType(ReserveAssetDataEventV2.$typeName, ...typeArgs);
1056
2025
  this.$typeArgs = typeArgs;
1057
2026
  this.lendingMarketId = fields.lendingMarketId;
1058
2027
  this.coinType = fields.coinType;
@@ -1070,48 +2039,51 @@ export class ReserveAssetDataEvent {
1070
2039
  this.price = fields.price;
1071
2040
  this.smoothedPrice = fields.smoothedPrice;
1072
2041
  this.priceLastUpdateTimestampS = fields.priceLastUpdateTimestampS;
2042
+ this.conf = fields.conf;
1073
2043
  }
1074
2044
  static reified() {
2045
+ const reifiedBcs = ReserveAssetDataEventV2.bcs;
1075
2046
  return {
1076
- typeName: ReserveAssetDataEvent.$typeName,
1077
- fullTypeName: composeSuiType(ReserveAssetDataEvent.$typeName, ...[]),
2047
+ get typeName() {
2048
+ return ReserveAssetDataEventV2.$typeName;
2049
+ },
2050
+ get fullTypeName() {
2051
+ return composeSuiType(ReserveAssetDataEventV2.$typeName, ...[]);
2052
+ },
1078
2053
  typeArgs: [],
1079
- isPhantom: ReserveAssetDataEvent.$isPhantom,
2054
+ isPhantom: ReserveAssetDataEventV2.$isPhantom,
1080
2055
  reifiedTypeArgs: [],
1081
- fromFields: (fields) => ReserveAssetDataEvent.fromFields(fields),
1082
- fromFieldsWithTypes: (item) => ReserveAssetDataEvent.fromFieldsWithTypes(item),
1083
- fromBcs: (data) => ReserveAssetDataEvent.fromBcs(data),
1084
- bcs: ReserveAssetDataEvent.bcs,
1085
- fromJSONField: (field) => ReserveAssetDataEvent.fromJSONField(field),
1086
- fromJSON: (json) => ReserveAssetDataEvent.fromJSON(json),
1087
- fetch: async (client, id) => ReserveAssetDataEvent.fetch(client, id),
2056
+ fromFields: (fields) => ReserveAssetDataEventV2.fromFields(fields),
2057
+ fromFieldsWithTypes: (item) => ReserveAssetDataEventV2.fromFieldsWithTypes(item),
2058
+ fromBcs: (data) => ReserveAssetDataEventV2.fromFields(reifiedBcs.parse(data)),
2059
+ bcs: reifiedBcs,
2060
+ fromJSONField: (field) => ReserveAssetDataEventV2.fromJSONField(field),
2061
+ fromJSON: (json) => ReserveAssetDataEventV2.fromJSON(json),
2062
+ fromCoreObject: (obj) => ReserveAssetDataEventV2.fromCoreObject(obj),
2063
+ fetch: async (client, id) => ReserveAssetDataEventV2.fetch(client, id),
1088
2064
  new: (fields) => {
1089
- return new ReserveAssetDataEvent([], fields);
2065
+ return new ReserveAssetDataEventV2([], fields);
1090
2066
  },
1091
- kind: "StructClassReified",
2067
+ kind: 'StructClassReified',
1092
2068
  };
1093
2069
  }
1094
2070
  static get r() {
1095
- return ReserveAssetDataEvent.reified();
2071
+ return ReserveAssetDataEventV2.reified();
1096
2072
  }
1097
2073
  static phantom() {
1098
- return phantom(ReserveAssetDataEvent.reified());
2074
+ return phantom(ReserveAssetDataEventV2.reified());
1099
2075
  }
1100
2076
  static get p() {
1101
- return ReserveAssetDataEvent.phantom();
2077
+ return ReserveAssetDataEventV2.phantom();
1102
2078
  }
1103
- static get bcs() {
1104
- return bcs.struct("ReserveAssetDataEvent", {
1105
- lending_market_id: bcs
1106
- .bytes(32)
1107
- .transform({
2079
+ static instantiateBcs() {
2080
+ return bcs.struct('ReserveAssetDataEventV2', {
2081
+ lending_market_id: bcs.bytes(32).transform({
1108
2082
  input: (val) => fromHex(val),
1109
2083
  output: (val) => toHex(val),
1110
2084
  }),
1111
2085
  coin_type: TypeName.bcs,
1112
- reserve_id: bcs
1113
- .bytes(32)
1114
- .transform({
2086
+ reserve_id: bcs.bytes(32).transform({
1115
2087
  input: (val) => fromHex(val),
1116
2088
  output: (val) => toHex(val),
1117
2089
  }),
@@ -1128,13 +2100,21 @@ export class ReserveAssetDataEvent {
1128
2100
  price: Decimal.bcs,
1129
2101
  smoothed_price: Decimal.bcs,
1130
2102
  price_last_update_timestamp_s: bcs.u64(),
2103
+ conf: Decimal.bcs,
1131
2104
  });
1132
2105
  }
2106
+ static cachedBcs = null;
2107
+ static get bcs() {
2108
+ if (!ReserveAssetDataEventV2.cachedBcs) {
2109
+ ReserveAssetDataEventV2.cachedBcs = ReserveAssetDataEventV2.instantiateBcs();
2110
+ }
2111
+ return ReserveAssetDataEventV2.cachedBcs;
2112
+ }
1133
2113
  static fromFields(fields) {
1134
- return ReserveAssetDataEvent.reified().new({
1135
- lendingMarketId: decodeFromFields("address", fields.lending_market_id),
2114
+ return ReserveAssetDataEventV2.reified().new({
2115
+ lendingMarketId: decodeFromFields('address', fields.lending_market_id),
1136
2116
  coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
1137
- reserveId: decodeFromFields("address", fields.reserve_id),
2117
+ reserveId: decodeFromFields('address', fields.reserve_id),
1138
2118
  availableAmount: decodeFromFields(Decimal.reified(), fields.available_amount),
1139
2119
  supplyAmount: decodeFromFields(Decimal.reified(), fields.supply_amount),
1140
2120
  borrowedAmount: decodeFromFields(Decimal.reified(), fields.borrowed_amount),
@@ -1143,21 +2123,22 @@ export class ReserveAssetDataEvent {
1143
2123
  borrowedAmountUsdEstimate: decodeFromFields(Decimal.reified(), fields.borrowed_amount_usd_estimate),
1144
2124
  borrowApr: decodeFromFields(Decimal.reified(), fields.borrow_apr),
1145
2125
  supplyApr: decodeFromFields(Decimal.reified(), fields.supply_apr),
1146
- ctokenSupply: decodeFromFields("u64", fields.ctoken_supply),
2126
+ ctokenSupply: decodeFromFields('u64', fields.ctoken_supply),
1147
2127
  cumulativeBorrowRate: decodeFromFields(Decimal.reified(), fields.cumulative_borrow_rate),
1148
2128
  price: decodeFromFields(Decimal.reified(), fields.price),
1149
2129
  smoothedPrice: decodeFromFields(Decimal.reified(), fields.smoothed_price),
1150
- priceLastUpdateTimestampS: decodeFromFields("u64", fields.price_last_update_timestamp_s),
2130
+ priceLastUpdateTimestampS: decodeFromFields('u64', fields.price_last_update_timestamp_s),
2131
+ conf: decodeFromFields(Decimal.reified(), fields.conf),
1151
2132
  });
1152
2133
  }
1153
2134
  static fromFieldsWithTypes(item) {
1154
- if (!isReserveAssetDataEvent(item.type)) {
1155
- throw new Error("not a ReserveAssetDataEvent type");
2135
+ if (!isReserveAssetDataEventV2(item.type)) {
2136
+ throw new Error('not a ReserveAssetDataEventV2 type');
1156
2137
  }
1157
- return ReserveAssetDataEvent.reified().new({
1158
- lendingMarketId: decodeFromFieldsWithTypes("address", item.fields.lending_market_id),
2138
+ return ReserveAssetDataEventV2.reified().new({
2139
+ lendingMarketId: decodeFromFieldsWithTypes('address', item.fields.lending_market_id),
1159
2140
  coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
1160
- reserveId: decodeFromFieldsWithTypes("address", item.fields.reserve_id),
2141
+ reserveId: decodeFromFieldsWithTypes('address', item.fields.reserve_id),
1161
2142
  availableAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.available_amount),
1162
2143
  supplyAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_amount),
1163
2144
  borrowedAmount: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount),
@@ -1166,20 +2147,21 @@ export class ReserveAssetDataEvent {
1166
2147
  borrowedAmountUsdEstimate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrowed_amount_usd_estimate),
1167
2148
  borrowApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.borrow_apr),
1168
2149
  supplyApr: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.supply_apr),
1169
- ctokenSupply: decodeFromFieldsWithTypes("u64", item.fields.ctoken_supply),
2150
+ ctokenSupply: decodeFromFieldsWithTypes('u64', item.fields.ctoken_supply),
1170
2151
  cumulativeBorrowRate: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.cumulative_borrow_rate),
1171
2152
  price: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.price),
1172
2153
  smoothedPrice: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.smoothed_price),
1173
- priceLastUpdateTimestampS: decodeFromFieldsWithTypes("u64", item.fields.price_last_update_timestamp_s),
2154
+ priceLastUpdateTimestampS: decodeFromFieldsWithTypes('u64', item.fields.price_last_update_timestamp_s),
2155
+ conf: decodeFromFieldsWithTypes(Decimal.reified(), item.fields.conf),
1174
2156
  });
1175
2157
  }
1176
2158
  static fromBcs(data) {
1177
- return ReserveAssetDataEvent.fromFields(ReserveAssetDataEvent.bcs.parse(data));
2159
+ return ReserveAssetDataEventV2.fromFields(ReserveAssetDataEventV2.bcs.parse(data));
1178
2160
  }
1179
2161
  toJSONField() {
1180
2162
  return {
1181
2163
  lendingMarketId: this.lendingMarketId,
1182
- coinType: this.coinType.toJSONField(),
2164
+ coinType: this.coinType,
1183
2165
  reserveId: this.reserveId,
1184
2166
  availableAmount: this.availableAmount.toJSONField(),
1185
2167
  supplyAmount: this.supplyAmount.toJSONField(),
@@ -1194,20 +2176,17 @@ export class ReserveAssetDataEvent {
1194
2176
  price: this.price.toJSONField(),
1195
2177
  smoothedPrice: this.smoothedPrice.toJSONField(),
1196
2178
  priceLastUpdateTimestampS: this.priceLastUpdateTimestampS.toString(),
2179
+ conf: this.conf.toJSONField(),
1197
2180
  };
1198
2181
  }
1199
2182
  toJSON() {
1200
- return {
1201
- $typeName: this.$typeName,
1202
- $typeArgs: this.$typeArgs,
1203
- ...this.toJSONField(),
1204
- };
2183
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
1205
2184
  }
1206
2185
  static fromJSONField(field) {
1207
- return ReserveAssetDataEvent.reified().new({
1208
- lendingMarketId: decodeFromJSONField("address", field.lendingMarketId),
2186
+ return ReserveAssetDataEventV2.reified().new({
2187
+ lendingMarketId: decodeFromJSONField('address', field.lendingMarketId),
1209
2188
  coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
1210
- reserveId: decodeFromJSONField("address", field.reserveId),
2189
+ reserveId: decodeFromJSONField('address', field.reserveId),
1211
2190
  availableAmount: decodeFromJSONField(Decimal.reified(), field.availableAmount),
1212
2191
  supplyAmount: decodeFromJSONField(Decimal.reified(), field.supplyAmount),
1213
2192
  borrowedAmount: decodeFromJSONField(Decimal.reified(), field.borrowedAmount),
@@ -1216,125 +2195,183 @@ export class ReserveAssetDataEvent {
1216
2195
  borrowedAmountUsdEstimate: decodeFromJSONField(Decimal.reified(), field.borrowedAmountUsdEstimate),
1217
2196
  borrowApr: decodeFromJSONField(Decimal.reified(), field.borrowApr),
1218
2197
  supplyApr: decodeFromJSONField(Decimal.reified(), field.supplyApr),
1219
- ctokenSupply: decodeFromJSONField("u64", field.ctokenSupply),
2198
+ ctokenSupply: decodeFromJSONField('u64', field.ctokenSupply),
1220
2199
  cumulativeBorrowRate: decodeFromJSONField(Decimal.reified(), field.cumulativeBorrowRate),
1221
2200
  price: decodeFromJSONField(Decimal.reified(), field.price),
1222
2201
  smoothedPrice: decodeFromJSONField(Decimal.reified(), field.smoothedPrice),
1223
- priceLastUpdateTimestampS: decodeFromJSONField("u64", field.priceLastUpdateTimestampS),
2202
+ priceLastUpdateTimestampS: decodeFromJSONField('u64', field.priceLastUpdateTimestampS),
2203
+ conf: decodeFromJSONField(Decimal.reified(), field.conf),
1224
2204
  });
1225
2205
  }
1226
2206
  static fromJSON(json) {
1227
- if (json.$typeName !== ReserveAssetDataEvent.$typeName) {
1228
- throw new Error("not a WithTwoGenerics json object");
2207
+ if (json.$typeName !== ReserveAssetDataEventV2.$typeName) {
2208
+ throw new Error(`not a ReserveAssetDataEventV2 json object: expected '${ReserveAssetDataEventV2.$typeName}' but got '${json.$typeName}'`);
1229
2209
  }
1230
- return ReserveAssetDataEvent.fromJSONField(json);
2210
+ return ReserveAssetDataEventV2.fromJSONField(json);
2211
+ }
2212
+ static fromCoreObject(obj) {
2213
+ if (!isReserveAssetDataEventV2(obj.type)) {
2214
+ throw new Error(`object at ${obj.objectId} is not a ReserveAssetDataEventV2 object`);
2215
+ }
2216
+ return ReserveAssetDataEventV2.fromBcs(obj.content);
1231
2217
  }
1232
2218
  static async fetch(client, id) {
1233
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
1234
- if (!isReserveAssetDataEvent(object.type)) {
1235
- throw new Error(`object at id ${id} is not a ReserveAssetDataEvent object`);
2219
+ const { object } = await client.core.getObject({
2220
+ objectId: id,
2221
+ include: { content: true },
2222
+ });
2223
+ if (!isReserveAssetDataEventV2(object.type)) {
2224
+ throw new Error(`object at id ${id} is not a ReserveAssetDataEventV2 object`);
1236
2225
  }
1237
- return ReserveAssetDataEvent.fromBcs(object.content);
2226
+ return ReserveAssetDataEventV2.fromBcs(object.content);
1238
2227
  }
1239
2228
  }
1240
- /* ============================== StakerKey =============================== */
1241
- export function isStakerKey(type) {
2229
+ /* ============================== ClaimStakingRewardsEvent =============================== */
2230
+ export function isClaimStakingRewardsEvent(type) {
1242
2231
  type = compressSuiType(type);
1243
- return type === `${PKG_V8}::reserve::StakerKey`;
2232
+ return type
2233
+ === `${getTypeOrigin('suilend', 'reserve::ClaimStakingRewardsEvent')}::reserve::ClaimStakingRewardsEvent`;
1244
2234
  }
1245
- export class StakerKey {
2235
+ export class ClaimStakingRewardsEvent {
1246
2236
  __StructClass = true;
1247
- static $typeName = `${PKG_V8}::reserve::StakerKey`;
2237
+ static get $typeName() {
2238
+ return `${getTypeOrigin('suilend', 'reserve::ClaimStakingRewardsEvent')}::reserve::ClaimStakingRewardsEvent`;
2239
+ }
1248
2240
  static $numTypeParams = 0;
1249
2241
  static $isPhantom = [];
1250
- $typeName = StakerKey.$typeName;
2242
+ $typeName = ClaimStakingRewardsEvent.$typeName;
1251
2243
  $fullTypeName;
1252
2244
  $typeArgs;
1253
- $isPhantom = StakerKey.$isPhantom;
1254
- dummyField;
2245
+ $isPhantom = ClaimStakingRewardsEvent.$isPhantom;
2246
+ lendingMarketId;
2247
+ coinType;
2248
+ reserveId;
2249
+ amount;
1255
2250
  constructor(typeArgs, fields) {
1256
- this.$fullTypeName = composeSuiType(StakerKey.$typeName, ...typeArgs);
2251
+ this.$fullTypeName = composeSuiType(ClaimStakingRewardsEvent.$typeName, ...typeArgs);
1257
2252
  this.$typeArgs = typeArgs;
1258
- this.dummyField = fields.dummyField;
2253
+ this.lendingMarketId = fields.lendingMarketId;
2254
+ this.coinType = fields.coinType;
2255
+ this.reserveId = fields.reserveId;
2256
+ this.amount = fields.amount;
1259
2257
  }
1260
2258
  static reified() {
2259
+ const reifiedBcs = ClaimStakingRewardsEvent.bcs;
1261
2260
  return {
1262
- typeName: StakerKey.$typeName,
1263
- fullTypeName: composeSuiType(StakerKey.$typeName, ...[]),
2261
+ get typeName() {
2262
+ return ClaimStakingRewardsEvent.$typeName;
2263
+ },
2264
+ get fullTypeName() {
2265
+ return composeSuiType(ClaimStakingRewardsEvent.$typeName, ...[]);
2266
+ },
1264
2267
  typeArgs: [],
1265
- isPhantom: StakerKey.$isPhantom,
2268
+ isPhantom: ClaimStakingRewardsEvent.$isPhantom,
1266
2269
  reifiedTypeArgs: [],
1267
- fromFields: (fields) => StakerKey.fromFields(fields),
1268
- fromFieldsWithTypes: (item) => StakerKey.fromFieldsWithTypes(item),
1269
- fromBcs: (data) => StakerKey.fromBcs(data),
1270
- bcs: StakerKey.bcs,
1271
- fromJSONField: (field) => StakerKey.fromJSONField(field),
1272
- fromJSON: (json) => StakerKey.fromJSON(json),
1273
- fetch: async (client, id) => StakerKey.fetch(client, id),
2270
+ fromFields: (fields) => ClaimStakingRewardsEvent.fromFields(fields),
2271
+ fromFieldsWithTypes: (item) => ClaimStakingRewardsEvent.fromFieldsWithTypes(item),
2272
+ fromBcs: (data) => ClaimStakingRewardsEvent.fromFields(reifiedBcs.parse(data)),
2273
+ bcs: reifiedBcs,
2274
+ fromJSONField: (field) => ClaimStakingRewardsEvent.fromJSONField(field),
2275
+ fromJSON: (json) => ClaimStakingRewardsEvent.fromJSON(json),
2276
+ fromCoreObject: (obj) => ClaimStakingRewardsEvent.fromCoreObject(obj),
2277
+ fetch: async (client, id) => ClaimStakingRewardsEvent.fetch(client, id),
1274
2278
  new: (fields) => {
1275
- return new StakerKey([], fields);
2279
+ return new ClaimStakingRewardsEvent([], fields);
1276
2280
  },
1277
- kind: "StructClassReified",
2281
+ kind: 'StructClassReified',
1278
2282
  };
1279
2283
  }
1280
2284
  static get r() {
1281
- return StakerKey.reified();
2285
+ return ClaimStakingRewardsEvent.reified();
1282
2286
  }
1283
2287
  static phantom() {
1284
- return phantom(StakerKey.reified());
2288
+ return phantom(ClaimStakingRewardsEvent.reified());
1285
2289
  }
1286
2290
  static get p() {
1287
- return StakerKey.phantom();
2291
+ return ClaimStakingRewardsEvent.phantom();
1288
2292
  }
1289
- static get bcs() {
1290
- return bcs.struct("StakerKey", {
1291
- dummy_field: bcs.bool(),
2293
+ static instantiateBcs() {
2294
+ return bcs.struct('ClaimStakingRewardsEvent', {
2295
+ lending_market_id: bcs.bytes(32).transform({
2296
+ input: (val) => fromHex(val),
2297
+ output: (val) => toHex(val),
2298
+ }),
2299
+ coin_type: TypeName.bcs,
2300
+ reserve_id: bcs.bytes(32).transform({
2301
+ input: (val) => fromHex(val),
2302
+ output: (val) => toHex(val),
2303
+ }),
2304
+ amount: bcs.u64(),
1292
2305
  });
1293
2306
  }
2307
+ static cachedBcs = null;
2308
+ static get bcs() {
2309
+ if (!ClaimStakingRewardsEvent.cachedBcs) {
2310
+ ClaimStakingRewardsEvent.cachedBcs = ClaimStakingRewardsEvent.instantiateBcs();
2311
+ }
2312
+ return ClaimStakingRewardsEvent.cachedBcs;
2313
+ }
1294
2314
  static fromFields(fields) {
1295
- return StakerKey.reified().new({
1296
- dummyField: decodeFromFields("bool", fields.dummy_field),
2315
+ return ClaimStakingRewardsEvent.reified().new({
2316
+ lendingMarketId: decodeFromFields('address', fields.lending_market_id),
2317
+ coinType: decodeFromFields(TypeName.reified(), fields.coin_type),
2318
+ reserveId: decodeFromFields('address', fields.reserve_id),
2319
+ amount: decodeFromFields('u64', fields.amount),
1297
2320
  });
1298
2321
  }
1299
2322
  static fromFieldsWithTypes(item) {
1300
- if (!isStakerKey(item.type)) {
1301
- throw new Error("not a StakerKey type");
2323
+ if (!isClaimStakingRewardsEvent(item.type)) {
2324
+ throw new Error('not a ClaimStakingRewardsEvent type');
1302
2325
  }
1303
- return StakerKey.reified().new({
1304
- dummyField: decodeFromFieldsWithTypes("bool", item.fields.dummy_field),
2326
+ return ClaimStakingRewardsEvent.reified().new({
2327
+ lendingMarketId: decodeFromFieldsWithTypes('address', item.fields.lending_market_id),
2328
+ coinType: decodeFromFieldsWithTypes(TypeName.reified(), item.fields.coin_type),
2329
+ reserveId: decodeFromFieldsWithTypes('address', item.fields.reserve_id),
2330
+ amount: decodeFromFieldsWithTypes('u64', item.fields.amount),
1305
2331
  });
1306
2332
  }
1307
2333
  static fromBcs(data) {
1308
- return StakerKey.fromFields(StakerKey.bcs.parse(data));
2334
+ return ClaimStakingRewardsEvent.fromFields(ClaimStakingRewardsEvent.bcs.parse(data));
1309
2335
  }
1310
2336
  toJSONField() {
1311
2337
  return {
1312
- dummyField: this.dummyField,
2338
+ lendingMarketId: this.lendingMarketId,
2339
+ coinType: this.coinType,
2340
+ reserveId: this.reserveId,
2341
+ amount: this.amount.toString(),
1313
2342
  };
1314
2343
  }
1315
2344
  toJSON() {
1316
- return {
1317
- $typeName: this.$typeName,
1318
- $typeArgs: this.$typeArgs,
1319
- ...this.toJSONField(),
1320
- };
2345
+ return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() };
1321
2346
  }
1322
2347
  static fromJSONField(field) {
1323
- return StakerKey.reified().new({
1324
- dummyField: decodeFromJSONField("bool", field.dummyField),
2348
+ return ClaimStakingRewardsEvent.reified().new({
2349
+ lendingMarketId: decodeFromJSONField('address', field.lendingMarketId),
2350
+ coinType: decodeFromJSONField(TypeName.reified(), field.coinType),
2351
+ reserveId: decodeFromJSONField('address', field.reserveId),
2352
+ amount: decodeFromJSONField('u64', field.amount),
1325
2353
  });
1326
2354
  }
1327
2355
  static fromJSON(json) {
1328
- if (json.$typeName !== StakerKey.$typeName) {
1329
- throw new Error("not a WithTwoGenerics json object");
2356
+ if (json.$typeName !== ClaimStakingRewardsEvent.$typeName) {
2357
+ throw new Error(`not a ClaimStakingRewardsEvent json object: expected '${ClaimStakingRewardsEvent.$typeName}' but got '${json.$typeName}'`);
1330
2358
  }
1331
- return StakerKey.fromJSONField(json);
2359
+ return ClaimStakingRewardsEvent.fromJSONField(json);
2360
+ }
2361
+ static fromCoreObject(obj) {
2362
+ if (!isClaimStakingRewardsEvent(obj.type)) {
2363
+ throw new Error(`object at ${obj.objectId} is not a ClaimStakingRewardsEvent object`);
2364
+ }
2365
+ return ClaimStakingRewardsEvent.fromBcs(obj.content);
1332
2366
  }
1333
2367
  static async fetch(client, id) {
1334
- const { object } = await client.getObject({ objectId: id, include: { content: true } });
1335
- if (!isStakerKey(object.type)) {
1336
- throw new Error(`object at id ${id} is not a StakerKey object`);
2368
+ const { object } = await client.core.getObject({
2369
+ objectId: id,
2370
+ include: { content: true },
2371
+ });
2372
+ if (!isClaimStakingRewardsEvent(object.type)) {
2373
+ throw new Error(`object at id ${id} is not a ClaimStakingRewardsEvent object`);
1337
2374
  }
1338
- return StakerKey.fromBcs(object.content);
2375
+ return ClaimStakingRewardsEvent.fromBcs(object.content);
1339
2376
  }
1340
2377
  }