@naviprotocol/lending 1.4.3 → 1.4.4-beta.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.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +131 -126
- package/dist/index.esm.js.map +1 -1
- package/dist/market.d.ts +9 -0
- package/dist/market.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Transaction as N } from "@mysten/sui/transactions";
|
|
2
2
|
import { bcs as m, toHex as ie, fromHex as ce } from "@mysten/bcs";
|
|
3
|
-
import { SuiClient as se, getFullnodeUrl as
|
|
4
|
-
import
|
|
3
|
+
import { SuiClient as se, getFullnodeUrl as ue } from "@mysten/sui/client";
|
|
4
|
+
import le from "lodash.camelcase";
|
|
5
5
|
import { normalizeStructTag as pe } from "@mysten/sui/utils";
|
|
6
6
|
import { SuiPriceServiceConnection as Z, SuiPythClient as de } from "@pythnetwork/pyth-sui-js";
|
|
7
7
|
import p from "bignumber.js";
|
|
@@ -129,7 +129,7 @@ const z = m.bytes(32).transform({
|
|
|
129
129
|
borrow_balance: m.u256(),
|
|
130
130
|
/** User's current supply balance */
|
|
131
131
|
supply_balance: m.u256()
|
|
132
|
-
}), ye = "1.4.
|
|
132
|
+
}), ye = "1.4.4-beta.2", S = {
|
|
133
133
|
version: ye
|
|
134
134
|
}, ge = S.version, he = () => {
|
|
135
135
|
if (typeof process < "u" && process.versions && process.versions.node)
|
|
@@ -144,7 +144,7 @@ const z = m.bytes(32).transform({
|
|
|
144
144
|
let e = "";
|
|
145
145
|
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${ge} (${he()})`), e;
|
|
146
146
|
}, K = ve(), $ = new se({
|
|
147
|
-
url:
|
|
147
|
+
url: ue("mainnet")
|
|
148
148
|
});
|
|
149
149
|
function Q(e) {
|
|
150
150
|
const n = [];
|
|
@@ -180,7 +180,7 @@ function W(e) {
|
|
|
180
180
|
return Array.isArray(e) ? e.map((n) => W(n)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
|
|
181
181
|
(n, o) => ({
|
|
182
182
|
...n,
|
|
183
|
-
[
|
|
183
|
+
[le(o)]: W(e[o])
|
|
184
184
|
}),
|
|
185
185
|
{}
|
|
186
186
|
) : e;
|
|
@@ -265,11 +265,11 @@ const R = P(
|
|
|
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 = c;
|
|
268
|
-
const i = p(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), s = p(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(),
|
|
268
|
+
const i = p(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), s = p(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), u = p(i).multipliedBy(t.oracle.price).toString(), d = p(s).multipliedBy(t.oracle.price).toString(), y = p(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), v = p.max(
|
|
269
269
|
p(t.borrowedAmount),
|
|
270
270
|
p(t.validBorrowAmount)
|
|
271
|
-
).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), g = p(y).multipliedBy(t.oracle.price).toString(),
|
|
272
|
-
t.poolSupplyAmount = i, t.poolBorrowAmount = s, t.poolSupplyValue =
|
|
271
|
+
).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), g = p(y).multipliedBy(t.oracle.price).toString(), l = p(v).multipliedBy(t.oracle.price).toString();
|
|
272
|
+
t.poolSupplyAmount = i, t.poolBorrowAmount = s, t.poolSupplyValue = u, t.poolBorrowValue = d, t.poolSupplyCapAmount = y, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = g, t.poolBorrowCapValue = l;
|
|
273
273
|
}), r.data;
|
|
274
274
|
}
|
|
275
275
|
)
|
|
@@ -362,7 +362,7 @@ async function Qe(e, n, o, r) {
|
|
|
362
362
|
let i;
|
|
363
363
|
if (t.version === 1)
|
|
364
364
|
if (r?.accountCap) {
|
|
365
|
-
const [
|
|
365
|
+
const [u] = e.moveCall({
|
|
366
366
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
|
|
367
367
|
arguments: [
|
|
368
368
|
e.object("0x06"),
|
|
@@ -377,9 +377,9 @@ async function Qe(e, n, o, r) {
|
|
|
377
377
|
],
|
|
378
378
|
typeArguments: [a.suiCoinType]
|
|
379
379
|
});
|
|
380
|
-
i =
|
|
380
|
+
i = u;
|
|
381
381
|
} else {
|
|
382
|
-
const [
|
|
382
|
+
const [u] = e.moveCall({
|
|
383
383
|
target: `${t.package}::incentive_v3::withdraw`,
|
|
384
384
|
arguments: [
|
|
385
385
|
e.object("0x06"),
|
|
@@ -393,10 +393,10 @@ async function Qe(e, n, o, r) {
|
|
|
393
393
|
],
|
|
394
394
|
typeArguments: [a.suiCoinType]
|
|
395
395
|
});
|
|
396
|
-
i =
|
|
396
|
+
i = u;
|
|
397
397
|
}
|
|
398
398
|
else if (r?.accountCap) {
|
|
399
|
-
const [
|
|
399
|
+
const [u] = e.moveCall({
|
|
400
400
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
401
401
|
arguments: [
|
|
402
402
|
e.object("0x06"),
|
|
@@ -412,9 +412,9 @@ async function Qe(e, n, o, r) {
|
|
|
412
412
|
],
|
|
413
413
|
typeArguments: [a.suiCoinType]
|
|
414
414
|
});
|
|
415
|
-
i =
|
|
415
|
+
i = u;
|
|
416
416
|
} else {
|
|
417
|
-
const [
|
|
417
|
+
const [u] = e.moveCall({
|
|
418
418
|
target: `${t.package}::incentive_v3::withdraw_v2`,
|
|
419
419
|
arguments: [
|
|
420
420
|
e.object("0x06"),
|
|
@@ -429,7 +429,7 @@ async function Qe(e, n, o, r) {
|
|
|
429
429
|
],
|
|
430
430
|
typeArguments: [a.suiCoinType]
|
|
431
431
|
});
|
|
432
|
-
i =
|
|
432
|
+
i = u;
|
|
433
433
|
}
|
|
434
434
|
return e.moveCall({
|
|
435
435
|
target: "0x2::coin::from_balance",
|
|
@@ -448,7 +448,7 @@ async function Xe(e, n, o, r) {
|
|
|
448
448
|
let i;
|
|
449
449
|
if (t.version === 1)
|
|
450
450
|
if (r?.accountCap) {
|
|
451
|
-
const [
|
|
451
|
+
const [u] = e.moveCall({
|
|
452
452
|
target: `${t.package}::incentive_v3::borrow_with_account_cap`,
|
|
453
453
|
arguments: [
|
|
454
454
|
e.object("0x06"),
|
|
@@ -463,9 +463,9 @@ async function Xe(e, n, o, r) {
|
|
|
463
463
|
],
|
|
464
464
|
typeArguments: [a.suiCoinType]
|
|
465
465
|
});
|
|
466
|
-
i =
|
|
466
|
+
i = u;
|
|
467
467
|
} else {
|
|
468
|
-
const [
|
|
468
|
+
const [u] = e.moveCall({
|
|
469
469
|
target: `${t.package}::incentive_v3::borrow`,
|
|
470
470
|
arguments: [
|
|
471
471
|
e.object("0x06"),
|
|
@@ -479,10 +479,10 @@ async function Xe(e, n, o, r) {
|
|
|
479
479
|
],
|
|
480
480
|
typeArguments: [a.suiCoinType]
|
|
481
481
|
});
|
|
482
|
-
i =
|
|
482
|
+
i = u;
|
|
483
483
|
}
|
|
484
484
|
else if (r?.accountCap) {
|
|
485
|
-
const [
|
|
485
|
+
const [u] = e.moveCall({
|
|
486
486
|
target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
487
487
|
arguments: [
|
|
488
488
|
e.object("0x06"),
|
|
@@ -498,9 +498,9 @@ async function Xe(e, n, o, r) {
|
|
|
498
498
|
],
|
|
499
499
|
typeArguments: [a.suiCoinType]
|
|
500
500
|
});
|
|
501
|
-
i =
|
|
501
|
+
i = u;
|
|
502
502
|
} else {
|
|
503
|
-
const [
|
|
503
|
+
const [u] = e.moveCall({
|
|
504
504
|
target: `${t.package}::incentive_v3::borrow_v2`,
|
|
505
505
|
arguments: [
|
|
506
506
|
e.object("0x06"),
|
|
@@ -515,7 +515,7 @@ async function Xe(e, n, o, r) {
|
|
|
515
515
|
],
|
|
516
516
|
typeArguments: [a.suiCoinType]
|
|
517
517
|
});
|
|
518
|
-
i =
|
|
518
|
+
i = u;
|
|
519
519
|
}
|
|
520
520
|
return e.moveCall({
|
|
521
521
|
target: "0x2::coin::from_balance",
|
|
@@ -620,6 +620,11 @@ const et = P(
|
|
|
620
620
|
id: 1,
|
|
621
621
|
key: "ember",
|
|
622
622
|
name: "Ember Market"
|
|
623
|
+
},
|
|
624
|
+
"sui-eco": {
|
|
625
|
+
id: 2,
|
|
626
|
+
key: "sui-eco",
|
|
627
|
+
name: "Sui Eco Market"
|
|
623
628
|
}
|
|
624
629
|
};
|
|
625
630
|
class Ce {
|
|
@@ -648,8 +653,8 @@ class Ce {
|
|
|
648
653
|
});
|
|
649
654
|
}), i = i.plus(s.poolBorrowValue), c = c.plus(s.poolSupplyValue);
|
|
650
655
|
}), this.poolMap = H(this.pools, "id"), this.emodeMap = J(this.emodes, "emodeId"), this.emodes.forEach((s) => {
|
|
651
|
-
const
|
|
652
|
-
this.emodePools.push(...
|
|
656
|
+
const u = this.getEModePools(s.emodeId);
|
|
657
|
+
this.emodePools.push(...u);
|
|
653
658
|
}), this._overview = {
|
|
654
659
|
marketTotalSupplyValue: c.toString(),
|
|
655
660
|
marketTotalBorrowValue: i.toString()
|
|
@@ -800,11 +805,11 @@ const x = P(
|
|
|
800
805
|
const c = (await t.devInspectTransactionBlock({
|
|
801
806
|
transactionBlock: r,
|
|
802
807
|
sender: e
|
|
803
|
-
})).results[0].returnValues, i = C.vector(C.u64()).parse(Uint8Array.from(c[0][0])), s = C.vector(C.u64()).parse(Uint8Array.from(c[1][0])),
|
|
808
|
+
})).results[0].returnValues, i = C.vector(C.u64()).parse(Uint8Array.from(c[0][0])), s = C.vector(C.u64()).parse(Uint8Array.from(c[1][0])), u = C.vector(C.Address).parse(Uint8Array.from(c[2][0]));
|
|
804
809
|
return i.map((d, y) => ({
|
|
805
810
|
marketId: Number(d),
|
|
806
811
|
emodeId: Number(s[y]),
|
|
807
|
-
accountCap:
|
|
812
|
+
accountCap: u[y].toString()
|
|
808
813
|
}));
|
|
809
814
|
}
|
|
810
815
|
)
|
|
@@ -817,7 +822,7 @@ function at(e, n, o) {
|
|
|
817
822
|
let a = 0;
|
|
818
823
|
const c = [];
|
|
819
824
|
let i = "";
|
|
820
|
-
if (n.sort((s,
|
|
825
|
+
if (n.sort((s, u) => Number(u.balance) - Number(s.balance)).forEach((s) => {
|
|
821
826
|
if (!(r && a >= t) && Number(s.balance) !== 0) {
|
|
822
827
|
if (i || (i = s.coinType), i !== s.coinType)
|
|
823
828
|
throw new Error("All coins must be of the same type");
|
|
@@ -874,32 +879,32 @@ async function te(e, n, o) {
|
|
|
874
879
|
const s = ((await t.devInspectTransactionBlock({
|
|
875
880
|
transactionBlock: r,
|
|
876
881
|
sender: e
|
|
877
|
-
})).results || []).map((d) => d.returnValues?.map((y) => C.vector(fe).parse(Uint8Array.from(y[0])))[0] || []),
|
|
882
|
+
})).results || []).map((d) => d.returnValues?.map((y) => C.vector(fe).parse(Uint8Array.from(y[0])))[0] || []), u = [];
|
|
878
883
|
return s.forEach((d, y) => {
|
|
879
884
|
const v = n[y], g = j(v.market);
|
|
880
|
-
d.forEach((
|
|
881
|
-
if (
|
|
885
|
+
d.forEach((l) => {
|
|
886
|
+
if (l.supply_balance === "0" && l.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
|
|
882
887
|
return;
|
|
883
|
-
const f = c[`${g.key}-${
|
|
888
|
+
const f = c[`${g.key}-${l.asset_id}`];
|
|
884
889
|
if (!f)
|
|
885
890
|
return;
|
|
886
891
|
const w = Y(
|
|
887
|
-
|
|
892
|
+
l.supply_balance,
|
|
888
893
|
f.currentSupplyIndex
|
|
889
894
|
).toString(), I = Y(
|
|
890
|
-
|
|
895
|
+
l.borrow_balance,
|
|
891
896
|
f.currentBorrowIndex
|
|
892
897
|
).toString();
|
|
893
|
-
|
|
898
|
+
u.push({
|
|
894
899
|
supplyBalance: w,
|
|
895
900
|
borrowBalance: I,
|
|
896
|
-
assetId:
|
|
901
|
+
assetId: l.asset_id,
|
|
897
902
|
market: g.key,
|
|
898
903
|
pool: f,
|
|
899
904
|
emodeId: v.emodeId
|
|
900
905
|
});
|
|
901
906
|
});
|
|
902
|
-
}),
|
|
907
|
+
}), u;
|
|
903
908
|
}
|
|
904
909
|
const it = P(
|
|
905
910
|
async (e, n) => {
|
|
@@ -927,14 +932,14 @@ async function st(e, n, o, r) {
|
|
|
927
932
|
v.type === F.Supply ? c += v.amount : v.type === F.Withdraw ? c -= v.amount : v.type === F.Borrow ? i += v.amount : v.type === F.Repay && (i -= v.amount);
|
|
928
933
|
}), c * i < 0)
|
|
929
934
|
throw new Error("Invalid operations");
|
|
930
|
-
const
|
|
935
|
+
const u = c > 0 || i > 0;
|
|
931
936
|
await ee(
|
|
932
937
|
a,
|
|
933
938
|
e,
|
|
934
939
|
s,
|
|
935
940
|
Math.abs(c),
|
|
936
941
|
Math.abs(i),
|
|
937
|
-
|
|
942
|
+
u,
|
|
938
943
|
r
|
|
939
944
|
);
|
|
940
945
|
const d = await t.devInspectTransactionBlock({
|
|
@@ -943,7 +948,7 @@ async function st(e, n, o, r) {
|
|
|
943
948
|
}), y = L(d, [C.u256()]);
|
|
944
949
|
return X(Number(y[0]) || 0);
|
|
945
950
|
}
|
|
946
|
-
const
|
|
951
|
+
const ut = B(
|
|
947
952
|
async (e, n) => {
|
|
948
953
|
const o = new URLSearchParams();
|
|
949
954
|
n?.cursor && o.set("cursor", n.cursor), o.set("userAddress", e);
|
|
@@ -951,7 +956,7 @@ const lt = B(
|
|
|
951
956
|
return (await fetch(r, { headers: M }).then((a) => a.json())).data;
|
|
952
957
|
}
|
|
953
958
|
);
|
|
954
|
-
async function
|
|
959
|
+
async function lt(e, n) {
|
|
955
960
|
let o = null;
|
|
956
961
|
const r = [], t = n?.client ?? $;
|
|
957
962
|
do {
|
|
@@ -991,9 +996,9 @@ const Pe = P(
|
|
|
991
996
|
}))
|
|
992
997
|
);
|
|
993
998
|
return (await te(e, a, n)).forEach((i) => {
|
|
994
|
-
const s = typeof i.emodeId == "number" ? t.find((
|
|
999
|
+
const s = typeof i.emodeId == "number" ? t.find((u) => {
|
|
995
1000
|
const d = j(i.market);
|
|
996
|
-
return
|
|
1001
|
+
return u.emodeId === i.emodeId && u.marketId === d.id;
|
|
997
1002
|
}) : void 0;
|
|
998
1003
|
if (s) {
|
|
999
1004
|
if (!i.pool.emodes.find((d) => d.emodeId === s.emodeId))
|
|
@@ -1044,7 +1049,7 @@ const Pe = P(
|
|
|
1044
1049
|
}
|
|
1045
1050
|
} else {
|
|
1046
1051
|
if (p(i.supplyBalance).gt(0)) {
|
|
1047
|
-
const
|
|
1052
|
+
const u = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1048
1053
|
o.push({
|
|
1049
1054
|
id: `${i.pool.uniqueId}_navi-lending-supply-${T()}`,
|
|
1050
1055
|
wallet: e,
|
|
@@ -1052,15 +1057,15 @@ const Pe = P(
|
|
|
1052
1057
|
type: "navi-lending-supply",
|
|
1053
1058
|
market: i.market,
|
|
1054
1059
|
"navi-lending-supply": {
|
|
1055
|
-
amount:
|
|
1060
|
+
amount: u.toString(),
|
|
1056
1061
|
pool: i.pool,
|
|
1057
1062
|
token: i.pool.token,
|
|
1058
|
-
valueUSD:
|
|
1063
|
+
valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
|
|
1059
1064
|
}
|
|
1060
1065
|
});
|
|
1061
1066
|
}
|
|
1062
1067
|
if (p(i.borrowBalance).gt(0)) {
|
|
1063
|
-
const
|
|
1068
|
+
const u = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1064
1069
|
o.push({
|
|
1065
1070
|
id: `${i.pool.uniqueId}_navi-lending-borrow-${T()}`,
|
|
1066
1071
|
wallet: e,
|
|
@@ -1068,10 +1073,10 @@ const Pe = P(
|
|
|
1068
1073
|
market: i.market,
|
|
1069
1074
|
type: "navi-lending-borrow",
|
|
1070
1075
|
"navi-lending-borrow": {
|
|
1071
|
-
amount:
|
|
1076
|
+
amount: u.toString(),
|
|
1072
1077
|
pool: i.pool,
|
|
1073
1078
|
token: i.pool.token,
|
|
1074
|
-
valueUSD:
|
|
1079
|
+
valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
|
|
1075
1080
|
}
|
|
1076
1081
|
});
|
|
1077
1082
|
}
|
|
@@ -1252,52 +1257,52 @@ class O {
|
|
|
1252
1257
|
}
|
|
1253
1258
|
getPositionsOverview(n) {
|
|
1254
1259
|
const o = {}, r = {};
|
|
1255
|
-
let t = new p(0), a = new p(0), c = new p(0), i = new p(0), s = new p(0),
|
|
1260
|
+
let t = new p(0), a = new p(0), c = new p(0), i = new p(0), s = new p(0), u = new p(0);
|
|
1256
1261
|
n.forEach((g) => {
|
|
1257
1262
|
if (g.type === "navi-lending-supply") {
|
|
1258
|
-
const
|
|
1263
|
+
const l = g["navi-lending-supply"], f = this.resolveValueUSD(l);
|
|
1259
1264
|
t = t.plus(f), s = s.plus(
|
|
1260
|
-
new p(f).multipliedBy(
|
|
1261
|
-
),
|
|
1262
|
-
new p(f).multipliedBy(
|
|
1265
|
+
new p(f).multipliedBy(l.pool.liquidationFactor.threshold)
|
|
1266
|
+
), u = u.plus(
|
|
1267
|
+
new p(f).multipliedBy(l.pool.ltvValue)
|
|
1263
1268
|
);
|
|
1264
1269
|
} else if (g.type === "navi-lending-borrow") {
|
|
1265
|
-
const
|
|
1266
|
-
a = a.plus(this.resolveValueUSD(
|
|
1270
|
+
const l = g["navi-lending-borrow"];
|
|
1271
|
+
a = a.plus(this.resolveValueUSD(l));
|
|
1267
1272
|
} else if (g.type === "navi-lending-emode-supply") {
|
|
1268
|
-
const
|
|
1273
|
+
const l = g["navi-lending-emode-supply"], f = this.resolveValueUSD(l);
|
|
1269
1274
|
t = t.plus(f);
|
|
1270
|
-
const w =
|
|
1275
|
+
const w = l.pool.emode;
|
|
1271
1276
|
s = s.plus(
|
|
1272
1277
|
new p(f).multipliedBy(w.lt)
|
|
1273
|
-
),
|
|
1278
|
+
), u = u.plus(
|
|
1274
1279
|
new p(f).multipliedBy(w.ltv)
|
|
1275
1280
|
);
|
|
1276
1281
|
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1277
|
-
const
|
|
1278
|
-
a = a.plus(this.resolveValueUSD(
|
|
1282
|
+
const l = g["navi-lending-emode-borrow"];
|
|
1283
|
+
a = a.plus(this.resolveValueUSD(l));
|
|
1279
1284
|
}
|
|
1280
|
-
}), a = p.max(a, 0), t = p.max(t, 0), s = p.max(s, 0),
|
|
1285
|
+
}), a = p.max(a, 0), t = p.max(t, 0), s = p.max(s, 0), u = p.max(u, 0), n.forEach((g) => {
|
|
1281
1286
|
if (g.type === "navi-lending-supply") {
|
|
1282
|
-
const
|
|
1287
|
+
const l = g["navi-lending-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
|
|
1283
1288
|
t.gt(0) && (c = c.plus(
|
|
1284
1289
|
new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
|
|
1285
|
-
)), o[
|
|
1290
|
+
)), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1286
1291
|
} else if (g.type === "navi-lending-borrow") {
|
|
1287
|
-
const
|
|
1292
|
+
const l = g["navi-lending-borrow"], f = this.resolveValueUSD(l), w = l.pool.borrowIncentiveApyInfo.apy;
|
|
1288
1293
|
a.gt(0) && (i = i.plus(
|
|
1289
1294
|
new p(f).dividedBy(a).multipliedBy(new p(w).dividedBy(100))
|
|
1290
|
-
)), r[
|
|
1295
|
+
)), r[l.pool.suiCoinType] = p(r[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1291
1296
|
} else if (g.type === "navi-lending-emode-supply") {
|
|
1292
|
-
const
|
|
1297
|
+
const l = g["navi-lending-emode-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
|
|
1293
1298
|
t.gt(0) && (c = c.plus(
|
|
1294
1299
|
new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
|
|
1295
|
-
)), o[
|
|
1300
|
+
)), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1296
1301
|
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1297
|
-
const
|
|
1302
|
+
const l = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(l), w = l.pool.borrowIncentiveApyInfo.apy;
|
|
1298
1303
|
a.gt(0) && (i = i.plus(
|
|
1299
1304
|
new p(f).dividedBy(a).multipliedBy(new p(w).dividedBy(100))
|
|
1300
|
-
)), r[
|
|
1305
|
+
)), r[l.pool.suiCoinType] = p(r[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1301
1306
|
}
|
|
1302
1307
|
});
|
|
1303
1308
|
const d = t.minus(a), y = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(c).minus(a.multipliedBy(i)).div(t.minus(a));
|
|
@@ -1310,7 +1315,7 @@ class O {
|
|
|
1310
1315
|
totalsupplyApy: c.toString(),
|
|
1311
1316
|
totalBorrowApy: i.toString(),
|
|
1312
1317
|
maxLiquidationValue: s.toString(),
|
|
1313
|
-
maxLoanToVaule:
|
|
1318
|
+
maxLoanToVaule: u.toString(),
|
|
1314
1319
|
supply: o,
|
|
1315
1320
|
borrow: r
|
|
1316
1321
|
};
|
|
@@ -1369,12 +1374,12 @@ async function $e(e, n) {
|
|
|
1369
1374
|
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
1370
1375
|
continue;
|
|
1371
1376
|
}
|
|
1372
|
-
const s = e.find((
|
|
1377
|
+
const s = e.find((l) => l.priceInfoObject == i.objectId);
|
|
1373
1378
|
if (!s) {
|
|
1374
1379
|
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
1375
1380
|
continue;
|
|
1376
1381
|
}
|
|
1377
|
-
const
|
|
1382
|
+
const u = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: d, negative: y } = u.price.fields, v = u.conf, g = u.timestamp;
|
|
1378
1383
|
o.push({
|
|
1379
1384
|
priceFeedId: s.priceFeedId,
|
|
1380
1385
|
priceInfoObject: s.priceInfoObject,
|
|
@@ -1507,8 +1512,8 @@ async function mt(e, n, o, r) {
|
|
|
1507
1512
|
const t = await ne({
|
|
1508
1513
|
...r
|
|
1509
1514
|
}), a = [];
|
|
1510
|
-
o.forEach((
|
|
1511
|
-
a.includes(
|
|
1515
|
+
o.forEach((u) => {
|
|
1516
|
+
a.includes(u.market) || a.push(u.market);
|
|
1512
1517
|
});
|
|
1513
1518
|
const c = await Pe(n, {
|
|
1514
1519
|
...r,
|
|
@@ -1554,7 +1559,7 @@ async function yt(e, n, o, r) {
|
|
|
1554
1559
|
))
|
|
1555
1560
|
throw new Error("Pool does not support flashloan");
|
|
1556
1561
|
if (t.version === 1) {
|
|
1557
|
-
const [s,
|
|
1562
|
+
const [s, u] = e.moveCall({
|
|
1558
1563
|
target: `${t.package}::lending::flash_loan_with_ctx`,
|
|
1559
1564
|
arguments: [
|
|
1560
1565
|
e.object(t.flashloanConfig),
|
|
@@ -1563,9 +1568,9 @@ async function yt(e, n, o, r) {
|
|
|
1563
1568
|
],
|
|
1564
1569
|
typeArguments: [a.suiCoinType]
|
|
1565
1570
|
});
|
|
1566
|
-
return [s,
|
|
1571
|
+
return [s, u];
|
|
1567
1572
|
} else {
|
|
1568
|
-
const [s,
|
|
1573
|
+
const [s, u] = e.moveCall({
|
|
1569
1574
|
target: `${t.package}::lending::flash_loan_with_ctx_v2`,
|
|
1570
1575
|
arguments: [
|
|
1571
1576
|
e.object(t.flashloanConfig),
|
|
@@ -1575,7 +1580,7 @@ async function yt(e, n, o, r) {
|
|
|
1575
1580
|
],
|
|
1576
1581
|
typeArguments: [a.suiCoinType]
|
|
1577
1582
|
});
|
|
1578
|
-
return [s,
|
|
1583
|
+
return [s, u];
|
|
1579
1584
|
}
|
|
1580
1585
|
}
|
|
1581
1586
|
async function gt(e, n, o, r, t) {
|
|
@@ -1590,7 +1595,7 @@ async function gt(e, n, o, r, t) {
|
|
|
1590
1595
|
(d) => k(d.coinType) === k(c.suiCoinType)
|
|
1591
1596
|
))
|
|
1592
1597
|
throw new Error("Pool does not support flashloan");
|
|
1593
|
-
const [
|
|
1598
|
+
const [u] = e.moveCall({
|
|
1594
1599
|
target: `${a.package}::lending::flash_repay_with_ctx`,
|
|
1595
1600
|
arguments: [
|
|
1596
1601
|
e.object("0x06"),
|
|
@@ -1601,13 +1606,13 @@ async function gt(e, n, o, r, t) {
|
|
|
1601
1606
|
],
|
|
1602
1607
|
typeArguments: [c.suiCoinType]
|
|
1603
1608
|
});
|
|
1604
|
-
return [
|
|
1609
|
+
return [u];
|
|
1605
1610
|
}
|
|
1606
1611
|
async function ht(e, n, o, r, t, a) {
|
|
1607
1612
|
const c = {
|
|
1608
1613
|
...a,
|
|
1609
1614
|
cacheTime: b
|
|
1610
|
-
}, i = await _(c), s = await A(n, c),
|
|
1615
|
+
}, i = await _(c), s = await A(n, c), u = await A(r, c);
|
|
1611
1616
|
if (i.version === 1) {
|
|
1612
1617
|
const [d, y] = e.moveCall({
|
|
1613
1618
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
@@ -1624,9 +1629,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1624
1629
|
// Pay asset pool contract
|
|
1625
1630
|
h(o, e.object),
|
|
1626
1631
|
// Debt repayment amount
|
|
1627
|
-
e.pure.u8(
|
|
1632
|
+
e.pure.u8(u.id),
|
|
1628
1633
|
// Collateral asset ID
|
|
1629
|
-
e.object(
|
|
1634
|
+
e.object(u.contract.pool),
|
|
1630
1635
|
// Collateral asset pool contract
|
|
1631
1636
|
h(t, e.pure.address),
|
|
1632
1637
|
// Borrower address
|
|
@@ -1635,7 +1640,7 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1635
1640
|
e.object(i.incentiveV3)
|
|
1636
1641
|
// Incentive V3 contract
|
|
1637
1642
|
],
|
|
1638
|
-
typeArguments: [s.suiCoinType,
|
|
1643
|
+
typeArguments: [s.suiCoinType, u.suiCoinType]
|
|
1639
1644
|
});
|
|
1640
1645
|
return [d, y];
|
|
1641
1646
|
} else {
|
|
@@ -1654,9 +1659,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1654
1659
|
// Pay asset pool contract
|
|
1655
1660
|
h(o, e.object),
|
|
1656
1661
|
// Debt repayment amount
|
|
1657
|
-
e.pure.u8(
|
|
1662
|
+
e.pure.u8(u.id),
|
|
1658
1663
|
// Collateral asset ID
|
|
1659
|
-
e.object(
|
|
1664
|
+
e.object(u.contract.pool),
|
|
1660
1665
|
// Collateral asset pool contract
|
|
1661
1666
|
h(t, e.pure.address),
|
|
1662
1667
|
// Borrower address
|
|
@@ -1667,7 +1672,7 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1667
1672
|
e.object("0x05")
|
|
1668
1673
|
// SuiSystemState object
|
|
1669
1674
|
],
|
|
1670
|
-
typeArguments: [s.suiCoinType,
|
|
1675
|
+
typeArguments: [s.suiCoinType, u.suiCoinType]
|
|
1671
1676
|
});
|
|
1672
1677
|
return [d, y];
|
|
1673
1678
|
}
|
|
@@ -1723,24 +1728,24 @@ async function De(e, n, o) {
|
|
|
1723
1728
|
)
|
|
1724
1729
|
);
|
|
1725
1730
|
});
|
|
1726
|
-
const
|
|
1731
|
+
const u = [];
|
|
1727
1732
|
return s.forEach((d, y) => {
|
|
1728
1733
|
const v = n[y];
|
|
1729
1734
|
if (d.length === 5 && Array.isArray(d[0])) {
|
|
1730
1735
|
const g = d[0].length;
|
|
1731
|
-
for (let
|
|
1736
|
+
for (let l = 0; l < g; l++) {
|
|
1732
1737
|
const f = c.find(
|
|
1733
|
-
(I) => k(I.coinType) === k(d[1][
|
|
1738
|
+
(I) => k(I.coinType) === k(d[1][l])
|
|
1734
1739
|
), w = a.find(
|
|
1735
|
-
(I) => k(I.coinType) === k(d[0][
|
|
1740
|
+
(I) => k(I.coinType) === k(d[0][l]) && I.market === v.market
|
|
1736
1741
|
);
|
|
1737
|
-
!f || !w ||
|
|
1742
|
+
!f || !w || u.push({
|
|
1738
1743
|
assetId: w.id,
|
|
1739
|
-
assetCoinType: k(d[0][
|
|
1740
|
-
rewardCoinType: k(d[1][
|
|
1741
|
-
option: Number(d[2][
|
|
1742
|
-
userClaimableReward: Number(d[4][
|
|
1743
|
-
ruleIds: Array.isArray(d[3][
|
|
1744
|
+
assetCoinType: k(d[0][l]),
|
|
1745
|
+
rewardCoinType: k(d[1][l]),
|
|
1746
|
+
option: Number(d[2][l]),
|
|
1747
|
+
userClaimableReward: Number(d[4][l]) / Math.pow(10, f.priceDecimal),
|
|
1748
|
+
ruleIds: Array.isArray(d[3][l]) ? d[3][l] : [d[3][l]],
|
|
1744
1749
|
market: v.market,
|
|
1745
1750
|
owner: v.owner,
|
|
1746
1751
|
address: v.address,
|
|
@@ -1748,7 +1753,7 @@ async function De(e, n, o) {
|
|
|
1748
1753
|
});
|
|
1749
1754
|
}
|
|
1750
1755
|
}
|
|
1751
|
-
}),
|
|
1756
|
+
}), u;
|
|
1752
1757
|
}
|
|
1753
1758
|
async function vt(e, n) {
|
|
1754
1759
|
const o = (n?.markets || [E.main]).map((a) => j(a));
|
|
@@ -1791,8 +1796,8 @@ function wt(e) {
|
|
|
1791
1796
|
for (const { assetId: r, rewardType: t, coinType: a, total: c, market: i } of n.values()) {
|
|
1792
1797
|
const s = `${r}-${t}-${i}`;
|
|
1793
1798
|
o.has(s) || o.set(s, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
1794
|
-
const
|
|
1795
|
-
|
|
1799
|
+
const u = o.get(s);
|
|
1800
|
+
u.rewards.set(a, (u.rewards.get(a) || 0) + c);
|
|
1796
1801
|
}
|
|
1797
1802
|
return Array.from(o.values()).map((r) => ({
|
|
1798
1803
|
assetId: r.assetId,
|
|
@@ -1824,27 +1829,27 @@ async function _t(e, n, o) {
|
|
|
1824
1829
|
cacheTime: b
|
|
1825
1830
|
}), t = /* @__PURE__ */ new Map();
|
|
1826
1831
|
for (const c of n) {
|
|
1827
|
-
const { rewardCoinType: i, ruleIds: s, market:
|
|
1828
|
-
for (const
|
|
1832
|
+
const { rewardCoinType: i, ruleIds: s, market: u, owner: d, address: y, emodeId: v } = c, g = `${i}___${y}`;
|
|
1833
|
+
for (const l of s) {
|
|
1829
1834
|
t.has(g) || t.set(g, {
|
|
1830
1835
|
assetIds: [],
|
|
1831
1836
|
ruleIds: [],
|
|
1832
1837
|
amount: 0,
|
|
1833
|
-
market:
|
|
1838
|
+
market: u,
|
|
1834
1839
|
owner: d,
|
|
1835
1840
|
address: y,
|
|
1836
1841
|
isEMode: typeof v < "u"
|
|
1837
1842
|
});
|
|
1838
1843
|
const f = t.get(g);
|
|
1839
|
-
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(
|
|
1844
|
+
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(l), f.amount += c.userClaimableReward;
|
|
1840
1845
|
}
|
|
1841
1846
|
}
|
|
1842
1847
|
const a = [];
|
|
1843
1848
|
for (const [
|
|
1844
1849
|
c,
|
|
1845
|
-
{ assetIds: i, ruleIds: s, amount:
|
|
1850
|
+
{ assetIds: i, ruleIds: s, amount: u, market: d, owner: y, address: v, isEMode: g }
|
|
1846
1851
|
] of t) {
|
|
1847
|
-
const
|
|
1852
|
+
const l = await _({
|
|
1848
1853
|
...o,
|
|
1849
1854
|
cacheTime: b,
|
|
1850
1855
|
market: d
|
|
@@ -1857,13 +1862,13 @@ async function _t(e, n, o) {
|
|
|
1857
1862
|
if (o?.customCoinReceive) {
|
|
1858
1863
|
let V;
|
|
1859
1864
|
o.accountCap ? V = e.moveCall({
|
|
1860
|
-
target: `${
|
|
1865
|
+
target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1861
1866
|
arguments: [
|
|
1862
1867
|
e.object("0x06"),
|
|
1863
1868
|
// Clock object
|
|
1864
|
-
e.object(
|
|
1869
|
+
e.object(l.incentiveV3),
|
|
1865
1870
|
// Incentive V3 contract
|
|
1866
|
-
e.object(
|
|
1871
|
+
e.object(l.storage),
|
|
1867
1872
|
// Protocol storage
|
|
1868
1873
|
e.object(I),
|
|
1869
1874
|
// Reward fund
|
|
@@ -1876,13 +1881,13 @@ async function _t(e, n, o) {
|
|
|
1876
1881
|
],
|
|
1877
1882
|
typeArguments: [f]
|
|
1878
1883
|
}) : g ? V = e.moveCall({
|
|
1879
|
-
target: `${
|
|
1884
|
+
target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1880
1885
|
arguments: [
|
|
1881
1886
|
e.object("0x06"),
|
|
1882
1887
|
// Clock object
|
|
1883
|
-
e.object(
|
|
1888
|
+
e.object(l.incentiveV3),
|
|
1884
1889
|
// Incentive V3 contract
|
|
1885
|
-
e.object(
|
|
1890
|
+
e.object(l.storage),
|
|
1886
1891
|
// Protocol storage
|
|
1887
1892
|
e.object(I),
|
|
1888
1893
|
// Reward fund
|
|
@@ -1895,13 +1900,13 @@ async function _t(e, n, o) {
|
|
|
1895
1900
|
],
|
|
1896
1901
|
typeArguments: [f]
|
|
1897
1902
|
}) : V = e.moveCall({
|
|
1898
|
-
target: `${
|
|
1903
|
+
target: `${l.package}::incentive_v3::claim_reward`,
|
|
1899
1904
|
arguments: [
|
|
1900
1905
|
e.object("0x06"),
|
|
1901
1906
|
// Clock object
|
|
1902
|
-
e.object(
|
|
1907
|
+
e.object(l.incentiveV3),
|
|
1903
1908
|
// Incentive V3 contract
|
|
1904
|
-
e.object(
|
|
1909
|
+
e.object(l.storage),
|
|
1905
1910
|
// Protocol storage
|
|
1906
1911
|
e.object(I),
|
|
1907
1912
|
// Reward fund
|
|
@@ -1927,7 +1932,7 @@ async function _t(e, n, o) {
|
|
|
1927
1932
|
}
|
|
1928
1933
|
if (o?.customCoinReceive.type === "depositNAVI") {
|
|
1929
1934
|
const re = p(w.totalSupplyAmount).shiftedBy(-9), ae = p(w.supplyCapCeiling).shiftedBy(-27);
|
|
1930
|
-
re.plus(
|
|
1935
|
+
re.plus(u).isGreaterThan(ae) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
1931
1936
|
[U],
|
|
1932
1937
|
e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1933
1938
|
) : await _e(e, w, U, o);
|
|
@@ -1940,13 +1945,13 @@ async function _t(e, n, o) {
|
|
|
1940
1945
|
});
|
|
1941
1946
|
} else if (o?.accountCap || g) {
|
|
1942
1947
|
const V = e.moveCall({
|
|
1943
|
-
target: `${
|
|
1948
|
+
target: `${l.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1944
1949
|
arguments: [
|
|
1945
1950
|
e.object("0x06"),
|
|
1946
1951
|
// Clock object
|
|
1947
|
-
e.object(
|
|
1952
|
+
e.object(l.incentiveV3),
|
|
1948
1953
|
// Incentive V3 contract
|
|
1949
|
-
e.object(
|
|
1954
|
+
e.object(l.storage),
|
|
1950
1955
|
// Protocol storage
|
|
1951
1956
|
e.object(I),
|
|
1952
1957
|
// Reward fund
|
|
@@ -1969,13 +1974,13 @@ async function _t(e, n, o) {
|
|
|
1969
1974
|
);
|
|
1970
1975
|
} else
|
|
1971
1976
|
e.moveCall({
|
|
1972
|
-
target: `${
|
|
1977
|
+
target: `${l.package}::incentive_v3::claim_reward_entry`,
|
|
1973
1978
|
arguments: [
|
|
1974
1979
|
e.object("0x06"),
|
|
1975
1980
|
// Clock object
|
|
1976
|
-
e.object(
|
|
1981
|
+
e.object(l.incentiveV3),
|
|
1977
1982
|
// Incentive V3 contract
|
|
1978
|
-
e.object(
|
|
1983
|
+
e.object(l.storage),
|
|
1979
1984
|
// Protocol storage
|
|
1980
1985
|
e.object(I),
|
|
1981
1986
|
// Reward fund
|
|
@@ -2017,7 +2022,7 @@ export {
|
|
|
2017
2022
|
Te as getAccountCapOwnerPTB,
|
|
2018
2023
|
G as getAllFlashLoanAssets,
|
|
2019
2024
|
et as getBorrowFee,
|
|
2020
|
-
|
|
2025
|
+
lt as getCoins,
|
|
2021
2026
|
_ as getConfig,
|
|
2022
2027
|
Ze as getFees,
|
|
2023
2028
|
ft as getFlashLoanAsset,
|
|
@@ -2036,7 +2041,7 @@ export {
|
|
|
2036
2041
|
st as getSimulatedHealthFactor,
|
|
2037
2042
|
ee as getSimulatedHealthFactorPTB,
|
|
2038
2043
|
Je as getStats,
|
|
2039
|
-
|
|
2044
|
+
ut as getTransactions,
|
|
2040
2045
|
vt as getUserAvailableLendingRewards,
|
|
2041
2046
|
kt as getUserClaimedRewardHistory,
|
|
2042
2047
|
x as getUserEModeCaps,
|