@naviprotocol/lending 1.4.4-beta.3 → 1.4.4-beta.4

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,27 +1,27 @@
1
1
  import { Transaction as N } from "@mysten/sui/transactions";
2
- import { bcs as m, toHex as ie, fromHex as ce } from "@mysten/bcs";
3
- import { SuiClient as se, getFullnodeUrl as ue } from "@mysten/sui/client";
4
- import le from "lodash.camelcase";
5
- import { normalizeStructTag as pe } from "@mysten/sui/utils";
6
- import { SuiPriceServiceConnection as Z, SuiPythClient as de } from "@pythnetwork/pyth-sui-js";
2
+ import { bcs as m, toHex as ce, fromHex as se } from "@mysten/bcs";
3
+ import { SuiClient as le, getFullnodeUrl as ue } from "@mysten/sui/client";
4
+ import pe from "lodash.camelcase";
5
+ import { normalizeStructTag as de } from "@mysten/sui/utils";
6
+ import { SuiPriceServiceConnection as Q, SuiPythClient as me } from "@pythnetwork/pyth-sui-js";
7
7
  import p from "bignumber.js";
8
8
  import { bcs as C } from "@mysten/sui/bcs";
9
- const z = m.bytes(32).transform({
9
+ const K = m.bytes(32).transform({
10
10
  // To change the input type, you need to provide a type definition for the input
11
- input: (e) => ce(e),
12
- output: (e) => ie(e)
13
- }), He = m.struct("IncentiveAPYInfo", {
11
+ input: (e) => se(e),
12
+ output: (e) => ce(e)
13
+ }), Ge = m.struct("IncentiveAPYInfo", {
14
14
  /** Asset identifier */
15
15
  asset_id: m.u8(),
16
16
  /** Annual Percentage Yield as a 256-bit integer */
17
17
  apy: m.u256(),
18
18
  /** List of supported coin types for this incentive */
19
19
  coin_types: m.vector(m.string())
20
- }), me = m.struct("IncentivePoolInfo", {
20
+ }), fe = m.struct("IncentivePoolInfo", {
21
21
  /** Unique pool identifier */
22
- pool_id: z,
22
+ pool_id: K,
23
23
  /** Address holding the incentive funds */
24
- funds: z,
24
+ funds: K,
25
25
  /** Current phase of the incentive program */
26
26
  phase: m.u64(),
27
27
  /** Timestamp when the incentive started */
@@ -44,12 +44,12 @@ const z = m.bytes(32).transform({
44
44
  available: m.u256(),
45
45
  /** Total amount of incentives */
46
46
  total: m.u256()
47
- }), Ge = m.struct("IncentivePoolInfoByPhase", {
47
+ }), ze = m.struct("IncentivePoolInfoByPhase", {
48
48
  /** Phase number */
49
49
  phase: m.u64(),
50
50
  /** List of incentive pools in this phase */
51
- pools: m.vector(me)
52
- }), ze = m.struct("OracleInfo", {
51
+ pools: m.vector(fe)
52
+ }), Ke = m.struct("OracleInfo", {
53
53
  /** Oracle identifier */
54
54
  oracle_id: m.u8(),
55
55
  /** Current price as a 256-bit integer */
@@ -58,7 +58,7 @@ const z = m.bytes(32).transform({
58
58
  decimals: m.u8(),
59
59
  /** Whether the oracle data is valid */
60
60
  valid: m.bool()
61
- }), Ke = m.struct("FlashLoanAssetConfig", {
61
+ }), Ye = m.struct("FlashLoanAssetConfig", {
62
62
  /** Unique identifier for the flash loan asset */
63
63
  id: m.string(),
64
64
  /** Asset identifier */
@@ -75,7 +75,7 @@ const z = m.bytes(32).transform({
75
75
  max: m.u64(),
76
76
  /** Minimum flash loan amount */
77
77
  min: m.u64()
78
- }), Ye = m.struct("ReserveDataInfo", {
78
+ }), Je = m.struct("ReserveDataInfo", {
79
79
  /** Reserve identifier */
80
80
  id: m.u8(),
81
81
  /** Oracle identifier for price feeds */
@@ -122,210 +122,210 @@ const z = m.bytes(32).transform({
122
122
  liquidation_bonus: m.u256(),
123
123
  /** Liquidation threshold */
124
124
  liquidation_threshold: m.u256()
125
- }), fe = m.struct("UserStateInfo", {
125
+ }), ye = m.struct("UserStateInfo", {
126
126
  /** Asset identifier */
127
127
  asset_id: m.u8(),
128
128
  /** User's current borrow balance */
129
129
  borrow_balance: m.u256(),
130
130
  /** User's current supply balance */
131
131
  supply_balance: m.u256()
132
- }), ye = "1.4.4-beta.3", S = {
133
- version: ye
134
- }, ge = S.version, he = () => {
132
+ }), ge = "1.4.4-beta.4", V = {
133
+ version: ge
134
+ }, he = V.version, ve = () => {
135
135
  if (typeof process < "u" && process.versions && process.versions.node)
136
136
  try {
137
- const e = require("os"), n = process.version, o = e.type(), r = e.arch();
138
- return `Node.js ${n.startsWith("v") ? n.substring(1) : n}; ${o}/${r}`;
137
+ const e = require("os"), r = process.version, o = e.type(), n = e.arch();
138
+ return `Node.js ${r.startsWith("v") ? r.substring(1) : r}; ${o}/${n}`;
139
139
  } catch {
140
140
  return `Node.js ${process.version}; OS/Unknown (Error)`;
141
141
  }
142
142
  return "Node/Unknown";
143
- }, ve = () => {
143
+ }, we = () => {
144
144
  let e = "";
145
- return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${ge} (${he()})`), e;
146
- }, K = ve(), $ = new se({
145
+ return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${he} (${ve()})`), e;
146
+ }, Y = we(), S = new le({
147
147
  url: ue("mainnet")
148
148
  });
149
- function Q(e) {
150
- const n = [];
151
- return e.forEach((o, r) => {
152
- const t = r === e.length - 1;
149
+ function X(e) {
150
+ const r = [];
151
+ return e.forEach((o, n) => {
152
+ const t = n === e.length - 1;
153
153
  if (typeof o == "object" && o !== null && t) {
154
154
  const { client: a, disableCache: s, cacheTime: i, ...c } = o;
155
- n.push(c);
155
+ r.push(c);
156
156
  } else
157
- n.push(o);
158
- }), JSON.stringify(n);
157
+ r.push(o);
158
+ }), JSON.stringify(r);
159
159
  }
160
160
  function B(e) {
161
- const n = {};
161
+ const r = {};
162
162
  return (...o) => {
163
- const r = Q(o);
164
- return n[r] || (n[r] = e(...o).finally(() => {
165
- delete n[r];
166
- })), n[r];
163
+ const n = X(o);
164
+ return r[n] || (r[n] = e(...o).finally(() => {
165
+ delete r[n];
166
+ })), r[n];
167
167
  };
168
168
  }
169
169
  function P(e) {
170
- let n = {};
170
+ let r = {};
171
171
  return (...o) => {
172
- const r = o[o.length - 1], t = Q(o), a = n[t];
173
- return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...o).then((s) => (n[t] = {
172
+ const n = o[o.length - 1], t = X(o), a = r[t];
173
+ return !n?.disableCache && typeof a?.data < "u" && (typeof n?.cacheTime > "u" || n.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...o).then((s) => (r[t] = {
174
174
  data: s,
175
175
  cacheAt: Date.now()
176
176
  }, s));
177
177
  };
178
178
  }
179
- function W(e) {
180
- return Array.isArray(e) ? e.map((n) => W(n)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
181
- (n, o) => ({
182
- ...n,
183
- [le(o)]: W(e[o])
179
+ function H(e) {
180
+ return Array.isArray(e) ? e.map((r) => H(r)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
181
+ (r, o) => ({
182
+ ...r,
183
+ [pe(o)]: H(e[o])
184
184
  }),
185
185
  {}
186
186
  ) : e;
187
187
  }
188
- function h(e, n) {
189
- return typeof e == "object" ? e : n(e);
188
+ function h(e, r) {
189
+ return typeof e == "object" ? e : r(e);
190
190
  }
191
- function we(e, n) {
192
- return typeof n == "string" ? e.object(n) : typeof n == "object" && n.$kind ? n : e.object(n.contract.pool);
191
+ function be(e, r) {
192
+ return typeof r == "string" ? e.object(r) : typeof r == "object" && r.$kind ? r : e.object(r.contract.pool);
193
193
  }
194
- function L(e, n, o) {
194
+ function W(e, r, o) {
195
195
  if (e.results && e.results.length > 0) {
196
196
  if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
197
- return e.results[0].returnValues.map((r, t) => (n[t] || n[0]).parse(Uint8Array.from(r[0])));
197
+ return e.results[0].returnValues.map((n, t) => (r[t] || r[0]).parse(Uint8Array.from(n[0])));
198
198
  } else if (e.error)
199
199
  return console.log(`Get an error, msg: ${e.error}`), [];
200
200
  return [];
201
201
  }
202
- function k(e) {
203
- return pe(e);
202
+ function b(e) {
203
+ return de(e);
204
204
  }
205
- function X(e) {
206
- const n = (e || 0) / Math.pow(10, 27);
207
- return n > Math.pow(10, 5) ? 1 / 0 : n;
205
+ function x(e) {
206
+ const r = (e || 0) / Math.pow(10, 27);
207
+ return r > Math.pow(10, 5) ? 1 / 0 : r;
208
208
  }
209
- new Z("https://hermes.pyth.network", {
209
+ new Q("https://hermes.pyth.network", {
210
210
  timeout: 2e4
211
211
  });
212
- const be = 27, Y = (e, n) => {
213
- if (!Number(e) || !Number(n)) return new p(0);
214
- const o = new p(1).shiftedBy(1 * be), r = o.multipliedBy(new p(0.5));
215
- return new p(e).multipliedBy(new p(n)).plus(r).dividedBy(o).integerValue(p.ROUND_DOWN);
216
- }, M = K ? {
217
- "User-Agent": K
212
+ const ke = 27, J = (e, r) => {
213
+ if (!Number(e) || !Number(r)) return new p(0);
214
+ const o = new p(1).shiftedBy(1 * ke), n = o.multipliedBy(new p(0.5));
215
+ return new p(e).multipliedBy(new p(r)).plus(n).dividedBy(o).integerValue(p.ROUND_DOWN);
216
+ }, M = Y ? {
217
+ "User-Agent": Y
218
218
  } : {};
219
- function H(e, n = "uniqueId") {
219
+ function G(e, r = "uniqueId") {
220
220
  return e.reduce(
221
- (o, r) => (o[r[n]] = r, o),
221
+ (o, n) => (o[n[r]] = n, o),
222
222
  {}
223
223
  );
224
224
  }
225
- function J(e, n = "uniqueId") {
225
+ function Z(e, r = "uniqueId") {
226
226
  return e.reduce(
227
- (o, r) => (o[r[n]] = r, o),
227
+ (o, n) => (o[n[r]] = n, o),
228
228
  {}
229
229
  );
230
230
  }
231
- function q(e, n) {
232
- const o = e.emodes.find((t) => t.emodeId === n.emodeId);
231
+ function L(e, r) {
232
+ const o = e.emodes.find((t) => t.emodeId === r.emodeId);
233
233
  if (!o)
234
234
  throw new Error("EMode not found in pool");
235
- const r = o.assets.find((t) => t.assetId === e.id);
235
+ const n = o.assets.find((t) => t.assetId === e.id);
236
236
  return {
237
237
  ...e,
238
238
  emode: {
239
- ...r,
239
+ ...n,
240
240
  emodeId: o.emodeId
241
241
  },
242
242
  isEMode: !0
243
243
  };
244
244
  }
245
- function ke(e) {
246
- const [n, o] = e.split("-");
247
- return !n || !o ? null : {
248
- marketKey: n,
245
+ function _e(e) {
246
+ const [r, o] = e.split("-");
247
+ return !r || !o ? null : {
248
+ marketKey: r,
249
249
  poolId: parseInt(o)
250
250
  };
251
251
  }
252
252
  function T() {
253
253
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
254
254
  }
255
- var F = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(F || {});
256
- const R = P(
255
+ var R = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(R || {});
256
+ const q = P(
257
257
  B(
258
258
  async (e) => {
259
- const n = (e?.markets || [E.main]).map((t) => j(t)), o = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${S.version}&market=${n.map(
259
+ const r = (e?.markets || [E.main]).map((t) => I(t)), o = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${V.version}&market=${r.map(
260
260
  (t) => t.key
261
- )}`, r = await fetch(o, { headers: M }).then((t) => t.json());
262
- return r.data.forEach((t) => {
263
- const s = r.meta.emodes.filter((f) => {
264
- const w = j(f.marketId);
265
- return t.market === w.key && f.isActive;
266
- }).filter((f) => !!f.assets.find((w) => w.assetId === t.id));
261
+ )}`, n = await fetch(o, { headers: M }).then((t) => t.json());
262
+ return n.data.forEach((t) => {
263
+ const s = n.meta.emodes.filter((f) => {
264
+ const k = I(f.marketId);
265
+ return t.market === k.key && f.isActive;
266
+ }).filter((f) => !!f.assets.find((k) => k.assetId === t.id));
267
267
  t.emodes = s;
268
- const i = p(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), c = p(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), u = p(i).multipliedBy(t.oracle.price).toString(), d = p(c).multipliedBy(t.oracle.price).toString(), y = p(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), v = p.max(
268
+ const i = p(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), c = p(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), l = p(i).multipliedBy(t.oracle.price).toString(), d = p(c).multipliedBy(t.oracle.price).toString(), y = p(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), v = p.max(
269
269
  p(t.borrowedAmount),
270
270
  p(t.validBorrowAmount)
271
- ).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), g = p(y).multipliedBy(t.oracle.price).toString(), l = p(v).multipliedBy(t.oracle.price).toString();
272
- t.poolSupplyAmount = i, t.poolBorrowAmount = c, t.poolSupplyValue = u, t.poolBorrowValue = d, t.poolSupplyCapAmount = y, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = g, t.poolBorrowCapValue = l;
273
- }), r.data;
271
+ ).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), g = p(y).multipliedBy(t.oracle.price).toString(), u = p(v).multipliedBy(t.oracle.price).toString();
272
+ t.poolSupplyAmount = i, t.poolBorrowAmount = c, t.poolSupplyValue = l, t.poolBorrowValue = d, t.poolSupplyCapAmount = y, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = g, t.poolBorrowCapValue = u;
273
+ }), n.data;
274
274
  }
275
275
  )
276
276
  );
277
- async function A(e, n) {
278
- let o = n?.market;
277
+ async function A(e, r) {
278
+ let o = r?.market;
279
279
  if (typeof e == "string") {
280
- const a = ke(e);
280
+ const a = _e(e);
281
281
  a && (o = a.marketKey, e = a.poolId);
282
282
  }
283
- const r = await R({
284
- ...n,
285
- markets: [o || D],
286
- cacheTime: b
283
+ const n = await q({
284
+ ...r,
285
+ markets: [o || U],
286
+ cacheTime: w
287
287
  });
288
288
  if (typeof e == "object")
289
289
  return e;
290
- const t = r.find((a) => typeof e == "string" ? k(a.suiCoinType) === k(e) : typeof e == "number" ? a.id === e : !1);
290
+ const t = n.find((a) => typeof e == "string" ? b(a.suiCoinType) === b(e) : typeof e == "number" ? a.id === e : !1);
291
291
  if (!t)
292
292
  throw new Error("Pool not found");
293
293
  return t.isDeprecated && console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`), t;
294
294
  }
295
- const Je = P(
295
+ const Ze = P(
296
296
  B(async (e) => {
297
- const n = `https://open-api.naviprotocol.io/api/navi/stats?sdk=${S.version}`;
298
- return (await fetch(n, { headers: M }).then((r) => r.json())).data;
297
+ const r = `https://open-api.naviprotocol.io/api/navi/stats?sdk=${V.version}`;
298
+ return (await fetch(r, { headers: M }).then((n) => n.json())).data;
299
299
  })
300
- ), Ze = P(
300
+ ), Qe = P(
301
301
  B(
302
302
  async (e) => {
303
- const n = `https://open-api.naviprotocol.io/api/navi/fee?sdk=${S.version}`;
304
- return await fetch(n, { headers: M }).then((r) => r.json());
303
+ const r = `https://open-api.naviprotocol.io/api/navi/fee?sdk=${V.version}`;
304
+ return await fetch(r, { headers: M }).then((n) => n.json());
305
305
  }
306
306
  )
307
307
  );
308
- async function _e(e, n, o, r) {
308
+ async function Ce(e, r, o, n) {
309
309
  const t = await _({
310
- ...r,
311
- cacheTime: b
312
- }), a = await A(n, r);
313
- r?.market;
314
- const s = r?.env || "prod";
310
+ ...n,
311
+ cacheTime: w
312
+ }), a = await A(r, n);
313
+ n?.market;
314
+ const s = n?.env || "prod";
315
315
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
316
316
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
317
317
  const i = typeof o == "object" && o.$kind === "GasCoin";
318
- if (k(a.suiCoinType) === k("0x2::sui::SUI") && i) {
319
- if (!r?.amount)
318
+ if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
319
+ if (!n?.amount)
320
320
  throw new Error("Amount is required for sui coin");
321
- o = e.splitCoins(o, [r.amount]);
321
+ o = e.splitCoins(o, [n.amount]);
322
322
  }
323
323
  let c;
324
- return typeof r?.amount < "u" ? c = h(r.amount, e.pure.u64) : c = e.moveCall({
324
+ return typeof n?.amount < "u" ? c = h(n.amount, e.pure.u64) : c = e.moveCall({
325
325
  target: "0x2::coin::value",
326
326
  arguments: [h(o, e.object)],
327
327
  typeArguments: [a.suiCoinType]
328
- }), r?.accountCap ? e.moveCall({
328
+ }), n?.accountCap ? e.moveCall({
329
329
  target: `${t.package}::incentive_v3::deposit_with_account_cap`,
330
330
  arguments: [
331
331
  e.object("0x06"),
@@ -335,7 +335,7 @@ async function _e(e, n, o, r) {
335
335
  h(o, e.object),
336
336
  e.object(t.incentiveV2),
337
337
  e.object(t.incentiveV3),
338
- h(r.accountCap, e.object)
338
+ h(n.accountCap, e.object)
339
339
  ],
340
340
  typeArguments: [a.suiCoinType]
341
341
  }) : e.moveCall({
@@ -356,15 +356,15 @@ async function _e(e, n, o, r) {
356
356
  arguments: [e.object(a.contract.pool), e.object("0x05")]
357
357
  }), e;
358
358
  }
359
- async function Qe(e, n, o, r) {
359
+ async function Xe(e, r, o, n) {
360
360
  const t = await _({
361
- ...r,
362
- cacheTime: b
363
- }), a = await A(n, r), s = h(o, e.pure.u64);
361
+ ...n,
362
+ cacheTime: w
363
+ }), a = await A(r, n), s = h(o, e.pure.u64);
364
364
  let i;
365
365
  if (t.version === 1)
366
- if (r?.accountCap) {
367
- const [u] = e.moveCall({
366
+ if (n?.accountCap) {
367
+ const [l] = e.moveCall({
368
368
  target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
369
369
  arguments: [
370
370
  e.object("0x06"),
@@ -375,13 +375,13 @@ async function Qe(e, n, o, r) {
375
375
  s,
376
376
  e.object(t.incentiveV2),
377
377
  e.object(t.incentiveV3),
378
- h(r.accountCap, e.object)
378
+ h(n.accountCap, e.object)
379
379
  ],
380
380
  typeArguments: [a.suiCoinType]
381
381
  });
382
- i = u;
382
+ i = l;
383
383
  } else {
384
- const [u] = e.moveCall({
384
+ const [l] = e.moveCall({
385
385
  target: `${t.package}::incentive_v3::withdraw`,
386
386
  arguments: [
387
387
  e.object("0x06"),
@@ -395,10 +395,10 @@ async function Qe(e, n, o, r) {
395
395
  ],
396
396
  typeArguments: [a.suiCoinType]
397
397
  });
398
- i = u;
398
+ i = l;
399
399
  }
400
- else if (r?.accountCap) {
401
- const [u] = e.moveCall({
400
+ else if (n?.accountCap) {
401
+ const [l] = e.moveCall({
402
402
  target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
403
403
  arguments: [
404
404
  e.object("0x06"),
@@ -409,14 +409,14 @@ async function Qe(e, n, o, r) {
409
409
  s,
410
410
  e.object(t.incentiveV2),
411
411
  e.object(t.incentiveV3),
412
- h(r.accountCap, e.object),
412
+ h(n.accountCap, e.object),
413
413
  e.object("0x05")
414
414
  ],
415
415
  typeArguments: [a.suiCoinType]
416
416
  });
417
- i = u;
417
+ i = l;
418
418
  } else {
419
- const [u] = e.moveCall({
419
+ const [l] = e.moveCall({
420
420
  target: `${t.package}::incentive_v3::withdraw_v2`,
421
421
  arguments: [
422
422
  e.object("0x06"),
@@ -431,7 +431,7 @@ async function Qe(e, n, o, r) {
431
431
  ],
432
432
  typeArguments: [a.suiCoinType]
433
433
  });
434
- i = u;
434
+ i = l;
435
435
  }
436
436
  return e.moveCall({
437
437
  target: "0x2::coin::from_balance",
@@ -439,18 +439,18 @@ async function Qe(e, n, o, r) {
439
439
  typeArguments: [a.suiCoinType]
440
440
  });
441
441
  }
442
- async function Xe(e, n, o, r) {
442
+ async function xe(e, r, o, n) {
443
443
  const t = await _({
444
- ...r,
445
- cacheTime: b
446
- }), a = await A(n, r);
444
+ ...n,
445
+ cacheTime: w
446
+ }), a = await A(r, n);
447
447
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
448
448
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
449
449
  const s = h(o, e.pure.u64);
450
450
  let i;
451
451
  if (t.version === 1)
452
- if (r?.accountCap) {
453
- const [u] = e.moveCall({
452
+ if (n?.accountCap) {
453
+ const [l] = e.moveCall({
454
454
  target: `${t.package}::incentive_v3::borrow_with_account_cap`,
455
455
  arguments: [
456
456
  e.object("0x06"),
@@ -461,13 +461,13 @@ async function Xe(e, n, o, r) {
461
461
  s,
462
462
  e.object(t.incentiveV2),
463
463
  e.object(t.incentiveV3),
464
- h(r.accountCap, e.object)
464
+ h(n.accountCap, e.object)
465
465
  ],
466
466
  typeArguments: [a.suiCoinType]
467
467
  });
468
- i = u;
468
+ i = l;
469
469
  } else {
470
- const [u] = e.moveCall({
470
+ const [l] = e.moveCall({
471
471
  target: `${t.package}::incentive_v3::borrow`,
472
472
  arguments: [
473
473
  e.object("0x06"),
@@ -481,10 +481,10 @@ async function Xe(e, n, o, r) {
481
481
  ],
482
482
  typeArguments: [a.suiCoinType]
483
483
  });
484
- i = u;
484
+ i = l;
485
485
  }
486
- else if (r?.accountCap) {
487
- const [u] = e.moveCall({
486
+ else if (n?.accountCap) {
487
+ const [l] = e.moveCall({
488
488
  target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
489
489
  arguments: [
490
490
  e.object("0x06"),
@@ -495,14 +495,14 @@ async function Xe(e, n, o, r) {
495
495
  s,
496
496
  e.object(t.incentiveV2),
497
497
  e.object(t.incentiveV3),
498
- h(r.accountCap, e.object),
498
+ h(n.accountCap, e.object),
499
499
  e.object("0x05")
500
500
  ],
501
501
  typeArguments: [a.suiCoinType]
502
502
  });
503
- i = u;
503
+ i = l;
504
504
  } else {
505
- const [u] = e.moveCall({
505
+ const [l] = e.moveCall({
506
506
  target: `${t.package}::incentive_v3::borrow_v2`,
507
507
  arguments: [
508
508
  e.object("0x06"),
@@ -517,7 +517,7 @@ async function Xe(e, n, o, r) {
517
517
  ],
518
518
  typeArguments: [a.suiCoinType]
519
519
  });
520
- i = u;
520
+ i = l;
521
521
  }
522
522
  return e.moveCall({
523
523
  target: "0x2::coin::from_balance",
@@ -525,22 +525,22 @@ async function Xe(e, n, o, r) {
525
525
  typeArguments: [a.suiCoinType]
526
526
  });
527
527
  }
528
- async function xe(e, n, o, r) {
528
+ async function et(e, r, o, n) {
529
529
  const t = await _({
530
- ...r,
531
- cacheTime: b
532
- }), a = await A(n, r), s = typeof o == "object" && o.$kind === "GasCoin";
533
- if (k(a.suiCoinType) === k("0x2::sui::SUI") && s) {
534
- if (!r?.amount)
530
+ ...n,
531
+ cacheTime: w
532
+ }), a = await A(r, n), s = typeof o == "object" && o.$kind === "GasCoin";
533
+ if (b(a.suiCoinType) === b("0x2::sui::SUI") && s) {
534
+ if (!n?.amount)
535
535
  throw new Error("Amount is required for sui coin");
536
- o = e.splitCoins(o, [r.amount]);
536
+ o = e.splitCoins(o, [n.amount]);
537
537
  }
538
538
  let i;
539
- if (typeof r?.amount < "u" ? i = h(r.amount, e.pure.u64) : i = e.moveCall({
539
+ if (typeof n?.amount < "u" ? i = h(n.amount, e.pure.u64) : i = e.moveCall({
540
540
  target: "0x2::coin::value",
541
541
  arguments: [h(o, e.object)],
542
542
  typeArguments: [a.suiCoinType]
543
- }), r?.accountCap) {
543
+ }), n?.accountCap) {
544
544
  const [c] = e.moveCall({
545
545
  target: `${t.package}::incentive_v3::repay_with_account_cap`,
546
546
  arguments: [
@@ -552,7 +552,7 @@ async function xe(e, n, o, r) {
552
552
  h(o, e.object),
553
553
  e.object(t.incentiveV2),
554
554
  e.object(t.incentiveV3),
555
- h(r.accountCap, e.object)
555
+ h(n.accountCap, e.object)
556
556
  ],
557
557
  typeArguments: [a.suiCoinType]
558
558
  });
@@ -578,19 +578,19 @@ async function xe(e, n, o, r) {
578
578
  typeArguments: [a.suiCoinType]
579
579
  }), e;
580
580
  }
581
- const et = P(
581
+ const tt = P(
582
582
  B(
583
583
  async (e) => {
584
- const n = await _({
584
+ const r = await _({
585
585
  ...e
586
586
  });
587
587
  if (e?.address && typeof e?.asset < "u")
588
588
  try {
589
- const t = await A(e.asset, e), a = e?.client ?? $, s = new N();
589
+ const t = await A(e.asset, e), a = e?.client ?? S, s = new N();
590
590
  s.moveCall({
591
- target: `${n.package}::incentive_v3::get_borrow_fee_v2`,
591
+ target: `${r.package}::incentive_v3::get_borrow_fee_v2`,
592
592
  arguments: [
593
- s.object(n.incentiveV3),
593
+ s.object(r.incentiveV3),
594
594
  s.pure.address(e.address),
595
595
  s.pure.u8(t.id),
596
596
  s.pure.u64(1e4)
@@ -600,19 +600,19 @@ const et = P(
600
600
  const i = await a.devInspectTransactionBlock({
601
601
  transactionBlock: s,
602
602
  sender: e.address
603
- }), c = L(i, [C.u64()]);
603
+ }), c = W(i, [C.u64()]);
604
604
  return (Number(c[0]) || 0) / 100;
605
605
  } catch (t) {
606
606
  console.error(t);
607
607
  }
608
- const r = (await $.getObject({
609
- id: n.incentiveV3,
608
+ const n = (await S.getObject({
609
+ id: r.incentiveV3,
610
610
  options: { showType: !0, showOwner: !0, showContent: !0 }
611
611
  })).data.content.fields.borrow_fee_rate;
612
- return Number(r) / 100;
612
+ return Number(n) / 100;
613
613
  }
614
614
  )
615
- ), D = "main", E = {
615
+ ), U = "main", E = {
616
616
  main: {
617
617
  id: 0,
618
618
  key: "main",
@@ -629,52 +629,52 @@ const et = P(
629
629
  name: "Sui Eco Market"
630
630
  }
631
631
  };
632
- class Ce {
633
- constructor(n, o) {
632
+ class je {
633
+ constructor(r, o) {
634
634
  this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
635
635
  marketTotalSupplyValue: "0",
636
636
  marketTotalBorrowValue: "0"
637
- }, this.config = j(n), this.initPools(o);
637
+ }, this.config = I(r), this.initPools(o);
638
638
  }
639
639
  get overview() {
640
640
  return this._overview;
641
641
  }
642
- initPools(n) {
643
- const o = H(this.pools), r = J(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
642
+ initPools(r) {
643
+ const o = G(this.pools), n = Z(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
644
644
  let s = p(0), i = p(0);
645
- n.forEach((c) => {
645
+ r.forEach((c) => {
646
646
  if (!this.checkMarket(c.market)) {
647
647
  console.warn(`Pool is not in market ${this.config.name}`, c);
648
648
  return;
649
649
  }
650
650
  o[c.uniqueId] || this.pools.push(c), c?.emodes?.forEach((d) => {
651
- r[d.uniqueId] || this.emodes.push(d), d.assets.forEach((y) => {
651
+ n[d.uniqueId] || this.emodes.push(d), d.assets.forEach((y) => {
652
652
  y.isDebt && d.assets.find(
653
653
  (g) => g.isCollateral && g.ltv > 0 && g.assetId !== c.id
654
654
  ) && t.add(c.uniqueId), y.isCollateral && d.assets.find((g) => g.isDebt && g.assetId !== c.id) && a.add(c.uniqueId);
655
655
  });
656
656
  }), i = i.plus(c.poolBorrowValue), s = s.plus(c.poolSupplyValue);
657
- }), this.poolMap = H(this.pools, "id"), this.emodeMap = J(this.emodes, "emodeId"), this.emodes.forEach((c) => {
658
- const u = this.getEModePools(c.emodeId);
659
- this.emodePools.push(...u);
657
+ }), this.poolMap = G(this.pools, "id"), this.emodeMap = Z(this.emodes, "emodeId"), this.emodes.forEach((c) => {
658
+ const l = this.getEModePools(c.emodeId);
659
+ this.emodePools.push(...l);
660
660
  }), this._overview = {
661
661
  marketTotalSupplyValue: s.toString(),
662
662
  marketTotalBorrowValue: i.toString()
663
663
  }, this.emodeBorrowablePools = this.pools.filter((c) => t.has(c.uniqueId)), this.emodeSupplyablePools = this.pools.filter((c) => a.has(c.uniqueId));
664
664
  }
665
- getEMode(n) {
666
- return this.emodeMap[n] || null;
665
+ getEMode(r) {
666
+ return this.emodeMap[r] || null;
667
667
  }
668
- getEModeRelatePools(n, o) {
669
- const { collateral: r, debt: t, emodeId: a } = o || {}, s = [];
670
- return n.emodes.forEach((i) => {
668
+ getEModeRelatePools(r, o) {
669
+ const { collateral: n, debt: t, emodeId: a } = o || {}, s = [];
670
+ return r.emodes.forEach((i) => {
671
671
  typeof a == "number" && a !== i.emodeId || i.assets.forEach((c) => {
672
- typeof r == "boolean" && r && c.isCollateral && c.assetId === n.id && s.push(this.poolMap[c.assetId]), typeof t == "boolean" && t && c.isDebt && c.assetId === n.id && s.push(this.poolMap[c.assetId]);
672
+ typeof n == "boolean" && n && c.isCollateral && c.assetId === r.id && s.push(this.poolMap[c.assetId]), typeof t == "boolean" && t && c.isDebt && c.assetId === r.id && s.push(this.poolMap[c.assetId]);
673
673
  });
674
674
  }), s;
675
675
  }
676
- getEModePools(n) {
677
- const o = this.getEMode(n);
676
+ getEModePools(r) {
677
+ const o = this.getEMode(r);
678
678
  return o ? o.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
679
679
  const a = o.assets.find((s) => s.assetId === t.id);
680
680
  return {
@@ -687,161 +687,161 @@ class Ce {
687
687
  };
688
688
  }) : [];
689
689
  }
690
- checkMarket(n) {
690
+ checkMarket(r) {
691
691
  let o = !1;
692
- return typeof n == "number" && n === this.config.id && (o = !0), typeof n == "string" && n === this.config.key && (o = !0), typeof n == "object" && n.id === this.config.id && (o = !0), o;
692
+ return typeof r == "number" && r === this.config.id && (o = !0), typeof r == "string" && r === this.config.key && (o = !0), typeof r == "object" && r.id === this.config.id && (o = !0), o;
693
693
  }
694
694
  }
695
- const j = (e) => {
696
- const o = Object.values(E).find((r) => typeof e == "number" ? r.id === e : typeof e == "string" ? r.key === e : r.id === e.id);
695
+ const I = (e) => {
696
+ const o = Object.values(E).find((n) => typeof e == "number" ? n.id === e : typeof e == "string" ? n.key === e : n.id === e.id);
697
697
  if (!o)
698
698
  throw new Error("Market not found");
699
699
  return o;
700
- }, je = P(
700
+ }, Ie = P(
701
701
  B(
702
- async (e, n) => {
703
- const o = await R({
702
+ async (e, r) => {
703
+ const o = await q({
704
704
  cacheTime: 6e4,
705
- ...n,
705
+ ...r,
706
706
  markets: e
707
707
  });
708
- return e.map((r) => {
709
- const t = j(r), a = o.filter((s) => s.market === t.key);
710
- return new Ce(r, a);
708
+ return e.map((n) => {
709
+ const t = I(n), a = o.filter((s) => s.market === t.key);
710
+ return new je(n, a);
711
711
  });
712
712
  }
713
713
  )
714
- ), tt = P(
714
+ ), ot = P(
715
715
  B(
716
- async (e, n) => (await je([e], n))[0]
716
+ async (e, r) => (await Ie([e], r))[0]
717
717
  )
718
718
  ), _ = P(
719
719
  B(
720
720
  async (e) => {
721
- const n = j(e?.market || D), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${S.version}&market=${n.key}`;
721
+ const r = I(e?.market || U), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${V.version}&market=${r.key}`;
722
722
  return (await fetch(o, { headers: M }).then((t) => t.json())).data;
723
723
  }
724
724
  )
725
- ), b = 1e3 * 60 * 5;
726
- async function Ie(e, n) {
725
+ ), w = 1e3 * 60 * 5;
726
+ async function Te(e, r) {
727
727
  const o = await _({
728
- cacheTime: b,
729
- ...n
728
+ cacheTime: w,
729
+ ...r
730
730
  });
731
731
  return e.moveCall({
732
732
  target: `${o.package}::lending::create_account`,
733
733
  arguments: []
734
734
  });
735
735
  }
736
- async function Te(e, n, o) {
737
- const r = await _({
738
- cacheTime: b,
736
+ async function Be(e, r, o) {
737
+ const n = await _({
738
+ cacheTime: w,
739
739
  ...o
740
740
  });
741
741
  return e.moveCall({
742
- target: `${r.package}::account::account_owner`,
743
- arguments: [n]
742
+ target: `${n.package}::account::account_owner`,
743
+ arguments: [r]
744
744
  });
745
745
  }
746
- async function Be(e, n, o) {
747
- const r = await _({
746
+ async function Ae(e, r, o) {
747
+ const n = await _({
748
748
  ...o,
749
- cacheTime: b
749
+ cacheTime: w
750
750
  });
751
751
  return o?.accountCap ? e.moveCall({
752
- target: `${r.package}::lending::enter_emode_with_account_cap`,
752
+ target: `${n.package}::lending::enter_emode_with_account_cap`,
753
753
  arguments: [
754
- e.object(r.storage),
755
- h(n, e.pure.u64),
754
+ e.object(n.storage),
755
+ h(r, e.pure.u64),
756
756
  h(o.accountCap, e.object)
757
757
  ]
758
758
  }) : e.moveCall({
759
- target: `${r.package}::lending::enter_emode`,
760
- arguments: [e.object(r.storage), h(n, e.pure.u64)]
759
+ target: `${n.package}::lending::enter_emode`,
760
+ arguments: [e.object(n.storage), h(r, e.pure.u64)]
761
761
  }), e;
762
762
  }
763
- async function ot(e, n) {
763
+ async function rt(e, r) {
764
764
  const o = await _({
765
- ...n,
766
- cacheTime: b
765
+ ...r,
766
+ cacheTime: w
767
767
  });
768
- return n?.accountCap ? e.moveCall({
768
+ return r?.accountCap ? e.moveCall({
769
769
  target: `${o.package}::lending::exit_emode_with_account_cap`,
770
- arguments: [e.object(o.storage), h(n.accountCap, e.object)]
770
+ arguments: [e.object(o.storage), h(r.accountCap, e.object)]
771
771
  }) : e.moveCall({
772
772
  target: `${o.package}::lending::exit_emode`,
773
773
  arguments: [e.object(o.storage)]
774
774
  }), e;
775
775
  }
776
- async function nt(e, n, o) {
777
- const r = await _({
778
- cacheTime: b,
776
+ async function nt(e, r, o) {
777
+ const n = await _({
778
+ cacheTime: w,
779
779
  ...o
780
- }), t = await Ie(e, o);
781
- await Be(e, n, {
780
+ }), t = await Te(e, o);
781
+ await Ae(e, r, {
782
782
  ...o,
783
783
  accountCap: t
784
784
  });
785
- const a = await j(o?.market || D), s = await Te(e, t, o);
785
+ const a = await I(o?.market || U), s = await Be(e, t, o);
786
786
  return e.moveCall({
787
- target: `${r.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
787
+ target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
788
788
  arguments: [
789
- e.object(r.emode.contract.registryObject),
789
+ e.object(n.emode.contract.registryObject),
790
790
  s,
791
791
  h(a.id, e.pure.u64),
792
- h(n, e.pure.u64)
792
+ h(r, e.pure.u64)
793
793
  ]
794
794
  }), t;
795
795
  }
796
- const x = P(
796
+ const ee = P(
797
797
  B(
798
- async (e, n) => {
798
+ async (e, r) => {
799
799
  const o = await _({
800
- cacheTime: b,
801
- ...n
802
- }), r = new N(), t = n?.client ?? $;
803
- r.moveCall({
800
+ cacheTime: w,
801
+ ...r
802
+ }), n = new N(), t = r?.client ?? S;
803
+ n.moveCall({
804
804
  target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
805
- arguments: [r.object(o.emode.contract.registryObject), r.pure.address(e)]
805
+ arguments: [n.object(o.emode.contract.registryObject), n.pure.address(e)]
806
806
  });
807
807
  const s = (await t.devInspectTransactionBlock({
808
- transactionBlock: r,
808
+ transactionBlock: n,
809
809
  sender: e
810
- })).results[0].returnValues, i = C.vector(C.u64()).parse(Uint8Array.from(s[0][0])), c = C.vector(C.u64()).parse(Uint8Array.from(s[1][0])), u = C.vector(C.Address).parse(Uint8Array.from(s[2][0]));
810
+ })).results[0].returnValues, i = C.vector(C.u64()).parse(Uint8Array.from(s[0][0])), c = C.vector(C.u64()).parse(Uint8Array.from(s[1][0])), l = C.vector(C.Address).parse(Uint8Array.from(s[2][0]));
811
811
  return i.map((d, y) => ({
812
812
  marketId: Number(d),
813
813
  emodeId: Number(c[y]),
814
- accountCap: u[y].toString()
814
+ accountCap: l[y].toString()
815
815
  }));
816
816
  }
817
817
  )
818
818
  );
819
- function rt(e) {
820
- return `${j(e.marketId).key}-${e.emodeId}`;
819
+ function at(e) {
820
+ return `${I(e.marketId).key}-${e.emodeId}`;
821
821
  }
822
- function at(e, n, o) {
823
- const r = typeof o?.balance == "number", t = r ? o.balance : 0;
822
+ function it(e, r, o) {
823
+ const n = typeof o?.balance == "number", t = n ? o.balance : 0;
824
824
  let a = 0;
825
825
  const s = [];
826
826
  let i = "";
827
- if (n.sort((c, u) => Number(u.balance) - Number(c.balance)).forEach((c) => {
828
- if (!(r && a >= t) && Number(c.balance) !== 0) {
827
+ if (r.sort((c, l) => Number(l.balance) - Number(c.balance)).forEach((c) => {
828
+ if (!(n && a >= t) && Number(c.balance) !== 0) {
829
829
  if (i || (i = c.coinType), i !== c.coinType)
830
830
  throw new Error("All coins must be of the same type");
831
831
  a += Number(c.balance), s.push(c.coinObjectId);
832
832
  }
833
833
  }), s.length === 0)
834
834
  throw new Error("No coins to merge");
835
- if (r && a < t)
835
+ if (n && a < t)
836
836
  throw new Error(
837
837
  `Balance is less than the specified balance: ${a} < ${t}`
838
838
  );
839
- return k(i) === k("0x2::sui::SUI") && o?.useGasCoin ? r ? e.splitCoins(e.gas, [e.pure.u64(t)]) : e.gas : (s.length === 1 ? e.object(s[0]) : e.mergeCoins(s[0], s.slice(1)), r ? e.splitCoins(s[0], [e.pure.u64(t)]) : s[0]);
839
+ return b(i) === b("0x2::sui::SUI") && o?.useGasCoin ? n ? e.splitCoins(e.gas, [e.pure.u64(t)]) : e.gas : (s.length === 1 ? e.object(s[0]) : e.mergeCoins(s[0], s.slice(1)), n ? e.splitCoins(s[0], [e.pure.u64(t)]) : s[0]);
840
840
  }
841
- async function ee(e, n, o, r, t, a, s) {
841
+ async function te(e, r, o, n, t, a, s) {
842
842
  const i = await _({
843
843
  ...s,
844
- cacheTime: b
844
+ cacheTime: w
845
845
  }), c = await A(o, s);
846
846
  return e.moveCall({
847
847
  target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
@@ -849,123 +849,123 @@ async function ee(e, n, o, r, t, a, s) {
849
849
  e.object("0x06"),
850
850
  e.object(i.storage),
851
851
  e.object(i.oracle.priceOracle),
852
- we(e, c),
853
- h(n, e.pure.address),
852
+ be(e, c),
853
+ h(r, e.pure.address),
854
854
  h(c.id, e.pure.u8),
855
- h(r, e.pure.u64),
855
+ h(n, e.pure.u64),
856
856
  h(t, e.pure.u64),
857
857
  h(a, e.pure.bool)
858
858
  ],
859
859
  typeArguments: [c.suiCoinType]
860
860
  });
861
861
  }
862
- async function Ae(e, n, o) {
863
- return ee(e, n, 0, 0, 0, !1, o);
862
+ async function Pe(e, r, o) {
863
+ return te(e, r, 0, 0, 0, !1, o);
864
864
  }
865
- async function te(e, n, o) {
866
- const r = new N(), t = o?.client ?? $, a = await R({
865
+ async function oe(e, r, o) {
866
+ const n = new N(), t = o?.client ?? S, a = await q({
867
867
  ...o,
868
868
  markets: Object.values(E)
869
- }), s = H(a);
870
- for (let d of n) {
869
+ }), s = G(a);
870
+ for (let d of r) {
871
871
  const y = await _({
872
872
  ...o,
873
- cacheTime: b,
873
+ cacheTime: w,
874
874
  market: d.market
875
875
  });
876
- r.moveCall({
876
+ n.moveCall({
877
877
  target: `${y.uiGetter}::getter_unchecked::get_user_state`,
878
- arguments: [r.object(y.storage), r.pure.address(d.address)]
878
+ arguments: [n.object(y.storage), n.pure.address(d.address)]
879
879
  });
880
880
  }
881
881
  const c = ((await t.devInspectTransactionBlock({
882
- transactionBlock: r,
882
+ transactionBlock: n,
883
883
  sender: e
884
- })).results || []).map((d) => d.returnValues?.map((y) => C.vector(fe).parse(Uint8Array.from(y[0])))[0] || []), u = [];
884
+ })).results || []).map((d) => d.returnValues?.map((y) => C.vector(ye).parse(Uint8Array.from(y[0])))[0] || []), l = [];
885
885
  return c.forEach((d, y) => {
886
- const v = n[y], g = j(v.market);
887
- d.forEach((l) => {
888
- if (l.supply_balance === "0" && l.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
886
+ const v = r[y], g = I(v.market);
887
+ d.forEach((u) => {
888
+ if (u.supply_balance === "0" && u.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
889
889
  return;
890
- const f = s[`${g.key}-${l.asset_id}`];
890
+ const f = s[`${g.key}-${u.asset_id}`];
891
891
  if (!f)
892
892
  return;
893
- const w = Y(
894
- l.supply_balance,
893
+ const k = J(
894
+ u.supply_balance,
895
895
  f.currentSupplyIndex
896
- ).toString(), I = Y(
897
- l.borrow_balance,
896
+ ).toString(), j = J(
897
+ u.borrow_balance,
898
898
  f.currentBorrowIndex
899
899
  ).toString();
900
- u.push({
901
- supplyBalance: w,
902
- borrowBalance: I,
903
- assetId: l.asset_id,
900
+ l.push({
901
+ supplyBalance: k,
902
+ borrowBalance: j,
903
+ assetId: u.asset_id,
904
904
  market: g.key,
905
905
  pool: f,
906
906
  emodeId: v.emodeId
907
907
  });
908
908
  });
909
- }), u;
909
+ }), l;
910
910
  }
911
- const it = P(
912
- async (e, n) => {
913
- const r = (n?.markets || Object.keys(E)).map((t) => j(t)).map((t) => ({
911
+ const ct = P(
912
+ async (e, r) => {
913
+ const n = (r?.markets || Object.keys(E)).map((t) => I(t)).map((t) => ({
914
914
  address: e,
915
915
  market: t.key
916
916
  }));
917
- return await te(e, r, n);
917
+ return await oe(e, n, r);
918
918
  }
919
919
  );
920
- async function ct(e, n) {
921
- const o = n?.client ?? $, r = new N();
922
- await Ae(r, e, n);
920
+ async function st(e, r) {
921
+ const o = r?.client ?? S, n = new N();
922
+ await Pe(n, e, r);
923
923
  const t = await o.devInspectTransactionBlock({
924
- transactionBlock: r,
924
+ transactionBlock: n,
925
925
  sender: e
926
- }), a = L(t, [C.u256()]);
927
- return X(Number(a[0]) || 0);
926
+ }), a = W(t, [C.u256()]);
927
+ return x(Number(a[0]) || 0);
928
928
  }
929
- async function st(e, n, o, r) {
930
- const t = r?.client ?? $, a = new N();
929
+ async function lt(e, r, o, n) {
930
+ const t = n?.client ?? S, a = new N();
931
931
  let s = 0, i = 0;
932
- const c = await A(n, r);
932
+ const c = await A(r, n);
933
933
  if (o.forEach((v) => {
934
- v.type === F.Supply ? s += v.amount : v.type === F.Withdraw ? s -= v.amount : v.type === F.Borrow ? i += v.amount : v.type === F.Repay && (i -= v.amount);
934
+ v.type === R.Supply ? s += v.amount : v.type === R.Withdraw ? s -= v.amount : v.type === R.Borrow ? i += v.amount : v.type === R.Repay && (i -= v.amount);
935
935
  }), s * i < 0)
936
936
  throw new Error("Invalid operations");
937
- const u = s > 0 || i > 0;
938
- await ee(
937
+ const l = s > 0 || i > 0;
938
+ await te(
939
939
  a,
940
940
  e,
941
941
  c,
942
942
  Math.abs(s),
943
943
  Math.abs(i),
944
- u,
945
- r
944
+ l,
945
+ n
946
946
  );
947
947
  const d = await t.devInspectTransactionBlock({
948
948
  transactionBlock: a,
949
949
  sender: e
950
- }), y = L(d, [C.u256()]);
951
- return X(Number(y[0]) || 0);
950
+ }), y = W(d, [C.u256()]);
951
+ return x(Number(y[0]) || 0);
952
952
  }
953
953
  const ut = B(
954
- async (e, n) => {
954
+ async (e, r) => {
955
955
  const o = new URLSearchParams();
956
- n?.cursor && o.set("cursor", n.cursor), o.set("userAddress", e);
957
- const r = `https://open-api.naviprotocol.io/api/navi/user/transactions?${o.toString()}&sdk=${S.version}`;
958
- return (await fetch(r, { headers: M }).then((a) => a.json())).data;
956
+ r?.cursor && o.set("cursor", r.cursor), o.set("userAddress", e);
957
+ const n = `https://open-api.naviprotocol.io/api/navi/user/transactions?${o.toString()}&sdk=${V.version}`;
958
+ return (await fetch(n, { headers: M }).then((a) => a.json())).data;
959
959
  }
960
960
  );
961
- async function lt(e, n) {
961
+ async function pt(e, r) {
962
962
  let o = null;
963
- const r = [], t = n?.client ?? $;
963
+ const n = [], t = r?.client ?? S;
964
964
  do {
965
965
  let a;
966
- if (n?.coinType ? a = await t.getCoins({
966
+ if (r?.coinType ? a = await t.getCoins({
967
967
  owner: e,
968
- coinType: n?.coinType,
968
+ coinType: r?.coinType,
969
969
  cursor: o,
970
970
  limit: 100
971
971
  }) : a = await t.getAllCoins({
@@ -974,39 +974,39 @@ async function lt(e, n) {
974
974
  limit: 100
975
975
  }), !a.data || !a.data.length)
976
976
  break;
977
- r.push(...a.data), o = a.nextCursor;
977
+ n.push(...a.data), o = a.nextCursor;
978
978
  } while (o);
979
- return r;
979
+ return n;
980
980
  }
981
- const Pe = P(
982
- async (e, n) => {
983
- const o = [], r = (n?.markets || Object.keys(E)).map((i) => j(i));
981
+ const $e = P(
982
+ async (e, r) => {
983
+ const o = [], n = (r?.markets || Object.keys(E)).map((i) => I(i));
984
984
  let t = [];
985
985
  try {
986
- t = await x(e, n);
986
+ t = await ee(e, r);
987
987
  } catch (i) {
988
988
  console.error(i);
989
989
  }
990
- const a = r.map((i) => ({
990
+ const a = n.map((i) => ({
991
991
  address: e,
992
992
  market: i.key
993
993
  })).concat(
994
- t.filter((i) => !!r.find((c) => c.id === i.marketId)).map((i) => ({
994
+ t.filter((i) => !!n.find((c) => c.id === i.marketId)).map((i) => ({
995
995
  address: i.accountCap,
996
- market: j(i.marketId).key,
996
+ market: I(i.marketId).key,
997
997
  emodeId: i.emodeId
998
998
  }))
999
999
  );
1000
- return (await te(e, a, n)).forEach((i) => {
1001
- const c = typeof i.emodeId == "number" ? t.find((u) => {
1002
- const d = j(i.market);
1003
- return u.emodeId === i.emodeId && u.marketId === d.id;
1000
+ return (await oe(e, a, r)).forEach((i) => {
1001
+ const c = typeof i.emodeId == "number" ? t.find((l) => {
1002
+ const d = I(i.market);
1003
+ return l.emodeId === i.emodeId && l.marketId === d.id;
1004
1004
  }) : void 0;
1005
1005
  if (c) {
1006
1006
  if (!i.pool.emodes.find((d) => d.emodeId === c.emodeId))
1007
1007
  return;
1008
1008
  if (p(i.supplyBalance).gte(0)) {
1009
- const d = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = q(i.pool, c);
1009
+ const d = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = L(i.pool, c);
1010
1010
  if (d.gt(0) || y.emode.isCollateral)
1011
1011
  try {
1012
1012
  o.push({
@@ -1017,7 +1017,7 @@ const Pe = P(
1017
1017
  type: "navi-lending-emode-supply",
1018
1018
  "navi-lending-emode-supply": {
1019
1019
  amount: d.toString(),
1020
- pool: q(i.pool, c),
1020
+ pool: L(i.pool, c),
1021
1021
  token: i.pool.token,
1022
1022
  valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
1023
1023
  emodeCap: c
@@ -1028,7 +1028,7 @@ const Pe = P(
1028
1028
  }
1029
1029
  }
1030
1030
  if (p(i.borrowBalance).gte(0)) {
1031
- const d = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = q(i.pool, c);
1031
+ const d = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = L(i.pool, c);
1032
1032
  if (d.gt(0) || y.emode.isDebt)
1033
1033
  try {
1034
1034
  o.push({
@@ -1039,7 +1039,7 @@ const Pe = P(
1039
1039
  type: "navi-lending-emode-borrow",
1040
1040
  "navi-lending-emode-borrow": {
1041
1041
  amount: d.toString(),
1042
- pool: q(i.pool, c),
1042
+ pool: L(i.pool, c),
1043
1043
  token: i.pool.token,
1044
1044
  valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
1045
1045
  emodeCap: c
@@ -1051,7 +1051,7 @@ const Pe = P(
1051
1051
  }
1052
1052
  } else {
1053
1053
  if (p(i.supplyBalance).gt(0)) {
1054
- const u = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1054
+ const l = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1055
1055
  o.push({
1056
1056
  id: `${i.pool.uniqueId}_navi-lending-supply-${T()}`,
1057
1057
  wallet: e,
@@ -1059,15 +1059,15 @@ const Pe = P(
1059
1059
  type: "navi-lending-supply",
1060
1060
  market: i.market,
1061
1061
  "navi-lending-supply": {
1062
- amount: u.toString(),
1062
+ amount: l.toString(),
1063
1063
  pool: i.pool,
1064
1064
  token: i.pool.token,
1065
- valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
1065
+ valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
1066
1066
  }
1067
1067
  });
1068
1068
  }
1069
1069
  if (p(i.borrowBalance).gt(0)) {
1070
- const u = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1070
+ const l = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1071
1071
  o.push({
1072
1072
  id: `${i.pool.uniqueId}_navi-lending-borrow-${T()}`,
1073
1073
  wallet: e,
@@ -1075,10 +1075,10 @@ const Pe = P(
1075
1075
  market: i.market,
1076
1076
  type: "navi-lending-borrow",
1077
1077
  "navi-lending-borrow": {
1078
- amount: u.toString(),
1078
+ amount: l.toString(),
1079
1079
  pool: i.pool,
1080
1080
  token: i.pool.token,
1081
- valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
1081
+ valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
1082
1082
  }
1083
1083
  });
1084
1084
  }
@@ -1087,7 +1087,7 @@ const Pe = P(
1087
1087
  }
1088
1088
  );
1089
1089
  class O {
1090
- constructor(n, o) {
1090
+ constructor(r, o) {
1091
1091
  this._positions = [], this._priceMap = {}, this._overview = {
1092
1092
  hf: 1 / 0,
1093
1093
  netVaule: "0",
@@ -1100,7 +1100,7 @@ class O {
1100
1100
  maxLoanToVaule: "0",
1101
1101
  supply: {},
1102
1102
  borrow: {}
1103
- }, this._priceMap = o || {}, this.positions = n;
1103
+ }, this._priceMap = o || {}, this.positions = r;
1104
1104
  }
1105
1105
  get positions() {
1106
1106
  return this._positions;
@@ -1111,33 +1111,33 @@ class O {
1111
1111
  get priceMap() {
1112
1112
  return this._priceMap;
1113
1113
  }
1114
- set positions(n) {
1115
- this._positions = n, this._overview = this.getPositionsOverview(n);
1114
+ set positions(r) {
1115
+ this._positions = r, this._overview = this.getPositionsOverview(r);
1116
1116
  }
1117
- updatePriceMap(n) {
1118
- return this._priceMap = n, this._overview = this.getPositionsOverview(this._positions), this;
1117
+ updatePriceMap(r) {
1118
+ return this._priceMap = r, this._overview = this.getPositionsOverview(this._positions), this;
1119
1119
  }
1120
- getPrice(n) {
1121
- const o = k(n.suiCoinType);
1120
+ getPrice(r) {
1121
+ const o = b(r.suiCoinType);
1122
1122
  if (this._priceMap[o] !== void 0)
1123
1123
  return this._priceMap[o].toString();
1124
- const r = n.suiCoinType;
1125
- return this._priceMap[r] !== void 0 ? this._priceMap[r].toString() : n.oracle.price;
1124
+ const n = r.suiCoinType;
1125
+ return this._priceMap[n] !== void 0 ? this._priceMap[n].toString() : r.oracle.price;
1126
1126
  }
1127
- filterPositionsByPool(n) {
1128
- const r = !!n.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
1127
+ filterPositionsByPool(r) {
1128
+ const n = !!r.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
1129
1129
  return new O(
1130
1130
  this.positions.filter((t) => {
1131
1131
  const a = t[t.type];
1132
- return r.includes(t.type) && a.pool.uniqueId === n.uniqueId;
1132
+ return n.includes(t.type) && a.pool.uniqueId === r.uniqueId;
1133
1133
  }),
1134
1134
  this._priceMap
1135
1135
  );
1136
1136
  }
1137
- deposit(n, o) {
1138
- const r = !!n.isEMode, t = this.getPrice(n);
1137
+ deposit(r, o) {
1138
+ const n = !!r.isEMode, t = this.getPrice(r);
1139
1139
  let a;
1140
- return r ? a = {
1140
+ return n ? a = {
1141
1141
  id: T(),
1142
1142
  wallet: "",
1143
1143
  protocol: "navi",
@@ -1146,8 +1146,8 @@ class O {
1146
1146
  "navi-lending-emode-supply": {
1147
1147
  amount: o.toString(),
1148
1148
  valueUSD: p(o).multipliedBy(t).toString(),
1149
- token: n.token,
1150
- pool: n,
1149
+ token: r.token,
1150
+ pool: r,
1151
1151
  emodeCap: {}
1152
1152
  }
1153
1153
  } : a = {
@@ -1159,15 +1159,15 @@ class O {
1159
1159
  "navi-lending-supply": {
1160
1160
  amount: o.toString(),
1161
1161
  valueUSD: p(o).multipliedBy(t).toString(),
1162
- token: n.token,
1163
- pool: n
1162
+ token: r.token,
1163
+ pool: r
1164
1164
  }
1165
1165
  }, new O([...this.positions, a], this._priceMap);
1166
1166
  }
1167
- withdraw(n, o) {
1168
- const r = !!n.isEMode, t = this.getPrice(n);
1167
+ withdraw(r, o) {
1168
+ const n = !!r.isEMode, t = this.getPrice(r);
1169
1169
  let a;
1170
- return r ? a = {
1170
+ return n ? a = {
1171
1171
  id: T(),
1172
1172
  wallet: "",
1173
1173
  protocol: "navi",
@@ -1176,8 +1176,8 @@ class O {
1176
1176
  "navi-lending-emode-supply": {
1177
1177
  amount: (-o).toString(),
1178
1178
  valueUSD: p(-o).multipliedBy(t).toString(),
1179
- token: n.token,
1180
- pool: n,
1179
+ token: r.token,
1180
+ pool: r,
1181
1181
  emodeCap: {}
1182
1182
  }
1183
1183
  } : a = {
@@ -1189,15 +1189,15 @@ class O {
1189
1189
  "navi-lending-supply": {
1190
1190
  amount: (-o).toString(),
1191
1191
  valueUSD: p(-o).multipliedBy(t).toString(),
1192
- token: n.token,
1193
- pool: n
1192
+ token: r.token,
1193
+ pool: r
1194
1194
  }
1195
1195
  }, new O([...this.positions, a], this._priceMap);
1196
1196
  }
1197
- borrow(n, o) {
1198
- const r = !!n.isEMode, t = this.getPrice(n);
1197
+ borrow(r, o) {
1198
+ const n = !!r.isEMode, t = this.getPrice(r);
1199
1199
  let a;
1200
- return r ? a = {
1200
+ return n ? a = {
1201
1201
  id: T(),
1202
1202
  wallet: "",
1203
1203
  protocol: "navi",
@@ -1206,8 +1206,8 @@ class O {
1206
1206
  "navi-lending-emode-borrow": {
1207
1207
  amount: o.toString(),
1208
1208
  valueUSD: p(o).multipliedBy(t).toString(),
1209
- token: n.token,
1210
- pool: n,
1209
+ token: r.token,
1210
+ pool: r,
1211
1211
  emodeCap: {}
1212
1212
  }
1213
1213
  } : a = {
@@ -1219,15 +1219,15 @@ class O {
1219
1219
  "navi-lending-borrow": {
1220
1220
  amount: o.toString(),
1221
1221
  valueUSD: p(o).multipliedBy(t).toString(),
1222
- token: n.token,
1223
- pool: n
1222
+ token: r.token,
1223
+ pool: r
1224
1224
  }
1225
1225
  }, new O([...this.positions, a], this._priceMap);
1226
1226
  }
1227
- repay(n, o) {
1228
- const r = !!n.isEMode, t = this.getPrice(n);
1227
+ repay(r, o) {
1228
+ const n = !!r.isEMode, t = this.getPrice(r);
1229
1229
  let a;
1230
- return r ? a = {
1230
+ return n ? a = {
1231
1231
  id: T(),
1232
1232
  wallet: "",
1233
1233
  protocol: "navi",
@@ -1236,8 +1236,8 @@ class O {
1236
1236
  "navi-lending-emode-borrow": {
1237
1237
  amount: (-o).toString(),
1238
1238
  valueUSD: p(-o).multipliedBy(t).toString(),
1239
- token: n.token,
1240
- pool: n,
1239
+ token: r.token,
1240
+ pool: r,
1241
1241
  emodeCap: {}
1242
1242
  }
1243
1243
  } : a = {
@@ -1249,62 +1249,62 @@ class O {
1249
1249
  "navi-lending-borrow": {
1250
1250
  amount: (-o).toString(),
1251
1251
  valueUSD: p(-o).multipliedBy(t).toString(),
1252
- token: n.token,
1253
- pool: n
1252
+ token: r.token,
1253
+ pool: r
1254
1254
  }
1255
1255
  }, new O([...this.positions, a], this._priceMap);
1256
1256
  }
1257
- resolveValueUSD(n) {
1258
- return Object.keys(this._priceMap).length > 0 ? p(n.amount).multipliedBy(this.getPrice(n.pool)).toString() : n.valueUSD;
1257
+ resolveValueUSD(r) {
1258
+ return Object.keys(this._priceMap).length > 0 ? p(r.amount).multipliedBy(this.getPrice(r.pool)).toString() : r.valueUSD;
1259
1259
  }
1260
- getPositionsOverview(n) {
1261
- const o = {}, r = {};
1262
- let t = new p(0), a = new p(0), s = new p(0), i = new p(0), c = new p(0), u = new p(0);
1263
- n.forEach((g) => {
1260
+ getPositionsOverview(r) {
1261
+ const o = {}, n = {};
1262
+ let t = new p(0), a = new p(0), s = new p(0), i = new p(0), c = new p(0), l = new p(0);
1263
+ r.forEach((g) => {
1264
1264
  if (g.type === "navi-lending-supply") {
1265
- const l = g["navi-lending-supply"], f = this.resolveValueUSD(l);
1265
+ const u = g["navi-lending-supply"], f = this.resolveValueUSD(u);
1266
1266
  t = t.plus(f), c = c.plus(
1267
- new p(f).multipliedBy(l.pool.liquidationFactor.threshold)
1268
- ), u = u.plus(
1269
- new p(f).multipliedBy(l.pool.ltvValue)
1267
+ new p(f).multipliedBy(u.pool.liquidationFactor.threshold)
1268
+ ), l = l.plus(
1269
+ new p(f).multipliedBy(u.pool.ltvValue)
1270
1270
  );
1271
1271
  } else if (g.type === "navi-lending-borrow") {
1272
- const l = g["navi-lending-borrow"];
1273
- a = a.plus(this.resolveValueUSD(l));
1272
+ const u = g["navi-lending-borrow"];
1273
+ a = a.plus(this.resolveValueUSD(u));
1274
1274
  } else if (g.type === "navi-lending-emode-supply") {
1275
- const l = g["navi-lending-emode-supply"], f = this.resolveValueUSD(l);
1275
+ const u = g["navi-lending-emode-supply"], f = this.resolveValueUSD(u);
1276
1276
  t = t.plus(f);
1277
- const w = l.pool.emode;
1277
+ const k = u.pool.emode;
1278
1278
  c = c.plus(
1279
- new p(f).multipliedBy(w.lt)
1280
- ), u = u.plus(
1281
- new p(f).multipliedBy(w.ltv)
1279
+ new p(f).multipliedBy(k.lt)
1280
+ ), l = l.plus(
1281
+ new p(f).multipliedBy(k.ltv)
1282
1282
  );
1283
1283
  } else if (g.type === "navi-lending-emode-borrow") {
1284
- const l = g["navi-lending-emode-borrow"];
1285
- a = a.plus(this.resolveValueUSD(l));
1284
+ const u = g["navi-lending-emode-borrow"];
1285
+ a = a.plus(this.resolveValueUSD(u));
1286
1286
  }
1287
- }), a = p.max(a, 0), t = p.max(t, 0), c = p.max(c, 0), u = p.max(u, 0), n.forEach((g) => {
1287
+ }), a = p.max(a, 0), t = p.max(t, 0), c = p.max(c, 0), l = p.max(l, 0), r.forEach((g) => {
1288
1288
  if (g.type === "navi-lending-supply") {
1289
- const l = g["navi-lending-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
1289
+ const u = g["navi-lending-supply"], f = this.resolveValueUSD(u), k = u.pool.supplyIncentiveApyInfo.apy;
1290
1290
  t.gt(0) && (s = s.plus(
1291
- new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
1292
- )), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1291
+ new p(f).dividedBy(t).multipliedBy(new p(k).dividedBy(100))
1292
+ )), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1293
1293
  } else if (g.type === "navi-lending-borrow") {
1294
- const l = g["navi-lending-borrow"], f = this.resolveValueUSD(l), w = l.pool.borrowIncentiveApyInfo.apy;
1294
+ const u = g["navi-lending-borrow"], f = this.resolveValueUSD(u), k = u.pool.borrowIncentiveApyInfo.apy;
1295
1295
  a.gt(0) && (i = i.plus(
1296
- new p(f).dividedBy(a).multipliedBy(new p(w).dividedBy(100))
1297
- )), r[l.pool.suiCoinType] = p(r[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1296
+ new p(f).dividedBy(a).multipliedBy(new p(k).dividedBy(100))
1297
+ )), n[u.pool.suiCoinType] = p(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1298
1298
  } else if (g.type === "navi-lending-emode-supply") {
1299
- const l = g["navi-lending-emode-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
1299
+ const u = g["navi-lending-emode-supply"], f = this.resolveValueUSD(u), k = u.pool.supplyIncentiveApyInfo.apy;
1300
1300
  t.gt(0) && (s = s.plus(
1301
- new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
1302
- )), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1301
+ new p(f).dividedBy(t).multipliedBy(new p(k).dividedBy(100))
1302
+ )), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1303
1303
  } else if (g.type === "navi-lending-emode-borrow") {
1304
- const l = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(l), w = l.pool.borrowIncentiveApyInfo.apy;
1304
+ const u = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(u), k = u.pool.borrowIncentiveApyInfo.apy;
1305
1305
  a.gt(0) && (i = i.plus(
1306
- new p(f).dividedBy(a).multipliedBy(new p(w).dividedBy(100))
1307
- )), r[l.pool.suiCoinType] = p(r[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1306
+ new p(f).dividedBy(a).multipliedBy(new p(k).dividedBy(100))
1307
+ )), n[u.pool.suiCoinType] = p(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1308
1308
  }
1309
1309
  });
1310
1310
  const d = t.minus(a), y = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(s).minus(a.multipliedBy(i)).div(t.minus(a));
@@ -1317,16 +1317,16 @@ class O {
1317
1317
  totalsupplyApy: s.toString(),
1318
1318
  totalBorrowApy: i.toString(),
1319
1319
  maxLiquidationValue: c.toString(),
1320
- maxLoanToVaule: u.toString(),
1320
+ maxLoanToVaule: l.toString(),
1321
1321
  supply: o,
1322
- borrow: r
1322
+ borrow: n
1323
1323
  };
1324
1324
  }
1325
1325
  }
1326
- async function pt(e, n, o, r) {
1326
+ async function dt(e, r, o, n) {
1327
1327
  const t = await _({
1328
- ...r,
1329
- cacheTime: b
1328
+ ...n,
1329
+ cacheTime: w
1330
1330
  });
1331
1331
  t.limter && e.moveCall({
1332
1332
  target: `${t.limter}::navi_adaptor::verify_navi_position_healthy`,
@@ -1334,39 +1334,39 @@ async function pt(e, n, o, r) {
1334
1334
  e.object("0x06"),
1335
1335
  e.object(t.storage),
1336
1336
  e.object(t.priceOracle),
1337
- h(n, e.pure.address),
1337
+ h(r, e.pure.address),
1338
1338
  e.pure.u256(new p(o).shiftedBy(27).toNumber())
1339
1339
  ]
1340
1340
  });
1341
1341
  }
1342
- const oe = new Z("https://hermes.pyth.network", {
1342
+ const re = new Q("https://hermes.pyth.network", {
1343
1343
  timeout: 1e4
1344
1344
  });
1345
- async function dt(e) {
1345
+ async function mt(e) {
1346
1346
  try {
1347
- const n = [], o = await oe.getLatestPriceFeeds(e);
1348
- if (!o) return n;
1349
- const r = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1347
+ const r = [], o = await re.getLatestPriceFeeds(e);
1348
+ if (!o) return r;
1349
+ const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1350
1350
  for (const t of o) {
1351
1351
  const a = t.getPriceUnchecked();
1352
- if (a.publishTime > r) {
1352
+ if (a.publishTime > n) {
1353
1353
  console.warn(
1354
- `pyth price feed is invalid, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`
1354
+ `pyth price feed is invalid, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
1355
1355
  );
1356
1356
  continue;
1357
1357
  }
1358
- r - t.getPriceUnchecked().publishTime > 30 && (console.info(
1359
- `stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`
1360
- ), n.push(t.id));
1358
+ n - t.getPriceUnchecked().publishTime > 30 && (console.info(
1359
+ `stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
1360
+ ), r.push(t.id));
1361
1361
  }
1362
- return n;
1363
- } catch (n) {
1364
- throw new Error(`failed to get pyth stale price feed id, msg: ${n.message}`);
1362
+ return r;
1363
+ } catch (r) {
1364
+ throw new Error(`failed to get pyth stale price feed id, msg: ${r.message}`);
1365
1365
  }
1366
1366
  }
1367
- async function $e(e, n) {
1367
+ async function Se(e, r) {
1368
1368
  try {
1369
- const o = [], r = n?.client ?? $, t = e.map((s) => s.priceInfoObject), a = await r.multiGetObjects({
1369
+ const o = [], n = r?.client ?? S, t = e.map((s) => s.priceInfoObject), a = await n.multiGetObjects({
1370
1370
  ids: Array.from(new Set(t)),
1371
1371
  options: { showContent: !0 }
1372
1372
  });
@@ -1376,12 +1376,12 @@ async function $e(e, n) {
1376
1376
  console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
1377
1377
  continue;
1378
1378
  }
1379
- const c = e.find((l) => l.priceInfoObject == i.objectId);
1379
+ const c = e.find((u) => u.priceInfoObject == i.objectId);
1380
1380
  if (!c) {
1381
1381
  console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
1382
1382
  continue;
1383
1383
  }
1384
- const u = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: d, negative: y } = u.price.fields, v = u.conf, g = u.timestamp;
1384
+ const l = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: d, negative: y } = l.price.fields, v = l.conf, g = l.timestamp;
1385
1385
  o.push({
1386
1386
  priceFeedId: c.priceFeedId,
1387
1387
  priceInfoObject: c.priceInfoObject,
@@ -1397,12 +1397,12 @@ async function $e(e, n) {
1397
1397
  return;
1398
1398
  }
1399
1399
  }
1400
- async function Se(e, n) {
1400
+ async function Ve(e, r) {
1401
1401
  try {
1402
- const o = [], r = await $e(e, n);
1403
- if (!r) return o;
1402
+ const o = [], n = await Se(e, r);
1403
+ if (!n) return o;
1404
1404
  const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1405
- for (const a of r) {
1405
+ for (const a of n) {
1406
1406
  if (a.publishTime > t) {
1407
1407
  console.warn(
1408
1408
  `pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
@@ -1419,51 +1419,51 @@ async function Se(e, n) {
1419
1419
  throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`);
1420
1420
  }
1421
1421
  }
1422
- async function Ve(e, n, o) {
1423
- const r = o?.client ?? $, t = await _({
1422
+ async function Me(e, r, o) {
1423
+ const n = o?.client ?? S, t = await _({
1424
1424
  ...o,
1425
- cacheTime: b
1425
+ cacheTime: w
1426
1426
  });
1427
1427
  try {
1428
- const a = await oe.getPriceFeedsUpdateData(n);
1429
- return await new de(
1430
- r,
1428
+ const a = await re.getPriceFeedsUpdateData(r);
1429
+ return await new me(
1430
+ n,
1431
1431
  t.oracle.pythStateId,
1432
1432
  t.oracle.wormholeStateId
1433
- ).updatePriceFeeds(e, a, n);
1433
+ ).updatePriceFeeds(e, a, r);
1434
1434
  } catch (a) {
1435
1435
  throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
1436
1436
  }
1437
1437
  }
1438
- async function Me(e, n, o) {
1439
- const r = await _({
1438
+ async function Ee(e, r, o) {
1439
+ const n = await _({
1440
1440
  ...o,
1441
- cacheTime: b
1441
+ cacheTime: w
1442
1442
  });
1443
1443
  if (o?.updatePythPriceFeeds) {
1444
- const t = n.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
1444
+ const t = r.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
1445
1445
  priceFeedId: a.pythPriceFeedId,
1446
1446
  priceInfoObject: a.pythPriceInfoObject,
1447
1447
  expiration: 30
1448
1448
  }));
1449
1449
  try {
1450
- const a = await Se(t, o);
1451
- a.length > 0 && await Ve(e, a, o);
1450
+ const a = await Ve(t, o);
1451
+ a.length > 0 && await Me(e, a, o);
1452
1452
  } catch {
1453
1453
  console.error("Failed to update Pyth price feeds");
1454
1454
  }
1455
1455
  }
1456
- for (const t of n)
1456
+ for (const t of r)
1457
1457
  o?.env === "dev" ? e.moveCall({
1458
- target: `${r.oracle.packageId}::oracle_pro::update_single_price`,
1458
+ target: `${n.oracle.packageId}::oracle_pro::update_single_price`,
1459
1459
  arguments: [
1460
1460
  e.object("0x6"),
1461
1461
  // Clock object
1462
- e.object(r.oracle.oracleConfig),
1462
+ e.object(n.oracle.oracleConfig),
1463
1463
  // Oracle configuration
1464
- e.object(r.oracle.priceOracle),
1464
+ e.object(n.oracle.priceOracle),
1465
1465
  // Price oracle contract
1466
- e.object(r.oracle.supraOracleHolder),
1466
+ e.object(n.oracle.supraOracleHolder),
1467
1467
  // Supra oracle holder
1468
1468
  e.object(t.pythPriceInfoObject),
1469
1469
  // Pyth price info object
@@ -1471,19 +1471,19 @@ async function Me(e, n, o) {
1471
1471
  // Price feed ID
1472
1472
  ]
1473
1473
  }) : e.moveCall({
1474
- target: `${r.oracle.packageId}::oracle_pro::update_single_price_v2`,
1474
+ target: `${n.oracle.packageId}::oracle_pro::update_single_price_v2`,
1475
1475
  arguments: [
1476
1476
  e.object("0x6"),
1477
1477
  // Clock object
1478
- e.object(r.oracle.oracleConfig),
1478
+ e.object(n.oracle.oracleConfig),
1479
1479
  // Oracle configuration
1480
- e.object(r.oracle.priceOracle),
1480
+ e.object(n.oracle.priceOracle),
1481
1481
  // Price oracle contract
1482
- e.object(r.oracle.supraOracleHolder),
1482
+ e.object(n.oracle.supraOracleHolder),
1483
1483
  // Supra oracle holder
1484
1484
  e.object(t.pythPriceInfoObject),
1485
1485
  // Pyth price info object
1486
- e.object(r.oracle.switchboardAggregator),
1486
+ e.object(n.oracle.switchboardAggregator),
1487
1487
  e.pure.address(t.feedId)
1488
1488
  // Price feed ID
1489
1489
  ]
@@ -1493,11 +1493,11 @@ async function Me(e, n, o) {
1493
1493
  async function ne(e) {
1494
1494
  return (await _({
1495
1495
  ...e,
1496
- cacheTime: b
1496
+ cacheTime: w
1497
1497
  })).oracle.feeds;
1498
1498
  }
1499
- function Ee(e, n) {
1500
- return e.filter((o) => !!(n?.lendingState && n.lendingState.find((t) => o.oracleId === t.pool.oracleId) || n?.lendingPositions && n.lendingPositions.find((t) => {
1499
+ function De(e, r) {
1500
+ return e.filter((o) => !!(r?.lendingState && r.lendingState.find((t) => o.oracleId === t.pool.oracleId) || r?.lendingPositions && r.lendingPositions.find((t) => {
1501
1501
  if (![
1502
1502
  "navi-lending-supply",
1503
1503
  "navi-lending-borrow",
@@ -1507,61 +1507,61 @@ function Ee(e, n) {
1507
1507
  return !1;
1508
1508
  const s = t[t.type]?.pool;
1509
1509
  return o.oracleId === s?.oracleId;
1510
- }) || n?.pools && n.pools.find((t) => o.oracleId === t.oracleId)));
1510
+ }) || r?.pools && r.pools.find((t) => o.oracleId === t.oracleId)));
1511
1511
  }
1512
- async function mt(e, n, o, r) {
1512
+ async function ft(e, r, o, n) {
1513
1513
  try {
1514
1514
  const t = await ne({
1515
- ...r
1515
+ ...n
1516
1516
  }), a = [];
1517
- o.forEach((u) => {
1518
- a.includes(u.market) || a.push(u.market);
1517
+ o.forEach((l) => {
1518
+ a.includes(l.market) || a.push(l.market);
1519
1519
  });
1520
- const s = await Pe(n, {
1521
- ...r,
1520
+ const s = await $e(r, {
1521
+ ...n,
1522
1522
  markets: a
1523
- }), i = Ee(t, {
1523
+ }), i = De(t, {
1524
1524
  lendingPositions: s,
1525
1525
  pools: o
1526
1526
  });
1527
- return await Me(e, i, {
1527
+ return await Ee(e, i, {
1528
1528
  updatePythPriceFeeds: !0,
1529
- ...r
1529
+ ...n
1530
1530
  });
1531
1531
  } catch (t) {
1532
- if (r?.throws)
1532
+ if (n?.throws)
1533
1533
  throw t;
1534
1534
  return console.error(t), e;
1535
1535
  }
1536
1536
  }
1537
- const G = P(
1537
+ const z = P(
1538
1538
  B(
1539
1539
  async (e) => {
1540
- const n = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${S.version}&market=${e?.market || D}`, o = await fetch(n, { headers: M }).then((r) => r.json());
1541
- return Object.keys(o.data).map((r) => ({
1542
- ...o.data[r],
1543
- coinType: r
1540
+ const r = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${V.version}&market=${e?.market || U}`, o = await fetch(r, { headers: M }).then((n) => n.json());
1541
+ return Object.keys(o.data).map((n) => ({
1542
+ ...o.data[n],
1543
+ coinType: n
1544
1544
  }));
1545
1545
  }
1546
1546
  )
1547
1547
  );
1548
- async function ft(e, n) {
1549
- return (await G(n)).find((r) => typeof e == "string" ? k(r.coinType) === k(e) : typeof e == "number" ? r.assetId === e : r.assetId === e.id) || null;
1548
+ async function yt(e, r) {
1549
+ return (await z(r)).find((n) => typeof e == "string" ? b(n.coinType) === b(e) : typeof e == "number" ? n.assetId === e : n.assetId === e.id) || null;
1550
1550
  }
1551
- async function yt(e, n, o, r) {
1551
+ async function gt(e, r, o, n) {
1552
1552
  const t = await _({
1553
- ...r,
1554
- cacheTime: b
1555
- }), a = await A(n, r);
1556
- if (!(await G({
1557
- ...r,
1558
- cacheTime: b
1553
+ ...n,
1554
+ cacheTime: w
1555
+ }), a = await A(r, n);
1556
+ if (!(await z({
1557
+ ...n,
1558
+ cacheTime: w
1559
1559
  })).some(
1560
- (c) => k(c.coinType) === k(a.suiCoinType)
1560
+ (c) => b(c.coinType) === b(a.suiCoinType)
1561
1561
  ))
1562
1562
  throw new Error("Pool does not support flashloan");
1563
1563
  if (t.version === 1) {
1564
- const [c, u] = e.moveCall({
1564
+ const [c, l] = e.moveCall({
1565
1565
  target: `${t.package}::lending::flash_loan_with_ctx`,
1566
1566
  arguments: [
1567
1567
  e.object(t.flashloanConfig),
@@ -1570,9 +1570,9 @@ async function yt(e, n, o, r) {
1570
1570
  ],
1571
1571
  typeArguments: [a.suiCoinType]
1572
1572
  });
1573
- return [c, u];
1573
+ return [c, l];
1574
1574
  } else {
1575
- const [c, u] = e.moveCall({
1575
+ const [c, l] = e.moveCall({
1576
1576
  target: `${t.package}::lending::flash_loan_with_ctx_v2`,
1577
1577
  arguments: [
1578
1578
  e.object(t.flashloanConfig),
@@ -1582,39 +1582,39 @@ async function yt(e, n, o, r) {
1582
1582
  ],
1583
1583
  typeArguments: [a.suiCoinType]
1584
1584
  });
1585
- return [c, u];
1585
+ return [c, l];
1586
1586
  }
1587
1587
  }
1588
- async function gt(e, n, o, r, t) {
1588
+ async function ht(e, r, o, n, t) {
1589
1589
  const a = await _({
1590
1590
  ...t,
1591
- cacheTime: b
1592
- }), s = await A(n, t);
1593
- if (!(await G({
1591
+ cacheTime: w
1592
+ }), s = await A(r, t);
1593
+ if (!(await z({
1594
1594
  ...t,
1595
- cacheTime: b
1595
+ cacheTime: w
1596
1596
  })).some(
1597
- (d) => k(d.coinType) === k(s.suiCoinType)
1597
+ (d) => b(d.coinType) === b(s.suiCoinType)
1598
1598
  ))
1599
1599
  throw new Error("Pool does not support flashloan");
1600
- const [u] = e.moveCall({
1600
+ const [l] = e.moveCall({
1601
1601
  target: `${a.package}::lending::flash_repay_with_ctx`,
1602
1602
  arguments: [
1603
1603
  e.object("0x06"),
1604
1604
  e.object(a.storage),
1605
1605
  e.object(s.contract.pool),
1606
1606
  h(o, e.object),
1607
- h(r, e.object)
1607
+ h(n, e.object)
1608
1608
  ],
1609
1609
  typeArguments: [s.suiCoinType]
1610
1610
  });
1611
- return [u];
1611
+ return [l];
1612
1612
  }
1613
- async function ht(e, n, o, r, t, a) {
1613
+ async function vt(e, r, o, n, t, a) {
1614
1614
  const s = {
1615
1615
  ...a,
1616
- cacheTime: b
1617
- }, i = await _(s), c = await A(n, s), u = await A(r, s);
1616
+ cacheTime: w
1617
+ }, i = await _(s), c = await A(r, s), l = await A(n, s);
1618
1618
  if (i.version === 1) {
1619
1619
  const [d, y] = e.moveCall({
1620
1620
  target: `${i.package}::incentive_v3::liquidation`,
@@ -1631,9 +1631,9 @@ async function ht(e, n, o, r, t, a) {
1631
1631
  // Pay asset pool contract
1632
1632
  h(o, e.object),
1633
1633
  // Debt repayment amount
1634
- e.pure.u8(u.id),
1634
+ e.pure.u8(l.id),
1635
1635
  // Collateral asset ID
1636
- e.object(u.contract.pool),
1636
+ e.object(l.contract.pool),
1637
1637
  // Collateral asset pool contract
1638
1638
  h(t, e.pure.address),
1639
1639
  // Borrower address
@@ -1642,7 +1642,7 @@ async function ht(e, n, o, r, t, a) {
1642
1642
  e.object(i.incentiveV3)
1643
1643
  // Incentive V3 contract
1644
1644
  ],
1645
- typeArguments: [c.suiCoinType, u.suiCoinType]
1645
+ typeArguments: [c.suiCoinType, l.suiCoinType]
1646
1646
  });
1647
1647
  return [d, y];
1648
1648
  } else {
@@ -1661,9 +1661,9 @@ async function ht(e, n, o, r, t, a) {
1661
1661
  // Pay asset pool contract
1662
1662
  h(o, e.object),
1663
1663
  // Debt repayment amount
1664
- e.pure.u8(u.id),
1664
+ e.pure.u8(l.id),
1665
1665
  // Collateral asset ID
1666
- e.object(u.contract.pool),
1666
+ e.object(l.contract.pool),
1667
1667
  // Collateral asset pool contract
1668
1668
  h(t, e.pure.address),
1669
1669
  // Borrower address
@@ -1674,21 +1674,21 @@ async function ht(e, n, o, r, t, a) {
1674
1674
  e.object("0x05")
1675
1675
  // SuiSystemState object
1676
1676
  ],
1677
- typeArguments: [c.suiCoinType, u.suiCoinType]
1677
+ typeArguments: [c.suiCoinType, l.suiCoinType]
1678
1678
  });
1679
1679
  return [d, y];
1680
1680
  }
1681
1681
  }
1682
- async function De(e, n, o) {
1683
- const r = o?.client ?? $, t = new N(), a = await R({
1682
+ async function Ue(e, r, o) {
1683
+ const n = o?.client ?? S, t = new N(), a = await q({
1684
1684
  ...o,
1685
1685
  markets: Object.values(E),
1686
- cacheTime: b
1686
+ cacheTime: w
1687
1687
  }), s = await ne(o);
1688
- for (let d of n) {
1688
+ for (let d of r) {
1689
1689
  const y = await _({
1690
1690
  ...o,
1691
- cacheTime: b,
1691
+ cacheTime: w,
1692
1692
  market: d.market
1693
1693
  });
1694
1694
  t.moveCall({
@@ -1705,13 +1705,13 @@ async function De(e, n, o) {
1705
1705
  ]
1706
1706
  });
1707
1707
  }
1708
- const i = await r.devInspectTransactionBlock({
1708
+ const i = await n.devInspectTransactionBlock({
1709
1709
  transactionBlock: t,
1710
1710
  sender: e
1711
1711
  }), c = [];
1712
1712
  i?.results?.forEach((d) => {
1713
1713
  c.push(
1714
- L(
1714
+ W(
1715
1715
  {
1716
1716
  results: [d]
1717
1717
  },
@@ -1730,24 +1730,24 @@ async function De(e, n, o) {
1730
1730
  )
1731
1731
  );
1732
1732
  });
1733
- const u = [];
1733
+ const l = [];
1734
1734
  return c.forEach((d, y) => {
1735
- const v = n[y];
1735
+ const v = r[y];
1736
1736
  if (d.length === 5 && Array.isArray(d[0])) {
1737
1737
  const g = d[0].length;
1738
- for (let l = 0; l < g; l++) {
1738
+ for (let u = 0; u < g; u++) {
1739
1739
  const f = s.find(
1740
- (I) => k(I.coinType) === k(d[1][l])
1741
- ), w = a.find(
1742
- (I) => k(I.coinType) === k(d[0][l]) && I.market === v.market
1740
+ (j) => b(j.coinType) === b(d[1][u])
1741
+ ), k = a.find(
1742
+ (j) => b(j.coinType) === b(d[0][u]) && j.market === v.market
1743
1743
  );
1744
- !f || !w || u.push({
1745
- assetId: w.id,
1746
- assetCoinType: k(d[0][l]),
1747
- rewardCoinType: k(d[1][l]),
1748
- option: Number(d[2][l]),
1749
- userClaimableReward: Number(d[4][l]) / Math.pow(10, f.priceDecimal),
1750
- ruleIds: Array.isArray(d[3][l]) ? d[3][l] : [d[3][l]],
1744
+ !f || !k || l.push({
1745
+ assetId: k.id,
1746
+ assetCoinType: b(d[0][u]),
1747
+ rewardCoinType: b(d[1][u]),
1748
+ option: Number(d[2][u]),
1749
+ userClaimableReward: Number(d[4][u]) / Math.pow(10, f.priceDecimal),
1750
+ ruleIds: Array.isArray(d[3][u]) ? d[3][u] : [d[3][u]],
1751
1751
  market: v.market,
1752
1752
  owner: v.owner,
1753
1753
  address: v.address,
@@ -1755,13 +1755,13 @@ async function De(e, n, o) {
1755
1755
  });
1756
1756
  }
1757
1757
  }
1758
- }), u;
1758
+ }), l;
1759
1759
  }
1760
- async function vt(e, n) {
1761
- const o = (n?.markets || [E.main]).map((a) => j(a));
1762
- let r = [];
1760
+ async function wt(e, r) {
1761
+ const o = (r?.markets || [E.main]).map((a) => I(a));
1762
+ let n = [];
1763
1763
  try {
1764
- r = await x(e, n);
1764
+ n = await ee(e, r);
1765
1765
  } catch (a) {
1766
1766
  console.error(a);
1767
1767
  }
@@ -1770,8 +1770,8 @@ async function vt(e, n) {
1770
1770
  owner: e,
1771
1771
  market: a.key
1772
1772
  })).concat(
1773
- r.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
1774
- const s = j(a.marketId);
1773
+ n.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
1774
+ const s = I(a.marketId);
1775
1775
  return {
1776
1776
  address: a.accountCap,
1777
1777
  owner: e,
@@ -1780,99 +1780,101 @@ async function vt(e, n) {
1780
1780
  };
1781
1781
  })
1782
1782
  );
1783
- return await De(e, t, n);
1783
+ return await Ue(e, t, r);
1784
1784
  }
1785
- function wt(e) {
1786
- const n = /* @__PURE__ */ new Map();
1787
- e.forEach((r) => {
1788
- const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
1789
- n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
1785
+ function bt(e) {
1786
+ const r = /* @__PURE__ */ new Map();
1787
+ e.forEach((n) => {
1788
+ const t = n.assetId, a = n.option, s = `${t}-${a}-${n.rewardCoinType}-${n.market}`;
1789
+ r.has(s) ? r.get(s).total += n.userClaimableReward : r.set(s, {
1790
1790
  assetId: t,
1791
1791
  rewardType: a,
1792
- coinType: r.rewardCoinType,
1793
- total: Number(r.userClaimableReward),
1794
- market: r.market
1792
+ coinType: n.rewardCoinType,
1793
+ total: Number(n.userClaimableReward),
1794
+ market: n.market
1795
1795
  });
1796
1796
  });
1797
1797
  const o = /* @__PURE__ */ new Map();
1798
- for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
1799
- const c = `${r}-${t}-${i}`;
1800
- o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
1801
- const u = o.get(c);
1802
- u.rewards.set(a, (u.rewards.get(a) || 0) + s);
1798
+ for (const { assetId: n, rewardType: t, coinType: a, total: s, market: i } of r.values()) {
1799
+ const c = `${n}-${t}-${i}`;
1800
+ o.has(c) || o.set(c, { assetId: n, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
1801
+ const l = o.get(c);
1802
+ l.rewards.set(a, (l.rewards.get(a) || 0) + s);
1803
1803
  }
1804
- return Array.from(o.values()).map((r) => ({
1805
- assetId: r.assetId,
1806
- rewardType: r.rewardType,
1807
- market: r.market,
1808
- rewards: Array.from(r.rewards.entries()).map(([t, a]) => ({
1804
+ return Array.from(o.values()).map((n) => ({
1805
+ assetId: n.assetId,
1806
+ rewardType: n.rewardType,
1807
+ market: n.market,
1808
+ rewards: Array.from(n.rewards.entries()).map(([t, a]) => ({
1809
1809
  coinType: t,
1810
1810
  available: a.toFixed(6)
1811
1811
  }))
1812
1812
  }));
1813
1813
  }
1814
- const bt = B(
1815
- async (e, n) => {
1816
- const o = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${S.version}&market=${n?.market || D}`;
1814
+ const kt = B(
1815
+ async (e, r) => {
1816
+ const o = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${V.version}&market=${r?.market || U}`;
1817
1817
  return (await fetch(o, { headers: M }).then((t) => t.json())).data;
1818
1818
  }
1819
- ), kt = B(
1820
- async (e, n) => {
1821
- const o = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${n?.page || 1}&pageSize=${n?.size || 400}&sdk=${S.version}&market=${n?.market || D}`, r = await fetch(o, { headers: M }).then((t) => t.json());
1822
- return W({
1823
- data: r.data.rewards
1819
+ ), _t = B(
1820
+ async (e, r) => {
1821
+ const o = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${r?.page || 1}&pageSize=${r?.size || 400}&sdk=${V.version}&market=${r?.market || U}`, n = await fetch(o, { headers: M }).then((t) => t.json());
1822
+ return H({
1823
+ data: n.data.rewards
1824
1824
  });
1825
1825
  }
1826
1826
  );
1827
- async function _t(e, n, o) {
1828
- const r = await R({
1827
+ async function Ct(e, r, o) {
1828
+ const n = await q({
1829
1829
  ...o,
1830
1830
  markets: Object.values(E),
1831
- cacheTime: b
1831
+ cacheTime: w
1832
1832
  }), t = /* @__PURE__ */ new Map();
1833
- for (const s of n) {
1834
- const { rewardCoinType: i, ruleIds: c, market: u, owner: d, address: y, emodeId: v } = s, g = `${i}___${y}`;
1835
- for (const l of c) {
1833
+ for (const s of r) {
1834
+ const { rewardCoinType: i, ruleIds: c, market: l, owner: d, address: y, emodeId: v } = s, g = `${i}___${y}`;
1835
+ for (const u of c) {
1836
1836
  t.has(g) || t.set(g, {
1837
1837
  assetIds: [],
1838
1838
  ruleIds: [],
1839
1839
  amount: 0,
1840
- market: u,
1840
+ market: l,
1841
1841
  owner: d,
1842
1842
  address: y,
1843
1843
  isEMode: typeof v < "u"
1844
1844
  });
1845
1845
  const f = t.get(g);
1846
- f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(l), f.amount += s.userClaimableReward;
1846
+ f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(u), f.amount += s.userClaimableReward;
1847
1847
  }
1848
1848
  }
1849
1849
  const a = [];
1850
1850
  for (const [
1851
1851
  s,
1852
- { assetIds: i, ruleIds: c, amount: u, market: d, owner: y, address: v, isEMode: g }
1852
+ { assetIds: i, ruleIds: c, amount: l, market: d, owner: y, address: v, isEMode: g }
1853
1853
  ] of t) {
1854
- const l = await _({
1854
+ const u = await _({
1855
1855
  ...o,
1856
- cacheTime: b,
1856
+ cacheTime: w,
1857
1857
  market: d
1858
- }), f = s.split("___")[0], w = r.find((V) => k(V.suiCoinType) === k(f));
1859
- if (!w || !w.contract.rewardFundId)
1858
+ }), f = s.split("___")[0], k = n.filter(($) => b($.suiCoinType) === b(f));
1859
+ k.sort(($, D) => $.market === d ? -1 : 1);
1860
+ const j = k[0];
1861
+ if (!j || !j.contract.rewardFundId)
1860
1862
  throw new Error(`No matching rewardFund found for reward coin: ${f} ${d}`);
1861
- const I = w.contract.rewardFundId;
1863
+ const F = j.contract.rewardFundId;
1862
1864
  if (o?.accountCap && !o.customCoinReceive)
1863
1865
  throw new Error("customCoinReceive is required when accountCap is provided");
1864
1866
  if (o?.customCoinReceive) {
1865
- let V;
1866
- o.accountCap ? V = e.moveCall({
1867
- target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
1867
+ let $;
1868
+ o.accountCap ? $ = e.moveCall({
1869
+ target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
1868
1870
  arguments: [
1869
1871
  e.object("0x06"),
1870
1872
  // Clock object
1871
- e.object(l.incentiveV3),
1873
+ e.object(u.incentiveV3),
1872
1874
  // Incentive V3 contract
1873
- e.object(l.storage),
1875
+ e.object(u.storage),
1874
1876
  // Protocol storage
1875
- e.object(I),
1877
+ e.object(F),
1876
1878
  // Reward fund
1877
1879
  e.pure.vector("string", i),
1878
1880
  // Asset IDs
@@ -1882,16 +1884,16 @@ async function _t(e, n, o) {
1882
1884
  // Account capability
1883
1885
  ],
1884
1886
  typeArguments: [f]
1885
- }) : g ? V = e.moveCall({
1886
- target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
1887
+ }) : g ? $ = e.moveCall({
1888
+ target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
1887
1889
  arguments: [
1888
1890
  e.object("0x06"),
1889
1891
  // Clock object
1890
- e.object(l.incentiveV3),
1892
+ e.object(u.incentiveV3),
1891
1893
  // Incentive V3 contract
1892
- e.object(l.storage),
1894
+ e.object(u.storage),
1893
1895
  // Protocol storage
1894
- e.object(I),
1896
+ e.object(F),
1895
1897
  // Reward fund
1896
1898
  e.pure.vector("string", i),
1897
1899
  // Asset IDs
@@ -1901,16 +1903,16 @@ async function _t(e, n, o) {
1901
1903
  // Account capability
1902
1904
  ],
1903
1905
  typeArguments: [f]
1904
- }) : V = e.moveCall({
1905
- target: `${l.package}::incentive_v3::claim_reward`,
1906
+ }) : $ = e.moveCall({
1907
+ target: `${u.package}::incentive_v3::claim_reward`,
1906
1908
  arguments: [
1907
1909
  e.object("0x06"),
1908
1910
  // Clock object
1909
- e.object(l.incentiveV3),
1911
+ e.object(u.incentiveV3),
1910
1912
  // Incentive V3 contract
1911
- e.object(l.storage),
1913
+ e.object(u.storage),
1912
1914
  // Protocol storage
1913
- e.object(I),
1915
+ e.object(F),
1914
1916
  // Reward fund
1915
1917
  e.pure.vector("string", i),
1916
1918
  // Asset IDs
@@ -1919,43 +1921,46 @@ async function _t(e, n, o) {
1919
1921
  ],
1920
1922
  typeArguments: [f]
1921
1923
  });
1922
- const [U] = e.moveCall({
1924
+ const [D] = e.moveCall({
1923
1925
  target: "0x2::coin::from_balance",
1924
- arguments: [V],
1926
+ arguments: [$],
1925
1927
  typeArguments: [f]
1926
1928
  });
1927
1929
  if (o?.customCoinReceive.type === "transfer") {
1928
1930
  if (!o.customCoinReceive.transfer)
1929
1931
  throw new Error("customCoinReceive.transfer is required");
1930
1932
  e.transferObjects(
1931
- [U],
1933
+ [D],
1932
1934
  h(o.customCoinReceive.transfer, e.pure.address)
1933
1935
  );
1934
1936
  }
1935
1937
  if (o?.customCoinReceive.type === "depositNAVI") {
1936
- const re = p(w.totalSupplyAmount).shiftedBy(-9), ae = p(w.supplyCapCeiling).shiftedBy(-27);
1937
- re.plus(u).isGreaterThan(ae) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1938
- [U],
1938
+ const ae = p(j.totalSupplyAmount).shiftedBy(-9), ie = p(j.supplyCapCeiling).shiftedBy(-27);
1939
+ ae.plus(l).isGreaterThan(ie) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1940
+ [D],
1939
1941
  e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1940
- ) : await _e(e, w, U, o);
1942
+ ) : await Ce(e, j, D, {
1943
+ ...o,
1944
+ market: j.market
1945
+ });
1941
1946
  } else
1942
1947
  a.push({
1943
- coin: U,
1944
- identifier: w,
1948
+ coin: D,
1949
+ identifier: j,
1945
1950
  owner: y,
1946
1951
  isEMode: g
1947
1952
  });
1948
1953
  } else if (o?.accountCap || g) {
1949
- const V = e.moveCall({
1950
- target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
1954
+ const $ = e.moveCall({
1955
+ target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
1951
1956
  arguments: [
1952
1957
  e.object("0x06"),
1953
1958
  // Clock object
1954
- e.object(l.incentiveV3),
1959
+ e.object(u.incentiveV3),
1955
1960
  // Incentive V3 contract
1956
- e.object(l.storage),
1961
+ e.object(u.storage),
1957
1962
  // Protocol storage
1958
- e.object(I),
1963
+ e.object(F),
1959
1964
  // Reward fund
1960
1965
  e.pure.vector("string", i),
1961
1966
  // Asset IDs
@@ -1965,26 +1970,26 @@ async function _t(e, n, o) {
1965
1970
  // Account capability
1966
1971
  ],
1967
1972
  typeArguments: [f]
1968
- }), [U] = e.moveCall({
1973
+ }), [D] = e.moveCall({
1969
1974
  target: "0x2::coin::from_balance",
1970
- arguments: [V],
1975
+ arguments: [$],
1971
1976
  typeArguments: [f]
1972
1977
  });
1973
1978
  e.transferObjects(
1974
- [U],
1979
+ [D],
1975
1980
  h(o?.accountCap || y, e.pure.address)
1976
1981
  );
1977
1982
  } else
1978
1983
  e.moveCall({
1979
- target: `${l.package}::incentive_v3::claim_reward_entry`,
1984
+ target: `${u.package}::incentive_v3::claim_reward_entry`,
1980
1985
  arguments: [
1981
1986
  e.object("0x06"),
1982
1987
  // Clock object
1983
- e.object(l.incentiveV3),
1988
+ e.object(u.incentiveV3),
1984
1989
  // Incentive V3 contract
1985
- e.object(l.storage),
1990
+ e.object(u.storage),
1986
1991
  // Protocol storage
1987
- e.object(I),
1992
+ e.object(F),
1988
1993
  // Reward fund
1989
1994
  e.pure.vector("string", i),
1990
1995
  // Asset IDs
@@ -1997,71 +2002,71 @@ async function _t(e, n, o) {
1997
2002
  return a;
1998
2003
  }
1999
2004
  export {
2000
- z as Address,
2001
- b as DEFAULT_CACHE_TIME,
2002
- D as DEFAULT_MARKET_IDENTITY,
2003
- Ke as FlashLoanAssetConfig,
2004
- He as IncentiveAPYInfo,
2005
- me as IncentivePoolInfo,
2006
- Ge as IncentivePoolInfoByPhase,
2005
+ K as Address,
2006
+ w as DEFAULT_CACHE_TIME,
2007
+ U as DEFAULT_MARKET_IDENTITY,
2008
+ Ye as FlashLoanAssetConfig,
2009
+ Ge as IncentiveAPYInfo,
2010
+ fe as IncentivePoolInfo,
2011
+ ze as IncentivePoolInfoByPhase,
2007
2012
  E as MARKETS,
2008
- Ce as Market,
2009
- ze as OracleInfo,
2010
- F as PoolOperator,
2011
- Ye as ReserveDataInfo,
2013
+ je as Market,
2014
+ Ke as OracleInfo,
2015
+ R as PoolOperator,
2016
+ Je as ReserveDataInfo,
2012
2017
  O as UserPositions,
2013
- fe as UserStateInfo,
2014
- Xe as borrowCoinPTB,
2015
- _t as claimLendingRewardsPTB,
2016
- Ie as createAccountCapPTB,
2018
+ ye as UserStateInfo,
2019
+ xe as borrowCoinPTB,
2020
+ Ct as claimLendingRewardsPTB,
2021
+ Te as createAccountCapPTB,
2017
2022
  nt as createEModeCapPTB,
2018
- _e as depositCoinPTB,
2019
- rt as emodeIdentityId,
2020
- Be as enterEModePTB,
2021
- ot as exitEModePTB,
2022
- Ee as filterPriceFeeds,
2023
- yt as flashloanPTB,
2024
- Te as getAccountCapOwnerPTB,
2025
- G as getAllFlashLoanAssets,
2026
- et as getBorrowFee,
2027
- lt as getCoins,
2023
+ Ce as depositCoinPTB,
2024
+ at as emodeIdentityId,
2025
+ Ae as enterEModePTB,
2026
+ rt as exitEModePTB,
2027
+ De as filterPriceFeeds,
2028
+ gt as flashloanPTB,
2029
+ Be as getAccountCapOwnerPTB,
2030
+ z as getAllFlashLoanAssets,
2031
+ tt as getBorrowFee,
2032
+ pt as getCoins,
2028
2033
  _ as getConfig,
2029
- Ze as getFees,
2030
- ft as getFlashLoanAsset,
2031
- ct as getHealthFactor,
2032
- Ae as getHealthFactorPTB,
2033
- Pe as getLendingPositions,
2034
- it as getLendingState,
2035
- tt as getMarket,
2036
- j as getMarketConfig,
2037
- je as getMarkets,
2034
+ Qe as getFees,
2035
+ yt as getFlashLoanAsset,
2036
+ st as getHealthFactor,
2037
+ Pe as getHealthFactorPTB,
2038
+ $e as getLendingPositions,
2039
+ ct as getLendingState,
2040
+ ot as getMarket,
2041
+ I as getMarketConfig,
2042
+ Ie as getMarkets,
2038
2043
  A as getPool,
2039
- R as getPools,
2044
+ q as getPools,
2040
2045
  ne as getPriceFeeds,
2041
- dt as getPythStalePriceFeedId,
2042
- Se as getPythStalePriceFeedIdV2,
2043
- st as getSimulatedHealthFactor,
2044
- ee as getSimulatedHealthFactorPTB,
2045
- Je as getStats,
2046
+ mt as getPythStalePriceFeedId,
2047
+ Ve as getPythStalePriceFeedIdV2,
2048
+ lt as getSimulatedHealthFactor,
2049
+ te as getSimulatedHealthFactorPTB,
2050
+ Ze as getStats,
2046
2051
  ut as getTransactions,
2047
- vt as getUserAvailableLendingRewards,
2048
- kt as getUserClaimedRewardHistory,
2049
- x as getUserEModeCaps,
2050
- bt as getUserTotalClaimedReward,
2051
- ht as liquidatePTB,
2052
- at as mergeCoinsPTB,
2053
- k as normalizeCoinType,
2054
- ke as parsePoolUID,
2052
+ wt as getUserAvailableLendingRewards,
2053
+ _t as getUserClaimedRewardHistory,
2054
+ ee as getUserEModeCaps,
2055
+ kt as getUserTotalClaimedReward,
2056
+ vt as liquidatePTB,
2057
+ it as mergeCoinsPTB,
2058
+ b as normalizeCoinType,
2059
+ _e as parsePoolUID,
2055
2060
  h as parseTxValue,
2056
- xe as repayCoinPTB,
2057
- gt as repayFlashLoanPTB,
2058
- wt as summaryLendingRewards,
2059
- mt as updateOraclePriceBeforeUserOperationPTB,
2060
- Me as updateOraclePricesPTB,
2061
- Ve as updatePythPriceFeeds,
2062
- pt as verifyHealthFactorPTB,
2061
+ et as repayCoinPTB,
2062
+ ht as repayFlashLoanPTB,
2063
+ bt as summaryLendingRewards,
2064
+ ft as updateOraclePriceBeforeUserOperationPTB,
2065
+ Ee as updateOraclePricesPTB,
2066
+ Me as updatePythPriceFeeds,
2067
+ dt as verifyHealthFactorPTB,
2063
2068
  P as withCache,
2064
2069
  B as withSingleton,
2065
- Qe as withdrawCoinPTB
2070
+ Xe as withdrawCoinPTB
2066
2071
  };
2067
2072
  //# sourceMappingURL=index.esm.js.map