@naviprotocol/wallet-client 1.3.2-dev.7 → 1.3.3

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,11 +1,11 @@
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 L, getCoins as te, mergeCoinsPTB as P, getPriceFeeds as Q, updateOraclePricesPTB as K, filterPriceFeeds as $, 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
- import R, { BigNumber as W } from "bignumber.js";
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
+ 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";
8
- import { buildSwapPTBFromQuote as q, generateRefId as Te, getQuote as ve } from "@naviprotocol/astros-aggregator-sdk";
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
10
  import { getCoinMetadataMap as Oe, MAX_U64 as Ae } from "@suilend/sui-fe";
11
11
  import { executeAuction as xe } from "shio-sdk";
@@ -64,7 +64,7 @@ class ke {
64
64
  throw new Error("subscribe not implemented.");
65
65
  }
66
66
  }
67
- class O {
67
+ class A {
68
68
  /**
69
69
  * Gets the current configuration for this module
70
70
  *
@@ -119,13 +119,13 @@ class S {
119
119
  else {
120
120
  const a = {};
121
121
  e == null || e.forEach((t) => {
122
- const n = p(t.coinType);
123
- let s = a[n];
124
- s || (s = {
125
- coinType: n,
126
- amount: W(0),
122
+ const s = p(t.coinType);
123
+ let n = a[s];
124
+ n || (n = {
125
+ coinType: s,
126
+ amount: L(0),
127
127
  coins: []
128
- }, a[n] = s), s.coins.push(t), s.amount = s.amount.plus(t.balance);
128
+ }, a[s] = n), n.coins.push(t), n.amount = n.amount.plus(t.balance);
129
129
  }), this.balances = a;
130
130
  }
131
131
  }
@@ -136,7 +136,7 @@ class S {
136
136
  * @returns UserCoinBalance object with coin type, total amount, and coin objects
137
137
  */
138
138
  getBalance(e) {
139
- return e = p(e), this.balances[e] || { coinType: e, amount: W(0), coins: [] };
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
@@ -155,7 +155,7 @@ class S {
155
155
  balanceOf(e) {
156
156
  e = p(e);
157
157
  const a = this.getBalance(e);
158
- return (a == null ? void 0 : a.amount) || W(0);
158
+ return (a == null ? void 0 : a.amount) || L(0);
159
159
  }
160
160
  /**
161
161
  * Creates a deep copy of the portfolio
@@ -170,12 +170,12 @@ class S {
170
170
  return a.balances = e, a;
171
171
  }
172
172
  }
173
- class Ne extends O {
173
+ class Ne extends A {
174
174
  constructor() {
175
175
  super(...arguments), this.name = "balance", this.defaultConfig = {
176
176
  coinPollingInterval: 6e3,
177
177
  disableCoinPolling: !1
178
- }, this.updatePortfolio = L(async () => {
178
+ }, this.updatePortfolio = Q(async () => {
179
179
  if (!this.walletClient)
180
180
  throw new Error("Wallet client not found");
181
181
  this._coins = await te(this.walletClient.address, {
@@ -219,8 +219,8 @@ class Ne extends O {
219
219
  * @param options - Optional parameters including dry run mode
220
220
  * @returns Transaction response or dry run response
221
221
  */
222
- async sendCoin(e, a, t, n) {
223
- return this.sendCoinBatch(e, [a], [t], n);
222
+ async sendCoin(e, a, t, s) {
223
+ return this.sendCoinBatch(e, [a], [t], s);
224
224
  }
225
225
  /**
226
226
  * Sends coins to multiple recipients in a single transaction
@@ -231,19 +231,19 @@ class Ne extends O {
231
231
  * @param options - Optional parameters including dry run mode
232
232
  * @returns Transaction response or dry run response
233
233
  */
234
- async sendCoinBatch(e, a, t, n) {
234
+ async sendCoinBatch(e, a, t, s) {
235
235
  var w;
236
236
  if (!this.walletClient)
237
237
  throw new Error("Wallet client not found");
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 s = this.portfolio.getBalance(e), c = t.reduce((g, h) => g.plus(h), R(0));
242
- if (s.amount.lt(c))
241
+ const n = this.portfolio.getBalance(e), c = t.reduce((g, h) => g.plus(h), R(0));
242
+ if (n.amount.lt(c))
243
243
  throw new Error("Insufficient balance");
244
244
  const i = new m();
245
245
  let l = i.gas;
246
- p(e) !== p("0x2::sui::SUI") && (l = P(i, s.coins, {
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[h]], g);
252
252
  }), await this.walletClient.signExecuteTransaction({
253
253
  transaction: i,
254
- dryRun: (w = n == null ? void 0 : n.dryRun) != null ? w : !1
254
+ dryRun: (w = s == null ? void 0 : s.dryRun) != null ? w : !1
255
255
  });
256
256
  }
257
257
  /**
@@ -283,11 +283,11 @@ class Ne extends O {
283
283
  if (e.length !== a.length)
284
284
  throw new Error("Objects and recipients must have the same length");
285
285
  await this.waitForUpdate();
286
- const n = new m();
286
+ const s = new m();
287
287
  return e.forEach((i, l) => {
288
- n.transferObjects([n.object(i)], a[l]);
288
+ s.transferObjects([s.object(i)], a[l]);
289
289
  }), await this.walletClient.signExecuteTransaction({
290
- transaction: n,
290
+ transaction: s,
291
291
  dryRun: (c = t == null ? void 0 : t.dryRun) != null ? c : !1
292
292
  });
293
293
  }
@@ -330,84 +330,85 @@ class Ne extends O {
330
330
  }
331
331
  }
332
332
  async function Y(o, e, a, t) {
333
- var A, x, k;
333
+ var x, k, O;
334
334
  if (!this.walletClient)
335
335
  throw new Error("Wallet client not found");
336
- const n = await this.getPool(a), s = await this.getLendingState(), c = this.walletClient.address, i = (A = t == null ? void 0 : t.protocol) != null ? A : "navi";
337
- let l;
338
- i === "navi" && (l = await this.getPool(e));
339
- const u = await this.getProtocol(i);
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);
340
337
  if (!u)
341
- throw new Error(`Protocol ${i} not found`);
342
- const r = await u.getPool(e.toString());
338
+ throw new Error(`Protocol ${l} not found`);
339
+ const r = await u.getPool(s.coinType);
343
340
  if (console.log("migrateBetweenSupplyPTB", {
344
341
  fromPoolLending: r
345
- }), i === "navi" && r.supplyBalance === 0)
342
+ }), l === "navi" && r.supplyBalance === 0)
346
343
  throw new Error("No supply balance");
347
344
  if (t != null && t.amount && t.amount > r.supplyBalance)
348
345
  throw new Error("Amount is less than supply balance");
349
- const w = await Q();
350
- await K(
346
+ const w = await K(), g = await Promise.all([s, n]);
347
+ await $(
351
348
  o,
352
- $(w, {
353
- lendingState: s,
354
- pools: l ? [l, n] : [n]
349
+ q(w, {
350
+ lendingState: c,
351
+ pools: g
355
352
  })
356
353
  );
357
- const g = await ae(n, {
354
+ const h = await ae(n, {
358
355
  env: this.config.env
359
356
  });
360
- if (!g)
357
+ if (!h)
361
358
  throw new Error(`${n.token.symbol} pool not support flashloan`);
362
- const h = (x = t == null ? void 0 : t.slippage) != null ? x : 5e-3, b = (k = t == null ? void 0 : t.amount) != null ? k : Number(r.supplyBalance), y = await this.walletClient.swap.getQuote(e, n.suiCoinType, b), d = Number(y.amount_out);
363
- if (d <= 0)
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(
360
+ s.suiCoinType,
361
+ n.suiCoinType,
362
+ y
363
+ ), f = Number(d.amount_out);
364
+ if (f <= 0)
364
365
  throw new Error("The amount of swapAmountOut must be greater than 0.");
365
- const f = Math.floor(d * (1 - h)), C = Math.floor(f / (1 + g.flashloanFee));
366
- if (C <= 0)
366
+ const C = Math.floor(f * (1 - b)), P = Math.floor(C / (1 + h.flashloanFee));
367
+ if (P <= 0)
367
368
  throw new Error("The calculated borrow amount must be positive.");
368
- const [B, v] = await ne(o, n, C), [E] = o.moveCall({
369
+ const [v, E] = await ne(o, n, P), [F] = o.moveCall({
369
370
  target: "0x2::coin::from_balance",
370
- arguments: [B],
371
+ arguments: [v],
371
372
  typeArguments: [n.suiCoinType]
372
373
  });
373
- await N(o, n, E, {
374
- amount: C
374
+ await N(o, n, F, {
375
+ amount: P
375
376
  });
376
- const F = await u.withdrawCoinPTB(o, e, b), j = await q(
377
- c,
377
+ const j = await u.withdrawCoinPTB(o, s.suiCoinType, y), I = await G(
378
+ i,
378
379
  o,
379
- f,
380
- F,
381
- y
382
- ), I = o.moveCall({
380
+ C,
381
+ j,
382
+ d
383
+ ), U = o.moveCall({
383
384
  target: "0x2::coin::into_balance",
384
- arguments: [j],
385
+ arguments: [I],
385
386
  typeArguments: [n.suiCoinType]
386
- }), [U] = await se(o, n, v, I), [M] = o.moveCall({
387
+ }), [M] = await se(o, n, E, U), [W] = o.moveCall({
387
388
  target: "0x2::coin::from_balance",
388
- arguments: [U],
389
+ arguments: [M],
389
390
  typeArguments: [n.suiCoinType]
390
391
  });
391
- return await N(o, n, M), o;
392
+ return await N(o, n, W), o;
392
393
  }
393
394
  async function Z(o, e, a, t) {
394
- var z, H, D;
395
+ var O, H, D;
395
396
  if (!this.walletClient)
396
397
  throw new Error("Wallet client not found");
397
- const n = this.walletClient.address, s = await this.getPool(e), c = await this.getPool(a), i = await this.getLendingState(), l = (z = t == null ? void 0 : t.protocol) != null ? z : "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);
398
399
  if (!u)
399
400
  throw new Error(`Protocol ${l} not found`);
400
- const r = await u.getPool(s.coinType);
401
+ const r = await u.getPool(n.coinType);
401
402
  if (console.log("migrateBetweenBorrowPTB", {
402
403
  fromPoolLending: r
403
404
  }), r.borrowBalance === 0)
404
405
  throw new Error("No borrow balance");
405
406
  if (t != null && t.amount && t.amount > r.borrowBalance)
406
407
  throw new Error("Amount is more than borrow balance");
407
- const w = await Q(), g = await Promise.all([s, c]);
408
- await K(
408
+ const w = await K(), g = await Promise.all([n, c]);
409
+ await $(
409
410
  o,
410
- $(w, {
411
+ q(w, {
411
412
  lendingState: i,
412
413
  pools: g
413
414
  })
@@ -416,63 +417,63 @@ async function Z(o, e, a, t) {
416
417
  if (Number(r.borrowBalance) === h) {
417
418
  const de = r.borrowAPR / 100;
418
419
  h = Math.ceil(
419
- new R(h).multipliedBy(de * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-s.token.decimals)).plus(h).toNumber()
420
+ new R(h).multipliedBy(de * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-n.token.decimals)).plus(h).toNumber()
420
421
  );
421
422
  }
422
- const b = await ae(s, {
423
+ const b = await ae(n, {
423
424
  env: this.config.env
424
425
  });
425
426
  if (!b)
426
- throw new Error(`${s.token.symbol} pool not support flashloan`);
427
+ throw new Error(`${n.token.symbol} pool not support flashloan`);
427
428
  if (!this.walletClient)
428
429
  throw new Error("Wallet client not found");
429
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(
430
- s.suiCoinType,
431
+ n.suiCoinType,
431
432
  c.suiCoinType,
432
433
  f
433
434
  );
434
- let B = 1 + y, v = Math.ceil(Number(C.amount_out) * B), E = await this.walletClient.swap.getQuote(
435
+ let P = 1 + y, v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
435
436
  c.suiCoinType,
436
- s.suiCoinType,
437
+ n.suiCoinType,
437
438
  v
438
439
  );
439
440
  for (; Number(E.amount_out) < f; )
440
- B = B * Math.max(f / Number(E.amount_out), 1.001), v = Math.ceil(Number(C.amount_out) * B), E = await this.walletClient.swap.getQuote(
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(
441
442
  c.suiCoinType,
442
- s.suiCoinType,
443
+ n.suiCoinType,
443
444
  v
444
445
  );
445
- const [F, j] = await ne(o, s, h), [I] = o.moveCall({
446
+ const [F, j] = await ne(o, n, h), [I] = o.moveCall({
446
447
  target: "0x2::coin::from_balance",
447
448
  arguments: [F],
448
- typeArguments: [s.suiCoinType]
449
+ typeArguments: [n.suiCoinType]
449
450
  });
450
- await u.repayCoinPTB(o, s.suiCoinType, I, h);
451
- const U = await ie(o, c, v), M = await q(
452
- n,
451
+ await u.repayCoinPTB(o, n.suiCoinType, I, h);
452
+ const U = await ie(o, c, v), M = await G(
453
+ s,
453
454
  o,
454
455
  d,
455
456
  U,
456
457
  E
457
- ), A = o.moveCall({
458
+ ), W = o.moveCall({
458
459
  target: "0x2::coin::into_balance",
459
460
  arguments: [M],
460
- typeArguments: [s.suiCoinType]
461
- }), [x] = await se(o, s, j, A), [k] = o.moveCall({
461
+ typeArguments: [n.suiCoinType]
462
+ }), [x] = await se(o, n, j, W), [k] = o.moveCall({
462
463
  target: "0x2::coin::from_balance",
463
464
  arguments: [x],
464
- typeArguments: [s.suiCoinType]
465
+ typeArguments: [n.suiCoinType]
465
466
  });
466
- return o.transferObjects([k], n), o;
467
+ return o.transferObjects([k], s), o;
467
468
  }
468
469
  async function ee(o, e, a, t) {
469
470
  var w, g;
470
471
  if (!this.walletClient)
471
472
  throw new Error("Wallet client not found");
472
- const n = await te(this.walletClient.address, {
473
+ const s = await te(this.walletClient.address, {
473
474
  client: this.walletClient.client,
474
475
  coinType: e
475
- }), s = await this.getPool(a), i = new S(n).getBalance(e);
476
+ }), n = await this.getPool(a), i = new S(s).getBalance(e);
476
477
  if (i.amount.eq(0))
477
478
  throw new Error(`No balance of ${e}`);
478
479
  if (console.log("migrateBalanceToSupplyPTB", {
@@ -480,12 +481,12 @@ async function ee(o, e, a, t) {
480
481
  }), t != null && t.amount && i.amount.lt(t.amount))
481
482
  throw new Error("Amount is greater than balance");
482
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;
483
- let r = await P(o, i.coins, {
484
+ let r = await B(o, i.coins, {
484
485
  balance: l,
485
486
  useGasCoin: !0
486
487
  });
487
- if (p(e) !== p(s.suiCoinType)) {
488
- const h = await this.walletClient.swap.getQuote(e, s.suiCoinType, l);
488
+ if (p(e) !== p(n.suiCoinType)) {
489
+ const h = await this.walletClient.swap.getQuote(e, n.suiCoinType, l);
489
490
  r = await this.walletClient.swap.buildSwapPTBFromQuote(
490
491
  o,
491
492
  h,
@@ -493,23 +494,23 @@ async function ee(o, e, a, t) {
493
494
  u
494
495
  );
495
496
  }
496
- return await N(o, s, r), o;
497
+ return await N(o, n, r), o;
497
498
  }
498
499
  class _e {
499
500
  constructor(e) {
500
501
  this.name = "navi", this.walletClient = e;
501
502
  }
502
503
  async getPool(e) {
503
- const a = await this.walletClient.lending.getPool(e), n = (await this.walletClient.lending.getLendingState()).find(
504
+ const a = await this.walletClient.lending.getPool(e), s = (await this.walletClient.lending.getLendingState()).find(
504
505
  (i) => i.pool.suiCoinType === p(e)
505
- ), s = n ? new R(n.supplyBalance).toNumber() : 0, c = n ? new R(n.borrowBalance).toNumber() : 0;
506
+ ), n = s ? new R(s.supplyBalance).toNumber() : 0, c = s ? new R(s.borrowBalance).toNumber() : 0;
506
507
  return {
507
- supplyBalance: s,
508
+ supplyBalance: n,
508
509
  borrowBalance: c,
509
510
  borrowAPR: parseFloat(a.borrowIncentiveApyInfo.apy)
510
511
  };
511
512
  }
512
- async depositCoinPTB(e, a, t, n) {
513
+ async depositCoinPTB(e, a, t, s) {
513
514
  throw new Error("Not implemented");
514
515
  }
515
516
  async withdrawCoinPTB(e, a, t) {
@@ -518,11 +519,11 @@ class _e {
518
519
  async borrowCoinPTB(e, a, t) {
519
520
  throw new Error("Not implemented");
520
521
  }
521
- async repayCoinPTB(e, a, t, n) {
522
- re(e, a, t, { amount: n });
522
+ async repayCoinPTB(e, a, t, s) {
523
+ re(e, a, t, { amount: s });
523
524
  }
524
525
  }
525
- class G {
526
+ class z {
526
527
  constructor(e, a, t) {
527
528
  this.name = "suilend", this.walletClient = e, this.obligationOwnerCap = a, this.suilendClient = t;
528
529
  }
@@ -537,24 +538,24 @@ class G {
537
538
  ]);
538
539
  if (t.length === 0)
539
540
  throw new Error("No existing obligations found for wallet address: " + e.address);
540
- return new G(e, t[0], a);
541
+ return new z(e, t[0], a);
541
542
  }
542
543
  async getPool(e) {
543
544
  var b, y;
544
- const a = p(e), t = this.suilendClient.lendingMarket.reserves, n = /* @__PURE__ */ new Set();
545
+ const a = p(e), t = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
545
546
  t.forEach((d) => {
546
- n.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((f) => {
547
- f && n.add(p(f.coinType.name));
547
+ s.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((f) => {
548
+ f && s.add(p(f.coinType.name));
548
549
  }), d.borrowsPoolRewardManager.poolRewards.forEach((f) => {
549
- f && n.add(p(f.coinType.name));
550
+ f && s.add(p(f.coinType.name));
550
551
  });
551
552
  });
552
- const s = await Oe(Array.from(n)), i = t.map((d) => Re(d, s)).reduce(
553
+ const n = await Oe(Array.from(s)), i = t.map((d) => Re(d, n)).reduce(
553
554
  (d, f) => (d[f.coinType] = f, d),
554
555
  {}
555
556
  ), l = await this.suilendClient.getObligation(
556
557
  this.obligationOwnerCap.obligationId
557
- ), u = Se(l, i), r = u.deposits.find((d) => d.coinType === a), w = u.borrows.find((d) => d.coinType === a), g = s[a].decimals;
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;
558
559
  return {
559
560
  cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
560
561
  supplyBalance: (b = r == null ? void 0 : r.depositedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? b : 0,
@@ -562,27 +563,27 @@ class G {
562
563
  borrowAPR: i[a].borrowAprPercent.toNumber()
563
564
  };
564
565
  }
565
- async depositCoinPTB(e, a, t, n) {
566
+ async depositCoinPTB(e, a, t, s) {
566
567
  throw new Error("Not implemented");
567
568
  }
568
569
  async withdrawCoinPTB(e, a, t) {
569
- const n = await this.getPool(a), s = t === n.supplyBalance;
570
+ const s = await this.getPool(a), n = t === s.supplyBalance;
570
571
  return await this.suilendClient.withdraw(
571
572
  this.obligationOwnerCap.id,
572
573
  this.obligationOwnerCap.obligationId,
573
574
  a,
574
- s ? Ae.toString() : Math.ceil(t / n.cTokenExchangeRate).toString(),
575
+ n ? Ae.toString() : Math.ceil(t / s.cTokenExchangeRate).toString(),
575
576
  e
576
577
  );
577
578
  }
578
579
  async borrowCoinPTB(e, a, t) {
579
580
  throw new Error("Not implemented");
580
581
  }
581
- async repayCoinPTB(e, a, t, n) {
582
+ async repayCoinPTB(e, a, t, s) {
582
583
  this.suilendClient.repay(this.obligationOwnerCap.obligationId, a, t, e), e.transferObjects([t], e.pure.address(this.walletClient.address));
583
584
  }
584
585
  }
585
- class Fe extends O {
586
+ class Fe extends A {
586
587
  constructor() {
587
588
  super(), this.name = "lending", this.defaultConfig = {
588
589
  env: "prod",
@@ -633,21 +634,21 @@ class Fe extends O {
633
634
  var u, r, w;
634
635
  if (!this.walletClient)
635
636
  throw new Error("Wallet client not found");
636
- const n = await T(e, {
637
+ const s = await T(e, {
637
638
  env: this.config.env
638
639
  });
639
640
  await this.walletClient.module("balance").waitForUpdate();
640
- const s = new m(), c = this.walletClient.module("balance").portfolio.getBalance(n.suiCoinType), i = P(s, c.coins, {
641
+ const n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
641
642
  balance: a,
642
643
  useGasCoin: !0
643
644
  });
644
- await N(s, n, i, {
645
+ await N(n, s, i, {
645
646
  env: this.config.env,
646
647
  amount: a,
647
648
  accountCap: t == null ? void 0 : t.accountCap
648
649
  });
649
650
  const l = await this.walletClient.signExecuteTransaction({
650
- transaction: s,
651
+ transaction: n,
651
652
  dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
652
653
  });
653
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", {
@@ -667,17 +668,17 @@ class Fe extends O {
667
668
  var l, u, r;
668
669
  if (!this.walletClient)
669
670
  throw new Error("Wallet client not found");
670
- const n = await T(e, {
671
+ const s = await T(e, {
671
672
  env: this.config.env
672
- }), s = new m();
673
- t != null && t.disableUpdateOracle || await this.updateOraclePTB(s, [n]);
674
- const c = await le(s, n, a, {
673
+ }), n = new m();
674
+ t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
675
+ const c = await le(n, s, a, {
675
676
  env: this.config.env,
676
677
  accountCap: t == null ? void 0 : t.accountCap
677
678
  });
678
- s.transferObjects([c], this.walletClient.address);
679
+ n.transferObjects([c], this.walletClient.address);
679
680
  const i = await this.walletClient.signExecuteTransaction({
680
- transaction: s,
681
+ transaction: n,
681
682
  dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
682
683
  });
683
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", {
@@ -697,17 +698,17 @@ class Fe extends O {
697
698
  var l, u, r;
698
699
  if (!this.walletClient)
699
700
  throw new Error("Wallet client not found");
700
- const n = await T(e, {
701
+ const s = await T(e, {
701
702
  env: this.config.env
702
- }), s = new m();
703
- t != null && t.disableUpdateOracle || await this.updateOraclePTB(s, [n]);
704
- const c = await ie(s, n, a, {
703
+ }), n = new m();
704
+ t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
705
+ const c = await ie(n, s, a, {
705
706
  env: this.config.env,
706
707
  accountCap: t == null ? void 0 : t.accountCap
707
708
  });
708
- s.transferObjects([c], this.walletClient.address);
709
+ n.transferObjects([c], this.walletClient.address);
709
710
  const i = await this.walletClient.signExecuteTransaction({
710
- transaction: s,
711
+ transaction: n,
711
712
  dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
712
713
  });
713
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", {
@@ -728,19 +729,19 @@ class Fe extends O {
728
729
  if (!this.walletClient)
729
730
  throw new Error("Wallet client not found");
730
731
  await this.walletClient.module("balance").waitForUpdate();
731
- const n = await T(e, {
732
+ const s = await T(e, {
732
733
  env: this.config.env
733
- }), s = new m(), c = this.walletClient.module("balance").portfolio.getBalance(n.suiCoinType), i = P(s, c.coins, {
734
+ }), n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
734
735
  balance: a,
735
736
  useGasCoin: !0
736
737
  });
737
- await re(s, n, i, {
738
+ await re(n, s, i, {
738
739
  env: this.config.env,
739
740
  amount: a,
740
741
  accountCap: t == null ? void 0 : t.accountCap
741
742
  });
742
743
  const l = await this.walletClient.signExecuteTransaction({
743
- transaction: s,
744
+ transaction: n,
744
745
  dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
745
746
  });
746
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", {
@@ -772,7 +773,7 @@ class Fe extends O {
772
773
  * @param options - Optional parameters including dry run mode
773
774
  * @returns Transaction response or dry run response
774
775
  */
775
- async liquidate(e, a, t, n, s) {
776
+ async liquidate(e, a, t, s, n) {
776
777
  var d, f, C;
777
778
  if (!this.walletClient)
778
779
  throw new Error("Wallet client not found");
@@ -780,7 +781,7 @@ class Fe extends O {
780
781
  env: this.config.env
781
782
  }), i = await T(t, {
782
783
  env: this.config.env
783
- }), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), r = P(l, u.coins, {
784
+ }), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), r = B(l, u.coins, {
784
785
  balance: a,
785
786
  useGasCoin: !0
786
787
  }), [w, g] = await be(
@@ -788,7 +789,7 @@ class Fe extends O {
788
789
  c,
789
790
  r,
790
791
  i,
791
- n,
792
+ s,
792
793
  {
793
794
  env: this.config.env
794
795
  }
@@ -804,13 +805,13 @@ class Fe extends O {
804
805
  l.transferObjects([h, b], this.walletClient.address);
805
806
  const y = await this.walletClient.signExecuteTransaction({
806
807
  transaction: l,
807
- dryRun: (d = s == null ? void 0 : s.dryRun) != null ? d : !1
808
+ dryRun: (d = n == null ? void 0 : n.dryRun) != null ? d : !1
808
809
  });
809
- return !(s != null && s.dryRun) && ((C = (f = y.effects) == null ? void 0 : f.status) == null ? void 0 : C.status) === "success" && (this.emit("lending:liquidate-success", {
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", {
810
811
  payIdentifier: e,
811
812
  payAmount: a,
812
813
  collateralIdentifier: t,
813
- liquidationAddress: n
814
+ liquidationAddress: s
814
815
  }), this.walletClient.module("balance").updatePortfolio()), y;
815
816
  }
816
817
  /**
@@ -849,7 +850,7 @@ class Fe extends O {
849
850
  * @returns Transaction response or dry run response
850
851
  */
851
852
  async claimAllRewards(e) {
852
- var s, c, i;
853
+ var n, c, i;
853
854
  if (!this.walletClient)
854
855
  throw new Error("Wallet client not found");
855
856
  const a = new m(), t = await J(this.walletClient.address, {
@@ -859,24 +860,24 @@ class Fe extends O {
859
860
  env: this.config.env,
860
861
  accountCap: e == null ? void 0 : e.accountCap
861
862
  });
862
- const n = await this.walletClient.signExecuteTransaction({
863
+ const s = await this.walletClient.signExecuteTransaction({
863
864
  transaction: a,
864
- dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
865
+ dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
865
866
  });
866
- return !(e != null && e.dryRun) && ((i = (c = n.effects) == null ? void 0 : c.status) == null ? void 0 : i.status) === "success" && (this.emit("lending:claim-rewards-success", {
867
+ return !(e != null && e.dryRun) && ((i = (c = s.effects) == null ? void 0 : c.status) == null ? void 0 : i.status) === "success" && (this.emit("lending:claim-rewards-success", {
867
868
  rewards: t
868
- }), this.walletClient.module("balance").updatePortfolio()), n;
869
+ }), this.walletClient.module("balance").updatePortfolio()), s;
869
870
  }
870
871
  async updateOraclePTB(e, a) {
871
- const t = await Q({
872
+ const t = await K({
872
873
  env: this.config.env
873
- }), n = await this.getLendingState({
874
+ }), s = await this.getLendingState({
874
875
  cacheTime: 60 * 1e3
875
- }), s = $(t, {
876
- lendingState: n,
876
+ }), n = q(t, {
877
+ lendingState: s,
877
878
  pools: a
878
879
  });
879
- await K(e, s, {
880
+ await $(e, n, {
880
881
  env: this.config.env,
881
882
  updatePythPriceFeeds: !0
882
883
  });
@@ -889,13 +890,13 @@ class Fe extends O {
889
890
  * @returns Transaction response or dry run response
890
891
  */
891
892
  async updateOracle(e) {
892
- var n;
893
+ var s;
893
894
  if (!this.walletClient)
894
895
  throw new Error("Wallet client not found");
895
896
  const a = new m();
896
897
  return await this.updateOraclePTB(a, e == null ? void 0 : e.pools), await this.walletClient.signExecuteTransaction({
897
898
  transaction: a,
898
- dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
899
+ dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
899
900
  });
900
901
  }
901
902
  /**
@@ -920,13 +921,13 @@ class Fe extends O {
920
921
  * @returns Transaction response or dry run response
921
922
  */
922
923
  async createAccountCap(e) {
923
- var s;
924
+ var n;
924
925
  if (!this.walletClient)
925
926
  throw new Error("Wallet client not found");
926
927
  const a = new m(), t = await Be(a);
927
928
  return a.transferObjects([t], this.walletClient.address), await this.walletClient.signExecuteTransaction({
928
929
  transaction: a,
929
- dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
930
+ dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
930
931
  });
931
932
  }
932
933
  async initializeProtocols() {
@@ -937,14 +938,14 @@ class Fe extends O {
937
938
  const e = [];
938
939
  e.push(new _e(this.walletClient));
939
940
  try {
940
- e.push(await G.create(this.walletClient));
941
+ e.push(await z.create(this.walletClient));
941
942
  } catch (a) {
942
943
  console.warn("Failed to initialize SuilendProtocol:", a);
943
944
  }
944
945
  this._protocols = e;
945
946
  }
946
947
  }
947
- class je extends O {
948
+ class je extends A {
948
949
  constructor() {
949
950
  super(...arguments), this.name = "volo", this.defaultConfig = {
950
951
  packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
@@ -952,7 +953,7 @@ class je extends O {
952
953
  metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
953
954
  coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
954
955
  }, this.getStats = oe(
955
- L(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
956
+ Q(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
956
957
  );
957
958
  }
958
959
  /**
@@ -1011,10 +1012,10 @@ class je extends O {
1011
1012
  throw new Error("Stake amount should be greater than 1Sui");
1012
1013
  const t = new m();
1013
1014
  await this.walletClient.module("balance").waitForUpdate();
1014
- const n = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), s = P(t, n.coins, {
1015
+ const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
1015
1016
  balance: e,
1016
1017
  useGasCoin: !0
1017
- }), c = await this.stakePTB(t, s);
1018
+ }), c = await this.stakePTB(t, n);
1018
1019
  t.transferObjects([c], this.walletClient.address);
1019
1020
  const i = await this.walletClient.signExecuteTransaction({
1020
1021
  transaction: t,
@@ -1039,9 +1040,9 @@ class je extends O {
1039
1040
  if (e < 1e9)
1040
1041
  throw new Error("Unstake amount should >= 1vSui");
1041
1042
  await this.walletClient.module("balance").waitForUpdate();
1042
- const t = new m(), n = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), s = P(t, n.coins, {
1043
+ const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
1043
1044
  balance: e
1044
- }), c = await this.unstakePTB(t, s);
1045
+ }), c = await this.unstakePTB(t, n);
1045
1046
  t.transferObjects([c], this.walletClient.address);
1046
1047
  const i = await this.walletClient.signExecuteTransaction({
1047
1048
  transaction: t,
@@ -1052,7 +1053,7 @@ class je extends O {
1052
1053
  }), this.walletClient.module("balance").updatePortfolio()), i;
1053
1054
  }
1054
1055
  }
1055
- class Ie extends O {
1056
+ class Ie extends A {
1056
1057
  constructor() {
1057
1058
  super(...arguments), this.name = "swap", this.defaultConfig = {
1058
1059
  apiKey: "",
@@ -1101,14 +1102,14 @@ class Ie extends O {
1101
1102
  * @param slippage - The slippage tolerance
1102
1103
  * @returns The swap transaction
1103
1104
  */
1104
- async buildSwapPTBFromQuote(e, a, t, n) {
1105
+ async buildSwapPTBFromQuote(e, a, t, s) {
1105
1106
  if (!this.walletClient)
1106
1107
  throw new Error("Wallet client not found");
1107
- const s = new R(a.amount_out).multipliedBy(1 - n).toFixed(0);
1108
- return await q(
1108
+ const n = new R(a.amount_out).multipliedBy(1 - s).toFixed(0);
1109
+ return await G(
1109
1110
  this.walletClient.address,
1110
1111
  e,
1111
- Number(s),
1112
+ Number(n),
1112
1113
  t,
1113
1114
  a,
1114
1115
  this.referral,
@@ -1134,16 +1135,16 @@ class Ie extends O {
1134
1135
  * @param options - Optional parameters including dry run mode
1135
1136
  * @returns Transaction response or dry run response
1136
1137
  */
1137
- async swap(e, a, t, n, s) {
1138
+ async swap(e, a, t, s, n) {
1138
1139
  var y, d, f;
1139
1140
  if (!this.walletClient)
1140
1141
  throw new Error("Wallet client not found");
1141
1142
  await this.walletClient.module("balance").waitForUpdate();
1142
- const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l = P(i, c.coins, {
1143
+ const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l = B(i, c.coins, {
1143
1144
  balance: t,
1144
1145
  useGasCoin: !0
1145
- }), u = await this.getQuote(e, a, t), r = await this.buildSwapPTBFromQuote(i, u, l, n);
1146
- if (i.transferObjects([r], this.walletClient.address), i.setSender(this.walletClient.address), s != null && s.dryRun)
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)
1147
1148
  return await this.walletClient.signExecuteTransaction({
1148
1149
  transaction: i,
1149
1150
  dryRun: !0
@@ -1166,26 +1167,26 @@ class Ie extends O {
1166
1167
  }
1167
1168
  });
1168
1169
  if (((d = (y = b.effects) == null ? void 0 : y.status) == null ? void 0 : d.status) === "success") {
1169
- const C = (f = b.events) == null ? void 0 : f.find((B) => B.type.includes("::slippage::SwapEvent"));
1170
+ const C = (f = b.events) == null ? void 0 : f.find((P) => P.type.includes("::slippage::SwapEvent"));
1170
1171
  C && this.emit("swap:swap-success", {
1171
1172
  fromCoinType: e,
1172
1173
  toCoinType: a,
1173
1174
  fromAmount: t,
1174
- slippage: n,
1175
+ slippage: s,
1175
1176
  toAmount: Number(C.parsedJson.amount_out)
1176
1177
  }), this.walletClient.module("balance").updatePortfolio();
1177
1178
  }
1178
1179
  return b;
1179
1180
  }
1180
1181
  }
1181
- class Ue extends O {
1182
+ class Ue extends A {
1182
1183
  constructor() {
1183
1184
  super(...arguments), this.name = "haedal", this.defaultConfig = {
1184
- packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
1185
+ packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
1185
1186
  configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
1186
1187
  coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
1187
1188
  }, this.getApy = oe(
1188
- L(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
1189
+ Q(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
1189
1190
  );
1190
1191
  }
1191
1192
  /**
@@ -1239,10 +1240,10 @@ class Ue extends O {
1239
1240
  throw new Error("Wallet client not found");
1240
1241
  const t = new m();
1241
1242
  await this.walletClient.module("balance").waitForUpdate();
1242
- const n = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), s = P(t, n.coins, {
1243
+ const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
1243
1244
  balance: e,
1244
1245
  useGasCoin: !0
1245
- }), c = await this.stakePTB(t, s);
1246
+ }), c = await this.stakePTB(t, n);
1246
1247
  t.transferObjects([c], this.walletClient.address);
1247
1248
  const i = await this.walletClient.signExecuteTransaction({
1248
1249
  transaction: t,
@@ -1261,9 +1262,9 @@ class Ue extends O {
1261
1262
  if (!this.walletClient)
1262
1263
  throw new Error("Wallet client not found");
1263
1264
  await this.walletClient.module("balance").waitForUpdate();
1264
- const t = new m(), n = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), s = P(t, n.coins, {
1265
+ const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
1265
1266
  balance: e
1266
- }), c = await this.unstakePTB(t, s);
1267
+ }), c = await this.unstakePTB(t, n);
1267
1268
  t.transferObjects([c], this.walletClient.address);
1268
1269
  const i = await this.walletClient.signExecuteTransaction({
1269
1270
  transaction: t,
@@ -1297,10 +1298,10 @@ class Ye {
1297
1298
  ...We,
1298
1299
  ...e.client
1299
1300
  };
1300
- 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, n]) => {
1301
- if (t !== n.name)
1302
- throw new Error(`Module name ${t} does not match module name ${n.name}`);
1303
- n.install(this);
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
+ if (t !== s.name)
1303
+ throw new Error(`Module name ${t} does not match module name ${s.name}`);
1304
+ s.install(this);
1304
1305
  });
1305
1306
  }
1306
1307
  get lending() {
@@ -1326,11 +1327,11 @@ class Ye {
1326
1327
  async signExecuteTransaction(e) {
1327
1328
  const { dryRun: a = !1, ...t } = e;
1328
1329
  if (a) {
1329
- let n;
1330
- return e.transaction instanceof m ? (e.transaction.setSenderIfNotSet(this.address), n = await e.transaction.build({
1330
+ let s;
1331
+ return e.transaction instanceof m ? (e.transaction.setSenderIfNotSet(this.address), s = await e.transaction.build({
1331
1332
  client: this.client
1332
- })) : n = e.transaction, this.client.dryRunTransactionBlock({
1333
- transactionBlock: n
1333
+ })) : s = e.transaction, this.client.dryRunTransactionBlock({
1334
+ transactionBlock: s
1334
1335
  });
1335
1336
  }
1336
1337
  return this.client.signAndExecuteTransaction({