@naviprotocol/lending 1.4.5 → 1.4.7-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Transaction as F } from "@mysten/sui/transactions";
2
- import { bcs as d, toHex as ue, fromHex as pe } from "@mysten/bcs";
2
+ import { bcs as d, toHex as le, fromHex as pe } from "@mysten/bcs";
3
3
  import { SuiClient as de, getFullnodeUrl as me } from "@mysten/sui/client";
4
4
  import fe from "lodash.camelcase";
5
5
  import { normalizeStructTag as ye } from "@mysten/sui/utils";
@@ -9,7 +9,7 @@ import { bcs as C } from "@mysten/sui/bcs";
9
9
  const J = d.bytes(32).transform({
10
10
  // To change the input type, you need to provide a type definition for the input
11
11
  input: (e) => pe(e),
12
- output: (e) => ue(e)
12
+ output: (e) => le(e)
13
13
  }), Je = d.struct("IncentiveAPYInfo", {
14
14
  /** Asset identifier */
15
15
  asset_id: d.u8(),
@@ -129,7 +129,7 @@ const J = d.bytes(32).transform({
129
129
  borrow_balance: d.u256(),
130
130
  /** User's current supply balance */
131
131
  supply_balance: d.u256()
132
- }), be = "1.4.5", E = {
132
+ }), be = "1.4.7-beta.1", E = {
133
133
  version: be
134
134
  }, ke = E.version, _e = () => {
135
135
  if (typeof process < "u" && process.versions && process.versions.node)
@@ -157,7 +157,7 @@ function ee(e) {
157
157
  r.push(o);
158
158
  }), JSON.stringify(r);
159
159
  }
160
- function P(e) {
160
+ function $(e) {
161
161
  const r = {};
162
162
  return (...o) => {
163
163
  const n = ee(o);
@@ -213,7 +213,7 @@ const Ie = 27, Q = (e, r) => {
213
213
  if (!Number(e) || !Number(r)) return new p(0);
214
214
  const o = new p(1).shiftedBy(1 * Ie), n = o.multipliedBy(new p(0.5));
215
215
  return new p(e).multipliedBy(new p(r)).plus(n).dividedBy(o).integerValue(p.ROUND_DOWN);
216
- }, D = Z ? {
216
+ }, U = Z ? {
217
217
  "User-Agent": Z
218
218
  } : {};
219
219
  function z(e, r = "uniqueId") {
@@ -249,32 +249,32 @@ function Te(e) {
249
249
  poolId: parseInt(o)
250
250
  };
251
251
  }
252
- function $() {
252
+ function S() {
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
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
256
  const q = M(
257
- P(
257
+ $(
258
258
  async (e) => {
259
- const r = (e?.markets || [U.main]).map((t) => T(t)), o = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${E.version}&market=${r.map(
259
+ const r = (e?.markets || [D.main]).map((t) => j(t)), o = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${E.version}&market=${r.map(
260
260
  (t) => t.key
261
- )}`, n = await fetch(o, { headers: D }).then((t) => t.json());
261
+ )}`, n = await fetch(o, { headers: U }).then((t) => t.json());
262
262
  return n.data.forEach((t) => {
263
263
  const s = n.meta.emodes.filter((f) => {
264
- const w = T(f.marketId);
264
+ const w = j(f.marketId);
265
265
  return t.market === w.key && f.isActive;
266
266
  }).filter((f) => !!f.assets.find((w) => w.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(), m = p(c).multipliedBy(t.oracle.price).toString(), h = 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(), m = p(c).multipliedBy(t.oracle.price).toString(), h = 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(), y = p(h).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 = m, t.poolSupplyCapAmount = h, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = y, t.poolBorrowCapValue = l;
271
+ ).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), y = p(h).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 = m, t.poolSupplyCapAmount = h, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = y, t.poolBorrowCapValue = u;
273
273
  }), n.data;
274
274
  }
275
275
  )
276
276
  );
277
- async function S(e, r) {
277
+ async function P(e, r) {
278
278
  let o = r?.market;
279
279
  if (typeof e == "string") {
280
280
  const a = Te(e);
@@ -293,15 +293,15 @@ async function S(e, r) {
293
293
  return t.isDeprecated && console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`), t;
294
294
  }
295
295
  const xe = M(
296
- P(async (e) => {
296
+ $(async (e) => {
297
297
  const r = `https://open-api.naviprotocol.io/api/navi/stats?sdk=${E.version}`;
298
- return (await fetch(r, { headers: D }).then((n) => n.json())).data;
298
+ return (await fetch(r, { headers: U }).then((n) => n.json())).data;
299
299
  })
300
300
  ), et = M(
301
- P(
301
+ $(
302
302
  async (e) => {
303
303
  const r = `https://open-api.naviprotocol.io/api/navi/fee?sdk=${E.version}`;
304
- return await fetch(r, { headers: D }).then((n) => n.json());
304
+ return await fetch(r, { headers: U }).then((n) => n.json());
305
305
  }
306
306
  )
307
307
  );
@@ -309,19 +309,17 @@ async function Be(e, r, o, n) {
309
309
  const t = await _({
310
310
  ...n,
311
311
  cacheTime: b
312
- }), a = await S(r, n);
313
- n?.market;
314
- const s = n?.env || "prod";
312
+ }), a = await P(r, n), s = j(n?.market || O), i = n?.env || "prod";
315
313
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
316
314
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
317
- const i = typeof o == "object" && o.$kind === "GasCoin";
318
- if (k(a.suiCoinType) === k("0x2::sui::SUI") && i) {
315
+ const c = typeof o == "object" && o.$kind === "GasCoin";
316
+ if (k(a.suiCoinType) === k("0x2::sui::SUI") && c) {
319
317
  if (!n?.amount)
320
318
  throw new Error("Amount is required for sui coin");
321
319
  o = e.splitCoins(o, [n.amount]);
322
320
  }
323
- let c;
324
- return typeof n?.amount < "u" ? c = g(n.amount, e.pure.u64) : c = e.moveCall({
321
+ let l;
322
+ return typeof n?.amount < "u" ? l = g(n.amount, e.pure.u64) : l = e.moveCall({
325
323
  target: "0x2::coin::value",
326
324
  arguments: [g(o, e.object)],
327
325
  typeArguments: [a.suiCoinType]
@@ -346,12 +344,12 @@ async function Be(e, r, o, n) {
346
344
  e.object(a.contract.pool),
347
345
  e.pure.u8(a.id),
348
346
  g(o, e.object),
349
- c,
347
+ l,
350
348
  e.object(t.incentiveV2),
351
349
  e.object(t.incentiveV3)
352
350
  ],
353
351
  typeArguments: [a.suiCoinType]
354
- }), t.version === 2 && a.token.symbol === "SUI" && s === "prod" && e.moveCall({
352
+ }), t.version === 2 && a.token.symbol === "SUI" && i === "prod" && s.key === "main" && e.moveCall({
355
353
  target: `${t.package}::pool::refresh_stake`,
356
354
  arguments: [e.object(a.contract.pool), e.object("0x05")]
357
355
  }), e;
@@ -360,11 +358,11 @@ async function tt(e, r, o, n) {
360
358
  const t = await _({
361
359
  ...n,
362
360
  cacheTime: b
363
- }), a = await S(r, n), s = g(o, e.pure.u64);
361
+ }), a = await P(r, n), s = g(o, e.pure.u64);
364
362
  let i;
365
363
  if (t.version === 1)
366
364
  if (n?.accountCap) {
367
- const [u] = e.moveCall({
365
+ const [l] = e.moveCall({
368
366
  target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
369
367
  arguments: [
370
368
  e.object("0x06"),
@@ -379,9 +377,9 @@ async function tt(e, r, o, n) {
379
377
  ],
380
378
  typeArguments: [a.suiCoinType]
381
379
  });
382
- i = u;
380
+ i = l;
383
381
  } else {
384
- const [u] = e.moveCall({
382
+ const [l] = e.moveCall({
385
383
  target: `${t.package}::incentive_v3::withdraw`,
386
384
  arguments: [
387
385
  e.object("0x06"),
@@ -395,10 +393,10 @@ async function tt(e, r, o, n) {
395
393
  ],
396
394
  typeArguments: [a.suiCoinType]
397
395
  });
398
- i = u;
396
+ i = l;
399
397
  }
400
398
  else if (n?.accountCap) {
401
- const [u] = e.moveCall({
399
+ const [l] = e.moveCall({
402
400
  target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
403
401
  arguments: [
404
402
  e.object("0x06"),
@@ -414,9 +412,9 @@ async function tt(e, r, o, n) {
414
412
  ],
415
413
  typeArguments: [a.suiCoinType]
416
414
  });
417
- i = u;
415
+ i = l;
418
416
  } else {
419
- const [u] = e.moveCall({
417
+ const [l] = e.moveCall({
420
418
  target: `${t.package}::incentive_v3::withdraw_v2`,
421
419
  arguments: [
422
420
  e.object("0x06"),
@@ -431,7 +429,7 @@ async function tt(e, r, o, n) {
431
429
  ],
432
430
  typeArguments: [a.suiCoinType]
433
431
  });
434
- i = u;
432
+ i = l;
435
433
  }
436
434
  return e.moveCall({
437
435
  target: "0x2::coin::from_balance",
@@ -443,14 +441,14 @@ async function ot(e, r, o, n) {
443
441
  const t = await _({
444
442
  ...n,
445
443
  cacheTime: b
446
- }), a = await S(r, n);
444
+ }), a = await P(r, n);
447
445
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
448
446
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
449
447
  const s = g(o, e.pure.u64);
450
448
  let i;
451
449
  if (t.version === 1)
452
450
  if (n?.accountCap) {
453
- const [u] = e.moveCall({
451
+ const [l] = e.moveCall({
454
452
  target: `${t.package}::incentive_v3::borrow_with_account_cap`,
455
453
  arguments: [
456
454
  e.object("0x06"),
@@ -465,9 +463,9 @@ async function ot(e, r, o, n) {
465
463
  ],
466
464
  typeArguments: [a.suiCoinType]
467
465
  });
468
- i = u;
466
+ i = l;
469
467
  } else {
470
- const [u] = e.moveCall({
468
+ const [l] = e.moveCall({
471
469
  target: `${t.package}::incentive_v3::borrow`,
472
470
  arguments: [
473
471
  e.object("0x06"),
@@ -481,10 +479,10 @@ async function ot(e, r, o, n) {
481
479
  ],
482
480
  typeArguments: [a.suiCoinType]
483
481
  });
484
- i = u;
482
+ i = l;
485
483
  }
486
484
  else if (n?.accountCap) {
487
- const [u] = e.moveCall({
485
+ const [l] = e.moveCall({
488
486
  target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
489
487
  arguments: [
490
488
  e.object("0x06"),
@@ -500,9 +498,9 @@ async function ot(e, r, o, n) {
500
498
  ],
501
499
  typeArguments: [a.suiCoinType]
502
500
  });
503
- i = u;
501
+ i = l;
504
502
  } else {
505
- const [u] = e.moveCall({
503
+ const [l] = e.moveCall({
506
504
  target: `${t.package}::incentive_v3::borrow_v2`,
507
505
  arguments: [
508
506
  e.object("0x06"),
@@ -517,7 +515,7 @@ async function ot(e, r, o, n) {
517
515
  ],
518
516
  typeArguments: [a.suiCoinType]
519
517
  });
520
- i = u;
518
+ i = l;
521
519
  }
522
520
  return e.moveCall({
523
521
  target: "0x2::coin::from_balance",
@@ -529,7 +527,7 @@ async function rt(e, r, o, n) {
529
527
  const t = await _({
530
528
  ...n,
531
529
  cacheTime: b
532
- }), a = await S(r, n), s = typeof o == "object" && o.$kind === "GasCoin";
530
+ }), a = await P(r, n), s = typeof o == "object" && o.$kind === "GasCoin";
533
531
  if (k(a.suiCoinType) === k("0x2::sui::SUI") && s) {
534
532
  if (!n?.amount)
535
533
  throw new Error("Amount is required for sui coin");
@@ -579,14 +577,14 @@ async function rt(e, r, o, n) {
579
577
  }), e;
580
578
  }
581
579
  const nt = M(
582
- P(
580
+ $(
583
581
  async (e) => {
584
582
  const r = await _({
585
583
  ...e
586
584
  });
587
585
  if (e?.address && typeof e?.asset < "u")
588
586
  try {
589
- const t = await S(e.asset, e), a = e?.client ?? V, s = new F();
587
+ const t = await P(e.asset, e), a = e?.client ?? V, s = new F();
590
588
  s.moveCall({
591
589
  target: `${r.package}::incentive_v3::get_borrow_fee_v2`,
592
590
  arguments: [
@@ -612,7 +610,7 @@ const nt = M(
612
610
  return Number(n) / 100;
613
611
  }
614
612
  )
615
- ), O = "main", U = {
613
+ ), O = "main", D = {
616
614
  main: {
617
615
  id: 0,
618
616
  key: "main",
@@ -632,6 +630,36 @@ const nt = M(
632
630
  id: 3,
633
631
  key: "sui-eco",
634
632
  name: "Sui Eco Market"
633
+ },
634
+ "vsui-usdc": {
635
+ id: 4,
636
+ key: "vsui-usdc",
637
+ name: "vSUI/USDC Market"
638
+ },
639
+ "sui-usdc": {
640
+ id: 5,
641
+ key: "sui-usdc",
642
+ name: "SUI/USDC Market"
643
+ },
644
+ "hasui-sui": {
645
+ id: 6,
646
+ key: "hasui-sui",
647
+ name: "haSUI/SUI Market"
648
+ },
649
+ "wbtc-usdc": {
650
+ id: 7,
651
+ key: "wbtc-usdc",
652
+ name: "WBTC/USDC Market"
653
+ },
654
+ "vsui-sui": {
655
+ id: 8,
656
+ key: "vsui-sui",
657
+ name: "vSUI/SUI Market"
658
+ },
659
+ "xbtc-usdc": {
660
+ id: 9,
661
+ key: "xbtc-usdc",
662
+ name: "xBTC/USDC Market"
635
663
  }
636
664
  };
637
665
  class Ae {
@@ -639,7 +667,7 @@ class Ae {
639
667
  this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
640
668
  marketTotalSupplyValue: "0",
641
669
  marketTotalBorrowValue: "0"
642
- }, this.config = T(r), this.initPools(o);
670
+ }, this.config = j(r), this.initPools(o);
643
671
  }
644
672
  get overview() {
645
673
  return this._overview;
@@ -660,8 +688,8 @@ class Ae {
660
688
  });
661
689
  }), i = i.plus(c.poolBorrowValue), s = s.plus(c.poolSupplyValue);
662
690
  }), this.poolMap = z(this.pools, "id"), this.emodeMap = X(this.emodes, "emodeId"), this.emodes.forEach((c) => {
663
- const u = this.getEModePools(c.emodeId);
664
- this.emodePools.push(...u);
691
+ const l = this.getEModePools(c.emodeId);
692
+ this.emodePools.push(...l);
665
693
  }), this._overview = {
666
694
  marketTotalSupplyValue: s.toString(),
667
695
  marketTotalBorrowValue: i.toString()
@@ -697,13 +725,13 @@ class Ae {
697
725
  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;
698
726
  }
699
727
  }
700
- const T = (e) => {
701
- const o = Object.values(U).find((n) => typeof e == "number" ? n.id === e : typeof e == "string" ? n.key === e : n.id === e.id);
728
+ const j = (e) => {
729
+ const o = Object.values(D).find((n) => typeof e == "number" ? n.id === e : typeof e == "string" ? n.key === e : n.id === e.id);
702
730
  if (!o)
703
731
  throw new Error("Market not found");
704
732
  return o;
705
- }, $e = M(
706
- P(
733
+ }, Se = M(
734
+ $(
707
735
  async (e, r) => {
708
736
  const o = await q({
709
737
  cacheTime: 6e4,
@@ -711,24 +739,24 @@ const T = (e) => {
711
739
  markets: e
712
740
  });
713
741
  return e.map((n) => {
714
- const t = T(n), a = o.filter((s) => s.market === t.key);
742
+ const t = j(n), a = o.filter((s) => s.market === t.key);
715
743
  return new Ae(n, a);
716
744
  });
717
745
  }
718
746
  )
719
747
  ), at = M(
720
- P(
721
- async (e, r) => (await $e([e], r))[0]
748
+ $(
749
+ async (e, r) => (await Se([e], r))[0]
722
750
  )
723
751
  ), _ = M(
724
- P(
752
+ $(
725
753
  async (e) => {
726
- const r = T(e?.market || O), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${E.version}&market=${r.key}`;
727
- return (await fetch(o, { headers: D }).then((t) => t.json())).data;
754
+ const r = j(e?.market || O), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${E.version}&market=${r.key}`;
755
+ return (await fetch(o, { headers: U }).then((t) => t.json())).data;
728
756
  }
729
757
  )
730
758
  ), b = 1e3 * 60 * 5;
731
- async function Pe(e, r) {
759
+ async function $e(e, r) {
732
760
  const o = await _({
733
761
  cacheTime: b,
734
762
  ...r
@@ -738,7 +766,7 @@ async function Pe(e, r) {
738
766
  arguments: []
739
767
  });
740
768
  }
741
- async function Se(e, r, o) {
769
+ async function Pe(e, r, o) {
742
770
  const n = await _({
743
771
  cacheTime: b,
744
772
  ...o
@@ -782,12 +810,12 @@ async function ct(e, r, o) {
782
810
  const n = await _({
783
811
  cacheTime: b,
784
812
  ...o
785
- }), t = await Pe(e, o);
813
+ }), t = await $e(e, o);
786
814
  await Me(e, r, {
787
815
  ...o,
788
816
  accountCap: t
789
817
  });
790
- const a = await T(o?.market || O), s = await Se(e, t, o);
818
+ const a = await j(o?.market || O), s = await Pe(e, t, o);
791
819
  return e.moveCall({
792
820
  target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
793
821
  arguments: [
@@ -799,7 +827,7 @@ async function ct(e, r, o) {
799
827
  }), t;
800
828
  }
801
829
  const oe = M(
802
- P(
830
+ $(
803
831
  async (e, r) => {
804
832
  const o = await _({
805
833
  cacheTime: b,
@@ -812,24 +840,24 @@ const oe = M(
812
840
  const s = (await t.devInspectTransactionBlock({
813
841
  transactionBlock: n,
814
842
  sender: e
815
- })).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]));
843
+ })).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]));
816
844
  return i.map((m, h) => ({
817
845
  marketId: Number(m),
818
846
  emodeId: Number(c[h]),
819
- accountCap: u[h].toString()
847
+ accountCap: l[h].toString()
820
848
  }));
821
849
  }
822
850
  )
823
851
  );
824
852
  function st(e) {
825
- return `${T(e.marketId).key}-${e.emodeId}`;
853
+ return `${j(e.marketId).key}-${e.emodeId}`;
826
854
  }
827
- function lt(e, r, o) {
855
+ function ut(e, r, o) {
828
856
  const n = typeof o?.balance == "number", t = n ? o.balance : 0;
829
857
  let a = 0;
830
858
  const s = [];
831
859
  let i = "";
832
- if (r.sort((c, u) => Number(u.balance) - Number(c.balance)).forEach((c) => {
860
+ if (r.sort((c, l) => Number(l.balance) - Number(c.balance)).forEach((c) => {
833
861
  if (!(n && a >= t) && Number(c.balance) !== 0) {
834
862
  if (i || (i = c.coinType), i !== c.coinType)
835
863
  throw new Error("All coins must be of the same type");
@@ -847,7 +875,7 @@ async function re(e, r, o, n, t, a, s) {
847
875
  const i = await _({
848
876
  ...s,
849
877
  cacheTime: b
850
- }), c = await S(o, s);
878
+ }), c = await P(o, s);
851
879
  return e.moveCall({
852
880
  target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
853
881
  arguments: [
@@ -870,74 +898,74 @@ async function Ve(e, r, o) {
870
898
  async function ne(e, r, o) {
871
899
  const n = new F(), t = o?.client ?? V, a = await q({
872
900
  ...o,
873
- markets: Object.values(U)
874
- }), s = z(a), c = Array.from(new Set(r.map((l) => l.market))).map((l) => T(l));
875
- for (const l of c) {
901
+ markets: Object.values(D)
902
+ }), s = z(a), c = Array.from(new Set(r.map((u) => u.market))).map((u) => j(u));
903
+ for (const u of c) {
876
904
  const f = await _({
877
905
  ...o,
878
906
  cacheTime: b,
879
- market: l.key
907
+ market: u.key
880
908
  });
881
909
  n.moveCall({
882
910
  target: `${f.uiGetter}::getter::get_reserve_data`,
883
911
  arguments: [n.object(f.storage)]
884
912
  });
885
913
  }
886
- for (let l of r) {
914
+ for (let u of r) {
887
915
  const f = await _({
888
916
  ...o,
889
917
  cacheTime: b,
890
- market: l.market
918
+ market: u.market
891
919
  });
892
920
  n.moveCall({
893
921
  target: `${f.uiGetter}::getter_unchecked::get_user_state`,
894
- arguments: [n.object(f.storage), n.pure.address(l.address)]
922
+ arguments: [n.object(f.storage), n.pure.address(u.address)]
895
923
  });
896
924
  }
897
925
  const m = (await t.devInspectTransactionBlock({
898
926
  transactionBlock: n,
899
927
  sender: e
900
928
  })).results || [], h = {};
901
- c.forEach((l, f) => {
929
+ c.forEach((u, f) => {
902
930
  try {
903
- const w = m[f]?.returnValues?.map((B) => C.vector(ve).parse(Uint8Array.from(B[0])))[0] || [], I = {};
931
+ const w = m[f]?.returnValues?.map((B) => C.vector(ve).parse(Uint8Array.from(B[0])))[0] || [], T = {};
904
932
  for (const B of w)
905
- I[B.id] = {
933
+ T[B.id] = {
906
934
  supplyIndex: B.supply_index,
907
935
  borrowIndex: B.borrow_index
908
936
  };
909
- h[l.key] = I;
937
+ h[u.key] = T;
910
938
  } catch (w) {
911
939
  console.warn(
912
- `[@naviprotocol/lending] Failed to decode reserve data for market "${l.key}", falling back to open-api pool indices`,
940
+ `[@naviprotocol/lending] Failed to decode reserve data for market "${u.key}", falling back to open-api pool indices`,
913
941
  w
914
942
  );
915
943
  }
916
944
  });
917
- const v = m.slice(c.length).map((l) => l.returnValues?.map((f) => C.vector(we).parse(Uint8Array.from(f[0])))[0] || []), y = [];
918
- return v.forEach((l, f) => {
919
- const w = r[f], I = T(w.market), B = h[I.key] || {};
920
- l.forEach((j) => {
921
- if (j.supply_balance === "0" && j.borrow_balance === "0" && (w.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
945
+ const v = m.slice(c.length).map((u) => u.returnValues?.map((f) => C.vector(we).parse(Uint8Array.from(f[0])))[0] || []), y = [];
946
+ return v.forEach((u, f) => {
947
+ const w = r[f], T = j(w.market), B = h[T.key] || {};
948
+ u.forEach((I) => {
949
+ if (I.supply_balance === "0" && I.borrow_balance === "0" && (w.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
922
950
  return;
923
- const A = s[`${I.key}-${j.asset_id}`];
951
+ const A = s[`${T.key}-${I.asset_id}`];
924
952
  if (!A)
925
953
  return;
926
- const L = B[j.asset_id], G = L?.supplyIndex ?? A.currentSupplyIndex, ce = L?.borrowIndex ?? A.currentBorrowIndex, se = Q(j.supply_balance, G).toString(), le = Q(j.borrow_balance, ce).toString();
954
+ const L = B[I.asset_id], G = L?.supplyIndex ?? A.currentSupplyIndex, ce = L?.borrowIndex ?? A.currentBorrowIndex, se = Q(I.supply_balance, G).toString(), ue = Q(I.borrow_balance, ce).toString();
927
955
  y.push({
928
956
  supplyBalance: se,
929
- borrowBalance: le,
930
- assetId: j.asset_id,
931
- market: I.key,
957
+ borrowBalance: ue,
958
+ assetId: I.asset_id,
959
+ market: T.key,
932
960
  pool: A,
933
961
  emodeId: w.emodeId
934
962
  });
935
963
  });
936
964
  }), y;
937
965
  }
938
- const ut = M(
966
+ const lt = M(
939
967
  async (e, r) => {
940
- const n = (r?.markets || Object.keys(U)).map((t) => T(t)).map((t) => ({
968
+ const n = (r?.markets || Object.keys(D)).map((t) => j(t)).map((t) => ({
941
969
  address: e,
942
970
  market: t.key
943
971
  }));
@@ -956,19 +984,19 @@ async function pt(e, r) {
956
984
  async function dt(e, r, o, n) {
957
985
  const t = n?.client ?? V, a = new F();
958
986
  let s = 0, i = 0;
959
- const c = await S(r, n);
987
+ const c = await P(r, n);
960
988
  if (o.forEach((v) => {
961
989
  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);
962
990
  }), s * i < 0)
963
991
  throw new Error("Invalid operations");
964
- const u = s > 0 || i > 0;
992
+ const l = s > 0 || i > 0;
965
993
  await re(
966
994
  a,
967
995
  e,
968
996
  c,
969
997
  Math.abs(s),
970
998
  Math.abs(i),
971
- u,
999
+ l,
972
1000
  n
973
1001
  );
974
1002
  const m = await t.devInspectTransactionBlock({
@@ -977,12 +1005,12 @@ async function dt(e, r, o, n) {
977
1005
  }), h = H(m, [C.u256()]);
978
1006
  return te(Number(h[0]) || 0);
979
1007
  }
980
- const mt = P(
1008
+ const mt = $(
981
1009
  async (e, r) => {
982
1010
  const o = new URLSearchParams();
983
1011
  r?.cursor && o.set("cursor", r.cursor), o.set("userAddress", e);
984
1012
  const n = `https://open-api.naviprotocol.io/api/navi/user/transactions?${o.toString()}&sdk=${E.version}`;
985
- return (await fetch(n, { headers: D }).then((a) => a.json())).data;
1013
+ return (await fetch(n, { headers: U }).then((a) => a.json())).data;
986
1014
  }
987
1015
  );
988
1016
  async function ft(e, r) {
@@ -1007,7 +1035,7 @@ async function ft(e, r) {
1007
1035
  }
1008
1036
  const Ee = M(
1009
1037
  async (e, r) => {
1010
- const o = [], n = (r?.markets || Object.keys(U)).map((i) => T(i));
1038
+ const o = [], n = (r?.markets || Object.keys(D)).map((i) => j(i));
1011
1039
  let t = [];
1012
1040
  try {
1013
1041
  t = await oe(e, r);
@@ -1020,14 +1048,14 @@ const Ee = M(
1020
1048
  })).concat(
1021
1049
  t.filter((i) => !!n.find((c) => c.id === i.marketId)).map((i) => ({
1022
1050
  address: i.accountCap,
1023
- market: T(i.marketId).key,
1051
+ market: j(i.marketId).key,
1024
1052
  emodeId: i.emodeId
1025
1053
  }))
1026
1054
  );
1027
1055
  return (await ne(e, a, r)).forEach((i) => {
1028
- const c = typeof i.emodeId == "number" ? t.find((u) => {
1029
- const m = T(i.market);
1030
- return u.emodeId === i.emodeId && u.marketId === m.id;
1056
+ const c = typeof i.emodeId == "number" ? t.find((l) => {
1057
+ const m = j(i.market);
1058
+ return l.emodeId === i.emodeId && l.marketId === m.id;
1031
1059
  }) : void 0;
1032
1060
  if (c) {
1033
1061
  if (!i.pool.emodes.find((m) => m.emodeId === c.emodeId))
@@ -1037,7 +1065,7 @@ const Ee = M(
1037
1065
  if (m.gt(0) || h.emode.isCollateral)
1038
1066
  try {
1039
1067
  o.push({
1040
- id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-supply-${$()}`,
1068
+ id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-supply-${S()}`,
1041
1069
  wallet: e,
1042
1070
  protocol: "navi",
1043
1071
  market: i.market,
@@ -1059,7 +1087,7 @@ const Ee = M(
1059
1087
  if (m.gt(0) || h.emode.isDebt)
1060
1088
  try {
1061
1089
  o.push({
1062
- id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-borrow-${$()}`,
1090
+ id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-borrow-${S()}`,
1063
1091
  wallet: e,
1064
1092
  protocol: "navi",
1065
1093
  market: i.market,
@@ -1078,34 +1106,34 @@ const Ee = M(
1078
1106
  }
1079
1107
  } else {
1080
1108
  if (p(i.supplyBalance).gt(0)) {
1081
- const u = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1109
+ const l = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1082
1110
  o.push({
1083
- id: `${i.pool.uniqueId}_navi-lending-supply-${$()}`,
1111
+ id: `${i.pool.uniqueId}_navi-lending-supply-${S()}`,
1084
1112
  wallet: e,
1085
1113
  protocol: "navi",
1086
1114
  type: "navi-lending-supply",
1087
1115
  market: i.market,
1088
1116
  "navi-lending-supply": {
1089
- amount: u.toString(),
1117
+ amount: l.toString(),
1090
1118
  pool: i.pool,
1091
1119
  token: i.pool.token,
1092
- valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
1120
+ valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
1093
1121
  }
1094
1122
  });
1095
1123
  }
1096
1124
  if (p(i.borrowBalance).gt(0)) {
1097
- const u = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1125
+ const l = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
1098
1126
  o.push({
1099
- id: `${i.pool.uniqueId}_navi-lending-borrow-${$()}`,
1127
+ id: `${i.pool.uniqueId}_navi-lending-borrow-${S()}`,
1100
1128
  wallet: e,
1101
1129
  protocol: "navi",
1102
1130
  market: i.market,
1103
1131
  type: "navi-lending-borrow",
1104
1132
  "navi-lending-borrow": {
1105
- amount: u.toString(),
1133
+ amount: l.toString(),
1106
1134
  pool: i.pool,
1107
1135
  token: i.pool.token,
1108
- valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
1136
+ valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
1109
1137
  }
1110
1138
  });
1111
1139
  }
@@ -1165,7 +1193,7 @@ class N {
1165
1193
  const n = !!r.isEMode, t = this.getPrice(r);
1166
1194
  let a;
1167
1195
  return n ? a = {
1168
- id: $(),
1196
+ id: S(),
1169
1197
  wallet: "",
1170
1198
  protocol: "navi",
1171
1199
  market: "",
@@ -1178,7 +1206,7 @@ class N {
1178
1206
  emodeCap: {}
1179
1207
  }
1180
1208
  } : a = {
1181
- id: $(),
1209
+ id: S(),
1182
1210
  wallet: "",
1183
1211
  protocol: "navi",
1184
1212
  market: "",
@@ -1195,7 +1223,7 @@ class N {
1195
1223
  const n = !!r.isEMode, t = this.getPrice(r);
1196
1224
  let a;
1197
1225
  return n ? a = {
1198
- id: $(),
1226
+ id: S(),
1199
1227
  wallet: "",
1200
1228
  protocol: "navi",
1201
1229
  market: "",
@@ -1208,7 +1236,7 @@ class N {
1208
1236
  emodeCap: {}
1209
1237
  }
1210
1238
  } : a = {
1211
- id: $(),
1239
+ id: S(),
1212
1240
  wallet: "",
1213
1241
  protocol: "navi",
1214
1242
  market: "",
@@ -1225,7 +1253,7 @@ class N {
1225
1253
  const n = !!r.isEMode, t = this.getPrice(r);
1226
1254
  let a;
1227
1255
  return n ? a = {
1228
- id: $(),
1256
+ id: S(),
1229
1257
  wallet: "",
1230
1258
  protocol: "navi",
1231
1259
  market: "",
@@ -1238,7 +1266,7 @@ class N {
1238
1266
  emodeCap: {}
1239
1267
  }
1240
1268
  } : a = {
1241
- id: $(),
1269
+ id: S(),
1242
1270
  wallet: "",
1243
1271
  protocol: "navi",
1244
1272
  market: "",
@@ -1255,7 +1283,7 @@ class N {
1255
1283
  const n = !!r.isEMode, t = this.getPrice(r);
1256
1284
  let a;
1257
1285
  return n ? a = {
1258
- id: $(),
1286
+ id: S(),
1259
1287
  wallet: "",
1260
1288
  protocol: "navi",
1261
1289
  market: "",
@@ -1268,7 +1296,7 @@ class N {
1268
1296
  emodeCap: {}
1269
1297
  }
1270
1298
  } : a = {
1271
- id: $(),
1299
+ id: S(),
1272
1300
  wallet: "",
1273
1301
  protocol: "navi",
1274
1302
  market: "",
@@ -1286,52 +1314,52 @@ class N {
1286
1314
  }
1287
1315
  getPositionsOverview(r) {
1288
1316
  const o = {}, n = {};
1289
- 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);
1317
+ 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);
1290
1318
  r.forEach((y) => {
1291
1319
  if (y.type === "navi-lending-supply") {
1292
- const l = y["navi-lending-supply"], f = this.resolveValueUSD(l);
1320
+ const u = y["navi-lending-supply"], f = this.resolveValueUSD(u);
1293
1321
  t = t.plus(f), c = c.plus(
1294
- new p(f).multipliedBy(l.pool.liquidationFactor.threshold)
1295
- ), u = u.plus(
1296
- new p(f).multipliedBy(l.pool.ltvValue)
1322
+ new p(f).multipliedBy(u.pool.liquidationFactor.threshold)
1323
+ ), l = l.plus(
1324
+ new p(f).multipliedBy(u.pool.ltvValue)
1297
1325
  );
1298
1326
  } else if (y.type === "navi-lending-borrow") {
1299
- const l = y["navi-lending-borrow"];
1300
- a = a.plus(this.resolveValueUSD(l));
1327
+ const u = y["navi-lending-borrow"];
1328
+ a = a.plus(this.resolveValueUSD(u));
1301
1329
  } else if (y.type === "navi-lending-emode-supply") {
1302
- const l = y["navi-lending-emode-supply"], f = this.resolveValueUSD(l);
1330
+ const u = y["navi-lending-emode-supply"], f = this.resolveValueUSD(u);
1303
1331
  t = t.plus(f);
1304
- const w = l.pool.emode;
1332
+ const w = u.pool.emode;
1305
1333
  c = c.plus(
1306
1334
  new p(f).multipliedBy(w.lt)
1307
- ), u = u.plus(
1335
+ ), l = l.plus(
1308
1336
  new p(f).multipliedBy(w.ltv)
1309
1337
  );
1310
1338
  } else if (y.type === "navi-lending-emode-borrow") {
1311
- const l = y["navi-lending-emode-borrow"];
1312
- a = a.plus(this.resolveValueUSD(l));
1339
+ const u = y["navi-lending-emode-borrow"];
1340
+ a = a.plus(this.resolveValueUSD(u));
1313
1341
  }
1314
- }), a = p.max(a, 0), t = p.max(t, 0), c = p.max(c, 0), u = p.max(u, 0), r.forEach((y) => {
1342
+ }), a = p.max(a, 0), t = p.max(t, 0), c = p.max(c, 0), l = p.max(l, 0), r.forEach((y) => {
1315
1343
  if (y.type === "navi-lending-supply") {
1316
- const l = y["navi-lending-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
1344
+ const u = y["navi-lending-supply"], f = this.resolveValueUSD(u), w = u.pool.supplyIncentiveApyInfo.apy;
1317
1345
  t.gt(0) && (s = s.plus(
1318
1346
  new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
1319
- )), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1347
+ )), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1320
1348
  } else if (y.type === "navi-lending-borrow") {
1321
- const l = y["navi-lending-borrow"], f = this.resolveValueUSD(l), w = l.pool.borrowIncentiveApyInfo.apy;
1349
+ const u = y["navi-lending-borrow"], f = this.resolveValueUSD(u), w = u.pool.borrowIncentiveApyInfo.apy;
1322
1350
  a.gt(0) && (i = i.plus(
1323
1351
  new p(f).dividedBy(a).multipliedBy(new p(w).dividedBy(100))
1324
- )), n[l.pool.suiCoinType] = p(n[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1352
+ )), n[u.pool.suiCoinType] = p(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1325
1353
  } else if (y.type === "navi-lending-emode-supply") {
1326
- const l = y["navi-lending-emode-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
1354
+ const u = y["navi-lending-emode-supply"], f = this.resolveValueUSD(u), w = u.pool.supplyIncentiveApyInfo.apy;
1327
1355
  t.gt(0) && (s = s.plus(
1328
1356
  new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
1329
- )), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1357
+ )), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1330
1358
  } else if (y.type === "navi-lending-emode-borrow") {
1331
- const l = y["navi-lending-emode-borrow"], f = this.resolveValueUSD(l), w = l.pool.borrowIncentiveApyInfo.apy;
1359
+ const u = y["navi-lending-emode-borrow"], f = this.resolveValueUSD(u), w = u.pool.borrowIncentiveApyInfo.apy;
1332
1360
  a.gt(0) && (i = i.plus(
1333
1361
  new p(f).dividedBy(a).multipliedBy(new p(w).dividedBy(100))
1334
- )), n[l.pool.suiCoinType] = p(n[l.pool.suiCoinType] || 0).plus(l.amount).toString();
1362
+ )), n[u.pool.suiCoinType] = p(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
1335
1363
  }
1336
1364
  });
1337
1365
  const m = t.minus(a), h = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(s).minus(a.multipliedBy(i)).div(t.minus(a));
@@ -1344,7 +1372,7 @@ class N {
1344
1372
  totalsupplyApy: s.toString(),
1345
1373
  totalBorrowApy: i.toString(),
1346
1374
  maxLiquidationValue: c.toString(),
1347
- maxLoanToVaule: u.toString(),
1375
+ maxLoanToVaule: l.toString(),
1348
1376
  supply: o,
1349
1377
  borrow: n
1350
1378
  };
@@ -1391,7 +1419,7 @@ async function gt(e) {
1391
1419
  throw new Error(`failed to get pyth stale price feed id, msg: ${r.message}`);
1392
1420
  }
1393
1421
  }
1394
- async function De(e, r) {
1422
+ async function Ue(e, r) {
1395
1423
  try {
1396
1424
  const o = [], n = r?.client ?? V, t = e.map((s) => s.priceInfoObject), a = await n.multiGetObjects({
1397
1425
  ids: Array.from(new Set(t)),
@@ -1403,12 +1431,12 @@ async function De(e, r) {
1403
1431
  console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
1404
1432
  continue;
1405
1433
  }
1406
- const c = e.find((l) => l.priceInfoObject == i.objectId);
1434
+ const c = e.find((u) => u.priceInfoObject == i.objectId);
1407
1435
  if (!c) {
1408
1436
  console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
1409
1437
  continue;
1410
1438
  }
1411
- const u = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: m, negative: h } = u.price.fields, v = u.conf, y = u.timestamp;
1439
+ const l = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: m, negative: h } = l.price.fields, v = l.conf, y = l.timestamp;
1412
1440
  o.push({
1413
1441
  priceFeedId: c.priceFeedId,
1414
1442
  priceInfoObject: c.priceInfoObject,
@@ -1424,9 +1452,9 @@ async function De(e, r) {
1424
1452
  return;
1425
1453
  }
1426
1454
  }
1427
- async function Ue(e, r) {
1455
+ async function De(e, r) {
1428
1456
  try {
1429
- const o = [], n = await De(e, r);
1457
+ const o = [], n = await Ue(e, r);
1430
1458
  if (!n) return o;
1431
1459
  const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1432
1460
  for (const a of n) {
@@ -1474,7 +1502,7 @@ async function Ne(e, r, o) {
1474
1502
  expiration: 30
1475
1503
  }));
1476
1504
  try {
1477
- const a = await Ue(t, o);
1505
+ const a = await De(t, o);
1478
1506
  a.length > 0 && await Oe(e, a, o);
1479
1507
  } catch {
1480
1508
  console.error("Failed to update Pyth price feeds");
@@ -1541,8 +1569,8 @@ async function ht(e, r, o, n) {
1541
1569
  const t = await ie({
1542
1570
  ...n
1543
1571
  }), a = [];
1544
- o.forEach((u) => {
1545
- a.includes(u.market) || a.push(u.market);
1572
+ o.forEach((l) => {
1573
+ a.includes(l.market) || a.push(l.market);
1546
1574
  });
1547
1575
  const s = await Ee(r, {
1548
1576
  ...n,
@@ -1562,12 +1590,12 @@ async function ht(e, r, o, n) {
1562
1590
  }
1563
1591
  }
1564
1592
  const Y = M(
1565
- P(
1593
+ $(
1566
1594
  async (e) => {
1567
- const r = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${E.version}&market=${e?.market || O}`, o = await fetch(r, { headers: D }).then((n) => n.json());
1568
- return Object.keys(o.data).map((n) => ({
1569
- ...o.data[n],
1570
- coinType: n
1595
+ const r = j(e?.market || O), o = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${E.version}&market=${r.key}`, n = await fetch(o, { headers: U }).then((t) => t.json());
1596
+ return Object.keys(n.data).map((t) => ({
1597
+ ...n.data[t],
1598
+ coinType: t
1571
1599
  }));
1572
1600
  }
1573
1601
  )
@@ -1579,7 +1607,7 @@ async function wt(e, r, o, n) {
1579
1607
  const t = await _({
1580
1608
  ...n,
1581
1609
  cacheTime: b
1582
- }), a = await S(r, n);
1610
+ }), a = await P(r, n);
1583
1611
  if (!(await Y({
1584
1612
  ...n,
1585
1613
  cacheTime: b
@@ -1588,7 +1616,7 @@ async function wt(e, r, o, n) {
1588
1616
  ))
1589
1617
  throw new Error("Pool does not support flashloan");
1590
1618
  if (t.version === 1) {
1591
- const [c, u] = e.moveCall({
1619
+ const [c, l] = e.moveCall({
1592
1620
  target: `${t.package}::lending::flash_loan_with_ctx`,
1593
1621
  arguments: [
1594
1622
  e.object(t.flashloanConfig),
@@ -1597,9 +1625,9 @@ async function wt(e, r, o, n) {
1597
1625
  ],
1598
1626
  typeArguments: [a.suiCoinType]
1599
1627
  });
1600
- return [c, u];
1628
+ return [c, l];
1601
1629
  } else {
1602
- const [c, u] = e.moveCall({
1630
+ const [c, l] = e.moveCall({
1603
1631
  target: `${t.package}::lending::flash_loan_with_ctx_v2`,
1604
1632
  arguments: [
1605
1633
  e.object(t.flashloanConfig),
@@ -1609,14 +1637,14 @@ async function wt(e, r, o, n) {
1609
1637
  ],
1610
1638
  typeArguments: [a.suiCoinType]
1611
1639
  });
1612
- return [c, u];
1640
+ return [c, l];
1613
1641
  }
1614
1642
  }
1615
1643
  async function bt(e, r, o, n, t) {
1616
1644
  const a = await _({
1617
1645
  ...t,
1618
1646
  cacheTime: b
1619
- }), s = await S(r, t);
1647
+ }), s = await P(r, t);
1620
1648
  if (!(await Y({
1621
1649
  ...t,
1622
1650
  cacheTime: b
@@ -1624,7 +1652,7 @@ async function bt(e, r, o, n, t) {
1624
1652
  (m) => k(m.coinType) === k(s.suiCoinType)
1625
1653
  ))
1626
1654
  throw new Error("Pool does not support flashloan");
1627
- const [u] = e.moveCall({
1655
+ const [l] = e.moveCall({
1628
1656
  target: `${a.package}::lending::flash_repay_with_ctx`,
1629
1657
  arguments: [
1630
1658
  e.object("0x06"),
@@ -1635,13 +1663,13 @@ async function bt(e, r, o, n, t) {
1635
1663
  ],
1636
1664
  typeArguments: [s.suiCoinType]
1637
1665
  });
1638
- return [u];
1666
+ return [l];
1639
1667
  }
1640
1668
  async function kt(e, r, o, n, t, a) {
1641
1669
  const s = {
1642
1670
  ...a,
1643
1671
  cacheTime: b
1644
- }, i = await _(s), c = await S(r, s), u = await S(n, s);
1672
+ }, i = await _(s), c = await P(r, s), l = await P(n, s);
1645
1673
  if (i.version === 1) {
1646
1674
  const [m, h] = e.moveCall({
1647
1675
  target: `${i.package}::incentive_v3::liquidation`,
@@ -1658,9 +1686,9 @@ async function kt(e, r, o, n, t, a) {
1658
1686
  // Pay asset pool contract
1659
1687
  g(o, e.object),
1660
1688
  // Debt repayment amount
1661
- e.pure.u8(u.id),
1689
+ e.pure.u8(l.id),
1662
1690
  // Collateral asset ID
1663
- e.object(u.contract.pool),
1691
+ e.object(l.contract.pool),
1664
1692
  // Collateral asset pool contract
1665
1693
  g(t, e.pure.address),
1666
1694
  // Borrower address
@@ -1669,7 +1697,7 @@ async function kt(e, r, o, n, t, a) {
1669
1697
  e.object(i.incentiveV3)
1670
1698
  // Incentive V3 contract
1671
1699
  ],
1672
- typeArguments: [c.suiCoinType, u.suiCoinType]
1700
+ typeArguments: [c.suiCoinType, l.suiCoinType]
1673
1701
  });
1674
1702
  return [m, h];
1675
1703
  } else {
@@ -1688,9 +1716,9 @@ async function kt(e, r, o, n, t, a) {
1688
1716
  // Pay asset pool contract
1689
1717
  g(o, e.object),
1690
1718
  // Debt repayment amount
1691
- e.pure.u8(u.id),
1719
+ e.pure.u8(l.id),
1692
1720
  // Collateral asset ID
1693
- e.object(u.contract.pool),
1721
+ e.object(l.contract.pool),
1694
1722
  // Collateral asset pool contract
1695
1723
  g(t, e.pure.address),
1696
1724
  // Borrower address
@@ -1701,7 +1729,7 @@ async function kt(e, r, o, n, t, a) {
1701
1729
  e.object("0x05")
1702
1730
  // SuiSystemState object
1703
1731
  ],
1704
- typeArguments: [c.suiCoinType, u.suiCoinType]
1732
+ typeArguments: [c.suiCoinType, l.suiCoinType]
1705
1733
  });
1706
1734
  return [m, h];
1707
1735
  }
@@ -1709,7 +1737,7 @@ async function kt(e, r, o, n, t, a) {
1709
1737
  async function Re(e, r, o) {
1710
1738
  const n = o?.client ?? V, t = new F(), a = await q({
1711
1739
  ...o,
1712
- markets: Object.values(U),
1740
+ markets: Object.values(D),
1713
1741
  cacheTime: b
1714
1742
  }), s = await ie(o);
1715
1743
  for (let m of r) {
@@ -1757,24 +1785,24 @@ async function Re(e, r, o) {
1757
1785
  )
1758
1786
  );
1759
1787
  });
1760
- const u = [];
1788
+ const l = [];
1761
1789
  return c.forEach((m, h) => {
1762
1790
  const v = r[h];
1763
1791
  if (m.length === 5 && Array.isArray(m[0])) {
1764
1792
  const y = m[0].length;
1765
- for (let l = 0; l < y; l++) {
1793
+ for (let u = 0; u < y; u++) {
1766
1794
  const f = s.find(
1767
- (I) => k(I.coinType) === k(m[1][l])
1795
+ (T) => k(T.coinType) === k(m[1][u])
1768
1796
  ), w = a.find(
1769
- (I) => k(I.coinType) === k(m[0][l]) && I.market === v.market
1797
+ (T) => k(T.coinType) === k(m[0][u]) && T.market === v.market
1770
1798
  );
1771
- !f || !w || u.push({
1799
+ !f || !w || l.push({
1772
1800
  assetId: w.id,
1773
- assetCoinType: k(m[0][l]),
1774
- rewardCoinType: k(m[1][l]),
1775
- option: Number(m[2][l]),
1776
- userClaimableReward: Number(m[4][l]) / Math.pow(10, f.priceDecimal),
1777
- ruleIds: Array.isArray(m[3][l]) ? m[3][l] : [m[3][l]],
1801
+ assetCoinType: k(m[0][u]),
1802
+ rewardCoinType: k(m[1][u]),
1803
+ option: Number(m[2][u]),
1804
+ userClaimableReward: Number(m[4][u]) / Math.pow(10, f.priceDecimal),
1805
+ ruleIds: Array.isArray(m[3][u]) ? m[3][u] : [m[3][u]],
1778
1806
  market: v.market,
1779
1807
  owner: v.owner,
1780
1808
  address: v.address,
@@ -1782,10 +1810,10 @@ async function Re(e, r, o) {
1782
1810
  });
1783
1811
  }
1784
1812
  }
1785
- }), u;
1813
+ }), l;
1786
1814
  }
1787
1815
  async function _t(e, r) {
1788
- const o = (r?.markets || [U.main]).map((a) => T(a));
1816
+ const o = (r?.markets || [D.main]).map((a) => j(a));
1789
1817
  let n = [];
1790
1818
  try {
1791
1819
  n = await oe(e, r);
@@ -1798,7 +1826,7 @@ async function _t(e, r) {
1798
1826
  market: a.key
1799
1827
  })).concat(
1800
1828
  n.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
1801
- const s = T(a.marketId);
1829
+ const s = j(a.marketId);
1802
1830
  return {
1803
1831
  address: a.accountCap,
1804
1832
  owner: e,
@@ -1825,8 +1853,8 @@ function Ct(e) {
1825
1853
  for (const { assetId: n, rewardType: t, coinType: a, total: s, market: i } of r.values()) {
1826
1854
  const c = `${n}-${t}-${i}`;
1827
1855
  o.has(c) || o.set(c, { assetId: n, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
1828
- const u = o.get(c);
1829
- u.rewards.set(a, (u.rewards.get(a) || 0) + s);
1856
+ const l = o.get(c);
1857
+ l.rewards.set(a, (l.rewards.get(a) || 0) + s);
1830
1858
  }
1831
1859
  return Array.from(o.values()).map((n) => ({
1832
1860
  assetId: n.assetId,
@@ -1838,69 +1866,69 @@ function Ct(e) {
1838
1866
  }))
1839
1867
  }));
1840
1868
  }
1841
- const jt = P(
1869
+ const jt = $(
1842
1870
  async (e, r) => {
1843
- const o = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${E.version}&market=${r?.market || O}`;
1844
- return (await fetch(o, { headers: D }).then((t) => t.json())).data;
1871
+ const o = j(r?.market || O), n = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${E.version}&market=${o.key}`;
1872
+ return (await fetch(n, { headers: U }).then((a) => a.json())).data;
1845
1873
  }
1846
- ), It = P(
1874
+ ), It = $(
1847
1875
  async (e, r) => {
1848
- const o = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${r?.page || 1}&pageSize=${r?.size || 400}&sdk=${E.version}&market=${r?.market || O}`, n = await fetch(o, { headers: D }).then((t) => t.json());
1876
+ const o = j(r?.market || O), n = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${r?.page || 1}&pageSize=${r?.size || 400}&sdk=${E.version}&market=${o.key}`, t = await fetch(n, { headers: U }).then((a) => a.json());
1849
1877
  return K({
1850
- data: n.data.rewards
1878
+ data: t.data.rewards
1851
1879
  });
1852
1880
  }
1853
1881
  );
1854
1882
  async function Tt(e, r, o) {
1855
1883
  const n = await q({
1856
1884
  ...o,
1857
- markets: Object.values(U),
1885
+ markets: Object.values(D),
1858
1886
  cacheTime: b
1859
1887
  }), t = /* @__PURE__ */ new Map();
1860
1888
  for (const s of r) {
1861
- const { rewardCoinType: i, ruleIds: c, market: u, owner: m, address: h, emodeId: v } = s, y = `${i}___${h}__${u}`;
1862
- for (const l of c) {
1889
+ const { rewardCoinType: i, ruleIds: c, market: l, owner: m, address: h, emodeId: v } = s, y = `${i}___${h}__${l}`;
1890
+ for (const u of c) {
1863
1891
  t.has(y) || t.set(y, {
1864
1892
  assetIds: [],
1865
1893
  ruleIds: [],
1866
1894
  amount: 0,
1867
- market: u,
1895
+ market: l,
1868
1896
  owner: m,
1869
1897
  address: h,
1870
1898
  isEMode: typeof v < "u"
1871
1899
  });
1872
1900
  const f = t.get(y);
1873
- f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(l), f.amount += s.userClaimableReward;
1901
+ f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(u), f.amount += s.userClaimableReward;
1874
1902
  }
1875
1903
  }
1876
1904
  const a = [];
1877
1905
  for (const [
1878
1906
  s,
1879
- { assetIds: i, ruleIds: c, amount: u, market: m, owner: h, address: v, isEMode: y }
1907
+ { assetIds: i, ruleIds: c, amount: l, market: m, owner: h, address: v, isEMode: y }
1880
1908
  ] of t) {
1881
- const l = await _({
1909
+ const u = await _({
1882
1910
  ...o,
1883
1911
  cacheTime: b,
1884
1912
  market: m
1885
1913
  }), f = s.split("___")[0], w = n.filter(
1886
- (j) => k(j.suiCoinType) === k(f)
1914
+ (I) => k(I.suiCoinType) === k(f)
1887
1915
  );
1888
- w.sort((j, A) => j.market === m ? -1 : 1);
1889
- const I = w[0], B = l.rewardFunds[k(f)];
1916
+ w.sort((I, A) => I.market === m ? -1 : 1);
1917
+ const T = w[0], B = u.rewardFunds[k(f)];
1890
1918
  if (!B)
1891
1919
  throw new Error(`No matching rewardFund found for reward coin: ${f} ${m}`);
1892
1920
  if (o?.accountCap && !o.customCoinReceive)
1893
1921
  throw new Error("customCoinReceive is required when accountCap is provided");
1894
1922
  if (o?.customCoinReceive) {
1895
- let j;
1896
- o.accountCap ? j = e.moveCall({
1897
- target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
1923
+ let I;
1924
+ o.accountCap ? I = e.moveCall({
1925
+ target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
1898
1926
  arguments: [
1899
1927
  e.object("0x06"),
1900
1928
  // Clock object
1901
- e.object(l.incentiveV3),
1929
+ e.object(u.incentiveV3),
1902
1930
  // Incentive V3 contract
1903
- e.object(l.storage),
1931
+ e.object(u.storage),
1904
1932
  // Protocol storage
1905
1933
  e.object(B),
1906
1934
  // Reward fund
@@ -1912,14 +1940,14 @@ async function Tt(e, r, o) {
1912
1940
  // Account capability
1913
1941
  ],
1914
1942
  typeArguments: [f]
1915
- }) : y ? j = e.moveCall({
1916
- target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
1943
+ }) : y ? I = e.moveCall({
1944
+ target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
1917
1945
  arguments: [
1918
1946
  e.object("0x06"),
1919
1947
  // Clock object
1920
- e.object(l.incentiveV3),
1948
+ e.object(u.incentiveV3),
1921
1949
  // Incentive V3 contract
1922
- e.object(l.storage),
1950
+ e.object(u.storage),
1923
1951
  // Protocol storage
1924
1952
  e.object(B),
1925
1953
  // Reward fund
@@ -1931,14 +1959,14 @@ async function Tt(e, r, o) {
1931
1959
  // Account capability
1932
1960
  ],
1933
1961
  typeArguments: [f]
1934
- }) : j = e.moveCall({
1935
- target: `${l.package}::incentive_v3::claim_reward`,
1962
+ }) : I = e.moveCall({
1963
+ target: `${u.package}::incentive_v3::claim_reward`,
1936
1964
  arguments: [
1937
1965
  e.object("0x06"),
1938
1966
  // Clock object
1939
- e.object(l.incentiveV3),
1967
+ e.object(u.incentiveV3),
1940
1968
  // Incentive V3 contract
1941
- e.object(l.storage),
1969
+ e.object(u.storage),
1942
1970
  // Protocol storage
1943
1971
  e.object(B),
1944
1972
  // Reward fund
@@ -1951,7 +1979,7 @@ async function Tt(e, r, o) {
1951
1979
  });
1952
1980
  const [A] = e.moveCall({
1953
1981
  target: "0x2::coin::from_balance",
1954
- arguments: [j],
1982
+ arguments: [I],
1955
1983
  typeArguments: [f]
1956
1984
  });
1957
1985
  if (o?.customCoinReceive.type === "transfer") {
@@ -1963,30 +1991,30 @@ async function Tt(e, r, o) {
1963
1991
  );
1964
1992
  }
1965
1993
  if (o?.customCoinReceive.type === "depositNAVI") {
1966
- const L = p(I.totalSupplyAmount).shiftedBy(-9), G = p(I.supplyCapCeiling).shiftedBy(-27);
1967
- L.plus(u).isGreaterThan(G) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1994
+ const L = p(T.totalSupplyAmount).shiftedBy(-9), G = p(T.supplyCapCeiling).shiftedBy(-27);
1995
+ L.plus(l).isGreaterThan(G) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1968
1996
  [A],
1969
1997
  e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1970
- ) : await Be(e, I, A, {
1998
+ ) : await Be(e, T, A, {
1971
1999
  ...o,
1972
- market: I.market
2000
+ market: T.market
1973
2001
  });
1974
2002
  } else
1975
2003
  a.push({
1976
2004
  coin: A,
1977
- identifier: I,
2005
+ identifier: T,
1978
2006
  owner: h,
1979
2007
  isEMode: y
1980
2008
  });
1981
2009
  } else if (o?.accountCap || y) {
1982
- const j = e.moveCall({
1983
- target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
2010
+ const I = e.moveCall({
2011
+ target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
1984
2012
  arguments: [
1985
2013
  e.object("0x06"),
1986
2014
  // Clock object
1987
- e.object(l.incentiveV3),
2015
+ e.object(u.incentiveV3),
1988
2016
  // Incentive V3 contract
1989
- e.object(l.storage),
2017
+ e.object(u.storage),
1990
2018
  // Protocol storage
1991
2019
  e.object(B),
1992
2020
  // Reward fund
@@ -2000,7 +2028,7 @@ async function Tt(e, r, o) {
2000
2028
  typeArguments: [f]
2001
2029
  }), [A] = e.moveCall({
2002
2030
  target: "0x2::coin::from_balance",
2003
- arguments: [j],
2031
+ arguments: [I],
2004
2032
  typeArguments: [f]
2005
2033
  });
2006
2034
  e.transferObjects(
@@ -2009,13 +2037,13 @@ async function Tt(e, r, o) {
2009
2037
  );
2010
2038
  } else
2011
2039
  e.moveCall({
2012
- target: `${l.package}::incentive_v3::claim_reward_entry`,
2040
+ target: `${u.package}::incentive_v3::claim_reward_entry`,
2013
2041
  arguments: [
2014
2042
  e.object("0x06"),
2015
2043
  // Clock object
2016
- e.object(l.incentiveV3),
2044
+ e.object(u.incentiveV3),
2017
2045
  // Incentive V3 contract
2018
- e.object(l.storage),
2046
+ e.object(u.storage),
2019
2047
  // Protocol storage
2020
2048
  e.object(B),
2021
2049
  // Reward fund
@@ -2037,7 +2065,7 @@ export {
2037
2065
  Je as IncentiveAPYInfo,
2038
2066
  he as IncentivePoolInfo,
2039
2067
  Ze as IncentivePoolInfoByPhase,
2040
- U as MARKETS,
2068
+ D as MARKETS,
2041
2069
  Ae as Market,
2042
2070
  Qe as OracleInfo,
2043
2071
  R as PoolOperator,
@@ -2046,7 +2074,7 @@ export {
2046
2074
  we as UserStateInfo,
2047
2075
  ot as borrowCoinPTB,
2048
2076
  Tt as claimLendingRewardsPTB,
2049
- Pe as createAccountCapPTB,
2077
+ $e as createAccountCapPTB,
2050
2078
  ct as createEModeCapPTB,
2051
2079
  Be as depositCoinPTB,
2052
2080
  st as emodeIdentityId,
@@ -2054,7 +2082,7 @@ export {
2054
2082
  it as exitEModePTB,
2055
2083
  Fe as filterPriceFeeds,
2056
2084
  wt as flashloanPTB,
2057
- Se as getAccountCapOwnerPTB,
2085
+ Pe as getAccountCapOwnerPTB,
2058
2086
  Y as getAllFlashLoanAssets,
2059
2087
  nt as getBorrowFee,
2060
2088
  ft as getCoins,
@@ -2064,15 +2092,15 @@ export {
2064
2092
  pt as getHealthFactor,
2065
2093
  Ve as getHealthFactorPTB,
2066
2094
  Ee as getLendingPositions,
2067
- ut as getLendingState,
2095
+ lt as getLendingState,
2068
2096
  at as getMarket,
2069
- T as getMarketConfig,
2070
- $e as getMarkets,
2071
- S as getPool,
2097
+ j as getMarketConfig,
2098
+ Se as getMarkets,
2099
+ P as getPool,
2072
2100
  q as getPools,
2073
2101
  ie as getPriceFeeds,
2074
2102
  gt as getPythStalePriceFeedId,
2075
- Ue as getPythStalePriceFeedIdV2,
2103
+ De as getPythStalePriceFeedIdV2,
2076
2104
  dt as getSimulatedHealthFactor,
2077
2105
  re as getSimulatedHealthFactorPTB,
2078
2106
  xe as getStats,
@@ -2082,7 +2110,7 @@ export {
2082
2110
  oe as getUserEModeCaps,
2083
2111
  jt as getUserTotalClaimedReward,
2084
2112
  kt as liquidatePTB,
2085
- lt as mergeCoinsPTB,
2113
+ ut as mergeCoinsPTB,
2086
2114
  k as normalizeCoinType,
2087
2115
  Te as parsePoolUID,
2088
2116
  g as parseTxValue,
@@ -2094,7 +2122,7 @@ export {
2094
2122
  Oe as updatePythPriceFeeds,
2095
2123
  yt as verifyHealthFactorPTB,
2096
2124
  M as withCache,
2097
- P as withSingleton,
2125
+ $ as withSingleton,
2098
2126
  tt as withdrawCoinPTB
2099
2127
  };
2100
2128
  //# sourceMappingURL=index.esm.js.map