@naviprotocol/wallet-client 1.4.5-dev.1 → 1.4.5
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 -21
- package/README.md +140 -140
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +131 -135
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/lendingModule/migrate.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import { getFullnodeUrl as we, SuiClient as he } from "@mysten/sui/client";
|
|
2
2
|
import fe from "mitt";
|
|
3
3
|
import ge from "axios";
|
|
4
|
-
import { withSingleton as
|
|
4
|
+
import { withSingleton as K, getCoins as te, mergeCoinsPTB as B, getPriceFeeds as $, updateOraclePricesPTB as q, filterPriceFeeds as G, depositCoinPTB as A, getFlashLoanAsset as ae, flashloanPTB as ne, repayFlashLoanPTB as se, borrowCoinPTB as ie, withdrawCoinPTB as le, repayCoinPTB as re, getPools as me, getPool as T, getHealthFactor as Ce, liquidatePTB as be, getUserAvailableLendingRewards as J, getUserClaimedRewardHistory as ye, claimLendingRewardsPTB as pe, getLendingState as Pe, createAccountCapPTB as Be, withCache as oe, parseTxValue as _ } from "@naviprotocol/lending";
|
|
5
5
|
import R, { BigNumber as Q } from "bignumber.js";
|
|
6
6
|
import { normalizeStructTag as p } from "@mysten/sui/utils";
|
|
7
7
|
import { Transaction as m } from "@mysten/sui/transactions";
|
|
8
|
-
import { buildSwapPTBFromQuote as
|
|
8
|
+
import { buildSwapPTBFromQuote as z, generateRefId as Te, getQuote as ve } from "@naviprotocol/astros-aggregator-sdk";
|
|
9
9
|
import { SuilendClient as V, LENDING_MARKET_ID as Ee, LENDING_MARKET_TYPE as X, parseReserve as Re, parseObligation as Se } from "@suilend/sdk";
|
|
10
|
-
import { getCoinMetadataMap as
|
|
11
|
-
import { executeAuction as
|
|
10
|
+
import { getCoinMetadataMap as Oe, MAX_U64 as Ae } from "@suilend/sui-fe";
|
|
11
|
+
import { executeAuction as xe } from "shio-sdk";
|
|
12
12
|
import { Signer as ce } from "@mysten/sui/cryptography";
|
|
13
13
|
const ue = ge.create({
|
|
14
14
|
timeout: 2e4
|
|
15
15
|
});
|
|
16
16
|
ue.interceptors.response.use(
|
|
17
|
-
function(
|
|
18
|
-
if (
|
|
19
|
-
throw new Error(
|
|
20
|
-
if (
|
|
21
|
-
throw new Error(
|
|
22
|
-
return
|
|
17
|
+
function(l) {
|
|
18
|
+
if (l.data.err)
|
|
19
|
+
throw new Error(l.data.err);
|
|
20
|
+
if (l.data.error)
|
|
21
|
+
throw new Error(l.data.error.message);
|
|
22
|
+
return l;
|
|
23
23
|
},
|
|
24
|
-
function(
|
|
25
|
-
return Promise.reject(
|
|
24
|
+
function(l) {
|
|
25
|
+
return Promise.reject(l);
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
|
-
class
|
|
28
|
+
class ke {
|
|
29
29
|
/**
|
|
30
30
|
* Creates a new custom transport instance
|
|
31
31
|
*
|
|
@@ -64,7 +64,7 @@ class Ne {
|
|
|
64
64
|
throw new Error("subscribe not implemented.");
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
class
|
|
67
|
+
class x {
|
|
68
68
|
/**
|
|
69
69
|
* Gets the current configuration for this module
|
|
70
70
|
*
|
|
@@ -170,12 +170,12 @@ class S {
|
|
|
170
170
|
return a.balances = e, a;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
class
|
|
173
|
+
class Ne extends x {
|
|
174
174
|
constructor() {
|
|
175
175
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
176
176
|
coinPollingInterval: 6e3,
|
|
177
177
|
disableCoinPolling: !1
|
|
178
|
-
}, this.updatePortfolio =
|
|
178
|
+
}, this.updatePortfolio = K(async () => {
|
|
179
179
|
if (!this.walletClient)
|
|
180
180
|
throw new Error("Wallet client not found");
|
|
181
181
|
this._coins = await te(this.walletClient.address, {
|
|
@@ -241,16 +241,16 @@ class Fe extends A {
|
|
|
241
241
|
const n = this.portfolio.getBalance(e), u = t.reduce((h, f) => h.plus(f), R(0));
|
|
242
242
|
if (n.amount.lt(u))
|
|
243
243
|
throw new Error("Insufficient balance");
|
|
244
|
-
const
|
|
245
|
-
let r =
|
|
246
|
-
p(e) !== p("0x2::sui::SUI") && (r = B(
|
|
244
|
+
const i = new m();
|
|
245
|
+
let r = i.gas;
|
|
246
|
+
p(e) !== p("0x2::sui::SUI") && (r = B(i, n.coins, {
|
|
247
247
|
balance: u.toNumber()
|
|
248
248
|
}));
|
|
249
|
-
const c =
|
|
249
|
+
const c = i.splitCoins(r, t);
|
|
250
250
|
return a.forEach((h, f) => {
|
|
251
|
-
|
|
251
|
+
i.transferObjects([c[f]], h);
|
|
252
252
|
}), await this.walletClient.signExecuteTransaction({
|
|
253
|
-
transaction:
|
|
253
|
+
transaction: i,
|
|
254
254
|
dryRun: (w = s == null ? void 0 : s.dryRun) != null ? w : !1
|
|
255
255
|
});
|
|
256
256
|
}
|
|
@@ -284,8 +284,8 @@ class Fe extends A {
|
|
|
284
284
|
throw new Error("Objects and recipients must have the same length");
|
|
285
285
|
await this.waitForUpdate();
|
|
286
286
|
const s = new m();
|
|
287
|
-
return e.forEach((
|
|
288
|
-
s.transferObjects([s.object(
|
|
287
|
+
return e.forEach((i, r) => {
|
|
288
|
+
s.transferObjects([s.object(i)], a[r]);
|
|
289
289
|
}), await this.walletClient.signExecuteTransaction({
|
|
290
290
|
transaction: s,
|
|
291
291
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
@@ -329,11 +329,11 @@ class Fe extends A {
|
|
|
329
329
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
async function Y(
|
|
333
|
-
var
|
|
332
|
+
async function Y(l, e, a, t) {
|
|
333
|
+
var k, N, O;
|
|
334
334
|
if (!this.walletClient)
|
|
335
335
|
throw new Error("Wallet client not found");
|
|
336
|
-
const s = await this.getPool(e), n = await this.getPool(a), u = await this.getLendingState(),
|
|
336
|
+
const s = await this.getPool(e), n = await this.getPool(a), u = await this.getLendingState(), i = this.walletClient.address, r = (k = t == null ? void 0 : t.protocol) != null ? k : "navi", c = await this.getProtocol(r);
|
|
337
337
|
if (!c)
|
|
338
338
|
throw new Error(`Protocol ${r} not found`);
|
|
339
339
|
const o = await c.getPool(s.coinType);
|
|
@@ -343,22 +343,22 @@ async function Y(i, e, a, t) {
|
|
|
343
343
|
throw new Error("No supply balance");
|
|
344
344
|
if (t != null && t.amount && t.amount > o.supplyBalance)
|
|
345
345
|
throw new Error("Amount is less than supply balance");
|
|
346
|
-
const w = (
|
|
347
|
-
if (await
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
const w = (N = t == null ? void 0 : t.slippage) != null ? N : 5e-3, h = (O = t == null ? void 0 : t.amount) != null ? O : Number(o.supplyBalance), f = await $(), b = await Promise.all([s, n]);
|
|
347
|
+
if (await q(
|
|
348
|
+
l,
|
|
349
|
+
G(f, {
|
|
350
350
|
lendingState: u,
|
|
351
351
|
pools: b
|
|
352
352
|
})
|
|
353
|
-
),
|
|
354
|
-
const
|
|
355
|
-
|
|
353
|
+
), r !== "navi" && s.id === n.id) {
|
|
354
|
+
const F = await c.withdrawCoinPTB(
|
|
355
|
+
l,
|
|
356
356
|
s.suiCoinType,
|
|
357
357
|
h
|
|
358
358
|
);
|
|
359
|
-
return await
|
|
359
|
+
return await A(l, n, F, {
|
|
360
360
|
amount: h
|
|
361
|
-
}),
|
|
361
|
+
}), l;
|
|
362
362
|
}
|
|
363
363
|
const y = await ae(n, {
|
|
364
364
|
env: this.config.env
|
|
@@ -375,40 +375,36 @@ async function Y(i, e, a, t) {
|
|
|
375
375
|
const C = Math.floor(g * (1 - w)), P = Math.floor(C / (1 + y.flashloanFee));
|
|
376
376
|
if (P <= 0)
|
|
377
377
|
throw new Error("The calculated borrow amount must be positive.");
|
|
378
|
-
const [v, E] = await ne(
|
|
378
|
+
const [v, E] = await ne(l, n, P), [j] = l.moveCall({
|
|
379
379
|
target: "0x2::coin::from_balance",
|
|
380
380
|
arguments: [v],
|
|
381
381
|
typeArguments: [n.suiCoinType]
|
|
382
382
|
});
|
|
383
|
-
await
|
|
383
|
+
await A(l, n, j, {
|
|
384
384
|
amount: P
|
|
385
385
|
});
|
|
386
|
-
const I = await c.withdrawCoinPTB(
|
|
387
|
-
console.log("migration before swap", i.blockData.transactions.length, i.blockData.transactions);
|
|
388
|
-
const U = await G(
|
|
389
|
-
l,
|
|
386
|
+
const I = await c.withdrawCoinPTB(l, s.suiCoinType, h), U = await z(
|
|
390
387
|
i,
|
|
388
|
+
l,
|
|
391
389
|
C,
|
|
392
390
|
I,
|
|
393
391
|
d
|
|
394
|
-
)
|
|
395
|
-
console.log("migration after swap", i.blockData.transactions.length, i.blockData.transactions);
|
|
396
|
-
const M = i.moveCall({
|
|
392
|
+
), M = l.moveCall({
|
|
397
393
|
target: "0x2::coin::into_balance",
|
|
398
394
|
arguments: [U],
|
|
399
395
|
typeArguments: [n.suiCoinType]
|
|
400
|
-
}), [W] = await se(
|
|
396
|
+
}), [W] = await se(l, n, E, M), [L] = l.moveCall({
|
|
401
397
|
target: "0x2::coin::from_balance",
|
|
402
398
|
arguments: [W],
|
|
403
399
|
typeArguments: [n.suiCoinType]
|
|
404
400
|
});
|
|
405
|
-
return await
|
|
401
|
+
return await A(l, n, L), l;
|
|
406
402
|
}
|
|
407
|
-
async function Z(
|
|
408
|
-
var
|
|
403
|
+
async function Z(l, e, a, t) {
|
|
404
|
+
var O, F, D;
|
|
409
405
|
if (!this.walletClient)
|
|
410
406
|
throw new Error("Wallet client not found");
|
|
411
|
-
const s = this.walletClient.address, n = await this.getPool(e), u = await this.getPool(a),
|
|
407
|
+
const s = this.walletClient.address, n = await this.getPool(e), u = await this.getPool(a), i = await this.getLendingState(), r = (O = t == null ? void 0 : t.protocol) != null ? O : "navi", c = await this.getProtocol(r);
|
|
412
408
|
if (!c)
|
|
413
409
|
throw new Error(`Protocol ${r} not found`);
|
|
414
410
|
const o = await c.getPool(n.coinType);
|
|
@@ -418,15 +414,15 @@ async function Z(i, e, a, t) {
|
|
|
418
414
|
throw new Error("No borrow balance");
|
|
419
415
|
if (t != null && t.amount && t.amount > o.borrowBalance)
|
|
420
416
|
throw new Error("Amount is more than borrow balance");
|
|
421
|
-
const w = await
|
|
422
|
-
await
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
lendingState:
|
|
417
|
+
const w = await $(), h = await Promise.all([n, u]);
|
|
418
|
+
await q(
|
|
419
|
+
l,
|
|
420
|
+
G(w, {
|
|
421
|
+
lendingState: i,
|
|
426
422
|
pools: h
|
|
427
423
|
})
|
|
428
424
|
);
|
|
429
|
-
let f = (
|
|
425
|
+
let f = (F = t == null ? void 0 : t.amount) != null ? F : Number(o.borrowBalance);
|
|
430
426
|
if (Number(o.borrowBalance) === f) {
|
|
431
427
|
const de = o.borrowAPR / 100;
|
|
432
428
|
f = Math.ceil(
|
|
@@ -440,7 +436,7 @@ async function Z(i, e, a, t) {
|
|
|
440
436
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
441
437
|
if (!this.walletClient)
|
|
442
438
|
throw new Error("Wallet client not found");
|
|
443
|
-
const y = (
|
|
439
|
+
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(f * (1 + b.flashloanFee)), g = d, C = await this.walletClient.swap.getQuote(
|
|
444
440
|
n.suiCoinType,
|
|
445
441
|
u.suiCoinType,
|
|
446
442
|
g
|
|
@@ -456,66 +452,66 @@ async function Z(i, e, a, t) {
|
|
|
456
452
|
n.suiCoinType,
|
|
457
453
|
v
|
|
458
454
|
);
|
|
459
|
-
const [
|
|
455
|
+
const [j, I] = await ne(l, n, f), [U] = l.moveCall({
|
|
460
456
|
target: "0x2::coin::from_balance",
|
|
461
|
-
arguments: [
|
|
457
|
+
arguments: [j],
|
|
462
458
|
typeArguments: [n.suiCoinType]
|
|
463
459
|
});
|
|
464
|
-
await c.repayCoinPTB(
|
|
465
|
-
const M = await ie(
|
|
460
|
+
await c.repayCoinPTB(l, n.suiCoinType, U, f);
|
|
461
|
+
const M = await ie(l, u, v), W = await z(
|
|
466
462
|
s,
|
|
467
|
-
|
|
463
|
+
l,
|
|
468
464
|
d,
|
|
469
465
|
M,
|
|
470
466
|
E
|
|
471
|
-
), L =
|
|
467
|
+
), L = l.moveCall({
|
|
472
468
|
target: "0x2::coin::into_balance",
|
|
473
469
|
arguments: [W],
|
|
474
470
|
typeArguments: [n.suiCoinType]
|
|
475
|
-
}), [
|
|
471
|
+
}), [k] = await se(l, n, I, L), [N] = l.moveCall({
|
|
476
472
|
target: "0x2::coin::from_balance",
|
|
477
|
-
arguments: [
|
|
473
|
+
arguments: [k],
|
|
478
474
|
typeArguments: [n.suiCoinType]
|
|
479
475
|
});
|
|
480
|
-
return
|
|
476
|
+
return l.transferObjects([N], s), l;
|
|
481
477
|
}
|
|
482
|
-
async function ee(
|
|
478
|
+
async function ee(l, e, a, t) {
|
|
483
479
|
var w, h;
|
|
484
480
|
if (!this.walletClient)
|
|
485
481
|
throw new Error("Wallet client not found");
|
|
486
482
|
const s = await te(this.walletClient.address, {
|
|
487
483
|
client: this.walletClient.client,
|
|
488
484
|
coinType: e
|
|
489
|
-
}), n = await this.getPool(a),
|
|
490
|
-
if (
|
|
485
|
+
}), n = await this.getPool(a), i = new S(s).getBalance(e);
|
|
486
|
+
if (i.amount.eq(0))
|
|
491
487
|
throw new Error(`No balance of ${e}`);
|
|
492
488
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
493
|
-
balance:
|
|
494
|
-
}), t != null && t.amount &&
|
|
489
|
+
balance: i.amount.toNumber()
|
|
490
|
+
}), t != null && t.amount && i.amount.lt(t.amount))
|
|
495
491
|
throw new Error("Amount is greater than balance");
|
|
496
|
-
const r = (w = t == null ? void 0 : t.amount) != null ? w :
|
|
497
|
-
let o = await B(
|
|
492
|
+
const r = (w = t == null ? void 0 : t.amount) != null ? w : i.amount.toNumber(), c = (h = t == null ? void 0 : t.slippage) != null ? h : 5e-3;
|
|
493
|
+
let o = await B(l, i.coins, {
|
|
498
494
|
balance: r,
|
|
499
495
|
useGasCoin: !0
|
|
500
496
|
});
|
|
501
497
|
if (p(e) !== p(n.suiCoinType)) {
|
|
502
498
|
const f = await this.walletClient.swap.getQuote(e, n.suiCoinType, r);
|
|
503
499
|
o = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
504
|
-
|
|
500
|
+
l,
|
|
505
501
|
f,
|
|
506
502
|
o,
|
|
507
503
|
c
|
|
508
504
|
);
|
|
509
505
|
}
|
|
510
|
-
return await
|
|
506
|
+
return await A(l, n, o), l;
|
|
511
507
|
}
|
|
512
|
-
class
|
|
508
|
+
class Fe {
|
|
513
509
|
constructor(e) {
|
|
514
510
|
this.name = "navi", this.walletClient = e;
|
|
515
511
|
}
|
|
516
512
|
async getPool(e) {
|
|
517
513
|
const a = await this.walletClient.lending.getPool(e), s = (await this.walletClient.lending.getLendingState()).find(
|
|
518
|
-
(
|
|
514
|
+
(i) => i.pool.suiCoinType === p(e)
|
|
519
515
|
), n = s ? new R(s.supplyBalance).toNumber() : 0, u = s ? new R(s.borrowBalance).toNumber() : 0;
|
|
520
516
|
return {
|
|
521
517
|
supplyBalance: n,
|
|
@@ -536,7 +532,7 @@ class _e {
|
|
|
536
532
|
re(e, a, t, { amount: s });
|
|
537
533
|
}
|
|
538
534
|
}
|
|
539
|
-
class
|
|
535
|
+
class H {
|
|
540
536
|
constructor(e, a, t) {
|
|
541
537
|
this.name = "suilend", this.walletClient = e, this.obligationOwnerCap = a, this.suilendClient = t;
|
|
542
538
|
}
|
|
@@ -551,7 +547,7 @@ class z {
|
|
|
551
547
|
]);
|
|
552
548
|
if (t.length === 0)
|
|
553
549
|
throw new Error("No existing obligations found for wallet address: " + e.address);
|
|
554
|
-
return new
|
|
550
|
+
return new H(e, t[0], a);
|
|
555
551
|
}
|
|
556
552
|
async getPool(e) {
|
|
557
553
|
var b, y;
|
|
@@ -563,17 +559,17 @@ class z {
|
|
|
563
559
|
g && s.add(p(g.coinType.name));
|
|
564
560
|
});
|
|
565
561
|
});
|
|
566
|
-
const n = await
|
|
562
|
+
const n = await Oe(Array.from(s)), i = t.map((d) => Re(d, n)).reduce(
|
|
567
563
|
(d, g) => (d[g.coinType] = g, d),
|
|
568
564
|
{}
|
|
569
565
|
), r = await this.suilendClient.getObligation(
|
|
570
566
|
this.obligationOwnerCap.obligationId
|
|
571
|
-
), c = Se(r,
|
|
567
|
+
), c = Se(r, i), o = c.deposits.find((d) => d.coinType === a), w = c.borrows.find((d) => d.coinType === a), h = n[a].decimals;
|
|
572
568
|
return {
|
|
573
|
-
cTokenExchangeRate:
|
|
569
|
+
cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
|
|
574
570
|
supplyBalance: (b = o == null ? void 0 : o.depositedAmount.shiftedBy(h).decimalPlaces(0).toNumber()) != null ? b : 0,
|
|
575
571
|
borrowBalance: (y = w == null ? void 0 : w.borrowedAmount.shiftedBy(h).decimalPlaces(0).toNumber()) != null ? y : 0,
|
|
576
|
-
borrowAPR:
|
|
572
|
+
borrowAPR: i[a].borrowAprPercent.toNumber()
|
|
577
573
|
};
|
|
578
574
|
}
|
|
579
575
|
async depositCoinPTB(e, a, t, s) {
|
|
@@ -585,7 +581,7 @@ class z {
|
|
|
585
581
|
this.obligationOwnerCap.id,
|
|
586
582
|
this.obligationOwnerCap.obligationId,
|
|
587
583
|
a,
|
|
588
|
-
n ?
|
|
584
|
+
n ? Ae.toString() : Math.ceil(t / s.cTokenExchangeRate).toString(),
|
|
589
585
|
e
|
|
590
586
|
);
|
|
591
587
|
}
|
|
@@ -596,7 +592,7 @@ class z {
|
|
|
596
592
|
this.suilendClient.repay(this.obligationOwnerCap.obligationId, a, t, e), e.transferObjects([t], e.pure.address(this.walletClient.address));
|
|
597
593
|
}
|
|
598
594
|
}
|
|
599
|
-
class
|
|
595
|
+
class _e extends x {
|
|
600
596
|
constructor() {
|
|
601
597
|
super(), this.name = "lending", this.defaultConfig = {
|
|
602
598
|
env: "prod",
|
|
@@ -651,11 +647,11 @@ class je extends A {
|
|
|
651
647
|
env: this.config.env
|
|
652
648
|
});
|
|
653
649
|
await this.walletClient.module("balance").waitForUpdate();
|
|
654
|
-
const n = new m(), u = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType),
|
|
650
|
+
const n = new m(), u = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, u.coins, {
|
|
655
651
|
balance: a,
|
|
656
652
|
useGasCoin: !0
|
|
657
653
|
});
|
|
658
|
-
await
|
|
654
|
+
await A(n, s, i, {
|
|
659
655
|
env: this.config.env,
|
|
660
656
|
amount: a,
|
|
661
657
|
accountCap: t == null ? void 0 : t.accountCap
|
|
@@ -690,14 +686,14 @@ class je extends A {
|
|
|
690
686
|
accountCap: t == null ? void 0 : t.accountCap
|
|
691
687
|
});
|
|
692
688
|
n.transferObjects([u], this.walletClient.address);
|
|
693
|
-
const
|
|
689
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
694
690
|
transaction: n,
|
|
695
691
|
dryRun: (r = t == null ? void 0 : t.dryRun) != null ? r : !1
|
|
696
692
|
});
|
|
697
|
-
return !(t != null && t.dryRun) && ((o = (c =
|
|
693
|
+
return !(t != null && t.dryRun) && ((o = (c = i.effects) == null ? void 0 : c.status) == null ? void 0 : o.status) === "success" && (this.emit("lending:withdraw-success", {
|
|
698
694
|
identifier: e,
|
|
699
695
|
amount: a
|
|
700
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
696
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
701
697
|
}
|
|
702
698
|
/**
|
|
703
699
|
* Borrows coins from a lending pool
|
|
@@ -720,14 +716,14 @@ class je extends A {
|
|
|
720
716
|
accountCap: t == null ? void 0 : t.accountCap
|
|
721
717
|
});
|
|
722
718
|
n.transferObjects([u], this.walletClient.address);
|
|
723
|
-
const
|
|
719
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
724
720
|
transaction: n,
|
|
725
721
|
dryRun: (r = t == null ? void 0 : t.dryRun) != null ? r : !1
|
|
726
722
|
});
|
|
727
|
-
return !(t != null && t.dryRun) && ((o = (c =
|
|
723
|
+
return !(t != null && t.dryRun) && ((o = (c = i.effects) == null ? void 0 : c.status) == null ? void 0 : o.status) === "success" && (this.emit("lending:borrow-success", {
|
|
728
724
|
identifier: e,
|
|
729
725
|
amount: a
|
|
730
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
726
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
731
727
|
}
|
|
732
728
|
/**
|
|
733
729
|
* Repays borrowed coins to a lending pool
|
|
@@ -744,11 +740,11 @@ class je extends A {
|
|
|
744
740
|
await this.walletClient.module("balance").waitForUpdate();
|
|
745
741
|
const s = await T(e, {
|
|
746
742
|
env: this.config.env
|
|
747
|
-
}), n = new m(), u = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType),
|
|
743
|
+
}), n = new m(), u = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, u.coins, {
|
|
748
744
|
balance: a,
|
|
749
745
|
useGasCoin: !0
|
|
750
746
|
});
|
|
751
|
-
await re(n, s,
|
|
747
|
+
await re(n, s, i, {
|
|
752
748
|
env: this.config.env,
|
|
753
749
|
amount: a,
|
|
754
750
|
accountCap: t == null ? void 0 : t.accountCap
|
|
@@ -792,7 +788,7 @@ class je extends A {
|
|
|
792
788
|
throw new Error("Wallet client not found");
|
|
793
789
|
const u = await T(e, {
|
|
794
790
|
env: this.config.env
|
|
795
|
-
}),
|
|
791
|
+
}), i = await T(t, {
|
|
796
792
|
env: this.config.env
|
|
797
793
|
}), r = new m(), c = this.walletClient.module("balance").portfolio.getBalance(u.suiCoinType), o = B(r, c.coins, {
|
|
798
794
|
balance: a,
|
|
@@ -801,7 +797,7 @@ class je extends A {
|
|
|
801
797
|
r,
|
|
802
798
|
u,
|
|
803
799
|
o,
|
|
804
|
-
|
|
800
|
+
i,
|
|
805
801
|
s,
|
|
806
802
|
{
|
|
807
803
|
env: this.config.env
|
|
@@ -809,7 +805,7 @@ class je extends A {
|
|
|
809
805
|
), [f] = r.moveCall({
|
|
810
806
|
target: "0x2::coin::from_balance",
|
|
811
807
|
arguments: [w],
|
|
812
|
-
typeArguments: [
|
|
808
|
+
typeArguments: [i.suiCoinType]
|
|
813
809
|
}), [b] = r.moveCall({
|
|
814
810
|
target: "0x2::coin::from_balance",
|
|
815
811
|
arguments: [h],
|
|
@@ -863,7 +859,7 @@ class je extends A {
|
|
|
863
859
|
* @returns Transaction response or dry run response
|
|
864
860
|
*/
|
|
865
861
|
async claimAllRewards(e) {
|
|
866
|
-
var n, u,
|
|
862
|
+
var n, u, i;
|
|
867
863
|
if (!this.walletClient)
|
|
868
864
|
throw new Error("Wallet client not found");
|
|
869
865
|
const a = new m(), t = await J(this.walletClient.address, {
|
|
@@ -877,20 +873,20 @@ class je extends A {
|
|
|
877
873
|
transaction: a,
|
|
878
874
|
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
879
875
|
});
|
|
880
|
-
return !(e != null && e.dryRun) && ((
|
|
876
|
+
return !(e != null && e.dryRun) && ((i = (u = s.effects) == null ? void 0 : u.status) == null ? void 0 : i.status) === "success" && (this.emit("lending:claim-rewards-success", {
|
|
881
877
|
rewards: t
|
|
882
878
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
883
879
|
}
|
|
884
880
|
async updateOraclePTB(e, a) {
|
|
885
|
-
const t = await
|
|
881
|
+
const t = await $({
|
|
886
882
|
env: this.config.env
|
|
887
883
|
}), s = await this.getLendingState({
|
|
888
884
|
cacheTime: 60 * 1e3
|
|
889
|
-
}), n =
|
|
885
|
+
}), n = G(t, {
|
|
890
886
|
lendingState: s,
|
|
891
887
|
pools: a
|
|
892
888
|
});
|
|
893
|
-
await
|
|
889
|
+
await q(e, n, {
|
|
894
890
|
env: this.config.env,
|
|
895
891
|
updatePythPriceFeeds: !0
|
|
896
892
|
});
|
|
@@ -949,16 +945,16 @@ class je extends A {
|
|
|
949
945
|
return;
|
|
950
946
|
}
|
|
951
947
|
const e = [];
|
|
952
|
-
e.push(new
|
|
948
|
+
e.push(new Fe(this.walletClient));
|
|
953
949
|
try {
|
|
954
|
-
e.push(await
|
|
950
|
+
e.push(await H.create(this.walletClient));
|
|
955
951
|
} catch (a) {
|
|
956
952
|
console.warn("Failed to initialize SuilendProtocol:", a);
|
|
957
953
|
}
|
|
958
954
|
this._protocols = e;
|
|
959
955
|
}
|
|
960
956
|
}
|
|
961
|
-
class
|
|
957
|
+
class je extends x {
|
|
962
958
|
constructor() {
|
|
963
959
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
964
960
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
@@ -966,7 +962,7 @@ class xe extends A {
|
|
|
966
962
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
967
963
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
968
964
|
}, this.getStats = oe(
|
|
969
|
-
|
|
965
|
+
K(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
970
966
|
);
|
|
971
967
|
}
|
|
972
968
|
/**
|
|
@@ -983,7 +979,7 @@ class xe extends A {
|
|
|
983
979
|
e.object(this.config.poolId),
|
|
984
980
|
e.object(this.config.metadataId),
|
|
985
981
|
e.object("0x05"),
|
|
986
|
-
|
|
982
|
+
_(a, e.object)
|
|
987
983
|
],
|
|
988
984
|
typeArguments: []
|
|
989
985
|
});
|
|
@@ -1003,7 +999,7 @@ class xe extends A {
|
|
|
1003
999
|
e.object(this.config.poolId),
|
|
1004
1000
|
e.object(this.config.metadataId),
|
|
1005
1001
|
e.object("0x05"),
|
|
1006
|
-
|
|
1002
|
+
_(a, e.object)
|
|
1007
1003
|
],
|
|
1008
1004
|
typeArguments: []
|
|
1009
1005
|
});
|
|
@@ -1030,13 +1026,13 @@ class xe extends A {
|
|
|
1030
1026
|
useGasCoin: !0
|
|
1031
1027
|
}), u = await this.stakePTB(t, n);
|
|
1032
1028
|
t.transferObjects([u], this.walletClient.address);
|
|
1033
|
-
const
|
|
1029
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
1034
1030
|
transaction: t,
|
|
1035
1031
|
dryRun: (r = a == null ? void 0 : a.dryRun) != null ? r : !1
|
|
1036
1032
|
});
|
|
1037
|
-
return !(a != null && a.dryRun) && ((o = (c =
|
|
1033
|
+
return !(a != null && a.dryRun) && ((o = (c = i.effects) == null ? void 0 : c.status) == null ? void 0 : o.status) === "success" && (this.emit("volo:stake-success", {
|
|
1038
1034
|
suiAmount: e
|
|
1039
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
1035
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1040
1036
|
}
|
|
1041
1037
|
/**
|
|
1042
1038
|
* Unstake vSUI tokens to receive SUI tokens
|
|
@@ -1057,16 +1053,16 @@ class xe extends A {
|
|
|
1057
1053
|
balance: e
|
|
1058
1054
|
}), u = await this.unstakePTB(t, n);
|
|
1059
1055
|
t.transferObjects([u], this.walletClient.address);
|
|
1060
|
-
const
|
|
1056
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
1061
1057
|
transaction: t,
|
|
1062
1058
|
dryRun: (r = a == null ? void 0 : a.dryRun) != null ? r : !1
|
|
1063
1059
|
});
|
|
1064
|
-
return !(a != null && a.dryRun) && ((o = (c =
|
|
1060
|
+
return !(a != null && a.dryRun) && ((o = (c = i.effects) == null ? void 0 : c.status) == null ? void 0 : o.status) === "success" && (this.emit("volo:unstake-success", {
|
|
1065
1061
|
vSuiAmount: e
|
|
1066
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
1062
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1067
1063
|
}
|
|
1068
1064
|
}
|
|
1069
|
-
class Ie extends
|
|
1065
|
+
class Ie extends x {
|
|
1070
1066
|
constructor() {
|
|
1071
1067
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1072
1068
|
apiKey: "",
|
|
@@ -1119,7 +1115,7 @@ class Ie extends A {
|
|
|
1119
1115
|
if (!this.walletClient)
|
|
1120
1116
|
throw new Error("Wallet client not found");
|
|
1121
1117
|
const n = new R(a.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1122
|
-
return await
|
|
1118
|
+
return await z(
|
|
1123
1119
|
this.walletClient.address,
|
|
1124
1120
|
e,
|
|
1125
1121
|
Number(n),
|
|
@@ -1153,20 +1149,20 @@ class Ie extends A {
|
|
|
1153
1149
|
if (!this.walletClient)
|
|
1154
1150
|
throw new Error("Wallet client not found");
|
|
1155
1151
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1156
|
-
const u = this.walletClient.module("balance").portfolio.getBalance(e),
|
|
1152
|
+
const u = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), r = B(i, u.coins, {
|
|
1157
1153
|
balance: t,
|
|
1158
1154
|
useGasCoin: !0
|
|
1159
|
-
}), c = await this.getQuote(e, a, t), o = await this.buildSwapPTBFromQuote(
|
|
1160
|
-
if (
|
|
1155
|
+
}), c = await this.getQuote(e, a, t), o = await this.buildSwapPTBFromQuote(i, c, r, s);
|
|
1156
|
+
if (i.transferObjects([o], this.walletClient.address), i.setSender(this.walletClient.address), n != null && n.dryRun)
|
|
1161
1157
|
return await this.walletClient.signExecuteTransaction({
|
|
1162
|
-
transaction:
|
|
1158
|
+
transaction: i,
|
|
1163
1159
|
dryRun: !0
|
|
1164
1160
|
});
|
|
1165
|
-
const w = await
|
|
1161
|
+
const w = await i.build({
|
|
1166
1162
|
client: this.walletClient.client
|
|
1167
1163
|
}), h = await this.walletClient.signer.signTransaction(w), f = [h.signature];
|
|
1168
1164
|
try {
|
|
1169
|
-
await
|
|
1165
|
+
await xe(h.bytes, f);
|
|
1170
1166
|
} catch (C) {
|
|
1171
1167
|
console.error(C);
|
|
1172
1168
|
}
|
|
@@ -1192,14 +1188,14 @@ class Ie extends A {
|
|
|
1192
1188
|
return b;
|
|
1193
1189
|
}
|
|
1194
1190
|
}
|
|
1195
|
-
class Ue extends
|
|
1191
|
+
class Ue extends x {
|
|
1196
1192
|
constructor() {
|
|
1197
1193
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1198
1194
|
packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
|
|
1199
1195
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1200
1196
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1201
1197
|
}, this.getApy = oe(
|
|
1202
|
-
|
|
1198
|
+
K(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
1203
1199
|
);
|
|
1204
1200
|
}
|
|
1205
1201
|
/**
|
|
@@ -1215,7 +1211,7 @@ class Ue extends A {
|
|
|
1215
1211
|
arguments: [
|
|
1216
1212
|
e.object("0x05"),
|
|
1217
1213
|
e.object(this.config.configId),
|
|
1218
|
-
|
|
1214
|
+
_(a, e.object),
|
|
1219
1215
|
e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1220
1216
|
],
|
|
1221
1217
|
typeArguments: []
|
|
@@ -1235,7 +1231,7 @@ class Ue extends A {
|
|
|
1235
1231
|
arguments: [
|
|
1236
1232
|
e.object("0x05"),
|
|
1237
1233
|
e.object(this.config.configId),
|
|
1238
|
-
|
|
1234
|
+
_(a, e.object)
|
|
1239
1235
|
],
|
|
1240
1236
|
typeArguments: []
|
|
1241
1237
|
});
|
|
@@ -1258,11 +1254,11 @@ class Ue extends A {
|
|
|
1258
1254
|
useGasCoin: !0
|
|
1259
1255
|
}), u = await this.stakePTB(t, n);
|
|
1260
1256
|
t.transferObjects([u], this.walletClient.address);
|
|
1261
|
-
const
|
|
1257
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
1262
1258
|
transaction: t,
|
|
1263
1259
|
dryRun: (r = a == null ? void 0 : a.dryRun) != null ? r : !1
|
|
1264
1260
|
});
|
|
1265
|
-
return !(a != null && a.dryRun) && ((o = (c =
|
|
1261
|
+
return !(a != null && a.dryRun) && ((o = (c = i.effects) == null ? void 0 : c.status) == null ? void 0 : o.status) === "success" && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1266
1262
|
}
|
|
1267
1263
|
/**
|
|
1268
1264
|
* Unstake haSUI for SUI
|
|
@@ -1279,20 +1275,20 @@ class Ue extends A {
|
|
|
1279
1275
|
balance: e
|
|
1280
1276
|
}), u = await this.unstakePTB(t, n);
|
|
1281
1277
|
t.transferObjects([u], this.walletClient.address);
|
|
1282
|
-
const
|
|
1278
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
1283
1279
|
transaction: t,
|
|
1284
1280
|
dryRun: (r = a == null ? void 0 : a.dryRun) != null ? r : !1
|
|
1285
1281
|
});
|
|
1286
|
-
return !(a != null && a.dryRun) && ((o = (c =
|
|
1282
|
+
return !(a != null && a.dryRun) && ((o = (c = i.effects) == null ? void 0 : c.status) == null ? void 0 : o.status) === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1287
1283
|
}
|
|
1288
1284
|
}
|
|
1289
1285
|
const Me = {
|
|
1290
1286
|
/** Balance management module */
|
|
1291
|
-
balance: new
|
|
1287
|
+
balance: new Ne(),
|
|
1292
1288
|
/** Lending protocol module */
|
|
1293
|
-
lending: new
|
|
1289
|
+
lending: new _e(),
|
|
1294
1290
|
/** Volo protocol module */
|
|
1295
|
-
volo: new
|
|
1291
|
+
volo: new je(),
|
|
1296
1292
|
/** DEX swapping module */
|
|
1297
1293
|
swap: new Ie(),
|
|
1298
1294
|
/** Haedal protocol module */
|
|
@@ -1311,7 +1307,7 @@ class Ye {
|
|
|
1311
1307
|
...We,
|
|
1312
1308
|
...e.client
|
|
1313
1309
|
};
|
|
1314
|
-
a.transport = a.transport || new
|
|
1310
|
+
a.transport = a.transport || new ke(a.url), this.client = new he(a), this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, s]) => {
|
|
1315
1311
|
if (t !== s.name)
|
|
1316
1312
|
throw new Error(`Module name ${t} does not match module name ${s.name}`);
|
|
1317
1313
|
s.install(this);
|