@naviprotocol/wallet-client 1.0.3-dev.1 → 1.0.3-dev.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,7 +1,7 @@
1
1
  import { getFullnodeUrl as le, SuiClient as ie } from "@mysten/sui/client";
2
2
  import re from "mitt";
3
3
  import ce from "axios";
4
- import { withSingleton as L, getCoins as oe, mergeCoinsPTB as y, getPriceFeeds as Q, updateOraclePricesPTB as q, filterPriceFeeds as K, getFlashLoanAsset as V, flashloanPTB as X, depositCoinPTB as A, withdrawCoinPTB as Y, repayFlashLoanPTB as Z, repayCoinPTB as ee, borrowCoinPTB as te, getPools as ue, getPool as P, getHealthFactor as de, liquidatePTB as we, getUserAvailableLendingRewards as H, getUserClaimedRewardHistory as he, claimLendingRewardsPTB as fe, getLendingState as ge, createAccountCapPTB as me, withCache as ae, parseTxValue as x } from "@naviprotocol/lending";
4
+ import { withSingleton as L, getCoins as oe, mergeCoinsPTB as y, getPriceFeeds as Q, updateOraclePricesPTB as q, filterPriceFeeds as K, getFlashLoanAsset as V, flashloanPTB as X, depositCoinPTB as F, withdrawCoinPTB as Y, repayFlashLoanPTB as Z, repayCoinPTB as ee, borrowCoinPTB as te, getPools as ue, getPool as P, getHealthFactor as de, liquidatePTB as we, getUserAvailableLendingRewards as H, getUserClaimedRewardHistory as he, claimLendingRewardsPTB as fe, getLendingState as ge, createAccountCapPTB as me, withCache as ae, parseTxValue as x } from "@naviprotocol/lending";
5
5
  import p, { BigNumber as M } from "bignumber.js";
6
6
  import { normalizeStructTag as T } from "@mysten/sui/utils";
7
7
  import { Transaction as w } from "@mysten/sui/transactions";
@@ -328,12 +328,18 @@ function Te(r, e = 2) {
328
328
  return r ? new p(r.toString()).shiftedBy(-1 * Pe).multipliedBy(100).decimalPlaces(e, p.ROUND_DOWN).toFixed(e) : "0.00";
329
329
  }
330
330
  async function D(r, e, a, t) {
331
- var S, F;
331
+ var S, O;
332
332
  if (!this.walletClient)
333
333
  throw new Error("Wallet client not found");
334
- await this.walletClient.balance.waitForUpdate();
335
- const s = await this.getPool(e), n = await this.getPool(a), c = await this.getLendingState(), l = c.find((O) => O.pool.id === s.id), i = this.walletClient.address;
336
- if (!l || l.supplyBalance === "0")
334
+ await this.walletClient.balance.updatePortfolio();
335
+ const s = await this.getPool(e), n = await this.getPool(a), c = await this.getLendingState(), l = c.find((A) => A.pool.id === s.id), i = this.walletClient.address;
336
+ if (console.log("migrateBetweenSupplyPTB", {
337
+ lendingState: c,
338
+ fromPoolLending: l,
339
+ fromPool: s,
340
+ toPool: n,
341
+ address: i
342
+ }), !l || l.supplyBalance === "0")
337
343
  throw new Error("No supply balance");
338
344
  if (t != null && t.amount && t.amount > Number(l.supplyBalance))
339
345
  throw new Error("Amount is less than supply balance");
@@ -348,17 +354,9 @@ async function D(r, e, a, t) {
348
354
  const d = await V(n, {
349
355
  env: this.config.env
350
356
  });
351
- if (console.log("migrateBetweenSupplyPTB", {
352
- toPool: n,
353
- toPoolFlashloanAsset: d,
354
- fromPool: s,
355
- fromPoolLending: l,
356
- options: t,
357
- from: e,
358
- to: a
359
- }), !d)
357
+ if (!d)
360
358
  throw new Error(`${n.token.symbol} pool not support flashloan`);
361
- const h = (S = t == null ? void 0 : t.slippage) != null ? S : 5e-3, f = (F = t == null ? void 0 : t.amount) != null ? F : Number(l.supplyBalance), b = await this.walletClient.swap.getQuote(
359
+ const h = (S = t == null ? void 0 : t.slippage) != null ? S : 5e-3, f = (O = t == null ? void 0 : t.amount) != null ? O : Number(l.supplyBalance), b = await this.walletClient.swap.getQuote(
362
360
  s.suiCoinType,
363
361
  n.suiCoinType,
364
362
  f
@@ -373,33 +371,39 @@ async function D(r, e, a, t) {
373
371
  arguments: [B],
374
372
  typeArguments: [n.suiCoinType]
375
373
  });
376
- await A(r, n, k, {
374
+ await F(r, n, k, {
377
375
  amount: g
378
376
  });
379
- const j = await Y(r, s, f), U = await $(
377
+ const j = await Y(r, s, f), _ = await $(
380
378
  i,
381
379
  r,
382
380
  C,
383
381
  j,
384
382
  b
385
- ), _ = r.moveCall({
383
+ ), U = r.moveCall({
386
384
  target: "0x2::coin::into_balance",
387
- arguments: [U],
385
+ arguments: [_],
388
386
  typeArguments: [n.suiCoinType]
389
- }), [W] = await Z(r, n, v, _), [N] = r.moveCall({
387
+ }), [W] = await Z(r, n, v, U), [N] = r.moveCall({
390
388
  target: "0x2::coin::from_balance",
391
389
  arguments: [W],
392
390
  typeArguments: [n.suiCoinType]
393
391
  });
394
- return await A(r, n, N), r;
392
+ return await F(r, n, N), r;
395
393
  }
396
394
  async function J(r, e, a, t) {
397
- var O, G;
395
+ var A, G;
398
396
  if (!this.walletClient)
399
397
  throw new Error("Wallet client not found");
400
- await this.walletClient.balance.waitForUpdate();
398
+ await this.walletClient.balance.updatePortfolio();
401
399
  const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a), l = await this.getLendingState(), i = l.find((I) => I.pool.id === n.id);
402
- if (!i || i.borrowBalance === "0")
400
+ if (console.log("migrateBetweenBorrowPTB", {
401
+ lendingState: l,
402
+ fromPoolLending: i,
403
+ fromPool: n,
404
+ toPool: c,
405
+ address: s
406
+ }), !i || i.borrowBalance === "0")
403
407
  throw new Error("No borrow balance");
404
408
  if (t != null && t.amount && t.amount > Number(i.borrowBalance))
405
409
  throw new Error("Amount is less than borrow balance");
@@ -411,7 +415,7 @@ async function J(r, e, a, t) {
411
415
  pools: u
412
416
  })
413
417
  );
414
- let d = (O = t == null ? void 0 : t.amount) != null ? O : Number(i.borrowBalance);
418
+ let d = (A = t == null ? void 0 : t.amount) != null ? A : Number(i.borrowBalance);
415
419
  if (Number(i.borrowBalance) === d) {
416
420
  const I = parseFloat(Te(n.currentBorrowRate, 8)) / 100;
417
421
  d = Math.ceil(
@@ -425,16 +429,6 @@ async function J(r, e, a, t) {
425
429
  throw new Error(`${n.token.symbol} pool not support flashloan`);
426
430
  if (!this.walletClient)
427
431
  throw new Error("Wallet client not found");
428
- console.log("migrateBetweenBorrowPTB", {
429
- toPool: c,
430
- fromPoolFlashloanAsset: h,
431
- fromPool: n,
432
- formAmount: d,
433
- fromPoolLending: i,
434
- options: t,
435
- from: e,
436
- to: a
437
- });
438
432
  const f = (G = t == null ? void 0 : t.slippage) != null ? G : 5e-3, b = Math.ceil(d * (1 + h.flashloanFee)), m = b, C = await this.walletClient.swap.getQuote(
439
433
  n.suiCoinType,
440
434
  c.suiCoinType,
@@ -451,36 +445,36 @@ async function J(r, e, a, t) {
451
445
  n.suiCoinType,
452
446
  B
453
447
  );
454
- const [k, j] = await X(r, n, d), [U] = r.moveCall({
448
+ const [k, j] = await X(r, n, d), [_] = r.moveCall({
455
449
  target: "0x2::coin::from_balance",
456
450
  arguments: [k],
457
451
  typeArguments: [n.suiCoinType]
458
452
  });
459
- await ee(r, n, U, {
453
+ await ee(r, n, _, {
460
454
  amount: d
461
455
  });
462
- const _ = await te(r, c, B), W = await $(
456
+ const U = await te(r, c, B), W = await $(
463
457
  s,
464
458
  r,
465
459
  b,
466
- _,
460
+ U,
467
461
  v
468
462
  ), N = r.moveCall({
469
463
  target: "0x2::coin::into_balance",
470
464
  arguments: [W],
471
465
  typeArguments: [n.suiCoinType]
472
- }), [S] = await Z(r, n, j, N), [F] = r.moveCall({
466
+ }), [S] = await Z(r, n, j, N), [O] = r.moveCall({
473
467
  target: "0x2::coin::from_balance",
474
468
  arguments: [S],
475
469
  typeArguments: [n.suiCoinType]
476
470
  });
477
- return r.transferObjects([F], s), r;
471
+ return r.transferObjects([O], s), r;
478
472
  }
479
473
  async function z(r, e, a, t) {
480
474
  var o, u;
481
475
  if (!this.walletClient)
482
476
  throw new Error("Wallet client not found");
483
- await this.walletClient.balance.waitForUpdate(), this.walletClient.address;
477
+ await this.walletClient.balance.updatePortfolio(), this.walletClient.address;
484
478
  const s = await this.getPool(a), n = this.walletClient.balance.portfolio.getBalance(e);
485
479
  if (n.amount.eq(0))
486
480
  throw new Error(`No balance of ${e}`);
@@ -500,7 +494,7 @@ async function z(r, e, a, t) {
500
494
  l
501
495
  );
502
496
  }
503
- return await A(r, s, i), r;
497
+ return await F(r, s, i), r;
504
498
  }
505
499
  class ve extends R {
506
500
  constructor() {
@@ -553,7 +547,7 @@ class ve extends R {
553
547
  balance: a,
554
548
  useGasCoin: !0
555
549
  });
556
- await A(n, s, l, {
550
+ await F(n, s, l, {
557
551
  env: this.config.env,
558
552
  amount: a,
559
553
  accountCap: t == null ? void 0 : t.accountCap
@@ -1164,7 +1158,7 @@ const Se = {
1164
1158
  swap: new Ee(),
1165
1159
  /** Haedal protocol module */
1166
1160
  haedal: new Re()
1167
- }, Fe = {
1161
+ }, Oe = {
1168
1162
  url: le("mainnet")
1169
1163
  };
1170
1164
  class Ie {
@@ -1175,7 +1169,7 @@ class Ie {
1175
1169
  constructor(e) {
1176
1170
  this.modules = Se, this.userConfigs = {}, this.events = re();
1177
1171
  const a = {
1178
- ...Fe,
1172
+ ...Oe,
1179
1173
  ...e.client
1180
1174
  };
1181
1175
  a.transport = a.transport || new ye(a.url), this.client = new ie(a), this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, s]) => {