@naviprotocol/lending 1.4.0-emode.17 → 1.4.0-emode.19
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/account.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +192 -191
- package/dist/index.esm.js.map +1 -1
- package/dist/oracle.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Transaction as U } from "@mysten/sui/transactions";
|
|
2
2
|
import { bcs as d, toHex as re, fromHex as ae } from "@mysten/bcs";
|
|
3
|
-
import { SuiClient as
|
|
3
|
+
import { SuiClient as ce, getFullnodeUrl as ie } from "@mysten/sui/client";
|
|
4
4
|
import se from "lodash.camelcase";
|
|
5
5
|
import { normalizeStructTag as ue } from "@mysten/sui/utils";
|
|
6
6
|
import { SuiPriceServiceConnection as Y, SuiPythClient as le } from "@pythnetwork/pyth-sui-js";
|
|
@@ -129,7 +129,7 @@ const W = d.bytes(32).transform({
|
|
|
129
129
|
borrow_balance: d.u256(),
|
|
130
130
|
/** User's current supply balance */
|
|
131
131
|
supply_balance: d.u256()
|
|
132
|
-
}), me = "1.4.0-emode.
|
|
132
|
+
}), me = "1.4.0-emode.19", $ = {
|
|
133
133
|
version: me
|
|
134
134
|
}, ye = $.version, ge = () => {
|
|
135
135
|
if (typeof process < "u" && process.versions && process.versions.node)
|
|
@@ -143,15 +143,15 @@ const W = d.bytes(32).transform({
|
|
|
143
143
|
}, fe = () => {
|
|
144
144
|
let e = "";
|
|
145
145
|
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${ye} (${ge()})`), e;
|
|
146
|
-
}, H = fe(), S = new
|
|
147
|
-
url:
|
|
146
|
+
}, H = fe(), S = new ce({
|
|
147
|
+
url: ie("mainnet")
|
|
148
148
|
});
|
|
149
149
|
function J(e) {
|
|
150
150
|
const o = [];
|
|
151
151
|
return e.forEach((n, r) => {
|
|
152
152
|
const t = r === e.length - 1;
|
|
153
153
|
if (typeof n == "object" && n !== null && t) {
|
|
154
|
-
const { client: a, disableCache:
|
|
154
|
+
const { client: a, disableCache: i, cacheTime: c, ...s } = n;
|
|
155
155
|
o.push(s);
|
|
156
156
|
} else
|
|
157
157
|
o.push(n);
|
|
@@ -170,10 +170,10 @@ function A(e) {
|
|
|
170
170
|
let o = {};
|
|
171
171
|
return (...n) => {
|
|
172
172
|
const r = n[n.length - 1], t = J(n), a = o[t];
|
|
173
|
-
return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? a.data : e(...n).then((
|
|
174
|
-
data:
|
|
173
|
+
return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? a.data : e(...n).then((i) => (o[t] = {
|
|
174
|
+
data: i,
|
|
175
175
|
cacheAt: Date.now()
|
|
176
|
-
},
|
|
176
|
+
}, i));
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
function F(e) {
|
|
@@ -260,16 +260,16 @@ const R = A(
|
|
|
260
260
|
(t) => t.key
|
|
261
261
|
)}`, r = await fetch(n, { headers: V }).then((t) => t.json());
|
|
262
262
|
return r.data.forEach((t) => {
|
|
263
|
-
const
|
|
263
|
+
const i = r.meta.emodes.filter((f) => {
|
|
264
264
|
const _ = j(f.marketId);
|
|
265
265
|
return t.market === _.key && f.isActive;
|
|
266
266
|
}).filter((f) => !!f.assets.find((_) => _.assetId === t.id));
|
|
267
|
-
t.emodes =
|
|
268
|
-
const
|
|
267
|
+
t.emodes = i;
|
|
268
|
+
const c = l(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), s = l(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), u = l(c).multipliedBy(t.oracle.price).toString(), m = l(s).multipliedBy(t.oracle.price).toString(), g = l(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), v = l.max(
|
|
269
269
|
l(t.borrowedAmount),
|
|
270
270
|
l(t.validBorrowAmount)
|
|
271
271
|
).shiftedBy(-9).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), w = l(g).multipliedBy(t.oracle.price).toString(), p = l(v).multipliedBy(t.oracle.price).toString();
|
|
272
|
-
t.poolSupplyAmount =
|
|
272
|
+
t.poolSupplyAmount = c, t.poolBorrowAmount = s, t.poolSupplyValue = u, t.poolBorrowValue = m, t.poolSupplyCapAmount = g, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = w, t.poolBorrowCapValue = p;
|
|
273
273
|
}), r.data;
|
|
274
274
|
}
|
|
275
275
|
)
|
|
@@ -312,14 +312,14 @@ async function be(e, o, n, r) {
|
|
|
312
312
|
}), a = await B(o, r);
|
|
313
313
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
314
314
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
315
|
-
const
|
|
316
|
-
if (b(a.suiCoinType) === b("0x2::sui::SUI") &&
|
|
315
|
+
const i = typeof n == "object" && n.$kind === "GasCoin";
|
|
316
|
+
if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
|
|
317
317
|
if (!r?.amount)
|
|
318
318
|
throw new Error("Amount is required for sui coin");
|
|
319
319
|
n = e.splitCoins(n, [r.amount]);
|
|
320
320
|
}
|
|
321
|
-
let
|
|
322
|
-
return typeof r?.amount < "u" ?
|
|
321
|
+
let c;
|
|
322
|
+
return typeof r?.amount < "u" ? c = y(r.amount, e.pure.u64) : c = e.moveCall({
|
|
323
323
|
target: "0x2::coin::value",
|
|
324
324
|
arguments: [y(n, e.object)],
|
|
325
325
|
typeArguments: [a.suiCoinType]
|
|
@@ -344,7 +344,7 @@ async function be(e, o, n, r) {
|
|
|
344
344
|
e.object(a.contract.pool),
|
|
345
345
|
e.pure.u8(a.id),
|
|
346
346
|
y(n, e.object),
|
|
347
|
-
|
|
347
|
+
c,
|
|
348
348
|
e.object(t.incentiveV2),
|
|
349
349
|
e.object(t.incentiveV3)
|
|
350
350
|
],
|
|
@@ -358,8 +358,8 @@ async function Ye(e, o, n, r) {
|
|
|
358
358
|
const t = await k({
|
|
359
359
|
...r,
|
|
360
360
|
cacheTime: h
|
|
361
|
-
}), a = await B(o, r),
|
|
362
|
-
let
|
|
361
|
+
}), a = await B(o, r), i = y(n, e.pure.u64);
|
|
362
|
+
let c;
|
|
363
363
|
if (t.version === 1)
|
|
364
364
|
if (r?.accountCap) {
|
|
365
365
|
const [u] = e.moveCall({
|
|
@@ -370,14 +370,14 @@ async function Ye(e, o, n, r) {
|
|
|
370
370
|
e.object(t.storage),
|
|
371
371
|
e.object(a.contract.pool),
|
|
372
372
|
e.pure.u8(a.id),
|
|
373
|
-
|
|
373
|
+
i,
|
|
374
374
|
e.object(t.incentiveV2),
|
|
375
375
|
e.object(t.incentiveV3),
|
|
376
376
|
y(r.accountCap, e.object)
|
|
377
377
|
],
|
|
378
378
|
typeArguments: [a.suiCoinType]
|
|
379
379
|
});
|
|
380
|
-
|
|
380
|
+
c = u;
|
|
381
381
|
} else {
|
|
382
382
|
const [u] = e.moveCall({
|
|
383
383
|
target: `${t.package}::incentive_v3::withdraw`,
|
|
@@ -387,13 +387,13 @@ async function Ye(e, o, n, r) {
|
|
|
387
387
|
e.object(t.storage),
|
|
388
388
|
e.object(a.contract.pool),
|
|
389
389
|
e.pure.u8(a.id),
|
|
390
|
-
|
|
390
|
+
i,
|
|
391
391
|
e.object(t.incentiveV2),
|
|
392
392
|
e.object(t.incentiveV3)
|
|
393
393
|
],
|
|
394
394
|
typeArguments: [a.suiCoinType]
|
|
395
395
|
});
|
|
396
|
-
|
|
396
|
+
c = u;
|
|
397
397
|
}
|
|
398
398
|
else if (r?.accountCap) {
|
|
399
399
|
const [u] = e.moveCall({
|
|
@@ -404,7 +404,7 @@ async function Ye(e, o, n, r) {
|
|
|
404
404
|
e.object(t.storage),
|
|
405
405
|
e.object(a.contract.pool),
|
|
406
406
|
e.pure.u8(a.id),
|
|
407
|
-
|
|
407
|
+
i,
|
|
408
408
|
e.object(t.incentiveV2),
|
|
409
409
|
e.object(t.incentiveV3),
|
|
410
410
|
y(r.accountCap, e.object),
|
|
@@ -412,7 +412,7 @@ async function Ye(e, o, n, r) {
|
|
|
412
412
|
],
|
|
413
413
|
typeArguments: [a.suiCoinType]
|
|
414
414
|
});
|
|
415
|
-
|
|
415
|
+
c = u;
|
|
416
416
|
} else {
|
|
417
417
|
const [u] = e.moveCall({
|
|
418
418
|
target: `${t.package}::incentive_v3::withdraw_v2`,
|
|
@@ -422,18 +422,18 @@ async function Ye(e, o, n, r) {
|
|
|
422
422
|
e.object(t.storage),
|
|
423
423
|
e.object(a.contract.pool),
|
|
424
424
|
e.pure.u8(a.id),
|
|
425
|
-
|
|
425
|
+
i,
|
|
426
426
|
e.object(t.incentiveV2),
|
|
427
427
|
e.object(t.incentiveV3),
|
|
428
428
|
e.object("0x05")
|
|
429
429
|
],
|
|
430
430
|
typeArguments: [a.suiCoinType]
|
|
431
431
|
});
|
|
432
|
-
|
|
432
|
+
c = u;
|
|
433
433
|
}
|
|
434
434
|
return e.moveCall({
|
|
435
435
|
target: "0x2::coin::from_balance",
|
|
436
|
-
arguments: [
|
|
436
|
+
arguments: [c],
|
|
437
437
|
typeArguments: [a.suiCoinType]
|
|
438
438
|
});
|
|
439
439
|
}
|
|
@@ -444,8 +444,8 @@ async function Je(e, o, n, r) {
|
|
|
444
444
|
}), a = await B(o, r);
|
|
445
445
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
446
446
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
447
|
-
const
|
|
448
|
-
let
|
|
447
|
+
const i = y(n, e.pure.u64);
|
|
448
|
+
let c;
|
|
449
449
|
if (t.version === 1)
|
|
450
450
|
if (r?.accountCap) {
|
|
451
451
|
const [u] = e.moveCall({
|
|
@@ -456,14 +456,14 @@ async function Je(e, o, n, r) {
|
|
|
456
456
|
e.object(t.storage),
|
|
457
457
|
e.object(a.contract.pool),
|
|
458
458
|
e.pure.u8(a.id),
|
|
459
|
-
|
|
459
|
+
i,
|
|
460
460
|
e.object(t.incentiveV2),
|
|
461
461
|
e.object(t.incentiveV3),
|
|
462
462
|
y(r.accountCap, e.object)
|
|
463
463
|
],
|
|
464
464
|
typeArguments: [a.suiCoinType]
|
|
465
465
|
});
|
|
466
|
-
|
|
466
|
+
c = u;
|
|
467
467
|
} else {
|
|
468
468
|
const [u] = e.moveCall({
|
|
469
469
|
target: `${t.package}::incentive_v3::borrow`,
|
|
@@ -473,13 +473,13 @@ async function Je(e, o, n, r) {
|
|
|
473
473
|
e.object(t.storage),
|
|
474
474
|
e.object(a.contract.pool),
|
|
475
475
|
e.pure.u8(a.id),
|
|
476
|
-
|
|
476
|
+
i,
|
|
477
477
|
e.object(t.incentiveV2),
|
|
478
478
|
e.object(t.incentiveV3)
|
|
479
479
|
],
|
|
480
480
|
typeArguments: [a.suiCoinType]
|
|
481
481
|
});
|
|
482
|
-
|
|
482
|
+
c = u;
|
|
483
483
|
}
|
|
484
484
|
else if (r?.accountCap) {
|
|
485
485
|
const [u] = e.moveCall({
|
|
@@ -490,7 +490,7 @@ async function Je(e, o, n, r) {
|
|
|
490
490
|
e.object(t.storage),
|
|
491
491
|
e.object(a.contract.pool),
|
|
492
492
|
e.pure.u8(a.id),
|
|
493
|
-
|
|
493
|
+
i,
|
|
494
494
|
e.object(t.incentiveV2),
|
|
495
495
|
e.object(t.incentiveV3),
|
|
496
496
|
y(r.accountCap, e.object),
|
|
@@ -498,7 +498,7 @@ async function Je(e, o, n, r) {
|
|
|
498
498
|
],
|
|
499
499
|
typeArguments: [a.suiCoinType]
|
|
500
500
|
});
|
|
501
|
-
|
|
501
|
+
c = u;
|
|
502
502
|
} else {
|
|
503
503
|
const [u] = e.moveCall({
|
|
504
504
|
target: `${t.package}::incentive_v3::borrow_v2`,
|
|
@@ -508,18 +508,18 @@ async function Je(e, o, n, r) {
|
|
|
508
508
|
e.object(t.storage),
|
|
509
509
|
e.object(a.contract.pool),
|
|
510
510
|
e.pure.u8(a.id),
|
|
511
|
-
|
|
511
|
+
i,
|
|
512
512
|
e.object(t.incentiveV2),
|
|
513
513
|
e.object(t.incentiveV3),
|
|
514
514
|
e.object("0x05")
|
|
515
515
|
],
|
|
516
516
|
typeArguments: [a.suiCoinType]
|
|
517
517
|
});
|
|
518
|
-
|
|
518
|
+
c = u;
|
|
519
519
|
}
|
|
520
520
|
return e.moveCall({
|
|
521
521
|
target: "0x2::coin::from_balance",
|
|
522
|
-
arguments: [e.object(
|
|
522
|
+
arguments: [e.object(c)],
|
|
523
523
|
typeArguments: [a.suiCoinType]
|
|
524
524
|
});
|
|
525
525
|
}
|
|
@@ -527,14 +527,14 @@ async function Qe(e, o, n, r) {
|
|
|
527
527
|
const t = await k({
|
|
528
528
|
...r,
|
|
529
529
|
cacheTime: h
|
|
530
|
-
}), a = await B(o, r),
|
|
531
|
-
if (b(a.suiCoinType) === b("0x2::sui::SUI") &&
|
|
530
|
+
}), a = await B(o, r), i = typeof n == "object" && n.$kind === "GasCoin";
|
|
531
|
+
if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
|
|
532
532
|
if (!r?.amount)
|
|
533
533
|
throw new Error("Amount is required for sui coin");
|
|
534
534
|
n = e.splitCoins(n, [r.amount]);
|
|
535
535
|
}
|
|
536
|
-
let
|
|
537
|
-
if (typeof r?.amount < "u" ?
|
|
536
|
+
let c;
|
|
537
|
+
if (typeof r?.amount < "u" ? c = y(r.amount, e.pure.u64) : c = e.moveCall({
|
|
538
538
|
target: "0x2::coin::value",
|
|
539
539
|
arguments: [y(n, e.object)],
|
|
540
540
|
typeArguments: [a.suiCoinType]
|
|
@@ -569,7 +569,7 @@ async function Qe(e, o, n, r) {
|
|
|
569
569
|
e.object(a.contract.pool),
|
|
570
570
|
e.pure.u8(a.id),
|
|
571
571
|
y(n, e.object),
|
|
572
|
-
|
|
572
|
+
c,
|
|
573
573
|
e.object(t.incentiveV2),
|
|
574
574
|
e.object(t.incentiveV3)
|
|
575
575
|
],
|
|
@@ -584,21 +584,21 @@ const Xe = A(
|
|
|
584
584
|
});
|
|
585
585
|
if (e?.address && typeof e?.asset < "u")
|
|
586
586
|
try {
|
|
587
|
-
const t = await B(e.asset, e), a = e?.client ?? S,
|
|
588
|
-
|
|
587
|
+
const t = await B(e.asset, e), a = e?.client ?? S, i = new U();
|
|
588
|
+
i.moveCall({
|
|
589
589
|
target: `${o.package}::incentive_v3::get_borrow_fee_v2`,
|
|
590
590
|
arguments: [
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
591
|
+
i.object(o.incentiveV3),
|
|
592
|
+
i.pure.address(e.address),
|
|
593
|
+
i.pure.u8(t.id),
|
|
594
|
+
i.pure.u64(1e4)
|
|
595
595
|
],
|
|
596
596
|
typeArguments: []
|
|
597
597
|
});
|
|
598
|
-
const
|
|
599
|
-
transactionBlock:
|
|
598
|
+
const c = await a.devInspectTransactionBlock({
|
|
599
|
+
transactionBlock: i,
|
|
600
600
|
sender: e.address
|
|
601
|
-
}), s = O(
|
|
601
|
+
}), s = O(c, [C.u64()]);
|
|
602
602
|
return (Number(s[0]) || 0) / 100;
|
|
603
603
|
} catch (t) {
|
|
604
604
|
console.error(t);
|
|
@@ -629,40 +629,40 @@ class ke {
|
|
|
629
629
|
}
|
|
630
630
|
addPools(o) {
|
|
631
631
|
const n = q(this.pools), r = z(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
632
|
-
let
|
|
632
|
+
let i = l(0), c = l(0);
|
|
633
633
|
o.forEach((s) => {
|
|
634
634
|
if (!this.checkMarket(s.market)) {
|
|
635
635
|
console.warn(`Pool is not in market ${this.config.name}`, s);
|
|
636
636
|
return;
|
|
637
637
|
}
|
|
638
|
-
n[s.uniqueId] || this.pools.push(s), s
|
|
638
|
+
n[s.uniqueId] || this.pools.push(s), s?.emodes?.forEach((m) => {
|
|
639
639
|
r[m.uniqueId] || this.emodes.push(m), m.assets.forEach((g) => {
|
|
640
640
|
g.isDebt && t.add(s.uniqueId), g.isCollateral && a.add(s.uniqueId);
|
|
641
641
|
});
|
|
642
|
-
}),
|
|
642
|
+
}), c = c.plus(s.poolBorrowValue), i = i.plus(s.poolSupplyValue);
|
|
643
643
|
}), this.poolMap = q(this.pools, "id"), this.emodeMap = z(this.emodes, "emodeId"), this.emodes.forEach((s) => {
|
|
644
644
|
const u = this.getEModePools(s.emodeId);
|
|
645
645
|
this.emodePools.push(...u);
|
|
646
646
|
}), this._overview = {
|
|
647
|
-
marketTotalSupplyValue:
|
|
648
|
-
marketTotalBorrowValue:
|
|
647
|
+
marketTotalSupplyValue: i.toString(),
|
|
648
|
+
marketTotalBorrowValue: c.toString()
|
|
649
649
|
}, this.emodeBorrowablePools = this.pools.filter((s) => t.has(s.uniqueId)), this.emodeSupplyablePools = this.pools.filter((s) => a.has(s.uniqueId));
|
|
650
650
|
}
|
|
651
651
|
getEMode(o) {
|
|
652
652
|
return this.emodeMap[o] || null;
|
|
653
653
|
}
|
|
654
654
|
getEModeRelatePools(o, n) {
|
|
655
|
-
const { collateral: r, debt: t, emodeId: a } = n || {},
|
|
656
|
-
return o.emodes.forEach((
|
|
657
|
-
typeof a == "number" && a !==
|
|
658
|
-
typeof r == "boolean" && r && s.isCollateral && s.assetId === o.id &&
|
|
655
|
+
const { collateral: r, debt: t, emodeId: a } = n || {}, i = [];
|
|
656
|
+
return o.emodes.forEach((c) => {
|
|
657
|
+
typeof a == "number" && a !== c.emodeId || c.assets.forEach((s) => {
|
|
658
|
+
typeof r == "boolean" && r && s.isCollateral && s.assetId === o.id && i.push(this.poolMap[s.assetId]), typeof t == "boolean" && t && s.isDebt && s.assetId === o.id && i.push(this.poolMap[s.assetId]);
|
|
659
659
|
});
|
|
660
|
-
}),
|
|
660
|
+
}), i;
|
|
661
661
|
}
|
|
662
662
|
getEModePools(o) {
|
|
663
663
|
const n = this.getEMode(o);
|
|
664
664
|
return n ? n.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
|
|
665
|
-
const a = n.assets.find((
|
|
665
|
+
const a = n.assets.find((i) => i.assetId === t.id);
|
|
666
666
|
return {
|
|
667
667
|
...t,
|
|
668
668
|
emode: {
|
|
@@ -692,7 +692,7 @@ const j = (e) => {
|
|
|
692
692
|
markets: e
|
|
693
693
|
});
|
|
694
694
|
return e.map((r) => {
|
|
695
|
-
const t = j(r), a = n.filter((
|
|
695
|
+
const t = j(r), a = n.filter((i) => i.market === t.key);
|
|
696
696
|
return new ke(r, a);
|
|
697
697
|
});
|
|
698
698
|
}
|
|
@@ -768,12 +768,12 @@ async function et(e, o, n) {
|
|
|
768
768
|
...n,
|
|
769
769
|
accountCap: t
|
|
770
770
|
});
|
|
771
|
-
const a = await j(n?.market || D),
|
|
771
|
+
const a = await j(n?.market || D), i = await je(e, t, n);
|
|
772
772
|
return e.moveCall({
|
|
773
773
|
target: `${r.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
774
774
|
arguments: [
|
|
775
775
|
e.object(r.emode.contract.registryObject),
|
|
776
|
-
|
|
776
|
+
i,
|
|
777
777
|
y(a.id, e.pure.u64),
|
|
778
778
|
y(o, e.pure.u64)
|
|
779
779
|
]
|
|
@@ -790,11 +790,11 @@ const X = A(
|
|
|
790
790
|
target: `${n.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
791
791
|
arguments: [r.object(n.emode.contract.registryObject), r.pure.address(e)]
|
|
792
792
|
});
|
|
793
|
-
const
|
|
793
|
+
const i = (await t.devInspectTransactionBlock({
|
|
794
794
|
transactionBlock: r,
|
|
795
795
|
sender: e
|
|
796
|
-
})).results[0].returnValues,
|
|
797
|
-
return
|
|
796
|
+
})).results[0].returnValues, c = C.vector(C.u64()).parse(Uint8Array.from(i[0][0])), s = C.vector(C.u64()).parse(Uint8Array.from(i[1][0])), u = C.vector(C.Address).parse(Uint8Array.from(i[2][0]));
|
|
797
|
+
return c.map((m, g) => ({
|
|
798
798
|
marketId: Number(m),
|
|
799
799
|
emodeId: Number(s[g]),
|
|
800
800
|
accountCap: u[g].toString()
|
|
@@ -808,33 +808,33 @@ function tt(e) {
|
|
|
808
808
|
function ot(e, o, n) {
|
|
809
809
|
const r = typeof n?.balance == "number", t = r ? n.balance : 0;
|
|
810
810
|
let a = 0;
|
|
811
|
-
const
|
|
812
|
-
let
|
|
811
|
+
const i = [];
|
|
812
|
+
let c = "";
|
|
813
813
|
if (o.sort((s, u) => Number(u.balance) - Number(s.balance)).forEach((s) => {
|
|
814
814
|
if (!(r && a >= t) && Number(s.balance) !== 0) {
|
|
815
|
-
if (
|
|
815
|
+
if (c || (c = s.coinType), c !== s.coinType)
|
|
816
816
|
throw new Error("All coins must be of the same type");
|
|
817
|
-
a += Number(s.balance),
|
|
817
|
+
a += Number(s.balance), i.push(s.coinObjectId);
|
|
818
818
|
}
|
|
819
|
-
}),
|
|
819
|
+
}), i.length === 0)
|
|
820
820
|
throw new Error("No coins to merge");
|
|
821
821
|
if (r && a < t)
|
|
822
822
|
throw new Error(
|
|
823
823
|
`Balance is less than the specified balance: ${a} < ${t}`
|
|
824
824
|
);
|
|
825
|
-
return b(
|
|
825
|
+
return b(c) === b("0x2::sui::SUI") && n?.useGasCoin ? r ? e.splitCoins(e.gas, [e.pure.u64(t)]) : e.gas : (i.length === 1 ? e.object(i[0]) : e.mergeCoins(i[0], i.slice(1)), r ? e.splitCoins(i[0], [e.pure.u64(t)]) : i[0]);
|
|
826
826
|
}
|
|
827
|
-
async function Z(e, o, n, r, t, a,
|
|
828
|
-
const
|
|
829
|
-
...
|
|
827
|
+
async function Z(e, o, n, r, t, a, i) {
|
|
828
|
+
const c = await k({
|
|
829
|
+
...i,
|
|
830
830
|
cacheTime: h
|
|
831
|
-
}), s = await B(n,
|
|
831
|
+
}), s = await B(n, i);
|
|
832
832
|
return e.moveCall({
|
|
833
|
-
target: `${
|
|
833
|
+
target: `${c.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
834
834
|
arguments: [
|
|
835
835
|
e.object("0x06"),
|
|
836
|
-
e.object(
|
|
837
|
-
e.object(
|
|
836
|
+
e.object(c.storage),
|
|
837
|
+
e.object(c.oracle.priceOracle),
|
|
838
838
|
we(e, s),
|
|
839
839
|
y(o, e.pure.address),
|
|
840
840
|
y(s.id, e.pure.u8),
|
|
@@ -852,7 +852,7 @@ async function x(e, o, n) {
|
|
|
852
852
|
const r = new U(), t = n?.client ?? S, a = await R({
|
|
853
853
|
...n,
|
|
854
854
|
markets: Object.values(E)
|
|
855
|
-
}),
|
|
855
|
+
}), i = q(a);
|
|
856
856
|
for (let m of o) {
|
|
857
857
|
const g = await k({
|
|
858
858
|
...n,
|
|
@@ -873,7 +873,7 @@ async function x(e, o, n) {
|
|
|
873
873
|
m.forEach((p) => {
|
|
874
874
|
if (p.supply_balance === "0" && p.borrow_balance === "0")
|
|
875
875
|
return;
|
|
876
|
-
const f =
|
|
876
|
+
const f = i[`${w.key}-${p.asset_id}`];
|
|
877
877
|
if (!f)
|
|
878
878
|
return;
|
|
879
879
|
const _ = G(
|
|
@@ -914,19 +914,19 @@ async function rt(e, o) {
|
|
|
914
914
|
}
|
|
915
915
|
async function at(e, o, n, r) {
|
|
916
916
|
const t = r?.client ?? S, a = new U();
|
|
917
|
-
let
|
|
917
|
+
let i = 0, c = 0;
|
|
918
918
|
const s = await B(o, r);
|
|
919
919
|
if (n.forEach((v) => {
|
|
920
|
-
v.type === N.Supply ?
|
|
921
|
-
}),
|
|
920
|
+
v.type === N.Supply ? i += v.amount : v.type === N.Withdraw ? i -= v.amount : v.type === N.Borrow ? c += v.amount : v.type === N.Repay && (c -= v.amount);
|
|
921
|
+
}), i * c < 0)
|
|
922
922
|
throw new Error("Invalid operations");
|
|
923
|
-
const u =
|
|
923
|
+
const u = i > 0 || c > 0;
|
|
924
924
|
await Z(
|
|
925
925
|
a,
|
|
926
926
|
e,
|
|
927
927
|
s,
|
|
928
|
-
Math.abs(c),
|
|
929
928
|
Math.abs(i),
|
|
929
|
+
Math.abs(c),
|
|
930
930
|
u,
|
|
931
931
|
r
|
|
932
932
|
);
|
|
@@ -936,7 +936,7 @@ async function at(e, o, n, r) {
|
|
|
936
936
|
}), g = O(m, [C.u256()]);
|
|
937
937
|
return Q(Number(g[0]) || 0);
|
|
938
938
|
}
|
|
939
|
-
const
|
|
939
|
+
const ct = I(
|
|
940
940
|
async (e, o) => {
|
|
941
941
|
const n = new URLSearchParams();
|
|
942
942
|
o?.cursor && n.set("cursor", o.cursor), n.set("userAddress", e);
|
|
@@ -944,7 +944,7 @@ const it = I(
|
|
|
944
944
|
return (await fetch(r, { headers: V }).then((a) => a.json())).data;
|
|
945
945
|
}
|
|
946
946
|
);
|
|
947
|
-
async function
|
|
947
|
+
async function it(e, o) {
|
|
948
948
|
let n = null;
|
|
949
949
|
const r = [], t = o?.client ?? S;
|
|
950
950
|
do {
|
|
@@ -966,86 +966,86 @@ async function ct(e, o) {
|
|
|
966
966
|
}
|
|
967
967
|
const Be = A(
|
|
968
968
|
async (e, o) => {
|
|
969
|
-
const n = [], r = (o?.markets || Object.keys(E)).map((
|
|
969
|
+
const n = [], r = (o?.markets || Object.keys(E)).map((c) => j(c)), t = await X(e, o), a = r.map((c) => ({
|
|
970
970
|
address: e,
|
|
971
|
-
market:
|
|
971
|
+
market: c.key
|
|
972
972
|
})).concat(
|
|
973
|
-
t.filter((
|
|
974
|
-
address:
|
|
975
|
-
market: j(
|
|
976
|
-
emodeId:
|
|
973
|
+
t.filter((c) => !!r.find((s) => s.id === c.marketId)).map((c) => ({
|
|
974
|
+
address: c.accountCap,
|
|
975
|
+
market: j(c.marketId).key,
|
|
976
|
+
emodeId: c.emodeId
|
|
977
977
|
}))
|
|
978
978
|
);
|
|
979
|
-
return (await x(e, a, o)).forEach((
|
|
980
|
-
const s =
|
|
981
|
-
const m = j(
|
|
982
|
-
return u.emodeId ===
|
|
979
|
+
return (await x(e, a, o)).forEach((c) => {
|
|
980
|
+
const s = c.emodeId ? t.find((u) => {
|
|
981
|
+
const m = j(c.market);
|
|
982
|
+
return u.emodeId === c.emodeId && u.marketId === m.id;
|
|
983
983
|
}) : void 0;
|
|
984
984
|
if (s) {
|
|
985
|
-
if (l(
|
|
986
|
-
const u = l(
|
|
985
|
+
if (l(c.supplyBalance).gt(0)) {
|
|
986
|
+
const u = l(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
|
|
987
987
|
n.push({
|
|
988
|
-
id: `${
|
|
988
|
+
id: `${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply`,
|
|
989
989
|
wallet: e,
|
|
990
990
|
protocol: "navi",
|
|
991
|
-
market:
|
|
991
|
+
market: c.market,
|
|
992
992
|
type: "navi-lending-emode-supply",
|
|
993
993
|
"navi-lending-emode-supply": {
|
|
994
994
|
amount: u.toString(),
|
|
995
|
-
pool: K(
|
|
996
|
-
token:
|
|
997
|
-
valueUSD: u.multipliedBy(
|
|
995
|
+
pool: K(c.pool, s),
|
|
996
|
+
token: c.pool.token,
|
|
997
|
+
valueUSD: u.multipliedBy(c.pool.oracle.price).toString(),
|
|
998
998
|
emodeCap: s
|
|
999
999
|
}
|
|
1000
1000
|
});
|
|
1001
1001
|
}
|
|
1002
|
-
if (l(
|
|
1003
|
-
const u = l(
|
|
1002
|
+
if (l(c.borrowBalance).gt(0)) {
|
|
1003
|
+
const u = l(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
|
|
1004
1004
|
n.push({
|
|
1005
|
-
id: `${
|
|
1005
|
+
id: `${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow`,
|
|
1006
1006
|
wallet: e,
|
|
1007
1007
|
protocol: "navi",
|
|
1008
|
-
market:
|
|
1008
|
+
market: c.market,
|
|
1009
1009
|
type: "navi-lending-emode-borrow",
|
|
1010
1010
|
"navi-lending-emode-borrow": {
|
|
1011
1011
|
amount: u.toString(),
|
|
1012
|
-
pool: K(
|
|
1013
|
-
token:
|
|
1014
|
-
valueUSD: u.multipliedBy(
|
|
1012
|
+
pool: K(c.pool, s),
|
|
1013
|
+
token: c.pool.token,
|
|
1014
|
+
valueUSD: u.multipliedBy(c.pool.oracle.price).toString(),
|
|
1015
1015
|
emodeCap: s
|
|
1016
1016
|
}
|
|
1017
1017
|
});
|
|
1018
1018
|
}
|
|
1019
1019
|
} else {
|
|
1020
|
-
if (l(
|
|
1021
|
-
const u = l(
|
|
1020
|
+
if (l(c.supplyBalance).gt(0)) {
|
|
1021
|
+
const u = l(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
|
|
1022
1022
|
n.push({
|
|
1023
|
-
id: `${
|
|
1023
|
+
id: `${c.pool.uniqueId}_navi-lending-supply`,
|
|
1024
1024
|
wallet: e,
|
|
1025
1025
|
protocol: "navi",
|
|
1026
1026
|
type: "navi-lending-supply",
|
|
1027
|
-
market:
|
|
1027
|
+
market: c.market,
|
|
1028
1028
|
"navi-lending-supply": {
|
|
1029
1029
|
amount: u.toString(),
|
|
1030
|
-
pool:
|
|
1031
|
-
token:
|
|
1032
|
-
valueUSD: u.multipliedBy(
|
|
1030
|
+
pool: c.pool,
|
|
1031
|
+
token: c.pool.token,
|
|
1032
|
+
valueUSD: u.multipliedBy(c.pool.oracle.price).toString()
|
|
1033
1033
|
}
|
|
1034
1034
|
});
|
|
1035
1035
|
}
|
|
1036
|
-
if (l(
|
|
1037
|
-
const u = l(
|
|
1036
|
+
if (l(c.borrowBalance).gt(0)) {
|
|
1037
|
+
const u = l(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
|
|
1038
1038
|
n.push({
|
|
1039
|
-
id: `${
|
|
1039
|
+
id: `${c.pool.uniqueId}_navi-lending-borrow`,
|
|
1040
1040
|
wallet: e,
|
|
1041
1041
|
protocol: "navi",
|
|
1042
|
-
market:
|
|
1042
|
+
market: c.market,
|
|
1043
1043
|
type: "navi-lending-borrow",
|
|
1044
1044
|
"navi-lending-borrow": {
|
|
1045
1045
|
amount: u.toString(),
|
|
1046
|
-
pool:
|
|
1047
|
-
token:
|
|
1048
|
-
valueUSD: u.multipliedBy(
|
|
1046
|
+
pool: c.pool,
|
|
1047
|
+
token: c.pool.token,
|
|
1048
|
+
valueUSD: u.multipliedBy(c.pool.oracle.price).toString()
|
|
1049
1049
|
}
|
|
1050
1050
|
});
|
|
1051
1051
|
}
|
|
@@ -1209,7 +1209,7 @@ class M {
|
|
|
1209
1209
|
}
|
|
1210
1210
|
getPositionsOverview(o) {
|
|
1211
1211
|
const n = {}, r = {};
|
|
1212
|
-
let t = new l(0), a = new l(0),
|
|
1212
|
+
let t = new l(0), a = new l(0), i = new l(0), c = new l(0), s = new l(0), u = new l(0);
|
|
1213
1213
|
o.forEach((w) => {
|
|
1214
1214
|
if (w.type === "navi-lending-supply") {
|
|
1215
1215
|
const p = w["navi-lending-supply"];
|
|
@@ -1233,35 +1233,35 @@ class M {
|
|
|
1233
1233
|
}), o.forEach((w) => {
|
|
1234
1234
|
if (w.type === "navi-lending-supply") {
|
|
1235
1235
|
const p = w["navi-lending-supply"], f = p.pool.supplyIncentiveApyInfo.apy;
|
|
1236
|
-
|
|
1236
|
+
i = i.plus(
|
|
1237
1237
|
new l(p.valueUSD).dividedBy(t).multipliedBy(new l(f).dividedBy(100))
|
|
1238
1238
|
), n[p.pool.suiCoinType] = l(n[p.pool.suiCoinType] || 0).plus(p.amount).toString();
|
|
1239
1239
|
} else if (w.type === "navi-lending-borrow") {
|
|
1240
1240
|
const p = w["navi-lending-borrow"], f = p.pool.borrowIncentiveApyInfo.apy;
|
|
1241
|
-
a.gt(0) && (
|
|
1241
|
+
a.gt(0) && (c = c.plus(
|
|
1242
1242
|
new l(p.valueUSD).dividedBy(a).multipliedBy(new l(f).dividedBy(100))
|
|
1243
1243
|
)), r[p.pool.suiCoinType] = l(r[p.pool.suiCoinType] || 0).plus(p.amount).toString();
|
|
1244
1244
|
} else if (w.type === "navi-lending-emode-supply") {
|
|
1245
1245
|
const p = w["navi-lending-emode-supply"], f = p.pool.supplyIncentiveApyInfo.apy;
|
|
1246
|
-
t.gt(0) && (
|
|
1246
|
+
t.gt(0) && (i = i.plus(
|
|
1247
1247
|
new l(p.valueUSD).dividedBy(t).multipliedBy(new l(f).dividedBy(100))
|
|
1248
1248
|
)), n[p.pool.suiCoinType] = l(n[p.pool.suiCoinType] || 0).plus(p.amount).toString();
|
|
1249
1249
|
} else if (w.type === "navi-lending-emode-borrow") {
|
|
1250
1250
|
const p = w["navi-lending-emode-borrow"], f = p.pool.borrowIncentiveApyInfo.apy;
|
|
1251
|
-
a.gt(0) && (
|
|
1251
|
+
a.gt(0) && (c = c.plus(
|
|
1252
1252
|
new l(p.valueUSD).dividedBy(a).multipliedBy(new l(f).dividedBy(100))
|
|
1253
1253
|
)), r[p.pool.suiCoinType] = l(r[p.pool.suiCoinType] || 0).plus(p.amount).toString();
|
|
1254
1254
|
}
|
|
1255
1255
|
});
|
|
1256
|
-
const m = t.minus(a), g = t.minus(a).eq(0) ? new l(0) : t.multipliedBy(
|
|
1256
|
+
const m = t.minus(a), g = t.minus(a).eq(0) ? new l(0) : t.multipliedBy(i).minus(a.multipliedBy(c)).div(t.minus(a));
|
|
1257
1257
|
return {
|
|
1258
1258
|
hf: a.toNumber() !== 0 ? s.dividedBy(a).toNumber() : 1 / 0,
|
|
1259
1259
|
netVaule: m.toString(),
|
|
1260
1260
|
netWorthApr: g.toString(),
|
|
1261
1261
|
totalSupplyValue: t.toString(),
|
|
1262
1262
|
totalBorrowValue: a.toString(),
|
|
1263
|
-
totalsupplyApy:
|
|
1264
|
-
totalBorrowApy:
|
|
1263
|
+
totalsupplyApy: i.toString(),
|
|
1264
|
+
totalBorrowApy: c.toString(),
|
|
1265
1265
|
maxLiquidationValue: s.toString(),
|
|
1266
1266
|
maxLoanToVaule: u.toString(),
|
|
1267
1267
|
supply: n,
|
|
@@ -1325,7 +1325,7 @@ async function $e(e, o, n) {
|
|
|
1325
1325
|
}
|
|
1326
1326
|
for (const t of o)
|
|
1327
1327
|
e.moveCall({
|
|
1328
|
-
target: `${r.oracle.packageId}::oracle_pro::
|
|
1328
|
+
target: `${r.oracle.packageId}::oracle_pro::update_single_price_v2`,
|
|
1329
1329
|
arguments: [
|
|
1330
1330
|
e.object("0x6"),
|
|
1331
1331
|
// Clock object
|
|
@@ -1337,6 +1337,7 @@ async function $e(e, o, n) {
|
|
|
1337
1337
|
// Supra oracle holder
|
|
1338
1338
|
e.object(t.pythPriceInfoObject),
|
|
1339
1339
|
// Pyth price info object
|
|
1340
|
+
e.object(r.oracle.switchboardAggregator),
|
|
1340
1341
|
e.pure.address(t.feedId)
|
|
1341
1342
|
// Price feed ID
|
|
1342
1343
|
]
|
|
@@ -1365,14 +1366,14 @@ async function st(e, o, n, r) {
|
|
|
1365
1366
|
n.forEach((u) => {
|
|
1366
1367
|
a.includes(u.market) || a.push(u.market);
|
|
1367
1368
|
});
|
|
1368
|
-
const
|
|
1369
|
+
const i = await Be(o, {
|
|
1369
1370
|
...r,
|
|
1370
1371
|
markets: a
|
|
1371
|
-
}),
|
|
1372
|
-
lendingPositions:
|
|
1372
|
+
}), c = Pe(t, {
|
|
1373
|
+
lendingPositions: i,
|
|
1373
1374
|
pools: n
|
|
1374
1375
|
});
|
|
1375
|
-
return await $e(e,
|
|
1376
|
+
return await $e(e, c, {
|
|
1376
1377
|
updatePythPriceFeeds: !0,
|
|
1377
1378
|
...r
|
|
1378
1379
|
});
|
|
@@ -1437,12 +1438,12 @@ async function pt(e, o, n, r, t) {
|
|
|
1437
1438
|
const a = await k({
|
|
1438
1439
|
...t,
|
|
1439
1440
|
cacheTime: h
|
|
1440
|
-
}),
|
|
1441
|
+
}), i = await B(o, t);
|
|
1441
1442
|
if (!(await L({
|
|
1442
1443
|
...t,
|
|
1443
1444
|
cacheTime: h
|
|
1444
1445
|
})).some(
|
|
1445
|
-
(m) => b(m.coinType) === b(
|
|
1446
|
+
(m) => b(m.coinType) === b(i.suiCoinType)
|
|
1446
1447
|
))
|
|
1447
1448
|
throw new Error("Pool does not support flashloan");
|
|
1448
1449
|
const [u] = e.moveCall({
|
|
@@ -1450,28 +1451,28 @@ async function pt(e, o, n, r, t) {
|
|
|
1450
1451
|
arguments: [
|
|
1451
1452
|
e.object("0x06"),
|
|
1452
1453
|
e.object(a.storage),
|
|
1453
|
-
e.object(
|
|
1454
|
+
e.object(i.contract.pool),
|
|
1454
1455
|
y(n, e.object),
|
|
1455
1456
|
y(r, e.object)
|
|
1456
1457
|
],
|
|
1457
|
-
typeArguments: [
|
|
1458
|
+
typeArguments: [i.suiCoinType]
|
|
1458
1459
|
});
|
|
1459
1460
|
return [u];
|
|
1460
1461
|
}
|
|
1461
1462
|
async function dt(e, o, n, r, t, a) {
|
|
1462
|
-
const
|
|
1463
|
+
const i = {
|
|
1463
1464
|
...a,
|
|
1464
1465
|
cacheTime: h
|
|
1465
|
-
},
|
|
1466
|
-
if (
|
|
1466
|
+
}, c = await k(i), s = await B(o, i), u = await B(r, i);
|
|
1467
|
+
if (c.version === 1) {
|
|
1467
1468
|
const [m, g] = e.moveCall({
|
|
1468
|
-
target: `${
|
|
1469
|
+
target: `${c.package}::incentive_v3::liquidation`,
|
|
1469
1470
|
arguments: [
|
|
1470
1471
|
e.object("0x06"),
|
|
1471
1472
|
// Clock object
|
|
1472
|
-
e.object(
|
|
1473
|
+
e.object(c.priceOracle),
|
|
1473
1474
|
// Price oracle for asset pricing
|
|
1474
|
-
e.object(
|
|
1475
|
+
e.object(c.storage),
|
|
1475
1476
|
// Protocol storage
|
|
1476
1477
|
e.pure.u8(s.id),
|
|
1477
1478
|
// Pay asset ID
|
|
@@ -1485,9 +1486,9 @@ async function dt(e, o, n, r, t, a) {
|
|
|
1485
1486
|
// Collateral asset pool contract
|
|
1486
1487
|
y(t, e.pure.address),
|
|
1487
1488
|
// Borrower address
|
|
1488
|
-
e.object(
|
|
1489
|
+
e.object(c.incentiveV2),
|
|
1489
1490
|
// Incentive V2 contract
|
|
1490
|
-
e.object(
|
|
1491
|
+
e.object(c.incentiveV3)
|
|
1491
1492
|
// Incentive V3 contract
|
|
1492
1493
|
],
|
|
1493
1494
|
typeArguments: [s.suiCoinType, u.suiCoinType]
|
|
@@ -1495,13 +1496,13 @@ async function dt(e, o, n, r, t, a) {
|
|
|
1495
1496
|
return [m, g];
|
|
1496
1497
|
} else {
|
|
1497
1498
|
const [m, g] = e.moveCall({
|
|
1498
|
-
target: `${
|
|
1499
|
+
target: `${c.package}::incentive_v3::liquidation_v2`,
|
|
1499
1500
|
arguments: [
|
|
1500
1501
|
e.object("0x06"),
|
|
1501
1502
|
// Clock object
|
|
1502
|
-
e.object(
|
|
1503
|
+
e.object(c.priceOracle),
|
|
1503
1504
|
// Price oracle for asset pricing
|
|
1504
|
-
e.object(
|
|
1505
|
+
e.object(c.storage),
|
|
1505
1506
|
// Protocol storage
|
|
1506
1507
|
e.pure.u8(s.id),
|
|
1507
1508
|
// Pay asset ID
|
|
@@ -1515,9 +1516,9 @@ async function dt(e, o, n, r, t, a) {
|
|
|
1515
1516
|
// Collateral asset pool contract
|
|
1516
1517
|
y(t, e.pure.address),
|
|
1517
1518
|
// Borrower address
|
|
1518
|
-
e.object(
|
|
1519
|
+
e.object(c.incentiveV2),
|
|
1519
1520
|
// Incentive V2 contract
|
|
1520
|
-
e.object(
|
|
1521
|
+
e.object(c.incentiveV3),
|
|
1521
1522
|
// Incentive V3 contract
|
|
1522
1523
|
e.object("0x05")
|
|
1523
1524
|
// SuiSystemState object
|
|
@@ -1532,7 +1533,7 @@ async function Ve(e, o, n) {
|
|
|
1532
1533
|
...n,
|
|
1533
1534
|
markets: Object.values(E),
|
|
1534
1535
|
cacheTime: h
|
|
1535
|
-
}),
|
|
1536
|
+
}), i = await te(n);
|
|
1536
1537
|
for (let m of o) {
|
|
1537
1538
|
const g = await k({
|
|
1538
1539
|
...n,
|
|
@@ -1553,11 +1554,11 @@ async function Ve(e, o, n) {
|
|
|
1553
1554
|
]
|
|
1554
1555
|
});
|
|
1555
1556
|
}
|
|
1556
|
-
const
|
|
1557
|
+
const c = await r.devInspectTransactionBlock({
|
|
1557
1558
|
transactionBlock: t,
|
|
1558
1559
|
sender: e
|
|
1559
1560
|
}), s = [];
|
|
1560
|
-
|
|
1561
|
+
c?.results?.forEach((m) => {
|
|
1561
1562
|
s.push(
|
|
1562
1563
|
O(
|
|
1563
1564
|
{
|
|
@@ -1584,7 +1585,7 @@ async function Ve(e, o, n) {
|
|
|
1584
1585
|
if (m.length === 5 && Array.isArray(m[0])) {
|
|
1585
1586
|
const w = m[0].length;
|
|
1586
1587
|
for (let p = 0; p < w; p++) {
|
|
1587
|
-
const f =
|
|
1588
|
+
const f = i.find(
|
|
1588
1589
|
(T) => b(T.coinType) === b(m[1][p])
|
|
1589
1590
|
), _ = a.find(
|
|
1590
1591
|
(T) => b(T.coinType) === b(m[0][p])
|
|
@@ -1609,11 +1610,11 @@ async function mt(e, o) {
|
|
|
1609
1610
|
address: e,
|
|
1610
1611
|
market: a.key
|
|
1611
1612
|
})).concat(
|
|
1612
|
-
r.filter((a) => !!n.find((
|
|
1613
|
-
const
|
|
1613
|
+
r.filter((a) => !!n.find((i) => i.id === a.marketId)).map((a) => {
|
|
1614
|
+
const i = j(a.marketId);
|
|
1614
1615
|
return {
|
|
1615
1616
|
address: e,
|
|
1616
|
-
market:
|
|
1617
|
+
market: i.key,
|
|
1617
1618
|
emodeId: a.emodeId
|
|
1618
1619
|
};
|
|
1619
1620
|
})
|
|
@@ -1623,8 +1624,8 @@ async function mt(e, o) {
|
|
|
1623
1624
|
function yt(e) {
|
|
1624
1625
|
const o = /* @__PURE__ */ new Map();
|
|
1625
1626
|
e.forEach((r) => {
|
|
1626
|
-
const t = r.assetId, a = r.option,
|
|
1627
|
-
o.has(
|
|
1627
|
+
const t = r.assetId, a = r.option, i = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
|
|
1628
|
+
o.has(i) ? o.get(i).total += r.userClaimableReward : o.set(i, {
|
|
1628
1629
|
assetId: t,
|
|
1629
1630
|
rewardType: a,
|
|
1630
1631
|
coinType: r.rewardCoinType,
|
|
@@ -1633,11 +1634,11 @@ function yt(e) {
|
|
|
1633
1634
|
});
|
|
1634
1635
|
});
|
|
1635
1636
|
const n = /* @__PURE__ */ new Map();
|
|
1636
|
-
for (const { assetId: r, rewardType: t, coinType: a, total:
|
|
1637
|
-
const s = `${r}-${t}-${
|
|
1638
|
-
n.has(s) || n.set(s, { assetId: r, rewardType: t, market:
|
|
1637
|
+
for (const { assetId: r, rewardType: t, coinType: a, total: i, market: c } of o.values()) {
|
|
1638
|
+
const s = `${r}-${t}-${c}`;
|
|
1639
|
+
n.has(s) || n.set(s, { assetId: r, rewardType: t, market: c, rewards: /* @__PURE__ */ new Map() });
|
|
1639
1640
|
const u = n.get(s);
|
|
1640
|
-
u.rewards.set(a, (u.rewards.get(a) || 0) +
|
|
1641
|
+
u.rewards.set(a, (u.rewards.get(a) || 0) + i);
|
|
1641
1642
|
}
|
|
1642
1643
|
return Array.from(n.values()).map((r) => ({
|
|
1643
1644
|
assetId: r.assetId,
|
|
@@ -1671,8 +1672,8 @@ async function wt(e, o, n) {
|
|
|
1671
1672
|
markets: Object.values(E),
|
|
1672
1673
|
cacheTime: h
|
|
1673
1674
|
}), a = /* @__PURE__ */ new Map();
|
|
1674
|
-
for (const
|
|
1675
|
-
const { rewardCoinType: s, ruleIds: u, market: m, owner: g, emodeId: v } =
|
|
1675
|
+
for (const c of o) {
|
|
1676
|
+
const { rewardCoinType: s, ruleIds: u, market: m, owner: g, emodeId: v } = c, w = `${s}-${m}-${g}`;
|
|
1676
1677
|
for (const p of u) {
|
|
1677
1678
|
a.has(w) || a.set(w, {
|
|
1678
1679
|
assetIds: [],
|
|
@@ -1683,16 +1684,16 @@ async function wt(e, o, n) {
|
|
|
1683
1684
|
isEMode: typeof v < "u"
|
|
1684
1685
|
});
|
|
1685
1686
|
const f = a.get(w);
|
|
1686
|
-
f.assetIds.push(
|
|
1687
|
+
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(p), f.amount += c.userClaimableReward;
|
|
1687
1688
|
}
|
|
1688
1689
|
}
|
|
1689
|
-
const
|
|
1690
|
-
for (const [
|
|
1690
|
+
const i = [];
|
|
1691
|
+
for (const [c, { assetIds: s, ruleIds: u, amount: m, market: g, owner: v, isEMode: w }] of a) {
|
|
1691
1692
|
const p = t.find(
|
|
1692
|
-
(_) => b(_.suiCoinType) === b(
|
|
1693
|
+
(_) => b(_.suiCoinType) === b(c) && _.market === g
|
|
1693
1694
|
);
|
|
1694
1695
|
if (!p || !p.contract.rewardFundId)
|
|
1695
|
-
throw new Error(`No matching rewardFund found for reward coin: ${
|
|
1696
|
+
throw new Error(`No matching rewardFund found for reward coin: ${c} ${g}`);
|
|
1696
1697
|
const f = p.contract.rewardFundId;
|
|
1697
1698
|
if (n?.accountCap && !n.customCoinReceive)
|
|
1698
1699
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
@@ -1716,7 +1717,7 @@ async function wt(e, o, n) {
|
|
|
1716
1717
|
y(n.accountCap, e.object)
|
|
1717
1718
|
// Account capability
|
|
1718
1719
|
],
|
|
1719
|
-
typeArguments: [
|
|
1720
|
+
typeArguments: [c]
|
|
1720
1721
|
}) : w ? _ = e.moveCall({
|
|
1721
1722
|
target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1722
1723
|
arguments: [
|
|
@@ -1735,7 +1736,7 @@ async function wt(e, o, n) {
|
|
|
1735
1736
|
y(v, e.object)
|
|
1736
1737
|
// Account capability
|
|
1737
1738
|
],
|
|
1738
|
-
typeArguments: [
|
|
1739
|
+
typeArguments: [c]
|
|
1739
1740
|
}) : _ = e.moveCall({
|
|
1740
1741
|
target: `${r.package}::incentive_v3::claim_reward`,
|
|
1741
1742
|
arguments: [
|
|
@@ -1752,12 +1753,12 @@ async function wt(e, o, n) {
|
|
|
1752
1753
|
e.pure.vector("address", u)
|
|
1753
1754
|
// Rule IDs
|
|
1754
1755
|
],
|
|
1755
|
-
typeArguments: [
|
|
1756
|
+
typeArguments: [c]
|
|
1756
1757
|
});
|
|
1757
1758
|
const [T] = e.moveCall({
|
|
1758
1759
|
target: "0x2::coin::from_balance",
|
|
1759
1760
|
arguments: [_],
|
|
1760
|
-
typeArguments: [
|
|
1761
|
+
typeArguments: [c]
|
|
1761
1762
|
});
|
|
1762
1763
|
if (n?.customCoinReceive.type === "transfer") {
|
|
1763
1764
|
if (!n.customCoinReceive.transfer)
|
|
@@ -1774,7 +1775,7 @@ async function wt(e, o, n) {
|
|
|
1774
1775
|
e.pure.address(n.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1775
1776
|
) : await be(e, p, T, n);
|
|
1776
1777
|
} else
|
|
1777
|
-
|
|
1778
|
+
i.push({
|
|
1778
1779
|
coin: T,
|
|
1779
1780
|
identifier: p,
|
|
1780
1781
|
owner: v,
|
|
@@ -1799,11 +1800,11 @@ async function wt(e, o, n) {
|
|
|
1799
1800
|
y(n?.accountCap || v, e.object)
|
|
1800
1801
|
// Account capability
|
|
1801
1802
|
],
|
|
1802
|
-
typeArguments: [
|
|
1803
|
+
typeArguments: [c]
|
|
1803
1804
|
}), [T] = e.moveCall({
|
|
1804
1805
|
target: "0x2::coin::from_balance",
|
|
1805
1806
|
arguments: [_],
|
|
1806
|
-
typeArguments: [
|
|
1807
|
+
typeArguments: [c]
|
|
1807
1808
|
});
|
|
1808
1809
|
e.transferObjects(
|
|
1809
1810
|
[T],
|
|
@@ -1826,10 +1827,10 @@ async function wt(e, o, n) {
|
|
|
1826
1827
|
e.pure.vector("address", u)
|
|
1827
1828
|
// Rule IDs
|
|
1828
1829
|
],
|
|
1829
|
-
typeArguments: [
|
|
1830
|
+
typeArguments: [c]
|
|
1830
1831
|
});
|
|
1831
1832
|
}
|
|
1832
|
-
return
|
|
1833
|
+
return i;
|
|
1833
1834
|
}
|
|
1834
1835
|
export {
|
|
1835
1836
|
W as Address,
|
|
@@ -1859,7 +1860,7 @@ export {
|
|
|
1859
1860
|
je as getAccountCapOwnerPTB,
|
|
1860
1861
|
L as getAllFlashLoanAssets,
|
|
1861
1862
|
Xe as getBorrowFee,
|
|
1862
|
-
|
|
1863
|
+
it as getCoins,
|
|
1863
1864
|
k as getConfig,
|
|
1864
1865
|
Ke as getFees,
|
|
1865
1866
|
ut as getFlashLoanAsset,
|
|
@@ -1877,7 +1878,7 @@ export {
|
|
|
1877
1878
|
at as getSimulatedHealthFactor,
|
|
1878
1879
|
Z as getSimulatedHealthFactorPTB,
|
|
1879
1880
|
ze as getStats,
|
|
1880
|
-
|
|
1881
|
+
ct as getTransactions,
|
|
1881
1882
|
mt as getUserAvailableLendingRewards,
|
|
1882
1883
|
ft as getUserClaimedRewardHistory,
|
|
1883
1884
|
X as getUserEModeCaps,
|