@naviprotocol/lending 1.4.4-beta.4 → 1.4.4-beta.6
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.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +47 -48
- package/dist/index.esm.js.map +1 -1
- package/dist/reward.d.ts.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transaction as
|
|
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.
|
|
132
|
+
}), ge = "1.4.4-beta.6", 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) =>
|
|
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 =
|
|
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
|
|
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: [
|
|
@@ -634,7 +634,7 @@ class je {
|
|
|
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 =
|
|
637
|
+
}, this.config = j(r), this.initPools(o);
|
|
638
638
|
}
|
|
639
639
|
get overview() {
|
|
640
640
|
return this._overview;
|
|
@@ -692,7 +692,7 @@ class je {
|
|
|
692
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
|
|
695
|
+
const j = (e) => {
|
|
696
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");
|
|
@@ -706,7 +706,7 @@ const I = (e) => {
|
|
|
706
706
|
markets: e
|
|
707
707
|
});
|
|
708
708
|
return e.map((n) => {
|
|
709
|
-
const t =
|
|
709
|
+
const t = j(n), a = o.filter((s) => s.market === t.key);
|
|
710
710
|
return new je(n, a);
|
|
711
711
|
});
|
|
712
712
|
}
|
|
@@ -718,7 +718,7 @@ const I = (e) => {
|
|
|
718
718
|
), _ = P(
|
|
719
719
|
B(
|
|
720
720
|
async (e) => {
|
|
721
|
-
const r =
|
|
721
|
+
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
722
|
return (await fetch(o, { headers: M }).then((t) => t.json())).data;
|
|
723
723
|
}
|
|
724
724
|
)
|
|
@@ -782,7 +782,7 @@ async function nt(e, r, o) {
|
|
|
782
782
|
...o,
|
|
783
783
|
accountCap: t
|
|
784
784
|
});
|
|
785
|
-
const a = await
|
|
785
|
+
const a = await j(o?.market || U), s = await Be(e, t, o);
|
|
786
786
|
return e.moveCall({
|
|
787
787
|
target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
788
788
|
arguments: [
|
|
@@ -799,7 +799,7 @@ const ee = P(
|
|
|
799
799
|
const o = await _({
|
|
800
800
|
cacheTime: w,
|
|
801
801
|
...r
|
|
802
|
-
}), n = new
|
|
802
|
+
}), n = new F(), t = r?.client ?? S;
|
|
803
803
|
n.moveCall({
|
|
804
804
|
target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
805
805
|
arguments: [n.object(o.emode.contract.registryObject), n.pure.address(e)]
|
|
@@ -817,7 +817,7 @@ const ee = P(
|
|
|
817
817
|
)
|
|
818
818
|
);
|
|
819
819
|
function at(e) {
|
|
820
|
-
return `${
|
|
820
|
+
return `${j(e.marketId).key}-${e.emodeId}`;
|
|
821
821
|
}
|
|
822
822
|
function it(e, r, o) {
|
|
823
823
|
const n = typeof o?.balance == "number", t = n ? o.balance : 0;
|
|
@@ -863,7 +863,7 @@ async function Pe(e, r, o) {
|
|
|
863
863
|
return te(e, r, 0, 0, 0, !1, o);
|
|
864
864
|
}
|
|
865
865
|
async function oe(e, r, o) {
|
|
866
|
-
const n = new
|
|
866
|
+
const n = new F(), t = o?.client ?? S, a = await q({
|
|
867
867
|
...o,
|
|
868
868
|
markets: Object.values(E)
|
|
869
869
|
}), s = G(a);
|
|
@@ -883,7 +883,7 @@ async function oe(e, r, o) {
|
|
|
883
883
|
sender: e
|
|
884
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 = r[y], g =
|
|
886
|
+
const v = r[y], g = j(v.market);
|
|
887
887
|
d.forEach((u) => {
|
|
888
888
|
if (u.supply_balance === "0" && u.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
|
|
889
889
|
return;
|
|
@@ -893,13 +893,13 @@ async function oe(e, r, o) {
|
|
|
893
893
|
const k = J(
|
|
894
894
|
u.supply_balance,
|
|
895
895
|
f.currentSupplyIndex
|
|
896
|
-
).toString(),
|
|
896
|
+
).toString(), I = J(
|
|
897
897
|
u.borrow_balance,
|
|
898
898
|
f.currentBorrowIndex
|
|
899
899
|
).toString();
|
|
900
900
|
l.push({
|
|
901
901
|
supplyBalance: k,
|
|
902
|
-
borrowBalance:
|
|
902
|
+
borrowBalance: I,
|
|
903
903
|
assetId: u.asset_id,
|
|
904
904
|
market: g.key,
|
|
905
905
|
pool: f,
|
|
@@ -910,7 +910,7 @@ async function oe(e, r, o) {
|
|
|
910
910
|
}
|
|
911
911
|
const ct = P(
|
|
912
912
|
async (e, r) => {
|
|
913
|
-
const n = (r?.markets || Object.keys(E)).map((t) =>
|
|
913
|
+
const n = (r?.markets || Object.keys(E)).map((t) => j(t)).map((t) => ({
|
|
914
914
|
address: e,
|
|
915
915
|
market: t.key
|
|
916
916
|
}));
|
|
@@ -918,7 +918,7 @@ const ct = P(
|
|
|
918
918
|
}
|
|
919
919
|
);
|
|
920
920
|
async function st(e, r) {
|
|
921
|
-
const o = r?.client ?? S, n = new
|
|
921
|
+
const o = r?.client ?? S, n = new F();
|
|
922
922
|
await Pe(n, e, r);
|
|
923
923
|
const t = await o.devInspectTransactionBlock({
|
|
924
924
|
transactionBlock: n,
|
|
@@ -927,7 +927,7 @@ async function st(e, r) {
|
|
|
927
927
|
return x(Number(a[0]) || 0);
|
|
928
928
|
}
|
|
929
929
|
async function lt(e, r, o, n) {
|
|
930
|
-
const t = n?.client ?? S, a = new
|
|
930
|
+
const t = n?.client ?? S, a = new F();
|
|
931
931
|
let s = 0, i = 0;
|
|
932
932
|
const c = await A(r, n);
|
|
933
933
|
if (o.forEach((v) => {
|
|
@@ -980,7 +980,7 @@ async function pt(e, r) {
|
|
|
980
980
|
}
|
|
981
981
|
const $e = P(
|
|
982
982
|
async (e, r) => {
|
|
983
|
-
const o = [], n = (r?.markets || Object.keys(E)).map((i) =>
|
|
983
|
+
const o = [], n = (r?.markets || Object.keys(E)).map((i) => j(i));
|
|
984
984
|
let t = [];
|
|
985
985
|
try {
|
|
986
986
|
t = await ee(e, r);
|
|
@@ -993,13 +993,13 @@ const $e = P(
|
|
|
993
993
|
})).concat(
|
|
994
994
|
t.filter((i) => !!n.find((c) => c.id === i.marketId)).map((i) => ({
|
|
995
995
|
address: i.accountCap,
|
|
996
|
-
market:
|
|
996
|
+
market: j(i.marketId).key,
|
|
997
997
|
emodeId: i.emodeId
|
|
998
998
|
}))
|
|
999
999
|
);
|
|
1000
1000
|
return (await oe(e, a, r)).forEach((i) => {
|
|
1001
1001
|
const c = typeof i.emodeId == "number" ? t.find((l) => {
|
|
1002
|
-
const d =
|
|
1002
|
+
const d = j(i.market);
|
|
1003
1003
|
return l.emodeId === i.emodeId && l.marketId === d.id;
|
|
1004
1004
|
}) : void 0;
|
|
1005
1005
|
if (c) {
|
|
@@ -1086,7 +1086,7 @@ const $e = P(
|
|
|
1086
1086
|
}), o;
|
|
1087
1087
|
}
|
|
1088
1088
|
);
|
|
1089
|
-
class
|
|
1089
|
+
class N {
|
|
1090
1090
|
constructor(r, o) {
|
|
1091
1091
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1092
1092
|
hf: 1 / 0,
|
|
@@ -1126,7 +1126,7 @@ class O {
|
|
|
1126
1126
|
}
|
|
1127
1127
|
filterPositionsByPool(r) {
|
|
1128
1128
|
const n = !!r.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1129
|
-
return new
|
|
1129
|
+
return new N(
|
|
1130
1130
|
this.positions.filter((t) => {
|
|
1131
1131
|
const a = t[t.type];
|
|
1132
1132
|
return n.includes(t.type) && a.pool.uniqueId === r.uniqueId;
|
|
@@ -1162,7 +1162,7 @@ class O {
|
|
|
1162
1162
|
token: r.token,
|
|
1163
1163
|
pool: r
|
|
1164
1164
|
}
|
|
1165
|
-
}, new
|
|
1165
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1166
1166
|
}
|
|
1167
1167
|
withdraw(r, o) {
|
|
1168
1168
|
const n = !!r.isEMode, t = this.getPrice(r);
|
|
@@ -1192,7 +1192,7 @@ class O {
|
|
|
1192
1192
|
token: r.token,
|
|
1193
1193
|
pool: r
|
|
1194
1194
|
}
|
|
1195
|
-
}, new
|
|
1195
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1196
1196
|
}
|
|
1197
1197
|
borrow(r, o) {
|
|
1198
1198
|
const n = !!r.isEMode, t = this.getPrice(r);
|
|
@@ -1222,7 +1222,7 @@ class O {
|
|
|
1222
1222
|
token: r.token,
|
|
1223
1223
|
pool: r
|
|
1224
1224
|
}
|
|
1225
|
-
}, new
|
|
1225
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1226
1226
|
}
|
|
1227
1227
|
repay(r, o) {
|
|
1228
1228
|
const n = !!r.isEMode, t = this.getPrice(r);
|
|
@@ -1252,7 +1252,7 @@ class O {
|
|
|
1252
1252
|
token: r.token,
|
|
1253
1253
|
pool: r
|
|
1254
1254
|
}
|
|
1255
|
-
}, new
|
|
1255
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1256
1256
|
}
|
|
1257
1257
|
resolveValueUSD(r) {
|
|
1258
1258
|
return Object.keys(this._priceMap).length > 0 ? p(r.amount).multipliedBy(this.getPrice(r.pool)).toString() : r.valueUSD;
|
|
@@ -1680,7 +1680,7 @@ async function vt(e, r, o, n, t, a) {
|
|
|
1680
1680
|
}
|
|
1681
1681
|
}
|
|
1682
1682
|
async function Ue(e, r, o) {
|
|
1683
|
-
const n = o?.client ?? S, t = new
|
|
1683
|
+
const n = o?.client ?? S, t = new F(), a = await q({
|
|
1684
1684
|
...o,
|
|
1685
1685
|
markets: Object.values(E),
|
|
1686
1686
|
cacheTime: w
|
|
@@ -1737,9 +1737,9 @@ async function Ue(e, r, o) {
|
|
|
1737
1737
|
const g = d[0].length;
|
|
1738
1738
|
for (let u = 0; u < g; u++) {
|
|
1739
1739
|
const f = s.find(
|
|
1740
|
-
(
|
|
1740
|
+
(I) => b(I.coinType) === b(d[1][u])
|
|
1741
1741
|
), k = a.find(
|
|
1742
|
-
(
|
|
1742
|
+
(I) => b(I.coinType) === b(d[0][u]) && I.market === v.market
|
|
1743
1743
|
);
|
|
1744
1744
|
!f || !k || l.push({
|
|
1745
1745
|
assetId: k.id,
|
|
@@ -1758,7 +1758,7 @@ async function Ue(e, r, o) {
|
|
|
1758
1758
|
}), l;
|
|
1759
1759
|
}
|
|
1760
1760
|
async function wt(e, r) {
|
|
1761
|
-
const o = (r?.markets || [E.main]).map((a) =>
|
|
1761
|
+
const o = (r?.markets || [E.main]).map((a) => j(a));
|
|
1762
1762
|
let n = [];
|
|
1763
1763
|
try {
|
|
1764
1764
|
n = await ee(e, r);
|
|
@@ -1771,7 +1771,7 @@ async function wt(e, r) {
|
|
|
1771
1771
|
market: a.key
|
|
1772
1772
|
})).concat(
|
|
1773
1773
|
n.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
|
|
1774
|
-
const s =
|
|
1774
|
+
const s = j(a.marketId);
|
|
1775
1775
|
return {
|
|
1776
1776
|
address: a.accountCap,
|
|
1777
1777
|
owner: e,
|
|
@@ -1831,7 +1831,7 @@ async function Ct(e, r, o) {
|
|
|
1831
1831
|
cacheTime: w
|
|
1832
1832
|
}), t = /* @__PURE__ */ new Map();
|
|
1833
1833
|
for (const s of r) {
|
|
1834
|
-
const { rewardCoinType: i, ruleIds: c, market: l, owner: d, address: y, emodeId: v } = s, g = `${i}___${y}`;
|
|
1834
|
+
const { rewardCoinType: i, ruleIds: c, market: l, owner: d, address: y, emodeId: v } = s, g = `${i}___${y}__${l}`;
|
|
1835
1835
|
for (const u of c) {
|
|
1836
1836
|
t.has(g) || t.set(g, {
|
|
1837
1837
|
assetIds: [],
|
|
@@ -1857,10 +1857,9 @@ async function Ct(e, r, o) {
|
|
|
1857
1857
|
market: d
|
|
1858
1858
|
}), f = s.split("___")[0], k = n.filter(($) => b($.suiCoinType) === b(f));
|
|
1859
1859
|
k.sort(($, D) => $.market === d ? -1 : 1);
|
|
1860
|
-
const
|
|
1861
|
-
if (!
|
|
1860
|
+
const I = k[0], O = u.rewardFunds[b(f)];
|
|
1861
|
+
if (!O)
|
|
1862
1862
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${d}`);
|
|
1863
|
-
const F = j.contract.rewardFundId;
|
|
1864
1863
|
if (o?.accountCap && !o.customCoinReceive)
|
|
1865
1864
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
1866
1865
|
if (o?.customCoinReceive) {
|
|
@@ -1874,7 +1873,7 @@ async function Ct(e, r, o) {
|
|
|
1874
1873
|
// Incentive V3 contract
|
|
1875
1874
|
e.object(u.storage),
|
|
1876
1875
|
// Protocol storage
|
|
1877
|
-
e.object(
|
|
1876
|
+
e.object(O),
|
|
1878
1877
|
// Reward fund
|
|
1879
1878
|
e.pure.vector("string", i),
|
|
1880
1879
|
// Asset IDs
|
|
@@ -1893,7 +1892,7 @@ async function Ct(e, r, o) {
|
|
|
1893
1892
|
// Incentive V3 contract
|
|
1894
1893
|
e.object(u.storage),
|
|
1895
1894
|
// Protocol storage
|
|
1896
|
-
e.object(
|
|
1895
|
+
e.object(O),
|
|
1897
1896
|
// Reward fund
|
|
1898
1897
|
e.pure.vector("string", i),
|
|
1899
1898
|
// Asset IDs
|
|
@@ -1912,7 +1911,7 @@ async function Ct(e, r, o) {
|
|
|
1912
1911
|
// Incentive V3 contract
|
|
1913
1912
|
e.object(u.storage),
|
|
1914
1913
|
// Protocol storage
|
|
1915
|
-
e.object(
|
|
1914
|
+
e.object(O),
|
|
1916
1915
|
// Reward fund
|
|
1917
1916
|
e.pure.vector("string", i),
|
|
1918
1917
|
// Asset IDs
|
|
@@ -1935,18 +1934,18 @@ async function Ct(e, r, o) {
|
|
|
1935
1934
|
);
|
|
1936
1935
|
}
|
|
1937
1936
|
if (o?.customCoinReceive.type === "depositNAVI") {
|
|
1938
|
-
const ae = p(
|
|
1937
|
+
const ae = p(I.totalSupplyAmount).shiftedBy(-9), ie = p(I.supplyCapCeiling).shiftedBy(-27);
|
|
1939
1938
|
ae.plus(l).isGreaterThan(ie) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
1940
1939
|
[D],
|
|
1941
1940
|
e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1942
|
-
) : await Ce(e,
|
|
1941
|
+
) : await Ce(e, I, D, {
|
|
1943
1942
|
...o,
|
|
1944
|
-
market:
|
|
1943
|
+
market: I.market
|
|
1945
1944
|
});
|
|
1946
1945
|
} else
|
|
1947
1946
|
a.push({
|
|
1948
1947
|
coin: D,
|
|
1949
|
-
identifier:
|
|
1948
|
+
identifier: I,
|
|
1950
1949
|
owner: y,
|
|
1951
1950
|
isEMode: g
|
|
1952
1951
|
});
|
|
@@ -1960,7 +1959,7 @@ async function Ct(e, r, o) {
|
|
|
1960
1959
|
// Incentive V3 contract
|
|
1961
1960
|
e.object(u.storage),
|
|
1962
1961
|
// Protocol storage
|
|
1963
|
-
e.object(
|
|
1962
|
+
e.object(O),
|
|
1964
1963
|
// Reward fund
|
|
1965
1964
|
e.pure.vector("string", i),
|
|
1966
1965
|
// Asset IDs
|
|
@@ -1989,7 +1988,7 @@ async function Ct(e, r, o) {
|
|
|
1989
1988
|
// Incentive V3 contract
|
|
1990
1989
|
e.object(u.storage),
|
|
1991
1990
|
// Protocol storage
|
|
1992
|
-
e.object(
|
|
1991
|
+
e.object(O),
|
|
1993
1992
|
// Reward fund
|
|
1994
1993
|
e.pure.vector("string", i),
|
|
1995
1994
|
// Asset IDs
|
|
@@ -2014,7 +2013,7 @@ export {
|
|
|
2014
2013
|
Ke as OracleInfo,
|
|
2015
2014
|
R as PoolOperator,
|
|
2016
2015
|
Je as ReserveDataInfo,
|
|
2017
|
-
|
|
2016
|
+
N as UserPositions,
|
|
2018
2017
|
ye as UserStateInfo,
|
|
2019
2018
|
xe as borrowCoinPTB,
|
|
2020
2019
|
Ct as claimLendingRewardsPTB,
|
|
@@ -2038,7 +2037,7 @@ export {
|
|
|
2038
2037
|
$e as getLendingPositions,
|
|
2039
2038
|
ct as getLendingState,
|
|
2040
2039
|
ot as getMarket,
|
|
2041
|
-
|
|
2040
|
+
j as getMarketConfig,
|
|
2042
2041
|
Ie as getMarkets,
|
|
2043
2042
|
A as getPool,
|
|
2044
2043
|
q as getPools,
|