@naviprotocol/lending 1.4.4-beta.5 → 1.4.4-beta.7

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,4 +1,4 @@
1
- import { Transaction as N } from "@mysten/sui/transactions";
1
+ import { Transaction as F } from "@mysten/sui/transactions";
2
2
  import { bcs as m, toHex as ce, fromHex as se } from "@mysten/bcs";
3
3
  import { SuiClient as le, getFullnodeUrl as ue } from "@mysten/sui/client";
4
4
  import pe from "lodash.camelcase";
@@ -129,7 +129,7 @@ const K = m.bytes(32).transform({
129
129
  borrow_balance: m.u256(),
130
130
  /** User's current supply balance */
131
131
  supply_balance: m.u256()
132
- }), ge = "1.4.4-beta.5", V = {
132
+ }), ge = "1.4.4-beta.7", V = {
133
133
  version: ge
134
134
  }, he = V.version, ve = () => {
135
135
  if (typeof process < "u" && process.versions && process.versions.node)
@@ -256,12 +256,12 @@ var R = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] =
256
256
  const q = P(
257
257
  B(
258
258
  async (e) => {
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(
259
+ const r = (e?.markets || [E.main]).map((t) => j(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
261
  )}`, n = await fetch(o, { headers: M }).then((t) => t.json());
262
262
  return n.data.forEach((t) => {
263
263
  const s = n.meta.emodes.filter((f) => {
264
- const k = I(f.marketId);
264
+ const k = j(f.marketId);
265
265
  return t.market === k.key && f.isActive;
266
266
  }).filter((f) => !!f.assets.find((k) => k.assetId === t.id));
267
267
  t.emodes = s;
@@ -586,7 +586,7 @@ const tt = P(
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, s = new N();
589
+ const t = await A(e.asset, e), a = e?.client ?? S, s = new F();
590
590
  s.moveCall({
591
591
  target: `${r.package}::incentive_v3::get_borrow_fee_v2`,
592
592
  arguments: [
@@ -627,6 +627,11 @@ const tt = P(
627
627
  id: 2,
628
628
  key: "sui-eco",
629
629
  name: "Sui Eco Market"
630
+ },
631
+ rwa: {
632
+ id: 3,
633
+ key: "rwa",
634
+ name: "RWA Market"
630
635
  }
631
636
  };
632
637
  class je {
@@ -634,7 +639,7 @@ class je {
634
639
  this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
635
640
  marketTotalSupplyValue: "0",
636
641
  marketTotalBorrowValue: "0"
637
- }, this.config = I(r), this.initPools(o);
642
+ }, this.config = j(r), this.initPools(o);
638
643
  }
639
644
  get overview() {
640
645
  return this._overview;
@@ -692,7 +697,7 @@ class je {
692
697
  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
698
  }
694
699
  }
695
- const I = (e) => {
700
+ const j = (e) => {
696
701
  const o = Object.values(E).find((n) => typeof e == "number" ? n.id === e : typeof e == "string" ? n.key === e : n.id === e.id);
697
702
  if (!o)
698
703
  throw new Error("Market not found");
@@ -706,7 +711,7 @@ const I = (e) => {
706
711
  markets: e
707
712
  });
708
713
  return e.map((n) => {
709
- const t = I(n), a = o.filter((s) => s.market === t.key);
714
+ const t = j(n), a = o.filter((s) => s.market === t.key);
710
715
  return new je(n, a);
711
716
  });
712
717
  }
@@ -718,7 +723,7 @@ const I = (e) => {
718
723
  ), _ = P(
719
724
  B(
720
725
  async (e) => {
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}`;
726
+ const r = j(e?.market || U), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${V.version}&market=${r.key}`;
722
727
  return (await fetch(o, { headers: M }).then((t) => t.json())).data;
723
728
  }
724
729
  )
@@ -782,7 +787,7 @@ async function nt(e, r, o) {
782
787
  ...o,
783
788
  accountCap: t
784
789
  });
785
- const a = await I(o?.market || U), s = await Be(e, t, o);
790
+ const a = await j(o?.market || U), s = await Be(e, t, o);
786
791
  return e.moveCall({
787
792
  target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
788
793
  arguments: [
@@ -799,7 +804,7 @@ const ee = P(
799
804
  const o = await _({
800
805
  cacheTime: w,
801
806
  ...r
802
- }), n = new N(), t = r?.client ?? S;
807
+ }), n = new F(), t = r?.client ?? S;
803
808
  n.moveCall({
804
809
  target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
805
810
  arguments: [n.object(o.emode.contract.registryObject), n.pure.address(e)]
@@ -817,7 +822,7 @@ const ee = P(
817
822
  )
818
823
  );
819
824
  function at(e) {
820
- return `${I(e.marketId).key}-${e.emodeId}`;
825
+ return `${j(e.marketId).key}-${e.emodeId}`;
821
826
  }
822
827
  function it(e, r, o) {
823
828
  const n = typeof o?.balance == "number", t = n ? o.balance : 0;
@@ -863,7 +868,7 @@ async function Pe(e, r, o) {
863
868
  return te(e, r, 0, 0, 0, !1, o);
864
869
  }
865
870
  async function oe(e, r, o) {
866
- const n = new N(), t = o?.client ?? S, a = await q({
871
+ const n = new F(), t = o?.client ?? S, a = await q({
867
872
  ...o,
868
873
  markets: Object.values(E)
869
874
  }), s = G(a);
@@ -883,7 +888,7 @@ async function oe(e, r, o) {
883
888
  sender: e
884
889
  })).results || []).map((d) => d.returnValues?.map((y) => C.vector(ye).parse(Uint8Array.from(y[0])))[0] || []), l = [];
885
890
  return c.forEach((d, y) => {
886
- const v = r[y], g = I(v.market);
891
+ const v = r[y], g = j(v.market);
887
892
  d.forEach((u) => {
888
893
  if (u.supply_balance === "0" && u.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
889
894
  return;
@@ -893,13 +898,13 @@ async function oe(e, r, o) {
893
898
  const k = J(
894
899
  u.supply_balance,
895
900
  f.currentSupplyIndex
896
- ).toString(), j = J(
901
+ ).toString(), I = J(
897
902
  u.borrow_balance,
898
903
  f.currentBorrowIndex
899
904
  ).toString();
900
905
  l.push({
901
906
  supplyBalance: k,
902
- borrowBalance: j,
907
+ borrowBalance: I,
903
908
  assetId: u.asset_id,
904
909
  market: g.key,
905
910
  pool: f,
@@ -910,7 +915,7 @@ async function oe(e, r, o) {
910
915
  }
911
916
  const ct = P(
912
917
  async (e, r) => {
913
- const n = (r?.markets || Object.keys(E)).map((t) => I(t)).map((t) => ({
918
+ const n = (r?.markets || Object.keys(E)).map((t) => j(t)).map((t) => ({
914
919
  address: e,
915
920
  market: t.key
916
921
  }));
@@ -918,7 +923,7 @@ const ct = P(
918
923
  }
919
924
  );
920
925
  async function st(e, r) {
921
- const o = r?.client ?? S, n = new N();
926
+ const o = r?.client ?? S, n = new F();
922
927
  await Pe(n, e, r);
923
928
  const t = await o.devInspectTransactionBlock({
924
929
  transactionBlock: n,
@@ -927,7 +932,7 @@ async function st(e, r) {
927
932
  return x(Number(a[0]) || 0);
928
933
  }
929
934
  async function lt(e, r, o, n) {
930
- const t = n?.client ?? S, a = new N();
935
+ const t = n?.client ?? S, a = new F();
931
936
  let s = 0, i = 0;
932
937
  const c = await A(r, n);
933
938
  if (o.forEach((v) => {
@@ -980,7 +985,7 @@ async function pt(e, r) {
980
985
  }
981
986
  const $e = P(
982
987
  async (e, r) => {
983
- const o = [], n = (r?.markets || Object.keys(E)).map((i) => I(i));
988
+ const o = [], n = (r?.markets || Object.keys(E)).map((i) => j(i));
984
989
  let t = [];
985
990
  try {
986
991
  t = await ee(e, r);
@@ -993,13 +998,13 @@ const $e = P(
993
998
  })).concat(
994
999
  t.filter((i) => !!n.find((c) => c.id === i.marketId)).map((i) => ({
995
1000
  address: i.accountCap,
996
- market: I(i.marketId).key,
1001
+ market: j(i.marketId).key,
997
1002
  emodeId: i.emodeId
998
1003
  }))
999
1004
  );
1000
1005
  return (await oe(e, a, r)).forEach((i) => {
1001
1006
  const c = typeof i.emodeId == "number" ? t.find((l) => {
1002
- const d = I(i.market);
1007
+ const d = j(i.market);
1003
1008
  return l.emodeId === i.emodeId && l.marketId === d.id;
1004
1009
  }) : void 0;
1005
1010
  if (c) {
@@ -1086,7 +1091,7 @@ const $e = P(
1086
1091
  }), o;
1087
1092
  }
1088
1093
  );
1089
- class O {
1094
+ class N {
1090
1095
  constructor(r, o) {
1091
1096
  this._positions = [], this._priceMap = {}, this._overview = {
1092
1097
  hf: 1 / 0,
@@ -1126,7 +1131,7 @@ class O {
1126
1131
  }
1127
1132
  filterPositionsByPool(r) {
1128
1133
  const n = !!r.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
1129
- return new O(
1134
+ return new N(
1130
1135
  this.positions.filter((t) => {
1131
1136
  const a = t[t.type];
1132
1137
  return n.includes(t.type) && a.pool.uniqueId === r.uniqueId;
@@ -1162,7 +1167,7 @@ class O {
1162
1167
  token: r.token,
1163
1168
  pool: r
1164
1169
  }
1165
- }, new O([...this.positions, a], this._priceMap);
1170
+ }, new N([...this.positions, a], this._priceMap);
1166
1171
  }
1167
1172
  withdraw(r, o) {
1168
1173
  const n = !!r.isEMode, t = this.getPrice(r);
@@ -1192,7 +1197,7 @@ class O {
1192
1197
  token: r.token,
1193
1198
  pool: r
1194
1199
  }
1195
- }, new O([...this.positions, a], this._priceMap);
1200
+ }, new N([...this.positions, a], this._priceMap);
1196
1201
  }
1197
1202
  borrow(r, o) {
1198
1203
  const n = !!r.isEMode, t = this.getPrice(r);
@@ -1222,7 +1227,7 @@ class O {
1222
1227
  token: r.token,
1223
1228
  pool: r
1224
1229
  }
1225
- }, new O([...this.positions, a], this._priceMap);
1230
+ }, new N([...this.positions, a], this._priceMap);
1226
1231
  }
1227
1232
  repay(r, o) {
1228
1233
  const n = !!r.isEMode, t = this.getPrice(r);
@@ -1252,7 +1257,7 @@ class O {
1252
1257
  token: r.token,
1253
1258
  pool: r
1254
1259
  }
1255
- }, new O([...this.positions, a], this._priceMap);
1260
+ }, new N([...this.positions, a], this._priceMap);
1256
1261
  }
1257
1262
  resolveValueUSD(r) {
1258
1263
  return Object.keys(this._priceMap).length > 0 ? p(r.amount).multipliedBy(this.getPrice(r.pool)).toString() : r.valueUSD;
@@ -1680,7 +1685,7 @@ async function vt(e, r, o, n, t, a) {
1680
1685
  }
1681
1686
  }
1682
1687
  async function Ue(e, r, o) {
1683
- const n = o?.client ?? S, t = new N(), a = await q({
1688
+ const n = o?.client ?? S, t = new F(), a = await q({
1684
1689
  ...o,
1685
1690
  markets: Object.values(E),
1686
1691
  cacheTime: w
@@ -1737,9 +1742,9 @@ async function Ue(e, r, o) {
1737
1742
  const g = d[0].length;
1738
1743
  for (let u = 0; u < g; u++) {
1739
1744
  const f = s.find(
1740
- (j) => b(j.coinType) === b(d[1][u])
1745
+ (I) => b(I.coinType) === b(d[1][u])
1741
1746
  ), k = a.find(
1742
- (j) => b(j.coinType) === b(d[0][u]) && j.market === v.market
1747
+ (I) => b(I.coinType) === b(d[0][u]) && I.market === v.market
1743
1748
  );
1744
1749
  !f || !k || l.push({
1745
1750
  assetId: k.id,
@@ -1758,7 +1763,7 @@ async function Ue(e, r, o) {
1758
1763
  }), l;
1759
1764
  }
1760
1765
  async function wt(e, r) {
1761
- const o = (r?.markets || [E.main]).map((a) => I(a));
1766
+ const o = (r?.markets || [E.main]).map((a) => j(a));
1762
1767
  let n = [];
1763
1768
  try {
1764
1769
  n = await ee(e, r);
@@ -1771,7 +1776,7 @@ async function wt(e, r) {
1771
1776
  market: a.key
1772
1777
  })).concat(
1773
1778
  n.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
1774
- const s = I(a.marketId);
1779
+ const s = j(a.marketId);
1775
1780
  return {
1776
1781
  address: a.accountCap,
1777
1782
  owner: e,
@@ -1855,12 +1860,13 @@ async function Ct(e, r, o) {
1855
1860
  ...o,
1856
1861
  cacheTime: w,
1857
1862
  market: d
1858
- }), f = s.split("___")[0], k = n.filter(($) => b($.suiCoinType) === b(f));
1863
+ }), f = s.split("___")[0], k = n.filter(
1864
+ ($) => b($.suiCoinType) === b(f)
1865
+ );
1859
1866
  k.sort(($, D) => $.market === d ? -1 : 1);
1860
- const j = k[0];
1861
- if (!j || !j.contract.rewardFundId)
1867
+ const I = k[0], O = u.rewardFunds[b(f)];
1868
+ if (!O)
1862
1869
  throw new Error(`No matching rewardFund found for reward coin: ${f} ${d}`);
1863
- const F = j.contract.rewardFundId;
1864
1870
  if (o?.accountCap && !o.customCoinReceive)
1865
1871
  throw new Error("customCoinReceive is required when accountCap is provided");
1866
1872
  if (o?.customCoinReceive) {
@@ -1874,7 +1880,7 @@ async function Ct(e, r, o) {
1874
1880
  // Incentive V3 contract
1875
1881
  e.object(u.storage),
1876
1882
  // Protocol storage
1877
- e.object(F),
1883
+ e.object(O),
1878
1884
  // Reward fund
1879
1885
  e.pure.vector("string", i),
1880
1886
  // Asset IDs
@@ -1893,7 +1899,7 @@ async function Ct(e, r, o) {
1893
1899
  // Incentive V3 contract
1894
1900
  e.object(u.storage),
1895
1901
  // Protocol storage
1896
- e.object(F),
1902
+ e.object(O),
1897
1903
  // Reward fund
1898
1904
  e.pure.vector("string", i),
1899
1905
  // Asset IDs
@@ -1912,7 +1918,7 @@ async function Ct(e, r, o) {
1912
1918
  // Incentive V3 contract
1913
1919
  e.object(u.storage),
1914
1920
  // Protocol storage
1915
- e.object(F),
1921
+ e.object(O),
1916
1922
  // Reward fund
1917
1923
  e.pure.vector("string", i),
1918
1924
  // Asset IDs
@@ -1935,18 +1941,18 @@ async function Ct(e, r, o) {
1935
1941
  );
1936
1942
  }
1937
1943
  if (o?.customCoinReceive.type === "depositNAVI") {
1938
- const ae = p(j.totalSupplyAmount).shiftedBy(-9), ie = p(j.supplyCapCeiling).shiftedBy(-27);
1944
+ const ae = p(I.totalSupplyAmount).shiftedBy(-9), ie = p(I.supplyCapCeiling).shiftedBy(-27);
1939
1945
  ae.plus(l).isGreaterThan(ie) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1940
1946
  [D],
1941
1947
  e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1942
- ) : await Ce(e, j, D, {
1948
+ ) : await Ce(e, I, D, {
1943
1949
  ...o,
1944
- market: j.market
1950
+ market: I.market
1945
1951
  });
1946
1952
  } else
1947
1953
  a.push({
1948
1954
  coin: D,
1949
- identifier: j,
1955
+ identifier: I,
1950
1956
  owner: y,
1951
1957
  isEMode: g
1952
1958
  });
@@ -1960,7 +1966,7 @@ async function Ct(e, r, o) {
1960
1966
  // Incentive V3 contract
1961
1967
  e.object(u.storage),
1962
1968
  // Protocol storage
1963
- e.object(F),
1969
+ e.object(O),
1964
1970
  // Reward fund
1965
1971
  e.pure.vector("string", i),
1966
1972
  // Asset IDs
@@ -1989,7 +1995,7 @@ async function Ct(e, r, o) {
1989
1995
  // Incentive V3 contract
1990
1996
  e.object(u.storage),
1991
1997
  // Protocol storage
1992
- e.object(F),
1998
+ e.object(O),
1993
1999
  // Reward fund
1994
2000
  e.pure.vector("string", i),
1995
2001
  // Asset IDs
@@ -2014,7 +2020,7 @@ export {
2014
2020
  Ke as OracleInfo,
2015
2021
  R as PoolOperator,
2016
2022
  Je as ReserveDataInfo,
2017
- O as UserPositions,
2023
+ N as UserPositions,
2018
2024
  ye as UserStateInfo,
2019
2025
  xe as borrowCoinPTB,
2020
2026
  Ct as claimLendingRewardsPTB,
@@ -2038,7 +2044,7 @@ export {
2038
2044
  $e as getLendingPositions,
2039
2045
  ct as getLendingState,
2040
2046
  ot as getMarket,
2041
- I as getMarketConfig,
2047
+ j as getMarketConfig,
2042
2048
  Ie as getMarkets,
2043
2049
  A as getPool,
2044
2050
  q as getPools,