@naviprotocol/lending 1.3.1 → 1.3.2

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
@@ -3,14 +3,14 @@ import { bcs as i, toHex as z, fromHex as W } from "@mysten/bcs";
3
3
  import { SuiClient as J, getFullnodeUrl as K } from "@mysten/sui/client";
4
4
  import Y from "lodash.camelcase";
5
5
  import { normalizeStructTag as Q } from "@mysten/sui/utils";
6
- import { SuiPriceServiceConnection as U, SuiPythClient as X } from "@pythnetwork/pyth-sui-js";
6
+ import { SuiPriceServiceConnection as D, SuiPythClient as X } from "@pythnetwork/pyth-sui-js";
7
7
  import T from "bignumber.js";
8
- import { bcs as h } from "@mysten/sui/bcs";
8
+ import { bcs as w } from "@mysten/sui/bcs";
9
9
  const R = i.bytes(32).transform({
10
10
  // To change the input type, you need to provide a type definition for the input
11
11
  input: (e) => W(e),
12
12
  output: (e) => z(e)
13
- }), he = i.struct("IncentiveAPYInfo", {
13
+ }), we = i.struct("IncentiveAPYInfo", {
14
14
  /** Asset identifier */
15
15
  asset_id: i.u8(),
16
16
  /** Annual Percentage Yield as a 256-bit integer */
@@ -49,7 +49,7 @@ const R = i.bytes(32).transform({
49
49
  phase: i.u64(),
50
50
  /** List of incentive pools in this phase */
51
51
  pools: i.vector(Z)
52
- }), je = i.struct("OracleInfo", {
52
+ }), Ce = i.struct("OracleInfo", {
53
53
  /** Oracle identifier */
54
54
  oracle_id: i.u8(),
55
55
  /** Current price as a 256-bit integer */
@@ -58,7 +58,7 @@ const R = i.bytes(32).transform({
58
58
  decimals: i.u8(),
59
59
  /** Whether the oracle data is valid */
60
60
  valid: i.bool()
61
- }), Ce = i.struct("FlashLoanAssetConfig", {
61
+ }), je = i.struct("FlashLoanAssetConfig", {
62
62
  /** Unique identifier for the flash loan asset */
63
63
  id: i.string(),
64
64
  /** Asset identifier */
@@ -129,9 +129,9 @@ const R = i.bytes(32).transform({
129
129
  borrow_balance: i.u256(),
130
130
  /** User's current supply balance */
131
131
  supply_balance: i.u256()
132
- }), ee = "1.3.1", D = {
132
+ }), ee = "1.3.2", U = {
133
133
  version: ee
134
- }, te = D.version, re = () => {
134
+ }, te = U.version, re = () => {
135
135
  if (typeof process != "undefined" && process.versions && process.versions.node)
136
136
  try {
137
137
  const e = require("os"), r = process.version, c = e.type(), t = e.arch();
@@ -157,7 +157,7 @@ function L(e) {
157
157
  r.push(c);
158
158
  }), JSON.stringify(r);
159
159
  }
160
- function C(e) {
160
+ function j(e) {
161
161
  const r = {};
162
162
  return (...c) => {
163
163
  const t = L(c);
@@ -206,7 +206,7 @@ function M(e) {
206
206
  const r = (e || 0) / Math.pow(10, 27);
207
207
  return r > Math.pow(10, 5) ? 1 / 0 : r;
208
208
  }
209
- new U("https://hermes.pyth.network", {
209
+ new D("https://hermes.pyth.network", {
210
210
  timeout: 2e4
211
211
  });
212
212
  const ne = 27, E = (e, r) => {
@@ -216,14 +216,14 @@ const ne = 27, E = (e, r) => {
216
216
  }, I = N ? {
217
217
  "User-Agent": N
218
218
  } : {}, b = $(
219
- C(async (e) => {
220
- const r = `https://open-api.naviprotocol.io/api/navi/config?env=${(e == null ? void 0 : e.env) || "prod"}&sdk=${D.version}`;
219
+ j(async (e) => {
220
+ const r = `https://open-api.naviprotocol.io/api/navi/config?env=${(e == null ? void 0 : e.env) || "prod"}&sdk=${U.version}`;
221
221
  return (await fetch(r, { headers: I }).then((t) => t.json())).data;
222
222
  })
223
223
  ), g = 1e3 * 60 * 5;
224
224
  var k = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(k || {});
225
225
  const S = $(
226
- C(async (e) => {
226
+ j(async (e) => {
227
227
  const r = `https://open-api.naviprotocol.io/api/navi/pools?env=${(e == null ? void 0 : e.env) || "prod"}`;
228
228
  return (await fetch(r, { headers: I }).then((t) => t.json())).data;
229
229
  })
@@ -238,12 +238,12 @@ async function v(e, r) {
238
238
  const t = c.find((a) => typeof e == "string" ? m(a.suiCoinType) === m(e) : typeof e == "number" ? a.id === e : !1);
239
239
  if (!t)
240
240
  throw new Error("Pool not found");
241
- return t;
241
+ return t.isDeprecated && console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`), t;
242
242
  }
243
243
  const Te = $(
244
- C(async (e) => (await fetch("https://open-api.naviprotocol.io/api/navi/stats", { headers: I }).then((t) => t.json())).data)
244
+ j(async (e) => (await fetch("https://open-api.naviprotocol.io/api/navi/stats", { headers: I }).then((t) => t.json())).data)
245
245
  ), Ae = $(
246
- C(
246
+ j(
247
247
  async (e) => await fetch("https://open-api.naviprotocol.io/api/navi/fee", { headers: I }).then((t) => t.json())
248
248
  )
249
249
  );
@@ -251,7 +251,10 @@ async function oe(e, r, c, t) {
251
251
  const a = await b({
252
252
  ...t,
253
253
  cacheTime: g
254
- }), n = await v(r, t), o = typeof c == "object" && c.$kind === "GasCoin";
254
+ }), n = await v(r, t);
255
+ if (n != null && n.deprecatedAt && Date.now() > n.deprecatedAt)
256
+ throw new Error(`The lending pool for coinType ${n.suiCoinType} has been deprecated.`);
257
+ const o = typeof c == "object" && c.$kind === "GasCoin";
255
258
  if (m(n.suiCoinType) === m("0x2::sui::SUI") && o) {
256
259
  if (!(t != null && t.amount))
257
260
  throw new Error("Amount is required for sui coin");
@@ -380,7 +383,10 @@ async function $e(e, r, c, t) {
380
383
  const a = await b({
381
384
  ...t,
382
385
  cacheTime: g
383
- }), n = await v(r, t), o = d(c, e.pure.u64);
386
+ }), n = await v(r, t);
387
+ if (n != null && n.deprecatedAt && Date.now() > n.deprecatedAt)
388
+ throw new Error(`The lending pool for coinType ${n.suiCoinType} has been deprecated.`);
389
+ const o = d(c, e.pure.u64);
384
390
  let s;
385
391
  if (a.version === 1)
386
392
  if (t != null && t.accountCap) {
@@ -506,7 +512,7 @@ async function ke(e, r, c, t) {
506
512
  }), e;
507
513
  }
508
514
  const Be = $(
509
- C(
515
+ j(
510
516
  async (e) => {
511
517
  var a;
512
518
  const r = await b({
@@ -528,7 +534,7 @@ const Be = $(
528
534
  const u = await o.devInspectTransactionBlock({
529
535
  transactionBlock: s,
530
536
  sender: e.address
531
- }), l = P(u, [h.u64()]);
537
+ }), l = P(u, [w.u64()]);
532
538
  return (Number(l[0]) || 0) / 100;
533
539
  } catch (n) {
534
540
  console.error(n);
@@ -601,22 +607,22 @@ const Ve = $(
601
607
  const o = await a.devInspectTransactionBlock({
602
608
  transactionBlock: t,
603
609
  sender: e
604
- }), s = P(o, [h.vector(x)]);
610
+ }), s = P(o, [w.vector(x)]);
605
611
  return V(
606
612
  s[0].filter((p) => p.supply_balance !== "0" || p.borrow_balance !== "0")
607
613
  ).map((p) => {
608
- const w = n.find((j) => j.id === p.assetId), f = E(
614
+ const h = n.find((C) => C.id === p.assetId), f = E(
609
615
  p.supplyBalance,
610
- w.currentSupplyIndex
616
+ h.currentSupplyIndex
611
617
  ).toString(), y = E(
612
618
  p.borrowBalance,
613
- w.currentBorrowIndex
619
+ h.currentBorrowIndex
614
620
  ).toString();
615
621
  return {
616
622
  ...p,
617
623
  supplyBalance: f,
618
624
  borrowBalance: y,
619
- pool: w
625
+ pool: h
620
626
  };
621
627
  }).filter((p) => !!p.pool);
622
628
  }
@@ -628,7 +634,7 @@ async function Se(e, r) {
628
634
  const a = await c.devInspectTransactionBlock({
629
635
  transactionBlock: t,
630
636
  sender: e
631
- }), n = P(a, [h.u256()]);
637
+ }), n = P(a, [w.u256()]);
632
638
  return M(Number(n[0]) || 0);
633
639
  }
634
640
  async function Fe(e, r, c, t) {
@@ -653,10 +659,10 @@ async function Fe(e, r, c, t) {
653
659
  const p = await a.devInspectTransactionBlock({
654
660
  transactionBlock: n,
655
661
  sender: e
656
- }), w = P(p, [h.u256()]);
657
- return M(Number(w[0]) || 0);
662
+ }), h = P(p, [w.u256()]);
663
+ return M(Number(h[0]) || 0);
658
664
  }
659
- const Re = C(
665
+ const Re = j(
660
666
  async (e, r) => {
661
667
  const c = new URLSearchParams();
662
668
  r != null && r.cursor && c.set("cursor", r.cursor), c.set("userAddress", e);
@@ -685,7 +691,7 @@ async function Ne(e, r) {
685
691
  } while (c);
686
692
  return t;
687
693
  }
688
- const q = new U("https://hermes.pyth.network", {
694
+ const q = new D("https://hermes.pyth.network", {
689
695
  timeout: 1e4
690
696
  });
691
697
  async function ie(e) {
@@ -766,11 +772,11 @@ async function le(e) {
766
772
  cacheTime: g
767
773
  })).oracle.feeds;
768
774
  }
769
- function Ue(e, r) {
775
+ function De(e, r) {
770
776
  return e.filter((c) => !!(r != null && r.lendingState && r.lendingState.find((a) => a.assetId === c.assetId) || r != null && r.pools && r.pools.find((a) => a.id === c.assetId)));
771
777
  }
772
778
  const F = $(
773
- C(async (e) => {
779
+ j(async (e) => {
774
780
  const r = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${(e == null ? void 0 : e.env) || "prod"}`, c = await fetch(r, { headers: I }).then((t) => t.json());
775
781
  return Object.keys(c.data).map((t) => ({
776
782
  ...c.data[t],
@@ -778,7 +784,7 @@ const F = $(
778
784
  }));
779
785
  })
780
786
  );
781
- async function De(e, r) {
787
+ async function Ue(e, r) {
782
788
  return (await F(r)).find((t) => typeof e == "string" ? m(t.coinType) === m(e) : typeof e == "number" ? t.assetId === e : t.assetId === e.id) || null;
783
789
  }
784
790
  async function Le(e, r, c, t) {
@@ -849,7 +855,7 @@ async function Oe(e, r, c, t, a, n) {
849
855
  cacheTime: g
850
856
  }, s = await b(o), u = await v(r, o), l = await v(t, o);
851
857
  if (s.version === 1) {
852
- const [p, w] = e.moveCall({
858
+ const [p, h] = e.moveCall({
853
859
  target: `${s.package}::incentive_v3::liquidation`,
854
860
  arguments: [
855
861
  e.object("0x06"),
@@ -877,9 +883,9 @@ async function Oe(e, r, c, t, a, n) {
877
883
  ],
878
884
  typeArguments: [u.suiCoinType, l.suiCoinType]
879
885
  });
880
- return [p, w];
886
+ return [p, h];
881
887
  } else {
882
- const [p, w] = e.moveCall({
888
+ const [p, h] = e.moveCall({
883
889
  target: `${s.package}::incentive_v3::liquidation_v2`,
884
890
  arguments: [
885
891
  e.object("0x06"),
@@ -909,7 +915,7 @@ async function Oe(e, r, c, t, a, n) {
909
915
  ],
910
916
  typeArguments: [u.suiCoinType, l.suiCoinType]
911
917
  });
912
- return [p, w];
918
+ return [p, h];
913
919
  }
914
920
  }
915
921
  async function qe(e, r) {
@@ -940,28 +946,28 @@ async function qe(e, r) {
940
946
  }), u = P(
941
947
  s,
942
948
  [
943
- h.vector(h.string()),
949
+ w.vector(w.string()),
944
950
  // Asset coin types
945
- h.vector(h.string()),
951
+ w.vector(w.string()),
946
952
  // Reward coin types
947
- h.vector(h.u8()),
953
+ w.vector(w.u8()),
948
954
  // Reward options
949
- h.vector(h.Address),
955
+ w.vector(w.Address),
950
956
  // Rule IDs
951
- h.vector(h.u256())
957
+ w.vector(w.u256())
952
958
  // Claimable amounts
953
959
  ]
954
960
  ), l = [];
955
961
  if (u.length === 5 && Array.isArray(u[0])) {
956
- const w = u[0].length;
957
- for (let f = 0; f < w; f++) {
962
+ const h = u[0].length;
963
+ for (let f = 0; f < h; f++) {
958
964
  const y = c.find(
959
965
  (_) => m(_.coinType) === m(u[1][f])
960
- ), j = t.find(
966
+ ), C = t.find(
961
967
  (_) => m(_.coinType) === m(u[0][f])
962
968
  );
963
- !y || !j || l.push({
964
- assetId: j.id,
969
+ !y || !C || l.push({
970
+ assetId: C.id,
965
971
  assetCoinType: m(u[0][f]),
966
972
  rewardCoinType: m(u[1][f]),
967
973
  option: Number(u[2][f]),
@@ -999,12 +1005,12 @@ function He(e) {
999
1005
  }))
1000
1006
  }));
1001
1007
  }
1002
- const Ge = C(
1008
+ const Ge = j(
1003
1009
  async (e) => {
1004
1010
  const r = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}`;
1005
1011
  return (await fetch(r, { headers: I }).then((t) => t.json())).data;
1006
1012
  }
1007
- ), ze = C(
1013
+ ), ze = j(
1008
1014
  async (e, r) => {
1009
1015
  const c = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${(r == null ? void 0 : r.page) || 1}&pageSize=${(r == null ? void 0 : r.size) || 400}`, t = await fetch(c, { headers: I }).then((a) => a.json());
1010
1016
  return V({
@@ -1023,16 +1029,16 @@ async function We(e, r, c) {
1023
1029
  }), n = /* @__PURE__ */ new Map();
1024
1030
  for (const u of r) {
1025
1031
  const { rewardCoinType: l, ruleIds: p } = u;
1026
- for (const w of p) {
1032
+ for (const h of p) {
1027
1033
  n.has(l) || n.set(l, { assetIds: [], ruleIds: [], amount: 0 });
1028
1034
  const f = n.get(l);
1029
- f.assetIds.push(u.assetCoinType.replace("0x", "")), f.ruleIds.push(w), f.amount += u.userClaimableReward;
1035
+ f.assetIds.push(u.assetCoinType.replace("0x", "")), f.ruleIds.push(h), f.amount += u.userClaimableReward;
1030
1036
  }
1031
1037
  }
1032
1038
  const o = [];
1033
- for (const [u, { assetIds: l, ruleIds: p, amount: w }] of n) {
1039
+ for (const [u, { assetIds: l, ruleIds: p, amount: h }] of n) {
1034
1040
  const f = a.find(
1035
- (j) => m(j.suiCoinType) === m(u)
1041
+ (C) => m(C.suiCoinType) === m(u)
1036
1042
  );
1037
1043
  if (!f || !f.contract.rewardFundId)
1038
1044
  throw new Error(`No matching rewardFund found for reward coin: ${u}`);
@@ -1040,8 +1046,8 @@ async function We(e, r, c) {
1040
1046
  if (c != null && c.accountCap && !c.customCoinReceive)
1041
1047
  throw new Error("customCoinReceive is required when accountCap is provided");
1042
1048
  if (c != null && c.customCoinReceive) {
1043
- let j;
1044
- c.accountCap ? j = e.moveCall({
1049
+ let C;
1050
+ c.accountCap ? C = e.moveCall({
1045
1051
  target: `${t.package}::incentive_v3::claim_reward_with_account_cap`,
1046
1052
  arguments: [
1047
1053
  e.object("0x06"),
@@ -1060,7 +1066,7 @@ async function We(e, r, c) {
1060
1066
  // Account capability
1061
1067
  ],
1062
1068
  typeArguments: [u]
1063
- }) : j = e.moveCall({
1069
+ }) : C = e.moveCall({
1064
1070
  target: `${t.package}::incentive_v3::claim_reward`,
1065
1071
  arguments: [
1066
1072
  e.object("0x06"),
@@ -1080,7 +1086,7 @@ async function We(e, r, c) {
1080
1086
  });
1081
1087
  const [_] = e.moveCall({
1082
1088
  target: "0x2::coin::from_balance",
1083
- arguments: [j],
1089
+ arguments: [C],
1084
1090
  typeArguments: [u]
1085
1091
  });
1086
1092
  if ((c == null ? void 0 : c.customCoinReceive.type) === "transfer") {
@@ -1093,7 +1099,7 @@ async function We(e, r, c) {
1093
1099
  }
1094
1100
  if ((c == null ? void 0 : c.customCoinReceive.type) === "depositNAVI") {
1095
1101
  const H = T(f.totalSupplyAmount).shiftedBy(-9), G = T(f.supplyCapCeiling).shiftedBy(-27);
1096
- H.plus(w).isGreaterThan(G) && ((s = c == null ? void 0 : c.customCoinReceive.depositNAVI) != null && s.fallbackReceiveAddress) ? e.transferObjects(
1102
+ H.plus(h).isGreaterThan(G) && ((s = c == null ? void 0 : c.customCoinReceive.depositNAVI) != null && s.fallbackReceiveAddress) ? e.transferObjects(
1097
1103
  [_],
1098
1104
  e.pure.address(c.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1099
1105
  ) : await oe(e, f, _, c);
@@ -1136,11 +1142,11 @@ async function Je(e, r) {
1136
1142
  export {
1137
1143
  R as Address,
1138
1144
  g as DEFAULT_CACHE_TIME,
1139
- Ce as FlashLoanAssetConfig,
1140
- he as IncentiveAPYInfo,
1145
+ je as FlashLoanAssetConfig,
1146
+ we as IncentiveAPYInfo,
1141
1147
  Z as IncentivePoolInfo,
1142
1148
  ve as IncentivePoolInfoByPhase,
1143
- je as OracleInfo,
1149
+ Ce as OracleInfo,
1144
1150
  k as PoolOperator,
1145
1151
  _e as ReserveDataInfo,
1146
1152
  x as UserStateInfo,
@@ -1148,14 +1154,14 @@ export {
1148
1154
  We as claimLendingRewardsPTB,
1149
1155
  Je as createAccountCapPTB,
1150
1156
  oe as depositCoinPTB,
1151
- Ue as filterPriceFeeds,
1157
+ De as filterPriceFeeds,
1152
1158
  Le as flashloanPTB,
1153
1159
  F as getAllFlashLoanAssets,
1154
1160
  Be as getBorrowFee,
1155
1161
  Ne as getCoins,
1156
1162
  b as getConfig,
1157
1163
  Ae as getFees,
1158
- De as getFlashLoanAsset,
1164
+ Ue as getFlashLoanAsset,
1159
1165
  Se as getHealthFactor,
1160
1166
  se as getHealthFactorPTB,
1161
1167
  Ve as getLendingState,
@@ -1180,7 +1186,7 @@ export {
1180
1186
  Ee as updateOraclePricesPTB,
1181
1187
  ue as updatePythPriceFeeds,
1182
1188
  $ as withCache,
1183
- C as withSingleton,
1189
+ j as withSingleton,
1184
1190
  Ie as withdrawCoinPTB
1185
1191
  };
1186
1192
  //# sourceMappingURL=index.esm.js.map