@naviprotocol/wallet-client 1.3.0-dev.2 → 1.3.0
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.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getFullnodeUrl as de, SuiClient as we } from "@mysten/sui/client";
|
|
2
2
|
import he from "mitt";
|
|
3
3
|
import fe from "axios";
|
|
4
|
-
import { withSingleton as Q, getCoins as ge, mergeCoinsPTB as
|
|
4
|
+
import { withSingleton as Q, getCoins as ge, mergeCoinsPTB as B, getPriceFeeds as K, updateOraclePricesPTB as $, filterPriceFeeds as q, getFlashLoanAsset as te, flashloanPTB as ae, depositCoinPTB as N, repayFlashLoanPTB as ne, borrowCoinPTB as se, withdrawCoinPTB as ie, repayCoinPTB as le, 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 re, parseTxValue as _ } from "@naviprotocol/lending";
|
|
5
5
|
import R, { BigNumber as L } from "bignumber.js";
|
|
6
|
-
import { normalizeStructTag as
|
|
6
|
+
import { normalizeStructTag as p } from "@mysten/sui/utils";
|
|
7
7
|
import { Transaction as m } from "@mysten/sui/transactions";
|
|
8
8
|
import { buildSwapPTBFromQuote as G, 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
|
|
10
|
+
import { getCoinMetadataMap as Oe, MAX_U64 as Ae } from "@suilend/sui-fe";
|
|
11
11
|
import { executeAuction as xe } from "shio-sdk";
|
|
12
12
|
import { Signer as oe } from "@mysten/sui/cryptography";
|
|
13
13
|
const ce = fe.create({
|
|
@@ -64,7 +64,7 @@ class ke {
|
|
|
64
64
|
throw new Error("subscribe not implemented.");
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
class
|
|
67
|
+
class A {
|
|
68
68
|
/**
|
|
69
69
|
* Gets the current configuration for this module
|
|
70
70
|
*
|
|
@@ -107,19 +107,19 @@ class O {
|
|
|
107
107
|
this.walletClient = void 0;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class O {
|
|
111
111
|
/**
|
|
112
112
|
* Creates a new user portfolio
|
|
113
113
|
*
|
|
114
114
|
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
115
115
|
*/
|
|
116
116
|
constructor(e) {
|
|
117
|
-
if (e instanceof
|
|
117
|
+
if (e instanceof O)
|
|
118
118
|
this.balances = JSON.parse(JSON.stringify(e.balances));
|
|
119
119
|
else {
|
|
120
120
|
const a = {};
|
|
121
121
|
e == null || e.forEach((t) => {
|
|
122
|
-
const s =
|
|
122
|
+
const s = p(t.coinType);
|
|
123
123
|
let n = a[s];
|
|
124
124
|
n || (n = {
|
|
125
125
|
coinType: s,
|
|
@@ -136,7 +136,7 @@ class A {
|
|
|
136
136
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
137
137
|
*/
|
|
138
138
|
getBalance(e) {
|
|
139
|
-
return e =
|
|
139
|
+
return e = p(e), this.balances[e] || { coinType: e, amount: L(0), coins: [] };
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Gets all coin types in the portfolio
|
|
@@ -153,7 +153,7 @@ class A {
|
|
|
153
153
|
* @returns BigNumber representing the total balance
|
|
154
154
|
*/
|
|
155
155
|
balanceOf(e) {
|
|
156
|
-
e =
|
|
156
|
+
e = p(e);
|
|
157
157
|
const a = this.getBalance(e);
|
|
158
158
|
return (a == null ? void 0 : a.amount) || L(0);
|
|
159
159
|
}
|
|
@@ -166,11 +166,11 @@ class A {
|
|
|
166
166
|
* @returns New UserPortfolio instance with copied data
|
|
167
167
|
*/
|
|
168
168
|
clone() {
|
|
169
|
-
const e = JSON.parse(JSON.stringify(this.balances)), a = new
|
|
169
|
+
const e = JSON.parse(JSON.stringify(this.balances)), a = new O();
|
|
170
170
|
return a.balances = e, a;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
class Ne extends
|
|
173
|
+
class Ne extends A {
|
|
174
174
|
constructor() {
|
|
175
175
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
176
176
|
coinPollingInterval: 6e3,
|
|
@@ -180,8 +180,8 @@ class Ne extends O {
|
|
|
180
180
|
throw new Error("Wallet client not found");
|
|
181
181
|
this._coins = await ge(this.walletClient.address, {
|
|
182
182
|
client: this.walletClient.client
|
|
183
|
-
}), this._portfolio = new
|
|
184
|
-
}), this._coins = [], this._portfolio = new
|
|
183
|
+
}), this._portfolio = new O(this._coins), this.emit("balance:portfolio-updated", {});
|
|
184
|
+
}), this._coins = [], this._portfolio = new O(), this.pollingTimer = null, this._updatePromise = null;
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* Gets the current coin objects from the wallet
|
|
@@ -232,7 +232,7 @@ class Ne extends O {
|
|
|
232
232
|
* @returns Transaction response or dry run response
|
|
233
233
|
*/
|
|
234
234
|
async sendCoinBatch(e, a, t, s) {
|
|
235
|
-
var
|
|
235
|
+
var w;
|
|
236
236
|
if (!this.walletClient)
|
|
237
237
|
throw new Error("Wallet client not found");
|
|
238
238
|
if (a.length !== t.length)
|
|
@@ -243,7 +243,7 @@ class Ne extends O {
|
|
|
243
243
|
throw new Error("Insufficient balance");
|
|
244
244
|
const i = new m();
|
|
245
245
|
let l = i.gas;
|
|
246
|
-
|
|
246
|
+
p(e) !== p("0x2::sui::SUI") && (l = B(i, n.coins, {
|
|
247
247
|
balance: c.toNumber()
|
|
248
248
|
}));
|
|
249
249
|
const u = i.splitCoins(l, t);
|
|
@@ -251,7 +251,7 @@ class Ne extends O {
|
|
|
251
251
|
i.transferObjects([u[f]], g);
|
|
252
252
|
}), await this.walletClient.signExecuteTransaction({
|
|
253
253
|
transaction: i,
|
|
254
|
-
dryRun: (
|
|
254
|
+
dryRun: (w = s == null ? void 0 : s.dryRun) != null ? w : !1
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
@@ -344,10 +344,10 @@ async function Y(r, e, a, t) {
|
|
|
344
344
|
throw new Error("No supply balance");
|
|
345
345
|
if (t != null && t.amount && t.amount > o.supplyBalance)
|
|
346
346
|
throw new Error("Amount is less than supply balance");
|
|
347
|
-
const
|
|
347
|
+
const w = await K(), g = await Promise.all([s, n]);
|
|
348
348
|
await $(
|
|
349
349
|
r,
|
|
350
|
-
q(
|
|
350
|
+
q(w, {
|
|
351
351
|
lendingState: c,
|
|
352
352
|
pools: g
|
|
353
353
|
})
|
|
@@ -361,19 +361,19 @@ async function Y(r, e, a, t) {
|
|
|
361
361
|
s.suiCoinType,
|
|
362
362
|
n.suiCoinType,
|
|
363
363
|
y
|
|
364
|
-
),
|
|
365
|
-
if (
|
|
364
|
+
), h = Number(d.amount_out);
|
|
365
|
+
if (h <= 0)
|
|
366
366
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
367
|
-
const C = Math.floor(
|
|
368
|
-
if (
|
|
367
|
+
const C = Math.floor(h * (1 - b)), P = Math.floor(C / (1 + f.flashloanFee));
|
|
368
|
+
if (P <= 0)
|
|
369
369
|
throw new Error("The calculated borrow amount must be positive.");
|
|
370
|
-
const [
|
|
370
|
+
const [v, E] = await ae(r, n, P), [F] = r.moveCall({
|
|
371
371
|
target: "0x2::coin::from_balance",
|
|
372
|
-
arguments: [
|
|
372
|
+
arguments: [v],
|
|
373
373
|
typeArguments: [n.suiCoinType]
|
|
374
374
|
});
|
|
375
375
|
await N(r, n, F, {
|
|
376
|
-
amount:
|
|
376
|
+
amount: P
|
|
377
377
|
});
|
|
378
378
|
const j = await u.withdrawCoinPTB(r, s.suiCoinType, y), I = await G(
|
|
379
379
|
i,
|
|
@@ -385,7 +385,7 @@ async function Y(r, e, a, t) {
|
|
|
385
385
|
target: "0x2::coin::into_balance",
|
|
386
386
|
arguments: [I],
|
|
387
387
|
typeArguments: [n.suiCoinType]
|
|
388
|
-
}), [M] = await ne(r, n,
|
|
388
|
+
}), [M] = await ne(r, n, E, U), [W] = r.moveCall({
|
|
389
389
|
target: "0x2::coin::from_balance",
|
|
390
390
|
arguments: [M],
|
|
391
391
|
typeArguments: [n.suiCoinType]
|
|
@@ -407,10 +407,10 @@ async function Z(r, e, a, t) {
|
|
|
407
407
|
throw new Error("No borrow balance");
|
|
408
408
|
if (t != null && t.amount && t.amount > o.borrowBalance)
|
|
409
409
|
throw new Error("Amount is more than borrow balance");
|
|
410
|
-
const
|
|
410
|
+
const w = await K(), g = await Promise.all([n, c]);
|
|
411
411
|
await $(
|
|
412
412
|
r,
|
|
413
|
-
q(
|
|
413
|
+
q(w, {
|
|
414
414
|
lendingState: i,
|
|
415
415
|
pools: g
|
|
416
416
|
})
|
|
@@ -429,44 +429,34 @@ async function Z(r, e, a, t) {
|
|
|
429
429
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
430
430
|
if (!this.walletClient)
|
|
431
431
|
throw new Error("Wallet client not found");
|
|
432
|
-
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(f * (1 + b.flashloanFee)),
|
|
432
|
+
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(f * (1 + b.flashloanFee)), h = d, C = await this.walletClient.swap.getQuote(
|
|
433
433
|
n.suiCoinType,
|
|
434
434
|
c.suiCoinType,
|
|
435
|
-
|
|
435
|
+
h
|
|
436
436
|
);
|
|
437
|
-
let
|
|
437
|
+
let P = 1 + y, v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
438
438
|
c.suiCoinType,
|
|
439
439
|
n.suiCoinType,
|
|
440
|
-
|
|
440
|
+
v
|
|
441
441
|
);
|
|
442
|
-
for (
|
|
443
|
-
|
|
444
|
-
minSwapAmount: w,
|
|
445
|
-
toQuoteAmount: Number(B.amount_out),
|
|
446
|
-
rate: p
|
|
447
|
-
}); Number(B.amount_out) < w; )
|
|
448
|
-
p = p * Math.max(w / Number(B.amount_out), 1.001), E = Math.ceil(Number(C.amount_out) * p), B = await this.walletClient.swap.getQuote(
|
|
442
|
+
for (; Number(E.amount_out) < h; )
|
|
443
|
+
P = P * Math.max(h / Number(E.amount_out), 1.001), v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
449
444
|
c.suiCoinType,
|
|
450
445
|
n.suiCoinType,
|
|
451
|
-
|
|
452
|
-
)
|
|
453
|
-
toQuote: B,
|
|
454
|
-
minSwapAmount: w,
|
|
455
|
-
toQuoteAmount: Number(B.amount_out),
|
|
456
|
-
rate: p
|
|
457
|
-
});
|
|
446
|
+
v
|
|
447
|
+
);
|
|
458
448
|
const [F, j] = await ae(r, n, f), [I] = r.moveCall({
|
|
459
449
|
target: "0x2::coin::from_balance",
|
|
460
450
|
arguments: [F],
|
|
461
451
|
typeArguments: [n.suiCoinType]
|
|
462
452
|
});
|
|
463
453
|
await u.repayCoinPTB(r, n.suiCoinType, I, f);
|
|
464
|
-
const U = await se(r, c,
|
|
454
|
+
const U = await se(r, c, v), M = await G(
|
|
465
455
|
s,
|
|
466
456
|
r,
|
|
467
457
|
d,
|
|
468
458
|
U,
|
|
469
|
-
|
|
459
|
+
E
|
|
470
460
|
), W = r.moveCall({
|
|
471
461
|
target: "0x2::coin::into_balance",
|
|
472
462
|
arguments: [M],
|
|
@@ -491,15 +481,15 @@ async function ee(r, e, a, t) {
|
|
|
491
481
|
}), t != null && t.amount && n.amount.lt(t.amount))
|
|
492
482
|
throw new Error("Amount is greater than balance");
|
|
493
483
|
const c = (u = t == null ? void 0 : t.amount) != null ? u : n.amount.toNumber(), i = (o = t == null ? void 0 : t.slippage) != null ? o : 5e-3;
|
|
494
|
-
let l = await
|
|
484
|
+
let l = await B(r, n.coins, {
|
|
495
485
|
balance: c,
|
|
496
486
|
useGasCoin: !0
|
|
497
487
|
});
|
|
498
|
-
if (
|
|
499
|
-
const
|
|
488
|
+
if (p(e) !== p(s.suiCoinType)) {
|
|
489
|
+
const w = await this.walletClient.swap.getQuote(e, s.suiCoinType, c);
|
|
500
490
|
l = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
501
491
|
r,
|
|
502
|
-
|
|
492
|
+
w,
|
|
503
493
|
l,
|
|
504
494
|
i
|
|
505
495
|
);
|
|
@@ -512,7 +502,7 @@ class _e {
|
|
|
512
502
|
}
|
|
513
503
|
async getPool(e) {
|
|
514
504
|
const a = await this.walletClient.lending.getPool(e), s = (await this.walletClient.lending.getLendingState()).find(
|
|
515
|
-
(i) => i.pool.suiCoinType ===
|
|
505
|
+
(i) => i.pool.suiCoinType === p(e)
|
|
516
506
|
), n = s ? new R(s.supplyBalance).toNumber() : 0, c = s ? new R(s.borrowBalance).toNumber() : 0;
|
|
517
507
|
return {
|
|
518
508
|
supplyBalance: n,
|
|
@@ -552,24 +542,24 @@ class z {
|
|
|
552
542
|
}
|
|
553
543
|
async getPool(e) {
|
|
554
544
|
var b, y;
|
|
555
|
-
const a =
|
|
545
|
+
const a = p(e), t = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
|
|
556
546
|
t.forEach((d) => {
|
|
557
|
-
s.add(
|
|
558
|
-
|
|
559
|
-
}), d.borrowsPoolRewardManager.poolRewards.forEach((
|
|
560
|
-
|
|
547
|
+
s.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((h) => {
|
|
548
|
+
h && s.add(p(h.coinType.name));
|
|
549
|
+
}), d.borrowsPoolRewardManager.poolRewards.forEach((h) => {
|
|
550
|
+
h && s.add(p(h.coinType.name));
|
|
561
551
|
});
|
|
562
552
|
});
|
|
563
|
-
const n = await
|
|
564
|
-
(d,
|
|
553
|
+
const n = await Oe(Array.from(s)), i = t.map((d) => Re(d, n)).reduce(
|
|
554
|
+
(d, h) => (d[h.coinType] = h, d),
|
|
565
555
|
{}
|
|
566
556
|
), l = await this.suilendClient.getObligation(
|
|
567
557
|
this.obligationOwnerCap.obligationId
|
|
568
|
-
), u = Se(l, i), o = u.deposits.find((d) => d.coinType === a),
|
|
558
|
+
), u = Se(l, i), o = u.deposits.find((d) => d.coinType === a), w = u.borrows.find((d) => d.coinType === a), g = n[a].decimals;
|
|
569
559
|
return {
|
|
570
560
|
cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
|
|
571
561
|
supplyBalance: (b = o == null ? void 0 : o.depositedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? b : 0,
|
|
572
|
-
borrowBalance: (y =
|
|
562
|
+
borrowBalance: (y = w == null ? void 0 : w.borrowedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? y : 0,
|
|
573
563
|
borrowAPR: i[a].borrowAprPercent.toNumber()
|
|
574
564
|
};
|
|
575
565
|
}
|
|
@@ -582,7 +572,7 @@ class z {
|
|
|
582
572
|
this.obligationOwnerCap.id,
|
|
583
573
|
this.obligationOwnerCap.obligationId,
|
|
584
574
|
a,
|
|
585
|
-
n ?
|
|
575
|
+
n ? Ae.toString() : Math.ceil(t / s.cTokenExchangeRate).toString(),
|
|
586
576
|
e
|
|
587
577
|
);
|
|
588
578
|
}
|
|
@@ -593,7 +583,7 @@ class z {
|
|
|
593
583
|
this.suilendClient.repay(this.obligationOwnerCap.obligationId, a, t, e), e.transferObjects([t], e.pure.address(this.walletClient.address));
|
|
594
584
|
}
|
|
595
585
|
}
|
|
596
|
-
class Fe extends
|
|
586
|
+
class Fe extends A {
|
|
597
587
|
constructor() {
|
|
598
588
|
super(), this.name = "lending", this.defaultConfig = {
|
|
599
589
|
env: "prod",
|
|
@@ -627,7 +617,7 @@ class Fe extends O {
|
|
|
627
617
|
* @returns Pool information
|
|
628
618
|
*/
|
|
629
619
|
async getPool(e, a) {
|
|
630
|
-
return await
|
|
620
|
+
return await T(e, {
|
|
631
621
|
env: this.config.env,
|
|
632
622
|
...a
|
|
633
623
|
});
|
|
@@ -641,14 +631,14 @@ class Fe extends O {
|
|
|
641
631
|
* @returns Transaction response or dry run response
|
|
642
632
|
*/
|
|
643
633
|
async deposit(e, a, t) {
|
|
644
|
-
var u, o,
|
|
634
|
+
var u, o, w;
|
|
645
635
|
if (!this.walletClient)
|
|
646
636
|
throw new Error("Wallet client not found");
|
|
647
|
-
const s = await
|
|
637
|
+
const s = await T(e, {
|
|
648
638
|
env: this.config.env
|
|
649
639
|
});
|
|
650
640
|
await this.walletClient.module("balance").waitForUpdate();
|
|
651
|
-
const n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i =
|
|
641
|
+
const n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
|
|
652
642
|
balance: a,
|
|
653
643
|
useGasCoin: !0
|
|
654
644
|
});
|
|
@@ -661,7 +651,7 @@ class Fe extends O {
|
|
|
661
651
|
transaction: n,
|
|
662
652
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
663
653
|
});
|
|
664
|
-
return !(t != null && t.dryRun) && ((
|
|
654
|
+
return !(t != null && t.dryRun) && ((w = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:deposit-success", {
|
|
665
655
|
identifier: e,
|
|
666
656
|
amount: a
|
|
667
657
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -678,7 +668,7 @@ class Fe extends O {
|
|
|
678
668
|
var l, u, o;
|
|
679
669
|
if (!this.walletClient)
|
|
680
670
|
throw new Error("Wallet client not found");
|
|
681
|
-
const s = await
|
|
671
|
+
const s = await T(e, {
|
|
682
672
|
env: this.config.env
|
|
683
673
|
}), n = new m();
|
|
684
674
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
@@ -708,7 +698,7 @@ class Fe extends O {
|
|
|
708
698
|
var l, u, o;
|
|
709
699
|
if (!this.walletClient)
|
|
710
700
|
throw new Error("Wallet client not found");
|
|
711
|
-
const s = await
|
|
701
|
+
const s = await T(e, {
|
|
712
702
|
env: this.config.env
|
|
713
703
|
}), n = new m();
|
|
714
704
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
@@ -735,13 +725,13 @@ class Fe extends O {
|
|
|
735
725
|
* @returns Transaction response or dry run response
|
|
736
726
|
*/
|
|
737
727
|
async repay(e, a, t) {
|
|
738
|
-
var u, o,
|
|
728
|
+
var u, o, w;
|
|
739
729
|
if (!this.walletClient)
|
|
740
730
|
throw new Error("Wallet client not found");
|
|
741
731
|
await this.walletClient.module("balance").waitForUpdate();
|
|
742
|
-
const s = await
|
|
732
|
+
const s = await T(e, {
|
|
743
733
|
env: this.config.env
|
|
744
|
-
}), n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i =
|
|
734
|
+
}), n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
|
|
745
735
|
balance: a,
|
|
746
736
|
useGasCoin: !0
|
|
747
737
|
});
|
|
@@ -754,7 +744,7 @@ class Fe extends O {
|
|
|
754
744
|
transaction: n,
|
|
755
745
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
756
746
|
});
|
|
757
|
-
return !(t != null && t.dryRun) && ((
|
|
747
|
+
return !(t != null && t.dryRun) && ((w = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:repay-success", {
|
|
758
748
|
identifier: e,
|
|
759
749
|
amount: a
|
|
760
750
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -784,17 +774,17 @@ class Fe extends O {
|
|
|
784
774
|
* @returns Transaction response or dry run response
|
|
785
775
|
*/
|
|
786
776
|
async liquidate(e, a, t, s, n) {
|
|
787
|
-
var d,
|
|
777
|
+
var d, h, C;
|
|
788
778
|
if (!this.walletClient)
|
|
789
779
|
throw new Error("Wallet client not found");
|
|
790
|
-
const c = await
|
|
780
|
+
const c = await T(e, {
|
|
791
781
|
env: this.config.env
|
|
792
|
-
}), i = await
|
|
782
|
+
}), i = await T(t, {
|
|
793
783
|
env: this.config.env
|
|
794
|
-
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), o =
|
|
784
|
+
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), o = B(l, u.coins, {
|
|
795
785
|
balance: a,
|
|
796
786
|
useGasCoin: !0
|
|
797
|
-
}), [
|
|
787
|
+
}), [w, g] = await be(
|
|
798
788
|
l,
|
|
799
789
|
c,
|
|
800
790
|
o,
|
|
@@ -805,7 +795,7 @@ class Fe extends O {
|
|
|
805
795
|
}
|
|
806
796
|
), [f] = l.moveCall({
|
|
807
797
|
target: "0x2::coin::from_balance",
|
|
808
|
-
arguments: [
|
|
798
|
+
arguments: [w],
|
|
809
799
|
typeArguments: [i.suiCoinType]
|
|
810
800
|
}), [b] = l.moveCall({
|
|
811
801
|
target: "0x2::coin::from_balance",
|
|
@@ -817,7 +807,7 @@ class Fe extends O {
|
|
|
817
807
|
transaction: l,
|
|
818
808
|
dryRun: (d = n == null ? void 0 : n.dryRun) != null ? d : !1
|
|
819
809
|
});
|
|
820
|
-
return !(n != null && n.dryRun) && ((C = (
|
|
810
|
+
return !(n != null && n.dryRun) && ((C = (h = y.effects) == null ? void 0 : h.status) == null ? void 0 : C.status) === "success" && (this.emit("lending:liquidate-success", {
|
|
821
811
|
payIdentifier: e,
|
|
822
812
|
payAmount: a,
|
|
823
813
|
collateralIdentifier: t,
|
|
@@ -955,7 +945,7 @@ class Fe extends O {
|
|
|
955
945
|
this._protocols = e;
|
|
956
946
|
}
|
|
957
947
|
}
|
|
958
|
-
class je extends
|
|
948
|
+
class je extends A {
|
|
959
949
|
constructor() {
|
|
960
950
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
961
951
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
@@ -1022,7 +1012,7 @@ class je extends O {
|
|
|
1022
1012
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
1023
1013
|
const t = new m();
|
|
1024
1014
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1025
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n =
|
|
1015
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
|
|
1026
1016
|
balance: e,
|
|
1027
1017
|
useGasCoin: !0
|
|
1028
1018
|
}), c = await this.stakePTB(t, n);
|
|
@@ -1050,7 +1040,7 @@ class je extends O {
|
|
|
1050
1040
|
if (e < 1e9)
|
|
1051
1041
|
throw new Error("Unstake amount should >= 1vSui");
|
|
1052
1042
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1053
|
-
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n =
|
|
1043
|
+
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
|
|
1054
1044
|
balance: e
|
|
1055
1045
|
}), c = await this.unstakePTB(t, n);
|
|
1056
1046
|
t.transferObjects([c], this.walletClient.address);
|
|
@@ -1063,7 +1053,7 @@ class je extends O {
|
|
|
1063
1053
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1064
1054
|
}
|
|
1065
1055
|
}
|
|
1066
|
-
class Ie extends
|
|
1056
|
+
class Ie extends A {
|
|
1067
1057
|
constructor() {
|
|
1068
1058
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1069
1059
|
apiKey: "",
|
|
@@ -1146,11 +1136,11 @@ class Ie extends O {
|
|
|
1146
1136
|
* @returns Transaction response or dry run response
|
|
1147
1137
|
*/
|
|
1148
1138
|
async swap(e, a, t, s, n) {
|
|
1149
|
-
var y, d,
|
|
1139
|
+
var y, d, h;
|
|
1150
1140
|
if (!this.walletClient)
|
|
1151
1141
|
throw new Error("Wallet client not found");
|
|
1152
1142
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1153
|
-
const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l =
|
|
1143
|
+
const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l = B(i, c.coins, {
|
|
1154
1144
|
balance: t,
|
|
1155
1145
|
useGasCoin: !0
|
|
1156
1146
|
}), u = await this.getQuote(e, a, t), o = await this.buildSwapPTBFromQuote(i, u, l, s);
|
|
@@ -1159,9 +1149,9 @@ class Ie extends O {
|
|
|
1159
1149
|
transaction: i,
|
|
1160
1150
|
dryRun: !0
|
|
1161
1151
|
});
|
|
1162
|
-
const
|
|
1152
|
+
const w = await i.build({
|
|
1163
1153
|
client: this.walletClient.client
|
|
1164
|
-
}), g = await this.walletClient.signer.signTransaction(
|
|
1154
|
+
}), g = await this.walletClient.signer.signTransaction(w), f = [g.signature];
|
|
1165
1155
|
try {
|
|
1166
1156
|
await xe(g.bytes, f);
|
|
1167
1157
|
} catch (C) {
|
|
@@ -1177,7 +1167,7 @@ class Ie extends O {
|
|
|
1177
1167
|
}
|
|
1178
1168
|
});
|
|
1179
1169
|
if (((d = (y = b.effects) == null ? void 0 : y.status) == null ? void 0 : d.status) === "success") {
|
|
1180
|
-
const C = (
|
|
1170
|
+
const C = (h = b.events) == null ? void 0 : h.find((P) => P.type.includes("::slippage::SwapEvent"));
|
|
1181
1171
|
C && this.emit("swap:swap-success", {
|
|
1182
1172
|
fromCoinType: e,
|
|
1183
1173
|
toCoinType: a,
|
|
@@ -1189,7 +1179,7 @@ class Ie extends O {
|
|
|
1189
1179
|
return b;
|
|
1190
1180
|
}
|
|
1191
1181
|
}
|
|
1192
|
-
class Ue extends
|
|
1182
|
+
class Ue extends A {
|
|
1193
1183
|
constructor() {
|
|
1194
1184
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1195
1185
|
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
@@ -1250,7 +1240,7 @@ class Ue extends O {
|
|
|
1250
1240
|
throw new Error("Wallet client not found");
|
|
1251
1241
|
const t = new m();
|
|
1252
1242
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1253
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n =
|
|
1243
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
|
|
1254
1244
|
balance: e,
|
|
1255
1245
|
useGasCoin: !0
|
|
1256
1246
|
}), c = await this.stakePTB(t, n);
|
|
@@ -1272,7 +1262,7 @@ class Ue extends O {
|
|
|
1272
1262
|
if (!this.walletClient)
|
|
1273
1263
|
throw new Error("Wallet client not found");
|
|
1274
1264
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1275
|
-
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n =
|
|
1265
|
+
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
|
|
1276
1266
|
balance: e
|
|
1277
1267
|
}), c = await this.unstakePTB(t, n);
|
|
1278
1268
|
t.transferObjects([c], this.walletClient.address);
|