@naviprotocol/lending 2.0.0-beta.0 → 2.0.0-beta.1

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