@naviprotocol/wallet-client 1.3.0 → 1.3.1
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 +137 -137
- 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,7 +1,7 @@
|
|
|
1
|
-
import { getFullnodeUrl as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as Q, getCoins as
|
|
1
|
+
import { getFullnodeUrl as we, SuiClient as he } from "@mysten/sui/client";
|
|
2
|
+
import fe from "mitt";
|
|
3
|
+
import ge from "axios";
|
|
4
|
+
import { withSingleton as Q, getCoins as te, mergeCoinsPTB as B, getPriceFeeds as K, updateOraclePricesPTB as $, filterPriceFeeds as q, getFlashLoanAsset as ae, flashloanPTB as ne, depositCoinPTB as N, 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 L } from "bignumber.js";
|
|
6
6
|
import { normalizeStructTag as p } from "@mysten/sui/utils";
|
|
7
7
|
import { Transaction as m } from "@mysten/sui/transactions";
|
|
@@ -9,20 +9,20 @@ import { buildSwapPTBFromQuote as G, generateRefId as Te, getQuote as ve } from
|
|
|
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
10
|
import { getCoinMetadataMap as Oe, MAX_U64 as Ae } from "@suilend/sui-fe";
|
|
11
11
|
import { executeAuction as xe } from "shio-sdk";
|
|
12
|
-
import { Signer as
|
|
13
|
-
const
|
|
12
|
+
import { Signer as ce } from "@mysten/sui/cryptography";
|
|
13
|
+
const ue = ge.create({
|
|
14
14
|
timeout: 2e4
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
function(
|
|
18
|
-
if (
|
|
19
|
-
throw new Error(
|
|
20
|
-
if (
|
|
21
|
-
throw new Error(
|
|
22
|
-
return
|
|
16
|
+
ue.interceptors.response.use(
|
|
17
|
+
function(o) {
|
|
18
|
+
if (o.data.err)
|
|
19
|
+
throw new Error(o.data.err);
|
|
20
|
+
if (o.data.error)
|
|
21
|
+
throw new Error(o.data.error.message);
|
|
22
|
+
return o;
|
|
23
23
|
},
|
|
24
|
-
function(
|
|
25
|
-
return Promise.reject(
|
|
24
|
+
function(o) {
|
|
25
|
+
return Promise.reject(o);
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
28
|
class ke {
|
|
@@ -44,7 +44,7 @@ class ke {
|
|
|
44
44
|
* @returns Promise<T> - The response data from the RPC call
|
|
45
45
|
*/
|
|
46
46
|
async request(e) {
|
|
47
|
-
return this.requestId += 1, (await
|
|
47
|
+
return this.requestId += 1, (await ue.post(this.rpcUrl, {
|
|
48
48
|
jsonrpc: "2.0",
|
|
49
49
|
id: this.requestId,
|
|
50
50
|
method: e.method,
|
|
@@ -107,14 +107,14 @@ class A {
|
|
|
107
107
|
this.walletClient = void 0;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class S {
|
|
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 S)
|
|
118
118
|
this.balances = JSON.parse(JSON.stringify(e.balances));
|
|
119
119
|
else {
|
|
120
120
|
const a = {};
|
|
@@ -166,7 +166,7 @@ class O {
|
|
|
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 S();
|
|
170
170
|
return a.balances = e, a;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -178,10 +178,10 @@ class Ne extends A {
|
|
|
178
178
|
}, this.updatePortfolio = Q(async () => {
|
|
179
179
|
if (!this.walletClient)
|
|
180
180
|
throw new Error("Wallet client not found");
|
|
181
|
-
this._coins = await
|
|
181
|
+
this._coins = await te(this.walletClient.address, {
|
|
182
182
|
client: this.walletClient.client
|
|
183
|
-
}), this._portfolio = new
|
|
184
|
-
}), this._coins = [], this._portfolio = new
|
|
183
|
+
}), this._portfolio = new S(this._coins), this.emit("balance:portfolio-updated", {});
|
|
184
|
+
}), this._coins = [], this._portfolio = new S(), this.pollingTimer = null, this._updatePromise = null;
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* Gets the current coin objects from the wallet
|
|
@@ -238,7 +238,7 @@ class Ne extends A {
|
|
|
238
238
|
if (a.length !== t.length)
|
|
239
239
|
throw new Error("Recipients and amounts must have the same length");
|
|
240
240
|
await this.waitForUpdate();
|
|
241
|
-
const n = this.portfolio.getBalance(e), c = t.reduce((g,
|
|
241
|
+
const n = this.portfolio.getBalance(e), c = t.reduce((g, h) => g.plus(h), R(0));
|
|
242
242
|
if (n.amount.lt(c))
|
|
243
243
|
throw new Error("Insufficient balance");
|
|
244
244
|
const i = new m();
|
|
@@ -247,8 +247,8 @@ class Ne extends A {
|
|
|
247
247
|
balance: c.toNumber()
|
|
248
248
|
}));
|
|
249
249
|
const u = i.splitCoins(l, t);
|
|
250
|
-
return a.forEach((g,
|
|
251
|
-
i.transferObjects([u[
|
|
250
|
+
return a.forEach((g, h) => {
|
|
251
|
+
i.transferObjects([u[h]], g);
|
|
252
252
|
}), await this.walletClient.signExecuteTransaction({
|
|
253
253
|
transaction: i,
|
|
254
254
|
dryRun: (w = s == null ? void 0 : s.dryRun) != null ? w : !1
|
|
@@ -329,172 +329,172 @@ class Ne extends A {
|
|
|
329
329
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
async function Y(
|
|
333
|
-
var x, k,
|
|
332
|
+
async function Y(o, e, a, t) {
|
|
333
|
+
var x, k, O;
|
|
334
334
|
if (!this.walletClient)
|
|
335
335
|
throw new Error("Wallet client not found");
|
|
336
|
-
await this.walletClient.balance.updatePortfolio();
|
|
337
336
|
const s = await this.getPool(e), n = await this.getPool(a), c = await this.getLendingState(), i = this.walletClient.address, l = (x = t == null ? void 0 : t.protocol) != null ? x : "navi", u = await this.getProtocol(l);
|
|
338
337
|
if (!u)
|
|
339
338
|
throw new Error(`Protocol ${l} not found`);
|
|
340
|
-
const
|
|
339
|
+
const r = await u.getPool(s.coinType);
|
|
341
340
|
if (console.log("migrateBetweenSupplyPTB", {
|
|
342
|
-
fromPoolLending:
|
|
343
|
-
}), l === "navi" &&
|
|
341
|
+
fromPoolLending: r
|
|
342
|
+
}), l === "navi" && r.supplyBalance === 0)
|
|
344
343
|
throw new Error("No supply balance");
|
|
345
|
-
if (t != null && t.amount && t.amount >
|
|
344
|
+
if (t != null && t.amount && t.amount > r.supplyBalance)
|
|
346
345
|
throw new Error("Amount is less than supply balance");
|
|
347
346
|
const w = await K(), g = await Promise.all([s, n]);
|
|
348
347
|
await $(
|
|
349
|
-
|
|
348
|
+
o,
|
|
350
349
|
q(w, {
|
|
351
350
|
lendingState: c,
|
|
352
351
|
pools: g
|
|
353
352
|
})
|
|
354
353
|
);
|
|
355
|
-
const
|
|
354
|
+
const h = await ae(n, {
|
|
356
355
|
env: this.config.env
|
|
357
356
|
});
|
|
358
|
-
if (!
|
|
357
|
+
if (!h)
|
|
359
358
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
360
|
-
const b = (k = t == null ? void 0 : t.slippage) != null ? k : 5e-3, y = (
|
|
359
|
+
const b = (k = t == null ? void 0 : t.slippage) != null ? k : 5e-3, y = (O = t == null ? void 0 : t.amount) != null ? O : Number(r.supplyBalance), d = await this.walletClient.swap.getQuote(
|
|
361
360
|
s.suiCoinType,
|
|
362
361
|
n.suiCoinType,
|
|
363
362
|
y
|
|
364
|
-
),
|
|
365
|
-
if (
|
|
363
|
+
), f = Number(d.amount_out);
|
|
364
|
+
if (f <= 0)
|
|
366
365
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
367
|
-
const C = Math.floor(
|
|
366
|
+
const C = Math.floor(f * (1 - b)), P = Math.floor(C / (1 + h.flashloanFee));
|
|
368
367
|
if (P <= 0)
|
|
369
368
|
throw new Error("The calculated borrow amount must be positive.");
|
|
370
|
-
const [v, E] = await
|
|
369
|
+
const [v, E] = await ne(o, n, P), [F] = o.moveCall({
|
|
371
370
|
target: "0x2::coin::from_balance",
|
|
372
371
|
arguments: [v],
|
|
373
372
|
typeArguments: [n.suiCoinType]
|
|
374
373
|
});
|
|
375
|
-
await N(
|
|
374
|
+
await N(o, n, F, {
|
|
376
375
|
amount: P
|
|
377
376
|
});
|
|
378
|
-
const j = await u.withdrawCoinPTB(
|
|
377
|
+
const j = await u.withdrawCoinPTB(o, s.suiCoinType, y), I = await G(
|
|
379
378
|
i,
|
|
380
|
-
|
|
379
|
+
o,
|
|
381
380
|
C,
|
|
382
381
|
j,
|
|
383
382
|
d
|
|
384
|
-
), U =
|
|
383
|
+
), U = o.moveCall({
|
|
385
384
|
target: "0x2::coin::into_balance",
|
|
386
385
|
arguments: [I],
|
|
387
386
|
typeArguments: [n.suiCoinType]
|
|
388
|
-
}), [M] = await
|
|
387
|
+
}), [M] = await se(o, n, E, U), [W] = o.moveCall({
|
|
389
388
|
target: "0x2::coin::from_balance",
|
|
390
389
|
arguments: [M],
|
|
391
390
|
typeArguments: [n.suiCoinType]
|
|
392
391
|
});
|
|
393
|
-
return await N(
|
|
392
|
+
return await N(o, n, W), o;
|
|
394
393
|
}
|
|
395
|
-
async function Z(
|
|
396
|
-
var
|
|
394
|
+
async function Z(o, e, a, t) {
|
|
395
|
+
var O, H, D;
|
|
397
396
|
if (!this.walletClient)
|
|
398
397
|
throw new Error("Wallet client not found");
|
|
399
|
-
|
|
400
|
-
const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a), i = await this.getLendingState(), l = (S = t == null ? void 0 : t.protocol) != null ? S : "navi", u = await this.getProtocol(l);
|
|
398
|
+
const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a), i = await this.getLendingState(), l = (O = t == null ? void 0 : t.protocol) != null ? O : "navi", u = await this.getProtocol(l);
|
|
401
399
|
if (!u)
|
|
402
400
|
throw new Error(`Protocol ${l} not found`);
|
|
403
|
-
const
|
|
401
|
+
const r = await u.getPool(n.coinType);
|
|
404
402
|
if (console.log("migrateBetweenBorrowPTB", {
|
|
405
|
-
fromPoolLending:
|
|
406
|
-
}),
|
|
403
|
+
fromPoolLending: r
|
|
404
|
+
}), r.borrowBalance === 0)
|
|
407
405
|
throw new Error("No borrow balance");
|
|
408
|
-
if (t != null && t.amount && t.amount >
|
|
406
|
+
if (t != null && t.amount && t.amount > r.borrowBalance)
|
|
409
407
|
throw new Error("Amount is more than borrow balance");
|
|
410
408
|
const w = await K(), g = await Promise.all([n, c]);
|
|
411
409
|
await $(
|
|
412
|
-
|
|
410
|
+
o,
|
|
413
411
|
q(w, {
|
|
414
412
|
lendingState: i,
|
|
415
413
|
pools: g
|
|
416
414
|
})
|
|
417
415
|
);
|
|
418
|
-
let
|
|
419
|
-
if (Number(
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
new R(
|
|
416
|
+
let h = (H = t == null ? void 0 : t.amount) != null ? H : Number(r.borrowBalance);
|
|
417
|
+
if (Number(r.borrowBalance) === h) {
|
|
418
|
+
const de = r.borrowAPR / 100;
|
|
419
|
+
h = Math.ceil(
|
|
420
|
+
new R(h).multipliedBy(de * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-n.token.decimals)).plus(h).toNumber()
|
|
423
421
|
);
|
|
424
422
|
}
|
|
425
|
-
const b = await
|
|
423
|
+
const b = await ae(n, {
|
|
426
424
|
env: this.config.env
|
|
427
425
|
});
|
|
428
426
|
if (!b)
|
|
429
427
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
430
428
|
if (!this.walletClient)
|
|
431
429
|
throw new Error("Wallet client not found");
|
|
432
|
-
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(
|
|
430
|
+
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(h * (1 + b.flashloanFee)), f = d, C = await this.walletClient.swap.getQuote(
|
|
433
431
|
n.suiCoinType,
|
|
434
432
|
c.suiCoinType,
|
|
435
|
-
|
|
433
|
+
f
|
|
436
434
|
);
|
|
437
435
|
let P = 1 + y, v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
438
436
|
c.suiCoinType,
|
|
439
437
|
n.suiCoinType,
|
|
440
438
|
v
|
|
441
439
|
);
|
|
442
|
-
for (; Number(E.amount_out) <
|
|
443
|
-
P = P * Math.max(
|
|
440
|
+
for (; Number(E.amount_out) < f; )
|
|
441
|
+
P = P * Math.max(f / Number(E.amount_out), 1.001), v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
444
442
|
c.suiCoinType,
|
|
445
443
|
n.suiCoinType,
|
|
446
444
|
v
|
|
447
445
|
);
|
|
448
|
-
const [F, j] = await
|
|
446
|
+
const [F, j] = await ne(o, n, h), [I] = o.moveCall({
|
|
449
447
|
target: "0x2::coin::from_balance",
|
|
450
448
|
arguments: [F],
|
|
451
449
|
typeArguments: [n.suiCoinType]
|
|
452
450
|
});
|
|
453
|
-
await u.repayCoinPTB(
|
|
454
|
-
const U = await
|
|
451
|
+
await u.repayCoinPTB(o, n.suiCoinType, I, h);
|
|
452
|
+
const U = await ie(o, c, v), M = await G(
|
|
455
453
|
s,
|
|
456
|
-
|
|
454
|
+
o,
|
|
457
455
|
d,
|
|
458
456
|
U,
|
|
459
457
|
E
|
|
460
|
-
), W =
|
|
458
|
+
), W = o.moveCall({
|
|
461
459
|
target: "0x2::coin::into_balance",
|
|
462
460
|
arguments: [M],
|
|
463
461
|
typeArguments: [n.suiCoinType]
|
|
464
|
-
}), [x] = await
|
|
462
|
+
}), [x] = await se(o, n, j, W), [k] = o.moveCall({
|
|
465
463
|
target: "0x2::coin::from_balance",
|
|
466
464
|
arguments: [x],
|
|
467
465
|
typeArguments: [n.suiCoinType]
|
|
468
466
|
});
|
|
469
|
-
return
|
|
467
|
+
return o.transferObjects([k], s), o;
|
|
470
468
|
}
|
|
471
|
-
async function ee(
|
|
472
|
-
var
|
|
469
|
+
async function ee(o, e, a, t) {
|
|
470
|
+
var w, g;
|
|
473
471
|
if (!this.walletClient)
|
|
474
472
|
throw new Error("Wallet client not found");
|
|
475
|
-
await this.walletClient.
|
|
476
|
-
|
|
477
|
-
|
|
473
|
+
const s = await te(this.walletClient.address, {
|
|
474
|
+
client: this.walletClient.client,
|
|
475
|
+
coinType: e
|
|
476
|
+
}), n = await this.getPool(a), i = new S(s).getBalance(e);
|
|
477
|
+
if (i.amount.eq(0))
|
|
478
478
|
throw new Error(`No balance of ${e}`);
|
|
479
479
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
480
|
-
balance:
|
|
481
|
-
}), t != null && t.amount &&
|
|
480
|
+
balance: i.amount.toNumber()
|
|
481
|
+
}), t != null && t.amount && i.amount.lt(t.amount))
|
|
482
482
|
throw new Error("Amount is greater than balance");
|
|
483
|
-
const
|
|
484
|
-
let
|
|
485
|
-
balance:
|
|
483
|
+
const l = (w = t == null ? void 0 : t.amount) != null ? w : i.amount.toNumber(), u = (g = t == null ? void 0 : t.slippage) != null ? g : 5e-3;
|
|
484
|
+
let r = await B(o, i.coins, {
|
|
485
|
+
balance: l,
|
|
486
486
|
useGasCoin: !0
|
|
487
487
|
});
|
|
488
|
-
if (p(e) !== p(
|
|
489
|
-
const
|
|
490
|
-
|
|
488
|
+
if (p(e) !== p(n.suiCoinType)) {
|
|
489
|
+
const h = await this.walletClient.swap.getQuote(e, n.suiCoinType, l);
|
|
490
|
+
r = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
491
|
+
o,
|
|
492
|
+
h,
|
|
491
493
|
r,
|
|
492
|
-
|
|
493
|
-
l,
|
|
494
|
-
i
|
|
494
|
+
u
|
|
495
495
|
);
|
|
496
496
|
}
|
|
497
|
-
return await N(
|
|
497
|
+
return await N(o, n, r), o;
|
|
498
498
|
}
|
|
499
499
|
class _e {
|
|
500
500
|
constructor(e) {
|
|
@@ -514,13 +514,13 @@ class _e {
|
|
|
514
514
|
throw new Error("Not implemented");
|
|
515
515
|
}
|
|
516
516
|
async withdrawCoinPTB(e, a, t) {
|
|
517
|
-
return
|
|
517
|
+
return le(e, a, t);
|
|
518
518
|
}
|
|
519
519
|
async borrowCoinPTB(e, a, t) {
|
|
520
520
|
throw new Error("Not implemented");
|
|
521
521
|
}
|
|
522
522
|
async repayCoinPTB(e, a, t, s) {
|
|
523
|
-
|
|
523
|
+
re(e, a, t, { amount: s });
|
|
524
524
|
}
|
|
525
525
|
}
|
|
526
526
|
class z {
|
|
@@ -544,21 +544,21 @@ class z {
|
|
|
544
544
|
var b, y;
|
|
545
545
|
const a = p(e), t = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
|
|
546
546
|
t.forEach((d) => {
|
|
547
|
-
s.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((
|
|
548
|
-
|
|
549
|
-
}), d.borrowsPoolRewardManager.poolRewards.forEach((
|
|
550
|
-
|
|
547
|
+
s.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((f) => {
|
|
548
|
+
f && s.add(p(f.coinType.name));
|
|
549
|
+
}), d.borrowsPoolRewardManager.poolRewards.forEach((f) => {
|
|
550
|
+
f && s.add(p(f.coinType.name));
|
|
551
551
|
});
|
|
552
552
|
});
|
|
553
553
|
const n = await Oe(Array.from(s)), i = t.map((d) => Re(d, n)).reduce(
|
|
554
|
-
(d,
|
|
554
|
+
(d, f) => (d[f.coinType] = f, d),
|
|
555
555
|
{}
|
|
556
556
|
), l = await this.suilendClient.getObligation(
|
|
557
557
|
this.obligationOwnerCap.obligationId
|
|
558
|
-
), u = Se(l, i),
|
|
558
|
+
), u = Se(l, i), r = u.deposits.find((d) => d.coinType === a), w = u.borrows.find((d) => d.coinType === a), g = n[a].decimals;
|
|
559
559
|
return {
|
|
560
560
|
cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
|
|
561
|
-
supplyBalance: (b =
|
|
561
|
+
supplyBalance: (b = r == null ? void 0 : r.depositedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? b : 0,
|
|
562
562
|
borrowBalance: (y = w == null ? void 0 : w.borrowedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? y : 0,
|
|
563
563
|
borrowAPR: i[a].borrowAprPercent.toNumber()
|
|
564
564
|
};
|
|
@@ -631,7 +631,7 @@ class Fe extends A {
|
|
|
631
631
|
* @returns Transaction response or dry run response
|
|
632
632
|
*/
|
|
633
633
|
async deposit(e, a, t) {
|
|
634
|
-
var u,
|
|
634
|
+
var u, r, w;
|
|
635
635
|
if (!this.walletClient)
|
|
636
636
|
throw new Error("Wallet client not found");
|
|
637
637
|
const s = await T(e, {
|
|
@@ -651,7 +651,7 @@ class Fe extends A {
|
|
|
651
651
|
transaction: n,
|
|
652
652
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
653
653
|
});
|
|
654
|
-
return !(t != null && t.dryRun) && ((w = (
|
|
654
|
+
return !(t != null && t.dryRun) && ((w = (r = l.effects) == null ? void 0 : r.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:deposit-success", {
|
|
655
655
|
identifier: e,
|
|
656
656
|
amount: a
|
|
657
657
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -665,14 +665,14 @@ class Fe extends A {
|
|
|
665
665
|
* @returns Transaction response or dry run response
|
|
666
666
|
*/
|
|
667
667
|
async withdraw(e, a, t) {
|
|
668
|
-
var l, u,
|
|
668
|
+
var l, u, r;
|
|
669
669
|
if (!this.walletClient)
|
|
670
670
|
throw new Error("Wallet client not found");
|
|
671
671
|
const s = await T(e, {
|
|
672
672
|
env: this.config.env
|
|
673
673
|
}), n = new m();
|
|
674
674
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
675
|
-
const c = await
|
|
675
|
+
const c = await le(n, s, a, {
|
|
676
676
|
env: this.config.env,
|
|
677
677
|
accountCap: t == null ? void 0 : t.accountCap
|
|
678
678
|
});
|
|
@@ -681,7 +681,7 @@ class Fe extends A {
|
|
|
681
681
|
transaction: n,
|
|
682
682
|
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
683
683
|
});
|
|
684
|
-
return !(t != null && t.dryRun) && ((
|
|
684
|
+
return !(t != null && t.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("lending:withdraw-success", {
|
|
685
685
|
identifier: e,
|
|
686
686
|
amount: a
|
|
687
687
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
@@ -695,14 +695,14 @@ class Fe extends A {
|
|
|
695
695
|
* @returns Transaction response or dry run response
|
|
696
696
|
*/
|
|
697
697
|
async borrow(e, a, t) {
|
|
698
|
-
var l, u,
|
|
698
|
+
var l, u, r;
|
|
699
699
|
if (!this.walletClient)
|
|
700
700
|
throw new Error("Wallet client not found");
|
|
701
701
|
const s = await T(e, {
|
|
702
702
|
env: this.config.env
|
|
703
703
|
}), n = new m();
|
|
704
704
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
705
|
-
const c = await
|
|
705
|
+
const c = await ie(n, s, a, {
|
|
706
706
|
env: this.config.env,
|
|
707
707
|
accountCap: t == null ? void 0 : t.accountCap
|
|
708
708
|
});
|
|
@@ -711,7 +711,7 @@ class Fe extends A {
|
|
|
711
711
|
transaction: n,
|
|
712
712
|
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
713
713
|
});
|
|
714
|
-
return !(t != null && t.dryRun) && ((
|
|
714
|
+
return !(t != null && t.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("lending:borrow-success", {
|
|
715
715
|
identifier: e,
|
|
716
716
|
amount: a
|
|
717
717
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
@@ -725,7 +725,7 @@ class Fe extends A {
|
|
|
725
725
|
* @returns Transaction response or dry run response
|
|
726
726
|
*/
|
|
727
727
|
async repay(e, a, t) {
|
|
728
|
-
var u,
|
|
728
|
+
var u, r, w;
|
|
729
729
|
if (!this.walletClient)
|
|
730
730
|
throw new Error("Wallet client not found");
|
|
731
731
|
await this.walletClient.module("balance").waitForUpdate();
|
|
@@ -735,7 +735,7 @@ class Fe extends A {
|
|
|
735
735
|
balance: a,
|
|
736
736
|
useGasCoin: !0
|
|
737
737
|
});
|
|
738
|
-
await
|
|
738
|
+
await re(n, s, i, {
|
|
739
739
|
env: this.config.env,
|
|
740
740
|
amount: a,
|
|
741
741
|
accountCap: t == null ? void 0 : t.accountCap
|
|
@@ -744,7 +744,7 @@ class Fe extends A {
|
|
|
744
744
|
transaction: n,
|
|
745
745
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
746
746
|
});
|
|
747
|
-
return !(t != null && t.dryRun) && ((w = (
|
|
747
|
+
return !(t != null && t.dryRun) && ((w = (r = l.effects) == null ? void 0 : r.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:repay-success", {
|
|
748
748
|
identifier: e,
|
|
749
749
|
amount: a
|
|
750
750
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -774,26 +774,26 @@ class Fe extends A {
|
|
|
774
774
|
* @returns Transaction response or dry run response
|
|
775
775
|
*/
|
|
776
776
|
async liquidate(e, a, t, s, n) {
|
|
777
|
-
var d,
|
|
777
|
+
var d, f, C;
|
|
778
778
|
if (!this.walletClient)
|
|
779
779
|
throw new Error("Wallet client not found");
|
|
780
780
|
const c = await T(e, {
|
|
781
781
|
env: this.config.env
|
|
782
782
|
}), i = await T(t, {
|
|
783
783
|
env: this.config.env
|
|
784
|
-
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType),
|
|
784
|
+
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), r = B(l, u.coins, {
|
|
785
785
|
balance: a,
|
|
786
786
|
useGasCoin: !0
|
|
787
787
|
}), [w, g] = await be(
|
|
788
788
|
l,
|
|
789
789
|
c,
|
|
790
|
-
|
|
790
|
+
r,
|
|
791
791
|
i,
|
|
792
792
|
s,
|
|
793
793
|
{
|
|
794
794
|
env: this.config.env
|
|
795
795
|
}
|
|
796
|
-
), [
|
|
796
|
+
), [h] = l.moveCall({
|
|
797
797
|
target: "0x2::coin::from_balance",
|
|
798
798
|
arguments: [w],
|
|
799
799
|
typeArguments: [i.suiCoinType]
|
|
@@ -802,12 +802,12 @@ class Fe extends A {
|
|
|
802
802
|
arguments: [g],
|
|
803
803
|
typeArguments: [c.suiCoinType]
|
|
804
804
|
});
|
|
805
|
-
l.transferObjects([
|
|
805
|
+
l.transferObjects([h, b], this.walletClient.address);
|
|
806
806
|
const y = await this.walletClient.signExecuteTransaction({
|
|
807
807
|
transaction: l,
|
|
808
808
|
dryRun: (d = n == null ? void 0 : n.dryRun) != null ? d : !1
|
|
809
809
|
});
|
|
810
|
-
return !(n != null && n.dryRun) && ((C = (
|
|
810
|
+
return !(n != null && n.dryRun) && ((C = (f = y.effects) == null ? void 0 : f.status) == null ? void 0 : C.status) === "success" && (this.emit("lending:liquidate-success", {
|
|
811
811
|
payIdentifier: e,
|
|
812
812
|
payAmount: a,
|
|
813
813
|
collateralIdentifier: t,
|
|
@@ -952,7 +952,7 @@ class je extends A {
|
|
|
952
952
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
953
953
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
954
954
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
955
|
-
}, this.getStats =
|
|
955
|
+
}, this.getStats = oe(
|
|
956
956
|
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
957
957
|
);
|
|
958
958
|
}
|
|
@@ -1005,7 +1005,7 @@ class je extends A {
|
|
|
1005
1005
|
* @throws Error if wallet client not found or stake amount is too low
|
|
1006
1006
|
*/
|
|
1007
1007
|
async stake(e, a) {
|
|
1008
|
-
var l, u,
|
|
1008
|
+
var l, u, r;
|
|
1009
1009
|
if (!this.walletClient)
|
|
1010
1010
|
throw new Error("Wallet client not found");
|
|
1011
1011
|
if (e < 1e9)
|
|
@@ -1021,7 +1021,7 @@ class je extends A {
|
|
|
1021
1021
|
transaction: t,
|
|
1022
1022
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1023
1023
|
});
|
|
1024
|
-
return !(a != null && a.dryRun) && ((
|
|
1024
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("volo:stake-success", {
|
|
1025
1025
|
suiAmount: e
|
|
1026
1026
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1027
1027
|
}
|
|
@@ -1034,7 +1034,7 @@ class je extends A {
|
|
|
1034
1034
|
* @throws Error if wallet client not found or unstake amount is too low
|
|
1035
1035
|
*/
|
|
1036
1036
|
async unstake(e, a) {
|
|
1037
|
-
var l, u,
|
|
1037
|
+
var l, u, r;
|
|
1038
1038
|
if (!this.walletClient)
|
|
1039
1039
|
throw new Error("Wallet client not found");
|
|
1040
1040
|
if (e < 1e9)
|
|
@@ -1048,7 +1048,7 @@ class je extends A {
|
|
|
1048
1048
|
transaction: t,
|
|
1049
1049
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1050
1050
|
});
|
|
1051
|
-
return !(a != null && a.dryRun) && ((
|
|
1051
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("volo:unstake-success", {
|
|
1052
1052
|
vSuiAmount: e
|
|
1053
1053
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1054
1054
|
}
|
|
@@ -1136,30 +1136,30 @@ class Ie extends A {
|
|
|
1136
1136
|
* @returns Transaction response or dry run response
|
|
1137
1137
|
*/
|
|
1138
1138
|
async swap(e, a, t, s, n) {
|
|
1139
|
-
var y, d,
|
|
1139
|
+
var y, d, f;
|
|
1140
1140
|
if (!this.walletClient)
|
|
1141
1141
|
throw new Error("Wallet client not found");
|
|
1142
1142
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1143
1143
|
const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l = B(i, c.coins, {
|
|
1144
1144
|
balance: t,
|
|
1145
1145
|
useGasCoin: !0
|
|
1146
|
-
}), u = await this.getQuote(e, a, t),
|
|
1147
|
-
if (i.transferObjects([
|
|
1146
|
+
}), u = await this.getQuote(e, a, t), r = await this.buildSwapPTBFromQuote(i, u, l, s);
|
|
1147
|
+
if (i.transferObjects([r], this.walletClient.address), i.setSender(this.walletClient.address), n != null && n.dryRun)
|
|
1148
1148
|
return await this.walletClient.signExecuteTransaction({
|
|
1149
1149
|
transaction: i,
|
|
1150
1150
|
dryRun: !0
|
|
1151
1151
|
});
|
|
1152
1152
|
const w = await i.build({
|
|
1153
1153
|
client: this.walletClient.client
|
|
1154
|
-
}), g = await this.walletClient.signer.signTransaction(w),
|
|
1154
|
+
}), g = await this.walletClient.signer.signTransaction(w), h = [g.signature];
|
|
1155
1155
|
try {
|
|
1156
|
-
await xe(g.bytes,
|
|
1156
|
+
await xe(g.bytes, h);
|
|
1157
1157
|
} catch (C) {
|
|
1158
1158
|
console.error(C);
|
|
1159
1159
|
}
|
|
1160
1160
|
const b = await this.walletClient.client.executeTransactionBlock({
|
|
1161
1161
|
transactionBlock: g.bytes,
|
|
1162
|
-
signature:
|
|
1162
|
+
signature: h,
|
|
1163
1163
|
options: {
|
|
1164
1164
|
showEffects: !0,
|
|
1165
1165
|
showEvents: !0,
|
|
@@ -1167,7 +1167,7 @@ class Ie extends A {
|
|
|
1167
1167
|
}
|
|
1168
1168
|
});
|
|
1169
1169
|
if (((d = (y = b.effects) == null ? void 0 : y.status) == null ? void 0 : d.status) === "success") {
|
|
1170
|
-
const C = (
|
|
1170
|
+
const C = (f = b.events) == null ? void 0 : f.find((P) => P.type.includes("::slippage::SwapEvent"));
|
|
1171
1171
|
C && this.emit("swap:swap-success", {
|
|
1172
1172
|
fromCoinType: e,
|
|
1173
1173
|
toCoinType: a,
|
|
@@ -1185,7 +1185,7 @@ class Ue extends A {
|
|
|
1185
1185
|
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
1186
1186
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1187
1187
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1188
|
-
}, this.getApy =
|
|
1188
|
+
}, this.getApy = oe(
|
|
1189
1189
|
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
1190
1190
|
);
|
|
1191
1191
|
}
|
|
@@ -1235,7 +1235,7 @@ class Ue extends A {
|
|
|
1235
1235
|
* @param options Optional dry run
|
|
1236
1236
|
*/
|
|
1237
1237
|
async stake(e, a) {
|
|
1238
|
-
var l, u,
|
|
1238
|
+
var l, u, r;
|
|
1239
1239
|
if (!this.walletClient)
|
|
1240
1240
|
throw new Error("Wallet client not found");
|
|
1241
1241
|
const t = new m();
|
|
@@ -1249,7 +1249,7 @@ class Ue extends A {
|
|
|
1249
1249
|
transaction: t,
|
|
1250
1250
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1251
1251
|
});
|
|
1252
|
-
return !(a != null && a.dryRun) && ((
|
|
1252
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1253
1253
|
}
|
|
1254
1254
|
/**
|
|
1255
1255
|
* Unstake haSUI for SUI
|
|
@@ -1258,7 +1258,7 @@ class Ue extends A {
|
|
|
1258
1258
|
* @param options Optional dry run
|
|
1259
1259
|
*/
|
|
1260
1260
|
async unstake(e, a) {
|
|
1261
|
-
var l, u,
|
|
1261
|
+
var l, u, r;
|
|
1262
1262
|
if (!this.walletClient)
|
|
1263
1263
|
throw new Error("Wallet client not found");
|
|
1264
1264
|
await this.walletClient.module("balance").waitForUpdate();
|
|
@@ -1270,7 +1270,7 @@ class Ue extends A {
|
|
|
1270
1270
|
transaction: t,
|
|
1271
1271
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1272
1272
|
});
|
|
1273
|
-
return !(a != null && a.dryRun) && ((
|
|
1273
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1274
1274
|
}
|
|
1275
1275
|
}
|
|
1276
1276
|
const Me = {
|
|
@@ -1285,7 +1285,7 @@ const Me = {
|
|
|
1285
1285
|
/** Haedal protocol module */
|
|
1286
1286
|
haedal: new Ue()
|
|
1287
1287
|
}, We = {
|
|
1288
|
-
url:
|
|
1288
|
+
url: we("mainnet")
|
|
1289
1289
|
};
|
|
1290
1290
|
class Ye {
|
|
1291
1291
|
/**
|
|
@@ -1293,12 +1293,12 @@ class Ye {
|
|
|
1293
1293
|
* @param options - Configuration options for the wallet client
|
|
1294
1294
|
*/
|
|
1295
1295
|
constructor(e) {
|
|
1296
|
-
this.modules = Me, this.userConfigs = {}, this.events =
|
|
1296
|
+
this.modules = Me, this.userConfigs = {}, this.events = fe();
|
|
1297
1297
|
const a = {
|
|
1298
1298
|
...We,
|
|
1299
1299
|
...e.client
|
|
1300
1300
|
};
|
|
1301
|
-
a.transport = a.transport || new ke(a.url), this.client = new
|
|
1301
|
+
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]) => {
|
|
1302
1302
|
if (t !== s.name)
|
|
1303
1303
|
throw new Error(`Module name ${t} does not match module name ${s.name}`);
|
|
1304
1304
|
s.install(this);
|
|
@@ -1374,7 +1374,7 @@ class Ye {
|
|
|
1374
1374
|
return e in this.modules;
|
|
1375
1375
|
}
|
|
1376
1376
|
}
|
|
1377
|
-
class Ze extends
|
|
1377
|
+
class Ze extends ce {
|
|
1378
1378
|
/**
|
|
1379
1379
|
* Creates a new watch-only signer
|
|
1380
1380
|
*
|
|
@@ -1438,7 +1438,7 @@ class Ze extends oe {
|
|
|
1438
1438
|
return {};
|
|
1439
1439
|
}
|
|
1440
1440
|
}
|
|
1441
|
-
class et extends
|
|
1441
|
+
class et extends ce {
|
|
1442
1442
|
/**
|
|
1443
1443
|
* Creates a new watch-only signer
|
|
1444
1444
|
*
|