@naviprotocol/lending 2.0.0-beta.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,183 +1,330 @@
1
- import { Transaction as F } from "@mysten/sui/transactions";
2
- import { bcs as l } from "@mysten/sui/bcs";
3
- import { toHex as de, fromHex as me, SUI_CLOCK_OBJECT_ID as z, normalizeStructTag as fe } from "@mysten/sui/utils";
4
- import ye from "lodash.camelcase";
5
- import d from "bignumber.js";
6
- import { getJsonRpcFullnodeUrl as ge, SuiJsonRpcClient as he } from "@mysten/sui/jsonRpc";
7
- const Z = l.bytes(32).transform({
1
+ import { Transaction as N } from "@mysten/sui/transactions";
2
+ import { bcs as u } from "@mysten/sui/bcs";
3
+ import { toHex as $e, fromHex as Oe, normalizeStructTag as K, SUI_CLOCK_OBJECT_ID as Z, fromBase64 as Ee } from "@mysten/sui/utils";
4
+ import Ve from "lodash.camelcase";
5
+ import p from "bignumber.js";
6
+ import { SuiJsonRpcClient as Me } from "@mysten/sui/jsonRpc";
7
+ import { SuiGraphQLClient as De } from "@mysten/sui/graphql";
8
+ import { GrpcWebFetchTransport as Ue, SuiGrpcClient as Fe } from "@mysten/sui/grpc";
9
+ const ne = u.bytes(32).transform({
8
10
  // To change the input type, you need to provide a type definition for the input
9
- input: (e) => me(e),
10
- output: (e) => de(e)
11
- }), et = l.struct("IncentiveAPYInfo", {
11
+ input: (e) => Oe(e),
12
+ output: (e) => $e(e)
13
+ }), Rt = u.struct("IncentiveAPYInfo", {
12
14
  /** Asset identifier */
13
- asset_id: l.u8(),
15
+ asset_id: u.u8(),
14
16
  /** Annual Percentage Yield as a 256-bit integer */
15
- apy: l.u256(),
17
+ apy: u.u256(),
16
18
  /** List of supported coin types for this incentive */
17
- coin_types: l.vector(l.string())
18
- }), we = l.struct("IncentivePoolInfo", {
19
+ coin_types: u.vector(u.string())
20
+ }), Ne = u.struct("IncentivePoolInfo", {
19
21
  /** Unique pool identifier */
20
- pool_id: Z,
22
+ pool_id: ne,
21
23
  /** Address holding the incentive funds */
22
- funds: Z,
24
+ funds: ne,
23
25
  /** Current phase of the incentive program */
24
- phase: l.u64(),
26
+ phase: u.u64(),
25
27
  /** Timestamp when the incentive started */
26
- start_at: l.u64(),
28
+ start_at: u.u64(),
27
29
  /** Timestamp when the incentive ends */
28
- end_at: l.u64(),
30
+ end_at: u.u64(),
29
31
  /** Timestamp when the incentive was closed */
30
- closed_at: l.u64(),
32
+ closed_at: u.u64(),
31
33
  /** Total supply of incentive tokens */
32
- total_supply: l.u64(),
34
+ total_supply: u.u64(),
33
35
  /** Asset identifier for the incentive */
34
- asset_id: l.u8(),
36
+ asset_id: u.u8(),
35
37
  /** Option type for the incentive */
36
- option: l.u8(),
38
+ option: u.u8(),
37
39
  /** Factor used in incentive calculations */
38
- factor: l.u256(),
40
+ factor: u.u256(),
39
41
  /** Amount of incentives already distributed */
40
- distributed: l.u64(),
42
+ distributed: u.u64(),
41
43
  /** Amount of incentives currently available */
42
- available: l.u256(),
44
+ available: u.u256(),
43
45
  /** Total amount of incentives */
44
- total: l.u256()
45
- }), tt = l.struct("IncentivePoolInfoByPhase", {
46
+ total: u.u256()
47
+ }), Lt = u.struct("IncentivePoolInfoByPhase", {
46
48
  /** Phase number */
47
- phase: l.u64(),
49
+ phase: u.u64(),
48
50
  /** List of incentive pools in this phase */
49
- pools: l.vector(we)
50
- }), ot = l.struct("OracleInfo", {
51
+ pools: u.vector(Ne)
52
+ }), qt = u.struct("OracleInfo", {
51
53
  /** Oracle identifier */
52
- oracle_id: l.u8(),
54
+ oracle_id: u.u8(),
53
55
  /** Current price as a 256-bit integer */
54
- price: l.u256(),
56
+ price: u.u256(),
55
57
  /** Number of decimal places for the price */
56
- decimals: l.u8(),
58
+ decimals: u.u8(),
57
59
  /** Whether the oracle data is valid */
58
- valid: l.bool()
59
- }), rt = l.struct("FlashLoanAssetConfig", {
60
+ valid: u.bool()
61
+ }), zt = u.struct("FlashLoanAssetConfig", {
60
62
  /** Unique identifier for the flash loan asset */
61
- id: l.string(),
63
+ id: u.string(),
62
64
  /** Asset identifier */
63
- asset_id: l.u8(),
65
+ asset_id: u.u8(),
64
66
  /** Coin type for the asset */
65
- coin_type: l.string(),
67
+ coin_type: u.string(),
66
68
  /** Pool identifier for the flash loan */
67
- pool_id: l.string(),
69
+ pool_id: u.string(),
68
70
  /** Rate paid to suppliers for flash loans */
69
- rate_to_supplier: l.u64(),
71
+ rate_to_supplier: u.u64(),
70
72
  /** Rate paid to treasury for flash loans */
71
- rate_to_treasury: l.u64(),
73
+ rate_to_treasury: u.u64(),
72
74
  /** Maximum flash loan amount */
73
- max: l.u64(),
75
+ max: u.u64(),
74
76
  /** Minimum flash loan amount */
75
- min: l.u64()
76
- }), ve = l.struct("ReserveDataInfo", {
77
+ min: u.u64()
78
+ }), Re = u.struct("ReserveDataInfo", {
77
79
  /** Reserve identifier */
78
- id: l.u8(),
80
+ id: u.u8(),
79
81
  /** Oracle identifier for price feeds */
80
- oracle_id: l.u8(),
82
+ oracle_id: u.u8(),
81
83
  /** Coin type for the reserve */
82
- coin_type: l.string(),
84
+ coin_type: u.string(),
83
85
  /** Maximum supply capacity */
84
- supply_cap: l.u256(),
86
+ supply_cap: u.u256(),
85
87
  /** Maximum borrow capacity */
86
- borrow_cap: l.u256(),
88
+ borrow_cap: u.u256(),
87
89
  /** Current supply interest rate */
88
- supply_rate: l.u256(),
90
+ supply_rate: u.u256(),
89
91
  /** Current borrow interest rate */
90
- borrow_rate: l.u256(),
92
+ borrow_rate: u.u256(),
91
93
  /** Current supply index for interest calculation */
92
- supply_index: l.u256(),
94
+ supply_index: u.u256(),
93
95
  /** Current borrow index for interest calculation */
94
- borrow_index: l.u256(),
96
+ borrow_index: u.u256(),
95
97
  /** Total amount supplied to the reserve */
96
- total_supply: l.u256(),
98
+ total_supply: u.u256(),
97
99
  /** Total amount borrowed from the reserve */
98
- total_borrow: l.u256(),
100
+ total_borrow: u.u256(),
99
101
  /** Timestamp of last update */
100
- last_update_at: l.u64(),
102
+ last_update_at: u.u64(),
101
103
  /** Loan-to-Value ratio for collateral */
102
- ltv: l.u256(),
104
+ ltv: u.u256(),
103
105
  /** Treasury factor for fee calculations */
104
- treasury_factor: l.u256(),
106
+ treasury_factor: u.u256(),
105
107
  /** Current treasury balance */
106
- treasury_balance: l.u256(),
108
+ treasury_balance: u.u256(),
107
109
  /** Base interest rate */
108
- base_rate: l.u256(),
110
+ base_rate: u.u256(),
109
111
  /** Interest rate multiplier */
110
- multiplier: l.u256(),
112
+ multiplier: u.u256(),
111
113
  /** Jump rate multiplier for high utilization */
112
- jump_rate_multiplier: l.u256(),
114
+ jump_rate_multiplier: u.u256(),
113
115
  /** Reserve factor for protocol fees */
114
- reserve_factor: l.u256(),
116
+ reserve_factor: u.u256(),
115
117
  /** Optimal utilization rate */
116
- optimal_utilization: l.u256(),
118
+ optimal_utilization: u.u256(),
117
119
  /** Liquidation ratio threshold */
118
- liquidation_ratio: l.u256(),
120
+ liquidation_ratio: u.u256(),
119
121
  /** Liquidation bonus for liquidators */
120
- liquidation_bonus: l.u256(),
122
+ liquidation_bonus: u.u256(),
121
123
  /** Liquidation threshold */
122
- liquidation_threshold: l.u256()
123
- }), be = l.struct("UserStateInfo", {
124
+ liquidation_threshold: u.u256()
125
+ }), Le = u.struct("UserStateInfo", {
124
126
  /** Asset identifier */
125
- asset_id: l.u8(),
127
+ asset_id: u.u8(),
126
128
  /** User's current borrow balance */
127
- borrow_balance: l.u256(),
129
+ borrow_balance: u.u256(),
128
130
  /** User's current supply balance */
129
- supply_balance: l.u256()
130
- }), ke = "2.0.0-beta.0", M = {
131
- version: ke
132
- }, _e = M.version, je = () => {
131
+ supply_balance: u.u256()
132
+ }), qe = "2.0.0", O = {
133
+ version: qe
134
+ }, ze = O.version, Ge = () => {
133
135
  if (typeof process < "u" && process.versions && process.versions.node) {
134
136
  const e = process.version;
135
137
  return `Node.js ${e.startsWith("v") ? e.substring(1) : e}`;
136
138
  }
137
139
  return "Node/Unknown";
138
- }, Ie = () => {
140
+ }, We = () => {
139
141
  let e = "";
140
- return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${_e} (${je()})`), e;
141
- }, X = Ie();
142
- function Ce(e = ge("mainnet"), t = "mainnet") {
143
- return new he({
144
- network: t,
145
- url: e
142
+ return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${ze} (${Ge()})`), e;
143
+ }, oe = We(), me = "0x2::sui::SUI";
144
+ class He extends Error {
145
+ constructor(t) {
146
+ super(
147
+ `NAVI Sui SDK capability "${t}" requires an explicit graphql client; no public GraphQL fallback is configured`
148
+ ), this.name = "NaviMissingGraphQLClientError";
149
+ }
150
+ }
151
+ function X(e) {
152
+ return e == null ? void 0 : String(e);
153
+ }
154
+ function Je(e, t) {
155
+ return (BigInt(e) + BigInt(t)).toString();
156
+ }
157
+ function Ke(e, t) {
158
+ return (BigInt(e) - BigInt(t)).toString();
159
+ }
160
+ function fe(e) {
161
+ const t = e.core;
162
+ if (typeof t?.getBalance != "function" || typeof t?.listBalances != "function")
163
+ throw new Error("NAVI Sui balance helpers require a v2 Core API client");
164
+ return t;
165
+ }
166
+ function ye(e, t = me) {
167
+ const r = X(e.addressBalance ?? e.fundsInAddressBalance) ?? "0";
168
+ let o = X(e.balance ?? e.totalBalance), n = X(e.coinBalance);
169
+ return !n && o && (n = Ke(o, r)), !o && n && (o = Je(n, r)), {
170
+ coinType: K(e.coinType ?? t),
171
+ totalBalance: o ?? "0",
172
+ coinBalance: n ?? "0",
173
+ addressBalance: r,
174
+ ...e.coinObjectCount === null || e.coinObjectCount === void 0 ? {} : { coinObjectCount: e.coinObjectCount }
175
+ };
176
+ }
177
+ function Gt(e, t = me) {
178
+ const r = K(t);
179
+ return e.filter((o) => K(o.coinType) === r).reduce((o, n) => o + BigInt(n.balance), 0n).toString();
180
+ }
181
+ async function Wt(e, t) {
182
+ const r = await fe(e).getBalance(t), o = r.balance;
183
+ return ye((o && typeof o == "object" ? o : r) ?? {}, t.coinType);
184
+ }
185
+ async function Ht(e, t) {
186
+ const r = await fe(e).listBalances(t), { balances: o = [] } = r;
187
+ return {
188
+ balances: o.map((n) => ye(n)),
189
+ nextCursor: r.nextCursor ?? r.cursor ?? null
190
+ };
191
+ }
192
+ function Qe(e, t) {
193
+ if ("client" in t)
194
+ return t.client;
195
+ const r = new Ue({
196
+ baseUrl: t.url,
197
+ meta: t.headers,
198
+ fetchInit: t.fetchInit,
199
+ fetch: t.fetch
200
+ });
201
+ return new Fe({
202
+ network: e,
203
+ transport: r
204
+ });
205
+ }
206
+ function Ye(e, t) {
207
+ return "client" in t ? t.client : new De({
208
+ network: e,
209
+ url: t.url,
210
+ headers: t.headers,
211
+ fetch: t.fetch
212
+ });
213
+ }
214
+ function ge(e, t) {
215
+ return "client" in t ? t.client : new Me({
216
+ network: e,
217
+ url: t.url
146
218
  });
147
219
  }
148
- const Te = 16 * 1024;
149
- function J(e) {
220
+ function Ze(e) {
221
+ const t = Qe(e.network, e.grpc);
222
+ return {
223
+ network: e.network,
224
+ coreClient: t,
225
+ grpc: t,
226
+ graphql: e.graphql ? Ye(e.network, e.graphql) : void 0,
227
+ legacyJsonRpc: e.legacyJsonRpc ? ge(e.network, e.legacyJsonRpc) : void 0,
228
+ services: e.services
229
+ };
230
+ }
231
+ function Jt(e, t) {
232
+ if (!e.graphql)
233
+ throw new He(t);
234
+ return e.graphql;
235
+ }
236
+ function Xe() {
237
+ const e = "NAVI Sui SDK requires an explicit v2 gRPC/Core client. Pass { network, grpc } or an explicit legacyJsonRpc client for deprecated compatibility.", t = new Proxy(
238
+ {},
239
+ {
240
+ get() {
241
+ throw new Error(e);
242
+ }
243
+ }
244
+ );
245
+ return new Proxy(
246
+ { core: t },
247
+ {
248
+ get(r, o) {
249
+ if (o === "core")
250
+ return r.core;
251
+ if (o === "network")
252
+ return "mainnet";
253
+ throw new Error(e);
254
+ }
255
+ }
256
+ );
257
+ }
258
+ function xe(e, t = "mainnet") {
259
+ return e ? typeof e == "string" ? ge(t, { url: e }) : Ze(e) : Xe();
260
+ }
261
+ const et = 16 * 1024;
262
+ function te(e) {
150
263
  return e.replace(/^0x/i, "");
151
264
  }
152
- function Pe(e) {
153
- const t = J(e), r = new Uint8Array(t.length / 2);
154
- for (let n = 0; n < r.length; n += 1)
155
- r[n] = parseInt(t.slice(n * 2, n * 2 + 2), 16);
265
+ function ae(e) {
266
+ const t = te(e), r = new Uint8Array(t.length / 2);
267
+ for (let o = 0; o < r.length; o += 1)
268
+ r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
156
269
  return r;
157
270
  }
158
- function Be(e, t) {
271
+ function tt(e, t) {
159
272
  return (e[t] << 8) + e[t + 1];
160
273
  }
161
- function Q(e) {
162
- return l.vector(l.U8).serialize(Array.from(e), {
163
- maxSize: Te
274
+ function ie(e) {
275
+ return u.vector(u.U8).serialize(Array.from(e), {
276
+ maxSize: et
164
277
  });
165
278
  }
166
- function Ae(e) {
279
+ function ce(e, t) {
280
+ return {
281
+ type: e,
282
+ bcs: t
283
+ };
284
+ }
285
+ function rt(e) {
286
+ return u.vector(u.U8).serialize(Array.from(new TextEncoder().encode(e))).toBytes();
287
+ }
288
+ function nt(e) {
289
+ return u.struct("PriceIdentifier", {
290
+ bytes: u.vector(u.U8)
291
+ }).serialize({
292
+ bytes: Array.from(e)
293
+ }).toBytes();
294
+ }
295
+ function ot(e) {
296
+ const t = [];
297
+ let r = 0, o = 0;
298
+ for (let n = 0; n < e.length; n += 1) {
299
+ const a = e[n];
300
+ a === "<" ? r += 1 : a === ">" ? r -= 1 : a === "," && r === 0 && (t.push(e.slice(o, n).trim()), o = n + 1);
301
+ }
302
+ return t.push(e.slice(o).trim()), t;
303
+ }
304
+ function at(e) {
305
+ const r = e.indexOf("::table::Table"), o = e.indexOf("<", r), n = e.lastIndexOf(">"), a = "::price_identifier::PriceIdentifier";
306
+ if (r < 0 || o < 0 || n <= o)
307
+ throw new Error(`Unexpected Pyth price table type: ${e}`);
308
+ const [c, i] = ot(e.slice(o + 1, n));
309
+ if (!c?.endsWith(a) || !i?.endsWith("::object::ID"))
310
+ throw new Error(`Unexpected Pyth price table type arguments: ${e}`);
311
+ return c.slice(0, -a.length);
312
+ }
313
+ function it(e) {
167
314
  return Uint8Array.from(atob(e), (t) => t.charCodeAt(0));
168
315
  }
169
- class te {
316
+ class he {
170
317
  constructor(t, r) {
171
318
  this.endpoint = t.replace(/\/$/, ""), this.timeout = r?.timeout ?? 1e4;
172
319
  }
173
320
  async getLatestPriceFeeds(t) {
174
- return (await this.get("/api/latest_price_feeds", t)).map((n) => ({
175
- id: n.id,
321
+ return (await this.get("/api/latest_price_feeds", t)).map((o) => ({
322
+ id: o.id,
176
323
  getPriceUnchecked: () => ({
177
- price: n.price.price,
178
- conf: n.price.conf,
179
- expo: n.price.expo,
180
- publishTime: n.price.publish_time
324
+ price: o.price.price,
325
+ conf: o.price.conf,
326
+ expo: o.price.expo,
327
+ publishTime: o.price.publish_time
181
328
  })
182
329
  }));
183
330
  }
@@ -189,22 +336,22 @@ class te {
189
336
  encoding: "base64",
190
337
  parsed: "false"
191
338
  }
192
- ), n = r.binary?.encoding, o = r.binary?.data ?? [];
193
- if (n && n !== "base64")
194
- throw new Error(`Unsupported Hermes price update encoding: ${n}`);
195
- if (o.length === 0)
339
+ ), o = r.binary?.encoding, n = r.binary?.data ?? [];
340
+ if (o && o !== "base64")
341
+ throw new Error(`Unsupported Hermes price update encoding: ${o}`);
342
+ if (n.length === 0)
196
343
  throw new Error("Hermes price update response did not include binary update data");
197
- return o.map(Ae);
344
+ return n.map(it);
198
345
  }
199
- async get(t, r, n) {
200
- const o = new AbortController(), a = setTimeout(() => o.abort(), this.timeout), c = new URL(`${this.endpoint}${t}`);
201
- for (const [i, s] of Object.entries(n ?? {}))
346
+ async get(t, r, o) {
347
+ const n = new AbortController(), a = setTimeout(() => n.abort(), this.timeout), c = new URL(`${this.endpoint}${t}`);
348
+ for (const [i, s] of Object.entries(o ?? {}))
202
349
  c.searchParams.set(i, s);
203
350
  for (const i of r)
204
- c.searchParams.append("ids[]", J(i));
351
+ c.searchParams.append("ids[]", te(i));
205
352
  try {
206
353
  const i = await fetch(c, {
207
- signal: o.signal
354
+ signal: n.signal
208
355
  });
209
356
  if (!i.ok)
210
357
  throw new Error(`Hermes request failed: ${i.status} ${i.statusText}`);
@@ -214,91 +361,147 @@ class te {
214
361
  }
215
362
  }
216
363
  }
217
- class $e {
218
- constructor(t, r, n) {
219
- this.provider = t, this.pythStateId = r, this.wormholeStateId = n, this.priceFeedObjectIdCache = /* @__PURE__ */ new Map();
364
+ class ct {
365
+ constructor(t, r, o) {
366
+ this.provider = t, this.pythStateId = r, this.wormholeStateId = o, this.priceFeedObjectIdCache = /* @__PURE__ */ new Map();
367
+ }
368
+ getCoreProvider() {
369
+ const t = this.provider.core;
370
+ return t && typeof t.getObject == "function" && typeof t.getDynamicObjectField == "function" ? t : null;
371
+ }
372
+ async getMoveObjectJson(t) {
373
+ const r = this.getCoreProvider();
374
+ if (r) {
375
+ const n = await r.getObject({
376
+ objectId: t,
377
+ include: { json: !0 }
378
+ });
379
+ return n.object ? {
380
+ objectId: n.object.objectId,
381
+ type: n.object.type,
382
+ fields: n.object.json
383
+ } : null;
384
+ }
385
+ if (!this.provider.getObject)
386
+ throw new Error("Sui Pyth provider does not support getObject");
387
+ const o = await this.provider.getObject({
388
+ id: t,
389
+ options: { showContent: !0 }
390
+ });
391
+ return !o.data || !o.data.content || o.data.content.dataType !== "moveObject" ? null : {
392
+ objectId: o.data.objectId,
393
+ type: o.data.type,
394
+ fields: o.data.content.fields
395
+ };
220
396
  }
221
- async updatePriceFeeds(t, r, n) {
222
- const o = await this.getPythPackageId(), a = await this.verifyVaasAndGetHotPotato(t, r, o), c = await this.getBaseUpdateFee(), i = t.splitCoins(
397
+ async getDynamicMoveObjectJson(t, r) {
398
+ const o = this.getCoreProvider();
399
+ if (o) {
400
+ const a = await o.getDynamicObjectField({
401
+ parentId: t,
402
+ name: r,
403
+ include: { json: !0 }
404
+ });
405
+ return a.object ? {
406
+ objectId: a.object.objectId,
407
+ type: a.object.type,
408
+ fields: a.object.json
409
+ } : null;
410
+ }
411
+ if (!this.provider.getDynamicFieldObject)
412
+ throw new Error("Sui Pyth provider does not support getDynamicFieldObject");
413
+ const n = await this.provider.getDynamicFieldObject({
414
+ parentId: t,
415
+ name: r
416
+ });
417
+ return n.data ? n.data.content ? n.data.content.dataType !== "moveObject" ? null : {
418
+ objectId: n.data.objectId,
419
+ type: n.data.type,
420
+ fields: n.data.content.fields
421
+ } : {
422
+ objectId: n.data.objectId,
423
+ type: n.data.type,
424
+ fields: void 0
425
+ } : null;
426
+ }
427
+ async updatePriceFeeds(t, r, o) {
428
+ const n = await this.getPythPackageId(), a = await this.verifyVaasAndGetHotPotato(t, r, n), c = await this.getBaseUpdateFee(), i = t.splitCoins(
223
429
  t.gas,
224
- n.map(() => t.pure.u64(c))
430
+ o.map(() => t.pure.u64(c))
225
431
  );
226
- return this.executePriceFeedUpdates(t, o, n, a, i);
432
+ return this.executePriceFeedUpdates(t, n, o, a, i);
227
433
  }
228
434
  async getBaseUpdateFee() {
229
435
  if (this.baseUpdateFee === void 0) {
230
- const t = await this.provider.getObject({
231
- id: this.pythStateId,
232
- options: { showContent: !0 }
233
- });
234
- if (!t.data || !t.data.content || t.data.content.dataType !== "moveObject")
436
+ const t = await this.getMoveObjectJson(this.pythStateId);
437
+ if (!t?.fields)
235
438
  throw new Error("Unable to fetch pyth state object");
236
- this.baseUpdateFee = Number(t.data.content.fields.base_update_fee);
439
+ this.baseUpdateFee = Number(t.fields.base_update_fee);
237
440
  }
238
441
  return this.baseUpdateFee;
239
442
  }
240
443
  async getPackageId(t) {
241
- const r = await this.provider.getObject({
242
- id: t,
243
- options: { showContent: !0 }
244
- });
245
- if (r.data?.content?.dataType === "moveObject") {
246
- const n = r.data.content.fields;
247
- if ("upgrade_cap" in n)
248
- return n.upgrade_cap.fields.package;
444
+ const r = await this.getMoveObjectJson(t);
445
+ if (r?.fields) {
446
+ const o = r.fields;
447
+ if ("upgrade_cap" in o) {
448
+ const n = o.upgrade_cap, a = n?.package ?? n?.fields?.package;
449
+ if (a)
450
+ return a;
451
+ }
249
452
  }
250
453
  throw new Error(`Cannot fetch package id for object ${t}`);
251
454
  }
252
455
  async verifyVaas(t, r) {
253
- const n = await this.getWormholePackageId();
254
- return t.map((o) => {
456
+ const o = await this.getWormholePackageId();
457
+ return t.map((n) => {
255
458
  const [a] = r.moveCall({
256
- target: `${n}::vaa::parse_and_verify`,
459
+ target: `${o}::vaa::parse_and_verify`,
257
460
  arguments: [
258
461
  r.object(this.wormholeStateId),
259
- r.pure(Q(o)),
260
- r.object(z)
462
+ r.pure(ie(n)),
463
+ r.object(Z)
261
464
  ]
262
465
  });
263
466
  return a;
264
467
  });
265
468
  }
266
- async verifyVaasAndGetHotPotato(t, r, n) {
469
+ async verifyVaasAndGetHotPotato(t, r, o) {
267
470
  if (r.length > 1)
268
471
  throw new Error(
269
472
  "SDK does not support sending multiple accumulator messages in a single transaction"
270
473
  );
271
- const o = this.extractVaaBytesFromAccumulatorMessage(r[0]), [a] = await this.verifyVaas([o], t), [c] = t.moveCall({
272
- target: `${n}::pyth::create_authenticated_price_infos_using_accumulator`,
474
+ const n = this.extractVaaBytesFromAccumulatorMessage(r[0]), [a] = await this.verifyVaas([n], t), [c] = t.moveCall({
475
+ target: `${o}::pyth::create_authenticated_price_infos_using_accumulator`,
273
476
  arguments: [
274
477
  t.object(this.pythStateId),
275
- t.pure(Q(r[0])),
478
+ t.pure(ie(r[0])),
276
479
  a,
277
- t.object(z)
480
+ t.object(Z)
278
481
  ]
279
482
  });
280
483
  return c;
281
484
  }
282
- async executePriceFeedUpdates(t, r, n, o, a) {
485
+ async executePriceFeedUpdates(t, r, o, n, a) {
283
486
  const c = [];
284
- for (const [i, s] of n.entries()) {
285
- const p = await this.getPriceFeedObjectId(s);
286
- if (!p)
487
+ for (const [i, s] of o.entries()) {
488
+ const l = await this.getPriceFeedObjectId(s);
489
+ if (!l)
287
490
  throw new Error(`Price feed ${s} not found, please create it first`);
288
- c.push(p), [o] = t.moveCall({
491
+ c.push(l), [n] = t.moveCall({
289
492
  target: `${r}::pyth::update_single_price_feed`,
290
493
  arguments: [
291
494
  t.object(this.pythStateId),
292
- o,
293
- t.object(p),
495
+ n,
496
+ t.object(l),
294
497
  a[i],
295
- t.object(z)
498
+ t.object(Z)
296
499
  ]
297
500
  });
298
501
  }
299
502
  return t.moveCall({
300
503
  target: `${r}::hot_potato_vector::destroy`,
301
- arguments: [o],
504
+ arguments: [n],
302
505
  typeArguments: [`${r}::price_info::PriceInfo`]
303
506
  }), c;
304
507
  }
@@ -309,337 +512,473 @@ class $e {
309
512
  return this.pythPackageId || (this.pythPackageId = await this.getPackageId(this.pythStateId)), this.pythPackageId;
310
513
  }
311
514
  async getPriceFeedObjectId(t) {
312
- const r = J(t);
515
+ const r = te(t);
313
516
  if (!this.priceFeedObjectIdCache.has(r)) {
314
- const { id: n, fieldType: o } = await this.getPriceTableInfo(), a = await this.provider.getDynamicFieldObject({
315
- parentId: n,
316
- name: {
317
- type: `${o}::price_identifier::PriceIdentifier`,
318
- value: {
319
- bytes: Array.from(Pe(r))
320
- }
517
+ const { id: o, fieldType: n } = await this.getPriceTableInfo(), a = this.getCoreProvider() ? ce(
518
+ `${n}::price_identifier::PriceIdentifier`,
519
+ nt(ae(r))
520
+ ) : {
521
+ type: `${n}::price_identifier::PriceIdentifier`,
522
+ value: {
523
+ bytes: Array.from(ae(r))
321
524
  }
322
- });
323
- if (!a.data || !a.data.content)
324
- this.priceFeedObjectIdCache.set(r, void 0);
325
- else {
326
- if (a.data.content.dataType !== "moveObject")
327
- throw new Error("Price feed type mismatch");
328
- this.priceFeedObjectIdCache.set(r, a.data.content.fields.value);
329
- }
525
+ }, c = await this.getDynamicMoveObjectJson(o, a);
526
+ c?.fields ? this.priceFeedObjectIdCache.set(r, c.fields.value) : this.priceFeedObjectIdCache.set(r, void 0);
330
527
  }
331
528
  return this.priceFeedObjectIdCache.get(r);
332
529
  }
333
530
  async getPriceTableInfo() {
334
531
  if (!this.priceTableInfo) {
335
- const t = await this.provider.getDynamicFieldObject({
336
- parentId: this.pythStateId,
337
- name: {
338
- type: "vector<u8>",
339
- value: "price_info"
340
- }
341
- });
342
- if (!t.data || !t.data.type)
532
+ const t = this.getCoreProvider() ? ce("vector<u8>", rt("price_info")) : {
533
+ type: "vector<u8>",
534
+ value: "price_info"
535
+ }, r = await this.getDynamicMoveObjectJson(this.pythStateId, t);
536
+ if (!r?.type)
343
537
  throw new Error("Price Table not found, contract may not be initialized");
344
- let r = t.data.type.replace("0x2::table::Table<", "");
345
- r = r.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>", ""), this.priceTableInfo = {
346
- id: t.data.objectId,
347
- fieldType: r
538
+ this.priceTableInfo = {
539
+ id: r.objectId,
540
+ fieldType: at(r.type)
348
541
  };
349
542
  }
350
543
  return this.priceTableInfo;
351
544
  }
352
545
  extractVaaBytesFromAccumulatorMessage(t) {
353
- const n = 7 + t[6] + 1, o = Be(t, n), a = n + 2;
354
- return t.subarray(a, a + o);
546
+ const o = 7 + t[6] + 1, n = tt(t, o), a = o + 2;
547
+ return t.subarray(a, a + n);
548
+ }
549
+ }
550
+ const st = "https://open-api.naviprotocol.io/api";
551
+ let J = {}, we = 0;
552
+ function lt(e) {
553
+ return e.replace(/\/+$/, "");
554
+ }
555
+ function Kt(e) {
556
+ J = {
557
+ ...J,
558
+ ...e,
559
+ services: {
560
+ ...J.services,
561
+ ...e.services
562
+ }
563
+ }, we += 1;
564
+ }
565
+ function se() {
566
+ return we;
567
+ }
568
+ function E(e) {
569
+ const t = e?.services?.naviOpenApi ?? J.services?.naviOpenApi;
570
+ return {
571
+ baseUrl: lt(t?.baseUrl ?? st),
572
+ headers: t?.headers
573
+ };
574
+ }
575
+ function M(e, t) {
576
+ const r = E(t), o = e.startsWith("/") ? e : `/${e}`;
577
+ return `${r.baseUrl}${o}`;
578
+ }
579
+ function ut(e) {
580
+ if (e instanceof Headers) {
581
+ const t = {};
582
+ return e.forEach((r, o) => {
583
+ t[o] = r;
584
+ }), t;
585
+ }
586
+ return Array.isArray(e) ? Object.fromEntries(e) : e;
587
+ }
588
+ function D(e, t) {
589
+ return {
590
+ ...ut(e),
591
+ ...t?.headers ?? {}
592
+ };
593
+ }
594
+ const V = xe();
595
+ function le(e) {
596
+ return e ? e instanceof Uint8Array ? Array.from(e) : Array.isArray(e) ? e : Array.from(Ee(e)) : [];
597
+ }
598
+ function dt(e) {
599
+ const t = e?.commandResults ?? [], r = e?.Transaction ?? e?.FailedTransaction ?? {}, o = r.effects?.errors?.[0] ?? r.effects?.status?.error ?? r.status?.error ?? r.status?.errors?.[0];
600
+ return o && console.warn("[lending] devInspect(core simulate) returned error:", o), {
601
+ effects: r.effects,
602
+ events: r.events,
603
+ error: o,
604
+ results: t.map((n) => ({
605
+ returnValues: (n.returnValues ?? []).map((a) => [le(a.bcs), ""]),
606
+ mutableReferenceOutputs: (n.mutatedReferences ?? []).map((a) => [
607
+ "",
608
+ le(a.bcs),
609
+ ""
610
+ ])
611
+ }))
612
+ };
613
+ }
614
+ async function q(e, t) {
615
+ const r = e?.core;
616
+ if (typeof r?.simulateTransaction == "function") {
617
+ const o = t.transaction ?? t.transactionBlock;
618
+ o instanceof N && o.setSenderIfNotSet(t.sender);
619
+ const n = await r.simulateTransaction({
620
+ transaction: o,
621
+ checksEnabled: !1,
622
+ include: {
623
+ effects: !0,
624
+ events: !0,
625
+ commandResults: !0
626
+ }
627
+ });
628
+ return dt(n);
629
+ }
630
+ return e.devInspectTransactionBlock({
631
+ transactionBlock: t.transactionBlock ?? t.transaction,
632
+ sender: t.sender
633
+ });
634
+ }
635
+ function be(e) {
636
+ return {
637
+ json: !!e?.showContent,
638
+ display: !!e?.showDisplay,
639
+ previousTransaction: !!e?.showPreviousTransaction,
640
+ objectBcs: !!e?.showBcs
641
+ };
642
+ }
643
+ function ve(e) {
644
+ return !e || e instanceof Error ? {
645
+ error: e instanceof Error ? { code: "notFound", error: e.message } : void 0
646
+ } : {
647
+ data: {
648
+ objectId: e.objectId,
649
+ version: e.version,
650
+ digest: e.digest,
651
+ type: e.type,
652
+ owner: e.owner,
653
+ previousTransaction: e.previousTransaction,
654
+ content: e.json === void 0 ? void 0 : {
655
+ dataType: "moveObject",
656
+ type: e.type,
657
+ fields: e.json
658
+ },
659
+ display: e.display
660
+ }
661
+ };
662
+ }
663
+ async function pt(e, t) {
664
+ const r = e?.core;
665
+ if (typeof r?.getObject == "function") {
666
+ const { object: o } = await r.getObject({
667
+ objectId: t.id,
668
+ include: be(t.options)
669
+ });
670
+ return ve(o);
671
+ }
672
+ return e.getObject(t);
673
+ }
674
+ async function mt(e, t) {
675
+ const r = e?.core;
676
+ if (typeof r?.getObjects == "function") {
677
+ const { objects: o } = await r.getObjects({
678
+ objectIds: t.ids,
679
+ include: be(t.options)
680
+ });
681
+ return o.map(ve);
355
682
  }
683
+ return e.multiGetObjects(t);
356
684
  }
357
- const V = Ce();
358
- function oe(e) {
685
+ function Ce(e) {
359
686
  const t = [];
360
- return e.forEach((r, n) => {
361
- const o = n === e.length - 1;
362
- if (typeof r == "object" && r !== null && o) {
363
- const { client: a, disableCache: c, cacheTime: i, ...s } = r;
364
- t.push(s);
687
+ let r = !1;
688
+ return e.forEach((o, n) => {
689
+ const a = n === e.length - 1;
690
+ if (typeof o == "object" && o !== null && a) {
691
+ const { client: c, disableCache: i, cacheTime: s, ...l } = o;
692
+ l.__naviSdkServiceConfigVersion = se(), t.push(l), r = !0;
365
693
  } else
366
- t.push(r);
694
+ t.push(o);
695
+ }), r || t.push({
696
+ __naviSdkServiceConfigVersion: se()
367
697
  }), JSON.stringify(t);
368
698
  }
369
699
  function A(e) {
370
700
  const t = {};
371
701
  return (...r) => {
372
- const n = oe(r);
373
- return t[n] || (t[n] = e(...r).finally(() => {
374
- delete t[n];
375
- })), t[n];
702
+ const o = Ce(r);
703
+ return t[o] || (t[o] = e(...r).finally(() => {
704
+ delete t[o];
705
+ })), t[o];
376
706
  };
377
707
  }
378
- function S(e) {
708
+ function $(e) {
379
709
  let t = {};
380
710
  return (...r) => {
381
- const n = r[r.length - 1], o = oe(r), a = t[o];
382
- return !n?.disableCache && typeof a?.data < "u" && (typeof n?.cacheTime > "u" || n.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...r).then((c) => (t[o] = {
711
+ const o = r[r.length - 1], n = Ce(r), a = t[n];
712
+ return !o?.disableCache && typeof a?.data < "u" && (typeof o?.cacheTime > "u" || o.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...r).then((c) => (t[n] = {
383
713
  data: c,
384
714
  cacheAt: Date.now()
385
715
  }, c));
386
716
  };
387
717
  }
388
- function G(e) {
389
- return Array.isArray(e) ? e.map((t) => G(t)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
718
+ function x(e) {
719
+ return Array.isArray(e) ? e.map((t) => x(t)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
390
720
  (t, r) => ({
391
721
  ...t,
392
- [ye(r)]: G(e[r])
722
+ [Ve(r)]: x(e[r])
393
723
  }),
394
724
  {}
395
725
  ) : e;
396
726
  }
397
- function g(e, t) {
398
- if (typeof e > "u")
727
+ function h(e, t) {
728
+ if (e == null)
399
729
  throw new Error("Transaction value is required");
400
730
  return typeof e == "object" ? e : t(e);
401
731
  }
402
- function Se(e, t) {
732
+ function ft(e, t) {
403
733
  return typeof t == "string" ? e.object(t) : typeof t == "object" && t.$kind ? t : e.object(t.contract.pool);
404
734
  }
405
- function H(e, t, r) {
735
+ function Q(e, t, r) {
406
736
  if (e.results && e.results.length > 0) {
407
737
  if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
408
- return e.results[0].returnValues.map((n, o) => (t[o] || t[0]).parse(Uint8Array.from(n[0])));
738
+ return e.results[0].returnValues.map((o, n) => (t[n] || t[0]).parse(Uint8Array.from(o[0])));
409
739
  } else if (e.error)
410
740
  return console.log(`Get an error, msg: ${e.error}`), [];
411
741
  return [];
412
742
  }
413
- function k(e) {
414
- return fe(e);
743
+ function C(e) {
744
+ return K(e);
415
745
  }
416
- function re(e) {
746
+ function je(e) {
417
747
  const t = (e || 0) / Math.pow(10, 27);
418
748
  return t > Math.pow(10, 5) ? 1 / 0 : t;
419
749
  }
420
- new te("https://hermes.pyth.network", {
750
+ new he("https://hermes.pyth.network", {
421
751
  timeout: 2e4
422
752
  });
423
- const Ve = 27, x = (e, t) => {
424
- if (!Number(e) || !Number(t)) return new d(0);
425
- const r = new d(1).shiftedBy(1 * Ve), n = r.multipliedBy(new d(0.5));
426
- return new d(e).multipliedBy(new d(t)).plus(n).dividedBy(r).integerValue(d.ROUND_DOWN);
427
- }, E = X ? {
428
- "User-Agent": X
753
+ const yt = 27, ue = (e, t) => {
754
+ if (!Number(e) || !Number(t)) return new p(0);
755
+ const r = new p(1).shiftedBy(1 * yt), o = r.multipliedBy(new p(0.5));
756
+ return new p(e).multipliedBy(new p(t)).plus(o).dividedBy(r).integerValue(p.ROUND_DOWN);
757
+ }, U = oe ? {
758
+ "User-Agent": oe
429
759
  } : {};
430
- function K(e, t = "uniqueId") {
760
+ function ee(e, t = "uniqueId") {
431
761
  return e.reduce(
432
- (r, n) => (r[n[t]] = n, r),
762
+ (r, o) => (r[o[t]] = o, r),
433
763
  {}
434
764
  );
435
765
  }
436
- function ee(e, t = "uniqueId") {
766
+ function de(e, t = "uniqueId") {
437
767
  return e.reduce(
438
- (r, n) => (r[n[t]] = n, r),
768
+ (r, o) => (r[o[t]] = o, r),
439
769
  {}
440
770
  );
441
771
  }
442
- function L(e, t) {
443
- const r = e.emodes.find((o) => o.emodeId === t.emodeId);
772
+ function H(e, t) {
773
+ const r = e.emodes.find((n) => n.emodeId === t.emodeId);
444
774
  if (!r)
445
775
  throw new Error("EMode not found in pool");
446
- const n = r.assets.find((o) => o.assetId === e.id);
776
+ const o = r.assets.find((n) => n.assetId === e.id);
447
777
  return {
448
778
  ...e,
449
779
  emode: {
450
- ...n,
780
+ ...o,
451
781
  emodeId: r.emodeId
452
782
  },
453
783
  isEMode: !0
454
784
  };
455
785
  }
456
- function Me(e) {
786
+ function gt(e) {
457
787
  const [t, r] = e.split("-");
458
788
  return !t || !r ? null : {
459
789
  marketKey: t,
460
790
  poolId: parseInt(r)
461
791
  };
462
792
  }
463
- function B() {
793
+ function P() {
464
794
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
465
795
  }
466
- var N = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(N || {});
467
- const R = S(
796
+ var z = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(z || {});
797
+ const G = $(
468
798
  A(
469
799
  async (e) => {
470
- const t = (e?.markets || [U.main]).map((o) => C(o)), r = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${M.version}&market=${t.map(
471
- (o) => o.key
472
- )}`, n = await fetch(r, { headers: E }).then((o) => o.json());
473
- return n.data.forEach((o) => {
474
- const c = n.meta.emodes.filter((f) => {
475
- const v = C(f.marketId);
476
- return o.market === v.key && f.isActive;
477
- }).filter((f) => !!f.assets.find((v) => v.assetId === o.id));
478
- o.emodes = c;
479
- const i = d(o.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(o.token.decimals, d.ROUND_DOWN).toString(), s = d(o.borrowedAmount).shiftedBy(-9).decimalPlaces(o.token.decimals, d.ROUND_DOWN).toString(), p = d(i).multipliedBy(o.oracle.price).toString(), m = d(s).multipliedBy(o.oracle.price).toString(), h = d(o.supplyCapCeiling).shiftedBy(-27).decimalPlaces(o.token.decimals, d.ROUND_DOWN).toString(), w = d.max(
480
- d(o.borrowedAmount),
481
- d(o.validBorrowAmount)
482
- ).shiftedBy(-9).decimalPlaces(o.token.decimals, d.ROUND_DOWN).toString(), y = d(h).multipliedBy(o.oracle.price).toString(), u = d(w).multipliedBy(o.oracle.price).toString();
483
- o.poolSupplyAmount = i, o.poolBorrowAmount = s, o.poolSupplyValue = p, o.poolBorrowValue = m, o.poolSupplyCapAmount = h, o.poolBorrowCapAmount = w, o.poolSupplyCapValue = y, o.poolBorrowCapValue = u;
800
+ const t = (e?.markets || [F.main]).map((a) => _(a)), r = E(e), o = M(
801
+ `/navi/pools?env=${e?.env || "prod"}&sdk=${O.version}&market=${t.map(
802
+ (a) => a.key
803
+ )}`,
804
+ e
805
+ ), n = await fetch(o, { headers: D(U, r) }).then(
806
+ (a) => a.json()
807
+ );
808
+ return n.data.forEach((a) => {
809
+ const i = n.meta.emodes.filter((b) => {
810
+ const k = _(b.marketId);
811
+ return a.market === k.key && b.isActive;
812
+ }).filter((b) => !!b.assets.find((k) => k.assetId === a.id));
813
+ a.emodes = i;
814
+ const s = p(a.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), l = p(a.borrowedAmount).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), m = p(s).multipliedBy(a.oracle.price).toString(), w = p(l).multipliedBy(a.oracle.price).toString(), y = p(a.supplyCapCeiling).shiftedBy(-27).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), g = p.max(
815
+ p(a.borrowedAmount),
816
+ p(a.validBorrowAmount)
817
+ ).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), d = p(y).multipliedBy(a.oracle.price).toString(), f = p(g).multipliedBy(a.oracle.price).toString();
818
+ a.poolSupplyAmount = s, a.poolBorrowAmount = l, a.poolSupplyValue = m, a.poolBorrowValue = w, a.poolSupplyCapAmount = y, a.poolBorrowCapAmount = g, a.poolSupplyCapValue = d, a.poolBorrowCapValue = f;
484
819
  }), n.data;
485
820
  }
486
821
  )
487
822
  );
488
- async function $(e, t) {
823
+ async function S(e, t) {
489
824
  let r = t?.market;
490
825
  if (typeof e == "string") {
491
- const a = Me(e);
826
+ const a = gt(e);
492
827
  a && (r = a.marketKey, e = a.poolId);
493
828
  }
494
- const n = await R({
829
+ const o = await G({
495
830
  ...t,
496
- markets: [r || O],
497
- cacheTime: b
831
+ markets: [r || R],
832
+ cacheTime: v
498
833
  });
499
834
  if (typeof e == "object")
500
835
  return e;
501
- const o = n.find((a) => typeof e == "string" ? k(a.suiCoinType) === k(e) : typeof e == "number" ? a.id === e : !1);
502
- if (!o)
836
+ const n = o.find((a) => typeof e == "string" ? C(a.suiCoinType) === C(e) : typeof e == "number" ? a.id === e : !1);
837
+ if (!n)
503
838
  throw new Error("Pool not found");
504
- return o.isDeprecated && console.log(`The lending pool for coinType ${o.suiCoinType} is going to be deprecated.`), o;
839
+ return n.isDeprecated && console.log(`The lending pool for coinType ${n.suiCoinType} is going to be deprecated.`), n;
505
840
  }
506
- const nt = S(
841
+ const Qt = $(
507
842
  A(async (e) => {
508
- const t = `https://open-api.naviprotocol.io/api/navi/stats?sdk=${M.version}`;
509
- return (await fetch(t, { headers: E }).then((n) => n.json())).data;
843
+ const t = E(e), r = M(`/navi/stats?sdk=${O.version}`, e);
844
+ return (await fetch(r, {
845
+ headers: D(U, t)
846
+ }).then((n) => n.json())).data;
510
847
  })
511
- ), at = S(
848
+ ), Yt = $(
512
849
  A(
513
850
  async (e) => {
514
- const t = `https://open-api.naviprotocol.io/api/navi/fee?sdk=${M.version}`;
515
- return await fetch(t, { headers: E }).then((n) => n.json());
851
+ const t = E(e), r = M(`/navi/fee?sdk=${O.version}`, e);
852
+ return await fetch(r, {
853
+ headers: D(U, t)
854
+ }).then((n) => n.json());
516
855
  }
517
856
  )
518
857
  );
519
- async function Ee(e, t, r, n) {
520
- const o = await _({
521
- ...n,
522
- cacheTime: b
523
- }), a = await $(t, n), c = n?.market || O, i = n?.env || "prod";
858
+ async function ht(e, t, r, o) {
859
+ const n = await j({
860
+ ...o,
861
+ cacheTime: v
862
+ }), a = await S(t, o), c = o?.market || R, i = o?.env || "prod";
524
863
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
525
864
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
526
- if (k(a.suiCoinType) === k("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
527
- if (!n?.amount)
865
+ if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
866
+ if (!o?.amount)
528
867
  throw new Error("Amount is required for sui coin");
529
- r = e.splitCoins(r, [n.amount]);
868
+ r = e.splitCoins(r, [o.amount]);
530
869
  }
531
870
  let s;
532
- return typeof n?.amount < "u" ? s = g(n.amount, e.pure.u64) : s = e.moveCall({
871
+ return typeof o?.amount < "u" ? s = h(o.amount, e.pure.u64) : s = e.moveCall({
533
872
  target: "0x2::coin::value",
534
- arguments: [g(r, e.object)],
873
+ arguments: [h(r, e.object)],
535
874
  typeArguments: [a.suiCoinType]
536
- }), n?.accountCap ? e.moveCall({
537
- target: `${o.package}::incentive_v3::deposit_with_account_cap`,
875
+ }), o?.accountCap ? e.moveCall({
876
+ target: `${n.package}::incentive_v3::deposit_with_account_cap`,
538
877
  arguments: [
539
878
  e.object("0x06"),
540
- e.object(o.storage),
879
+ e.object(n.storage),
541
880
  e.object(a.contract.pool),
542
881
  e.pure.u8(a.id),
543
- g(r, e.object),
544
- e.object(o.incentiveV2),
545
- e.object(o.incentiveV3),
546
- g(n.accountCap, e.object)
882
+ h(r, e.object),
883
+ e.object(n.incentiveV2),
884
+ e.object(n.incentiveV3),
885
+ h(o.accountCap, e.object)
547
886
  ],
548
887
  typeArguments: [a.suiCoinType]
549
888
  }) : e.moveCall({
550
- target: `${o.package}::incentive_v3::entry_deposit`,
889
+ target: `${n.package}::incentive_v3::entry_deposit`,
551
890
  arguments: [
552
891
  e.object("0x06"),
553
- e.object(o.storage),
892
+ e.object(n.storage),
554
893
  e.object(a.contract.pool),
555
894
  e.pure.u8(a.id),
556
- g(r, e.object),
895
+ h(r, e.object),
557
896
  s,
558
- e.object(o.incentiveV2),
559
- e.object(o.incentiveV3)
897
+ e.object(n.incentiveV2),
898
+ e.object(n.incentiveV3)
560
899
  ],
561
900
  typeArguments: [a.suiCoinType]
562
- }), o.version === 2 && a.token.symbol === "SUI" && i === "prod" && c === "main" && e.moveCall({
563
- target: `${o.package}::pool::refresh_stake`,
901
+ }), n.version === 2 && a.token.symbol === "SUI" && i === "prod" && c === "main" && e.moveCall({
902
+ target: `${n.package}::pool::refresh_stake`,
564
903
  arguments: [e.object(a.contract.pool), e.object("0x05")]
565
904
  }), e;
566
905
  }
567
- async function it(e, t, r, n) {
568
- const o = await _({
569
- ...n,
570
- cacheTime: b
571
- }), a = await $(t, n), c = g(r, e.pure.u64);
906
+ async function Zt(e, t, r, o) {
907
+ const n = await j({
908
+ ...o,
909
+ cacheTime: v
910
+ }), a = await S(t, o), c = h(r, e.pure.u64);
572
911
  let i;
573
- if (o.version === 1)
574
- if (n?.accountCap) {
575
- const [p] = e.moveCall({
576
- target: `${o.package}::incentive_v3::withdraw_with_account_cap`,
912
+ if (n.version === 1)
913
+ if (o?.accountCap) {
914
+ const [l] = e.moveCall({
915
+ target: `${n.package}::incentive_v3::withdraw_with_account_cap`,
577
916
  arguments: [
578
917
  e.object("0x06"),
579
- e.object(o.priceOracle),
580
- e.object(o.storage),
918
+ e.object(n.priceOracle),
919
+ e.object(n.storage),
581
920
  e.object(a.contract.pool),
582
921
  e.pure.u8(a.id),
583
922
  c,
584
- e.object(o.incentiveV2),
585
- e.object(o.incentiveV3),
586
- g(n.accountCap, e.object)
923
+ e.object(n.incentiveV2),
924
+ e.object(n.incentiveV3),
925
+ h(o.accountCap, e.object)
587
926
  ],
588
927
  typeArguments: [a.suiCoinType]
589
928
  });
590
- i = p;
929
+ i = l;
591
930
  } else {
592
- const [p] = e.moveCall({
593
- target: `${o.package}::incentive_v3::withdraw`,
931
+ const [l] = e.moveCall({
932
+ target: `${n.package}::incentive_v3::withdraw`,
594
933
  arguments: [
595
934
  e.object("0x06"),
596
- e.object(o.priceOracle),
597
- e.object(o.storage),
935
+ e.object(n.priceOracle),
936
+ e.object(n.storage),
598
937
  e.object(a.contract.pool),
599
938
  e.pure.u8(a.id),
600
939
  c,
601
- e.object(o.incentiveV2),
602
- e.object(o.incentiveV3)
940
+ e.object(n.incentiveV2),
941
+ e.object(n.incentiveV3)
603
942
  ],
604
943
  typeArguments: [a.suiCoinType]
605
944
  });
606
- i = p;
945
+ i = l;
607
946
  }
608
- else if (n?.accountCap) {
609
- const [p] = e.moveCall({
610
- target: `${o.package}::incentive_v3::withdraw_with_account_cap_v2`,
947
+ else if (o?.accountCap) {
948
+ const [l] = e.moveCall({
949
+ target: `${n.package}::incentive_v3::withdraw_with_account_cap_v2`,
611
950
  arguments: [
612
951
  e.object("0x06"),
613
- e.object(o.priceOracle),
614
- e.object(o.storage),
952
+ e.object(n.priceOracle),
953
+ e.object(n.storage),
615
954
  e.object(a.contract.pool),
616
955
  e.pure.u8(a.id),
617
956
  c,
618
- e.object(o.incentiveV2),
619
- e.object(o.incentiveV3),
620
- g(n.accountCap, e.object),
957
+ e.object(n.incentiveV2),
958
+ e.object(n.incentiveV3),
959
+ h(o.accountCap, e.object),
621
960
  e.object("0x05")
622
961
  ],
623
962
  typeArguments: [a.suiCoinType]
624
963
  });
625
- i = p;
964
+ i = l;
626
965
  } else {
627
- const [p] = e.moveCall({
628
- target: `${o.package}::incentive_v3::withdraw_v2`,
966
+ const [l] = e.moveCall({
967
+ target: `${n.package}::incentive_v3::withdraw_v2`,
629
968
  arguments: [
630
969
  e.object("0x06"),
631
- e.object(o.priceOracle),
632
- e.object(o.storage),
970
+ e.object(n.priceOracle),
971
+ e.object(n.storage),
633
972
  e.object(a.contract.pool),
634
973
  e.pure.u8(a.id),
635
974
  c,
636
- e.object(o.incentiveV2),
637
- e.object(o.incentiveV3),
975
+ e.object(n.incentiveV2),
976
+ e.object(n.incentiveV3),
638
977
  e.object("0x05")
639
978
  ],
640
979
  typeArguments: [a.suiCoinType]
641
980
  });
642
- i = p;
981
+ i = l;
643
982
  }
644
983
  return e.moveCall({
645
984
  target: "0x2::coin::from_balance",
@@ -647,85 +986,85 @@ async function it(e, t, r, n) {
647
986
  typeArguments: [a.suiCoinType]
648
987
  });
649
988
  }
650
- async function ct(e, t, r, n) {
651
- const o = await _({
652
- ...n,
653
- cacheTime: b
654
- }), a = await $(t, n);
989
+ async function Xt(e, t, r, o) {
990
+ const n = await j({
991
+ ...o,
992
+ cacheTime: v
993
+ }), a = await S(t, o);
655
994
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
656
995
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
657
- const c = g(r, e.pure.u64);
996
+ const c = h(r, e.pure.u64);
658
997
  let i;
659
- if (o.version === 1)
660
- if (n?.accountCap) {
661
- const [p] = e.moveCall({
662
- target: `${o.package}::incentive_v3::borrow_with_account_cap`,
998
+ if (n.version === 1)
999
+ if (o?.accountCap) {
1000
+ const [l] = e.moveCall({
1001
+ target: `${n.package}::incentive_v3::borrow_with_account_cap`,
663
1002
  arguments: [
664
1003
  e.object("0x06"),
665
- e.object(o.priceOracle),
666
- e.object(o.storage),
1004
+ e.object(n.priceOracle),
1005
+ e.object(n.storage),
667
1006
  e.object(a.contract.pool),
668
1007
  e.pure.u8(a.id),
669
1008
  c,
670
- e.object(o.incentiveV2),
671
- e.object(o.incentiveV3),
672
- g(n.accountCap, e.object)
1009
+ e.object(n.incentiveV2),
1010
+ e.object(n.incentiveV3),
1011
+ h(o.accountCap, e.object)
673
1012
  ],
674
1013
  typeArguments: [a.suiCoinType]
675
1014
  });
676
- i = p;
1015
+ i = l;
677
1016
  } else {
678
- const [p] = e.moveCall({
679
- target: `${o.package}::incentive_v3::borrow`,
1017
+ const [l] = e.moveCall({
1018
+ target: `${n.package}::incentive_v3::borrow`,
680
1019
  arguments: [
681
1020
  e.object("0x06"),
682
- e.object(o.priceOracle),
683
- e.object(o.storage),
1021
+ e.object(n.priceOracle),
1022
+ e.object(n.storage),
684
1023
  e.object(a.contract.pool),
685
1024
  e.pure.u8(a.id),
686
1025
  c,
687
- e.object(o.incentiveV2),
688
- e.object(o.incentiveV3)
1026
+ e.object(n.incentiveV2),
1027
+ e.object(n.incentiveV3)
689
1028
  ],
690
1029
  typeArguments: [a.suiCoinType]
691
1030
  });
692
- i = p;
1031
+ i = l;
693
1032
  }
694
- else if (n?.accountCap) {
695
- const [p] = e.moveCall({
696
- target: `${o.package}::incentive_v3::borrow_with_account_cap_v2`,
1033
+ else if (o?.accountCap) {
1034
+ const [l] = e.moveCall({
1035
+ target: `${n.package}::incentive_v3::borrow_with_account_cap_v2`,
697
1036
  arguments: [
698
1037
  e.object("0x06"),
699
- e.object(o.priceOracle),
700
- e.object(o.storage),
1038
+ e.object(n.priceOracle),
1039
+ e.object(n.storage),
701
1040
  e.object(a.contract.pool),
702
1041
  e.pure.u8(a.id),
703
1042
  c,
704
- e.object(o.incentiveV2),
705
- e.object(o.incentiveV3),
706
- g(n.accountCap, e.object),
1043
+ e.object(n.incentiveV2),
1044
+ e.object(n.incentiveV3),
1045
+ h(o.accountCap, e.object),
707
1046
  e.object("0x05")
708
1047
  ],
709
1048
  typeArguments: [a.suiCoinType]
710
1049
  });
711
- i = p;
1050
+ i = l;
712
1051
  } else {
713
- const [p] = e.moveCall({
714
- target: `${o.package}::incentive_v3::borrow_v2`,
1052
+ const [l] = e.moveCall({
1053
+ target: `${n.package}::incentive_v3::borrow_v2`,
715
1054
  arguments: [
716
1055
  e.object("0x06"),
717
- e.object(o.priceOracle),
718
- e.object(o.storage),
1056
+ e.object(n.priceOracle),
1057
+ e.object(n.storage),
719
1058
  e.object(a.contract.pool),
720
1059
  e.pure.u8(a.id),
721
1060
  c,
722
- e.object(o.incentiveV2),
723
- e.object(o.incentiveV3),
1061
+ e.object(n.incentiveV2),
1062
+ e.object(n.incentiveV3),
724
1063
  e.object("0x05")
725
1064
  ],
726
1065
  typeArguments: [a.suiCoinType]
727
1066
  });
728
- i = p;
1067
+ i = l;
729
1068
  }
730
1069
  return e.moveCall({
731
1070
  target: "0x2::coin::from_balance",
@@ -733,34 +1072,34 @@ async function ct(e, t, r, n) {
733
1072
  typeArguments: [a.suiCoinType]
734
1073
  });
735
1074
  }
736
- async function st(e, t, r, n) {
737
- const o = await _({
738
- ...n,
739
- cacheTime: b
740
- }), a = await $(t, n);
741
- if (k(a.suiCoinType) === k("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
742
- if (!n?.amount)
1075
+ async function xt(e, t, r, o) {
1076
+ const n = await j({
1077
+ ...o,
1078
+ cacheTime: v
1079
+ }), a = await S(t, o);
1080
+ if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
1081
+ if (!o?.amount)
743
1082
  throw new Error("Amount is required for sui coin");
744
- r = e.splitCoins(r, [n.amount]);
1083
+ r = e.splitCoins(r, [o.amount]);
745
1084
  }
746
1085
  let c;
747
- if (typeof n?.amount < "u" ? c = g(n.amount, e.pure.u64) : c = e.moveCall({
1086
+ if (typeof o?.amount < "u" ? c = h(o.amount, e.pure.u64) : c = e.moveCall({
748
1087
  target: "0x2::coin::value",
749
- arguments: [g(r, e.object)],
1088
+ arguments: [h(r, e.object)],
750
1089
  typeArguments: [a.suiCoinType]
751
- }), n?.accountCap) {
1090
+ }), o?.accountCap) {
752
1091
  const [i] = e.moveCall({
753
- target: `${o.package}::incentive_v3::repay_with_account_cap`,
1092
+ target: `${n.package}::incentive_v3::repay_with_account_cap`,
754
1093
  arguments: [
755
1094
  e.object("0x06"),
756
- e.object(o.priceOracle),
757
- e.object(o.storage),
1095
+ e.object(n.priceOracle),
1096
+ e.object(n.storage),
758
1097
  e.object(a.contract.pool),
759
1098
  e.pure.u8(a.id),
760
- g(r, e.object),
761
- e.object(o.incentiveV2),
762
- e.object(o.incentiveV3),
763
- g(n.accountCap, e.object)
1099
+ h(r, e.object),
1100
+ e.object(n.incentiveV2),
1101
+ e.object(n.incentiveV3),
1102
+ h(o.accountCap, e.object)
764
1103
  ],
765
1104
  typeArguments: [a.suiCoinType]
766
1105
  });
@@ -771,56 +1110,59 @@ async function st(e, t, r, n) {
771
1110
  });
772
1111
  } else
773
1112
  return e.moveCall({
774
- target: `${o.package}::incentive_v3::entry_repay`,
1113
+ target: `${n.package}::incentive_v3::entry_repay`,
775
1114
  arguments: [
776
1115
  e.object("0x06"),
777
- e.object(o.priceOracle),
778
- e.object(o.storage),
1116
+ e.object(n.priceOracle),
1117
+ e.object(n.storage),
779
1118
  e.object(a.contract.pool),
780
1119
  e.pure.u8(a.id),
781
- g(r, e.object),
1120
+ h(r, e.object),
782
1121
  c,
783
- e.object(o.incentiveV2),
784
- e.object(o.incentiveV3)
1122
+ e.object(n.incentiveV2),
1123
+ e.object(n.incentiveV3)
785
1124
  ],
786
1125
  typeArguments: [a.suiCoinType]
787
1126
  }), e;
788
1127
  }
789
- const lt = S(
1128
+ const er = $(
790
1129
  A(
791
1130
  async (e) => {
792
- const t = await _({
1131
+ const t = await j({
793
1132
  ...e
794
- });
1133
+ }), r = e?.client ?? V;
795
1134
  if (e?.address && typeof e?.asset < "u")
796
1135
  try {
797
- const o = await $(e.asset, e), a = e?.client ?? V, c = new F();
1136
+ const a = await S(e.asset, e), c = new N();
798
1137
  c.moveCall({
799
1138
  target: `${t.package}::incentive_v3::get_borrow_fee_v2`,
800
1139
  arguments: [
801
1140
  c.object(t.incentiveV3),
802
1141
  c.pure.address(e.address),
803
- c.pure.u8(o.id),
1142
+ c.pure.u8(a.id),
804
1143
  c.pure.u64(1e4)
805
1144
  ],
806
1145
  typeArguments: []
807
1146
  });
808
- const i = await a.devInspectTransactionBlock({
1147
+ const i = await q(r, {
809
1148
  transactionBlock: c,
810
1149
  sender: e.address
811
- }), s = H(i, [l.u64()]);
1150
+ }), s = Q(i, [u.u64()]);
812
1151
  return (Number(s[0]) || 0) / 100;
813
- } catch (o) {
814
- console.error(o);
1152
+ } catch (a) {
1153
+ console.error(
1154
+ "[lending] getBorrowFee per-user query failed, falling back to global rate:",
1155
+ a
1156
+ );
815
1157
  }
816
- const n = (await V.getObject({
1158
+ const n = (await pt(r, {
817
1159
  id: t.incentiveV3,
818
1160
  options: { showType: !0, showOwner: !0, showContent: !0 }
819
1161
  })).data.content.fields.borrow_fee_rate;
820
1162
  return Number(n) / 100;
821
1163
  }
822
1164
  )
823
- ), O = "main", U = {
1165
+ ), R = "main", F = {
824
1166
  main: {
825
1167
  id: 0,
826
1168
  key: "main",
@@ -842,56 +1184,56 @@ const lt = S(
842
1184
  name: "Sui Eco Market"
843
1185
  }
844
1186
  };
845
- class Ue {
1187
+ class wt {
846
1188
  constructor(t, r) {
847
1189
  this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
848
1190
  marketTotalSupplyValue: "0",
849
1191
  marketTotalBorrowValue: "0"
850
- }, this.config = C(t), this.initPools(r);
1192
+ }, this.config = _(t), this.initPools(r);
851
1193
  }
852
1194
  get overview() {
853
1195
  return this._overview;
854
1196
  }
855
1197
  initPools(t) {
856
- const r = K(this.pools), n = ee(this.emodes), o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
857
- let c = d(0), i = d(0);
1198
+ const r = ee(this.pools), o = de(this.emodes), n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
1199
+ let c = p(0), i = p(0);
858
1200
  t.forEach((s) => {
859
1201
  if (!this.checkMarket(s.market)) {
860
1202
  console.warn(`Pool is not in market ${this.config.name}`, s);
861
1203
  return;
862
1204
  }
863
1205
  r[s.uniqueId] || this.pools.push(s), s?.emodes?.forEach((m) => {
864
- n[m.uniqueId] || this.emodes.push(m), m.assets.forEach((h) => {
865
- h.isDebt && m.assets.find(
866
- (y) => y.isCollateral && y.ltv > 0 && y.assetId !== s.id
867
- ) && o.add(s.uniqueId), h.isCollateral && m.assets.find((y) => y.isDebt && y.assetId !== s.id) && a.add(s.uniqueId);
1206
+ o[m.uniqueId] || this.emodes.push(m), m.assets.forEach((w) => {
1207
+ w.isDebt && m.assets.find(
1208
+ (g) => g.isCollateral && g.ltv > 0 && g.assetId !== s.id
1209
+ ) && n.add(s.uniqueId), w.isCollateral && m.assets.find((g) => g.isDebt && g.assetId !== s.id) && a.add(s.uniqueId);
868
1210
  });
869
1211
  }), i = i.plus(s.poolBorrowValue), c = c.plus(s.poolSupplyValue);
870
- }), this.poolMap = K(this.pools, "id"), this.emodeMap = ee(this.emodes, "emodeId"), this.emodes.forEach((s) => {
871
- const p = this.getEModePools(s.emodeId);
872
- this.emodePools.push(...p);
1212
+ }), this.poolMap = ee(this.pools, "id"), this.emodeMap = de(this.emodes, "emodeId"), this.emodes.forEach((s) => {
1213
+ const l = this.getEModePools(s.emodeId);
1214
+ this.emodePools.push(...l);
873
1215
  }), this._overview = {
874
1216
  marketTotalSupplyValue: c.toString(),
875
1217
  marketTotalBorrowValue: i.toString()
876
- }, this.emodeBorrowablePools = this.pools.filter((s) => o.has(s.uniqueId)), this.emodeSupplyablePools = this.pools.filter((s) => a.has(s.uniqueId));
1218
+ }, this.emodeBorrowablePools = this.pools.filter((s) => n.has(s.uniqueId)), this.emodeSupplyablePools = this.pools.filter((s) => a.has(s.uniqueId));
877
1219
  }
878
1220
  getEMode(t) {
879
1221
  return this.emodeMap[t] || null;
880
1222
  }
881
1223
  getEModeRelatePools(t, r) {
882
- const { collateral: n, debt: o, emodeId: a } = r || {}, c = [];
1224
+ const { collateral: o, debt: n, emodeId: a } = r || {}, c = [];
883
1225
  return t.emodes.forEach((i) => {
884
1226
  typeof a == "number" && a !== i.emodeId || i.assets.forEach((s) => {
885
- typeof n == "boolean" && n && s.isCollateral && s.assetId === t.id && c.push(this.poolMap[s.assetId]), typeof o == "boolean" && o && s.isDebt && s.assetId === t.id && c.push(this.poolMap[s.assetId]);
1227
+ typeof o == "boolean" && o && s.isCollateral && s.assetId === t.id && c.push(this.poolMap[s.assetId]), typeof n == "boolean" && n && s.isDebt && s.assetId === t.id && c.push(this.poolMap[s.assetId]);
886
1228
  });
887
1229
  }), c;
888
1230
  }
889
1231
  getEModePools(t) {
890
1232
  const r = this.getEMode(t);
891
- return r ? r.assets.map((o) => o.assetId).map((o) => this.poolMap[o]).filter((o) => !!o).map((o) => {
892
- const a = r.assets.find((c) => c.assetId === o.id);
1233
+ return r ? r.assets.map((n) => n.assetId).map((n) => this.poolMap[n]).filter((n) => !!n).map((n) => {
1234
+ const a = r.assets.find((c) => c.assetId === n.id);
893
1235
  return {
894
- ...o,
1236
+ ...n,
895
1237
  emode: {
896
1238
  ...a,
897
1239
  emodeId: r.emodeId
@@ -905,40 +1247,45 @@ class Ue {
905
1247
  return typeof t == "number" && t === this.config.id && (r = !0), typeof t == "string" && t === this.config.key && (r = !0), typeof t == "object" && t.id === this.config.id && (r = !0), r;
906
1248
  }
907
1249
  }
908
- const C = (e) => {
909
- const r = Object.values(U).find((n) => typeof e == "number" ? n.id === e : typeof e == "string" ? n.key === e : n.id === e.id);
1250
+ const _ = (e) => {
1251
+ const r = Object.values(F).find((o) => typeof e == "number" ? o.id === e : typeof e == "string" ? o.key === e : o.id === e.id);
910
1252
  if (!r)
911
1253
  throw new Error("Market not found");
912
1254
  return r;
913
- }, Oe = S(
1255
+ }, bt = $(
914
1256
  A(
915
1257
  async (e, t) => {
916
- const r = await R({
1258
+ const r = await G({
917
1259
  cacheTime: 6e4,
918
1260
  ...t,
919
1261
  markets: e
920
1262
  });
921
- return e.map((n) => {
922
- const o = C(n), a = r.filter((c) => c.market === o.key);
923
- return new Ue(n, a);
1263
+ return e.map((o) => {
1264
+ const n = _(o), a = r.filter((c) => c.market === n.key);
1265
+ return new wt(o, a);
924
1266
  });
925
1267
  }
926
1268
  )
927
- ), ut = S(
1269
+ ), tr = $(
928
1270
  A(
929
- async (e, t) => (await Oe([e], t))[0]
1271
+ async (e, t) => (await bt([e], t))[0]
930
1272
  )
931
- ), _ = S(
1273
+ ), j = $(
932
1274
  A(
933
1275
  async (e) => {
934
- const t = C(e?.market || O), r = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${M.version}&market=${t.key}`;
935
- return (await fetch(r, { headers: E }).then((o) => o.json())).data;
1276
+ const t = _(e?.market || R), r = E(e), o = M(
1277
+ `/navi/config?env=${e?.env || "prod"}&sdk=${O.version}&market=${t.key}`,
1278
+ e
1279
+ );
1280
+ return (await fetch(o, {
1281
+ headers: D(U, r)
1282
+ }).then((a) => a.json())).data;
936
1283
  }
937
1284
  )
938
- ), b = 1e3 * 60 * 5;
939
- async function De(e, t) {
940
- const r = await _({
941
- cacheTime: b,
1285
+ ), v = 1e3 * 60 * 5;
1286
+ async function vt(e, t) {
1287
+ const r = await j({
1288
+ cacheTime: v,
942
1289
  ...t
943
1290
  });
944
1291
  return e.moveCall({
@@ -946,374 +1293,443 @@ async function De(e, t) {
946
1293
  arguments: []
947
1294
  });
948
1295
  }
949
- async function Fe(e, t, r) {
950
- const n = await _({
951
- cacheTime: b,
1296
+ async function Ct(e, t, r) {
1297
+ const o = await j({
1298
+ cacheTime: v,
952
1299
  ...r
953
1300
  });
954
1301
  return e.moveCall({
955
- target: `${n.package}::account::account_owner`,
1302
+ target: `${o.package}::account::account_owner`,
956
1303
  arguments: [t]
957
1304
  });
958
1305
  }
959
- async function Ne(e, t, r) {
960
- const n = await _({
1306
+ async function jt(e, t, r) {
1307
+ const o = await j({
961
1308
  ...r,
962
- cacheTime: b
1309
+ cacheTime: v
963
1310
  });
964
1311
  return r?.accountCap ? e.moveCall({
965
- target: `${n.package}::lending::enter_emode_with_account_cap`,
1312
+ target: `${o.package}::lending::enter_emode_with_account_cap`,
966
1313
  arguments: [
967
- e.object(n.storage),
968
- g(t, e.pure.u64),
969
- g(r.accountCap, e.object)
1314
+ e.object(o.storage),
1315
+ h(t, e.pure.u64),
1316
+ h(r.accountCap, e.object)
970
1317
  ]
971
1318
  }) : e.moveCall({
972
- target: `${n.package}::lending::enter_emode`,
973
- arguments: [e.object(n.storage), g(t, e.pure.u64)]
1319
+ target: `${o.package}::lending::enter_emode`,
1320
+ arguments: [e.object(o.storage), h(t, e.pure.u64)]
974
1321
  }), e;
975
1322
  }
976
- async function pt(e, t) {
977
- const r = await _({
1323
+ async function rr(e, t) {
1324
+ const r = await j({
978
1325
  ...t,
979
- cacheTime: b
1326
+ cacheTime: v
980
1327
  });
981
1328
  return t?.accountCap ? e.moveCall({
982
1329
  target: `${r.package}::lending::exit_emode_with_account_cap`,
983
- arguments: [e.object(r.storage), g(t.accountCap, e.object)]
1330
+ arguments: [e.object(r.storage), h(t.accountCap, e.object)]
984
1331
  }) : e.moveCall({
985
1332
  target: `${r.package}::lending::exit_emode`,
986
1333
  arguments: [e.object(r.storage)]
987
1334
  }), e;
988
1335
  }
989
- async function dt(e, t, r) {
990
- const n = await _({
991
- cacheTime: b,
1336
+ async function nr(e, t, r) {
1337
+ const o = await j({
1338
+ cacheTime: v,
992
1339
  ...r
993
- }), o = await De(e, r);
994
- await Ne(e, t, {
1340
+ }), n = await vt(e, r);
1341
+ await jt(e, t, {
995
1342
  ...r,
996
- accountCap: o
1343
+ accountCap: n
997
1344
  });
998
- const a = await C(r?.market || O), c = await Fe(e, o, r);
1345
+ const a = await _(r?.market || R), c = await Ct(e, n, r);
999
1346
  return e.moveCall({
1000
- target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
1347
+ target: `${o.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
1001
1348
  arguments: [
1002
- e.object(n.emode.contract.registryObject),
1349
+ e.object(o.emode.contract.registryObject),
1003
1350
  c,
1004
- g(a.id, e.pure.u64),
1005
- g(t, e.pure.u64)
1351
+ h(a.id, e.pure.u64),
1352
+ h(t, e.pure.u64)
1006
1353
  ]
1007
- }), o;
1354
+ }), n;
1008
1355
  }
1009
- const ne = S(
1356
+ const ke = $(
1010
1357
  A(
1011
1358
  async (e, t) => {
1012
- const r = await _({
1013
- cacheTime: b,
1359
+ const r = await j({
1360
+ cacheTime: v,
1014
1361
  ...t
1015
- }), n = new F(), o = t?.client ?? V;
1016
- n.moveCall({
1362
+ }), o = new N(), n = t?.client ?? V;
1363
+ o.moveCall({
1017
1364
  target: `${r.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
1018
- arguments: [n.object(r.emode.contract.registryObject), n.pure.address(e)]
1365
+ arguments: [o.object(r.emode.contract.registryObject), o.pure.address(e)]
1019
1366
  });
1020
- const c = (await o.devInspectTransactionBlock({
1021
- transactionBlock: n,
1367
+ const c = (await q(n, {
1368
+ transactionBlock: o,
1022
1369
  sender: e
1023
- })).results[0].returnValues, i = l.vector(l.u64()).parse(Uint8Array.from(c[0][0])), s = l.vector(l.u64()).parse(Uint8Array.from(c[1][0])), p = l.vector(l.Address).parse(Uint8Array.from(c[2][0]));
1024
- return i.map((m, h) => ({
1370
+ })).results[0].returnValues, i = u.vector(u.u64()).parse(Uint8Array.from(c[0][0])), s = u.vector(u.u64()).parse(Uint8Array.from(c[1][0])), l = u.vector(u.Address).parse(Uint8Array.from(c[2][0]));
1371
+ return i.map((m, w) => ({
1025
1372
  marketId: Number(m),
1026
- emodeId: Number(s[h]),
1027
- accountCap: p[h].toString()
1373
+ emodeId: Number(s[w]),
1374
+ accountCap: l[w].toString()
1028
1375
  }));
1029
1376
  }
1030
1377
  )
1031
1378
  );
1032
- function mt(e) {
1033
- return `${C(e.marketId).key}-${e.emodeId}`;
1379
+ function or(e) {
1380
+ return `${_(e.marketId).key}-${e.emodeId}`;
1034
1381
  }
1035
- function ft(e, t, r) {
1036
- const n = typeof r?.balance == "number", o = n ? r.balance : 0;
1382
+ function kt(e, t) {
1383
+ return e.coinType ? e.coinType : t || (typeof e.type == "string" ? e.type.match(/::coin::Coin<(.+)>$/) : null)?.[1];
1384
+ }
1385
+ function pe(e, t) {
1386
+ const r = kt(e, t), o = e.coinObjectId ?? e.objectId;
1387
+ return !r || !o || e.balance === void 0 || e.balance === null ? null : {
1388
+ ...e,
1389
+ coinType: C(r),
1390
+ coinObjectId: o
1391
+ };
1392
+ }
1393
+ function ar(e, t, r) {
1394
+ const o = typeof r?.balance == "number", n = o ? r.balance : 0;
1037
1395
  let a = 0;
1038
1396
  const c = [];
1039
1397
  let i = "";
1040
- if (t.sort((s, p) => Number(p.balance) - Number(s.balance)).forEach((s) => {
1041
- if (!(n && a >= o) && Number(s.balance) !== 0) {
1398
+ if (t.sort((s, l) => Number(l.balance) - Number(s.balance)).forEach((s) => {
1399
+ if (!(o && a >= n) && Number(s.balance) !== 0) {
1042
1400
  if (i || (i = s.coinType), i !== s.coinType)
1043
1401
  throw new Error("All coins must be of the same type");
1044
1402
  a += Number(s.balance), c.push(s.coinObjectId);
1045
1403
  }
1046
1404
  }), c.length === 0)
1047
1405
  throw new Error("No coins to merge");
1048
- if (n && a < o)
1406
+ if (o && a < n)
1049
1407
  throw new Error(
1050
- `Balance is less than the specified balance: ${a} < ${o}`
1408
+ `Balance is less than the specified balance: ${a} < ${n}`
1051
1409
  );
1052
- return k(i) === k("0x2::sui::SUI") && r?.useGasCoin ? n ? e.splitCoins(e.gas, [e.pure.u64(o)]) : e.gas : (c.length === 1 ? e.object(c[0]) : e.mergeCoins(c[0], c.slice(1)), n ? e.splitCoins(c[0], [e.pure.u64(o)]) : c[0]);
1410
+ return C(i) === C("0x2::sui::SUI") && r?.useGasCoin ? o ? e.splitCoins(e.gas, [e.pure.u64(n)]) : e.gas : (c.length === 1 ? e.object(c[0]) : e.mergeCoins(c[0], c.slice(1)), o ? e.splitCoins(c[0], [e.pure.u64(n)]) : c[0]);
1053
1411
  }
1054
- async function ae(e, t, r, n, o, a, c) {
1055
- const i = await _({
1412
+ async function Ie(e, t, r, o, n, a, c) {
1413
+ const i = await j({
1056
1414
  ...c,
1057
- cacheTime: b
1058
- }), s = await $(r, c);
1415
+ cacheTime: v
1416
+ }), s = await S(r, c);
1059
1417
  return e.moveCall({
1060
1418
  target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
1061
1419
  arguments: [
1062
1420
  e.object("0x06"),
1063
1421
  e.object(i.storage),
1064
1422
  e.object(i.oracle.priceOracle),
1065
- Se(e, s),
1066
- g(t, e.pure.address),
1067
- g(s.id, e.pure.u8),
1068
- g(n, e.pure.u64),
1069
- g(o, e.pure.u64),
1070
- g(a, e.pure.bool)
1423
+ ft(e, s),
1424
+ h(t, e.pure.address),
1425
+ h(s.id, e.pure.u8),
1426
+ h(o, e.pure.u64),
1427
+ h(n, e.pure.u64),
1428
+ h(a, e.pure.bool)
1071
1429
  ],
1072
1430
  typeArguments: [s.suiCoinType]
1073
1431
  });
1074
1432
  }
1075
- async function Re(e, t, r) {
1076
- return ae(e, t, 0, 0, 0, !1, r);
1433
+ async function It(e, t, r) {
1434
+ return Ie(e, t, 0, 0, 0, !1, r);
1077
1435
  }
1078
- async function ie(e, t, r) {
1079
- const n = new F(), o = r?.client ?? V, a = await R({
1436
+ async function _e(e, t, r) {
1437
+ const o = new N(), n = r?.client ?? V, a = await G({
1080
1438
  ...r,
1081
- markets: Object.values(U)
1082
- }), c = K(a), s = Array.from(new Set(t.map((u) => u.market))).map((u) => C(u));
1083
- for (const u of s) {
1084
- const f = await _({
1439
+ markets: Object.values(F)
1440
+ }), c = ee(a), s = Array.from(new Set(t.map((d) => d.market))).map((d) => _(d));
1441
+ for (const d of s) {
1442
+ const f = await j({
1085
1443
  ...r,
1086
- cacheTime: b,
1087
- market: u.key
1444
+ cacheTime: v,
1445
+ market: d.key
1088
1446
  });
1089
- n.moveCall({
1447
+ o.moveCall({
1090
1448
  target: `${f.uiGetter}::getter::get_reserve_data`,
1091
- arguments: [n.object(f.storage)]
1449
+ arguments: [o.object(f.storage)]
1092
1450
  });
1093
1451
  }
1094
- for (let u of t) {
1095
- const f = await _({
1452
+ for (let d of t) {
1453
+ const f = await j({
1096
1454
  ...r,
1097
- cacheTime: b,
1098
- market: u.market
1455
+ cacheTime: v,
1456
+ market: d.market
1099
1457
  });
1100
- n.moveCall({
1458
+ o.moveCall({
1101
1459
  target: `${f.uiGetter}::getter_unchecked::get_user_state`,
1102
- arguments: [n.object(f.storage), n.pure.address(u.address)]
1460
+ arguments: [o.object(f.storage), o.pure.address(d.address)]
1103
1461
  });
1104
1462
  }
1105
- const m = (await o.devInspectTransactionBlock({
1106
- transactionBlock: n,
1463
+ const m = (await q(n, {
1464
+ transactionBlock: o,
1107
1465
  sender: e
1108
- })).results || [], h = {};
1109
- s.forEach((u, f) => {
1466
+ })).results || [], w = {};
1467
+ s.forEach((d, f) => {
1110
1468
  try {
1111
- const v = m[f]?.returnValues?.map((T) => l.vector(ve).parse(Uint8Array.from(T[0])))[0] || [], I = {};
1112
- for (const T of v)
1113
- I[T.id] = {
1469
+ const b = m[f]?.returnValues?.map((T) => u.vector(Re).parse(Uint8Array.from(T[0])))[0] || [], k = {};
1470
+ for (const T of b)
1471
+ k[T.id] = {
1114
1472
  supplyIndex: T.supply_index,
1115
1473
  borrowIndex: T.borrow_index
1116
1474
  };
1117
- h[u.key] = I;
1118
- } catch (v) {
1475
+ w[d.key] = k;
1476
+ } catch (b) {
1119
1477
  console.warn(
1120
- `[@naviprotocol/lending] Failed to decode reserve data for market "${u.key}", falling back to open-api pool indices`,
1121
- v
1478
+ `[@naviprotocol/lending] Failed to decode reserve data for market "${d.key}", falling back to open-api pool indices`,
1479
+ b
1122
1480
  );
1123
1481
  }
1124
1482
  });
1125
- const w = m.slice(s.length).map((u) => u.returnValues?.map((f) => l.vector(be).parse(Uint8Array.from(f[0])))[0] || []), y = [];
1126
- return w.forEach((u, f) => {
1127
- const v = t[f], I = C(v.market), T = h[I.key] || {};
1128
- u.forEach((j) => {
1129
- if (j.supply_balance === "0" && j.borrow_balance === "0" && (v.emodeId === void 0 || !r?.includeZeroBalanceEmodePositions))
1483
+ const y = m.slice(s.length).map((d) => d.returnValues?.map((f) => u.vector(Le).parse(Uint8Array.from(f[0])))[0] || []), g = [];
1484
+ return y.forEach((d, f) => {
1485
+ const b = t[f], k = _(b.market), T = w[k.key] || {};
1486
+ d.forEach((I) => {
1487
+ if (I.supply_balance === "0" && I.borrow_balance === "0" && (b.emodeId === void 0 || !r?.includeZeroBalanceEmodePositions))
1130
1488
  return;
1131
- const P = c[`${I.key}-${j.asset_id}`];
1132
- if (!P)
1489
+ const B = c[`${k.key}-${I.asset_id}`];
1490
+ if (!B)
1133
1491
  return;
1134
- const q = T[j.asset_id], W = q?.supplyIndex ?? P.currentSupplyIndex, le = q?.borrowIndex ?? P.currentBorrowIndex, ue = x(j.supply_balance, W).toString(), pe = x(j.borrow_balance, le).toString();
1135
- y.push({
1136
- supplyBalance: ue,
1137
- borrowBalance: pe,
1138
- assetId: j.asset_id,
1139
- market: I.key,
1140
- pool: P,
1141
- emodeId: v.emodeId
1492
+ const W = T[I.asset_id], Y = W?.supplyIndex ?? B.currentSupplyIndex, Pe = W?.borrowIndex ?? B.currentBorrowIndex, Ae = ue(I.supply_balance, Y).toString(), Se = ue(I.borrow_balance, Pe).toString();
1493
+ g.push({
1494
+ supplyBalance: Ae,
1495
+ borrowBalance: Se,
1496
+ assetId: I.asset_id,
1497
+ market: k.key,
1498
+ pool: B,
1499
+ emodeId: b.emodeId
1142
1500
  });
1143
1501
  });
1144
- }), y;
1502
+ }), g;
1145
1503
  }
1146
- const yt = S(
1504
+ const ir = $(
1147
1505
  async (e, t) => {
1148
- const n = (t?.markets || Object.keys(U)).map((o) => C(o)).map((o) => ({
1506
+ const o = (t?.markets || Object.keys(F)).map((n) => _(n)).map((n) => ({
1149
1507
  address: e,
1150
- market: o.key
1508
+ market: n.key
1151
1509
  }));
1152
- return await ie(e, n, t);
1510
+ return await _e(e, o, t);
1153
1511
  }
1154
1512
  );
1155
- async function gt(e, t) {
1156
- const r = t?.client ?? V, n = new F();
1157
- await Re(n, e, t);
1158
- const o = await r.devInspectTransactionBlock({
1159
- transactionBlock: n,
1513
+ async function cr(e, t) {
1514
+ const r = t?.client ?? V, o = new N();
1515
+ await It(o, e, t);
1516
+ const n = await q(r, {
1517
+ transactionBlock: o,
1160
1518
  sender: e
1161
- }), a = H(o, [l.u256()]);
1162
- return re(Number(a[0]) || 0);
1519
+ }), a = Q(n, [u.u256()]);
1520
+ return je(Number(a[0]) || 0);
1163
1521
  }
1164
- async function ht(e, t, r, n) {
1165
- const o = n?.client ?? V, a = new F();
1522
+ async function sr(e, t, r, o) {
1523
+ const n = o?.client ?? V, a = new N();
1166
1524
  let c = 0, i = 0;
1167
- const s = await $(t, n);
1168
- if (r.forEach((w) => {
1169
- w.type === N.Supply ? c += w.amount : w.type === N.Withdraw ? c -= w.amount : w.type === N.Borrow ? i += w.amount : w.type === N.Repay && (i -= w.amount);
1525
+ const s = await S(t, o);
1526
+ if (r.forEach((y) => {
1527
+ y.type === z.Supply ? c += y.amount : y.type === z.Withdraw ? c -= y.amount : y.type === z.Borrow ? i += y.amount : y.type === z.Repay && (i -= y.amount);
1170
1528
  }), c * i < 0)
1171
1529
  throw new Error("Invalid operations");
1172
- const p = c > 0 || i > 0;
1173
- await ae(
1530
+ const l = c > 0 || i > 0;
1531
+ await Ie(
1174
1532
  a,
1175
1533
  e,
1176
1534
  s,
1177
1535
  Math.abs(c),
1178
1536
  Math.abs(i),
1179
- p,
1180
- n
1537
+ l,
1538
+ o
1181
1539
  );
1182
- const m = await o.devInspectTransactionBlock({
1540
+ const m = await q(n, {
1183
1541
  transactionBlock: a,
1184
1542
  sender: e
1185
- }), h = H(m, [l.u256()]);
1186
- return re(Number(h[0]) || 0);
1543
+ }), w = Q(m, [u.u256()]);
1544
+ return je(Number(w[0]) || 0);
1187
1545
  }
1188
- const wt = A(
1546
+ const lr = A(
1189
1547
  async (e, t) => {
1190
1548
  const r = new URLSearchParams();
1191
1549
  t?.cursor && r.set("cursor", t.cursor), r.set("userAddress", e);
1192
- const n = `https://open-api.naviprotocol.io/api/navi/user/transactions?${r.toString()}&sdk=${M.version}`;
1193
- return (await fetch(n, { headers: E }).then((a) => a.json())).data;
1550
+ const o = E(t), n = M(
1551
+ `/navi/user/transactions?${r.toString()}&sdk=${O.version}`,
1552
+ t
1553
+ );
1554
+ return (await fetch(n, {
1555
+ headers: D(U, o)
1556
+ }).then((c) => c.json())).data;
1194
1557
  }
1195
1558
  );
1196
- async function vt(e, t) {
1559
+ async function ur(e, t) {
1197
1560
  let r = null;
1198
- const n = [], o = t?.client ?? V;
1561
+ const o = [], n = t?.client ?? V, a = n.core;
1199
1562
  do {
1200
- let a;
1201
- if (t?.coinType ? a = await o.getCoins({
1202
- owner: e,
1203
- coinType: t?.coinType,
1204
- cursor: r,
1205
- limit: 100
1206
- }) : a = await o.getAllCoins({
1207
- owner: e,
1208
- cursor: r,
1209
- limit: 100
1210
- }), !a.data || !a.data.length)
1563
+ let c;
1564
+ if (t?.coinType)
1565
+ if (typeof a?.listCoins == "function") {
1566
+ const i = await a.listCoins({
1567
+ owner: e,
1568
+ coinType: t?.coinType,
1569
+ cursor: r,
1570
+ limit: 100
1571
+ });
1572
+ c = {
1573
+ data: (i.objects ?? i.data ?? []).map((s) => pe(s, t?.coinType)).filter(Boolean),
1574
+ nextCursor: i.cursor ?? i.nextCursor ?? null,
1575
+ hasNextPage: i.hasNextPage ?? !1
1576
+ };
1577
+ } else {
1578
+ if (typeof n.getCoins != "function")
1579
+ throw new Error("getCoins requires core.listCoins or an explicit legacy getCoins client");
1580
+ c = await n.getCoins({
1581
+ owner: e,
1582
+ coinType: t?.coinType,
1583
+ cursor: r,
1584
+ limit: 100
1585
+ });
1586
+ }
1587
+ else if (typeof a?.listBalances == "function" && typeof a?.listCoins == "function") {
1588
+ const i = /* @__PURE__ */ new Set();
1589
+ let s = null;
1590
+ do {
1591
+ const l = await a.listBalances({
1592
+ owner: e,
1593
+ cursor: s,
1594
+ limit: 100
1595
+ });
1596
+ for (const m of l.balances ?? [])
1597
+ m?.coinType && i.add(m.coinType);
1598
+ s = l.cursor ?? l.nextCursor ?? null;
1599
+ } while (s);
1600
+ for (const l of i) {
1601
+ let m = null;
1602
+ do {
1603
+ const w = await a.listCoins({
1604
+ owner: e,
1605
+ coinType: l,
1606
+ cursor: m,
1607
+ limit: 100
1608
+ });
1609
+ o.push(
1610
+ ...(w.objects ?? w.data ?? []).map((y) => pe(y, l)).filter(Boolean)
1611
+ ), m = w.cursor ?? w.nextCursor ?? null;
1612
+ } while (m);
1613
+ }
1211
1614
  break;
1212
- n.push(...a.data), r = a.nextCursor;
1615
+ } else {
1616
+ if (typeof n.getAllCoins != "function")
1617
+ throw new Error(
1618
+ "getCoins requires core.listBalances/core.listCoins or an explicit legacy getAllCoins client"
1619
+ );
1620
+ c = await n.getAllCoins({
1621
+ owner: e,
1622
+ cursor: r,
1623
+ limit: 100
1624
+ });
1625
+ }
1626
+ if (!c.data || !c.data.length)
1627
+ break;
1628
+ o.push(...c.data), r = c.nextCursor;
1213
1629
  } while (r);
1214
- return n;
1630
+ return o;
1215
1631
  }
1216
- const qe = S(
1632
+ const _t = $(
1217
1633
  async (e, t) => {
1218
- const r = [], n = (t?.markets || Object.keys(U)).map((i) => C(i));
1219
- let o = [];
1634
+ const r = [], o = (t?.markets || Object.keys(F)).map((i) => _(i));
1635
+ let n = [];
1220
1636
  try {
1221
- o = await ne(e, t);
1637
+ n = await ke(e, t);
1222
1638
  } catch (i) {
1223
1639
  console.error(i);
1224
1640
  }
1225
- const a = n.map((i) => ({
1641
+ const a = o.map((i) => ({
1226
1642
  address: e,
1227
1643
  market: i.key
1228
1644
  })).concat(
1229
- o.filter((i) => !!n.find((s) => s.id === i.marketId)).map((i) => ({
1645
+ n.filter((i) => !!o.find((s) => s.id === i.marketId)).map((i) => ({
1230
1646
  address: i.accountCap,
1231
- market: C(i.marketId).key,
1647
+ market: _(i.marketId).key,
1232
1648
  emodeId: i.emodeId
1233
1649
  }))
1234
1650
  );
1235
- return (await ie(e, a, t)).forEach((i) => {
1236
- const s = typeof i.emodeId == "number" ? o.find((p) => {
1237
- const m = C(i.market);
1238
- return p.emodeId === i.emodeId && p.marketId === m.id;
1651
+ return (await _e(e, a, t)).forEach((i) => {
1652
+ const s = typeof i.emodeId == "number" ? n.find((l) => {
1653
+ const m = _(i.market);
1654
+ return l.emodeId === i.emodeId && l.marketId === m.id;
1239
1655
  }) : void 0;
1240
1656
  if (s) {
1241
1657
  if (!i.pool.emodes.find((m) => m.emodeId === s.emodeId))
1242
1658
  return;
1243
- if (d(i.supplyBalance).gte(0)) {
1244
- const m = d(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, d.ROUND_DOWN), h = L(i.pool, s);
1245
- if (m.gt(0) || h.emode.isCollateral)
1659
+ if (p(i.supplyBalance).gte(0)) {
1660
+ const m = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = H(i.pool, s);
1661
+ if (m.gt(0) || w.emode.isCollateral)
1246
1662
  try {
1247
1663
  r.push({
1248
- id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${B()}`,
1664
+ id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${P()}`,
1249
1665
  wallet: e,
1250
1666
  protocol: "navi",
1251
1667
  market: i.market,
1252
1668
  type: "navi-lending-emode-supply",
1253
1669
  "navi-lending-emode-supply": {
1254
1670
  amount: m.toString(),
1255
- pool: L(i.pool, s),
1671
+ pool: H(i.pool, s),
1256
1672
  token: i.pool.token,
1257
1673
  valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
1258
1674
  emodeCap: s
1259
1675
  }
1260
1676
  });
1261
- } catch (w) {
1262
- console.error(w);
1677
+ } catch (y) {
1678
+ console.error(y);
1263
1679
  }
1264
1680
  }
1265
- if (d(i.borrowBalance).gte(0)) {
1266
- const m = d(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, d.ROUND_DOWN), h = L(i.pool, s);
1267
- if (m.gt(0) || h.emode.isDebt)
1681
+ if (p(i.borrowBalance).gte(0)) {
1682
+ const m = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = H(i.pool, s);
1683
+ if (m.gt(0) || w.emode.isDebt)
1268
1684
  try {
1269
1685
  r.push({
1270
- id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${B()}`,
1686
+ id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${P()}`,
1271
1687
  wallet: e,
1272
1688
  protocol: "navi",
1273
1689
  market: i.market,
1274
1690
  type: "navi-lending-emode-borrow",
1275
1691
  "navi-lending-emode-borrow": {
1276
1692
  amount: m.toString(),
1277
- pool: L(i.pool, s),
1693
+ pool: H(i.pool, s),
1278
1694
  token: i.pool.token,
1279
1695
  valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
1280
1696
  emodeCap: s
1281
1697
  }
1282
1698
  });
1283
- } catch (w) {
1284
- console.error(w);
1699
+ } catch (y) {
1700
+ console.error(y);
1285
1701
  }
1286
1702
  }
1287
1703
  } else {
1288
- if (d(i.supplyBalance).gt(0)) {
1289
- const p = d(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, d.ROUND_DOWN);
1704
+ if (p(i.supplyBalance).gt(0)) {
1705
+ const l = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1290
1706
  r.push({
1291
- id: `${i.pool.uniqueId}_navi-lending-supply-${B()}`,
1707
+ id: `${i.pool.uniqueId}_navi-lending-supply-${P()}`,
1292
1708
  wallet: e,
1293
1709
  protocol: "navi",
1294
1710
  type: "navi-lending-supply",
1295
1711
  market: i.market,
1296
1712
  "navi-lending-supply": {
1297
- amount: p.toString(),
1713
+ amount: l.toString(),
1298
1714
  pool: i.pool,
1299
1715
  token: i.pool.token,
1300
- valueUSD: p.multipliedBy(i.pool.oracle.price).toString()
1716
+ valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
1301
1717
  }
1302
1718
  });
1303
1719
  }
1304
- if (d(i.borrowBalance).gt(0)) {
1305
- const p = d(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, d.ROUND_DOWN);
1720
+ if (p(i.borrowBalance).gt(0)) {
1721
+ const l = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1306
1722
  r.push({
1307
- id: `${i.pool.uniqueId}_navi-lending-borrow-${B()}`,
1723
+ id: `${i.pool.uniqueId}_navi-lending-borrow-${P()}`,
1308
1724
  wallet: e,
1309
1725
  protocol: "navi",
1310
1726
  market: i.market,
1311
1727
  type: "navi-lending-borrow",
1312
1728
  "navi-lending-borrow": {
1313
- amount: p.toString(),
1729
+ amount: l.toString(),
1314
1730
  pool: i.pool,
1315
1731
  token: i.pool.token,
1316
- valueUSD: p.multipliedBy(i.pool.oracle.price).toString()
1732
+ valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
1317
1733
  }
1318
1734
  });
1319
1735
  }
@@ -1321,7 +1737,7 @@ const qe = S(
1321
1737
  }), r;
1322
1738
  }
1323
1739
  );
1324
- class D {
1740
+ class L {
1325
1741
  constructor(t, r) {
1326
1742
  this._positions = [], this._priceMap = {}, this._overview = {
1327
1743
  hf: 1 / 0,
@@ -1353,256 +1769,256 @@ class D {
1353
1769
  return this._priceMap = t, this._overview = this.getPositionsOverview(this._positions), this;
1354
1770
  }
1355
1771
  getPrice(t) {
1356
- const r = k(t.suiCoinType);
1772
+ const r = C(t.suiCoinType);
1357
1773
  if (this._priceMap[r] !== void 0)
1358
1774
  return this._priceMap[r].toString();
1359
- const n = t.suiCoinType;
1360
- return this._priceMap[n] !== void 0 ? this._priceMap[n].toString() : t.oracle.price;
1775
+ const o = t.suiCoinType;
1776
+ return this._priceMap[o] !== void 0 ? this._priceMap[o].toString() : t.oracle.price;
1361
1777
  }
1362
1778
  filterPositionsByPool(t) {
1363
- const n = !!t.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
1364
- return new D(
1365
- this.positions.filter((o) => {
1366
- const a = o[o.type];
1367
- return n.includes(o.type) && a.pool.uniqueId === t.uniqueId;
1779
+ const o = !!t.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
1780
+ return new L(
1781
+ this.positions.filter((n) => {
1782
+ const a = n[n.type];
1783
+ return o.includes(n.type) && a.pool.uniqueId === t.uniqueId;
1368
1784
  }),
1369
1785
  this._priceMap
1370
1786
  );
1371
1787
  }
1372
1788
  deposit(t, r) {
1373
- const n = !!t.isEMode, o = this.getPrice(t);
1789
+ const o = !!t.isEMode, n = this.getPrice(t);
1374
1790
  let a;
1375
- return n ? a = {
1376
- id: B(),
1791
+ return o ? a = {
1792
+ id: P(),
1377
1793
  wallet: "",
1378
1794
  protocol: "navi",
1379
1795
  market: "",
1380
1796
  type: "navi-lending-emode-supply",
1381
1797
  "navi-lending-emode-supply": {
1382
1798
  amount: r.toString(),
1383
- valueUSD: d(r).multipliedBy(o).toString(),
1799
+ valueUSD: p(r).multipliedBy(n).toString(),
1384
1800
  token: t.token,
1385
1801
  pool: t,
1386
1802
  emodeCap: {}
1387
1803
  }
1388
1804
  } : a = {
1389
- id: B(),
1805
+ id: P(),
1390
1806
  wallet: "",
1391
1807
  protocol: "navi",
1392
1808
  market: "",
1393
1809
  type: "navi-lending-supply",
1394
1810
  "navi-lending-supply": {
1395
1811
  amount: r.toString(),
1396
- valueUSD: d(r).multipliedBy(o).toString(),
1812
+ valueUSD: p(r).multipliedBy(n).toString(),
1397
1813
  token: t.token,
1398
1814
  pool: t
1399
1815
  }
1400
- }, new D([...this.positions, a], this._priceMap);
1816
+ }, new L([...this.positions, a], this._priceMap);
1401
1817
  }
1402
1818
  withdraw(t, r) {
1403
- const n = !!t.isEMode, o = this.getPrice(t);
1819
+ const o = !!t.isEMode, n = this.getPrice(t);
1404
1820
  let a;
1405
- return n ? a = {
1406
- id: B(),
1821
+ return o ? a = {
1822
+ id: P(),
1407
1823
  wallet: "",
1408
1824
  protocol: "navi",
1409
1825
  market: "",
1410
1826
  type: "navi-lending-emode-supply",
1411
1827
  "navi-lending-emode-supply": {
1412
1828
  amount: (-r).toString(),
1413
- valueUSD: d(-r).multipliedBy(o).toString(),
1829
+ valueUSD: p(-r).multipliedBy(n).toString(),
1414
1830
  token: t.token,
1415
1831
  pool: t,
1416
1832
  emodeCap: {}
1417
1833
  }
1418
1834
  } : a = {
1419
- id: B(),
1835
+ id: P(),
1420
1836
  wallet: "",
1421
1837
  protocol: "navi",
1422
1838
  market: "",
1423
1839
  type: "navi-lending-supply",
1424
1840
  "navi-lending-supply": {
1425
1841
  amount: (-r).toString(),
1426
- valueUSD: d(-r).multipliedBy(o).toString(),
1842
+ valueUSD: p(-r).multipliedBy(n).toString(),
1427
1843
  token: t.token,
1428
1844
  pool: t
1429
1845
  }
1430
- }, new D([...this.positions, a], this._priceMap);
1846
+ }, new L([...this.positions, a], this._priceMap);
1431
1847
  }
1432
1848
  borrow(t, r) {
1433
- const n = !!t.isEMode, o = this.getPrice(t);
1849
+ const o = !!t.isEMode, n = this.getPrice(t);
1434
1850
  let a;
1435
- return n ? a = {
1436
- id: B(),
1851
+ return o ? a = {
1852
+ id: P(),
1437
1853
  wallet: "",
1438
1854
  protocol: "navi",
1439
1855
  market: "",
1440
1856
  type: "navi-lending-emode-borrow",
1441
1857
  "navi-lending-emode-borrow": {
1442
1858
  amount: r.toString(),
1443
- valueUSD: d(r).multipliedBy(o).toString(),
1859
+ valueUSD: p(r).multipliedBy(n).toString(),
1444
1860
  token: t.token,
1445
1861
  pool: t,
1446
1862
  emodeCap: {}
1447
1863
  }
1448
1864
  } : a = {
1449
- id: B(),
1865
+ id: P(),
1450
1866
  wallet: "",
1451
1867
  protocol: "navi",
1452
1868
  market: "",
1453
1869
  type: "navi-lending-borrow",
1454
1870
  "navi-lending-borrow": {
1455
1871
  amount: r.toString(),
1456
- valueUSD: d(r).multipliedBy(o).toString(),
1872
+ valueUSD: p(r).multipliedBy(n).toString(),
1457
1873
  token: t.token,
1458
1874
  pool: t
1459
1875
  }
1460
- }, new D([...this.positions, a], this._priceMap);
1876
+ }, new L([...this.positions, a], this._priceMap);
1461
1877
  }
1462
1878
  repay(t, r) {
1463
- const n = !!t.isEMode, o = this.getPrice(t);
1879
+ const o = !!t.isEMode, n = this.getPrice(t);
1464
1880
  let a;
1465
- return n ? a = {
1466
- id: B(),
1881
+ return o ? a = {
1882
+ id: P(),
1467
1883
  wallet: "",
1468
1884
  protocol: "navi",
1469
1885
  market: "",
1470
1886
  type: "navi-lending-emode-borrow",
1471
1887
  "navi-lending-emode-borrow": {
1472
1888
  amount: (-r).toString(),
1473
- valueUSD: d(-r).multipliedBy(o).toString(),
1889
+ valueUSD: p(-r).multipliedBy(n).toString(),
1474
1890
  token: t.token,
1475
1891
  pool: t,
1476
1892
  emodeCap: {}
1477
1893
  }
1478
1894
  } : a = {
1479
- id: B(),
1895
+ id: P(),
1480
1896
  wallet: "",
1481
1897
  protocol: "navi",
1482
1898
  market: "",
1483
1899
  type: "navi-lending-borrow",
1484
1900
  "navi-lending-borrow": {
1485
1901
  amount: (-r).toString(),
1486
- valueUSD: d(-r).multipliedBy(o).toString(),
1902
+ valueUSD: p(-r).multipliedBy(n).toString(),
1487
1903
  token: t.token,
1488
1904
  pool: t
1489
1905
  }
1490
- }, new D([...this.positions, a], this._priceMap);
1906
+ }, new L([...this.positions, a], this._priceMap);
1491
1907
  }
1492
1908
  resolveValueUSD(t) {
1493
- return Object.keys(this._priceMap).length > 0 ? d(t.amount).multipliedBy(this.getPrice(t.pool)).toString() : t.valueUSD;
1909
+ return Object.keys(this._priceMap).length > 0 ? p(t.amount).multipliedBy(this.getPrice(t.pool)).toString() : t.valueUSD;
1494
1910
  }
1495
1911
  getPositionsOverview(t) {
1496
- const r = {}, n = {};
1497
- let o = new d(0), a = new d(0), c = new d(0), i = new d(0), s = new d(0), p = new d(0);
1498
- t.forEach((y) => {
1499
- if (y.type === "navi-lending-supply") {
1500
- const u = y["navi-lending-supply"], f = this.resolveValueUSD(u);
1501
- o = o.plus(f), s = s.plus(
1502
- new d(f).multipliedBy(u.pool.liquidationFactor.threshold)
1503
- ), p = p.plus(
1504
- new d(f).multipliedBy(u.pool.ltvValue)
1912
+ const r = {}, o = {};
1913
+ let n = new p(0), a = new p(0), c = new p(0), i = new p(0), s = new p(0), l = new p(0);
1914
+ t.forEach((g) => {
1915
+ if (g.type === "navi-lending-supply") {
1916
+ const d = g["navi-lending-supply"], f = this.resolveValueUSD(d);
1917
+ n = n.plus(f), s = s.plus(
1918
+ new p(f).multipliedBy(d.pool.liquidationFactor.threshold)
1919
+ ), l = l.plus(
1920
+ new p(f).multipliedBy(d.pool.ltvValue)
1505
1921
  );
1506
- } else if (y.type === "navi-lending-borrow") {
1507
- const u = y["navi-lending-borrow"];
1508
- a = a.plus(this.resolveValueUSD(u));
1509
- } else if (y.type === "navi-lending-emode-supply") {
1510
- const u = y["navi-lending-emode-supply"], f = this.resolveValueUSD(u);
1511
- o = o.plus(f);
1512
- const v = u.pool.emode;
1922
+ } else if (g.type === "navi-lending-borrow") {
1923
+ const d = g["navi-lending-borrow"];
1924
+ a = a.plus(this.resolveValueUSD(d));
1925
+ } else if (g.type === "navi-lending-emode-supply") {
1926
+ const d = g["navi-lending-emode-supply"], f = this.resolveValueUSD(d);
1927
+ n = n.plus(f);
1928
+ const b = d.pool.emode;
1513
1929
  s = s.plus(
1514
- new d(f).multipliedBy(v.lt)
1515
- ), p = p.plus(
1516
- new d(f).multipliedBy(v.ltv)
1930
+ new p(f).multipliedBy(b.lt)
1931
+ ), l = l.plus(
1932
+ new p(f).multipliedBy(b.ltv)
1517
1933
  );
1518
- } else if (y.type === "navi-lending-emode-borrow") {
1519
- const u = y["navi-lending-emode-borrow"];
1520
- a = a.plus(this.resolveValueUSD(u));
1934
+ } else if (g.type === "navi-lending-emode-borrow") {
1935
+ const d = g["navi-lending-emode-borrow"];
1936
+ a = a.plus(this.resolveValueUSD(d));
1521
1937
  }
1522
- }), a = d.max(a, 0), o = d.max(o, 0), s = d.max(s, 0), p = d.max(p, 0), t.forEach((y) => {
1523
- if (y.type === "navi-lending-supply") {
1524
- const u = y["navi-lending-supply"], f = this.resolveValueUSD(u), v = u.pool.supplyIncentiveApyInfo.apy;
1525
- o.gt(0) && (c = c.plus(
1526
- new d(f).dividedBy(o).multipliedBy(new d(v).dividedBy(100))
1527
- )), r[u.pool.suiCoinType] = d(r[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1528
- } else if (y.type === "navi-lending-borrow") {
1529
- const u = y["navi-lending-borrow"], f = this.resolveValueUSD(u), v = u.pool.borrowIncentiveApyInfo.apy;
1938
+ }), a = p.max(a, 0), n = p.max(n, 0), s = p.max(s, 0), l = p.max(l, 0), t.forEach((g) => {
1939
+ if (g.type === "navi-lending-supply") {
1940
+ const d = g["navi-lending-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
1941
+ n.gt(0) && (c = c.plus(
1942
+ new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
1943
+ )), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
1944
+ } else if (g.type === "navi-lending-borrow") {
1945
+ const d = g["navi-lending-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
1530
1946
  a.gt(0) && (i = i.plus(
1531
- new d(f).dividedBy(a).multipliedBy(new d(v).dividedBy(100))
1532
- )), n[u.pool.suiCoinType] = d(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1533
- } else if (y.type === "navi-lending-emode-supply") {
1534
- const u = y["navi-lending-emode-supply"], f = this.resolveValueUSD(u), v = u.pool.supplyIncentiveApyInfo.apy;
1535
- o.gt(0) && (c = c.plus(
1536
- new d(f).dividedBy(o).multipliedBy(new d(v).dividedBy(100))
1537
- )), r[u.pool.suiCoinType] = d(r[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1538
- } else if (y.type === "navi-lending-emode-borrow") {
1539
- const u = y["navi-lending-emode-borrow"], f = this.resolveValueUSD(u), v = u.pool.borrowIncentiveApyInfo.apy;
1947
+ new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
1948
+ )), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
1949
+ } else if (g.type === "navi-lending-emode-supply") {
1950
+ const d = g["navi-lending-emode-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
1951
+ n.gt(0) && (c = c.plus(
1952
+ new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
1953
+ )), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
1954
+ } else if (g.type === "navi-lending-emode-borrow") {
1955
+ const d = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
1540
1956
  a.gt(0) && (i = i.plus(
1541
- new d(f).dividedBy(a).multipliedBy(new d(v).dividedBy(100))
1542
- )), n[u.pool.suiCoinType] = d(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1957
+ new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
1958
+ )), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
1543
1959
  }
1544
1960
  });
1545
- const m = o.minus(a), h = o.minus(a).eq(0) ? new d(0) : o.multipliedBy(c).minus(a.multipliedBy(i)).div(o.minus(a));
1961
+ const m = n.minus(a), w = n.minus(a).eq(0) ? new p(0) : n.multipliedBy(c).minus(a.multipliedBy(i)).div(n.minus(a));
1546
1962
  return {
1547
1963
  hf: a.toNumber() !== 0 ? s.dividedBy(a).toNumber() : 1 / 0,
1548
1964
  netVaule: m.toString(),
1549
- netWorthApr: h.toString(),
1550
- totalSupplyValue: o.toString(),
1965
+ netWorthApr: w.toString(),
1966
+ totalSupplyValue: n.toString(),
1551
1967
  totalBorrowValue: a.toString(),
1552
1968
  totalsupplyApy: c.toString(),
1553
1969
  totalBorrowApy: i.toString(),
1554
1970
  maxLiquidationValue: s.toString(),
1555
- maxLoanToVaule: p.toString(),
1971
+ maxLoanToVaule: l.toString(),
1556
1972
  supply: r,
1557
- borrow: n
1973
+ borrow: o
1558
1974
  };
1559
1975
  }
1560
1976
  }
1561
- async function bt(e, t, r, n) {
1562
- const o = await _({
1563
- ...n,
1564
- cacheTime: b
1977
+ async function dr(e, t, r, o) {
1978
+ const n = await j({
1979
+ ...o,
1980
+ cacheTime: v
1565
1981
  });
1566
- o.limter && e.moveCall({
1567
- target: `${o.limter}::navi_adaptor::verify_navi_position_healthy`,
1982
+ n.limter && e.moveCall({
1983
+ target: `${n.limter}::navi_adaptor::verify_navi_position_healthy`,
1568
1984
  arguments: [
1569
1985
  e.object("0x06"),
1570
- e.object(o.storage),
1571
- e.object(o.priceOracle),
1572
- g(t, e.pure.address),
1573
- e.pure.u256(new d(r).shiftedBy(27).toNumber())
1986
+ e.object(n.storage),
1987
+ e.object(n.priceOracle),
1988
+ h(t, e.pure.address),
1989
+ e.pure.u256(new p(r).shiftedBy(27).toNumber())
1574
1990
  ]
1575
1991
  });
1576
1992
  }
1577
- const ce = new te("https://hermes.pyth.network", {
1993
+ const Te = new he("https://hermes.pyth.network", {
1578
1994
  timeout: 1e4
1579
1995
  });
1580
- async function kt(e) {
1996
+ async function pr(e) {
1581
1997
  try {
1582
- const t = [], r = await ce.getLatestPriceFeeds(e);
1998
+ const t = [], r = await Te.getLatestPriceFeeds(e);
1583
1999
  if (!r) return t;
1584
- const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1585
- for (const o of r) {
1586
- const a = o.getPriceUnchecked();
1587
- if (a.publishTime > n) {
2000
+ const o = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
2001
+ for (const n of r) {
2002
+ const a = n.getPriceUnchecked();
2003
+ if (a.publishTime > o) {
1588
2004
  console.warn(
1589
- `pyth price feed is invalid, id: ${o.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
2005
+ `pyth price feed is invalid, id: ${n.id}, publish time: ${a.publishTime}, current timestamp: ${o}`
1590
2006
  );
1591
2007
  continue;
1592
2008
  }
1593
- n - o.getPriceUnchecked().publishTime > 30 && (console.info(
1594
- `stale price feed, id: ${o.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
1595
- ), t.push(o.id));
2009
+ o - n.getPriceUnchecked().publishTime > 30 && (console.info(
2010
+ `stale price feed, id: ${n.id}, publish time: ${a.publishTime}, current timestamp: ${o}`
2011
+ ), t.push(n.id));
1596
2012
  }
1597
2013
  return t;
1598
2014
  } catch (t) {
1599
2015
  throw new Error(`failed to get pyth stale price feed id, msg: ${t.message}`);
1600
2016
  }
1601
2017
  }
1602
- async function Le(e, t) {
2018
+ async function Tt(e, t) {
1603
2019
  try {
1604
- const r = [], n = t?.client ?? V, o = e.map((c) => c.priceInfoObject), a = await n.multiGetObjects({
1605
- ids: Array.from(new Set(o)),
2020
+ const r = [], o = t?.client ?? V, n = e.map((c) => c.priceInfoObject), a = await mt(o, {
2021
+ ids: Array.from(new Set(n)),
1606
2022
  options: { showContent: !0 }
1607
2023
  });
1608
2024
  for (const c of a) {
@@ -1611,18 +2027,23 @@ async function Le(e, t) {
1611
2027
  console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
1612
2028
  continue;
1613
2029
  }
1614
- const s = e.find((u) => u.priceInfoObject == i.objectId);
2030
+ const s = e.find((f) => f.priceInfoObject == i.objectId);
1615
2031
  if (!s) {
1616
2032
  console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
1617
2033
  continue;
1618
2034
  }
1619
- const p = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: m, negative: h } = p.price.fields, w = p.conf, y = p.timestamp;
2035
+ const l = i.content.fields?.price_info?.price_feed?.price, m = l?.price;
2036
+ if (!m) {
2037
+ console.warn(`unexpected pyth price struct, priceInfoObject: ${i.objectId}`);
2038
+ continue;
2039
+ }
2040
+ const { magnitude: w, negative: y } = m, g = l.conf, d = l.timestamp;
1620
2041
  r.push({
1621
2042
  priceFeedId: s.priceFeedId,
1622
2043
  priceInfoObject: s.priceInfoObject,
1623
- price: h ? "-" + m : m,
1624
- conf: w,
1625
- publishTime: Number(y),
2044
+ price: y ? "-" + w : w,
2045
+ conf: g,
2046
+ publishTime: Number(d),
1626
2047
  expiration: s.expiration
1627
2048
  });
1628
2049
  }
@@ -1632,21 +2053,21 @@ async function Le(e, t) {
1632
2053
  return;
1633
2054
  }
1634
2055
  }
1635
- async function He(e, t) {
2056
+ async function Bt(e, t) {
1636
2057
  try {
1637
- const r = [], n = await Le(e, t);
1638
- if (!n) return r;
1639
- const o = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1640
- for (const a of n) {
1641
- if (a.publishTime > o) {
2058
+ const r = [], o = await Tt(e, t);
2059
+ if (!o) return r;
2060
+ const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
2061
+ for (const a of o) {
2062
+ if (a.publishTime > n) {
1642
2063
  console.warn(
1643
- `pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${o}`
2064
+ `pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${n}`
1644
2065
  );
1645
2066
  continue;
1646
2067
  }
1647
2068
  const c = a.expiration || 60;
1648
- o - a.publishTime > c && (console.info(
1649
- `stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${o}`
2069
+ n - a.publishTime > c && (console.info(
2070
+ `stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${n}`
1650
2071
  ), r.push(a.priceFeedId));
1651
2072
  }
1652
2073
  return r;
@@ -1654,204 +2075,209 @@ async function He(e, t) {
1654
2075
  throw new Error(`failed to get pyth stale price feed id, msg: ${r.message}`);
1655
2076
  }
1656
2077
  }
1657
- async function We(e, t, r) {
1658
- const n = r?.client ?? V, o = await _({
2078
+ async function Pt(e, t, r) {
2079
+ const o = r?.client ?? V, n = await j({
1659
2080
  ...r,
1660
- cacheTime: b
2081
+ cacheTime: v
1661
2082
  });
1662
2083
  try {
1663
- const a = await ce.getPriceFeedsUpdateData(t);
1664
- return await new $e(
1665
- n,
1666
- o.oracle.pythStateId,
1667
- o.oracle.wormholeStateId
2084
+ const a = await Te.getPriceFeedsUpdateData(t);
2085
+ return await new ct(
2086
+ o,
2087
+ n.oracle.pythStateId,
2088
+ n.oracle.wormholeStateId
1668
2089
  ).updatePriceFeeds(e, a, t);
1669
2090
  } catch (a) {
1670
2091
  throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
1671
2092
  }
1672
2093
  }
1673
- async function ze(e, t, r) {
1674
- const n = await _({
2094
+ async function At(e, t, r) {
2095
+ const o = await j({
1675
2096
  ...r,
1676
- cacheTime: b
2097
+ cacheTime: v
1677
2098
  });
1678
2099
  if (r?.updatePythPriceFeeds) {
1679
- const o = t.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
2100
+ const n = t.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
1680
2101
  priceFeedId: a.pythPriceFeedId,
1681
2102
  priceInfoObject: a.pythPriceInfoObject,
1682
2103
  expiration: 30
1683
2104
  }));
1684
2105
  try {
1685
- const a = await He(o, r);
1686
- a.length > 0 && await We(e, a, r);
2106
+ const a = await Bt(n, r);
2107
+ a.length > 0 && await Pt(e, a, r);
1687
2108
  } catch {
1688
2109
  console.error("Failed to update Pyth price feeds");
1689
2110
  }
1690
2111
  }
1691
- for (const o of t)
2112
+ for (const n of t)
1692
2113
  r?.env === "dev" ? e.moveCall({
1693
- target: `${n.oracle.packageId}::oracle_pro::update_single_price`,
2114
+ target: `${o.oracle.packageId}::oracle_pro::update_single_price`,
1694
2115
  arguments: [
1695
2116
  e.object("0x6"),
1696
2117
  // Clock object
1697
- e.object(n.oracle.oracleConfig),
2118
+ e.object(o.oracle.oracleConfig),
1698
2119
  // Oracle configuration
1699
- e.object(n.oracle.priceOracle),
2120
+ e.object(o.oracle.priceOracle),
1700
2121
  // Price oracle contract
1701
- e.object(n.oracle.supraOracleHolder),
2122
+ e.object(o.oracle.supraOracleHolder),
1702
2123
  // Supra oracle holder
1703
- e.object(o.pythPriceInfoObject),
2124
+ e.object(n.pythPriceInfoObject),
1704
2125
  // Pyth price info object
1705
- e.pure.address(o.feedId)
2126
+ e.pure.address(n.feedId)
1706
2127
  // Price feed ID
1707
2128
  ]
1708
2129
  }) : e.moveCall({
1709
- target: `${n.oracle.packageId}::oracle_pro::update_single_price_v2`,
2130
+ target: `${o.oracle.packageId}::oracle_pro::update_single_price_v2`,
1710
2131
  arguments: [
1711
2132
  e.object("0x6"),
1712
2133
  // Clock object
1713
- e.object(n.oracle.oracleConfig),
2134
+ e.object(o.oracle.oracleConfig),
1714
2135
  // Oracle configuration
1715
- e.object(n.oracle.priceOracle),
2136
+ e.object(o.oracle.priceOracle),
1716
2137
  // Price oracle contract
1717
- e.object(n.oracle.supraOracleHolder),
2138
+ e.object(o.oracle.supraOracleHolder),
1718
2139
  // Supra oracle holder
1719
- e.object(o.pythPriceInfoObject),
2140
+ e.object(n.pythPriceInfoObject),
1720
2141
  // Pyth price info object
1721
- e.object(n.oracle.switchboardAggregator),
1722
- e.pure.address(o.feedId)
2142
+ e.object(o.oracle.switchboardAggregator),
2143
+ e.pure.address(n.feedId)
1723
2144
  // Price feed ID
1724
2145
  ]
1725
2146
  });
1726
2147
  return e;
1727
2148
  }
1728
- async function se(e) {
1729
- return (await _({
2149
+ async function Be(e) {
2150
+ return (await j({
1730
2151
  ...e,
1731
- cacheTime: b
2152
+ cacheTime: v
1732
2153
  })).oracle.feeds;
1733
2154
  }
1734
- function Ge(e, t) {
1735
- return e.filter((r) => !!(t?.lendingState && t.lendingState.find((o) => r.oracleId === o.pool.oracleId) || t?.lendingPositions && t.lendingPositions.find((o) => {
2155
+ function St(e, t) {
2156
+ return e.filter((r) => !!(t?.lendingState && t.lendingState.find((n) => r.oracleId === n.pool.oracleId) || t?.lendingPositions && t.lendingPositions.find((n) => {
1736
2157
  if (![
1737
2158
  "navi-lending-supply",
1738
2159
  "navi-lending-borrow",
1739
2160
  "navi-lending-emode-supply",
1740
2161
  "navi-lending-emode-borrow"
1741
- ].includes(o.type))
2162
+ ].includes(n.type))
1742
2163
  return !1;
1743
- const c = o[o.type]?.pool;
2164
+ const c = n[n.type]?.pool;
1744
2165
  return r.oracleId === c?.oracleId;
1745
- }) || t?.pools && t.pools.find((o) => r.oracleId === o.oracleId)));
2166
+ }) || t?.pools && t.pools.find((n) => r.oracleId === n.oracleId)));
1746
2167
  }
1747
- async function _t(e, t, r, n) {
2168
+ async function mr(e, t, r, o) {
1748
2169
  try {
1749
- const o = await se({
1750
- ...n
2170
+ const n = await Be({
2171
+ ...o
1751
2172
  }), a = [];
1752
- r.forEach((p) => {
1753
- a.includes(p.market) || a.push(p.market);
2173
+ r.forEach((l) => {
2174
+ a.includes(l.market) || a.push(l.market);
1754
2175
  });
1755
- const c = await qe(t, {
1756
- ...n,
2176
+ const c = await _t(t, {
2177
+ ...o,
1757
2178
  markets: a
1758
- }), i = Ge(o, {
2179
+ }), i = St(n, {
1759
2180
  lendingPositions: c,
1760
2181
  pools: r
1761
2182
  });
1762
- return await ze(e, i, {
2183
+ return await At(e, i, {
1763
2184
  updatePythPriceFeeds: !0,
1764
- ...n
2185
+ ...o
1765
2186
  });
1766
- } catch (o) {
1767
- if (n?.throws)
1768
- throw o;
1769
- return console.error(o), e;
2187
+ } catch (n) {
2188
+ if (o?.throws)
2189
+ throw n;
2190
+ return console.error(n), e;
1770
2191
  }
1771
2192
  }
1772
- const Y = S(
2193
+ const re = $(
1773
2194
  A(
1774
2195
  async (e) => {
1775
- const t = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${M.version}&market=${e?.market || O}`, r = await fetch(t, { headers: E }).then((n) => n.json());
1776
- return Object.keys(r.data).map((n) => ({
1777
- ...r.data[n],
2196
+ const t = E(e), r = M(
2197
+ `/navi/flashloan?env=${e?.env || "prod"}&sdk=${O.version}&market=${e?.market || R}`,
2198
+ e
2199
+ ), o = await fetch(r, {
2200
+ headers: D(U, t)
2201
+ }).then((n) => n.json());
2202
+ return Object.keys(o.data).map((n) => ({
2203
+ ...o.data[n],
1778
2204
  coinType: n
1779
2205
  }));
1780
2206
  }
1781
2207
  )
1782
2208
  );
1783
- async function jt(e, t) {
1784
- return (await Y(t)).find((n) => typeof e == "string" ? k(n.coinType) === k(e) : typeof e == "number" ? n.assetId === e : n.assetId === e.id) || null;
2209
+ async function fr(e, t) {
2210
+ return (await re(t)).find((o) => typeof e == "string" ? C(o.coinType) === C(e) : typeof e == "number" ? o.assetId === e : o.assetId === e.id) || null;
1785
2211
  }
1786
- async function It(e, t, r, n) {
1787
- const o = await _({
1788
- ...n,
1789
- cacheTime: b
1790
- }), a = await $(t, n);
1791
- if (!(await Y({
1792
- ...n,
1793
- cacheTime: b
2212
+ async function yr(e, t, r, o) {
2213
+ const n = await j({
2214
+ ...o,
2215
+ cacheTime: v
2216
+ }), a = await S(t, o);
2217
+ if (!(await re({
2218
+ ...o,
2219
+ cacheTime: v
1794
2220
  })).some(
1795
- (s) => k(s.coinType) === k(a.suiCoinType)
2221
+ (s) => C(s.coinType) === C(a.suiCoinType)
1796
2222
  ))
1797
2223
  throw new Error("Pool does not support flashloan");
1798
- if (o.version === 1) {
1799
- const [s, p] = e.moveCall({
1800
- target: `${o.package}::lending::flash_loan_with_ctx`,
2224
+ if (n.version === 1) {
2225
+ const [s, l] = e.moveCall({
2226
+ target: `${n.package}::lending::flash_loan_with_ctx`,
1801
2227
  arguments: [
1802
- e.object(o.flashloanConfig),
2228
+ e.object(n.flashloanConfig),
1803
2229
  e.object(a.contract.pool),
1804
- g(r, e.pure.u64)
2230
+ h(r, e.pure.u64)
1805
2231
  ],
1806
2232
  typeArguments: [a.suiCoinType]
1807
2233
  });
1808
- return [s, p];
2234
+ return [s, l];
1809
2235
  } else {
1810
- const [s, p] = e.moveCall({
1811
- target: `${o.package}::lending::flash_loan_with_ctx_v2`,
2236
+ const [s, l] = e.moveCall({
2237
+ target: `${n.package}::lending::flash_loan_with_ctx_v2`,
1812
2238
  arguments: [
1813
- e.object(o.flashloanConfig),
2239
+ e.object(n.flashloanConfig),
1814
2240
  e.object(a.contract.pool),
1815
- g(r, e.pure.u64),
2241
+ h(r, e.pure.u64),
1816
2242
  e.object("0x05")
1817
2243
  ],
1818
2244
  typeArguments: [a.suiCoinType]
1819
2245
  });
1820
- return [s, p];
2246
+ return [s, l];
1821
2247
  }
1822
2248
  }
1823
- async function Ct(e, t, r, n, o) {
1824
- const a = await _({
1825
- ...o,
1826
- cacheTime: b
1827
- }), c = await $(t, o);
1828
- if (!(await Y({
1829
- ...o,
1830
- cacheTime: b
2249
+ async function gr(e, t, r, o, n) {
2250
+ const a = await j({
2251
+ ...n,
2252
+ cacheTime: v
2253
+ }), c = await S(t, n);
2254
+ if (!(await re({
2255
+ ...n,
2256
+ cacheTime: v
1831
2257
  })).some(
1832
- (m) => k(m.coinType) === k(c.suiCoinType)
2258
+ (m) => C(m.coinType) === C(c.suiCoinType)
1833
2259
  ))
1834
2260
  throw new Error("Pool does not support flashloan");
1835
- const [p] = e.moveCall({
2261
+ const [l] = e.moveCall({
1836
2262
  target: `${a.package}::lending::flash_repay_with_ctx`,
1837
2263
  arguments: [
1838
2264
  e.object("0x06"),
1839
2265
  e.object(a.storage),
1840
2266
  e.object(c.contract.pool),
1841
- g(r, e.object),
1842
- g(n, e.object)
2267
+ h(r, e.object),
2268
+ h(o, e.object)
1843
2269
  ],
1844
2270
  typeArguments: [c.suiCoinType]
1845
2271
  });
1846
- return [p];
2272
+ return [l];
1847
2273
  }
1848
- async function Tt(e, t, r, n, o, a) {
2274
+ async function hr(e, t, r, o, n, a) {
1849
2275
  const c = {
1850
2276
  ...a,
1851
- cacheTime: b
1852
- }, i = await _(c), s = await $(t, c), p = await $(n, c);
2277
+ cacheTime: v
2278
+ }, i = await j(c), s = await S(t, c), l = await S(o, c);
1853
2279
  if (i.version === 1) {
1854
- const [m, h] = e.moveCall({
2280
+ const [m, w] = e.moveCall({
1855
2281
  target: `${i.package}::incentive_v3::liquidation`,
1856
2282
  arguments: [
1857
2283
  e.object("0x06"),
@@ -1864,24 +2290,24 @@ async function Tt(e, t, r, n, o, a) {
1864
2290
  // Pay asset ID
1865
2291
  e.object(s.contract.pool),
1866
2292
  // Pay asset pool contract
1867
- g(r, e.object),
2293
+ h(r, e.object),
1868
2294
  // Debt repayment amount
1869
- e.pure.u8(p.id),
2295
+ e.pure.u8(l.id),
1870
2296
  // Collateral asset ID
1871
- e.object(p.contract.pool),
2297
+ e.object(l.contract.pool),
1872
2298
  // Collateral asset pool contract
1873
- g(o, e.pure.address),
2299
+ h(n, e.pure.address),
1874
2300
  // Borrower address
1875
2301
  e.object(i.incentiveV2),
1876
2302
  // Incentive V2 contract
1877
2303
  e.object(i.incentiveV3)
1878
2304
  // Incentive V3 contract
1879
2305
  ],
1880
- typeArguments: [s.suiCoinType, p.suiCoinType]
2306
+ typeArguments: [s.suiCoinType, l.suiCoinType]
1881
2307
  });
1882
- return [m, h];
2308
+ return [m, w];
1883
2309
  } else {
1884
- const [m, h] = e.moveCall({
2310
+ const [m, w] = e.moveCall({
1885
2311
  target: `${i.package}::incentive_v3::liquidation_v2`,
1886
2312
  arguments: [
1887
2313
  e.object("0x06"),
@@ -1894,13 +2320,13 @@ async function Tt(e, t, r, n, o, a) {
1894
2320
  // Pay asset ID
1895
2321
  e.object(s.contract.pool),
1896
2322
  // Pay asset pool contract
1897
- g(r, e.object),
2323
+ h(r, e.object),
1898
2324
  // Debt repayment amount
1899
- e.pure.u8(p.id),
2325
+ e.pure.u8(l.id),
1900
2326
  // Collateral asset ID
1901
- e.object(p.contract.pool),
2327
+ e.object(l.contract.pool),
1902
2328
  // Collateral asset pool contract
1903
- g(o, e.pure.address),
2329
+ h(n, e.pure.address),
1904
2330
  // Borrower address
1905
2331
  e.object(i.incentiveV2),
1906
2332
  // Incentive V2 contract
@@ -1909,104 +2335,102 @@ async function Tt(e, t, r, n, o, a) {
1909
2335
  e.object("0x05")
1910
2336
  // SuiSystemState object
1911
2337
  ],
1912
- typeArguments: [s.suiCoinType, p.suiCoinType]
2338
+ typeArguments: [s.suiCoinType, l.suiCoinType]
1913
2339
  });
1914
- return [m, h];
2340
+ return [m, w];
1915
2341
  }
1916
2342
  }
1917
- async function Ke(e, t, r) {
1918
- const n = r?.client ?? V, o = new F(), a = await R({
2343
+ async function $t(e, t, r) {
2344
+ const o = r?.client ?? V, n = await G({
1919
2345
  ...r,
1920
- markets: Object.values(U),
1921
- cacheTime: b
1922
- }), c = await se(r);
1923
- for (let m of t) {
1924
- const h = await _({
1925
- ...r,
1926
- cacheTime: b,
1927
- market: m.market
1928
- });
1929
- o.moveCall({
1930
- target: `${h.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
1931
- arguments: [
1932
- o.object("0x06"),
1933
- // Clock object
1934
- o.object(h.storage),
1935
- // Protocol storage
1936
- o.object(h.incentiveV3),
1937
- // Incentive V3 contract
1938
- o.pure.address(m.address)
1939
- // User address
1940
- ]
1941
- });
1942
- }
1943
- const i = await n.devInspectTransactionBlock({
1944
- transactionBlock: o,
1945
- sender: e
1946
- }), s = [];
1947
- i?.results?.forEach((m) => {
1948
- s.push(
1949
- H(
1950
- {
1951
- results: [m]
1952
- },
1953
- [
1954
- l.vector(l.string()),
2346
+ markets: Object.values(F),
2347
+ cacheTime: v
2348
+ }), a = await Be(r), c = [];
2349
+ return await Promise.all(
2350
+ t.map(async (i) => {
2351
+ try {
2352
+ const s = await j({
2353
+ ...r,
2354
+ cacheTime: v,
2355
+ market: i.market
2356
+ }), l = new N();
2357
+ l.moveCall({
2358
+ target: `${s.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
2359
+ arguments: [
2360
+ l.object("0x06"),
2361
+ // Clock object
2362
+ l.object(s.storage),
2363
+ // Protocol storage
2364
+ l.object(s.incentiveV3),
2365
+ // Incentive V3 contract
2366
+ l.pure.address(i.address)
2367
+ // User address
2368
+ ]
2369
+ });
2370
+ const w = (await q(o, {
2371
+ transactionBlock: l,
2372
+ sender: e
2373
+ }))?.results?.[0];
2374
+ if (!w)
2375
+ return;
2376
+ const y = Q({ results: [w] }, [
2377
+ u.vector(u.string()),
1955
2378
  // Asset coin types
1956
- l.vector(l.string()),
2379
+ u.vector(u.string()),
1957
2380
  // Reward coin types
1958
- l.vector(l.u8()),
2381
+ u.vector(u.u8()),
1959
2382
  // Reward options
1960
- l.vector(l.Address),
2383
+ u.vector(u.Address),
1961
2384
  // Rule IDs
1962
- l.vector(l.u256())
2385
+ u.vector(u.u256())
1963
2386
  // Claimable amounts
1964
- ]
1965
- )
1966
- );
1967
- });
1968
- const p = [];
1969
- return s.forEach((m, h) => {
1970
- const w = t[h];
1971
- if (m.length === 5 && Array.isArray(m[0])) {
1972
- const y = m[0].length;
1973
- for (let u = 0; u < y; u++) {
1974
- const f = c.find(
1975
- (I) => k(I.coinType) === k(m[1][u])
1976
- ), v = a.find(
1977
- (I) => k(I.coinType) === k(m[0][u]) && I.market === w.market
2387
+ ]);
2388
+ if (y.length === 5 && Array.isArray(y[0])) {
2389
+ const g = y[0].length;
2390
+ for (let d = 0; d < g; d++) {
2391
+ const f = a.find(
2392
+ (k) => C(k.coinType) === C(y[1][d])
2393
+ ), b = n.find(
2394
+ (k) => C(k.coinType) === C(y[0][d]) && k.market === i.market
2395
+ );
2396
+ !f || !b || c.push({
2397
+ assetId: b.id,
2398
+ assetCoinType: C(y[0][d]),
2399
+ rewardCoinType: C(y[1][d]),
2400
+ option: Number(y[2][d]),
2401
+ userClaimableReward: Number(y[4][d]) / Math.pow(10, f.priceDecimal),
2402
+ ruleIds: Array.isArray(y[3][d]) ? y[3][d] : [y[3][d]],
2403
+ market: i.market,
2404
+ owner: i.owner,
2405
+ address: i.address,
2406
+ emodeId: i.emodeId
2407
+ });
2408
+ }
2409
+ }
2410
+ } catch (s) {
2411
+ console.error(
2412
+ `[lending] getLendingRewardsBatch task failed (market=${i.market}, address=${i.address}):`,
2413
+ s
1978
2414
  );
1979
- !f || !v || p.push({
1980
- assetId: v.id,
1981
- assetCoinType: k(m[0][u]),
1982
- rewardCoinType: k(m[1][u]),
1983
- option: Number(m[2][u]),
1984
- userClaimableReward: Number(m[4][u]) / Math.pow(10, f.priceDecimal),
1985
- ruleIds: Array.isArray(m[3][u]) ? m[3][u] : [m[3][u]],
1986
- market: w.market,
1987
- owner: w.owner,
1988
- address: w.address,
1989
- emodeId: w.emodeId
1990
- });
1991
2415
  }
1992
- }
1993
- }), p;
2416
+ })
2417
+ ), c;
1994
2418
  }
1995
- async function Pt(e, t) {
1996
- const r = (t?.markets || [U.main]).map((a) => C(a));
1997
- let n = [];
2419
+ async function wr(e, t) {
2420
+ const r = (t?.markets || [F.main]).map((a) => _(a));
2421
+ let o = [];
1998
2422
  try {
1999
- n = await ne(e, t);
2423
+ o = await ke(e, t);
2000
2424
  } catch (a) {
2001
2425
  console.error(a);
2002
2426
  }
2003
- const o = r.map((a) => ({
2427
+ const n = r.map((a) => ({
2004
2428
  address: e,
2005
2429
  owner: e,
2006
2430
  market: a.key
2007
2431
  })).concat(
2008
- n.filter((a) => !!r.find((c) => c.id === a.marketId)).map((a) => {
2009
- const c = C(a.marketId);
2432
+ o.filter((a) => !!r.find((c) => c.id === a.marketId)).map((a) => {
2433
+ const c = _(a.marketId);
2010
2434
  return {
2011
2435
  address: a.accountCap,
2012
2436
  owner: e,
@@ -2015,100 +2439,110 @@ async function Pt(e, t) {
2015
2439
  };
2016
2440
  })
2017
2441
  );
2018
- return await Ke(e, o, t);
2442
+ return await $t(e, n, t);
2019
2443
  }
2020
- function Bt(e) {
2444
+ function br(e) {
2021
2445
  const t = /* @__PURE__ */ new Map();
2022
- e.forEach((n) => {
2023
- const o = n.assetId, a = n.option, c = `${o}-${a}-${n.rewardCoinType}-${n.market}`;
2024
- t.has(c) ? t.get(c).total += n.userClaimableReward : t.set(c, {
2025
- assetId: o,
2446
+ e.forEach((o) => {
2447
+ const n = o.assetId, a = o.option, c = `${n}-${a}-${o.rewardCoinType}-${o.market}`;
2448
+ t.has(c) ? t.get(c).total += o.userClaimableReward : t.set(c, {
2449
+ assetId: n,
2026
2450
  rewardType: a,
2027
- coinType: n.rewardCoinType,
2028
- total: Number(n.userClaimableReward),
2029
- market: n.market
2451
+ coinType: o.rewardCoinType,
2452
+ total: Number(o.userClaimableReward),
2453
+ market: o.market
2030
2454
  });
2031
2455
  });
2032
2456
  const r = /* @__PURE__ */ new Map();
2033
- for (const { assetId: n, rewardType: o, coinType: a, total: c, market: i } of t.values()) {
2034
- const s = `${n}-${o}-${i}`;
2035
- r.has(s) || r.set(s, { assetId: n, rewardType: o, market: i, rewards: /* @__PURE__ */ new Map() });
2036
- const p = r.get(s);
2037
- p.rewards.set(a, (p.rewards.get(a) || 0) + c);
2038
- }
2039
- return Array.from(r.values()).map((n) => ({
2040
- assetId: n.assetId,
2041
- rewardType: n.rewardType,
2042
- market: n.market,
2043
- rewards: Array.from(n.rewards.entries()).map(([o, a]) => ({
2044
- coinType: o,
2457
+ for (const { assetId: o, rewardType: n, coinType: a, total: c, market: i } of t.values()) {
2458
+ const s = `${o}-${n}-${i}`;
2459
+ r.has(s) || r.set(s, { assetId: o, rewardType: n, market: i, rewards: /* @__PURE__ */ new Map() });
2460
+ const l = r.get(s);
2461
+ l.rewards.set(a, (l.rewards.get(a) || 0) + c);
2462
+ }
2463
+ return Array.from(r.values()).map((o) => ({
2464
+ assetId: o.assetId,
2465
+ rewardType: o.rewardType,
2466
+ market: o.market,
2467
+ rewards: Array.from(o.rewards.entries()).map(([n, a]) => ({
2468
+ coinType: n,
2045
2469
  available: a.toFixed(6)
2046
2470
  }))
2047
2471
  }));
2048
2472
  }
2049
- const At = A(
2473
+ const vr = A(
2050
2474
  async (e, t) => {
2051
- const r = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${M.version}&market=${t?.market || O}`;
2052
- return (await fetch(r, { headers: E }).then((o) => o.json())).data;
2475
+ const r = E(t), o = M(
2476
+ `/navi/user/total_claimed_reward?userAddress=${e}&sdk=${O.version}&market=${t?.market || R}`,
2477
+ t
2478
+ );
2479
+ return (await fetch(o, {
2480
+ headers: D(U, r)
2481
+ }).then((a) => a.json())).data;
2053
2482
  }
2054
- ), $t = A(
2483
+ ), Cr = A(
2055
2484
  async (e, t) => {
2056
- const r = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${t?.page || 1}&pageSize=${t?.size || 400}&sdk=${M.version}&market=${t?.market || O}`, n = await fetch(r, { headers: E }).then((o) => o.json());
2057
- return G({
2485
+ const r = E(t), o = M(
2486
+ `/navi/user/rewards?userAddress=${e}&page=${t?.page || 1}&pageSize=${t?.size || 400}&sdk=${O.version}&market=${t?.market || R}`,
2487
+ t
2488
+ ), n = await fetch(o, {
2489
+ headers: D(U, r)
2490
+ }).then((a) => a.json());
2491
+ return x({
2058
2492
  data: n.data.rewards
2059
2493
  });
2060
2494
  }
2061
2495
  );
2062
- async function St(e, t, r) {
2063
- const n = await R({
2496
+ async function jr(e, t, r) {
2497
+ const o = await G({
2064
2498
  ...r,
2065
- markets: Object.values(U),
2066
- cacheTime: b
2067
- }), o = /* @__PURE__ */ new Map();
2499
+ markets: Object.values(F),
2500
+ cacheTime: v
2501
+ }), n = /* @__PURE__ */ new Map();
2068
2502
  for (const c of t) {
2069
- const { rewardCoinType: i, ruleIds: s, market: p, owner: m, address: h, emodeId: w } = c, y = `${i}___${h}__${p}`;
2070
- for (const u of s) {
2071
- o.has(y) || o.set(y, {
2503
+ const { rewardCoinType: i, ruleIds: s, market: l, owner: m, address: w, emodeId: y } = c, g = `${i}___${w}__${l}`;
2504
+ for (const d of s) {
2505
+ n.has(g) || n.set(g, {
2072
2506
  assetIds: [],
2073
2507
  ruleIds: [],
2074
2508
  amount: 0,
2075
- market: p,
2509
+ market: l,
2076
2510
  owner: m,
2077
- address: h,
2078
- isEMode: typeof w < "u"
2511
+ address: w,
2512
+ isEMode: typeof y < "u"
2079
2513
  });
2080
- const f = o.get(y);
2081
- f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(u), f.amount += c.userClaimableReward;
2514
+ const f = n.get(g);
2515
+ f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(d), f.amount += c.userClaimableReward;
2082
2516
  }
2083
2517
  }
2084
2518
  const a = [];
2085
2519
  for (const [
2086
2520
  c,
2087
- { assetIds: i, ruleIds: s, amount: p, market: m, owner: h, address: w, isEMode: y }
2088
- ] of o) {
2089
- const u = await _({
2521
+ { assetIds: i, ruleIds: s, amount: l, market: m, owner: w, address: y, isEMode: g }
2522
+ ] of n) {
2523
+ const d = await j({
2090
2524
  ...r,
2091
- cacheTime: b,
2525
+ cacheTime: v,
2092
2526
  market: m
2093
- }), f = c.split("___")[0], v = n.filter(
2094
- (j) => k(j.suiCoinType) === k(f)
2527
+ }), f = c.split("___")[0], b = o.filter(
2528
+ (I) => C(I.suiCoinType) === C(f)
2095
2529
  );
2096
- v.sort((j, P) => j.market === m ? -1 : 1);
2097
- const I = v[0], T = u.rewardFunds[k(f)];
2530
+ b.sort((I, B) => I.market === m ? -1 : 1);
2531
+ const k = b[0], T = d.rewardFunds[C(f)];
2098
2532
  if (!T)
2099
2533
  throw new Error(`No matching rewardFund found for reward coin: ${f} ${m}`);
2100
2534
  if (r?.accountCap && !r.customCoinReceive)
2101
2535
  throw new Error("customCoinReceive is required when accountCap is provided");
2102
2536
  if (r?.customCoinReceive) {
2103
- let j;
2104
- r.accountCap ? j = e.moveCall({
2105
- target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
2537
+ let I;
2538
+ r.accountCap ? I = e.moveCall({
2539
+ target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
2106
2540
  arguments: [
2107
2541
  e.object("0x06"),
2108
2542
  // Clock object
2109
- e.object(u.incentiveV3),
2543
+ e.object(d.incentiveV3),
2110
2544
  // Incentive V3 contract
2111
- e.object(u.storage),
2545
+ e.object(d.storage),
2112
2546
  // Protocol storage
2113
2547
  e.object(T),
2114
2548
  // Reward fund
@@ -2116,18 +2550,18 @@ async function St(e, t, r) {
2116
2550
  // Asset IDs
2117
2551
  e.pure.vector("address", s),
2118
2552
  // Rule IDs
2119
- g(r.accountCap, e.object)
2553
+ h(r.accountCap, e.object)
2120
2554
  // Account capability
2121
2555
  ],
2122
2556
  typeArguments: [f]
2123
- }) : y ? j = e.moveCall({
2124
- target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
2557
+ }) : g ? I = e.moveCall({
2558
+ target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
2125
2559
  arguments: [
2126
2560
  e.object("0x06"),
2127
2561
  // Clock object
2128
- e.object(u.incentiveV3),
2562
+ e.object(d.incentiveV3),
2129
2563
  // Incentive V3 contract
2130
- e.object(u.storage),
2564
+ e.object(d.storage),
2131
2565
  // Protocol storage
2132
2566
  e.object(T),
2133
2567
  // Reward fund
@@ -2135,18 +2569,18 @@ async function St(e, t, r) {
2135
2569
  // Asset IDs
2136
2570
  e.pure.vector("address", s),
2137
2571
  // Rule IDs
2138
- g(w, e.object)
2572
+ h(y, e.object)
2139
2573
  // Account capability
2140
2574
  ],
2141
2575
  typeArguments: [f]
2142
- }) : j = e.moveCall({
2143
- target: `${u.package}::incentive_v3::claim_reward`,
2576
+ }) : I = e.moveCall({
2577
+ target: `${d.package}::incentive_v3::claim_reward`,
2144
2578
  arguments: [
2145
2579
  e.object("0x06"),
2146
2580
  // Clock object
2147
- e.object(u.incentiveV3),
2581
+ e.object(d.incentiveV3),
2148
2582
  // Incentive V3 contract
2149
- e.object(u.storage),
2583
+ e.object(d.storage),
2150
2584
  // Protocol storage
2151
2585
  e.object(T),
2152
2586
  // Reward fund
@@ -2157,44 +2591,44 @@ async function St(e, t, r) {
2157
2591
  ],
2158
2592
  typeArguments: [f]
2159
2593
  });
2160
- const [P] = e.moveCall({
2594
+ const [B] = e.moveCall({
2161
2595
  target: "0x2::coin::from_balance",
2162
- arguments: [j],
2596
+ arguments: [I],
2163
2597
  typeArguments: [f]
2164
2598
  });
2165
2599
  if (r?.customCoinReceive.type === "transfer") {
2166
2600
  if (!r.customCoinReceive.transfer)
2167
2601
  throw new Error("customCoinReceive.transfer is required");
2168
2602
  e.transferObjects(
2169
- [P],
2170
- g(r.customCoinReceive.transfer, e.pure.address)
2603
+ [B],
2604
+ h(r.customCoinReceive.transfer, e.pure.address)
2171
2605
  );
2172
2606
  }
2173
2607
  if (r?.customCoinReceive.type === "depositNAVI") {
2174
- const q = d(I.totalSupplyAmount).shiftedBy(-9), W = d(I.supplyCapCeiling).shiftedBy(-27);
2175
- q.plus(p).isGreaterThan(W) && r?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
2176
- [P],
2608
+ const W = p(k.totalSupplyAmount).shiftedBy(-9), Y = p(k.supplyCapCeiling).shiftedBy(-27);
2609
+ W.plus(l).isGreaterThan(Y) && r?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
2610
+ [B],
2177
2611
  e.pure.address(r.customCoinReceive.depositNAVI.fallbackReceiveAddress)
2178
- ) : await Ee(e, I, P, {
2612
+ ) : await ht(e, k, B, {
2179
2613
  ...r,
2180
- market: I.market
2614
+ market: k.market
2181
2615
  });
2182
2616
  } else
2183
2617
  a.push({
2184
- coin: P,
2185
- identifier: I,
2186
- owner: h,
2187
- isEMode: y
2618
+ coin: B,
2619
+ identifier: k,
2620
+ owner: w,
2621
+ isEMode: g
2188
2622
  });
2189
- } else if (r?.accountCap || y) {
2190
- const j = e.moveCall({
2191
- target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
2623
+ } else if (r?.accountCap || g) {
2624
+ const I = e.moveCall({
2625
+ target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
2192
2626
  arguments: [
2193
2627
  e.object("0x06"),
2194
2628
  // Clock object
2195
- e.object(u.incentiveV3),
2629
+ e.object(d.incentiveV3),
2196
2630
  // Incentive V3 contract
2197
- e.object(u.storage),
2631
+ e.object(d.storage),
2198
2632
  // Protocol storage
2199
2633
  e.object(T),
2200
2634
  // Reward fund
@@ -2202,28 +2636,28 @@ async function St(e, t, r) {
2202
2636
  // Asset IDs
2203
2637
  e.pure.vector("address", s),
2204
2638
  // Rule IDs
2205
- g(r?.accountCap || w, e.object)
2639
+ h(r?.accountCap || y, e.object)
2206
2640
  // Account capability
2207
2641
  ],
2208
2642
  typeArguments: [f]
2209
- }), [P] = e.moveCall({
2643
+ }), [B] = e.moveCall({
2210
2644
  target: "0x2::coin::from_balance",
2211
- arguments: [j],
2645
+ arguments: [I],
2212
2646
  typeArguments: [f]
2213
2647
  });
2214
2648
  e.transferObjects(
2215
- [P],
2216
- g(r?.accountCap || h, e.pure.address)
2649
+ [B],
2650
+ h(r?.accountCap || w, e.pure.address)
2217
2651
  );
2218
2652
  } else
2219
2653
  e.moveCall({
2220
- target: `${u.package}::incentive_v3::claim_reward_entry`,
2654
+ target: `${d.package}::incentive_v3::claim_reward_entry`,
2221
2655
  arguments: [
2222
2656
  e.object("0x06"),
2223
2657
  // Clock object
2224
- e.object(u.incentiveV3),
2658
+ e.object(d.incentiveV3),
2225
2659
  // Incentive V3 contract
2226
- e.object(u.storage),
2660
+ e.object(d.storage),
2227
2661
  // Protocol storage
2228
2662
  e.object(T),
2229
2663
  // Reward fund
@@ -2238,74 +2672,86 @@ async function St(e, t, r) {
2238
2672
  return a;
2239
2673
  }
2240
2674
  export {
2241
- Z as Address,
2242
- b as DEFAULT_CACHE_TIME,
2243
- O as DEFAULT_MARKET_IDENTITY,
2244
- rt as FlashLoanAssetConfig,
2245
- et as IncentiveAPYInfo,
2246
- we as IncentivePoolInfo,
2247
- tt as IncentivePoolInfoByPhase,
2248
- U as MARKETS,
2249
- Ue as Market,
2250
- ot as OracleInfo,
2251
- N as PoolOperator,
2252
- ve as ReserveDataInfo,
2253
- te as SuiPriceServiceConnection,
2254
- $e as SuiPythClient,
2255
- D as UserPositions,
2256
- be as UserStateInfo,
2257
- ct as borrowCoinPTB,
2258
- St as claimLendingRewardsPTB,
2259
- De as createAccountCapPTB,
2260
- dt as createEModeCapPTB,
2261
- Ce as createNaviSuiClient,
2262
- Ee as depositCoinPTB,
2263
- mt as emodeIdentityId,
2264
- Ne as enterEModePTB,
2265
- pt as exitEModePTB,
2266
- Ge as filterPriceFeeds,
2267
- It as flashloanPTB,
2268
- Fe as getAccountCapOwnerPTB,
2269
- Y as getAllFlashLoanAssets,
2270
- lt as getBorrowFee,
2271
- vt as getCoins,
2272
- _ as getConfig,
2273
- at as getFees,
2274
- jt as getFlashLoanAsset,
2275
- gt as getHealthFactor,
2276
- Re as getHealthFactorPTB,
2277
- qe as getLendingPositions,
2278
- yt as getLendingState,
2279
- ut as getMarket,
2280
- C as getMarketConfig,
2281
- Oe as getMarkets,
2282
- $ as getPool,
2283
- R as getPools,
2284
- se as getPriceFeeds,
2285
- kt as getPythStalePriceFeedId,
2286
- He as getPythStalePriceFeedIdV2,
2287
- ht as getSimulatedHealthFactor,
2288
- ae as getSimulatedHealthFactorPTB,
2289
- nt as getStats,
2290
- wt as getTransactions,
2291
- Pt as getUserAvailableLendingRewards,
2292
- $t as getUserClaimedRewardHistory,
2293
- ne as getUserEModeCaps,
2294
- At as getUserTotalClaimedReward,
2295
- Tt as liquidatePTB,
2296
- ft as mergeCoinsPTB,
2297
- k as normalizeCoinType,
2298
- Me as parsePoolUID,
2299
- g as parseTxValue,
2300
- st as repayCoinPTB,
2301
- Ct as repayFlashLoanPTB,
2302
- Bt as summaryLendingRewards,
2303
- _t as updateOraclePriceBeforeUserOperationPTB,
2304
- ze as updateOraclePricesPTB,
2305
- We as updatePythPriceFeeds,
2306
- bt as verifyHealthFactorPTB,
2307
- S as withCache,
2675
+ ne as Address,
2676
+ v as DEFAULT_CACHE_TIME,
2677
+ R as DEFAULT_MARKET_IDENTITY,
2678
+ zt as FlashLoanAssetConfig,
2679
+ Rt as IncentiveAPYInfo,
2680
+ Ne as IncentivePoolInfo,
2681
+ Lt as IncentivePoolInfoByPhase,
2682
+ F as MARKETS,
2683
+ wt as Market,
2684
+ He as NaviMissingGraphQLClientError,
2685
+ qt as OracleInfo,
2686
+ z as PoolOperator,
2687
+ Re as ReserveDataInfo,
2688
+ he as SuiPriceServiceConnection,
2689
+ ct as SuiPythClient,
2690
+ L as UserPositions,
2691
+ Le as UserStateInfo,
2692
+ Xt as borrowCoinPTB,
2693
+ M as buildNaviOpenApiUrl,
2694
+ jr as claimLendingRewardsPTB,
2695
+ Kt as configureNaviSdk,
2696
+ vt as createAccountCapPTB,
2697
+ nr as createEModeCapPTB,
2698
+ ge as createNaviLegacyJsonRpcClient,
2699
+ xe as createNaviSuiClient,
2700
+ Ze as createNaviSuiClientBundle,
2701
+ ht as depositCoinPTB,
2702
+ or as emodeIdentityId,
2703
+ jt as enterEModePTB,
2704
+ rr as exitEModePTB,
2705
+ St as filterPriceFeeds,
2706
+ yr as flashloanPTB,
2707
+ Ct as getAccountCapOwnerPTB,
2708
+ Wt as getAddressBalance,
2709
+ re as getAllFlashLoanAssets,
2710
+ er as getBorrowFee,
2711
+ Gt as getCoinObjectOnlyBalance,
2712
+ ur as getCoins,
2713
+ j as getConfig,
2714
+ Yt as getFees,
2715
+ fr as getFlashLoanAsset,
2716
+ cr as getHealthFactor,
2717
+ It as getHealthFactorPTB,
2718
+ _t as getLendingPositions,
2719
+ ir as getLendingState,
2720
+ tr as getMarket,
2721
+ _ as getMarketConfig,
2722
+ bt as getMarkets,
2723
+ S as getPool,
2724
+ G as getPools,
2725
+ Be as getPriceFeeds,
2726
+ pr as getPythStalePriceFeedId,
2727
+ Bt as getPythStalePriceFeedIdV2,
2728
+ sr as getSimulatedHealthFactor,
2729
+ Ie as getSimulatedHealthFactorPTB,
2730
+ Qt as getStats,
2731
+ lr as getTransactions,
2732
+ wr as getUserAvailableLendingRewards,
2733
+ Cr as getUserClaimedRewardHistory,
2734
+ ke as getUserEModeCaps,
2735
+ vr as getUserTotalClaimedReward,
2736
+ hr as liquidatePTB,
2737
+ Ht as listAddressBalances,
2738
+ ar as mergeCoinsPTB,
2739
+ D as mergeServiceHeaders,
2740
+ ye as normalizeAddressBalance,
2741
+ C as normalizeCoinType,
2742
+ gt as parsePoolUID,
2743
+ h as parseTxValue,
2744
+ xt as repayCoinPTB,
2745
+ gr as repayFlashLoanPTB,
2746
+ Jt as requireNaviGraphQLClient,
2747
+ E as resolveNaviOpenApiEndpoint,
2748
+ br as summaryLendingRewards,
2749
+ mr as updateOraclePriceBeforeUserOperationPTB,
2750
+ At as updateOraclePricesPTB,
2751
+ Pt as updatePythPriceFeeds,
2752
+ dr as verifyHealthFactorPTB,
2753
+ $ as withCache,
2308
2754
  A as withSingleton,
2309
- it as withdrawCoinPTB
2755
+ Zt as withdrawCoinPTB
2310
2756
  };
2311
2757
  //# sourceMappingURL=index.esm.js.map