@naviprotocol/lending 1.4.1-beta.2 → 1.4.1-beta.4
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 +361 -361
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Transaction as U } from "@mysten/sui/transactions";
|
|
2
|
-
import { bcs as m, toHex as
|
|
3
|
-
import { SuiClient as se, getFullnodeUrl as
|
|
4
|
-
import
|
|
2
|
+
import { bcs as m, toHex as ce, fromHex as ie } from "@mysten/bcs";
|
|
3
|
+
import { SuiClient as se, getFullnodeUrl as le } from "@mysten/sui/client";
|
|
4
|
+
import ue 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";
|
|
8
8
|
import { bcs as C } from "@mysten/sui/bcs";
|
|
9
9
|
const z = m.bytes(32).transform({
|
|
10
10
|
// To change the input type, you need to provide a type definition for the input
|
|
11
|
-
input: (e) =>
|
|
12
|
-
output: (e) =>
|
|
11
|
+
input: (e) => ie(e),
|
|
12
|
+
output: (e) => ce(e)
|
|
13
13
|
}), He = m.struct("IncentiveAPYInfo", {
|
|
14
14
|
/** Asset identifier */
|
|
15
15
|
asset_id: m.u8(),
|
|
@@ -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.1-beta.
|
|
132
|
+
}), ye = "1.4.1-beta.4", V = {
|
|
133
133
|
version: ye
|
|
134
134
|
}, ge = V.version, he = () => {
|
|
135
135
|
if (typeof process < "u" && process.versions && process.versions.node)
|
|
@@ -144,14 +144,14 @@ 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(), P = new se({
|
|
147
|
-
url:
|
|
147
|
+
url: le("mainnet")
|
|
148
148
|
});
|
|
149
149
|
function Q(e) {
|
|
150
150
|
const n = [];
|
|
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:
|
|
154
|
+
const { client: a, disableCache: i, cacheTime: c, ...s } = o;
|
|
155
155
|
n.push(s);
|
|
156
156
|
} else
|
|
157
157
|
n.push(o);
|
|
@@ -170,17 +170,17 @@ function $(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) ? 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) ? a.data : e(...o).then((i) => (n[t] = {
|
|
174
|
+
data: i,
|
|
175
175
|
cacheAt: Date.now()
|
|
176
|
-
},
|
|
176
|
+
}, i));
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
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
|
+
[ue(o)]: W(e[o])
|
|
184
184
|
}),
|
|
185
185
|
{}
|
|
186
186
|
) : e;
|
|
@@ -199,7 +199,7 @@ function L(e, n, o) {
|
|
|
199
199
|
return console.log(`Get an error, msg: ${e.error}`), [];
|
|
200
200
|
return [];
|
|
201
201
|
}
|
|
202
|
-
function
|
|
202
|
+
function b(e) {
|
|
203
203
|
return pe(e);
|
|
204
204
|
}
|
|
205
205
|
function X(e) {
|
|
@@ -249,7 +249,7 @@ function ke(e) {
|
|
|
249
249
|
poolId: parseInt(o)
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
-
function
|
|
252
|
+
function T() {
|
|
253
253
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
254
254
|
}
|
|
255
255
|
var F = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(F || {});
|
|
@@ -260,16 +260,16 @@ const R = $(
|
|
|
260
260
|
(t) => t.key
|
|
261
261
|
)}`, r = await fetch(o, { headers: E }).then((t) => t.json());
|
|
262
262
|
return r.data.forEach((t) => {
|
|
263
|
-
const
|
|
263
|
+
const i = r.meta.emodes.filter((h) => {
|
|
264
264
|
const j = _(h.marketId);
|
|
265
265
|
return t.market === j.key && h.isActive;
|
|
266
266
|
}).filter((h) => !!h.assets.find((j) => j.assetId === t.id));
|
|
267
|
-
t.emodes =
|
|
268
|
-
const
|
|
267
|
+
t.emodes = i;
|
|
268
|
+
const c = 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(), l = p(c).multipliedBy(t.oracle.price).toString(), d = p(s).multipliedBy(t.oracle.price).toString(), f = 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(), y = p(f).multipliedBy(t.oracle.price).toString(),
|
|
272
|
-
t.poolSupplyAmount =
|
|
271
|
+
).shiftedBy(-9).decimalPlaces(t.token.decimals, p.ROUND_DOWN).toString(), y = p(f).multipliedBy(t.oracle.price).toString(), u = p(v).multipliedBy(t.oracle.price).toString();
|
|
272
|
+
t.poolSupplyAmount = c, t.poolBorrowAmount = s, t.poolSupplyValue = l, t.poolBorrowValue = d, t.poolSupplyCapAmount = f, t.poolBorrowCapAmount = v, t.poolSupplyCapValue = y, t.poolBorrowCapValue = u;
|
|
273
273
|
}), r.data;
|
|
274
274
|
}
|
|
275
275
|
)
|
|
@@ -283,11 +283,11 @@ async function A(e, n) {
|
|
|
283
283
|
const r = await R({
|
|
284
284
|
...n,
|
|
285
285
|
markets: [o || N],
|
|
286
|
-
cacheTime:
|
|
286
|
+
cacheTime: w
|
|
287
287
|
});
|
|
288
288
|
if (typeof e == "object")
|
|
289
289
|
return e;
|
|
290
|
-
const t = r.find((a) => typeof e == "string" ?
|
|
290
|
+
const t = r.find((a) => typeof e == "string" ? b(a.suiCoinType) === b(e) : typeof e == "number" ? a.id === e : !1);
|
|
291
291
|
if (!t)
|
|
292
292
|
throw new Error("Pool not found");
|
|
293
293
|
return t.isDeprecated && console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`), t;
|
|
@@ -308,18 +308,18 @@ const Je = $(
|
|
|
308
308
|
async function Ce(e, n, o, r) {
|
|
309
309
|
const t = await k({
|
|
310
310
|
...r,
|
|
311
|
-
cacheTime:
|
|
311
|
+
cacheTime: w
|
|
312
312
|
}), a = await A(n, 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 (
|
|
315
|
+
const i = typeof o == "object" && o.$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
|
o = e.splitCoins(o, [r.amount]);
|
|
320
320
|
}
|
|
321
|
-
let
|
|
322
|
-
return typeof r?.amount < "u" ?
|
|
321
|
+
let c;
|
|
322
|
+
return typeof r?.amount < "u" ? c = g(r.amount, e.pure.u64) : c = e.moveCall({
|
|
323
323
|
target: "0x2::coin::value",
|
|
324
324
|
arguments: [g(o, e.object)],
|
|
325
325
|
typeArguments: [a.suiCoinType]
|
|
@@ -344,7 +344,7 @@ async function Ce(e, n, o, r) {
|
|
|
344
344
|
e.object(a.contract.pool),
|
|
345
345
|
e.pure.u8(a.id),
|
|
346
346
|
g(o, e.object),
|
|
347
|
-
|
|
347
|
+
c,
|
|
348
348
|
e.object(t.incentiveV2),
|
|
349
349
|
e.object(t.incentiveV3)
|
|
350
350
|
],
|
|
@@ -357,12 +357,12 @@ async function Ce(e, n, o, r) {
|
|
|
357
357
|
async function Qe(e, n, o, r) {
|
|
358
358
|
const t = await k({
|
|
359
359
|
...r,
|
|
360
|
-
cacheTime:
|
|
361
|
-
}), a = await A(n, r),
|
|
362
|
-
let
|
|
360
|
+
cacheTime: w
|
|
361
|
+
}), a = await A(n, r), i = g(o, e.pure.u64);
|
|
362
|
+
let c;
|
|
363
363
|
if (t.version === 1)
|
|
364
364
|
if (r?.accountCap) {
|
|
365
|
-
const [
|
|
365
|
+
const [l] = e.moveCall({
|
|
366
366
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
|
|
367
367
|
arguments: [
|
|
368
368
|
e.object("0x06"),
|
|
@@ -370,16 +370,16 @@ async function Qe(e, n, o, 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
|
g(r.accountCap, e.object)
|
|
377
377
|
],
|
|
378
378
|
typeArguments: [a.suiCoinType]
|
|
379
379
|
});
|
|
380
|
-
|
|
380
|
+
c = l;
|
|
381
381
|
} else {
|
|
382
|
-
const [
|
|
382
|
+
const [l] = e.moveCall({
|
|
383
383
|
target: `${t.package}::incentive_v3::withdraw`,
|
|
384
384
|
arguments: [
|
|
385
385
|
e.object("0x06"),
|
|
@@ -387,16 +387,16 @@ async function Qe(e, n, o, 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 = l;
|
|
397
397
|
}
|
|
398
398
|
else if (r?.accountCap) {
|
|
399
|
-
const [
|
|
399
|
+
const [l] = e.moveCall({
|
|
400
400
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
401
401
|
arguments: [
|
|
402
402
|
e.object("0x06"),
|
|
@@ -404,7 +404,7 @@ async function Qe(e, n, o, 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
|
g(r.accountCap, e.object),
|
|
@@ -412,9 +412,9 @@ async function Qe(e, n, o, r) {
|
|
|
412
412
|
],
|
|
413
413
|
typeArguments: [a.suiCoinType]
|
|
414
414
|
});
|
|
415
|
-
|
|
415
|
+
c = l;
|
|
416
416
|
} else {
|
|
417
|
-
const [
|
|
417
|
+
const [l] = e.moveCall({
|
|
418
418
|
target: `${t.package}::incentive_v3::withdraw_v2`,
|
|
419
419
|
arguments: [
|
|
420
420
|
e.object("0x06"),
|
|
@@ -422,33 +422,33 @@ async function Qe(e, n, o, 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 = l;
|
|
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
|
}
|
|
440
440
|
async function Xe(e, n, o, r) {
|
|
441
441
|
const t = await k({
|
|
442
442
|
...r,
|
|
443
|
-
cacheTime:
|
|
443
|
+
cacheTime: w
|
|
444
444
|
}), a = await A(n, 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 = g(o, e.pure.u64);
|
|
448
|
+
let c;
|
|
449
449
|
if (t.version === 1)
|
|
450
450
|
if (r?.accountCap) {
|
|
451
|
-
const [
|
|
451
|
+
const [l] = e.moveCall({
|
|
452
452
|
target: `${t.package}::incentive_v3::borrow_with_account_cap`,
|
|
453
453
|
arguments: [
|
|
454
454
|
e.object("0x06"),
|
|
@@ -456,16 +456,16 @@ async function Xe(e, n, o, 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
|
g(r.accountCap, e.object)
|
|
463
463
|
],
|
|
464
464
|
typeArguments: [a.suiCoinType]
|
|
465
465
|
});
|
|
466
|
-
|
|
466
|
+
c = l;
|
|
467
467
|
} else {
|
|
468
|
-
const [
|
|
468
|
+
const [l] = e.moveCall({
|
|
469
469
|
target: `${t.package}::incentive_v3::borrow`,
|
|
470
470
|
arguments: [
|
|
471
471
|
e.object("0x06"),
|
|
@@ -473,16 +473,16 @@ async function Xe(e, n, o, 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 = l;
|
|
483
483
|
}
|
|
484
484
|
else if (r?.accountCap) {
|
|
485
|
-
const [
|
|
485
|
+
const [l] = e.moveCall({
|
|
486
486
|
target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
487
487
|
arguments: [
|
|
488
488
|
e.object("0x06"),
|
|
@@ -490,7 +490,7 @@ async function Xe(e, n, o, 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
|
g(r.accountCap, e.object),
|
|
@@ -498,9 +498,9 @@ async function Xe(e, n, o, r) {
|
|
|
498
498
|
],
|
|
499
499
|
typeArguments: [a.suiCoinType]
|
|
500
500
|
});
|
|
501
|
-
|
|
501
|
+
c = l;
|
|
502
502
|
} else {
|
|
503
|
-
const [
|
|
503
|
+
const [l] = e.moveCall({
|
|
504
504
|
target: `${t.package}::incentive_v3::borrow_v2`,
|
|
505
505
|
arguments: [
|
|
506
506
|
e.object("0x06"),
|
|
@@ -508,33 +508,33 @@ async function Xe(e, n, o, 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 = l;
|
|
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
|
}
|
|
526
526
|
async function xe(e, n, o, r) {
|
|
527
527
|
const t = await k({
|
|
528
528
|
...r,
|
|
529
|
-
cacheTime:
|
|
530
|
-
}), a = await A(n, r),
|
|
531
|
-
if (
|
|
529
|
+
cacheTime: w
|
|
530
|
+
}), a = await A(n, r), i = typeof o == "object" && o.$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
|
o = e.splitCoins(o, [r.amount]);
|
|
535
535
|
}
|
|
536
|
-
let
|
|
537
|
-
if (typeof r?.amount < "u" ?
|
|
536
|
+
let c;
|
|
537
|
+
if (typeof r?.amount < "u" ? c = g(r.amount, e.pure.u64) : c = e.moveCall({
|
|
538
538
|
target: "0x2::coin::value",
|
|
539
539
|
arguments: [g(o, e.object)],
|
|
540
540
|
typeArguments: [a.suiCoinType]
|
|
@@ -569,7 +569,7 @@ async function xe(e, n, o, r) {
|
|
|
569
569
|
e.object(a.contract.pool),
|
|
570
570
|
e.pure.u8(a.id),
|
|
571
571
|
g(o, e.object),
|
|
572
|
-
|
|
572
|
+
c,
|
|
573
573
|
e.object(t.incentiveV2),
|
|
574
574
|
e.object(t.incentiveV3)
|
|
575
575
|
],
|
|
@@ -584,21 +584,21 @@ const et = $(
|
|
|
584
584
|
});
|
|
585
585
|
if (e?.address && typeof e?.asset < "u")
|
|
586
586
|
try {
|
|
587
|
-
const t = await A(e.asset, e), a = e?.client ?? P,
|
|
588
|
-
|
|
587
|
+
const t = await A(e.asset, e), a = e?.client ?? P, i = new U();
|
|
588
|
+
i.moveCall({
|
|
589
589
|
target: `${n.package}::incentive_v3::get_borrow_fee_v2`,
|
|
590
590
|
arguments: [
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
591
|
+
i.object(n.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 = L(
|
|
601
|
+
}), s = L(c, [C.u64()]);
|
|
602
602
|
return (Number(s[0]) || 0) / 100;
|
|
603
603
|
} catch (t) {
|
|
604
604
|
console.error(t);
|
|
@@ -634,7 +634,7 @@ class je {
|
|
|
634
634
|
}
|
|
635
635
|
initPools(n) {
|
|
636
636
|
const o = H(this.pools), r = J(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
637
|
-
let
|
|
637
|
+
let i = p(0), c = p(0);
|
|
638
638
|
n.forEach((s) => {
|
|
639
639
|
if (!this.checkMarket(s.market)) {
|
|
640
640
|
console.warn(`Pool is not in market ${this.config.name}`, s);
|
|
@@ -646,30 +646,30 @@ class je {
|
|
|
646
646
|
(y) => y.isCollateral && y.ltv > 0 && y.assetId !== s.id
|
|
647
647
|
) && t.add(s.uniqueId), f.isCollateral && d.assets.find((y) => y.isDebt && y.assetId !== s.id) && a.add(s.uniqueId);
|
|
648
648
|
});
|
|
649
|
-
}),
|
|
649
|
+
}), c = c.plus(s.poolBorrowValue), i = i.plus(s.poolSupplyValue);
|
|
650
650
|
}), this.poolMap = H(this.pools, "id"), this.emodeMap = J(this.emodes, "emodeId"), this.emodes.forEach((s) => {
|
|
651
|
-
const
|
|
652
|
-
this.emodePools.push(...
|
|
651
|
+
const l = this.getEModePools(s.emodeId);
|
|
652
|
+
this.emodePools.push(...l);
|
|
653
653
|
}), this._overview = {
|
|
654
|
-
marketTotalSupplyValue:
|
|
655
|
-
marketTotalBorrowValue:
|
|
654
|
+
marketTotalSupplyValue: i.toString(),
|
|
655
|
+
marketTotalBorrowValue: c.toString()
|
|
656
656
|
}, this.emodeBorrowablePools = this.pools.filter((s) => t.has(s.uniqueId)), this.emodeSupplyablePools = this.pools.filter((s) => a.has(s.uniqueId));
|
|
657
657
|
}
|
|
658
658
|
getEMode(n) {
|
|
659
659
|
return this.emodeMap[n] || null;
|
|
660
660
|
}
|
|
661
661
|
getEModeRelatePools(n, o) {
|
|
662
|
-
const { collateral: r, debt: t, emodeId: a } = o || {},
|
|
663
|
-
return n.emodes.forEach((
|
|
664
|
-
typeof a == "number" && a !==
|
|
665
|
-
typeof r == "boolean" && r && s.isCollateral && s.assetId === n.id &&
|
|
662
|
+
const { collateral: r, debt: t, emodeId: a } = o || {}, i = [];
|
|
663
|
+
return n.emodes.forEach((c) => {
|
|
664
|
+
typeof a == "number" && a !== c.emodeId || c.assets.forEach((s) => {
|
|
665
|
+
typeof r == "boolean" && r && s.isCollateral && s.assetId === n.id && i.push(this.poolMap[s.assetId]), typeof t == "boolean" && t && s.isDebt && s.assetId === n.id && i.push(this.poolMap[s.assetId]);
|
|
666
666
|
});
|
|
667
|
-
}),
|
|
667
|
+
}), i;
|
|
668
668
|
}
|
|
669
669
|
getEModePools(n) {
|
|
670
670
|
const o = this.getEMode(n);
|
|
671
671
|
return o ? o.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
|
|
672
|
-
const a = o.assets.find((
|
|
672
|
+
const a = o.assets.find((i) => i.assetId === t.id);
|
|
673
673
|
return {
|
|
674
674
|
...t,
|
|
675
675
|
emode: {
|
|
@@ -699,7 +699,7 @@ const _ = (e) => {
|
|
|
699
699
|
markets: e
|
|
700
700
|
});
|
|
701
701
|
return e.map((r) => {
|
|
702
|
-
const t = _(r), a = o.filter((
|
|
702
|
+
const t = _(r), a = o.filter((i) => i.market === t.key);
|
|
703
703
|
return new je(r, a);
|
|
704
704
|
});
|
|
705
705
|
}
|
|
@@ -715,10 +715,10 @@ const _ = (e) => {
|
|
|
715
715
|
return (await fetch(o, { headers: E }).then((t) => t.json())).data;
|
|
716
716
|
}
|
|
717
717
|
)
|
|
718
|
-
),
|
|
719
|
-
async function
|
|
718
|
+
), w = 1e3 * 60 * 5;
|
|
719
|
+
async function Ie(e, n) {
|
|
720
720
|
const o = await k({
|
|
721
|
-
cacheTime:
|
|
721
|
+
cacheTime: w,
|
|
722
722
|
...n
|
|
723
723
|
});
|
|
724
724
|
return e.moveCall({
|
|
@@ -726,9 +726,9 @@ async function Te(e, n) {
|
|
|
726
726
|
arguments: []
|
|
727
727
|
});
|
|
728
728
|
}
|
|
729
|
-
async function
|
|
729
|
+
async function Te(e, n, o) {
|
|
730
730
|
const r = await k({
|
|
731
|
-
cacheTime:
|
|
731
|
+
cacheTime: w,
|
|
732
732
|
...o
|
|
733
733
|
});
|
|
734
734
|
return e.moveCall({
|
|
@@ -739,7 +739,7 @@ async function Ie(e, n, o) {
|
|
|
739
739
|
async function Be(e, n, o) {
|
|
740
740
|
const r = await k({
|
|
741
741
|
...o,
|
|
742
|
-
cacheTime:
|
|
742
|
+
cacheTime: w
|
|
743
743
|
});
|
|
744
744
|
return o?.accountCap ? e.moveCall({
|
|
745
745
|
target: `${r.package}::lending::enter_emode_with_account_cap`,
|
|
@@ -756,7 +756,7 @@ async function Be(e, n, o) {
|
|
|
756
756
|
async function ot(e, n) {
|
|
757
757
|
const o = await k({
|
|
758
758
|
...n,
|
|
759
|
-
cacheTime:
|
|
759
|
+
cacheTime: w
|
|
760
760
|
});
|
|
761
761
|
return n?.accountCap ? e.moveCall({
|
|
762
762
|
target: `${o.package}::lending::exit_emode_with_account_cap`,
|
|
@@ -768,19 +768,19 @@ async function ot(e, n) {
|
|
|
768
768
|
}
|
|
769
769
|
async function nt(e, n, o) {
|
|
770
770
|
const r = await k({
|
|
771
|
-
cacheTime:
|
|
771
|
+
cacheTime: w,
|
|
772
772
|
...o
|
|
773
|
-
}), t = await
|
|
773
|
+
}), t = await Ie(e, o);
|
|
774
774
|
await Be(e, n, {
|
|
775
775
|
...o,
|
|
776
776
|
accountCap: t
|
|
777
777
|
});
|
|
778
|
-
const a = await _(o?.market || N),
|
|
778
|
+
const a = await _(o?.market || N), i = await Te(e, t, o);
|
|
779
779
|
return e.moveCall({
|
|
780
780
|
target: `${r.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
781
781
|
arguments: [
|
|
782
782
|
e.object(r.emode.contract.registryObject),
|
|
783
|
-
|
|
783
|
+
i,
|
|
784
784
|
g(a.id, e.pure.u64),
|
|
785
785
|
g(n, e.pure.u64)
|
|
786
786
|
]
|
|
@@ -790,21 +790,21 @@ const x = $(
|
|
|
790
790
|
B(
|
|
791
791
|
async (e, n) => {
|
|
792
792
|
const o = await k({
|
|
793
|
-
cacheTime:
|
|
793
|
+
cacheTime: w,
|
|
794
794
|
...n
|
|
795
795
|
}), r = new U(), t = n?.client ?? P;
|
|
796
796
|
r.moveCall({
|
|
797
797
|
target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
798
798
|
arguments: [r.object(o.emode.contract.registryObject), r.pure.address(e)]
|
|
799
799
|
});
|
|
800
|
-
const
|
|
800
|
+
const i = (await t.devInspectTransactionBlock({
|
|
801
801
|
transactionBlock: r,
|
|
802
802
|
sender: e
|
|
803
|
-
})).results[0].returnValues,
|
|
804
|
-
return
|
|
803
|
+
})).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])), l = C.vector(C.Address).parse(Uint8Array.from(i[2][0]));
|
|
804
|
+
return c.map((d, f) => ({
|
|
805
805
|
marketId: Number(d),
|
|
806
806
|
emodeId: Number(s[f]),
|
|
807
|
-
accountCap:
|
|
807
|
+
accountCap: l[f].toString()
|
|
808
808
|
}));
|
|
809
809
|
}
|
|
810
810
|
)
|
|
@@ -815,33 +815,33 @@ function rt(e) {
|
|
|
815
815
|
function at(e, n, o) {
|
|
816
816
|
const r = typeof o?.balance == "number", t = r ? o.balance : 0;
|
|
817
817
|
let a = 0;
|
|
818
|
-
const
|
|
819
|
-
let
|
|
820
|
-
if (n.sort((s,
|
|
818
|
+
const i = [];
|
|
819
|
+
let c = "";
|
|
820
|
+
if (n.sort((s, l) => Number(l.balance) - Number(s.balance)).forEach((s) => {
|
|
821
821
|
if (!(r && a >= t) && Number(s.balance) !== 0) {
|
|
822
|
-
if (
|
|
822
|
+
if (c || (c = s.coinType), c !== s.coinType)
|
|
823
823
|
throw new Error("All coins must be of the same type");
|
|
824
|
-
a += Number(s.balance),
|
|
824
|
+
a += Number(s.balance), i.push(s.coinObjectId);
|
|
825
825
|
}
|
|
826
|
-
}),
|
|
826
|
+
}), i.length === 0)
|
|
827
827
|
throw new Error("No coins to merge");
|
|
828
828
|
if (r && a < t)
|
|
829
829
|
throw new Error(
|
|
830
830
|
`Balance is less than the specified balance: ${a} < ${t}`
|
|
831
831
|
);
|
|
832
|
-
return
|
|
832
|
+
return b(c) === b("0x2::sui::SUI") && o?.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]);
|
|
833
833
|
}
|
|
834
|
-
async function ee(e, n, o, r, t, a,
|
|
835
|
-
const
|
|
836
|
-
...
|
|
837
|
-
cacheTime:
|
|
838
|
-
}), s = await A(o,
|
|
834
|
+
async function ee(e, n, o, r, t, a, i) {
|
|
835
|
+
const c = await k({
|
|
836
|
+
...i,
|
|
837
|
+
cacheTime: w
|
|
838
|
+
}), s = await A(o, i);
|
|
839
839
|
return e.moveCall({
|
|
840
|
-
target: `${
|
|
840
|
+
target: `${c.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
841
841
|
arguments: [
|
|
842
842
|
e.object("0x06"),
|
|
843
|
-
e.object(
|
|
844
|
-
e.object(
|
|
843
|
+
e.object(c.storage),
|
|
844
|
+
e.object(c.oracle.priceOracle),
|
|
845
845
|
we(e, s),
|
|
846
846
|
g(n, e.pure.address),
|
|
847
847
|
g(s.id, e.pure.u8),
|
|
@@ -859,11 +859,11 @@ async function te(e, n, o) {
|
|
|
859
859
|
const r = new U(), t = o?.client ?? P, a = await R({
|
|
860
860
|
...o,
|
|
861
861
|
markets: Object.values(M)
|
|
862
|
-
}),
|
|
862
|
+
}), i = H(a);
|
|
863
863
|
for (let d of n) {
|
|
864
864
|
const f = await k({
|
|
865
865
|
...o,
|
|
866
|
-
cacheTime:
|
|
866
|
+
cacheTime: w,
|
|
867
867
|
market: d.market
|
|
868
868
|
});
|
|
869
869
|
r.moveCall({
|
|
@@ -874,34 +874,34 @@ async function te(e, n, o) {
|
|
|
874
874
|
const s = ((await t.devInspectTransactionBlock({
|
|
875
875
|
transactionBlock: r,
|
|
876
876
|
sender: e
|
|
877
|
-
})).results || []).map((d) => d.returnValues?.map((f) => C.vector(fe).parse(Uint8Array.from(f[0])))[0] || []),
|
|
877
|
+
})).results || []).map((d) => d.returnValues?.map((f) => C.vector(fe).parse(Uint8Array.from(f[0])))[0] || []), l = [];
|
|
878
878
|
return s.forEach((d, f) => {
|
|
879
879
|
const v = n[f], y = _(v.market);
|
|
880
|
-
d.forEach((
|
|
881
|
-
if (
|
|
880
|
+
d.forEach((u) => {
|
|
881
|
+
if (u.supply_balance === "0" && u.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
|
|
882
882
|
return;
|
|
883
|
-
const h =
|
|
883
|
+
const h = i[`${y.key}-${u.asset_id}`];
|
|
884
884
|
if (!h)
|
|
885
885
|
return;
|
|
886
886
|
const j = Y(
|
|
887
|
-
|
|
887
|
+
u.supply_balance,
|
|
888
888
|
h.currentSupplyIndex
|
|
889
|
-
).toString(),
|
|
890
|
-
|
|
889
|
+
).toString(), I = Y(
|
|
890
|
+
u.borrow_balance,
|
|
891
891
|
h.currentBorrowIndex
|
|
892
892
|
).toString();
|
|
893
|
-
|
|
893
|
+
l.push({
|
|
894
894
|
supplyBalance: j,
|
|
895
|
-
borrowBalance:
|
|
896
|
-
assetId:
|
|
895
|
+
borrowBalance: I,
|
|
896
|
+
assetId: u.asset_id,
|
|
897
897
|
market: y.key,
|
|
898
898
|
pool: h,
|
|
899
899
|
emodeId: v.emodeId
|
|
900
900
|
});
|
|
901
901
|
});
|
|
902
|
-
}),
|
|
902
|
+
}), l;
|
|
903
903
|
}
|
|
904
|
-
const
|
|
904
|
+
const ct = $(
|
|
905
905
|
async (e, n) => {
|
|
906
906
|
const r = (n?.markets || Object.keys(M)).map((t) => _(t)).map((t) => ({
|
|
907
907
|
address: e,
|
|
@@ -910,7 +910,7 @@ const it = $(
|
|
|
910
910
|
return await te(e, r, n);
|
|
911
911
|
}
|
|
912
912
|
);
|
|
913
|
-
async function
|
|
913
|
+
async function it(e, n) {
|
|
914
914
|
const o = n?.client ?? P, r = new U();
|
|
915
915
|
await Ae(r, e, n);
|
|
916
916
|
const t = await o.devInspectTransactionBlock({
|
|
@@ -921,20 +921,20 @@ async function ct(e, n) {
|
|
|
921
921
|
}
|
|
922
922
|
async function st(e, n, o, r) {
|
|
923
923
|
const t = r?.client ?? P, a = new U();
|
|
924
|
-
let
|
|
924
|
+
let i = 0, c = 0;
|
|
925
925
|
const s = await A(n, r);
|
|
926
926
|
if (o.forEach((v) => {
|
|
927
|
-
v.type === F.Supply ?
|
|
928
|
-
}),
|
|
927
|
+
v.type === F.Supply ? i += v.amount : v.type === F.Withdraw ? i -= v.amount : v.type === F.Borrow ? c += v.amount : v.type === F.Repay && (c -= v.amount);
|
|
928
|
+
}), i * c < 0)
|
|
929
929
|
throw new Error("Invalid operations");
|
|
930
|
-
const
|
|
930
|
+
const l = i > 0 || c > 0;
|
|
931
931
|
await ee(
|
|
932
932
|
a,
|
|
933
933
|
e,
|
|
934
934
|
s,
|
|
935
|
-
Math.abs(c),
|
|
936
935
|
Math.abs(i),
|
|
937
|
-
|
|
936
|
+
Math.abs(c),
|
|
937
|
+
l,
|
|
938
938
|
r
|
|
939
939
|
);
|
|
940
940
|
const d = await t.devInspectTransactionBlock({
|
|
@@ -943,7 +943,7 @@ async function st(e, n, o, r) {
|
|
|
943
943
|
}), f = L(d, [C.u256()]);
|
|
944
944
|
return X(Number(f[0]) || 0);
|
|
945
945
|
}
|
|
946
|
-
const
|
|
946
|
+
const lt = B(
|
|
947
947
|
async (e, n) => {
|
|
948
948
|
const o = new URLSearchParams();
|
|
949
949
|
n?.cursor && o.set("cursor", n.cursor), o.set("userAddress", e);
|
|
@@ -951,7 +951,7 @@ const ut = B(
|
|
|
951
951
|
return (await fetch(r, { headers: E }).then((a) => a.json())).data;
|
|
952
952
|
}
|
|
953
953
|
);
|
|
954
|
-
async function
|
|
954
|
+
async function ut(e, n) {
|
|
955
955
|
let o = null;
|
|
956
956
|
const r = [], t = n?.client ?? P;
|
|
957
957
|
do {
|
|
@@ -973,46 +973,46 @@ async function lt(e, n) {
|
|
|
973
973
|
}
|
|
974
974
|
const $e = $(
|
|
975
975
|
async (e, n) => {
|
|
976
|
-
const o = [], r = (n?.markets || Object.keys(M)).map((
|
|
976
|
+
const o = [], r = (n?.markets || Object.keys(M)).map((c) => _(c));
|
|
977
977
|
let t = [];
|
|
978
978
|
try {
|
|
979
979
|
t = await x(e, n);
|
|
980
|
-
} catch (
|
|
981
|
-
console.error(
|
|
980
|
+
} catch (c) {
|
|
981
|
+
console.error(c);
|
|
982
982
|
}
|
|
983
|
-
const a = r.map((
|
|
983
|
+
const a = r.map((c) => ({
|
|
984
984
|
address: e,
|
|
985
|
-
market:
|
|
985
|
+
market: c.key
|
|
986
986
|
})).concat(
|
|
987
|
-
t.filter((
|
|
988
|
-
address:
|
|
989
|
-
market: _(
|
|
990
|
-
emodeId:
|
|
987
|
+
t.filter((c) => !!r.find((s) => s.id === c.marketId)).map((c) => ({
|
|
988
|
+
address: c.accountCap,
|
|
989
|
+
market: _(c.marketId).key,
|
|
990
|
+
emodeId: c.emodeId
|
|
991
991
|
}))
|
|
992
992
|
);
|
|
993
|
-
return (await te(e, a, n)).forEach((
|
|
994
|
-
const s = typeof
|
|
995
|
-
const d = _(
|
|
996
|
-
return
|
|
993
|
+
return (await te(e, a, n)).forEach((c) => {
|
|
994
|
+
const s = typeof c.emodeId == "number" ? t.find((l) => {
|
|
995
|
+
const d = _(c.market);
|
|
996
|
+
return l.emodeId === c.emodeId && l.marketId === d.id;
|
|
997
997
|
}) : void 0;
|
|
998
998
|
if (s) {
|
|
999
|
-
if (!
|
|
999
|
+
if (!c.pool.emodes.find((d) => d.emodeId === s.emodeId))
|
|
1000
1000
|
return;
|
|
1001
|
-
if (p(
|
|
1002
|
-
const d = p(
|
|
1001
|
+
if (p(c.supplyBalance).gte(0)) {
|
|
1002
|
+
const d = p(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, p.ROUND_DOWN), f = q(c.pool, s);
|
|
1003
1003
|
if (d.gt(0) || f.emode.isCollateral)
|
|
1004
1004
|
try {
|
|
1005
1005
|
o.push({
|
|
1006
|
-
id: `${
|
|
1006
|
+
id: `${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${T()}`,
|
|
1007
1007
|
wallet: e,
|
|
1008
1008
|
protocol: "navi",
|
|
1009
|
-
market:
|
|
1009
|
+
market: c.market,
|
|
1010
1010
|
type: "navi-lending-emode-supply",
|
|
1011
1011
|
"navi-lending-emode-supply": {
|
|
1012
1012
|
amount: d.toString(),
|
|
1013
|
-
pool: q(
|
|
1014
|
-
token:
|
|
1015
|
-
valueUSD: d.multipliedBy(
|
|
1013
|
+
pool: q(c.pool, s),
|
|
1014
|
+
token: c.pool.token,
|
|
1015
|
+
valueUSD: d.multipliedBy(c.pool.oracle.price).toString(),
|
|
1016
1016
|
emodeCap: s
|
|
1017
1017
|
}
|
|
1018
1018
|
});
|
|
@@ -1020,21 +1020,21 @@ const $e = $(
|
|
|
1020
1020
|
console.error(v);
|
|
1021
1021
|
}
|
|
1022
1022
|
}
|
|
1023
|
-
if (p(
|
|
1024
|
-
const d = p(
|
|
1023
|
+
if (p(c.borrowBalance).gte(0)) {
|
|
1024
|
+
const d = p(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, p.ROUND_DOWN), f = q(c.pool, s);
|
|
1025
1025
|
if (d.gt(0) || f.emode.isDebt)
|
|
1026
1026
|
try {
|
|
1027
1027
|
o.push({
|
|
1028
|
-
id: `${
|
|
1028
|
+
id: `${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${T()}`,
|
|
1029
1029
|
wallet: e,
|
|
1030
1030
|
protocol: "navi",
|
|
1031
|
-
market:
|
|
1031
|
+
market: c.market,
|
|
1032
1032
|
type: "navi-lending-emode-borrow",
|
|
1033
1033
|
"navi-lending-emode-borrow": {
|
|
1034
1034
|
amount: d.toString(),
|
|
1035
|
-
pool: q(
|
|
1036
|
-
token:
|
|
1037
|
-
valueUSD: d.multipliedBy(
|
|
1035
|
+
pool: q(c.pool, s),
|
|
1036
|
+
token: c.pool.token,
|
|
1037
|
+
valueUSD: d.multipliedBy(c.pool.oracle.price).toString(),
|
|
1038
1038
|
emodeCap: s
|
|
1039
1039
|
}
|
|
1040
1040
|
});
|
|
@@ -1043,35 +1043,35 @@ const $e = $(
|
|
|
1043
1043
|
}
|
|
1044
1044
|
}
|
|
1045
1045
|
} else {
|
|
1046
|
-
if (p(
|
|
1047
|
-
const
|
|
1046
|
+
if (p(c.supplyBalance).gt(0)) {
|
|
1047
|
+
const l = p(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, p.ROUND_DOWN);
|
|
1048
1048
|
o.push({
|
|
1049
|
-
id: `${
|
|
1049
|
+
id: `${c.pool.uniqueId}_navi-lending-supply-${T()}`,
|
|
1050
1050
|
wallet: e,
|
|
1051
1051
|
protocol: "navi",
|
|
1052
1052
|
type: "navi-lending-supply",
|
|
1053
|
-
market:
|
|
1053
|
+
market: c.market,
|
|
1054
1054
|
"navi-lending-supply": {
|
|
1055
|
-
amount:
|
|
1056
|
-
pool:
|
|
1057
|
-
token:
|
|
1058
|
-
valueUSD:
|
|
1055
|
+
amount: l.toString(),
|
|
1056
|
+
pool: c.pool,
|
|
1057
|
+
token: c.pool.token,
|
|
1058
|
+
valueUSD: l.multipliedBy(c.pool.oracle.price).toString()
|
|
1059
1059
|
}
|
|
1060
1060
|
});
|
|
1061
1061
|
}
|
|
1062
|
-
if (p(
|
|
1063
|
-
const
|
|
1062
|
+
if (p(c.borrowBalance).gt(0)) {
|
|
1063
|
+
const l = p(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, p.ROUND_DOWN);
|
|
1064
1064
|
o.push({
|
|
1065
|
-
id: `${
|
|
1065
|
+
id: `${c.pool.uniqueId}_navi-lending-borrow-${T()}`,
|
|
1066
1066
|
wallet: e,
|
|
1067
1067
|
protocol: "navi",
|
|
1068
|
-
market:
|
|
1068
|
+
market: c.market,
|
|
1069
1069
|
type: "navi-lending-borrow",
|
|
1070
1070
|
"navi-lending-borrow": {
|
|
1071
|
-
amount:
|
|
1072
|
-
pool:
|
|
1073
|
-
token:
|
|
1074
|
-
valueUSD:
|
|
1071
|
+
amount: l.toString(),
|
|
1072
|
+
pool: c.pool,
|
|
1073
|
+
token: c.pool.token,
|
|
1074
|
+
valueUSD: l.multipliedBy(c.pool.oracle.price).toString()
|
|
1075
1075
|
}
|
|
1076
1076
|
});
|
|
1077
1077
|
}
|
|
@@ -1117,7 +1117,7 @@ class O {
|
|
|
1117
1117
|
const r = !!n.isEMode;
|
|
1118
1118
|
let t;
|
|
1119
1119
|
return r ? t = {
|
|
1120
|
-
id:
|
|
1120
|
+
id: T(),
|
|
1121
1121
|
wallet: "",
|
|
1122
1122
|
protocol: "navi",
|
|
1123
1123
|
market: "",
|
|
@@ -1130,7 +1130,7 @@ class O {
|
|
|
1130
1130
|
emodeCap: {}
|
|
1131
1131
|
}
|
|
1132
1132
|
} : t = {
|
|
1133
|
-
id:
|
|
1133
|
+
id: T(),
|
|
1134
1134
|
wallet: "",
|
|
1135
1135
|
protocol: "navi",
|
|
1136
1136
|
market: "",
|
|
@@ -1147,7 +1147,7 @@ class O {
|
|
|
1147
1147
|
const r = !!n.isEMode;
|
|
1148
1148
|
let t;
|
|
1149
1149
|
return r ? t = {
|
|
1150
|
-
id:
|
|
1150
|
+
id: T(),
|
|
1151
1151
|
wallet: "",
|
|
1152
1152
|
protocol: "navi",
|
|
1153
1153
|
market: "",
|
|
@@ -1160,7 +1160,7 @@ class O {
|
|
|
1160
1160
|
emodeCap: {}
|
|
1161
1161
|
}
|
|
1162
1162
|
} : t = {
|
|
1163
|
-
id:
|
|
1163
|
+
id: T(),
|
|
1164
1164
|
wallet: "",
|
|
1165
1165
|
protocol: "navi",
|
|
1166
1166
|
market: "",
|
|
@@ -1177,7 +1177,7 @@ class O {
|
|
|
1177
1177
|
const r = !!n.isEMode;
|
|
1178
1178
|
let t;
|
|
1179
1179
|
return r ? t = {
|
|
1180
|
-
id:
|
|
1180
|
+
id: T(),
|
|
1181
1181
|
wallet: "",
|
|
1182
1182
|
protocol: "navi",
|
|
1183
1183
|
market: "",
|
|
@@ -1190,7 +1190,7 @@ class O {
|
|
|
1190
1190
|
emodeCap: {}
|
|
1191
1191
|
}
|
|
1192
1192
|
} : t = {
|
|
1193
|
-
id:
|
|
1193
|
+
id: T(),
|
|
1194
1194
|
wallet: "",
|
|
1195
1195
|
protocol: "navi",
|
|
1196
1196
|
market: "",
|
|
@@ -1207,7 +1207,7 @@ class O {
|
|
|
1207
1207
|
const r = !!n.isEMode;
|
|
1208
1208
|
let t;
|
|
1209
1209
|
return r ? t = {
|
|
1210
|
-
id:
|
|
1210
|
+
id: T(),
|
|
1211
1211
|
wallet: "",
|
|
1212
1212
|
protocol: "navi",
|
|
1213
1213
|
market: "",
|
|
@@ -1220,7 +1220,7 @@ class O {
|
|
|
1220
1220
|
emodeCap: {}
|
|
1221
1221
|
}
|
|
1222
1222
|
} : t = {
|
|
1223
|
-
id:
|
|
1223
|
+
id: T(),
|
|
1224
1224
|
wallet: "",
|
|
1225
1225
|
protocol: "navi",
|
|
1226
1226
|
market: "",
|
|
@@ -1235,61 +1235,61 @@ class O {
|
|
|
1235
1235
|
}
|
|
1236
1236
|
getPositionsOverview(n) {
|
|
1237
1237
|
const o = {}, r = {};
|
|
1238
|
-
let t = new p(0), a = new p(0),
|
|
1238
|
+
let t = new p(0), a = new p(0), i = new p(0), c = new p(0), s = new p(0), l = new p(0);
|
|
1239
1239
|
n.forEach((y) => {
|
|
1240
1240
|
if (y.type === "navi-lending-supply") {
|
|
1241
|
-
const
|
|
1242
|
-
t = t.plus(
|
|
1243
|
-
new p(
|
|
1244
|
-
),
|
|
1245
|
-
new p(
|
|
1241
|
+
const u = y["navi-lending-supply"];
|
|
1242
|
+
t = t.plus(u.valueUSD), s = s.plus(
|
|
1243
|
+
new p(u.valueUSD).multipliedBy(u.pool.liquidationFactor.threshold)
|
|
1244
|
+
), l = l.plus(
|
|
1245
|
+
new p(u.valueUSD).multipliedBy(u.pool.ltvValue)
|
|
1246
1246
|
);
|
|
1247
1247
|
} else if (y.type === "navi-lending-borrow")
|
|
1248
1248
|
a = a.plus(y["navi-lending-borrow"].valueUSD);
|
|
1249
1249
|
else if (y.type === "navi-lending-emode-supply") {
|
|
1250
|
-
const
|
|
1251
|
-
t = t.plus(
|
|
1252
|
-
const h =
|
|
1250
|
+
const u = y["navi-lending-emode-supply"];
|
|
1251
|
+
t = t.plus(u.valueUSD);
|
|
1252
|
+
const h = u.pool.emode;
|
|
1253
1253
|
s = s.plus(
|
|
1254
|
-
new p(
|
|
1255
|
-
),
|
|
1256
|
-
new p(
|
|
1254
|
+
new p(u.valueUSD).multipliedBy(h.lt)
|
|
1255
|
+
), l = l.plus(
|
|
1256
|
+
new p(u.valueUSD).multipliedBy(h.ltv)
|
|
1257
1257
|
);
|
|
1258
1258
|
} else y.type === "navi-lending-emode-borrow" && (a = a.plus(y["navi-lending-emode-borrow"].valueUSD));
|
|
1259
|
-
}), a = p.max(a, 0), t = p.max(t, 0), s = p.max(s, 0),
|
|
1259
|
+
}), a = p.max(a, 0), t = p.max(t, 0), s = p.max(s, 0), l = p.max(l, 0), n.forEach((y) => {
|
|
1260
1260
|
if (y.type === "navi-lending-supply") {
|
|
1261
|
-
const
|
|
1262
|
-
t.gt(0) && (
|
|
1263
|
-
new p(
|
|
1264
|
-
)), o[
|
|
1261
|
+
const u = y["navi-lending-supply"], h = u.pool.supplyIncentiveApyInfo.apy;
|
|
1262
|
+
t.gt(0) && (i = i.plus(
|
|
1263
|
+
new p(u.valueUSD).dividedBy(t).multipliedBy(new p(h).dividedBy(100))
|
|
1264
|
+
)), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1265
1265
|
} else if (y.type === "navi-lending-borrow") {
|
|
1266
|
-
const
|
|
1267
|
-
a.gt(0) && (
|
|
1268
|
-
new p(
|
|
1269
|
-
)), r[
|
|
1266
|
+
const u = y["navi-lending-borrow"], h = u.pool.borrowIncentiveApyInfo.apy;
|
|
1267
|
+
a.gt(0) && (c = c.plus(
|
|
1268
|
+
new p(u.valueUSD).dividedBy(a).multipliedBy(new p(h).dividedBy(100))
|
|
1269
|
+
)), r[u.pool.suiCoinType] = p(r[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1270
1270
|
} else if (y.type === "navi-lending-emode-supply") {
|
|
1271
|
-
const
|
|
1272
|
-
t.gt(0) && (
|
|
1273
|
-
new p(
|
|
1274
|
-
)), o[
|
|
1271
|
+
const u = y["navi-lending-emode-supply"], h = u.pool.supplyIncentiveApyInfo.apy;
|
|
1272
|
+
t.gt(0) && (i = i.plus(
|
|
1273
|
+
new p(u.valueUSD).dividedBy(t).multipliedBy(new p(h).dividedBy(100))
|
|
1274
|
+
)), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1275
1275
|
} else if (y.type === "navi-lending-emode-borrow") {
|
|
1276
|
-
const
|
|
1277
|
-
a.gt(0) && (
|
|
1278
|
-
new p(
|
|
1279
|
-
)), r[
|
|
1276
|
+
const u = y["navi-lending-emode-borrow"], h = u.pool.borrowIncentiveApyInfo.apy;
|
|
1277
|
+
a.gt(0) && (c = c.plus(
|
|
1278
|
+
new p(u.valueUSD).dividedBy(a).multipliedBy(new p(h).dividedBy(100))
|
|
1279
|
+
)), r[u.pool.suiCoinType] = p(r[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1280
1280
|
}
|
|
1281
1281
|
});
|
|
1282
|
-
const d = t.minus(a), f = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(
|
|
1282
|
+
const d = t.minus(a), f = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(i).minus(a.multipliedBy(c)).div(t.minus(a));
|
|
1283
1283
|
return {
|
|
1284
1284
|
hf: a.toNumber() !== 0 ? s.dividedBy(a).toNumber() : 1 / 0,
|
|
1285
1285
|
netVaule: d.toString(),
|
|
1286
1286
|
netWorthApr: f.toString(),
|
|
1287
1287
|
totalSupplyValue: t.toString(),
|
|
1288
1288
|
totalBorrowValue: a.toString(),
|
|
1289
|
-
totalsupplyApy:
|
|
1290
|
-
totalBorrowApy:
|
|
1289
|
+
totalsupplyApy: i.toString(),
|
|
1290
|
+
totalBorrowApy: c.toString(),
|
|
1291
1291
|
maxLiquidationValue: s.toString(),
|
|
1292
|
-
maxLoanToVaule:
|
|
1292
|
+
maxLoanToVaule: l.toString(),
|
|
1293
1293
|
supply: o,
|
|
1294
1294
|
borrow: r
|
|
1295
1295
|
};
|
|
@@ -1298,7 +1298,7 @@ class O {
|
|
|
1298
1298
|
async function pt(e, n, o, r) {
|
|
1299
1299
|
const t = await k({
|
|
1300
1300
|
...r,
|
|
1301
|
-
cacheTime:
|
|
1301
|
+
cacheTime: w
|
|
1302
1302
|
});
|
|
1303
1303
|
t.limter && e.moveCall({
|
|
1304
1304
|
target: `${t.limter}::navi_adaptor::verify_navi_position_healthy`,
|
|
@@ -1338,22 +1338,22 @@ async function dt(e) {
|
|
|
1338
1338
|
}
|
|
1339
1339
|
async function Pe(e, n) {
|
|
1340
1340
|
try {
|
|
1341
|
-
const o = [], r = n?.client ?? P, t = e.map((
|
|
1341
|
+
const o = [], r = n?.client ?? P, t = e.map((i) => i.priceInfoObject), a = await r.multiGetObjects({
|
|
1342
1342
|
ids: Array.from(new Set(t)),
|
|
1343
1343
|
options: { showContent: !0 }
|
|
1344
1344
|
});
|
|
1345
|
-
for (const
|
|
1346
|
-
const
|
|
1347
|
-
if (!
|
|
1348
|
-
console.warn(`fetched object ${
|
|
1345
|
+
for (const i of a) {
|
|
1346
|
+
const c = i.data;
|
|
1347
|
+
if (!c || !c.content || c.content.dataType !== "moveObject") {
|
|
1348
|
+
console.warn(`fetched object ${c?.objectId} datatype should be moveObject`);
|
|
1349
1349
|
continue;
|
|
1350
1350
|
}
|
|
1351
|
-
const s = e.find((
|
|
1351
|
+
const s = e.find((u) => u.priceInfoObject == c.objectId);
|
|
1352
1352
|
if (!s) {
|
|
1353
|
-
console.warn(`unable to find pyth info from array, priceInfoObject: ${
|
|
1353
|
+
console.warn(`unable to find pyth info from array, priceInfoObject: ${c.objectId}`);
|
|
1354
1354
|
continue;
|
|
1355
1355
|
}
|
|
1356
|
-
const
|
|
1356
|
+
const l = c.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: d, negative: f } = l.price.fields, v = l.conf, y = l.timestamp;
|
|
1357
1357
|
o.push({
|
|
1358
1358
|
priceFeedId: s.priceFeedId,
|
|
1359
1359
|
priceInfoObject: s.priceInfoObject,
|
|
@@ -1381,8 +1381,8 @@ async function Se(e, n) {
|
|
|
1381
1381
|
);
|
|
1382
1382
|
continue;
|
|
1383
1383
|
}
|
|
1384
|
-
const
|
|
1385
|
-
t - a.publishTime >
|
|
1384
|
+
const i = a.expiration || 60;
|
|
1385
|
+
t - a.publishTime > i && (console.info(
|
|
1386
1386
|
`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
|
|
1387
1387
|
), o.push(a.priceFeedId));
|
|
1388
1388
|
}
|
|
@@ -1394,7 +1394,7 @@ async function Se(e, n) {
|
|
|
1394
1394
|
async function Ve(e, n, o) {
|
|
1395
1395
|
const r = o?.client ?? P, t = await k({
|
|
1396
1396
|
...o,
|
|
1397
|
-
cacheTime:
|
|
1397
|
+
cacheTime: w
|
|
1398
1398
|
});
|
|
1399
1399
|
try {
|
|
1400
1400
|
const a = await oe.getPriceFeedsUpdateData(n);
|
|
@@ -1410,7 +1410,7 @@ async function Ve(e, n, o) {
|
|
|
1410
1410
|
async function Ee(e, n, o) {
|
|
1411
1411
|
const r = await k({
|
|
1412
1412
|
...o,
|
|
1413
|
-
cacheTime:
|
|
1413
|
+
cacheTime: w
|
|
1414
1414
|
});
|
|
1415
1415
|
if (o?.updatePythPriceFeeds) {
|
|
1416
1416
|
const t = n.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
|
|
@@ -1426,7 +1426,7 @@ async function Ee(e, n, o) {
|
|
|
1426
1426
|
}
|
|
1427
1427
|
}
|
|
1428
1428
|
for (const t of n)
|
|
1429
|
-
o?.env === "dev"
|
|
1429
|
+
o?.env === "dev" ? e.moveCall({
|
|
1430
1430
|
target: `${r.oracle.packageId}::oracle_pro::update_single_price`,
|
|
1431
1431
|
arguments: [
|
|
1432
1432
|
e.object("0x6"),
|
|
@@ -1465,11 +1465,11 @@ async function Ee(e, n, o) {
|
|
|
1465
1465
|
async function ne(e) {
|
|
1466
1466
|
return (await k({
|
|
1467
1467
|
...e,
|
|
1468
|
-
cacheTime:
|
|
1468
|
+
cacheTime: w
|
|
1469
1469
|
})).oracle.feeds;
|
|
1470
1470
|
}
|
|
1471
1471
|
function Me(e, n) {
|
|
1472
|
-
return e.filter((o) => !!(n?.lendingState && n.lendingState.find((t) =>
|
|
1472
|
+
return e.filter((o) => !!(n?.lendingState && n.lendingState.find((t) => o.oracleId === t.pool.oracleId) || n?.lendingPositions && n.lendingPositions.find((t) => {
|
|
1473
1473
|
if (![
|
|
1474
1474
|
"navi-lending-supply",
|
|
1475
1475
|
"navi-lending-borrow",
|
|
@@ -1477,26 +1477,26 @@ function Me(e, n) {
|
|
|
1477
1477
|
"navi-lending-emode-borrow"
|
|
1478
1478
|
].includes(t.type))
|
|
1479
1479
|
return !1;
|
|
1480
|
-
const
|
|
1481
|
-
return
|
|
1482
|
-
}) || n?.pools && n.pools.find((t) =>
|
|
1480
|
+
const i = t[t.type]?.pool;
|
|
1481
|
+
return o.oracleId === i?.oracleId;
|
|
1482
|
+
}) || n?.pools && n.pools.find((t) => o.oracleId === t.oracleId)));
|
|
1483
1483
|
}
|
|
1484
1484
|
async function mt(e, n, o, r) {
|
|
1485
1485
|
try {
|
|
1486
1486
|
const t = await ne({
|
|
1487
1487
|
...r
|
|
1488
1488
|
}), a = [];
|
|
1489
|
-
o.forEach((
|
|
1490
|
-
a.includes(
|
|
1489
|
+
o.forEach((l) => {
|
|
1490
|
+
a.includes(l.market) || a.push(l.market);
|
|
1491
1491
|
});
|
|
1492
|
-
const
|
|
1492
|
+
const i = await $e(n, {
|
|
1493
1493
|
...r,
|
|
1494
1494
|
markets: a
|
|
1495
|
-
}),
|
|
1496
|
-
lendingPositions:
|
|
1495
|
+
}), c = Me(t, {
|
|
1496
|
+
lendingPositions: i,
|
|
1497
1497
|
pools: o
|
|
1498
1498
|
});
|
|
1499
|
-
return await Ee(e,
|
|
1499
|
+
return await Ee(e, c, {
|
|
1500
1500
|
updatePythPriceFeeds: !0,
|
|
1501
1501
|
...r
|
|
1502
1502
|
});
|
|
@@ -1518,22 +1518,22 @@ const G = $(
|
|
|
1518
1518
|
)
|
|
1519
1519
|
);
|
|
1520
1520
|
async function ft(e, n) {
|
|
1521
|
-
return (await G(n)).find((r) => typeof e == "string" ?
|
|
1521
|
+
return (await G(n)).find((r) => typeof e == "string" ? b(r.coinType) === b(e) : typeof e == "number" ? r.assetId === e : r.assetId === e.id) || null;
|
|
1522
1522
|
}
|
|
1523
1523
|
async function yt(e, n, o, r) {
|
|
1524
1524
|
const t = await k({
|
|
1525
1525
|
...r,
|
|
1526
|
-
cacheTime:
|
|
1526
|
+
cacheTime: w
|
|
1527
1527
|
}), a = await A(n, r);
|
|
1528
1528
|
if (!(await G({
|
|
1529
1529
|
...r,
|
|
1530
|
-
cacheTime:
|
|
1530
|
+
cacheTime: w
|
|
1531
1531
|
})).some(
|
|
1532
|
-
(s) =>
|
|
1532
|
+
(s) => b(s.coinType) === b(a.suiCoinType)
|
|
1533
1533
|
))
|
|
1534
1534
|
throw new Error("Pool does not support flashloan");
|
|
1535
1535
|
if (t.version === 1) {
|
|
1536
|
-
const [s,
|
|
1536
|
+
const [s, l] = e.moveCall({
|
|
1537
1537
|
target: `${t.package}::lending::flash_loan_with_ctx`,
|
|
1538
1538
|
arguments: [
|
|
1539
1539
|
e.object(t.flashloanConfig),
|
|
@@ -1542,9 +1542,9 @@ async function yt(e, n, o, r) {
|
|
|
1542
1542
|
],
|
|
1543
1543
|
typeArguments: [a.suiCoinType]
|
|
1544
1544
|
});
|
|
1545
|
-
return [s,
|
|
1545
|
+
return [s, l];
|
|
1546
1546
|
} else {
|
|
1547
|
-
const [s,
|
|
1547
|
+
const [s, l] = e.moveCall({
|
|
1548
1548
|
target: `${t.package}::lending::flash_loan_with_ctx_v2`,
|
|
1549
1549
|
arguments: [
|
|
1550
1550
|
e.object(t.flashloanConfig),
|
|
@@ -1554,48 +1554,48 @@ async function yt(e, n, o, r) {
|
|
|
1554
1554
|
],
|
|
1555
1555
|
typeArguments: [a.suiCoinType]
|
|
1556
1556
|
});
|
|
1557
|
-
return [s,
|
|
1557
|
+
return [s, l];
|
|
1558
1558
|
}
|
|
1559
1559
|
}
|
|
1560
1560
|
async function gt(e, n, o, r, t) {
|
|
1561
1561
|
const a = await k({
|
|
1562
1562
|
...t,
|
|
1563
|
-
cacheTime:
|
|
1564
|
-
}),
|
|
1563
|
+
cacheTime: w
|
|
1564
|
+
}), i = await A(n, t);
|
|
1565
1565
|
if (!(await G({
|
|
1566
1566
|
...t,
|
|
1567
|
-
cacheTime:
|
|
1567
|
+
cacheTime: w
|
|
1568
1568
|
})).some(
|
|
1569
|
-
(d) =>
|
|
1569
|
+
(d) => b(d.coinType) === b(i.suiCoinType)
|
|
1570
1570
|
))
|
|
1571
1571
|
throw new Error("Pool does not support flashloan");
|
|
1572
|
-
const [
|
|
1572
|
+
const [l] = e.moveCall({
|
|
1573
1573
|
target: `${a.package}::lending::flash_repay_with_ctx`,
|
|
1574
1574
|
arguments: [
|
|
1575
1575
|
e.object("0x06"),
|
|
1576
1576
|
e.object(a.storage),
|
|
1577
|
-
e.object(
|
|
1577
|
+
e.object(i.contract.pool),
|
|
1578
1578
|
g(o, e.object),
|
|
1579
1579
|
g(r, e.object)
|
|
1580
1580
|
],
|
|
1581
|
-
typeArguments: [
|
|
1581
|
+
typeArguments: [i.suiCoinType]
|
|
1582
1582
|
});
|
|
1583
|
-
return [
|
|
1583
|
+
return [l];
|
|
1584
1584
|
}
|
|
1585
1585
|
async function ht(e, n, o, r, t, a) {
|
|
1586
|
-
const
|
|
1586
|
+
const i = {
|
|
1587
1587
|
...a,
|
|
1588
|
-
cacheTime:
|
|
1589
|
-
},
|
|
1590
|
-
if (
|
|
1588
|
+
cacheTime: w
|
|
1589
|
+
}, c = await k(i), s = await A(n, i), l = await A(r, i);
|
|
1590
|
+
if (c.version === 1) {
|
|
1591
1591
|
const [d, f] = e.moveCall({
|
|
1592
|
-
target: `${
|
|
1592
|
+
target: `${c.package}::incentive_v3::liquidation`,
|
|
1593
1593
|
arguments: [
|
|
1594
1594
|
e.object("0x06"),
|
|
1595
1595
|
// Clock object
|
|
1596
|
-
e.object(
|
|
1596
|
+
e.object(c.priceOracle),
|
|
1597
1597
|
// Price oracle for asset pricing
|
|
1598
|
-
e.object(
|
|
1598
|
+
e.object(c.storage),
|
|
1599
1599
|
// Protocol storage
|
|
1600
1600
|
e.pure.u8(s.id),
|
|
1601
1601
|
// Pay asset ID
|
|
@@ -1603,29 +1603,29 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1603
1603
|
// Pay asset pool contract
|
|
1604
1604
|
g(o, e.object),
|
|
1605
1605
|
// Debt repayment amount
|
|
1606
|
-
e.pure.u8(
|
|
1606
|
+
e.pure.u8(l.id),
|
|
1607
1607
|
// Collateral asset ID
|
|
1608
|
-
e.object(
|
|
1608
|
+
e.object(l.contract.pool),
|
|
1609
1609
|
// Collateral asset pool contract
|
|
1610
1610
|
g(t, e.pure.address),
|
|
1611
1611
|
// Borrower address
|
|
1612
|
-
e.object(
|
|
1612
|
+
e.object(c.incentiveV2),
|
|
1613
1613
|
// Incentive V2 contract
|
|
1614
|
-
e.object(
|
|
1614
|
+
e.object(c.incentiveV3)
|
|
1615
1615
|
// Incentive V3 contract
|
|
1616
1616
|
],
|
|
1617
|
-
typeArguments: [s.suiCoinType,
|
|
1617
|
+
typeArguments: [s.suiCoinType, l.suiCoinType]
|
|
1618
1618
|
});
|
|
1619
1619
|
return [d, f];
|
|
1620
1620
|
} else {
|
|
1621
1621
|
const [d, f] = e.moveCall({
|
|
1622
|
-
target: `${
|
|
1622
|
+
target: `${c.package}::incentive_v3::liquidation_v2`,
|
|
1623
1623
|
arguments: [
|
|
1624
1624
|
e.object("0x06"),
|
|
1625
1625
|
// Clock object
|
|
1626
|
-
e.object(
|
|
1626
|
+
e.object(c.priceOracle),
|
|
1627
1627
|
// Price oracle for asset pricing
|
|
1628
|
-
e.object(
|
|
1628
|
+
e.object(c.storage),
|
|
1629
1629
|
// Protocol storage
|
|
1630
1630
|
e.pure.u8(s.id),
|
|
1631
1631
|
// Pay asset ID
|
|
@@ -1633,20 +1633,20 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1633
1633
|
// Pay asset pool contract
|
|
1634
1634
|
g(o, e.object),
|
|
1635
1635
|
// Debt repayment amount
|
|
1636
|
-
e.pure.u8(
|
|
1636
|
+
e.pure.u8(l.id),
|
|
1637
1637
|
// Collateral asset ID
|
|
1638
|
-
e.object(
|
|
1638
|
+
e.object(l.contract.pool),
|
|
1639
1639
|
// Collateral asset pool contract
|
|
1640
1640
|
g(t, e.pure.address),
|
|
1641
1641
|
// Borrower address
|
|
1642
|
-
e.object(
|
|
1642
|
+
e.object(c.incentiveV2),
|
|
1643
1643
|
// Incentive V2 contract
|
|
1644
|
-
e.object(
|
|
1644
|
+
e.object(c.incentiveV3),
|
|
1645
1645
|
// Incentive V3 contract
|
|
1646
1646
|
e.object("0x05")
|
|
1647
1647
|
// SuiSystemState object
|
|
1648
1648
|
],
|
|
1649
|
-
typeArguments: [s.suiCoinType,
|
|
1649
|
+
typeArguments: [s.suiCoinType, l.suiCoinType]
|
|
1650
1650
|
});
|
|
1651
1651
|
return [d, f];
|
|
1652
1652
|
}
|
|
@@ -1655,12 +1655,12 @@ async function De(e, n, o) {
|
|
|
1655
1655
|
const r = o?.client ?? P, t = new U(), a = await R({
|
|
1656
1656
|
...o,
|
|
1657
1657
|
markets: Object.values(M),
|
|
1658
|
-
cacheTime:
|
|
1659
|
-
}),
|
|
1658
|
+
cacheTime: w
|
|
1659
|
+
}), i = await ne(o);
|
|
1660
1660
|
for (let d of n) {
|
|
1661
1661
|
const f = await k({
|
|
1662
1662
|
...o,
|
|
1663
|
-
cacheTime:
|
|
1663
|
+
cacheTime: w,
|
|
1664
1664
|
market: d.market
|
|
1665
1665
|
});
|
|
1666
1666
|
t.moveCall({
|
|
@@ -1677,11 +1677,11 @@ async function De(e, n, o) {
|
|
|
1677
1677
|
]
|
|
1678
1678
|
});
|
|
1679
1679
|
}
|
|
1680
|
-
const
|
|
1680
|
+
const c = await r.devInspectTransactionBlock({
|
|
1681
1681
|
transactionBlock: t,
|
|
1682
1682
|
sender: e
|
|
1683
1683
|
}), s = [];
|
|
1684
|
-
|
|
1684
|
+
c?.results?.forEach((d) => {
|
|
1685
1685
|
s.push(
|
|
1686
1686
|
L(
|
|
1687
1687
|
{
|
|
@@ -1702,24 +1702,24 @@ async function De(e, n, o) {
|
|
|
1702
1702
|
)
|
|
1703
1703
|
);
|
|
1704
1704
|
});
|
|
1705
|
-
const
|
|
1705
|
+
const l = [];
|
|
1706
1706
|
return s.forEach((d, f) => {
|
|
1707
1707
|
const v = n[f];
|
|
1708
1708
|
if (d.length === 5 && Array.isArray(d[0])) {
|
|
1709
1709
|
const y = d[0].length;
|
|
1710
|
-
for (let
|
|
1711
|
-
const h =
|
|
1712
|
-
(
|
|
1710
|
+
for (let u = 0; u < y; u++) {
|
|
1711
|
+
const h = i.find(
|
|
1712
|
+
(I) => b(I.coinType) === b(d[1][u])
|
|
1713
1713
|
), j = a.find(
|
|
1714
|
-
(
|
|
1714
|
+
(I) => b(I.coinType) === b(d[0][u]) && I.market === v.market
|
|
1715
1715
|
);
|
|
1716
|
-
!h || !j ||
|
|
1716
|
+
!h || !j || l.push({
|
|
1717
1717
|
assetId: j.id,
|
|
1718
|
-
assetCoinType:
|
|
1719
|
-
rewardCoinType:
|
|
1720
|
-
option: Number(d[2][
|
|
1721
|
-
userClaimableReward: Number(d[4][
|
|
1722
|
-
ruleIds: Array.isArray(d[3][
|
|
1718
|
+
assetCoinType: b(d[0][u]),
|
|
1719
|
+
rewardCoinType: b(d[1][u]),
|
|
1720
|
+
option: Number(d[2][u]),
|
|
1721
|
+
userClaimableReward: Number(d[4][u]) / Math.pow(10, h.priceDecimal),
|
|
1722
|
+
ruleIds: Array.isArray(d[3][u]) ? d[3][u] : [d[3][u]],
|
|
1723
1723
|
market: v.market,
|
|
1724
1724
|
owner: v.owner,
|
|
1725
1725
|
address: v.address,
|
|
@@ -1727,7 +1727,7 @@ async function De(e, n, o) {
|
|
|
1727
1727
|
});
|
|
1728
1728
|
}
|
|
1729
1729
|
}
|
|
1730
|
-
}),
|
|
1730
|
+
}), l;
|
|
1731
1731
|
}
|
|
1732
1732
|
async function vt(e, n) {
|
|
1733
1733
|
const o = (n?.markets || [M.main]).map((a) => _(a));
|
|
@@ -1742,12 +1742,12 @@ async function vt(e, n) {
|
|
|
1742
1742
|
owner: e,
|
|
1743
1743
|
market: a.key
|
|
1744
1744
|
})).concat(
|
|
1745
|
-
r.filter((a) => !!o.find((
|
|
1746
|
-
const
|
|
1745
|
+
r.filter((a) => !!o.find((i) => i.id === a.marketId)).map((a) => {
|
|
1746
|
+
const i = _(a.marketId);
|
|
1747
1747
|
return {
|
|
1748
1748
|
address: a.accountCap,
|
|
1749
1749
|
owner: e,
|
|
1750
|
-
market:
|
|
1750
|
+
market: i.key,
|
|
1751
1751
|
emodeId: a.emodeId
|
|
1752
1752
|
};
|
|
1753
1753
|
})
|
|
@@ -1757,8 +1757,8 @@ async function vt(e, n) {
|
|
|
1757
1757
|
function wt(e) {
|
|
1758
1758
|
const n = /* @__PURE__ */ new Map();
|
|
1759
1759
|
e.forEach((r) => {
|
|
1760
|
-
const t = r.assetId, a = r.option,
|
|
1761
|
-
n.has(
|
|
1760
|
+
const t = r.assetId, a = r.option, i = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
|
|
1761
|
+
n.has(i) ? n.get(i).total += r.userClaimableReward : n.set(i, {
|
|
1762
1762
|
assetId: t,
|
|
1763
1763
|
rewardType: a,
|
|
1764
1764
|
coinType: r.rewardCoinType,
|
|
@@ -1767,11 +1767,11 @@ function wt(e) {
|
|
|
1767
1767
|
});
|
|
1768
1768
|
});
|
|
1769
1769
|
const o = /* @__PURE__ */ new Map();
|
|
1770
|
-
for (const { assetId: r, rewardType: t, coinType: a, total:
|
|
1771
|
-
const s = `${r}-${t}-${
|
|
1772
|
-
o.has(s) || o.set(s, { assetId: r, rewardType: t, market:
|
|
1773
|
-
const
|
|
1774
|
-
|
|
1770
|
+
for (const { assetId: r, rewardType: t, coinType: a, total: i, market: c } of n.values()) {
|
|
1771
|
+
const s = `${r}-${t}-${c}`;
|
|
1772
|
+
o.has(s) || o.set(s, { assetId: r, rewardType: t, market: c, rewards: /* @__PURE__ */ new Map() });
|
|
1773
|
+
const l = o.get(s);
|
|
1774
|
+
l.rewards.set(a, (l.rewards.get(a) || 0) + i);
|
|
1775
1775
|
}
|
|
1776
1776
|
return Array.from(o.values()).map((r) => ({
|
|
1777
1777
|
assetId: r.assetId,
|
|
@@ -1800,55 +1800,55 @@ async function Ct(e, n, o) {
|
|
|
1800
1800
|
const r = await R({
|
|
1801
1801
|
...o,
|
|
1802
1802
|
markets: Object.values(M),
|
|
1803
|
-
cacheTime:
|
|
1803
|
+
cacheTime: w
|
|
1804
1804
|
}), t = /* @__PURE__ */ new Map();
|
|
1805
|
-
for (const
|
|
1806
|
-
const { rewardCoinType:
|
|
1807
|
-
for (const
|
|
1805
|
+
for (const i of n) {
|
|
1806
|
+
const { rewardCoinType: c, ruleIds: s, market: l, owner: d, address: f, emodeId: v } = i, y = `${c}___${f}`;
|
|
1807
|
+
for (const u of s) {
|
|
1808
1808
|
t.has(y) || t.set(y, {
|
|
1809
1809
|
assetIds: [],
|
|
1810
1810
|
ruleIds: [],
|
|
1811
1811
|
amount: 0,
|
|
1812
|
-
market:
|
|
1812
|
+
market: l,
|
|
1813
1813
|
owner: d,
|
|
1814
1814
|
address: f,
|
|
1815
1815
|
isEMode: typeof v < "u"
|
|
1816
1816
|
});
|
|
1817
1817
|
const h = t.get(y);
|
|
1818
|
-
h.assetIds.push(
|
|
1818
|
+
h.assetIds.push(i.assetCoinType.replace("0x", "")), h.ruleIds.push(u), h.amount += i.userClaimableReward;
|
|
1819
1819
|
}
|
|
1820
1820
|
}
|
|
1821
1821
|
const a = [];
|
|
1822
1822
|
for (const [
|
|
1823
|
-
|
|
1824
|
-
{ assetIds:
|
|
1823
|
+
i,
|
|
1824
|
+
{ assetIds: c, ruleIds: s, amount: l, market: d, owner: f, address: v, isEMode: y }
|
|
1825
1825
|
] of t) {
|
|
1826
|
-
const
|
|
1826
|
+
const u = await k({
|
|
1827
1827
|
...o,
|
|
1828
|
-
cacheTime:
|
|
1828
|
+
cacheTime: w,
|
|
1829
1829
|
market: d
|
|
1830
|
-
}), h =
|
|
1831
|
-
(S) =>
|
|
1830
|
+
}), h = i.split("___")[0], j = r.find(
|
|
1831
|
+
(S) => b(S.suiCoinType) === b(h) && S.market === d
|
|
1832
1832
|
);
|
|
1833
1833
|
if (!j || !j.contract.rewardFundId)
|
|
1834
1834
|
throw new Error(`No matching rewardFund found for reward coin: ${h} ${d}`);
|
|
1835
|
-
const
|
|
1835
|
+
const I = j.contract.rewardFundId;
|
|
1836
1836
|
if (o?.accountCap && !o.customCoinReceive)
|
|
1837
1837
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
1838
1838
|
if (o?.customCoinReceive) {
|
|
1839
1839
|
let S;
|
|
1840
1840
|
o.accountCap ? S = e.moveCall({
|
|
1841
|
-
target: `${
|
|
1841
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1842
1842
|
arguments: [
|
|
1843
1843
|
e.object("0x06"),
|
|
1844
1844
|
// Clock object
|
|
1845
|
-
e.object(
|
|
1845
|
+
e.object(u.incentiveV3),
|
|
1846
1846
|
// Incentive V3 contract
|
|
1847
|
-
e.object(
|
|
1847
|
+
e.object(u.storage),
|
|
1848
1848
|
// Protocol storage
|
|
1849
|
-
e.object(
|
|
1849
|
+
e.object(I),
|
|
1850
1850
|
// Reward fund
|
|
1851
|
-
e.pure.vector("string",
|
|
1851
|
+
e.pure.vector("string", c),
|
|
1852
1852
|
// Asset IDs
|
|
1853
1853
|
e.pure.vector("address", s),
|
|
1854
1854
|
// Rule IDs
|
|
@@ -1857,17 +1857,17 @@ async function Ct(e, n, o) {
|
|
|
1857
1857
|
],
|
|
1858
1858
|
typeArguments: [h]
|
|
1859
1859
|
}) : y ? S = e.moveCall({
|
|
1860
|
-
target: `${
|
|
1860
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1861
1861
|
arguments: [
|
|
1862
1862
|
e.object("0x06"),
|
|
1863
1863
|
// Clock object
|
|
1864
|
-
e.object(
|
|
1864
|
+
e.object(u.incentiveV3),
|
|
1865
1865
|
// Incentive V3 contract
|
|
1866
|
-
e.object(
|
|
1866
|
+
e.object(u.storage),
|
|
1867
1867
|
// Protocol storage
|
|
1868
|
-
e.object(
|
|
1868
|
+
e.object(I),
|
|
1869
1869
|
// Reward fund
|
|
1870
|
-
e.pure.vector("string",
|
|
1870
|
+
e.pure.vector("string", c),
|
|
1871
1871
|
// Asset IDs
|
|
1872
1872
|
e.pure.vector("address", s),
|
|
1873
1873
|
// Rule IDs
|
|
@@ -1876,17 +1876,17 @@ async function Ct(e, n, o) {
|
|
|
1876
1876
|
],
|
|
1877
1877
|
typeArguments: [h]
|
|
1878
1878
|
}) : S = e.moveCall({
|
|
1879
|
-
target: `${
|
|
1879
|
+
target: `${u.package}::incentive_v3::claim_reward`,
|
|
1880
1880
|
arguments: [
|
|
1881
1881
|
e.object("0x06"),
|
|
1882
1882
|
// Clock object
|
|
1883
|
-
e.object(
|
|
1883
|
+
e.object(u.incentiveV3),
|
|
1884
1884
|
// Incentive V3 contract
|
|
1885
|
-
e.object(
|
|
1885
|
+
e.object(u.storage),
|
|
1886
1886
|
// Protocol storage
|
|
1887
|
-
e.object(
|
|
1887
|
+
e.object(I),
|
|
1888
1888
|
// Reward fund
|
|
1889
|
-
e.pure.vector("string",
|
|
1889
|
+
e.pure.vector("string", c),
|
|
1890
1890
|
// Asset IDs
|
|
1891
1891
|
e.pure.vector("address", s)
|
|
1892
1892
|
// Rule IDs
|
|
@@ -1908,7 +1908,7 @@ async function Ct(e, n, o) {
|
|
|
1908
1908
|
}
|
|
1909
1909
|
if (o?.customCoinReceive.type === "depositNAVI") {
|
|
1910
1910
|
const re = p(j.totalSupplyAmount).shiftedBy(-9), ae = p(j.supplyCapCeiling).shiftedBy(-27);
|
|
1911
|
-
re.plus(
|
|
1911
|
+
re.plus(l).isGreaterThan(ae) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
1912
1912
|
[D],
|
|
1913
1913
|
e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1914
1914
|
) : await Ce(e, j, D, o);
|
|
@@ -1921,17 +1921,17 @@ async function Ct(e, n, o) {
|
|
|
1921
1921
|
});
|
|
1922
1922
|
} else if (o?.accountCap || y) {
|
|
1923
1923
|
const S = e.moveCall({
|
|
1924
|
-
target: `${
|
|
1924
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1925
1925
|
arguments: [
|
|
1926
1926
|
e.object("0x06"),
|
|
1927
1927
|
// Clock object
|
|
1928
|
-
e.object(
|
|
1928
|
+
e.object(u.incentiveV3),
|
|
1929
1929
|
// Incentive V3 contract
|
|
1930
|
-
e.object(
|
|
1930
|
+
e.object(u.storage),
|
|
1931
1931
|
// Protocol storage
|
|
1932
|
-
e.object(
|
|
1932
|
+
e.object(I),
|
|
1933
1933
|
// Reward fund
|
|
1934
|
-
e.pure.vector("string",
|
|
1934
|
+
e.pure.vector("string", c),
|
|
1935
1935
|
// Asset IDs
|
|
1936
1936
|
e.pure.vector("address", s),
|
|
1937
1937
|
// Rule IDs
|
|
@@ -1950,17 +1950,17 @@ async function Ct(e, n, o) {
|
|
|
1950
1950
|
);
|
|
1951
1951
|
} else
|
|
1952
1952
|
e.moveCall({
|
|
1953
|
-
target: `${
|
|
1953
|
+
target: `${u.package}::incentive_v3::claim_reward_entry`,
|
|
1954
1954
|
arguments: [
|
|
1955
1955
|
e.object("0x06"),
|
|
1956
1956
|
// Clock object
|
|
1957
|
-
e.object(
|
|
1957
|
+
e.object(u.incentiveV3),
|
|
1958
1958
|
// Incentive V3 contract
|
|
1959
|
-
e.object(
|
|
1959
|
+
e.object(u.storage),
|
|
1960
1960
|
// Protocol storage
|
|
1961
|
-
e.object(
|
|
1961
|
+
e.object(I),
|
|
1962
1962
|
// Reward fund
|
|
1963
|
-
e.pure.vector("string",
|
|
1963
|
+
e.pure.vector("string", c),
|
|
1964
1964
|
// Asset IDs
|
|
1965
1965
|
e.pure.vector("address", s)
|
|
1966
1966
|
// Rule IDs
|
|
@@ -1972,7 +1972,7 @@ async function Ct(e, n, o) {
|
|
|
1972
1972
|
}
|
|
1973
1973
|
export {
|
|
1974
1974
|
z as Address,
|
|
1975
|
-
|
|
1975
|
+
w as DEFAULT_CACHE_TIME,
|
|
1976
1976
|
N as DEFAULT_MARKET_IDENTITY,
|
|
1977
1977
|
Ke as FlashLoanAssetConfig,
|
|
1978
1978
|
He as IncentiveAPYInfo,
|
|
@@ -1987,7 +1987,7 @@ export {
|
|
|
1987
1987
|
fe as UserStateInfo,
|
|
1988
1988
|
Xe as borrowCoinPTB,
|
|
1989
1989
|
Ct as claimLendingRewardsPTB,
|
|
1990
|
-
|
|
1990
|
+
Ie as createAccountCapPTB,
|
|
1991
1991
|
nt as createEModeCapPTB,
|
|
1992
1992
|
Ce as depositCoinPTB,
|
|
1993
1993
|
rt as emodeIdentityId,
|
|
@@ -1995,17 +1995,17 @@ export {
|
|
|
1995
1995
|
ot as exitEModePTB,
|
|
1996
1996
|
Me as filterPriceFeeds,
|
|
1997
1997
|
yt as flashloanPTB,
|
|
1998
|
-
|
|
1998
|
+
Te as getAccountCapOwnerPTB,
|
|
1999
1999
|
G as getAllFlashLoanAssets,
|
|
2000
2000
|
et as getBorrowFee,
|
|
2001
|
-
|
|
2001
|
+
ut as getCoins,
|
|
2002
2002
|
k as getConfig,
|
|
2003
2003
|
Ze as getFees,
|
|
2004
2004
|
ft as getFlashLoanAsset,
|
|
2005
|
-
|
|
2005
|
+
it as getHealthFactor,
|
|
2006
2006
|
Ae as getHealthFactorPTB,
|
|
2007
2007
|
$e as getLendingPositions,
|
|
2008
|
-
|
|
2008
|
+
ct as getLendingState,
|
|
2009
2009
|
tt as getMarket,
|
|
2010
2010
|
_ as getMarketConfig,
|
|
2011
2011
|
_e as getMarkets,
|
|
@@ -2017,14 +2017,14 @@ export {
|
|
|
2017
2017
|
st as getSimulatedHealthFactor,
|
|
2018
2018
|
ee as getSimulatedHealthFactorPTB,
|
|
2019
2019
|
Je as getStats,
|
|
2020
|
-
|
|
2020
|
+
lt as getTransactions,
|
|
2021
2021
|
vt as getUserAvailableLendingRewards,
|
|
2022
2022
|
kt as getUserClaimedRewardHistory,
|
|
2023
2023
|
x as getUserEModeCaps,
|
|
2024
2024
|
bt as getUserTotalClaimedReward,
|
|
2025
2025
|
ht as liquidatePTB,
|
|
2026
2026
|
at as mergeCoinsPTB,
|
|
2027
|
-
|
|
2027
|
+
b as normalizeCoinType,
|
|
2028
2028
|
ke as parsePoolUID,
|
|
2029
2029
|
g as parseTxValue,
|
|
2030
2030
|
xe as repayCoinPTB,
|