@naviprotocol/lending 1.4.4-beta.1 → 1.4.4-beta.3
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 +170 -168
- package/dist/index.esm.js.map +1 -1
- package/dist/market.d.ts +1 -1
- package/dist/pool.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -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.4-beta.
|
|
132
|
+
}), ye = "1.4.4-beta.3", S = {
|
|
133
133
|
version: ye
|
|
134
134
|
}, ge = S.version, he = () => {
|
|
135
135
|
if (typeof process < "u" && process.versions && process.versions.node)
|
|
@@ -151,8 +151,8 @@ function Q(e) {
|
|
|
151
151
|
return e.forEach((o, r) => {
|
|
152
152
|
const t = r === e.length - 1;
|
|
153
153
|
if (typeof o == "object" && o !== null && t) {
|
|
154
|
-
const { client: a, disableCache:
|
|
155
|
-
n.push(
|
|
154
|
+
const { client: a, disableCache: s, cacheTime: i, ...c } = o;
|
|
155
|
+
n.push(c);
|
|
156
156
|
} else
|
|
157
157
|
n.push(o);
|
|
158
158
|
}), JSON.stringify(n);
|
|
@@ -170,10 +170,10 @@ function P(e) {
|
|
|
170
170
|
let n = {};
|
|
171
171
|
return (...o) => {
|
|
172
172
|
const r = o[o.length - 1], t = Q(o), a = n[t];
|
|
173
|
-
return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...o).then((
|
|
174
|
-
data:
|
|
173
|
+
return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...o).then((s) => (n[t] = {
|
|
174
|
+
data: s,
|
|
175
175
|
cacheAt: Date.now()
|
|
176
|
-
},
|
|
176
|
+
}, s));
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
function W(e) {
|
|
@@ -260,16 +260,16 @@ const R = P(
|
|
|
260
260
|
(t) => t.key
|
|
261
261
|
)}`, r = await fetch(o, { headers: M }).then((t) => t.json());
|
|
262
262
|
return r.data.forEach((t) => {
|
|
263
|
-
const
|
|
263
|
+
const s = r.meta.emodes.filter((f) => {
|
|
264
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
|
-
t.emodes =
|
|
268
|
-
const i = p(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(),
|
|
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(), d = p(c).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
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 =
|
|
272
|
+
t.poolSupplyAmount = i, t.poolBorrowAmount = c, 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
|
)
|
|
@@ -310,16 +310,18 @@ async function _e(e, n, o, r) {
|
|
|
310
310
|
...r,
|
|
311
311
|
cacheTime: b
|
|
312
312
|
}), a = await A(n, r);
|
|
313
|
-
|
|
313
|
+
r?.market;
|
|
314
|
+
const s = r?.env || "prod";
|
|
315
|
+
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
314
316
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
315
|
-
const
|
|
316
|
-
if (k(a.suiCoinType) === k("0x2::sui::SUI") &&
|
|
317
|
+
const i = typeof o == "object" && o.$kind === "GasCoin";
|
|
318
|
+
if (k(a.suiCoinType) === k("0x2::sui::SUI") && i) {
|
|
317
319
|
if (!r?.amount)
|
|
318
320
|
throw new Error("Amount is required for sui coin");
|
|
319
321
|
o = e.splitCoins(o, [r.amount]);
|
|
320
322
|
}
|
|
321
|
-
let
|
|
322
|
-
return typeof r?.amount < "u" ?
|
|
323
|
+
let c;
|
|
324
|
+
return typeof r?.amount < "u" ? c = h(r.amount, e.pure.u64) : c = e.moveCall({
|
|
323
325
|
target: "0x2::coin::value",
|
|
324
326
|
arguments: [h(o, e.object)],
|
|
325
327
|
typeArguments: [a.suiCoinType]
|
|
@@ -344,12 +346,12 @@ async function _e(e, n, o, r) {
|
|
|
344
346
|
e.object(a.contract.pool),
|
|
345
347
|
e.pure.u8(a.id),
|
|
346
348
|
h(o, e.object),
|
|
347
|
-
|
|
349
|
+
c,
|
|
348
350
|
e.object(t.incentiveV2),
|
|
349
351
|
e.object(t.incentiveV3)
|
|
350
352
|
],
|
|
351
353
|
typeArguments: [a.suiCoinType]
|
|
352
|
-
}), t.version === 2 && a.token.symbol === "SUI" && e.moveCall({
|
|
354
|
+
}), t.version === 2 && a.token.symbol === "SUI" && s === "prod" && e.moveCall({
|
|
353
355
|
target: `${t.package}::pool::refresh_stake`,
|
|
354
356
|
arguments: [e.object(a.contract.pool), e.object("0x05")]
|
|
355
357
|
}), e;
|
|
@@ -358,7 +360,7 @@ async function Qe(e, n, o, r) {
|
|
|
358
360
|
const t = await _({
|
|
359
361
|
...r,
|
|
360
362
|
cacheTime: b
|
|
361
|
-
}), a = await A(n, r),
|
|
363
|
+
}), a = await A(n, r), s = h(o, e.pure.u64);
|
|
362
364
|
let i;
|
|
363
365
|
if (t.version === 1)
|
|
364
366
|
if (r?.accountCap) {
|
|
@@ -370,7 +372,7 @@ async function Qe(e, n, o, r) {
|
|
|
370
372
|
e.object(t.storage),
|
|
371
373
|
e.object(a.contract.pool),
|
|
372
374
|
e.pure.u8(a.id),
|
|
373
|
-
|
|
375
|
+
s,
|
|
374
376
|
e.object(t.incentiveV2),
|
|
375
377
|
e.object(t.incentiveV3),
|
|
376
378
|
h(r.accountCap, e.object)
|
|
@@ -387,7 +389,7 @@ async function Qe(e, n, o, r) {
|
|
|
387
389
|
e.object(t.storage),
|
|
388
390
|
e.object(a.contract.pool),
|
|
389
391
|
e.pure.u8(a.id),
|
|
390
|
-
|
|
392
|
+
s,
|
|
391
393
|
e.object(t.incentiveV2),
|
|
392
394
|
e.object(t.incentiveV3)
|
|
393
395
|
],
|
|
@@ -404,7 +406,7 @@ async function Qe(e, n, o, r) {
|
|
|
404
406
|
e.object(t.storage),
|
|
405
407
|
e.object(a.contract.pool),
|
|
406
408
|
e.pure.u8(a.id),
|
|
407
|
-
|
|
409
|
+
s,
|
|
408
410
|
e.object(t.incentiveV2),
|
|
409
411
|
e.object(t.incentiveV3),
|
|
410
412
|
h(r.accountCap, e.object),
|
|
@@ -422,7 +424,7 @@ async function Qe(e, n, o, r) {
|
|
|
422
424
|
e.object(t.storage),
|
|
423
425
|
e.object(a.contract.pool),
|
|
424
426
|
e.pure.u8(a.id),
|
|
425
|
-
|
|
427
|
+
s,
|
|
426
428
|
e.object(t.incentiveV2),
|
|
427
429
|
e.object(t.incentiveV3),
|
|
428
430
|
e.object("0x05")
|
|
@@ -444,7 +446,7 @@ async function Xe(e, n, o, r) {
|
|
|
444
446
|
}), a = await A(n, r);
|
|
445
447
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
446
448
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
447
|
-
const
|
|
449
|
+
const s = h(o, e.pure.u64);
|
|
448
450
|
let i;
|
|
449
451
|
if (t.version === 1)
|
|
450
452
|
if (r?.accountCap) {
|
|
@@ -456,7 +458,7 @@ async function Xe(e, n, o, r) {
|
|
|
456
458
|
e.object(t.storage),
|
|
457
459
|
e.object(a.contract.pool),
|
|
458
460
|
e.pure.u8(a.id),
|
|
459
|
-
|
|
461
|
+
s,
|
|
460
462
|
e.object(t.incentiveV2),
|
|
461
463
|
e.object(t.incentiveV3),
|
|
462
464
|
h(r.accountCap, e.object)
|
|
@@ -473,7 +475,7 @@ async function Xe(e, n, o, r) {
|
|
|
473
475
|
e.object(t.storage),
|
|
474
476
|
e.object(a.contract.pool),
|
|
475
477
|
e.pure.u8(a.id),
|
|
476
|
-
|
|
478
|
+
s,
|
|
477
479
|
e.object(t.incentiveV2),
|
|
478
480
|
e.object(t.incentiveV3)
|
|
479
481
|
],
|
|
@@ -490,7 +492,7 @@ async function Xe(e, n, o, r) {
|
|
|
490
492
|
e.object(t.storage),
|
|
491
493
|
e.object(a.contract.pool),
|
|
492
494
|
e.pure.u8(a.id),
|
|
493
|
-
|
|
495
|
+
s,
|
|
494
496
|
e.object(t.incentiveV2),
|
|
495
497
|
e.object(t.incentiveV3),
|
|
496
498
|
h(r.accountCap, e.object),
|
|
@@ -508,7 +510,7 @@ async function Xe(e, n, o, r) {
|
|
|
508
510
|
e.object(t.storage),
|
|
509
511
|
e.object(a.contract.pool),
|
|
510
512
|
e.pure.u8(a.id),
|
|
511
|
-
|
|
513
|
+
s,
|
|
512
514
|
e.object(t.incentiveV2),
|
|
513
515
|
e.object(t.incentiveV3),
|
|
514
516
|
e.object("0x05")
|
|
@@ -527,8 +529,8 @@ async function xe(e, n, o, r) {
|
|
|
527
529
|
const t = await _({
|
|
528
530
|
...r,
|
|
529
531
|
cacheTime: b
|
|
530
|
-
}), a = await A(n, r),
|
|
531
|
-
if (k(a.suiCoinType) === k("0x2::sui::SUI") &&
|
|
532
|
+
}), a = await A(n, r), s = typeof o == "object" && o.$kind === "GasCoin";
|
|
533
|
+
if (k(a.suiCoinType) === k("0x2::sui::SUI") && s) {
|
|
532
534
|
if (!r?.amount)
|
|
533
535
|
throw new Error("Amount is required for sui coin");
|
|
534
536
|
o = e.splitCoins(o, [r.amount]);
|
|
@@ -539,7 +541,7 @@ async function xe(e, n, o, r) {
|
|
|
539
541
|
arguments: [h(o, e.object)],
|
|
540
542
|
typeArguments: [a.suiCoinType]
|
|
541
543
|
}), r?.accountCap) {
|
|
542
|
-
const [
|
|
544
|
+
const [c] = e.moveCall({
|
|
543
545
|
target: `${t.package}::incentive_v3::repay_with_account_cap`,
|
|
544
546
|
arguments: [
|
|
545
547
|
e.object("0x06"),
|
|
@@ -556,7 +558,7 @@ async function xe(e, n, o, r) {
|
|
|
556
558
|
});
|
|
557
559
|
return e.moveCall({
|
|
558
560
|
target: "0x2::coin::from_balance",
|
|
559
|
-
arguments: [
|
|
561
|
+
arguments: [c],
|
|
560
562
|
typeArguments: [a.suiCoinType]
|
|
561
563
|
});
|
|
562
564
|
} else
|
|
@@ -584,22 +586,22 @@ const et = P(
|
|
|
584
586
|
});
|
|
585
587
|
if (e?.address && typeof e?.asset < "u")
|
|
586
588
|
try {
|
|
587
|
-
const t = await A(e.asset, e), a = e?.client ?? $,
|
|
588
|
-
|
|
589
|
+
const t = await A(e.asset, e), a = e?.client ?? $, s = new N();
|
|
590
|
+
s.moveCall({
|
|
589
591
|
target: `${n.package}::incentive_v3::get_borrow_fee_v2`,
|
|
590
592
|
arguments: [
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
593
|
+
s.object(n.incentiveV3),
|
|
594
|
+
s.pure.address(e.address),
|
|
595
|
+
s.pure.u8(t.id),
|
|
596
|
+
s.pure.u64(1e4)
|
|
595
597
|
],
|
|
596
598
|
typeArguments: []
|
|
597
599
|
});
|
|
598
600
|
const i = await a.devInspectTransactionBlock({
|
|
599
|
-
transactionBlock:
|
|
601
|
+
transactionBlock: s,
|
|
600
602
|
sender: e.address
|
|
601
|
-
}),
|
|
602
|
-
return (Number(
|
|
603
|
+
}), c = L(i, [C.u64()]);
|
|
604
|
+
return (Number(c[0]) || 0) / 100;
|
|
603
605
|
} catch (t) {
|
|
604
606
|
console.error(t);
|
|
605
607
|
}
|
|
@@ -621,7 +623,7 @@ const et = P(
|
|
|
621
623
|
key: "ember",
|
|
622
624
|
name: "Ember Market"
|
|
623
625
|
},
|
|
624
|
-
|
|
626
|
+
"sui-eco": {
|
|
625
627
|
id: 2,
|
|
626
628
|
key: "sui-eco",
|
|
627
629
|
name: "Sui Eco Market"
|
|
@@ -639,42 +641,42 @@ class Ce {
|
|
|
639
641
|
}
|
|
640
642
|
initPools(n) {
|
|
641
643
|
const o = H(this.pools), r = J(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
642
|
-
let
|
|
643
|
-
n.forEach((
|
|
644
|
-
if (!this.checkMarket(
|
|
645
|
-
console.warn(`Pool is not in market ${this.config.name}`,
|
|
644
|
+
let s = p(0), i = p(0);
|
|
645
|
+
n.forEach((c) => {
|
|
646
|
+
if (!this.checkMarket(c.market)) {
|
|
647
|
+
console.warn(`Pool is not in market ${this.config.name}`, c);
|
|
646
648
|
return;
|
|
647
649
|
}
|
|
648
|
-
o[
|
|
650
|
+
o[c.uniqueId] || this.pools.push(c), c?.emodes?.forEach((d) => {
|
|
649
651
|
r[d.uniqueId] || this.emodes.push(d), d.assets.forEach((y) => {
|
|
650
652
|
y.isDebt && d.assets.find(
|
|
651
|
-
(g) => g.isCollateral && g.ltv > 0 && g.assetId !==
|
|
652
|
-
) && t.add(
|
|
653
|
+
(g) => g.isCollateral && g.ltv > 0 && g.assetId !== c.id
|
|
654
|
+
) && t.add(c.uniqueId), y.isCollateral && d.assets.find((g) => g.isDebt && g.assetId !== c.id) && a.add(c.uniqueId);
|
|
653
655
|
});
|
|
654
|
-
}), i = i.plus(
|
|
655
|
-
}), this.poolMap = H(this.pools, "id"), this.emodeMap = J(this.emodes, "emodeId"), this.emodes.forEach((
|
|
656
|
-
const u = this.getEModePools(
|
|
656
|
+
}), i = i.plus(c.poolBorrowValue), s = s.plus(c.poolSupplyValue);
|
|
657
|
+
}), this.poolMap = H(this.pools, "id"), this.emodeMap = J(this.emodes, "emodeId"), this.emodes.forEach((c) => {
|
|
658
|
+
const u = this.getEModePools(c.emodeId);
|
|
657
659
|
this.emodePools.push(...u);
|
|
658
660
|
}), this._overview = {
|
|
659
|
-
marketTotalSupplyValue:
|
|
661
|
+
marketTotalSupplyValue: s.toString(),
|
|
660
662
|
marketTotalBorrowValue: i.toString()
|
|
661
|
-
}, this.emodeBorrowablePools = this.pools.filter((
|
|
663
|
+
}, this.emodeBorrowablePools = this.pools.filter((c) => t.has(c.uniqueId)), this.emodeSupplyablePools = this.pools.filter((c) => a.has(c.uniqueId));
|
|
662
664
|
}
|
|
663
665
|
getEMode(n) {
|
|
664
666
|
return this.emodeMap[n] || null;
|
|
665
667
|
}
|
|
666
668
|
getEModeRelatePools(n, o) {
|
|
667
|
-
const { collateral: r, debt: t, emodeId: a } = o || {},
|
|
669
|
+
const { collateral: r, debt: t, emodeId: a } = o || {}, s = [];
|
|
668
670
|
return n.emodes.forEach((i) => {
|
|
669
|
-
typeof a == "number" && a !== i.emodeId || i.assets.forEach((
|
|
670
|
-
typeof r == "boolean" && r &&
|
|
671
|
+
typeof a == "number" && a !== i.emodeId || i.assets.forEach((c) => {
|
|
672
|
+
typeof r == "boolean" && r && c.isCollateral && c.assetId === n.id && s.push(this.poolMap[c.assetId]), typeof t == "boolean" && t && c.isDebt && c.assetId === n.id && s.push(this.poolMap[c.assetId]);
|
|
671
673
|
});
|
|
672
|
-
}),
|
|
674
|
+
}), s;
|
|
673
675
|
}
|
|
674
676
|
getEModePools(n) {
|
|
675
677
|
const o = this.getEMode(n);
|
|
676
678
|
return o ? o.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
|
|
677
|
-
const a = o.assets.find((
|
|
679
|
+
const a = o.assets.find((s) => s.assetId === t.id);
|
|
678
680
|
return {
|
|
679
681
|
...t,
|
|
680
682
|
emode: {
|
|
@@ -704,7 +706,7 @@ const j = (e) => {
|
|
|
704
706
|
markets: e
|
|
705
707
|
});
|
|
706
708
|
return e.map((r) => {
|
|
707
|
-
const t = j(r), a = o.filter((
|
|
709
|
+
const t = j(r), a = o.filter((s) => s.market === t.key);
|
|
708
710
|
return new Ce(r, a);
|
|
709
711
|
});
|
|
710
712
|
}
|
|
@@ -780,12 +782,12 @@ async function nt(e, n, o) {
|
|
|
780
782
|
...o,
|
|
781
783
|
accountCap: t
|
|
782
784
|
});
|
|
783
|
-
const a = await j(o?.market || D),
|
|
785
|
+
const a = await j(o?.market || D), s = await Te(e, t, o);
|
|
784
786
|
return e.moveCall({
|
|
785
787
|
target: `${r.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
786
788
|
arguments: [
|
|
787
789
|
e.object(r.emode.contract.registryObject),
|
|
788
|
-
|
|
790
|
+
s,
|
|
789
791
|
h(a.id, e.pure.u64),
|
|
790
792
|
h(n, e.pure.u64)
|
|
791
793
|
]
|
|
@@ -802,13 +804,13 @@ const x = P(
|
|
|
802
804
|
target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
803
805
|
arguments: [r.object(o.emode.contract.registryObject), r.pure.address(e)]
|
|
804
806
|
});
|
|
805
|
-
const
|
|
807
|
+
const s = (await t.devInspectTransactionBlock({
|
|
806
808
|
transactionBlock: r,
|
|
807
809
|
sender: e
|
|
808
|
-
})).results[0].returnValues, i = C.vector(C.u64()).parse(Uint8Array.from(
|
|
810
|
+
})).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]));
|
|
809
811
|
return i.map((d, y) => ({
|
|
810
812
|
marketId: Number(d),
|
|
811
|
-
emodeId: Number(
|
|
813
|
+
emodeId: Number(c[y]),
|
|
812
814
|
accountCap: u[y].toString()
|
|
813
815
|
}));
|
|
814
816
|
}
|
|
@@ -820,41 +822,41 @@ function rt(e) {
|
|
|
820
822
|
function at(e, n, o) {
|
|
821
823
|
const r = typeof o?.balance == "number", t = r ? o.balance : 0;
|
|
822
824
|
let a = 0;
|
|
823
|
-
const
|
|
825
|
+
const s = [];
|
|
824
826
|
let i = "";
|
|
825
|
-
if (n.sort((
|
|
826
|
-
if (!(r && a >= t) && Number(
|
|
827
|
-
if (i || (i =
|
|
827
|
+
if (n.sort((c, u) => Number(u.balance) - Number(c.balance)).forEach((c) => {
|
|
828
|
+
if (!(r && a >= t) && Number(c.balance) !== 0) {
|
|
829
|
+
if (i || (i = c.coinType), i !== c.coinType)
|
|
828
830
|
throw new Error("All coins must be of the same type");
|
|
829
|
-
a += Number(
|
|
831
|
+
a += Number(c.balance), s.push(c.coinObjectId);
|
|
830
832
|
}
|
|
831
|
-
}),
|
|
833
|
+
}), s.length === 0)
|
|
832
834
|
throw new Error("No coins to merge");
|
|
833
835
|
if (r && a < t)
|
|
834
836
|
throw new Error(
|
|
835
837
|
`Balance is less than the specified balance: ${a} < ${t}`
|
|
836
838
|
);
|
|
837
|
-
return k(i) === k("0x2::sui::SUI") && o?.useGasCoin ? r ? e.splitCoins(e.gas, [e.pure.u64(t)]) : e.gas : (
|
|
839
|
+
return k(i) === k("0x2::sui::SUI") && o?.useGasCoin ? r ? e.splitCoins(e.gas, [e.pure.u64(t)]) : e.gas : (s.length === 1 ? e.object(s[0]) : e.mergeCoins(s[0], s.slice(1)), r ? e.splitCoins(s[0], [e.pure.u64(t)]) : s[0]);
|
|
838
840
|
}
|
|
839
|
-
async function ee(e, n, o, r, t, a,
|
|
841
|
+
async function ee(e, n, o, r, t, a, s) {
|
|
840
842
|
const i = await _({
|
|
841
|
-
...
|
|
843
|
+
...s,
|
|
842
844
|
cacheTime: b
|
|
843
|
-
}),
|
|
845
|
+
}), c = await A(o, s);
|
|
844
846
|
return e.moveCall({
|
|
845
847
|
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
846
848
|
arguments: [
|
|
847
849
|
e.object("0x06"),
|
|
848
850
|
e.object(i.storage),
|
|
849
851
|
e.object(i.oracle.priceOracle),
|
|
850
|
-
we(e,
|
|
852
|
+
we(e, c),
|
|
851
853
|
h(n, e.pure.address),
|
|
852
|
-
h(
|
|
854
|
+
h(c.id, e.pure.u8),
|
|
853
855
|
h(r, e.pure.u64),
|
|
854
856
|
h(t, e.pure.u64),
|
|
855
857
|
h(a, e.pure.bool)
|
|
856
858
|
],
|
|
857
|
-
typeArguments: [
|
|
859
|
+
typeArguments: [c.suiCoinType]
|
|
858
860
|
});
|
|
859
861
|
}
|
|
860
862
|
async function Ae(e, n, o) {
|
|
@@ -864,7 +866,7 @@ async function te(e, n, o) {
|
|
|
864
866
|
const r = new N(), t = o?.client ?? $, a = await R({
|
|
865
867
|
...o,
|
|
866
868
|
markets: Object.values(E)
|
|
867
|
-
}),
|
|
869
|
+
}), s = H(a);
|
|
868
870
|
for (let d of n) {
|
|
869
871
|
const y = await _({
|
|
870
872
|
...o,
|
|
@@ -876,16 +878,16 @@ async function te(e, n, o) {
|
|
|
876
878
|
arguments: [r.object(y.storage), r.pure.address(d.address)]
|
|
877
879
|
});
|
|
878
880
|
}
|
|
879
|
-
const
|
|
881
|
+
const c = ((await t.devInspectTransactionBlock({
|
|
880
882
|
transactionBlock: r,
|
|
881
883
|
sender: e
|
|
882
884
|
})).results || []).map((d) => d.returnValues?.map((y) => C.vector(fe).parse(Uint8Array.from(y[0])))[0] || []), u = [];
|
|
883
|
-
return
|
|
885
|
+
return c.forEach((d, y) => {
|
|
884
886
|
const v = n[y], g = j(v.market);
|
|
885
887
|
d.forEach((l) => {
|
|
886
888
|
if (l.supply_balance === "0" && l.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
|
|
887
889
|
return;
|
|
888
|
-
const f =
|
|
890
|
+
const f = s[`${g.key}-${l.asset_id}`];
|
|
889
891
|
if (!f)
|
|
890
892
|
return;
|
|
891
893
|
const w = Y(
|
|
@@ -926,18 +928,18 @@ async function ct(e, n) {
|
|
|
926
928
|
}
|
|
927
929
|
async function st(e, n, o, r) {
|
|
928
930
|
const t = r?.client ?? $, a = new N();
|
|
929
|
-
let
|
|
930
|
-
const
|
|
931
|
+
let s = 0, i = 0;
|
|
932
|
+
const c = await A(n, r);
|
|
931
933
|
if (o.forEach((v) => {
|
|
932
|
-
v.type === F.Supply ?
|
|
933
|
-
}),
|
|
934
|
+
v.type === F.Supply ? s += v.amount : v.type === F.Withdraw ? s -= v.amount : v.type === F.Borrow ? i += v.amount : v.type === F.Repay && (i -= v.amount);
|
|
935
|
+
}), s * i < 0)
|
|
934
936
|
throw new Error("Invalid operations");
|
|
935
|
-
const u =
|
|
937
|
+
const u = s > 0 || i > 0;
|
|
936
938
|
await ee(
|
|
937
939
|
a,
|
|
938
940
|
e,
|
|
939
|
-
|
|
940
|
-
Math.abs(
|
|
941
|
+
c,
|
|
942
|
+
Math.abs(s),
|
|
941
943
|
Math.abs(i),
|
|
942
944
|
u,
|
|
943
945
|
r
|
|
@@ -989,36 +991,36 @@ const Pe = P(
|
|
|
989
991
|
address: e,
|
|
990
992
|
market: i.key
|
|
991
993
|
})).concat(
|
|
992
|
-
t.filter((i) => !!r.find((
|
|
994
|
+
t.filter((i) => !!r.find((c) => c.id === i.marketId)).map((i) => ({
|
|
993
995
|
address: i.accountCap,
|
|
994
996
|
market: j(i.marketId).key,
|
|
995
997
|
emodeId: i.emodeId
|
|
996
998
|
}))
|
|
997
999
|
);
|
|
998
1000
|
return (await te(e, a, n)).forEach((i) => {
|
|
999
|
-
const
|
|
1001
|
+
const c = typeof i.emodeId == "number" ? t.find((u) => {
|
|
1000
1002
|
const d = j(i.market);
|
|
1001
1003
|
return u.emodeId === i.emodeId && u.marketId === d.id;
|
|
1002
1004
|
}) : void 0;
|
|
1003
|
-
if (
|
|
1004
|
-
if (!i.pool.emodes.find((d) => d.emodeId ===
|
|
1005
|
+
if (c) {
|
|
1006
|
+
if (!i.pool.emodes.find((d) => d.emodeId === c.emodeId))
|
|
1005
1007
|
return;
|
|
1006
1008
|
if (p(i.supplyBalance).gte(0)) {
|
|
1007
|
-
const d = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = q(i.pool,
|
|
1009
|
+
const d = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = q(i.pool, c);
|
|
1008
1010
|
if (d.gt(0) || y.emode.isCollateral)
|
|
1009
1011
|
try {
|
|
1010
1012
|
o.push({
|
|
1011
|
-
id: `${i.pool.uniqueId}_${
|
|
1013
|
+
id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-supply-${T()}`,
|
|
1012
1014
|
wallet: e,
|
|
1013
1015
|
protocol: "navi",
|
|
1014
1016
|
market: i.market,
|
|
1015
1017
|
type: "navi-lending-emode-supply",
|
|
1016
1018
|
"navi-lending-emode-supply": {
|
|
1017
1019
|
amount: d.toString(),
|
|
1018
|
-
pool: q(i.pool,
|
|
1020
|
+
pool: q(i.pool, c),
|
|
1019
1021
|
token: i.pool.token,
|
|
1020
1022
|
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
1021
|
-
emodeCap:
|
|
1023
|
+
emodeCap: c
|
|
1022
1024
|
}
|
|
1023
1025
|
});
|
|
1024
1026
|
} catch (v) {
|
|
@@ -1026,21 +1028,21 @@ const Pe = P(
|
|
|
1026
1028
|
}
|
|
1027
1029
|
}
|
|
1028
1030
|
if (p(i.borrowBalance).gte(0)) {
|
|
1029
|
-
const d = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = q(i.pool,
|
|
1031
|
+
const d = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = q(i.pool, c);
|
|
1030
1032
|
if (d.gt(0) || y.emode.isDebt)
|
|
1031
1033
|
try {
|
|
1032
1034
|
o.push({
|
|
1033
|
-
id: `${i.pool.uniqueId}_${
|
|
1035
|
+
id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-borrow-${T()}`,
|
|
1034
1036
|
wallet: e,
|
|
1035
1037
|
protocol: "navi",
|
|
1036
1038
|
market: i.market,
|
|
1037
1039
|
type: "navi-lending-emode-borrow",
|
|
1038
1040
|
"navi-lending-emode-borrow": {
|
|
1039
1041
|
amount: d.toString(),
|
|
1040
|
-
pool: q(i.pool,
|
|
1042
|
+
pool: q(i.pool, c),
|
|
1041
1043
|
token: i.pool.token,
|
|
1042
1044
|
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
1043
|
-
emodeCap:
|
|
1045
|
+
emodeCap: c
|
|
1044
1046
|
}
|
|
1045
1047
|
});
|
|
1046
1048
|
} catch (v) {
|
|
@@ -1257,11 +1259,11 @@ class O {
|
|
|
1257
1259
|
}
|
|
1258
1260
|
getPositionsOverview(n) {
|
|
1259
1261
|
const o = {}, r = {};
|
|
1260
|
-
let t = new p(0), a = new p(0),
|
|
1262
|
+
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);
|
|
1261
1263
|
n.forEach((g) => {
|
|
1262
1264
|
if (g.type === "navi-lending-supply") {
|
|
1263
1265
|
const l = g["navi-lending-supply"], f = this.resolveValueUSD(l);
|
|
1264
|
-
t = t.plus(f),
|
|
1266
|
+
t = t.plus(f), c = c.plus(
|
|
1265
1267
|
new p(f).multipliedBy(l.pool.liquidationFactor.threshold)
|
|
1266
1268
|
), u = u.plus(
|
|
1267
1269
|
new p(f).multipliedBy(l.pool.ltvValue)
|
|
@@ -1273,7 +1275,7 @@ class O {
|
|
|
1273
1275
|
const l = g["navi-lending-emode-supply"], f = this.resolveValueUSD(l);
|
|
1274
1276
|
t = t.plus(f);
|
|
1275
1277
|
const w = l.pool.emode;
|
|
1276
|
-
|
|
1278
|
+
c = c.plus(
|
|
1277
1279
|
new p(f).multipliedBy(w.lt)
|
|
1278
1280
|
), u = u.plus(
|
|
1279
1281
|
new p(f).multipliedBy(w.ltv)
|
|
@@ -1282,10 +1284,10 @@ class O {
|
|
|
1282
1284
|
const l = g["navi-lending-emode-borrow"];
|
|
1283
1285
|
a = a.plus(this.resolveValueUSD(l));
|
|
1284
1286
|
}
|
|
1285
|
-
}), a = p.max(a, 0), t = p.max(t, 0),
|
|
1287
|
+
}), a = p.max(a, 0), t = p.max(t, 0), c = p.max(c, 0), u = p.max(u, 0), n.forEach((g) => {
|
|
1286
1288
|
if (g.type === "navi-lending-supply") {
|
|
1287
1289
|
const l = g["navi-lending-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
|
|
1288
|
-
t.gt(0) && (
|
|
1290
|
+
t.gt(0) && (s = s.plus(
|
|
1289
1291
|
new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
|
|
1290
1292
|
)), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1291
1293
|
} else if (g.type === "navi-lending-borrow") {
|
|
@@ -1295,7 +1297,7 @@ class O {
|
|
|
1295
1297
|
)), r[l.pool.suiCoinType] = p(r[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1296
1298
|
} else if (g.type === "navi-lending-emode-supply") {
|
|
1297
1299
|
const l = g["navi-lending-emode-supply"], f = this.resolveValueUSD(l), w = l.pool.supplyIncentiveApyInfo.apy;
|
|
1298
|
-
t.gt(0) && (
|
|
1300
|
+
t.gt(0) && (s = s.plus(
|
|
1299
1301
|
new p(f).dividedBy(t).multipliedBy(new p(w).dividedBy(100))
|
|
1300
1302
|
)), o[l.pool.suiCoinType] = p(o[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1301
1303
|
} else if (g.type === "navi-lending-emode-borrow") {
|
|
@@ -1305,16 +1307,16 @@ class O {
|
|
|
1305
1307
|
)), r[l.pool.suiCoinType] = p(r[l.pool.suiCoinType] || 0).plus(l.amount).toString();
|
|
1306
1308
|
}
|
|
1307
1309
|
});
|
|
1308
|
-
const d = t.minus(a), y = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(
|
|
1310
|
+
const d = t.minus(a), y = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(s).minus(a.multipliedBy(i)).div(t.minus(a));
|
|
1309
1311
|
return {
|
|
1310
|
-
hf: a.toNumber() !== 0 ?
|
|
1312
|
+
hf: a.toNumber() !== 0 ? c.dividedBy(a).toNumber() : 1 / 0,
|
|
1311
1313
|
netVaule: d.toString(),
|
|
1312
1314
|
netWorthApr: y.toString(),
|
|
1313
1315
|
totalSupplyValue: t.toString(),
|
|
1314
1316
|
totalBorrowValue: a.toString(),
|
|
1315
|
-
totalsupplyApy:
|
|
1317
|
+
totalsupplyApy: s.toString(),
|
|
1316
1318
|
totalBorrowApy: i.toString(),
|
|
1317
|
-
maxLiquidationValue:
|
|
1319
|
+
maxLiquidationValue: c.toString(),
|
|
1318
1320
|
maxLoanToVaule: u.toString(),
|
|
1319
1321
|
supply: o,
|
|
1320
1322
|
borrow: r
|
|
@@ -1364,29 +1366,29 @@ async function dt(e) {
|
|
|
1364
1366
|
}
|
|
1365
1367
|
async function $e(e, n) {
|
|
1366
1368
|
try {
|
|
1367
|
-
const o = [], r = n?.client ?? $, t = e.map((
|
|
1369
|
+
const o = [], r = n?.client ?? $, t = e.map((s) => s.priceInfoObject), a = await r.multiGetObjects({
|
|
1368
1370
|
ids: Array.from(new Set(t)),
|
|
1369
1371
|
options: { showContent: !0 }
|
|
1370
1372
|
});
|
|
1371
|
-
for (const
|
|
1372
|
-
const i =
|
|
1373
|
+
for (const s of a) {
|
|
1374
|
+
const i = s.data;
|
|
1373
1375
|
if (!i || !i.content || i.content.dataType !== "moveObject") {
|
|
1374
1376
|
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
1375
1377
|
continue;
|
|
1376
1378
|
}
|
|
1377
|
-
const
|
|
1378
|
-
if (!
|
|
1379
|
+
const c = e.find((l) => l.priceInfoObject == i.objectId);
|
|
1380
|
+
if (!c) {
|
|
1379
1381
|
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
1380
1382
|
continue;
|
|
1381
1383
|
}
|
|
1382
1384
|
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;
|
|
1383
1385
|
o.push({
|
|
1384
|
-
priceFeedId:
|
|
1385
|
-
priceInfoObject:
|
|
1386
|
+
priceFeedId: c.priceFeedId,
|
|
1387
|
+
priceInfoObject: c.priceInfoObject,
|
|
1386
1388
|
price: y ? "-" + d : d,
|
|
1387
1389
|
conf: v,
|
|
1388
1390
|
publishTime: Number(g),
|
|
1389
|
-
expiration:
|
|
1391
|
+
expiration: c.expiration
|
|
1390
1392
|
});
|
|
1391
1393
|
}
|
|
1392
1394
|
return o;
|
|
@@ -1407,8 +1409,8 @@ async function Se(e, n) {
|
|
|
1407
1409
|
);
|
|
1408
1410
|
continue;
|
|
1409
1411
|
}
|
|
1410
|
-
const
|
|
1411
|
-
t - a.publishTime >
|
|
1412
|
+
const s = a.expiration || 60;
|
|
1413
|
+
t - a.publishTime > s && (console.info(
|
|
1412
1414
|
`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
|
|
1413
1415
|
), o.push(a.priceFeedId));
|
|
1414
1416
|
}
|
|
@@ -1503,8 +1505,8 @@ function Ee(e, n) {
|
|
|
1503
1505
|
"navi-lending-emode-borrow"
|
|
1504
1506
|
].includes(t.type))
|
|
1505
1507
|
return !1;
|
|
1506
|
-
const
|
|
1507
|
-
return o.oracleId ===
|
|
1508
|
+
const s = t[t.type]?.pool;
|
|
1509
|
+
return o.oracleId === s?.oracleId;
|
|
1508
1510
|
}) || n?.pools && n.pools.find((t) => o.oracleId === t.oracleId)));
|
|
1509
1511
|
}
|
|
1510
1512
|
async function mt(e, n, o, r) {
|
|
@@ -1515,11 +1517,11 @@ async function mt(e, n, o, r) {
|
|
|
1515
1517
|
o.forEach((u) => {
|
|
1516
1518
|
a.includes(u.market) || a.push(u.market);
|
|
1517
1519
|
});
|
|
1518
|
-
const
|
|
1520
|
+
const s = await Pe(n, {
|
|
1519
1521
|
...r,
|
|
1520
1522
|
markets: a
|
|
1521
1523
|
}), i = Ee(t, {
|
|
1522
|
-
lendingPositions:
|
|
1524
|
+
lendingPositions: s,
|
|
1523
1525
|
pools: o
|
|
1524
1526
|
});
|
|
1525
1527
|
return await Me(e, i, {
|
|
@@ -1555,11 +1557,11 @@ async function yt(e, n, o, r) {
|
|
|
1555
1557
|
...r,
|
|
1556
1558
|
cacheTime: b
|
|
1557
1559
|
})).some(
|
|
1558
|
-
(
|
|
1560
|
+
(c) => k(c.coinType) === k(a.suiCoinType)
|
|
1559
1561
|
))
|
|
1560
1562
|
throw new Error("Pool does not support flashloan");
|
|
1561
1563
|
if (t.version === 1) {
|
|
1562
|
-
const [
|
|
1564
|
+
const [c, u] = e.moveCall({
|
|
1563
1565
|
target: `${t.package}::lending::flash_loan_with_ctx`,
|
|
1564
1566
|
arguments: [
|
|
1565
1567
|
e.object(t.flashloanConfig),
|
|
@@ -1568,9 +1570,9 @@ async function yt(e, n, o, r) {
|
|
|
1568
1570
|
],
|
|
1569
1571
|
typeArguments: [a.suiCoinType]
|
|
1570
1572
|
});
|
|
1571
|
-
return [
|
|
1573
|
+
return [c, u];
|
|
1572
1574
|
} else {
|
|
1573
|
-
const [
|
|
1575
|
+
const [c, u] = e.moveCall({
|
|
1574
1576
|
target: `${t.package}::lending::flash_loan_with_ctx_v2`,
|
|
1575
1577
|
arguments: [
|
|
1576
1578
|
e.object(t.flashloanConfig),
|
|
@@ -1580,19 +1582,19 @@ async function yt(e, n, o, r) {
|
|
|
1580
1582
|
],
|
|
1581
1583
|
typeArguments: [a.suiCoinType]
|
|
1582
1584
|
});
|
|
1583
|
-
return [
|
|
1585
|
+
return [c, u];
|
|
1584
1586
|
}
|
|
1585
1587
|
}
|
|
1586
1588
|
async function gt(e, n, o, r, t) {
|
|
1587
1589
|
const a = await _({
|
|
1588
1590
|
...t,
|
|
1589
1591
|
cacheTime: b
|
|
1590
|
-
}),
|
|
1592
|
+
}), s = await A(n, t);
|
|
1591
1593
|
if (!(await G({
|
|
1592
1594
|
...t,
|
|
1593
1595
|
cacheTime: b
|
|
1594
1596
|
})).some(
|
|
1595
|
-
(d) => k(d.coinType) === k(
|
|
1597
|
+
(d) => k(d.coinType) === k(s.suiCoinType)
|
|
1596
1598
|
))
|
|
1597
1599
|
throw new Error("Pool does not support flashloan");
|
|
1598
1600
|
const [u] = e.moveCall({
|
|
@@ -1600,19 +1602,19 @@ async function gt(e, n, o, r, t) {
|
|
|
1600
1602
|
arguments: [
|
|
1601
1603
|
e.object("0x06"),
|
|
1602
1604
|
e.object(a.storage),
|
|
1603
|
-
e.object(
|
|
1605
|
+
e.object(s.contract.pool),
|
|
1604
1606
|
h(o, e.object),
|
|
1605
1607
|
h(r, e.object)
|
|
1606
1608
|
],
|
|
1607
|
-
typeArguments: [
|
|
1609
|
+
typeArguments: [s.suiCoinType]
|
|
1608
1610
|
});
|
|
1609
1611
|
return [u];
|
|
1610
1612
|
}
|
|
1611
1613
|
async function ht(e, n, o, r, t, a) {
|
|
1612
|
-
const
|
|
1614
|
+
const s = {
|
|
1613
1615
|
...a,
|
|
1614
1616
|
cacheTime: b
|
|
1615
|
-
}, i = await _(
|
|
1617
|
+
}, i = await _(s), c = await A(n, s), u = await A(r, s);
|
|
1616
1618
|
if (i.version === 1) {
|
|
1617
1619
|
const [d, y] = e.moveCall({
|
|
1618
1620
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
@@ -1623,9 +1625,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1623
1625
|
// Price oracle for asset pricing
|
|
1624
1626
|
e.object(i.storage),
|
|
1625
1627
|
// Protocol storage
|
|
1626
|
-
e.pure.u8(
|
|
1628
|
+
e.pure.u8(c.id),
|
|
1627
1629
|
// Pay asset ID
|
|
1628
|
-
e.object(
|
|
1630
|
+
e.object(c.contract.pool),
|
|
1629
1631
|
// Pay asset pool contract
|
|
1630
1632
|
h(o, e.object),
|
|
1631
1633
|
// Debt repayment amount
|
|
@@ -1640,7 +1642,7 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1640
1642
|
e.object(i.incentiveV3)
|
|
1641
1643
|
// Incentive V3 contract
|
|
1642
1644
|
],
|
|
1643
|
-
typeArguments: [
|
|
1645
|
+
typeArguments: [c.suiCoinType, u.suiCoinType]
|
|
1644
1646
|
});
|
|
1645
1647
|
return [d, y];
|
|
1646
1648
|
} else {
|
|
@@ -1653,9 +1655,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1653
1655
|
// Price oracle for asset pricing
|
|
1654
1656
|
e.object(i.storage),
|
|
1655
1657
|
// Protocol storage
|
|
1656
|
-
e.pure.u8(
|
|
1658
|
+
e.pure.u8(c.id),
|
|
1657
1659
|
// Pay asset ID
|
|
1658
|
-
e.object(
|
|
1660
|
+
e.object(c.contract.pool),
|
|
1659
1661
|
// Pay asset pool contract
|
|
1660
1662
|
h(o, e.object),
|
|
1661
1663
|
// Debt repayment amount
|
|
@@ -1672,7 +1674,7 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1672
1674
|
e.object("0x05")
|
|
1673
1675
|
// SuiSystemState object
|
|
1674
1676
|
],
|
|
1675
|
-
typeArguments: [
|
|
1677
|
+
typeArguments: [c.suiCoinType, u.suiCoinType]
|
|
1676
1678
|
});
|
|
1677
1679
|
return [d, y];
|
|
1678
1680
|
}
|
|
@@ -1682,7 +1684,7 @@ async function De(e, n, o) {
|
|
|
1682
1684
|
...o,
|
|
1683
1685
|
markets: Object.values(E),
|
|
1684
1686
|
cacheTime: b
|
|
1685
|
-
}),
|
|
1687
|
+
}), s = await ne(o);
|
|
1686
1688
|
for (let d of n) {
|
|
1687
1689
|
const y = await _({
|
|
1688
1690
|
...o,
|
|
@@ -1706,9 +1708,9 @@ async function De(e, n, o) {
|
|
|
1706
1708
|
const i = await r.devInspectTransactionBlock({
|
|
1707
1709
|
transactionBlock: t,
|
|
1708
1710
|
sender: e
|
|
1709
|
-
}),
|
|
1711
|
+
}), c = [];
|
|
1710
1712
|
i?.results?.forEach((d) => {
|
|
1711
|
-
|
|
1713
|
+
c.push(
|
|
1712
1714
|
L(
|
|
1713
1715
|
{
|
|
1714
1716
|
results: [d]
|
|
@@ -1729,12 +1731,12 @@ async function De(e, n, o) {
|
|
|
1729
1731
|
);
|
|
1730
1732
|
});
|
|
1731
1733
|
const u = [];
|
|
1732
|
-
return
|
|
1734
|
+
return c.forEach((d, y) => {
|
|
1733
1735
|
const v = n[y];
|
|
1734
1736
|
if (d.length === 5 && Array.isArray(d[0])) {
|
|
1735
1737
|
const g = d[0].length;
|
|
1736
1738
|
for (let l = 0; l < g; l++) {
|
|
1737
|
-
const f =
|
|
1739
|
+
const f = s.find(
|
|
1738
1740
|
(I) => k(I.coinType) === k(d[1][l])
|
|
1739
1741
|
), w = a.find(
|
|
1740
1742
|
(I) => k(I.coinType) === k(d[0][l]) && I.market === v.market
|
|
@@ -1768,12 +1770,12 @@ async function vt(e, n) {
|
|
|
1768
1770
|
owner: e,
|
|
1769
1771
|
market: a.key
|
|
1770
1772
|
})).concat(
|
|
1771
|
-
r.filter((a) => !!o.find((
|
|
1772
|
-
const
|
|
1773
|
+
r.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
|
|
1774
|
+
const s = j(a.marketId);
|
|
1773
1775
|
return {
|
|
1774
1776
|
address: a.accountCap,
|
|
1775
1777
|
owner: e,
|
|
1776
|
-
market:
|
|
1778
|
+
market: s.key,
|
|
1777
1779
|
emodeId: a.emodeId
|
|
1778
1780
|
};
|
|
1779
1781
|
})
|
|
@@ -1783,8 +1785,8 @@ async function vt(e, n) {
|
|
|
1783
1785
|
function wt(e) {
|
|
1784
1786
|
const n = /* @__PURE__ */ new Map();
|
|
1785
1787
|
e.forEach((r) => {
|
|
1786
|
-
const t = r.assetId, a = r.option,
|
|
1787
|
-
n.has(
|
|
1788
|
+
const t = r.assetId, a = r.option, s = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
|
|
1789
|
+
n.has(s) ? n.get(s).total += r.userClaimableReward : n.set(s, {
|
|
1788
1790
|
assetId: t,
|
|
1789
1791
|
rewardType: a,
|
|
1790
1792
|
coinType: r.rewardCoinType,
|
|
@@ -1793,11 +1795,11 @@ function wt(e) {
|
|
|
1793
1795
|
});
|
|
1794
1796
|
});
|
|
1795
1797
|
const o = /* @__PURE__ */ new Map();
|
|
1796
|
-
for (const { assetId: r, rewardType: t, coinType: a, total:
|
|
1797
|
-
const
|
|
1798
|
-
o.has(
|
|
1799
|
-
const u = o.get(
|
|
1800
|
-
u.rewards.set(a, (u.rewards.get(a) || 0) +
|
|
1798
|
+
for (const { assetId: r, rewardType: t, coinType: a, total: s, market: i } of n.values()) {
|
|
1799
|
+
const c = `${r}-${t}-${i}`;
|
|
1800
|
+
o.has(c) || o.set(c, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
1801
|
+
const u = o.get(c);
|
|
1802
|
+
u.rewards.set(a, (u.rewards.get(a) || 0) + s);
|
|
1801
1803
|
}
|
|
1802
1804
|
return Array.from(o.values()).map((r) => ({
|
|
1803
1805
|
assetId: r.assetId,
|
|
@@ -1828,9 +1830,9 @@ async function _t(e, n, o) {
|
|
|
1828
1830
|
markets: Object.values(E),
|
|
1829
1831
|
cacheTime: b
|
|
1830
1832
|
}), t = /* @__PURE__ */ new Map();
|
|
1831
|
-
for (const
|
|
1832
|
-
const { rewardCoinType: i, ruleIds:
|
|
1833
|
-
for (const l of
|
|
1833
|
+
for (const s of n) {
|
|
1834
|
+
const { rewardCoinType: i, ruleIds: c, market: u, owner: d, address: y, emodeId: v } = s, g = `${i}___${y}`;
|
|
1835
|
+
for (const l of c) {
|
|
1834
1836
|
t.has(g) || t.set(g, {
|
|
1835
1837
|
assetIds: [],
|
|
1836
1838
|
ruleIds: [],
|
|
@@ -1841,19 +1843,19 @@ async function _t(e, n, o) {
|
|
|
1841
1843
|
isEMode: typeof v < "u"
|
|
1842
1844
|
});
|
|
1843
1845
|
const f = t.get(g);
|
|
1844
|
-
f.assetIds.push(
|
|
1846
|
+
f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(l), f.amount += s.userClaimableReward;
|
|
1845
1847
|
}
|
|
1846
1848
|
}
|
|
1847
1849
|
const a = [];
|
|
1848
1850
|
for (const [
|
|
1849
|
-
|
|
1850
|
-
{ assetIds: i, ruleIds:
|
|
1851
|
+
s,
|
|
1852
|
+
{ assetIds: i, ruleIds: c, amount: u, market: d, owner: y, address: v, isEMode: g }
|
|
1851
1853
|
] of t) {
|
|
1852
1854
|
const l = await _({
|
|
1853
1855
|
...o,
|
|
1854
1856
|
cacheTime: b,
|
|
1855
1857
|
market: d
|
|
1856
|
-
}), f =
|
|
1858
|
+
}), f = s.split("___")[0], w = r.find((V) => k(V.suiCoinType) === k(f));
|
|
1857
1859
|
if (!w || !w.contract.rewardFundId)
|
|
1858
1860
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${d}`);
|
|
1859
1861
|
const I = w.contract.rewardFundId;
|
|
@@ -1874,7 +1876,7 @@ async function _t(e, n, o) {
|
|
|
1874
1876
|
// Reward fund
|
|
1875
1877
|
e.pure.vector("string", i),
|
|
1876
1878
|
// Asset IDs
|
|
1877
|
-
e.pure.vector("address",
|
|
1879
|
+
e.pure.vector("address", c),
|
|
1878
1880
|
// Rule IDs
|
|
1879
1881
|
h(o.accountCap, e.object)
|
|
1880
1882
|
// Account capability
|
|
@@ -1893,7 +1895,7 @@ async function _t(e, n, o) {
|
|
|
1893
1895
|
// Reward fund
|
|
1894
1896
|
e.pure.vector("string", i),
|
|
1895
1897
|
// Asset IDs
|
|
1896
|
-
e.pure.vector("address",
|
|
1898
|
+
e.pure.vector("address", c),
|
|
1897
1899
|
// Rule IDs
|
|
1898
1900
|
h(v, e.object)
|
|
1899
1901
|
// Account capability
|
|
@@ -1912,7 +1914,7 @@ async function _t(e, n, o) {
|
|
|
1912
1914
|
// Reward fund
|
|
1913
1915
|
e.pure.vector("string", i),
|
|
1914
1916
|
// Asset IDs
|
|
1915
|
-
e.pure.vector("address",
|
|
1917
|
+
e.pure.vector("address", c)
|
|
1916
1918
|
// Rule IDs
|
|
1917
1919
|
],
|
|
1918
1920
|
typeArguments: [f]
|
|
@@ -1957,7 +1959,7 @@ async function _t(e, n, o) {
|
|
|
1957
1959
|
// Reward fund
|
|
1958
1960
|
e.pure.vector("string", i),
|
|
1959
1961
|
// Asset IDs
|
|
1960
|
-
e.pure.vector("address",
|
|
1962
|
+
e.pure.vector("address", c),
|
|
1961
1963
|
// Rule IDs
|
|
1962
1964
|
h(o?.accountCap || v, e.object)
|
|
1963
1965
|
// Account capability
|
|
@@ -1986,7 +1988,7 @@ async function _t(e, n, o) {
|
|
|
1986
1988
|
// Reward fund
|
|
1987
1989
|
e.pure.vector("string", i),
|
|
1988
1990
|
// Asset IDs
|
|
1989
|
-
e.pure.vector("address",
|
|
1991
|
+
e.pure.vector("address", c)
|
|
1990
1992
|
// Rule IDs
|
|
1991
1993
|
],
|
|
1992
1994
|
typeArguments: [f]
|