@naviprotocol/lending 1.3.7 → 1.3.9
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/LICENSE +21 -0
- package/dist/account.d.ts +7 -5
- 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 +209 -212
- package/dist/index.esm.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +14 -14
package/dist/index.esm.js
CHANGED
|
@@ -129,7 +129,7 @@ const R = i.bytes(32).transform({
|
|
|
129
129
|
borrow_balance: i.u256(),
|
|
130
130
|
/** User's current supply balance */
|
|
131
131
|
supply_balance: i.u256()
|
|
132
|
-
}), x = "1.3.
|
|
132
|
+
}), x = "1.3.9", C = {
|
|
133
133
|
version: x
|
|
134
134
|
}, ee = C.version, te = () => {
|
|
135
135
|
if (typeof process < "u" && process.versions && process.versions.node)
|
|
@@ -151,8 +151,8 @@ function U(e) {
|
|
|
151
151
|
return e.forEach((a, t) => {
|
|
152
152
|
const n = t === e.length - 1;
|
|
153
153
|
if (typeof a == "object" && a !== null && n) {
|
|
154
|
-
const { client: o, disableCache:
|
|
155
|
-
r.push(
|
|
154
|
+
const { client: o, disableCache: c, cacheTime: s, ...u } = a;
|
|
155
|
+
r.push(u);
|
|
156
156
|
} else
|
|
157
157
|
r.push(a);
|
|
158
158
|
}), JSON.stringify(r);
|
|
@@ -170,10 +170,10 @@ function I(e) {
|
|
|
170
170
|
let r = {};
|
|
171
171
|
return (...a) => {
|
|
172
172
|
const t = a[a.length - 1], n = U(a), o = r[n];
|
|
173
|
-
return !t?.disableCache && typeof o?.data < "u" && (typeof t?.cacheTime > "u" || t.cacheTime > Date.now() - o.cacheAt) ? o.data : e(...a).then((
|
|
174
|
-
data:
|
|
173
|
+
return !t?.disableCache && typeof o?.data < "u" && (typeof t?.cacheTime > "u" || t.cacheTime > Date.now() - o.cacheAt) ? o.data : e(...a).then((c) => (r[n] = {
|
|
174
|
+
data: c,
|
|
175
175
|
cacheAt: Date.now()
|
|
176
|
-
},
|
|
176
|
+
}, c));
|
|
177
177
|
};
|
|
178
178
|
}
|
|
179
179
|
function V(e) {
|
|
@@ -220,7 +220,7 @@ const oe = 27, D = (e, r) => {
|
|
|
220
220
|
const r = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${C.version}`;
|
|
221
221
|
return (await fetch(r, { headers: $ }).then((t) => t.json())).data;
|
|
222
222
|
})
|
|
223
|
-
),
|
|
223
|
+
), m = 1e3 * 60 * 5;
|
|
224
224
|
var k = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(k || {});
|
|
225
225
|
const S = I(
|
|
226
226
|
j(async (e) => {
|
|
@@ -231,7 +231,7 @@ const S = I(
|
|
|
231
231
|
async function w(e, r) {
|
|
232
232
|
const a = await S({
|
|
233
233
|
...r,
|
|
234
|
-
cacheTime:
|
|
234
|
+
cacheTime: m
|
|
235
235
|
});
|
|
236
236
|
if (typeof e == "object")
|
|
237
237
|
return e;
|
|
@@ -256,18 +256,18 @@ const _e = I(
|
|
|
256
256
|
async function ae(e, r, a, t) {
|
|
257
257
|
const n = await b({
|
|
258
258
|
...t,
|
|
259
|
-
cacheTime:
|
|
259
|
+
cacheTime: m
|
|
260
260
|
}), o = await w(r, t);
|
|
261
261
|
if (o?.deprecatedAt && Date.now() > o.deprecatedAt)
|
|
262
262
|
throw new Error(`The lending pool for coinType ${o.suiCoinType} has been deprecated.`);
|
|
263
|
-
const
|
|
264
|
-
if (f(o.suiCoinType) === f("0x2::sui::SUI") &&
|
|
263
|
+
const c = typeof a == "object" && a.$kind === "GasCoin";
|
|
264
|
+
if (f(o.suiCoinType) === f("0x2::sui::SUI") && c) {
|
|
265
265
|
if (!t?.amount)
|
|
266
266
|
throw new Error("Amount is required for sui coin");
|
|
267
267
|
a = e.splitCoins(a, [t.amount]);
|
|
268
268
|
}
|
|
269
|
-
let
|
|
270
|
-
return typeof t?.amount < "u" ?
|
|
269
|
+
let s;
|
|
270
|
+
return typeof t?.amount < "u" ? s = d(t.amount, e.pure.u64) : s = e.moveCall({
|
|
271
271
|
target: "0x2::coin::value",
|
|
272
272
|
arguments: [d(a, e.object)],
|
|
273
273
|
typeArguments: [o.suiCoinType]
|
|
@@ -292,7 +292,7 @@ async function ae(e, r, a, t) {
|
|
|
292
292
|
e.object(o.contract.pool),
|
|
293
293
|
e.pure.u8(o.id),
|
|
294
294
|
d(a, e.object),
|
|
295
|
-
|
|
295
|
+
s,
|
|
296
296
|
e.object(n.incentiveV2),
|
|
297
297
|
e.object(n.incentiveV3)
|
|
298
298
|
],
|
|
@@ -305,12 +305,12 @@ async function ae(e, r, a, t) {
|
|
|
305
305
|
async function Ae(e, r, a, t) {
|
|
306
306
|
const n = await b({
|
|
307
307
|
...t,
|
|
308
|
-
cacheTime:
|
|
309
|
-
}), o = await w(r, t),
|
|
310
|
-
let
|
|
308
|
+
cacheTime: m
|
|
309
|
+
}), o = await w(r, t), c = d(a, e.pure.u64);
|
|
310
|
+
let s;
|
|
311
311
|
if (n.version === 1)
|
|
312
312
|
if (t?.accountCap) {
|
|
313
|
-
const [
|
|
313
|
+
const [l] = e.moveCall({
|
|
314
314
|
target: `${n.package}::incentive_v3::withdraw_with_account_cap`,
|
|
315
315
|
arguments: [
|
|
316
316
|
e.object("0x06"),
|
|
@@ -318,16 +318,16 @@ async function Ae(e, r, a, t) {
|
|
|
318
318
|
e.object(n.storage),
|
|
319
319
|
e.object(o.contract.pool),
|
|
320
320
|
e.pure.u8(o.id),
|
|
321
|
-
|
|
321
|
+
c,
|
|
322
322
|
e.object(n.incentiveV2),
|
|
323
323
|
e.object(n.incentiveV3),
|
|
324
324
|
d(t.accountCap, e.object)
|
|
325
325
|
],
|
|
326
326
|
typeArguments: [o.suiCoinType]
|
|
327
327
|
});
|
|
328
|
-
|
|
328
|
+
s = l;
|
|
329
329
|
} else {
|
|
330
|
-
const [
|
|
330
|
+
const [l] = e.moveCall({
|
|
331
331
|
target: `${n.package}::incentive_v3::withdraw`,
|
|
332
332
|
arguments: [
|
|
333
333
|
e.object("0x06"),
|
|
@@ -335,16 +335,16 @@ async function Ae(e, r, a, t) {
|
|
|
335
335
|
e.object(n.storage),
|
|
336
336
|
e.object(o.contract.pool),
|
|
337
337
|
e.pure.u8(o.id),
|
|
338
|
-
|
|
338
|
+
c,
|
|
339
339
|
e.object(n.incentiveV2),
|
|
340
340
|
e.object(n.incentiveV3)
|
|
341
341
|
],
|
|
342
342
|
typeArguments: [o.suiCoinType]
|
|
343
343
|
});
|
|
344
|
-
|
|
344
|
+
s = l;
|
|
345
345
|
}
|
|
346
346
|
else if (t?.accountCap) {
|
|
347
|
-
const [
|
|
347
|
+
const [l] = e.moveCall({
|
|
348
348
|
target: `${n.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
349
349
|
arguments: [
|
|
350
350
|
e.object("0x06"),
|
|
@@ -352,7 +352,7 @@ async function Ae(e, r, a, t) {
|
|
|
352
352
|
e.object(n.storage),
|
|
353
353
|
e.object(o.contract.pool),
|
|
354
354
|
e.pure.u8(o.id),
|
|
355
|
-
|
|
355
|
+
c,
|
|
356
356
|
e.object(n.incentiveV2),
|
|
357
357
|
e.object(n.incentiveV3),
|
|
358
358
|
d(t.accountCap, e.object),
|
|
@@ -360,9 +360,9 @@ async function Ae(e, r, a, t) {
|
|
|
360
360
|
],
|
|
361
361
|
typeArguments: [o.suiCoinType]
|
|
362
362
|
});
|
|
363
|
-
|
|
363
|
+
s = l;
|
|
364
364
|
} else {
|
|
365
|
-
const [
|
|
365
|
+
const [l] = e.moveCall({
|
|
366
366
|
target: `${n.package}::incentive_v3::withdraw_v2`,
|
|
367
367
|
arguments: [
|
|
368
368
|
e.object("0x06"),
|
|
@@ -370,33 +370,33 @@ async function Ae(e, r, a, t) {
|
|
|
370
370
|
e.object(n.storage),
|
|
371
371
|
e.object(o.contract.pool),
|
|
372
372
|
e.pure.u8(o.id),
|
|
373
|
-
|
|
373
|
+
c,
|
|
374
374
|
e.object(n.incentiveV2),
|
|
375
375
|
e.object(n.incentiveV3),
|
|
376
376
|
e.object("0x05")
|
|
377
377
|
],
|
|
378
378
|
typeArguments: [o.suiCoinType]
|
|
379
379
|
});
|
|
380
|
-
|
|
380
|
+
s = l;
|
|
381
381
|
}
|
|
382
382
|
return e.moveCall({
|
|
383
383
|
target: "0x2::coin::from_balance",
|
|
384
|
-
arguments: [
|
|
384
|
+
arguments: [s],
|
|
385
385
|
typeArguments: [o.suiCoinType]
|
|
386
386
|
});
|
|
387
387
|
}
|
|
388
388
|
async function $e(e, r, a, t) {
|
|
389
389
|
const n = await b({
|
|
390
390
|
...t,
|
|
391
|
-
cacheTime:
|
|
391
|
+
cacheTime: m
|
|
392
392
|
}), o = await w(r, t);
|
|
393
393
|
if (o?.deprecatedAt && Date.now() > o.deprecatedAt)
|
|
394
394
|
throw new Error(`The lending pool for coinType ${o.suiCoinType} has been deprecated.`);
|
|
395
|
-
const
|
|
396
|
-
let
|
|
395
|
+
const c = d(a, e.pure.u64);
|
|
396
|
+
let s;
|
|
397
397
|
if (n.version === 1)
|
|
398
398
|
if (t?.accountCap) {
|
|
399
|
-
const [
|
|
399
|
+
const [l] = e.moveCall({
|
|
400
400
|
target: `${n.package}::incentive_v3::borrow_with_account_cap`,
|
|
401
401
|
arguments: [
|
|
402
402
|
e.object("0x06"),
|
|
@@ -404,16 +404,16 @@ async function $e(e, r, a, t) {
|
|
|
404
404
|
e.object(n.storage),
|
|
405
405
|
e.object(o.contract.pool),
|
|
406
406
|
e.pure.u8(o.id),
|
|
407
|
-
|
|
407
|
+
c,
|
|
408
408
|
e.object(n.incentiveV2),
|
|
409
409
|
e.object(n.incentiveV3),
|
|
410
410
|
d(t.accountCap, e.object)
|
|
411
411
|
],
|
|
412
412
|
typeArguments: [o.suiCoinType]
|
|
413
413
|
});
|
|
414
|
-
|
|
414
|
+
s = l;
|
|
415
415
|
} else {
|
|
416
|
-
const [
|
|
416
|
+
const [l] = e.moveCall({
|
|
417
417
|
target: `${n.package}::incentive_v3::borrow`,
|
|
418
418
|
arguments: [
|
|
419
419
|
e.object("0x06"),
|
|
@@ -421,16 +421,16 @@ async function $e(e, r, a, t) {
|
|
|
421
421
|
e.object(n.storage),
|
|
422
422
|
e.object(o.contract.pool),
|
|
423
423
|
e.pure.u8(o.id),
|
|
424
|
-
|
|
424
|
+
c,
|
|
425
425
|
e.object(n.incentiveV2),
|
|
426
426
|
e.object(n.incentiveV3)
|
|
427
427
|
],
|
|
428
428
|
typeArguments: [o.suiCoinType]
|
|
429
429
|
});
|
|
430
|
-
|
|
430
|
+
s = l;
|
|
431
431
|
}
|
|
432
432
|
else if (t?.accountCap) {
|
|
433
|
-
const [
|
|
433
|
+
const [l] = e.moveCall({
|
|
434
434
|
target: `${n.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
435
435
|
arguments: [
|
|
436
436
|
e.object("0x06"),
|
|
@@ -438,7 +438,7 @@ async function $e(e, r, a, t) {
|
|
|
438
438
|
e.object(n.storage),
|
|
439
439
|
e.object(o.contract.pool),
|
|
440
440
|
e.pure.u8(o.id),
|
|
441
|
-
|
|
441
|
+
c,
|
|
442
442
|
e.object(n.incentiveV2),
|
|
443
443
|
e.object(n.incentiveV3),
|
|
444
444
|
d(t.accountCap, e.object),
|
|
@@ -446,9 +446,9 @@ async function $e(e, r, a, t) {
|
|
|
446
446
|
],
|
|
447
447
|
typeArguments: [o.suiCoinType]
|
|
448
448
|
});
|
|
449
|
-
|
|
449
|
+
s = l;
|
|
450
450
|
} else {
|
|
451
|
-
const [
|
|
451
|
+
const [l] = e.moveCall({
|
|
452
452
|
target: `${n.package}::incentive_v3::borrow_v2`,
|
|
453
453
|
arguments: [
|
|
454
454
|
e.object("0x06"),
|
|
@@ -456,38 +456,38 @@ async function $e(e, r, a, t) {
|
|
|
456
456
|
e.object(n.storage),
|
|
457
457
|
e.object(o.contract.pool),
|
|
458
458
|
e.pure.u8(o.id),
|
|
459
|
-
|
|
459
|
+
c,
|
|
460
460
|
e.object(n.incentiveV2),
|
|
461
461
|
e.object(n.incentiveV3),
|
|
462
462
|
e.object("0x05")
|
|
463
463
|
],
|
|
464
464
|
typeArguments: [o.suiCoinType]
|
|
465
465
|
});
|
|
466
|
-
|
|
466
|
+
s = l;
|
|
467
467
|
}
|
|
468
468
|
return e.moveCall({
|
|
469
469
|
target: "0x2::coin::from_balance",
|
|
470
|
-
arguments: [e.object(
|
|
470
|
+
arguments: [e.object(s)],
|
|
471
471
|
typeArguments: [o.suiCoinType]
|
|
472
472
|
});
|
|
473
473
|
}
|
|
474
474
|
async function Ie(e, r, a, t) {
|
|
475
475
|
const n = await b({
|
|
476
476
|
...t,
|
|
477
|
-
cacheTime:
|
|
478
|
-
}), o = await w(r, t),
|
|
479
|
-
if (f(o.suiCoinType) === f("0x2::sui::SUI") &&
|
|
477
|
+
cacheTime: m
|
|
478
|
+
}), o = await w(r, t), c = typeof a == "object" && a.$kind === "GasCoin";
|
|
479
|
+
if (f(o.suiCoinType) === f("0x2::sui::SUI") && c) {
|
|
480
480
|
if (!t?.amount)
|
|
481
481
|
throw new Error("Amount is required for sui coin");
|
|
482
482
|
a = e.splitCoins(a, [t.amount]);
|
|
483
483
|
}
|
|
484
|
-
let
|
|
485
|
-
if (typeof t?.amount < "u" ?
|
|
484
|
+
let s;
|
|
485
|
+
if (typeof t?.amount < "u" ? s = d(t.amount, e.pure.u64) : s = e.moveCall({
|
|
486
486
|
target: "0x2::coin::value",
|
|
487
487
|
arguments: [d(a, e.object)],
|
|
488
488
|
typeArguments: [o.suiCoinType]
|
|
489
489
|
}), t?.accountCap) {
|
|
490
|
-
const [
|
|
490
|
+
const [u] = e.moveCall({
|
|
491
491
|
target: `${n.package}::incentive_v3::repay_with_account_cap`,
|
|
492
492
|
arguments: [
|
|
493
493
|
e.object("0x06"),
|
|
@@ -504,7 +504,7 @@ async function Ie(e, r, a, t) {
|
|
|
504
504
|
});
|
|
505
505
|
return e.moveCall({
|
|
506
506
|
target: "0x2::coin::from_balance",
|
|
507
|
-
arguments: [
|
|
507
|
+
arguments: [u],
|
|
508
508
|
typeArguments: [o.suiCoinType]
|
|
509
509
|
});
|
|
510
510
|
} else
|
|
@@ -517,7 +517,7 @@ async function Ie(e, r, a, t) {
|
|
|
517
517
|
e.object(o.contract.pool),
|
|
518
518
|
e.pure.u8(o.id),
|
|
519
519
|
d(a, e.object),
|
|
520
|
-
|
|
520
|
+
s,
|
|
521
521
|
e.object(n.incentiveV2),
|
|
522
522
|
e.object(n.incentiveV3)
|
|
523
523
|
],
|
|
@@ -532,22 +532,22 @@ const ke = I(
|
|
|
532
532
|
});
|
|
533
533
|
if (e?.address && typeof e?.asset < "u")
|
|
534
534
|
try {
|
|
535
|
-
const n = await w(e.asset, e), o = e?.client ?? A,
|
|
536
|
-
|
|
535
|
+
const n = await w(e.asset, e), o = e?.client ?? A, c = new B();
|
|
536
|
+
c.moveCall({
|
|
537
537
|
target: `${r.package}::incentive_v3::get_borrow_fee_v2`,
|
|
538
538
|
arguments: [
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
539
|
+
c.object(r.incentiveV3),
|
|
540
|
+
c.pure.address(e.address),
|
|
541
|
+
c.pure.u8(n.id),
|
|
542
|
+
c.pure.u64(1e4)
|
|
543
543
|
],
|
|
544
544
|
typeArguments: []
|
|
545
545
|
});
|
|
546
|
-
const
|
|
547
|
-
transactionBlock:
|
|
546
|
+
const s = await o.devInspectTransactionBlock({
|
|
547
|
+
transactionBlock: c,
|
|
548
548
|
sender: e.address
|
|
549
|
-
}),
|
|
550
|
-
return (Number(
|
|
549
|
+
}), u = P(s, [h.u64()]);
|
|
550
|
+
return (Number(u[0]) || 0) / 100;
|
|
551
551
|
} catch (n) {
|
|
552
552
|
console.error(n);
|
|
553
553
|
}
|
|
@@ -562,44 +562,41 @@ const ke = I(
|
|
|
562
562
|
function Be(e, r, a) {
|
|
563
563
|
const t = typeof a?.balance == "number", n = t ? a.balance : 0;
|
|
564
564
|
let o = 0;
|
|
565
|
-
const
|
|
566
|
-
let
|
|
567
|
-
if (r.sort((u,
|
|
565
|
+
const c = [];
|
|
566
|
+
let s = "";
|
|
567
|
+
if (r.sort((u, l) => Number(l.balance) - Number(u.balance)).forEach((u) => {
|
|
568
568
|
if (!(t && o >= n) && Number(u.balance) !== 0) {
|
|
569
|
-
if (
|
|
569
|
+
if (s || (s = u.coinType), s !== u.coinType)
|
|
570
570
|
throw new Error("All coins must be of the same type");
|
|
571
|
-
o += Number(u.balance),
|
|
571
|
+
o += Number(u.balance), c.push(u.coinObjectId);
|
|
572
572
|
}
|
|
573
|
-
}),
|
|
573
|
+
}), c.length === 0)
|
|
574
574
|
throw new Error("No coins to merge");
|
|
575
575
|
if (t && o < n)
|
|
576
576
|
throw new Error(
|
|
577
577
|
`Balance is less than the specified balance: ${o} < ${n}`
|
|
578
578
|
);
|
|
579
|
-
|
|
580
|
-
return t ? e.splitCoins(e.gas, [e.pure.u64(n)]) : e.gas;
|
|
581
|
-
const l = s.length === 1 ? e.object(s[0]) : e.mergeCoins(s[0], s.slice(1));
|
|
582
|
-
return t ? e.splitCoins(l, [e.pure.u64(n)]) : l;
|
|
579
|
+
return f(s) === f("0x2::sui::SUI") && a?.useGasCoin ? t ? e.splitCoins(e.gas, [e.pure.u64(n)]) : e.gas : (c.length === 1 ? e.object(c[0]) : e.mergeCoins(c[0], c.slice(1)), t ? e.splitCoins(c[0], [e.pure.u64(n)]) : c[0]);
|
|
583
580
|
}
|
|
584
|
-
async function M(e, r, a, t, n, o,
|
|
585
|
-
const
|
|
586
|
-
...
|
|
587
|
-
cacheTime:
|
|
588
|
-
}),
|
|
581
|
+
async function M(e, r, a, t, n, o, c) {
|
|
582
|
+
const s = await b({
|
|
583
|
+
...c,
|
|
584
|
+
cacheTime: m
|
|
585
|
+
}), u = await w(a, c);
|
|
589
586
|
return e.moveCall({
|
|
590
|
-
target: `${
|
|
587
|
+
target: `${s.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
591
588
|
arguments: [
|
|
592
589
|
e.object("0x06"),
|
|
593
|
-
e.object(
|
|
594
|
-
e.object(
|
|
595
|
-
re(e,
|
|
590
|
+
e.object(s.storage),
|
|
591
|
+
e.object(s.oracle.priceOracle),
|
|
592
|
+
re(e, u),
|
|
596
593
|
d(r, e.pure.address),
|
|
597
|
-
d(
|
|
594
|
+
d(u.id, e.pure.u8),
|
|
598
595
|
d(t, e.pure.u64),
|
|
599
596
|
d(n, e.pure.u64),
|
|
600
597
|
d(o, e.pure.bool)
|
|
601
598
|
],
|
|
602
|
-
typeArguments: [
|
|
599
|
+
typeArguments: [u.suiCoinType]
|
|
603
600
|
});
|
|
604
601
|
}
|
|
605
602
|
async function ce(e, r, a) {
|
|
@@ -609,33 +606,33 @@ const Pe = I(
|
|
|
609
606
|
async (e, r) => {
|
|
610
607
|
const a = await b({
|
|
611
608
|
...r,
|
|
612
|
-
cacheTime:
|
|
609
|
+
cacheTime: m
|
|
613
610
|
}), t = new B(), n = r?.client ?? A, o = await S(r);
|
|
614
611
|
t.moveCall({
|
|
615
612
|
target: `${a.uiGetter}::getter_unchecked::get_user_state`,
|
|
616
613
|
arguments: [t.object(a.storage), t.pure.address(e)]
|
|
617
614
|
});
|
|
618
|
-
const
|
|
615
|
+
const c = await n.devInspectTransactionBlock({
|
|
619
616
|
transactionBlock: t,
|
|
620
617
|
sender: e
|
|
621
|
-
}),
|
|
618
|
+
}), s = P(c, [h.vector(Z)]);
|
|
622
619
|
return V(
|
|
623
|
-
|
|
624
|
-
).map((
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
|
|
620
|
+
s[0].filter((l) => l.supply_balance !== "0" || l.borrow_balance !== "0")
|
|
621
|
+
).map((l) => {
|
|
622
|
+
const g = o.find((v) => v.id === l.assetId), p = D(
|
|
623
|
+
l.supplyBalance,
|
|
624
|
+
g.currentSupplyIndex
|
|
628
625
|
).toString(), y = D(
|
|
629
|
-
|
|
630
|
-
|
|
626
|
+
l.borrowBalance,
|
|
627
|
+
g.currentBorrowIndex
|
|
631
628
|
).toString();
|
|
632
629
|
return {
|
|
633
|
-
...
|
|
630
|
+
...l,
|
|
634
631
|
supplyBalance: p,
|
|
635
632
|
borrowBalance: y,
|
|
636
|
-
pool:
|
|
633
|
+
pool: g
|
|
637
634
|
};
|
|
638
|
-
}).filter((
|
|
635
|
+
}).filter((l) => !!l.pool);
|
|
639
636
|
}
|
|
640
637
|
);
|
|
641
638
|
async function Ve(e, r) {
|
|
@@ -649,26 +646,26 @@ async function Ve(e, r) {
|
|
|
649
646
|
}
|
|
650
647
|
async function Se(e, r, a, t) {
|
|
651
648
|
const n = t?.client ?? A, o = new B();
|
|
652
|
-
let
|
|
653
|
-
const
|
|
649
|
+
let c = 0, s = 0;
|
|
650
|
+
const u = await w(r, t);
|
|
654
651
|
if (a.forEach((y) => {
|
|
655
|
-
y.type === k.Supply ?
|
|
656
|
-
}),
|
|
652
|
+
y.type === k.Supply ? c += y.amount : y.type === k.Withdraw ? c -= y.amount : y.type === k.Borrow ? s += y.amount : y.type === k.Repay && (s -= y.amount);
|
|
653
|
+
}), c * s < 0)
|
|
657
654
|
throw new Error("Invalid operations");
|
|
658
|
-
const
|
|
655
|
+
const l = c > 0 || s > 0;
|
|
659
656
|
await M(
|
|
660
657
|
o,
|
|
661
658
|
e,
|
|
662
|
-
l,
|
|
663
|
-
Math.abs(s),
|
|
664
|
-
Math.abs(c),
|
|
665
659
|
u,
|
|
660
|
+
Math.abs(c),
|
|
661
|
+
Math.abs(s),
|
|
662
|
+
l,
|
|
666
663
|
t
|
|
667
664
|
);
|
|
668
|
-
const
|
|
665
|
+
const g = await n.devInspectTransactionBlock({
|
|
669
666
|
transactionBlock: o,
|
|
670
667
|
sender: e
|
|
671
|
-
}), p = P(
|
|
668
|
+
}), p = P(g, [h.u256()]);
|
|
672
669
|
return L(Number(p[0]) || 0);
|
|
673
670
|
}
|
|
674
671
|
const Fe = j(
|
|
@@ -727,7 +724,7 @@ async function se(e) {
|
|
|
727
724
|
async function ie(e, r, a) {
|
|
728
725
|
const t = a?.client ?? A, n = await b({
|
|
729
726
|
...a,
|
|
730
|
-
cacheTime:
|
|
727
|
+
cacheTime: m
|
|
731
728
|
});
|
|
732
729
|
try {
|
|
733
730
|
const o = await O.getPriceFeedsUpdateData(r);
|
|
@@ -743,7 +740,7 @@ async function ie(e, r, a) {
|
|
|
743
740
|
async function Ne(e, r, a) {
|
|
744
741
|
const t = await b({
|
|
745
742
|
...a,
|
|
746
|
-
cacheTime:
|
|
743
|
+
cacheTime: m
|
|
747
744
|
});
|
|
748
745
|
if (a?.updatePythPriceFeeds) {
|
|
749
746
|
const n = r.filter((o) => !!o.pythPriceFeedId).map((o) => o.pythPriceFeedId);
|
|
@@ -776,7 +773,7 @@ async function Ne(e, r, a) {
|
|
|
776
773
|
async function ue(e) {
|
|
777
774
|
return (await b({
|
|
778
775
|
...e,
|
|
779
|
-
cacheTime:
|
|
776
|
+
cacheTime: m
|
|
780
777
|
})).oracle.feeds;
|
|
781
778
|
}
|
|
782
779
|
function De(e, r) {
|
|
@@ -797,17 +794,17 @@ async function Ee(e, r) {
|
|
|
797
794
|
async function Ue(e, r, a, t) {
|
|
798
795
|
const n = await b({
|
|
799
796
|
...t,
|
|
800
|
-
cacheTime:
|
|
797
|
+
cacheTime: m
|
|
801
798
|
}), o = await w(r, t);
|
|
802
799
|
if (!(await F({
|
|
803
800
|
...t,
|
|
804
|
-
cacheTime:
|
|
801
|
+
cacheTime: m
|
|
805
802
|
})).some(
|
|
806
|
-
(
|
|
803
|
+
(u) => f(u.coinType) === f(o.suiCoinType)
|
|
807
804
|
))
|
|
808
805
|
throw new Error("Pool does not support flashloan");
|
|
809
806
|
if (n.version === 1) {
|
|
810
|
-
const [
|
|
807
|
+
const [u, l] = e.moveCall({
|
|
811
808
|
target: `${n.package}::lending::flash_loan_with_ctx`,
|
|
812
809
|
arguments: [
|
|
813
810
|
e.object(n.flashloanConfig),
|
|
@@ -816,9 +813,9 @@ async function Ue(e, r, a, t) {
|
|
|
816
813
|
],
|
|
817
814
|
typeArguments: [o.suiCoinType]
|
|
818
815
|
});
|
|
819
|
-
return [
|
|
816
|
+
return [u, l];
|
|
820
817
|
} else {
|
|
821
|
-
const [
|
|
818
|
+
const [u, l] = e.moveCall({
|
|
822
819
|
target: `${n.package}::lending::flash_loan_with_ctx_v2`,
|
|
823
820
|
arguments: [
|
|
824
821
|
e.object(n.flashloanConfig),
|
|
@@ -828,129 +825,129 @@ async function Ue(e, r, a, t) {
|
|
|
828
825
|
],
|
|
829
826
|
typeArguments: [o.suiCoinType]
|
|
830
827
|
});
|
|
831
|
-
return [
|
|
828
|
+
return [u, l];
|
|
832
829
|
}
|
|
833
830
|
}
|
|
834
831
|
async function Le(e, r, a, t, n) {
|
|
835
832
|
const o = await b({
|
|
836
833
|
...n,
|
|
837
|
-
cacheTime:
|
|
838
|
-
}),
|
|
834
|
+
cacheTime: m
|
|
835
|
+
}), c = await w(r, n);
|
|
839
836
|
if (!(await F({
|
|
840
837
|
...n,
|
|
841
|
-
cacheTime:
|
|
838
|
+
cacheTime: m
|
|
842
839
|
})).some(
|
|
843
|
-
(
|
|
840
|
+
(g) => f(g.coinType) === f(c.suiCoinType)
|
|
844
841
|
))
|
|
845
842
|
throw new Error("Pool does not support flashloan");
|
|
846
|
-
const [
|
|
843
|
+
const [l] = e.moveCall({
|
|
847
844
|
target: `${o.package}::lending::flash_repay_with_ctx`,
|
|
848
845
|
arguments: [
|
|
849
846
|
e.object("0x06"),
|
|
850
847
|
e.object(o.storage),
|
|
851
|
-
e.object(
|
|
848
|
+
e.object(c.contract.pool),
|
|
852
849
|
d(a, e.object),
|
|
853
850
|
d(t, e.object)
|
|
854
851
|
],
|
|
855
|
-
typeArguments: [
|
|
852
|
+
typeArguments: [c.suiCoinType]
|
|
856
853
|
});
|
|
857
|
-
return [
|
|
854
|
+
return [l];
|
|
858
855
|
}
|
|
859
856
|
async function Me(e, r, a, t, n, o) {
|
|
860
|
-
const
|
|
857
|
+
const c = {
|
|
861
858
|
...o,
|
|
862
|
-
cacheTime:
|
|
863
|
-
},
|
|
864
|
-
if (
|
|
865
|
-
const [
|
|
866
|
-
target: `${
|
|
859
|
+
cacheTime: m
|
|
860
|
+
}, s = await b(c), u = await w(r, c), l = await w(t, c);
|
|
861
|
+
if (s.version === 1) {
|
|
862
|
+
const [g, p] = e.moveCall({
|
|
863
|
+
target: `${s.package}::incentive_v3::liquidation`,
|
|
867
864
|
arguments: [
|
|
868
865
|
e.object("0x06"),
|
|
869
866
|
// Clock object
|
|
870
|
-
e.object(
|
|
867
|
+
e.object(s.priceOracle),
|
|
871
868
|
// Price oracle for asset pricing
|
|
872
|
-
e.object(
|
|
869
|
+
e.object(s.storage),
|
|
873
870
|
// Protocol storage
|
|
874
|
-
e.pure.u8(
|
|
871
|
+
e.pure.u8(u.id),
|
|
875
872
|
// Pay asset ID
|
|
876
|
-
e.object(
|
|
873
|
+
e.object(u.contract.pool),
|
|
877
874
|
// Pay asset pool contract
|
|
878
875
|
d(a, e.object),
|
|
879
876
|
// Debt repayment amount
|
|
880
|
-
e.pure.u8(
|
|
877
|
+
e.pure.u8(l.id),
|
|
881
878
|
// Collateral asset ID
|
|
882
|
-
e.object(
|
|
879
|
+
e.object(l.contract.pool),
|
|
883
880
|
// Collateral asset pool contract
|
|
884
881
|
d(n, e.pure.address),
|
|
885
882
|
// Borrower address
|
|
886
|
-
e.object(
|
|
883
|
+
e.object(s.incentiveV2),
|
|
887
884
|
// Incentive V2 contract
|
|
888
|
-
e.object(
|
|
885
|
+
e.object(s.incentiveV3)
|
|
889
886
|
// Incentive V3 contract
|
|
890
887
|
],
|
|
891
|
-
typeArguments: [
|
|
888
|
+
typeArguments: [u.suiCoinType, l.suiCoinType]
|
|
892
889
|
});
|
|
893
|
-
return [
|
|
890
|
+
return [g, p];
|
|
894
891
|
} else {
|
|
895
|
-
const [
|
|
896
|
-
target: `${
|
|
892
|
+
const [g, p] = e.moveCall({
|
|
893
|
+
target: `${s.package}::incentive_v3::liquidation_v2`,
|
|
897
894
|
arguments: [
|
|
898
895
|
e.object("0x06"),
|
|
899
896
|
// Clock object
|
|
900
|
-
e.object(
|
|
897
|
+
e.object(s.priceOracle),
|
|
901
898
|
// Price oracle for asset pricing
|
|
902
|
-
e.object(
|
|
899
|
+
e.object(s.storage),
|
|
903
900
|
// Protocol storage
|
|
904
|
-
e.pure.u8(
|
|
901
|
+
e.pure.u8(u.id),
|
|
905
902
|
// Pay asset ID
|
|
906
|
-
e.object(
|
|
903
|
+
e.object(u.contract.pool),
|
|
907
904
|
// Pay asset pool contract
|
|
908
905
|
d(a, e.object),
|
|
909
906
|
// Debt repayment amount
|
|
910
|
-
e.pure.u8(
|
|
907
|
+
e.pure.u8(l.id),
|
|
911
908
|
// Collateral asset ID
|
|
912
|
-
e.object(
|
|
909
|
+
e.object(l.contract.pool),
|
|
913
910
|
// Collateral asset pool contract
|
|
914
911
|
d(n, e.pure.address),
|
|
915
912
|
// Borrower address
|
|
916
|
-
e.object(
|
|
913
|
+
e.object(s.incentiveV2),
|
|
917
914
|
// Incentive V2 contract
|
|
918
|
-
e.object(
|
|
915
|
+
e.object(s.incentiveV3),
|
|
919
916
|
// Incentive V3 contract
|
|
920
917
|
e.object("0x05")
|
|
921
918
|
// SuiSystemState object
|
|
922
919
|
],
|
|
923
|
-
typeArguments: [
|
|
920
|
+
typeArguments: [u.suiCoinType, l.suiCoinType]
|
|
924
921
|
});
|
|
925
|
-
return [
|
|
922
|
+
return [g, p];
|
|
926
923
|
}
|
|
927
924
|
}
|
|
928
925
|
async function Oe(e, r) {
|
|
929
926
|
const a = await ue(r), t = await S({
|
|
930
927
|
...r,
|
|
931
|
-
cacheTime:
|
|
928
|
+
cacheTime: m
|
|
932
929
|
}), n = r?.client ?? A, o = await b({
|
|
933
930
|
...r,
|
|
934
|
-
cacheTime:
|
|
935
|
-
}),
|
|
936
|
-
|
|
931
|
+
cacheTime: m
|
|
932
|
+
}), c = new B();
|
|
933
|
+
c.moveCall({
|
|
937
934
|
target: `${o.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
938
935
|
arguments: [
|
|
939
|
-
|
|
936
|
+
c.object("0x06"),
|
|
940
937
|
// Clock object
|
|
941
|
-
|
|
938
|
+
c.object(o.storage),
|
|
942
939
|
// Protocol storage
|
|
943
|
-
|
|
940
|
+
c.object(o.incentiveV3),
|
|
944
941
|
// Incentive V3 contract
|
|
945
|
-
|
|
942
|
+
c.pure.address(e)
|
|
946
943
|
// User address
|
|
947
944
|
]
|
|
948
945
|
});
|
|
949
|
-
const
|
|
950
|
-
transactionBlock:
|
|
946
|
+
const s = await n.devInspectTransactionBlock({
|
|
947
|
+
transactionBlock: c,
|
|
951
948
|
sender: e
|
|
952
|
-
}),
|
|
953
|
-
|
|
949
|
+
}), u = P(
|
|
950
|
+
s,
|
|
954
951
|
[
|
|
955
952
|
h.vector(h.string()),
|
|
956
953
|
// Asset coin types
|
|
@@ -963,32 +960,32 @@ async function Oe(e, r) {
|
|
|
963
960
|
h.vector(h.u256())
|
|
964
961
|
// Claimable amounts
|
|
965
962
|
]
|
|
966
|
-
),
|
|
967
|
-
if (
|
|
968
|
-
const
|
|
969
|
-
for (let p = 0; p <
|
|
963
|
+
), l = [];
|
|
964
|
+
if (u.length === 5 && Array.isArray(u[0])) {
|
|
965
|
+
const g = u[0].length;
|
|
966
|
+
for (let p = 0; p < g; p++) {
|
|
970
967
|
const y = a.find(
|
|
971
|
-
(_) => f(_.coinType) === f(
|
|
968
|
+
(_) => f(_.coinType) === f(u[1][p])
|
|
972
969
|
), v = t.find(
|
|
973
|
-
(_) => f(_.coinType) === f(
|
|
970
|
+
(_) => f(_.coinType) === f(u[0][p])
|
|
974
971
|
);
|
|
975
|
-
!y || !v ||
|
|
972
|
+
!y || !v || l.push({
|
|
976
973
|
assetId: v.id,
|
|
977
|
-
assetCoinType: f(
|
|
978
|
-
rewardCoinType: f(
|
|
979
|
-
option: Number(
|
|
980
|
-
userClaimableReward: Number(
|
|
981
|
-
ruleIds: Array.isArray(
|
|
974
|
+
assetCoinType: f(u[0][p]),
|
|
975
|
+
rewardCoinType: f(u[1][p]),
|
|
976
|
+
option: Number(u[2][p]),
|
|
977
|
+
userClaimableReward: Number(u[4][p]) / Math.pow(10, y.priceDecimal),
|
|
978
|
+
ruleIds: Array.isArray(u[3][p]) ? u[3][p] : [u[3][p]]
|
|
982
979
|
});
|
|
983
980
|
}
|
|
984
981
|
}
|
|
985
|
-
return
|
|
982
|
+
return l;
|
|
986
983
|
}
|
|
987
984
|
function qe(e) {
|
|
988
985
|
const r = /* @__PURE__ */ new Map();
|
|
989
986
|
e.forEach((t) => {
|
|
990
|
-
const n = t.assetId, o = t.option,
|
|
991
|
-
r.has(
|
|
987
|
+
const n = t.assetId, o = t.option, c = `${n}-${o}-${t.rewardCoinType}`;
|
|
988
|
+
r.has(c) ? r.get(c).total += t.userClaimableReward : r.set(c, {
|
|
992
989
|
assetId: n,
|
|
993
990
|
rewardType: o,
|
|
994
991
|
coinType: t.rewardCoinType,
|
|
@@ -996,11 +993,11 @@ function qe(e) {
|
|
|
996
993
|
});
|
|
997
994
|
});
|
|
998
995
|
const a = /* @__PURE__ */ new Map();
|
|
999
|
-
for (const { assetId: t, rewardType: n, coinType: o, total:
|
|
1000
|
-
const
|
|
1001
|
-
a.has(
|
|
1002
|
-
const
|
|
1003
|
-
|
|
996
|
+
for (const { assetId: t, rewardType: n, coinType: o, total: c } of r.values()) {
|
|
997
|
+
const s = `${t}-${n}`;
|
|
998
|
+
a.has(s) || a.set(s, { assetId: t, rewardType: n, rewards: /* @__PURE__ */ new Map() });
|
|
999
|
+
const u = a.get(s);
|
|
1000
|
+
u.rewards.set(o, (u.rewards.get(o) || 0) + c);
|
|
1004
1001
|
}
|
|
1005
1002
|
return Array.from(a.values()).map((t) => ({
|
|
1006
1003
|
assetId: t.assetId,
|
|
@@ -1027,26 +1024,26 @@ const He = j(
|
|
|
1027
1024
|
async function ze(e, r, a) {
|
|
1028
1025
|
const t = await b({
|
|
1029
1026
|
...a,
|
|
1030
|
-
cacheTime:
|
|
1027
|
+
cacheTime: m
|
|
1031
1028
|
}), n = await S({
|
|
1032
1029
|
...a,
|
|
1033
|
-
cacheTime:
|
|
1030
|
+
cacheTime: m
|
|
1034
1031
|
}), o = /* @__PURE__ */ new Map();
|
|
1035
|
-
for (const
|
|
1036
|
-
const { rewardCoinType:
|
|
1037
|
-
for (const
|
|
1038
|
-
o.has(
|
|
1039
|
-
const p = o.get(
|
|
1040
|
-
p.assetIds.push(
|
|
1032
|
+
for (const s of r) {
|
|
1033
|
+
const { rewardCoinType: u, ruleIds: l } = s;
|
|
1034
|
+
for (const g of l) {
|
|
1035
|
+
o.has(u) || o.set(u, { assetIds: [], ruleIds: [], amount: 0 });
|
|
1036
|
+
const p = o.get(u);
|
|
1037
|
+
p.assetIds.push(s.assetCoinType.replace("0x", "")), p.ruleIds.push(g), p.amount += s.userClaimableReward;
|
|
1041
1038
|
}
|
|
1042
1039
|
}
|
|
1043
|
-
const
|
|
1044
|
-
for (const [
|
|
1040
|
+
const c = [];
|
|
1041
|
+
for (const [s, { assetIds: u, ruleIds: l, amount: g }] of o) {
|
|
1045
1042
|
const p = n.find(
|
|
1046
|
-
(v) => f(v.suiCoinType) === f(
|
|
1043
|
+
(v) => f(v.suiCoinType) === f(s)
|
|
1047
1044
|
);
|
|
1048
1045
|
if (!p || !p.contract.rewardFundId)
|
|
1049
|
-
throw new Error(`No matching rewardFund found for reward coin: ${
|
|
1046
|
+
throw new Error(`No matching rewardFund found for reward coin: ${s}`);
|
|
1050
1047
|
const y = p.contract.rewardFundId;
|
|
1051
1048
|
if (a?.accountCap && !a.customCoinReceive)
|
|
1052
1049
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
@@ -1063,14 +1060,14 @@ async function ze(e, r, a) {
|
|
|
1063
1060
|
// Protocol storage
|
|
1064
1061
|
e.object(y),
|
|
1065
1062
|
// Reward fund
|
|
1066
|
-
e.pure.vector("string",
|
|
1063
|
+
e.pure.vector("string", u),
|
|
1067
1064
|
// Asset IDs
|
|
1068
|
-
e.pure.vector("address",
|
|
1065
|
+
e.pure.vector("address", l),
|
|
1069
1066
|
// Rule IDs
|
|
1070
1067
|
d(a.accountCap, e.object)
|
|
1071
1068
|
// Account capability
|
|
1072
1069
|
],
|
|
1073
|
-
typeArguments: [
|
|
1070
|
+
typeArguments: [s]
|
|
1074
1071
|
}) : v = e.moveCall({
|
|
1075
1072
|
target: `${t.package}::incentive_v3::claim_reward`,
|
|
1076
1073
|
arguments: [
|
|
@@ -1082,17 +1079,17 @@ async function ze(e, r, a) {
|
|
|
1082
1079
|
// Protocol storage
|
|
1083
1080
|
e.object(y),
|
|
1084
1081
|
// Reward fund
|
|
1085
|
-
e.pure.vector("string",
|
|
1082
|
+
e.pure.vector("string", u),
|
|
1086
1083
|
// Asset IDs
|
|
1087
|
-
e.pure.vector("address",
|
|
1084
|
+
e.pure.vector("address", l)
|
|
1088
1085
|
// Rule IDs
|
|
1089
1086
|
],
|
|
1090
|
-
typeArguments: [
|
|
1087
|
+
typeArguments: [s]
|
|
1091
1088
|
});
|
|
1092
1089
|
const [_] = e.moveCall({
|
|
1093
1090
|
target: "0x2::coin::from_balance",
|
|
1094
1091
|
arguments: [v],
|
|
1095
|
-
typeArguments: [
|
|
1092
|
+
typeArguments: [s]
|
|
1096
1093
|
});
|
|
1097
1094
|
if (a?.customCoinReceive.type === "transfer") {
|
|
1098
1095
|
if (!a.customCoinReceive.transfer)
|
|
@@ -1104,12 +1101,12 @@ async function ze(e, r, a) {
|
|
|
1104
1101
|
}
|
|
1105
1102
|
if (a?.customCoinReceive.type === "depositNAVI") {
|
|
1106
1103
|
const q = T(p.totalSupplyAmount).shiftedBy(-9), H = T(p.supplyCapCeiling).shiftedBy(-27);
|
|
1107
|
-
q.plus(
|
|
1104
|
+
q.plus(g).isGreaterThan(H) && a?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
1108
1105
|
[_],
|
|
1109
1106
|
e.pure.address(a.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1110
1107
|
) : await ae(e, p, _, a);
|
|
1111
1108
|
} else
|
|
1112
|
-
|
|
1109
|
+
c.push({
|
|
1113
1110
|
coin: _,
|
|
1114
1111
|
identifier: p
|
|
1115
1112
|
});
|
|
@@ -1125,15 +1122,15 @@ async function ze(e, r, a) {
|
|
|
1125
1122
|
// Protocol storage
|
|
1126
1123
|
e.object(y),
|
|
1127
1124
|
// Reward fund
|
|
1128
|
-
e.pure.vector("string",
|
|
1125
|
+
e.pure.vector("string", u),
|
|
1129
1126
|
// Asset IDs
|
|
1130
|
-
e.pure.vector("address",
|
|
1127
|
+
e.pure.vector("address", l)
|
|
1131
1128
|
// Rule IDs
|
|
1132
1129
|
],
|
|
1133
|
-
typeArguments: [
|
|
1130
|
+
typeArguments: [s]
|
|
1134
1131
|
});
|
|
1135
1132
|
}
|
|
1136
|
-
return
|
|
1133
|
+
return c;
|
|
1137
1134
|
}
|
|
1138
1135
|
async function We(e, r) {
|
|
1139
1136
|
const a = await b({
|
|
@@ -1146,7 +1143,7 @@ async function We(e, r) {
|
|
|
1146
1143
|
}
|
|
1147
1144
|
export {
|
|
1148
1145
|
R as Address,
|
|
1149
|
-
|
|
1146
|
+
m as DEFAULT_CACHE_TIME,
|
|
1150
1147
|
Ce as FlashLoanAssetConfig,
|
|
1151
1148
|
he as IncentiveAPYInfo,
|
|
1152
1149
|
X as IncentivePoolInfo,
|