@naviprotocol/wallet-client 2.0.4 → 2.0.5-beta.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,11 +1,11 @@
1
- import mt from "mitt";
2
- import { withSingleton as Q, getCoins as et, mergeCoinsPTB as m, getPriceFeeds as $, updateOraclePricesPTB as K, filterPriceFeeds as q, depositCoinPTB as A, getFlashLoanAsset as nt, flashloanPTB as at, repayFlashLoanPTB as it, borrowCoinPTB as st, withdrawCoinPTB as ot, repayCoinPTB as rt, getPools as Ct, getPool as P, getHealthFactor as yt, liquidatePTB as bt, getUserAvailableLendingRewards as D, getUserClaimedRewardHistory as vt, claimLendingRewardsPTB as Bt, getLendingState as Tt, createAccountCapPTB as Pt, withCache as lt, resolveNaviOpenApiEndpoint as ct, buildNaviOpenApiUrl as ut, mergeServiceHeaders as ht, parseTxValue as F, PUBLIC_MAINNET_GRPC_URL as St, createNaviSuiClientBundle as Ot, createNaviLegacyJsonRpcClient as Et } from "@naviprotocol/lending";
3
- import E, { BigNumber as M } from "bignumber.js";
4
- import { normalizeStructTag as B, fromBase64 as dt } from "@mysten/sui/utils";
5
- import { Transaction as h } from "@mysten/sui/transactions";
6
- import { buildSwapPTBFromQuote as z, generateRefId as Rt, getQuote as xt } from "@naviprotocol/astros-aggregator-sdk";
7
- import { executeAuction as At } from "shio-sdk";
8
- import { Signer as wt } from "@mysten/sui/cryptography";
1
+ import me from "mitt";
2
+ import { withSingleton as Q, getCoins as te, mergeCoinsPTB as v, listAddressBalances as Ce, getPriceFeeds as $, updateOraclePricesPTB as z, filterPriceFeeds as K, depositCoinPTB as j, getFlashLoanAsset as ne, flashloanPTB as ae, repayFlashLoanPTB as ie, borrowCoinPTB as se, getAddressBalance as ye, withdrawCoinPTB as oe, repayCoinPTB as le, getPools as be, getPool as S, getHealthFactor as ve, liquidatePTB as Be, getUserAvailableLendingRewards as D, getUserClaimedRewardHistory as Te, claimLendingRewardsPTB as Pe, getLendingState as Se, createAccountCapPTB as Oe, withCache as re, resolveNaviOpenApiEndpoint as ce, buildNaviOpenApiUrl as ue, mergeServiceHeaders as de, parseTxValue as _, PUBLIC_MAINNET_GRPC_URL as Ee, createNaviSuiClientBundle as Re, createNaviLegacyJsonRpcClient as xe } from "@naviprotocol/lending";
3
+ import R, { BigNumber as b } from "bignumber.js";
4
+ import { normalizeStructTag as y, fromBase64 as he } from "@mysten/sui/utils";
5
+ import { Transaction as f } from "@mysten/sui/transactions";
6
+ import { buildSwapPTBFromQuote as q, generateRefId as Ae, getQuote as je } from "@naviprotocol/astros-aggregator-sdk";
7
+ import { executeAuction as Fe } from "shio-sdk";
8
+ import { Signer as we } from "@mysten/sui/cryptography";
9
9
  class k {
10
10
  /**
11
11
  * Gets the current configuration for this module
@@ -24,8 +24,8 @@ class k {
24
24
  * @param event - The event name to emit
25
25
  * @param data - The event data to emit
26
26
  */
27
- emit(t, e) {
28
- this.walletClient?.events.emit(t, e);
27
+ emit(e, n) {
28
+ this.walletClient?.events.emit(e, n);
29
29
  }
30
30
  /**
31
31
  * Installs this module into a wallet client
@@ -35,8 +35,8 @@ class k {
35
35
  *
36
36
  * @param walletClient - The wallet client instance to install into
37
37
  */
38
- install(t) {
39
- this.walletClient = t;
38
+ install(e) {
39
+ this.walletClient = e;
40
40
  }
41
41
  /**
42
42
  * Uninstalls this module from the wallet client
@@ -48,28 +48,47 @@ class k {
48
48
  this.walletClient = void 0;
49
49
  }
50
50
  }
51
- class R {
51
+ class x {
52
52
  /**
53
53
  * Creates a new user portfolio
54
54
  *
55
55
  * @param coins - Array of coin objects or existing portfolio to copy from
56
+ * @param addressBalances - Optional map of normalized coin type to funds held
57
+ * directly at the address level (v2 address balances). Coin objects only
58
+ * account for `Coin<T>` objects, so this carries the balance that lives at
59
+ * the address and is not represented by any object. Defaults to empty,
60
+ * which preserves legacy coin-object-only behavior.
56
61
  */
57
- constructor(t) {
58
- if (t instanceof R)
59
- this.balances = JSON.parse(JSON.stringify(t.balances));
62
+ constructor(e, n) {
63
+ if (e instanceof x)
64
+ this.balances = JSON.parse(JSON.stringify(e.balances)), Object.values(this.balances).forEach((t) => {
65
+ t.amount = b(t.amount), t.addressBalance = b(t.addressBalance ?? 0);
66
+ });
60
67
  else {
61
- const e = {};
62
- t?.forEach((n) => {
63
- if (!n.coinType || n.balance === void 0 || n.balance === null)
68
+ const t = {};
69
+ e?.forEach((i) => {
70
+ if (!i.coinType || i.balance === void 0 || i.balance === null)
71
+ return;
72
+ const a = y(i.coinType);
73
+ let o = t[a];
74
+ o || (o = {
75
+ coinType: a,
76
+ amount: b(0),
77
+ addressBalance: b(0),
78
+ coins: []
79
+ }, t[a] = o), o.coins.push(i), o.amount = o.amount.plus(i.balance);
80
+ }), n && Object.entries(n).forEach(([i, a]) => {
81
+ if (a == null)
64
82
  return;
65
- const s = B(n.coinType);
66
- let a = e[s];
67
- a || (a = {
68
- coinType: s,
69
- amount: M(0),
83
+ const o = y(i);
84
+ let l = t[o];
85
+ l || (l = {
86
+ coinType: o,
87
+ amount: b(0),
88
+ addressBalance: b(0),
70
89
  coins: []
71
- }, e[s] = a), a.coins.push(n), a.amount = a.amount.plus(n.balance);
72
- }), this.balances = e;
90
+ }, t[o] = l), l.addressBalance = b(a);
91
+ }), this.balances = t;
73
92
  }
74
93
  }
75
94
  /**
@@ -78,8 +97,26 @@ class R {
78
97
  * @param coinType - The coin type to query
79
98
  * @returns UserCoinBalance object with coin type, total amount, and coin objects
80
99
  */
81
- getBalance(t) {
82
- return t = B(t), this.balances[t] || { coinType: t, amount: M(0), coins: [] };
100
+ getBalance(e) {
101
+ return e = y(e), this.balances[e] || {
102
+ coinType: e,
103
+ amount: b(0),
104
+ addressBalance: b(0),
105
+ coins: []
106
+ };
107
+ }
108
+ /**
109
+ * Gets the combined total balance for a coin type: the sum of coin objects
110
+ * (`amount`) plus funds held at the address level (`addressBalance`). Use
111
+ * this for sufficiency checks; use `.amount` when you specifically need the
112
+ * coin-object-only sum.
113
+ *
114
+ * @param coinType - The coin type to query
115
+ * @returns BigNumber representing the combined total balance
116
+ */
117
+ combinedBalanceOf(e) {
118
+ const n = this.getBalance(e);
119
+ return n.amount.plus(n.addressBalance ?? 0);
83
120
  }
84
121
  /**
85
122
  * Gets all coin types in the portfolio
@@ -87,7 +124,7 @@ class R {
87
124
  * @returns Array of coin type strings
88
125
  */
89
126
  getCoinTypes() {
90
- return Object.values(this.balances).map((t) => t.coinType);
127
+ return Object.values(this.balances).map((e) => e.coinType);
91
128
  }
92
129
  /**
93
130
  * Gets the total balance amount for a specific coin type
@@ -95,8 +132,8 @@ class R {
95
132
  * @param coinType - The coin type to query
96
133
  * @returns BigNumber representing the total balance
97
134
  */
98
- balanceOf(t) {
99
- return t = B(t), this.getBalance(t)?.amount || M(0);
135
+ balanceOf(e) {
136
+ return e = y(e), this.getBalance(e)?.amount || b(0);
100
137
  }
101
138
  /**
102
139
  * Creates a deep copy of the portfolio
@@ -107,11 +144,10 @@ class R {
107
144
  * @returns New UserPortfolio instance with copied data
108
145
  */
109
146
  clone() {
110
- const t = JSON.parse(JSON.stringify(this.balances)), e = new R();
111
- return e.balances = t, e;
147
+ return new x(this);
112
148
  }
113
149
  }
114
- class jt extends k {
150
+ class ke extends k {
115
151
  constructor() {
116
152
  super(...arguments), this.name = "balance", this.defaultConfig = {
117
153
  coinPollingInterval: 6e3,
@@ -119,10 +155,12 @@ class jt extends k {
119
155
  }, this.updatePortfolio = Q(async () => {
120
156
  if (!this.walletClient)
121
157
  throw new Error("Wallet client not found");
122
- this._coins = await et(this.walletClient.address, {
158
+ this._coins = await te(this.walletClient.address, {
123
159
  client: this.walletClient.client
124
- }), this._portfolio = new R(this._coins), this.emit("balance:portfolio-updated", {});
125
- }), this._coins = [], this._portfolio = new R(), this.pollingTimer = null, this._updatePromise = null;
160
+ });
161
+ const e = await this.getAddressBalanceMap();
162
+ this._portfolio = new x(this._coins, e), this.emit("balance:portfolio-updated", {});
163
+ }), this._coins = [], this._portfolio = new x(), this.pollingTimer = null, this._updatePromise = null;
126
164
  }
127
165
  /**
128
166
  * Gets the current coin objects from the wallet
@@ -160,8 +198,8 @@ class jt extends k {
160
198
  * @param options - Optional parameters including dry run mode
161
199
  * @returns Transaction response or dry run response
162
200
  */
163
- async sendCoin(t, e, n, s) {
164
- return this.sendCoinBatch(t, [e], [n], s);
201
+ async sendCoin(e, n, t, i) {
202
+ return this.sendCoinBatch(e, [n], [t], i);
165
203
  }
166
204
  /**
167
205
  * Sends coins to multiple recipients in a single transaction
@@ -172,26 +210,39 @@ class jt extends k {
172
210
  * @param options - Optional parameters including dry run mode
173
211
  * @returns Transaction response or dry run response
174
212
  */
175
- async sendCoinBatch(t, e, n, s) {
213
+ async sendCoinBatch(e, n, t, i) {
176
214
  if (!this.walletClient)
177
215
  throw new Error("Wallet client not found");
178
- if (e.length !== n.length)
216
+ if (n.length !== t.length)
179
217
  throw new Error("Recipients and amounts must have the same length");
180
218
  await this.waitForUpdate();
181
- const a = this.portfolio.getBalance(t), r = n.reduce((w, d) => w.plus(d), E(0));
182
- if (a.amount.lt(r))
219
+ const a = this.portfolio.getBalance(e), o = y(e) === y("0x2::sui::SUI"), l = o ? a.amount : this.portfolio.combinedBalanceOf(e), r = t.reduce((u, d) => u.plus(d), R(0));
220
+ if (l.lt(r))
183
221
  throw new Error("Insufficient balance");
184
- const o = new h();
185
- let l = o.gas;
186
- B(t) !== B("0x2::sui::SUI") && (l = m(o, a.coins, {
187
- balance: r.toNumber()
188
- }));
189
- const c = o.splitCoins(l, n);
190
- return e.forEach((w, d) => {
191
- o.transferObjects([c[d]], w);
192
- }), await this.walletClient.signExecuteTransaction({
193
- transaction: o,
194
- dryRun: s?.dryRun ?? !1
222
+ const c = new f();
223
+ if (o) {
224
+ const u = c.splitCoins(c.gas, t);
225
+ n.forEach((d, h) => {
226
+ c.transferObjects([u[h]], d);
227
+ });
228
+ } else {
229
+ const u = v(c, a.coins, {
230
+ balance: r.toNumber(),
231
+ addressBalance: a.addressBalance.toFixed(0),
232
+ coinType: e
233
+ });
234
+ if (n.length === 1)
235
+ c.transferObjects([u], n[0]);
236
+ else {
237
+ const d = c.splitCoins(u, t.slice(0, -1));
238
+ n.slice(0, -1).forEach((h, g) => {
239
+ c.transferObjects([d[g]], h);
240
+ }), c.transferObjects([u], n[n.length - 1]);
241
+ }
242
+ }
243
+ return await this.walletClient.signExecuteTransaction({
244
+ transaction: c,
245
+ dryRun: i?.dryRun ?? !1
195
246
  });
196
247
  }
197
248
  /**
@@ -202,8 +253,8 @@ class jt extends k {
202
253
  * @param options - Optional parameters including dry run mode
203
254
  * @returns Transaction response or dry run response
204
255
  */
205
- async transferObject(t, e, n) {
206
- return this.transferObjectBatch([t], [e], n);
256
+ async transferObject(e, n, t) {
257
+ return this.transferObjectBatch([e], [n], t);
207
258
  }
208
259
  /**
209
260
  * Transfers multiple objects to their respective recipients in a single transaction
@@ -216,20 +267,53 @@ class jt extends k {
216
267
  * @param options - Optional parameters including dry run mode
217
268
  * @returns Transaction response or dry run response
218
269
  */
219
- async transferObjectBatch(t, e, n) {
270
+ async transferObjectBatch(e, n, t) {
220
271
  if (!this.walletClient)
221
272
  throw new Error("Wallet client not found");
222
- if (t.length !== e.length)
273
+ if (e.length !== n.length)
223
274
  throw new Error("Objects and recipients must have the same length");
224
275
  await this.waitForUpdate();
225
- const s = new h();
226
- return t.forEach((r, o) => {
227
- s.transferObjects([s.object(r)], e[o]);
276
+ const i = new f();
277
+ return e.forEach((o, l) => {
278
+ i.transferObjects([i.object(o)], n[l]);
228
279
  }), await this.walletClient.signExecuteTransaction({
229
- transaction: s,
230
- dryRun: n?.dryRun ?? !1
280
+ transaction: i,
281
+ dryRun: t?.dryRun ?? !1
231
282
  });
232
283
  }
284
+ /**
285
+ * Builds a map of coin type to address-level balance (v2 address balances).
286
+ *
287
+ * Feature-detects the v2 Core balance API on the injected client; when it is
288
+ * unavailable (legacy JSON-RPC only), returns an empty map so the portfolio
289
+ * falls back to coin-object-only behavior.
290
+ *
291
+ * @returns Map of normalized coin type to address balance (atomic units)
292
+ */
293
+ async getAddressBalanceMap() {
294
+ const e = {};
295
+ if (!this.walletClient)
296
+ return e;
297
+ const n = this.walletClient.client.core;
298
+ if (typeof n?.listBalances != "function" || typeof n?.getBalance != "function")
299
+ return e;
300
+ try {
301
+ let t = null;
302
+ do {
303
+ const { balances: i, nextCursor: a } = await Ce(this.walletClient.client, {
304
+ owner: this.walletClient.address,
305
+ cursor: t,
306
+ limit: 100
307
+ });
308
+ for (const o of i)
309
+ o.addressBalance && o.addressBalance !== "0" && (e[o.coinType] = o.addressBalance);
310
+ t = a;
311
+ } while (t);
312
+ } catch (t) {
313
+ console.error(t);
314
+ }
315
+ return e;
316
+ }
233
317
  /**
234
318
  * Starts polling for portfolio updates
235
319
  *
@@ -240,8 +324,8 @@ class jt extends k {
240
324
  if (!this.config.disableCoinPolling)
241
325
  try {
242
326
  await this.updatePortfolio();
243
- } catch (t) {
244
- console.error(t);
327
+ } catch (e) {
328
+ console.error(e);
245
329
  } finally {
246
330
  this.pollingTimer = setTimeout(this.startPolling, this.config.coinPollingInterval);
247
331
  }
@@ -251,10 +335,10 @@ class jt extends k {
251
335
  *
252
336
  * @param walletClient - The wallet client instance to install into
253
337
  */
254
- install(t) {
255
- super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((e) => {
256
- t.events.on("balance:portfolio-updated", () => {
257
- e();
338
+ install(e) {
339
+ super.install(e), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((n) => {
340
+ e.events.on("balance:portfolio-updated", () => {
341
+ n();
258
342
  });
259
343
  });
260
344
  }
@@ -273,284 +357,297 @@ const G = {
273
357
  showBalanceChanges: !0,
274
358
  showObjectChanges: !0
275
359
  };
276
- function H(i) {
360
+ function H(s) {
277
361
  return {
278
362
  ...G,
279
- ...i
363
+ ...s
280
364
  };
281
365
  }
282
- function p(i) {
283
- const t = i?.effects?.status;
284
- return t?.status === "success" || t?.success === !0;
366
+ function C(s) {
367
+ const e = s?.effects?.status;
368
+ return e?.status === "success" || e?.success === !0;
285
369
  }
286
- function x(i, t) {
287
- const n = kt(t ?? {}), s = Ft(n);
370
+ function A(s, e) {
371
+ const t = _e(e ?? {}), i = Ne(t);
288
372
  return {
289
- ...n,
290
- kind: i,
291
- effects: s,
292
- events: Nt(n.events),
293
- balanceChanges: Array.isArray(n.balanceChanges) ? n.balanceChanges : [],
294
- objectChanges: Array.isArray(n.objectChanges) ? n.objectChanges : []
373
+ ...t,
374
+ kind: s,
375
+ effects: i,
376
+ events: Ie(t.events),
377
+ balanceChanges: Array.isArray(t.balanceChanges) ? t.balanceChanges : [],
378
+ objectChanges: Array.isArray(t.objectChanges) ? t.objectChanges : []
295
379
  };
296
380
  }
297
- function kt(i) {
298
- const t = i.Transaction;
299
- if (j(t))
300
- return t;
301
- const e = i.FailedTransaction;
302
- return j(e) ? e : i;
381
+ function _e(s) {
382
+ const e = s.Transaction;
383
+ if (F(e))
384
+ return e;
385
+ const n = s.FailedTransaction;
386
+ return F(n) ? n : s;
303
387
  }
304
- function Ft(i) {
305
- if (j(i.effects))
306
- return i.effects;
307
- if (j(i.status))
388
+ function Ne(s) {
389
+ if (F(s.effects))
390
+ return s.effects;
391
+ if (F(s.status))
308
392
  return {
309
- status: i.status
393
+ status: s.status
310
394
  };
311
395
  }
312
- function Nt(i) {
313
- return Array.isArray(i) ? i.map((t) => j(t) ? {
314
- ...t,
315
- type: t.type ?? t.eventType,
316
- parsedJson: t.parsedJson ?? t.json
317
- } : t) : [];
396
+ function Ie(s) {
397
+ return Array.isArray(s) ? s.map((e) => F(e) ? {
398
+ ...e,
399
+ type: e.type ?? e.eventType,
400
+ parsedJson: e.parsedJson ?? e.json
401
+ } : e) : [];
318
402
  }
319
- function j(i) {
320
- return typeof i == "object" && i !== null;
403
+ function F(s) {
404
+ return typeof s == "object" && s !== null;
321
405
  }
322
- async function V(i, t, e, n) {
406
+ async function V(s, e, n, t) {
323
407
  if (!this.walletClient)
324
408
  throw new Error("Wallet client not found");
325
- const s = await this.getPool(t), a = await this.getPool(e), r = await this.getLendingState(), o = this.walletClient.address, l = n?.protocol ?? "navi", c = await this.getProtocol(l);
409
+ const i = await this.getPool(e), a = await this.getPool(n), o = await this.getLendingState(), l = this.walletClient.address, r = t?.protocol ?? "navi", c = await this.getProtocol(r);
326
410
  if (!c)
327
- throw new Error(`Protocol ${l} not found`);
328
- const u = await c.getPool(s.coinType);
411
+ throw new Error(`Protocol ${r} not found`);
412
+ const w = await c.getPool(i.coinType);
329
413
  if (console.log("migrateBetweenSupplyPTB", {
330
- fromPoolLending: u
331
- }), l === "navi" && u.supplyBalance === 0)
414
+ fromPoolLending: w
415
+ }), r === "navi" && w.supplyBalance === 0)
332
416
  throw new Error("No supply balance");
333
- if (n?.amount && n.amount > u.supplyBalance)
417
+ if (t?.amount && t.amount > w.supplyBalance)
334
418
  throw new Error("Amount is less than supply balance");
335
- const w = n?.slippage ?? 5e-3, d = n?.amount ?? Number(u.supplyBalance), f = await $(this.naviServiceOptions), C = await Promise.all([s, a]);
336
- if (await K(
337
- i,
338
- q(f, {
339
- lendingState: r,
340
- pools: C
419
+ const u = t?.slippage ?? 5e-3, d = t?.amount ?? Number(w.supplyBalance), h = await $(this.naviServiceOptions), g = await Promise.all([i, a]);
420
+ if (await z(
421
+ s,
422
+ K(h, {
423
+ lendingState: o,
424
+ pools: g
341
425
  }),
342
426
  this.naviServiceOptions
343
- ), l !== "navi" && s.id === a.id) {
427
+ ), r !== "navi" && i.id === a.id) {
344
428
  const L = await c.withdrawCoinPTB(
345
- i,
346
- s.suiCoinType,
429
+ s,
430
+ i.suiCoinType,
347
431
  d
348
432
  );
349
- return await A(i, a, L, {
433
+ return await j(s, a, L, {
350
434
  ...this.naviServiceOptions,
351
435
  amount: d
352
- }), i;
436
+ }), s;
353
437
  }
354
- const y = await nt(a, {
438
+ const m = await ne(a, {
355
439
  ...this.naviServiceOptions,
356
440
  env: this.config.env
357
441
  });
358
- if (!y)
442
+ if (!m)
359
443
  throw new Error(`${a.token.symbol} pool not support flashloan`);
360
- const b = await this.walletClient.swap.getQuote(
361
- s.suiCoinType,
444
+ const B = await this.walletClient.swap.getQuote(
445
+ i.suiCoinType,
362
446
  a.suiCoinType,
363
447
  d
364
- ), g = Number(b.amount_out);
365
- if (g <= 0)
448
+ ), p = Number(B.amount_out);
449
+ if (p <= 0)
366
450
  throw new Error("The amount of swapAmountOut must be greater than 0.");
367
- const T = Math.floor(g * (1 - w)), v = Math.floor(T / (1 + y.flashloanFee));
368
- if (v <= 0)
451
+ const P = Math.floor(p * (1 - u)), T = Math.floor(P / (1 + m.flashloanFee));
452
+ if (T <= 0)
369
453
  throw new Error("The calculated borrow amount must be positive.");
370
- const [S, O] = await at(
371
- i,
454
+ const [O, E] = await ae(
455
+ s,
372
456
  a,
373
- v,
457
+ T,
374
458
  this.naviServiceOptions
375
- ), [N] = i.moveCall({
459
+ ), [N] = s.moveCall({
376
460
  target: "0x2::coin::from_balance",
377
- arguments: [S],
461
+ arguments: [O],
378
462
  typeArguments: [a.suiCoinType]
379
463
  });
380
- await A(i, a, N, {
464
+ await j(s, a, N, {
381
465
  ...this.naviServiceOptions,
382
- amount: v
466
+ amount: T
383
467
  });
384
- const _ = await c.withdrawCoinPTB(i, s.suiCoinType, d), U = await z(
385
- o,
386
- i,
387
- T,
388
- _,
389
- b
390
- ), W = i.moveCall({
468
+ const I = await c.withdrawCoinPTB(s, i.suiCoinType, d), U = await q(
469
+ l,
470
+ s,
471
+ P,
472
+ I,
473
+ B
474
+ ), W = s.moveCall({
391
475
  target: "0x2::coin::into_balance",
392
476
  arguments: [U],
393
477
  typeArguments: [a.suiCoinType]
394
- }), [I] = await it(
395
- i,
478
+ }), [J] = await ie(
479
+ s,
396
480
  a,
397
- O,
481
+ E,
398
482
  W,
399
483
  this.naviServiceOptions
400
- ), [J] = i.moveCall({
484
+ ), [M] = s.moveCall({
401
485
  target: "0x2::coin::from_balance",
402
- arguments: [I],
486
+ arguments: [J],
403
487
  typeArguments: [a.suiCoinType]
404
488
  });
405
- return await A(i, a, J, this.naviServiceOptions), i;
489
+ return await j(s, a, M, this.naviServiceOptions), s;
406
490
  }
407
- async function X(i, t, e, n) {
491
+ async function X(s, e, n, t) {
408
492
  if (!this.walletClient)
409
493
  throw new Error("Wallet client not found");
410
- const s = this.walletClient.address, a = await this.getPool(t), r = await this.getPool(e), o = await this.getLendingState(), l = n?.protocol ?? "navi", c = await this.getProtocol(l);
494
+ const i = this.walletClient.address, a = await this.getPool(e), o = await this.getPool(n), l = await this.getLendingState(), r = t?.protocol ?? "navi", c = await this.getProtocol(r);
411
495
  if (!c)
412
- throw new Error(`Protocol ${l} not found`);
413
- const u = await c.getPool(a.coinType);
496
+ throw new Error(`Protocol ${r} not found`);
497
+ const w = await c.getPool(a.coinType);
414
498
  if (console.log("migrateBetweenBorrowPTB", {
415
- fromPoolLending: u
416
- }), u.borrowBalance === 0)
499
+ fromPoolLending: w
500
+ }), w.borrowBalance === 0)
417
501
  throw new Error("No borrow balance");
418
- if (n?.amount && n.amount > u.borrowBalance)
502
+ if (t?.amount && t.amount > w.borrowBalance)
419
503
  throw new Error("Amount is more than borrow balance");
420
- const w = await $(this.naviServiceOptions), d = await Promise.all([a, r]);
421
- await K(
422
- i,
423
- q(w, {
424
- lendingState: o,
504
+ const u = await $(this.naviServiceOptions), d = await Promise.all([a, o]);
505
+ await z(
506
+ s,
507
+ K(u, {
508
+ lendingState: l,
425
509
  pools: d
426
510
  }),
427
511
  this.naviServiceOptions
428
512
  );
429
- let f = n?.amount ?? Number(u.borrowBalance);
430
- if (Number(u.borrowBalance) === f) {
431
- const pt = u.borrowAPR / 100;
432
- f = Math.ceil(
433
- new E(f).multipliedBy(pt * (60 * 3) / (365 * 24 * 3600)).plus(new E(1).shiftedBy(-a.token.decimals)).plus(f).toNumber()
513
+ let h = t?.amount ?? Number(w.borrowBalance);
514
+ if (Number(w.borrowBalance) === h) {
515
+ const pe = w.borrowAPR / 100;
516
+ h = Math.ceil(
517
+ new R(h).multipliedBy(pe * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-a.token.decimals)).plus(h).toNumber()
434
518
  );
435
519
  }
436
- const C = await nt(a, {
520
+ const g = await ne(a, {
437
521
  ...this.naviServiceOptions,
438
522
  env: this.config.env
439
523
  });
440
- if (!C)
524
+ if (!g)
441
525
  throw new Error(`${a.token.symbol} pool not support flashloan`);
442
526
  if (!this.walletClient)
443
527
  throw new Error("Wallet client not found");
444
- const y = n?.slippage ?? 5e-3, b = Math.ceil(f * (1 + C.flashloanFee)), g = b, T = await this.walletClient.swap.getQuote(
528
+ const m = t?.slippage ?? 5e-3, B = Math.ceil(h * (1 + g.flashloanFee)), p = B, P = await this.walletClient.swap.getQuote(
445
529
  a.suiCoinType,
446
- r.suiCoinType,
447
- g
530
+ o.suiCoinType,
531
+ p
448
532
  );
449
- let v = 1 + y, S = Math.ceil(Number(T.amount_out) * v), O = await this.walletClient.swap.getQuote(
450
- r.suiCoinType,
533
+ let T = 1 + m, O = Math.ceil(Number(P.amount_out) * T), E = await this.walletClient.swap.getQuote(
534
+ o.suiCoinType,
451
535
  a.suiCoinType,
452
- S
536
+ O
453
537
  );
454
- for (; Number(O.amount_out) < g; )
455
- v = v * Math.max(g / Number(O.amount_out), 1.001), S = Math.ceil(Number(T.amount_out) * v), O = await this.walletClient.swap.getQuote(
456
- r.suiCoinType,
538
+ for (; Number(E.amount_out) < p; )
539
+ T = T * Math.max(p / Number(E.amount_out), 1.001), O = Math.ceil(Number(P.amount_out) * T), E = await this.walletClient.swap.getQuote(
540
+ o.suiCoinType,
457
541
  a.suiCoinType,
458
- S
542
+ O
459
543
  );
460
- const [N, _] = await at(
461
- i,
544
+ const [N, I] = await ae(
545
+ s,
462
546
  a,
463
- f,
547
+ h,
464
548
  this.naviServiceOptions
465
- ), [U] = i.moveCall({
549
+ ), [U] = s.moveCall({
466
550
  target: "0x2::coin::from_balance",
467
551
  arguments: [N],
468
552
  typeArguments: [a.suiCoinType]
469
553
  });
470
- await c.repayCoinPTB(i, a.suiCoinType, U, f);
471
- const W = await st(i, r, S, this.naviServiceOptions), I = await z(
472
- s,
554
+ await c.repayCoinPTB(s, a.suiCoinType, U, h);
555
+ const W = await se(s, o, O, this.naviServiceOptions), J = await q(
473
556
  i,
474
- b,
557
+ s,
558
+ B,
475
559
  W,
476
- O
477
- ), J = i.moveCall({
560
+ E
561
+ ), M = s.moveCall({
478
562
  target: "0x2::coin::into_balance",
479
- arguments: [I],
563
+ arguments: [J],
480
564
  typeArguments: [a.suiCoinType]
481
- }), [L] = await it(
482
- i,
565
+ }), [L] = await ie(
566
+ s,
483
567
  a,
484
- _,
485
- J,
568
+ I,
569
+ M,
486
570
  this.naviServiceOptions
487
- ), [gt] = i.moveCall({
571
+ ), [ge] = s.moveCall({
488
572
  target: "0x2::coin::from_balance",
489
573
  arguments: [L],
490
574
  typeArguments: [a.suiCoinType]
491
575
  });
492
- return i.transferObjects([gt], s), i;
576
+ return s.transferObjects([ge], i), s;
493
577
  }
494
- async function Y(i, t, e, n) {
578
+ async function Y(s, e, n, t) {
495
579
  if (!this.walletClient)
496
580
  throw new Error("Wallet client not found");
497
- const s = await et(this.walletClient.address, {
581
+ const i = await te(this.walletClient.address, {
498
582
  client: this.walletClient.client,
499
- coinType: t
500
- }), a = await this.getPool(e), o = new R(s).getBalance(t);
501
- if (o.amount.eq(0))
502
- throw new Error(`No balance of ${t}`);
583
+ coinType: e
584
+ }), a = await this.getPool(n);
585
+ let o = "0";
586
+ if (typeof this.walletClient.client.core?.getBalance == "function")
587
+ try {
588
+ o = (await ye(this.walletClient.client, {
589
+ owner: this.walletClient.address,
590
+ coinType: e
591
+ })).addressBalance;
592
+ } catch (m) {
593
+ console.error(m);
594
+ }
595
+ const r = new x(i, { [e]: o }), c = r.getBalance(e), u = y(e) === y("0x2::sui::SUI") ? c.amount : r.combinedBalanceOf(e);
596
+ if (u.eq(0))
597
+ throw new Error(`No balance of ${e}`);
503
598
  if (console.log("migrateBalanceToSupplyPTB", {
504
- balance: o.amount.toNumber()
505
- }), n?.amount && o.amount.lt(n.amount))
599
+ balance: u.toNumber()
600
+ }), t?.amount && u.lt(t.amount))
506
601
  throw new Error("Amount is greater than balance");
507
- const l = n?.amount ?? o.amount.toNumber(), c = n?.slippage ?? 5e-3;
508
- let u = await m(i, o.coins, {
509
- balance: l,
510
- useGasCoin: !0
602
+ const d = t?.amount ?? u.toNumber(), h = t?.slippage ?? 5e-3;
603
+ let g = await v(s, c.coins, {
604
+ balance: d,
605
+ useGasCoin: !0,
606
+ addressBalance: c.addressBalance.toFixed(0),
607
+ coinType: e
511
608
  });
512
- if (B(t) !== B(a.suiCoinType)) {
513
- const w = await this.walletClient.swap.getQuote(t, a.suiCoinType, l);
514
- u = await this.walletClient.swap.buildSwapPTBFromQuote(
515
- i,
516
- w,
517
- u,
518
- c
609
+ if (y(e) !== y(a.suiCoinType)) {
610
+ const m = await this.walletClient.swap.getQuote(e, a.suiCoinType, d);
611
+ g = await this.walletClient.swap.buildSwapPTBFromQuote(
612
+ s,
613
+ m,
614
+ g,
615
+ h
519
616
  );
520
617
  }
521
- return await A(i, a, u, this.naviServiceOptions), i;
618
+ return await j(s, a, g, this.naviServiceOptions), s;
522
619
  }
523
- class _t {
524
- constructor(t) {
525
- this.name = "navi", this.walletClient = t;
526
- }
527
- async getPool(t) {
528
- const e = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
529
- (o) => o.pool.suiCoinType === B(t)
530
- ), a = s ? new E(s.supplyBalance).toNumber() : 0, r = s ? new E(s.borrowBalance).toNumber() : 0;
620
+ class Ue {
621
+ constructor(e) {
622
+ this.name = "navi", this.walletClient = e;
623
+ }
624
+ async getPool(e) {
625
+ const n = await this.walletClient.lending.getPool(e), i = (await this.walletClient.lending.getLendingState()).find(
626
+ (l) => l.pool.suiCoinType === y(e)
627
+ ), a = i ? new R(i.supplyBalance).toNumber() : 0, o = i ? new R(i.borrowBalance).toNumber() : 0;
531
628
  return {
532
629
  supplyBalance: a,
533
- borrowBalance: r,
534
- borrowAPR: parseFloat(e.borrowIncentiveApyInfo.apy)
630
+ borrowBalance: o,
631
+ borrowAPR: parseFloat(n.borrowIncentiveApyInfo.apy)
535
632
  };
536
633
  }
537
- async depositCoinPTB(t, e, n, s) {
634
+ async depositCoinPTB(e, n, t, i) {
538
635
  throw new Error("Not implemented");
539
636
  }
540
- async withdrawCoinPTB(t, e, n) {
541
- return ot(t, e, n, this.walletClient.lending.naviServiceOptions);
637
+ async withdrawCoinPTB(e, n, t) {
638
+ return oe(e, n, t, this.walletClient.lending.naviServiceOptions);
542
639
  }
543
- async borrowCoinPTB(t, e, n) {
640
+ async borrowCoinPTB(e, n, t) {
544
641
  throw new Error("Not implemented");
545
642
  }
546
- async repayCoinPTB(t, e, n, s) {
547
- rt(t, e, n, {
643
+ async repayCoinPTB(e, n, t, i) {
644
+ le(e, n, t, {
548
645
  ...this.walletClient.lending.naviServiceOptions,
549
- amount: s
646
+ amount: i
550
647
  });
551
648
  }
552
649
  }
553
- class Ut extends k {
650
+ class We extends k {
554
651
  constructor() {
555
652
  super(), this.name = "lending", this.defaultConfig = {
556
653
  env: "prod",
@@ -563,16 +660,16 @@ class Ut extends k {
563
660
  return this._protocols.length > 0 ? this._protocols : this.config.protocols;
564
661
  }
565
662
  get naviServiceOptions() {
566
- const t = this.config.services ?? this.walletClient?.clientBundle.services;
663
+ const e = this.config.services ?? this.walletClient?.clientBundle.services;
567
664
  return {
568
- ...t ? { services: t } : {}
665
+ ...e ? { services: e } : {}
569
666
  };
570
667
  }
571
- install(t) {
572
- super.install(t), this._protocols = [];
668
+ install(e) {
669
+ super.install(e), this._protocols = [];
573
670
  }
574
- async getProtocol(t) {
575
- return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((e) => e.name === t);
671
+ async getProtocol(e) {
672
+ return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((n) => n.name === e);
576
673
  }
577
674
  /**
578
675
  * Gets all available lending pools
@@ -580,11 +677,11 @@ class Ut extends k {
580
677
  * @param options - Optional caching options
581
678
  * @returns Array of pool information
582
679
  */
583
- async getPools(t) {
584
- return await Ct({
680
+ async getPools(e) {
681
+ return await be({
585
682
  ...this.naviServiceOptions,
586
683
  env: this.config.env,
587
- ...t
684
+ ...e
588
685
  });
589
686
  }
590
687
  /**
@@ -594,11 +691,11 @@ class Ut extends k {
594
691
  * @param options - Optional caching options
595
692
  * @returns Pool information
596
693
  */
597
- async getPool(t, e) {
598
- return await P(t, {
694
+ async getPool(e, n) {
695
+ return await S(e, {
599
696
  ...this.naviServiceOptions,
600
697
  env: this.config.env,
601
- ...e
698
+ ...n
602
699
  });
603
700
  }
604
701
  /**
@@ -609,32 +706,34 @@ class Ut extends k {
609
706
  * @param options - Optional parameters including dry run mode and account capability
610
707
  * @returns Transaction response or dry run response
611
708
  */
612
- async deposit(t, e, n) {
709
+ async deposit(e, n, t) {
613
710
  if (!this.walletClient)
614
711
  throw new Error("Wallet client not found");
615
- const s = await P(t, {
712
+ const i = await S(e, {
616
713
  ...this.naviServiceOptions,
617
714
  env: this.config.env
618
715
  });
619
716
  await this.walletClient.module("balance").waitForUpdate();
620
- const a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
621
- balance: e,
622
- useGasCoin: !0
717
+ const a = new f(), o = this.walletClient.module("balance").portfolio.getBalance(i.suiCoinType), l = v(a, o.coins, {
718
+ balance: n,
719
+ useGasCoin: !0,
720
+ addressBalance: o.addressBalance.toFixed(0),
721
+ coinType: i.suiCoinType
623
722
  });
624
- await A(a, s, o, {
723
+ await j(a, i, l, {
625
724
  ...this.naviServiceOptions,
626
725
  env: this.config.env,
627
- amount: e,
628
- accountCap: n?.accountCap
726
+ amount: n,
727
+ accountCap: t?.accountCap
629
728
  });
630
- const l = await this.walletClient.signExecuteTransaction({
729
+ const r = await this.walletClient.signExecuteTransaction({
631
730
  transaction: a,
632
- dryRun: n?.dryRun ?? !1
731
+ dryRun: t?.dryRun ?? !1
633
732
  });
634
- return !n?.dryRun && p(l) && (this.emit("lending:deposit-success", {
635
- identifier: t,
636
- amount: e
637
- }), this.walletClient.module("balance").updatePortfolio()), l;
733
+ return !t?.dryRun && C(r) && (this.emit("lending:deposit-success", {
734
+ identifier: e,
735
+ amount: n
736
+ }), this.walletClient.module("balance").updatePortfolio()), r;
638
737
  }
639
738
  /**
640
739
  * Withdraws coins from a lending pool
@@ -644,28 +743,28 @@ class Ut extends k {
644
743
  * @param options - Optional parameters including dry run mode and account capability
645
744
  * @returns Transaction response or dry run response
646
745
  */
647
- async withdraw(t, e, n) {
746
+ async withdraw(e, n, t) {
648
747
  if (!this.walletClient)
649
748
  throw new Error("Wallet client not found");
650
- const s = await P(t, {
749
+ const i = await S(e, {
651
750
  ...this.naviServiceOptions,
652
751
  env: this.config.env
653
- }), a = new h();
654
- n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
655
- const r = await ot(a, s, e, {
752
+ }), a = new f();
753
+ t?.disableUpdateOracle || await this.updateOraclePTB(a, [i]);
754
+ const o = await oe(a, i, n, {
656
755
  ...this.naviServiceOptions,
657
756
  env: this.config.env,
658
- accountCap: n?.accountCap
757
+ accountCap: t?.accountCap
659
758
  });
660
- a.transferObjects([r], this.walletClient.address);
661
- const o = await this.walletClient.signExecuteTransaction({
759
+ a.transferObjects([o], this.walletClient.address);
760
+ const l = await this.walletClient.signExecuteTransaction({
662
761
  transaction: a,
663
- dryRun: n?.dryRun ?? !1
762
+ dryRun: t?.dryRun ?? !1
664
763
  });
665
- return !n?.dryRun && p(o) && (this.emit("lending:withdraw-success", {
666
- identifier: t,
667
- amount: e
668
- }), this.walletClient.module("balance").updatePortfolio()), o;
764
+ return !t?.dryRun && C(l) && (this.emit("lending:withdraw-success", {
765
+ identifier: e,
766
+ amount: n
767
+ }), this.walletClient.module("balance").updatePortfolio()), l;
669
768
  }
670
769
  /**
671
770
  * Borrows coins from a lending pool
@@ -675,28 +774,28 @@ class Ut extends k {
675
774
  * @param options - Optional parameters including dry run mode and account capability
676
775
  * @returns Transaction response or dry run response
677
776
  */
678
- async borrow(t, e, n) {
777
+ async borrow(e, n, t) {
679
778
  if (!this.walletClient)
680
779
  throw new Error("Wallet client not found");
681
- const s = await P(t, {
780
+ const i = await S(e, {
682
781
  ...this.naviServiceOptions,
683
782
  env: this.config.env
684
- }), a = new h();
685
- n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
686
- const r = await st(a, s, e, {
783
+ }), a = new f();
784
+ t?.disableUpdateOracle || await this.updateOraclePTB(a, [i]);
785
+ const o = await se(a, i, n, {
687
786
  ...this.naviServiceOptions,
688
787
  env: this.config.env,
689
- accountCap: n?.accountCap
788
+ accountCap: t?.accountCap
690
789
  });
691
- a.transferObjects([r], this.walletClient.address);
692
- const o = await this.walletClient.signExecuteTransaction({
790
+ a.transferObjects([o], this.walletClient.address);
791
+ const l = await this.walletClient.signExecuteTransaction({
693
792
  transaction: a,
694
- dryRun: n?.dryRun ?? !1
793
+ dryRun: t?.dryRun ?? !1
695
794
  });
696
- return !n?.dryRun && p(o) && (this.emit("lending:borrow-success", {
697
- identifier: t,
698
- amount: e
699
- }), this.walletClient.module("balance").updatePortfolio()), o;
795
+ return !t?.dryRun && C(l) && (this.emit("lending:borrow-success", {
796
+ identifier: e,
797
+ amount: n
798
+ }), this.walletClient.module("balance").updatePortfolio()), l;
700
799
  }
701
800
  /**
702
801
  * Repays borrowed coins to a lending pool
@@ -706,31 +805,33 @@ class Ut extends k {
706
805
  * @param options - Optional parameters including dry run mode and account capability
707
806
  * @returns Transaction response or dry run response
708
807
  */
709
- async repay(t, e, n) {
808
+ async repay(e, n, t) {
710
809
  if (!this.walletClient)
711
810
  throw new Error("Wallet client not found");
712
811
  await this.walletClient.module("balance").waitForUpdate();
713
- const s = await P(t, {
812
+ const i = await S(e, {
714
813
  ...this.naviServiceOptions,
715
814
  env: this.config.env
716
- }), a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
717
- balance: e,
718
- useGasCoin: !0
815
+ }), a = new f(), o = this.walletClient.module("balance").portfolio.getBalance(i.suiCoinType), l = v(a, o.coins, {
816
+ balance: n,
817
+ useGasCoin: !0,
818
+ addressBalance: o.addressBalance.toFixed(0),
819
+ coinType: i.suiCoinType
719
820
  });
720
- await rt(a, s, o, {
821
+ await le(a, i, l, {
721
822
  ...this.naviServiceOptions,
722
823
  env: this.config.env,
723
- amount: e,
724
- accountCap: n?.accountCap
824
+ amount: n,
825
+ accountCap: t?.accountCap
725
826
  });
726
- const l = await this.walletClient.signExecuteTransaction({
827
+ const r = await this.walletClient.signExecuteTransaction({
727
828
  transaction: a,
728
- dryRun: n?.dryRun ?? !1
829
+ dryRun: t?.dryRun ?? !1
729
830
  });
730
- return !n?.dryRun && p(l) && (this.emit("lending:repay-success", {
731
- identifier: t,
732
- amount: e
733
- }), this.walletClient.module("balance").updatePortfolio()), l;
831
+ return !t?.dryRun && C(r) && (this.emit("lending:repay-success", {
832
+ identifier: e,
833
+ amount: n
834
+ }), this.walletClient.module("balance").updatePortfolio()), r;
734
835
  }
735
836
  /**
736
837
  * Gets the current health factor for the user
@@ -740,8 +841,8 @@ class Ut extends k {
740
841
  async getHealthFactor() {
741
842
  if (!this.walletClient)
742
843
  throw new Error("Wallet client not found");
743
- const t = this.walletClient.address;
744
- return await yt(t, {
844
+ const e = this.walletClient.address;
845
+ return await ve(e, {
745
846
  ...this.naviServiceOptions,
746
847
  env: this.config.env,
747
848
  client: this.walletClient.client
@@ -757,48 +858,50 @@ class Ut extends k {
757
858
  * @param options - Optional parameters including dry run mode
758
859
  * @returns Transaction response or dry run response
759
860
  */
760
- async liquidate(t, e, n, s, a) {
861
+ async liquidate(e, n, t, i, a) {
761
862
  if (!this.walletClient)
762
863
  throw new Error("Wallet client not found");
763
- const r = await P(t, {
864
+ const o = await S(e, {
764
865
  ...this.naviServiceOptions,
765
866
  env: this.config.env
766
- }), o = await P(n, {
867
+ }), l = await S(t, {
767
868
  ...this.naviServiceOptions,
768
869
  env: this.config.env
769
- }), l = new h(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u = m(l, c.coins, {
770
- balance: e,
771
- useGasCoin: !0
772
- }), [w, d] = await bt(
773
- l,
870
+ }), r = new f(), c = this.walletClient.module("balance").portfolio.getBalance(o.suiCoinType), w = v(r, c.coins, {
871
+ balance: n,
872
+ useGasCoin: !0,
873
+ addressBalance: c.addressBalance.toFixed(0),
874
+ coinType: o.suiCoinType
875
+ }), [u, d] = await Be(
774
876
  r,
775
- u,
776
877
  o,
777
- s,
878
+ w,
879
+ l,
880
+ i,
778
881
  {
779
882
  ...this.naviServiceOptions,
780
883
  env: this.config.env
781
884
  }
782
- ), [f] = l.moveCall({
885
+ ), [h] = r.moveCall({
783
886
  target: "0x2::coin::from_balance",
784
- arguments: [w],
785
- typeArguments: [o.suiCoinType]
786
- }), [C] = l.moveCall({
887
+ arguments: [u],
888
+ typeArguments: [l.suiCoinType]
889
+ }), [g] = r.moveCall({
787
890
  target: "0x2::coin::from_balance",
788
891
  arguments: [d],
789
- typeArguments: [r.suiCoinType]
892
+ typeArguments: [o.suiCoinType]
790
893
  });
791
- l.transferObjects([f, C], this.walletClient.address);
792
- const y = await this.walletClient.signExecuteTransaction({
793
- transaction: l,
894
+ r.transferObjects([h, g], this.walletClient.address);
895
+ const m = await this.walletClient.signExecuteTransaction({
896
+ transaction: r,
794
897
  dryRun: a?.dryRun ?? !1
795
898
  });
796
- return !a?.dryRun && p(y) && (this.emit("lending:liquidate-success", {
797
- payIdentifier: t,
798
- payAmount: e,
799
- collateralIdentifier: n,
800
- liquidationAddress: s
801
- }), this.walletClient.module("balance").updatePortfolio()), y;
899
+ return !a?.dryRun && C(m) && (this.emit("lending:liquidate-success", {
900
+ payIdentifier: e,
901
+ payAmount: n,
902
+ collateralIdentifier: t,
903
+ liquidationAddress: i
904
+ }), this.walletClient.module("balance").updatePortfolio()), m;
802
905
  }
803
906
  /**
804
907
  * Gets the available lending rewards for the current user.
@@ -807,12 +910,12 @@ class Ut extends k {
807
910
  * @returns The available lending rewards for the user.
808
911
  * @throws If the wallet client is not found.
809
912
  */
810
- async getAvailableRewards(t) {
913
+ async getAvailableRewards(e) {
811
914
  if (!this.walletClient)
812
915
  throw new Error("Wallet client not found");
813
916
  return D(this.walletClient.address, {
814
917
  ...this.naviServiceOptions,
815
- ...t,
918
+ ...e,
816
919
  env: this.config.env,
817
920
  client: this.walletClient.client
818
921
  });
@@ -824,12 +927,12 @@ class Ut extends k {
824
927
  * @returns The claimed reward history for the user.
825
928
  * @throws If the wallet client is not found.
826
929
  */
827
- async getClaimedRewardHistory(t) {
930
+ async getClaimedRewardHistory(e) {
828
931
  if (!this.walletClient)
829
932
  throw new Error("Wallet client not found");
830
- return vt(this.walletClient.address, {
933
+ return Te(this.walletClient.address, {
831
934
  ...this.naviServiceOptions,
832
- ...t
935
+ ...e
833
936
  });
834
937
  }
835
938
  /**
@@ -838,38 +941,38 @@ class Ut extends k {
838
941
  * @param options - Optional parameters including dry run mode and account capability
839
942
  * @returns Transaction response or dry run response
840
943
  */
841
- async claimAllRewards(t) {
944
+ async claimAllRewards(e) {
842
945
  if (!this.walletClient)
843
946
  throw new Error("Wallet client not found");
844
- const e = new h(), n = await D(this.walletClient.address, {
947
+ const n = new f(), t = await D(this.walletClient.address, {
845
948
  ...this.naviServiceOptions,
846
949
  env: this.config.env,
847
950
  client: this.walletClient.client
848
951
  });
849
- await Bt(e, n, {
952
+ await Pe(n, t, {
850
953
  ...this.naviServiceOptions,
851
954
  env: this.config.env,
852
- accountCap: t?.accountCap
955
+ accountCap: e?.accountCap
853
956
  });
854
- const s = await this.walletClient.signExecuteTransaction({
855
- transaction: e,
856
- dryRun: t?.dryRun ?? !1
957
+ const i = await this.walletClient.signExecuteTransaction({
958
+ transaction: n,
959
+ dryRun: e?.dryRun ?? !1
857
960
  });
858
- return !t?.dryRun && p(s) && (this.emit("lending:claim-rewards-success", {
859
- rewards: n
860
- }), this.walletClient.module("balance").updatePortfolio()), s;
961
+ return !e?.dryRun && C(i) && (this.emit("lending:claim-rewards-success", {
962
+ rewards: t
963
+ }), this.walletClient.module("balance").updatePortfolio()), i;
861
964
  }
862
- async updateOraclePTB(t, e) {
863
- const n = await $({
965
+ async updateOraclePTB(e, n) {
966
+ const t = await $({
864
967
  ...this.naviServiceOptions,
865
968
  env: this.config.env
866
- }), s = await this.getLendingState({
969
+ }), i = await this.getLendingState({
867
970
  cacheTime: 60 * 1e3
868
- }), a = q(n, {
869
- lendingState: s,
870
- pools: e
971
+ }), a = K(t, {
972
+ lendingState: i,
973
+ pools: n
871
974
  });
872
- await K(t, a, {
975
+ await z(e, a, {
873
976
  ...this.naviServiceOptions,
874
977
  env: this.config.env,
875
978
  updatePythPriceFeeds: !0,
@@ -883,13 +986,13 @@ class Ut extends k {
883
986
  * @param options.dryRun - Whether to perform a dry run
884
987
  * @returns Transaction response or dry run response
885
988
  */
886
- async updateOracle(t) {
989
+ async updateOracle(e) {
887
990
  if (!this.walletClient)
888
991
  throw new Error("Wallet client not found");
889
- const e = new h();
890
- return await this.updateOraclePTB(e, t?.pools), await this.walletClient.signExecuteTransaction({
891
- transaction: e,
892
- dryRun: t?.dryRun ?? !1
992
+ const n = new f();
993
+ return await this.updateOraclePTB(n, e?.pools), await this.walletClient.signExecuteTransaction({
994
+ transaction: n,
995
+ dryRun: e?.dryRun ?? !1
893
996
  });
894
997
  }
895
998
  /**
@@ -898,13 +1001,13 @@ class Ut extends k {
898
1001
  * @param options - Optional caching options
899
1002
  * @returns User's lending state information
900
1003
  */
901
- async getLendingState(t) {
1004
+ async getLendingState(e) {
902
1005
  if (!this.walletClient)
903
1006
  throw new Error("Wallet client not found");
904
- return await Tt(this.walletClient.address, {
1007
+ return await Se(this.walletClient.address, {
905
1008
  ...this.naviServiceOptions,
906
1009
  env: this.config.env,
907
- ...t,
1010
+ ...e,
908
1011
  client: this.walletClient.client
909
1012
  });
910
1013
  }
@@ -914,13 +1017,13 @@ class Ut extends k {
914
1017
  * @param options - Optional parameters including dry run mode
915
1018
  * @returns Transaction response or dry run response
916
1019
  */
917
- async createAccountCap(t) {
1020
+ async createAccountCap(e) {
918
1021
  if (!this.walletClient)
919
1022
  throw new Error("Wallet client not found");
920
- const e = new h(), n = await Pt(e);
921
- return e.transferObjects([n], this.walletClient.address), await this.walletClient.signExecuteTransaction({
922
- transaction: e,
923
- dryRun: t?.dryRun ?? !1
1023
+ const n = new f(), t = await Oe(n);
1024
+ return n.transferObjects([t], this.walletClient.address), await this.walletClient.signExecuteTransaction({
1025
+ transaction: n,
1026
+ dryRun: e?.dryRun ?? !1
924
1027
  });
925
1028
  }
926
1029
  async initializeProtocols() {
@@ -928,41 +1031,41 @@ class Ut extends k {
928
1031
  console.warn("Wallet client not available during protocol initialization");
929
1032
  return;
930
1033
  }
931
- const t = [];
932
- if (t.push(new _t(this.walletClient)), this.config.enableSuilend)
1034
+ const e = [];
1035
+ if (e.push(new Ue(this.walletClient)), this.config.enableSuilend)
933
1036
  try {
934
- const { default: e } = await import("./suilend-CWugUjwd.js");
935
- t.push(
936
- await e.create(this.walletClient, {
1037
+ const { default: n } = await import("./suilend-CWugUjwd.js");
1038
+ e.push(
1039
+ await n.create(this.walletClient, {
937
1040
  grpcClient: this.config.suilendGrpcClient,
938
1041
  grpcUrl: this.config.suilendGrpcUrl
939
1042
  })
940
1043
  );
941
- } catch (e) {
942
- console.warn("Failed to initialize SuilendProtocol:", e);
1044
+ } catch (n) {
1045
+ console.warn("Failed to initialize SuilendProtocol:", n);
943
1046
  }
944
- this._protocols = t;
1047
+ this._protocols = e;
945
1048
  }
946
1049
  }
947
- class Wt extends k {
1050
+ class Je extends k {
948
1051
  constructor() {
949
1052
  super(...arguments), this.name = "volo", this.defaultConfig = {
950
1053
  packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
951
1054
  poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
952
1055
  metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
953
1056
  coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
954
- }, this.getStatsCached = lt(
955
- Q(async (t) => {
956
- const e = { services: t?.services }, n = ct(e);
957
- return (await fetch(ut("/volo/stats", e), {
958
- headers: ht({}, n)
1057
+ }, this.getStatsCached = re(
1058
+ Q(async (e) => {
1059
+ const n = { services: e?.services }, t = ce(n);
1060
+ return (await fetch(ue("/volo/stats", n), {
1061
+ headers: de({}, t)
959
1062
  }).then((a) => a.json())).data;
960
1063
  })
961
1064
  );
962
1065
  }
963
- getStats(t) {
1066
+ getStats(e) {
964
1067
  return this.getStatsCached({
965
- services: t?.services ?? this.config.services
1068
+ services: e?.services ?? this.config.services
966
1069
  });
967
1070
  }
968
1071
  /**
@@ -972,18 +1075,18 @@ class Wt extends k {
972
1075
  * @param suiCoin - The SUI coin object to stake
973
1076
  * @returns The vSUI coin object received from staking
974
1077
  */
975
- async stakePTB(t, e) {
976
- const [n] = t.moveCall({
1078
+ async stakePTB(e, n) {
1079
+ const [t] = e.moveCall({
977
1080
  target: `${this.config.packageId}::stake_pool::stake`,
978
1081
  arguments: [
979
- t.object(this.config.poolId),
980
- t.object(this.config.metadataId),
981
- t.object("0x05"),
982
- F(e, t.object)
1082
+ e.object(this.config.poolId),
1083
+ e.object(this.config.metadataId),
1084
+ e.object("0x05"),
1085
+ _(n, e.object)
983
1086
  ],
984
1087
  typeArguments: []
985
1088
  });
986
- return n;
1089
+ return t;
987
1090
  }
988
1091
  /**
989
1092
  * Adds unstaking operation to a transaction black
@@ -992,18 +1095,18 @@ class Wt extends k {
992
1095
  * @param vSuiCoin - The vSUI coin object to unstake
993
1096
  * @returns The SUI coin object received from unstaking
994
1097
  */
995
- async unstakePTB(t, e) {
996
- const [n] = t.moveCall({
1098
+ async unstakePTB(e, n) {
1099
+ const [t] = e.moveCall({
997
1100
  target: `${this.config.packageId}::stake_pool::unstake`,
998
1101
  arguments: [
999
- t.object(this.config.poolId),
1000
- t.object(this.config.metadataId),
1001
- t.object("0x05"),
1002
- F(e, t.object)
1102
+ e.object(this.config.poolId),
1103
+ e.object(this.config.metadataId),
1104
+ e.object("0x05"),
1105
+ _(n, e.object)
1003
1106
  ],
1004
1107
  typeArguments: []
1005
1108
  });
1006
- return n;
1109
+ return t;
1007
1110
  }
1008
1111
  /**
1009
1112
  * Stake SUI tokens to receive vSUI tokens
@@ -1013,25 +1116,27 @@ class Wt extends k {
1013
1116
  * @returns Transaction response or dry run response
1014
1117
  * @throws Error if wallet client not found or stake amount is too low
1015
1118
  */
1016
- async stake(t, e) {
1119
+ async stake(e, n) {
1017
1120
  if (!this.walletClient)
1018
1121
  throw new Error("Wallet client not found");
1019
- if (t < 1e9)
1122
+ if (e < 1e9)
1020
1123
  throw new Error("Stake amount should be greater than 1Sui");
1021
- const n = new h();
1124
+ const t = new f();
1022
1125
  await this.walletClient.module("balance").waitForUpdate();
1023
- const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
1024
- balance: t,
1025
- useGasCoin: !0
1026
- }), r = await this.stakePTB(n, a);
1027
- n.transferObjects([r], this.walletClient.address);
1028
- const o = await this.walletClient.signExecuteTransaction({
1029
- transaction: n,
1030
- dryRun: e?.dryRun ?? !1
1126
+ const i = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = v(t, i.coins, {
1127
+ balance: e,
1128
+ useGasCoin: !0,
1129
+ addressBalance: i.addressBalance.toFixed(0),
1130
+ coinType: "0x2::sui::SUI"
1131
+ }), o = await this.stakePTB(t, a);
1132
+ t.transferObjects([o], this.walletClient.address);
1133
+ const l = await this.walletClient.signExecuteTransaction({
1134
+ transaction: t,
1135
+ dryRun: n?.dryRun ?? !1
1031
1136
  });
1032
- return !e?.dryRun && p(o) && (this.emit("volo:stake-success", {
1033
- suiAmount: t
1034
- }), this.walletClient.module("balance").updatePortfolio()), o;
1137
+ return !n?.dryRun && C(l) && (this.emit("volo:stake-success", {
1138
+ suiAmount: e
1139
+ }), this.walletClient.module("balance").updatePortfolio()), l;
1035
1140
  }
1036
1141
  /**
1037
1142
  * Unstake vSUI tokens to receive SUI tokens
@@ -1041,38 +1146,40 @@ class Wt extends k {
1041
1146
  * @returns Transaction response or dry run response
1042
1147
  * @throws Error if wallet client not found or unstake amount is too low
1043
1148
  */
1044
- async unstake(t, e) {
1149
+ async unstake(e, n) {
1045
1150
  if (!this.walletClient)
1046
1151
  throw new Error("Wallet client not found");
1047
- if (t < 1e9)
1152
+ if (e < 1e9)
1048
1153
  throw new Error("Unstake amount should >= 1vSui");
1049
1154
  await this.walletClient.module("balance").waitForUpdate();
1050
- const n = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
1051
- balance: t
1052
- }), r = await this.unstakePTB(n, a);
1053
- n.transferObjects([r], this.walletClient.address);
1054
- const o = await this.walletClient.signExecuteTransaction({
1055
- transaction: n,
1056
- dryRun: e?.dryRun ?? !1
1155
+ const t = new f(), i = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = v(t, i.coins, {
1156
+ balance: e,
1157
+ addressBalance: i.addressBalance.toFixed(0),
1158
+ coinType: this.config.coinType
1159
+ }), o = await this.unstakePTB(t, a);
1160
+ t.transferObjects([o], this.walletClient.address);
1161
+ const l = await this.walletClient.signExecuteTransaction({
1162
+ transaction: t,
1163
+ dryRun: n?.dryRun ?? !1
1057
1164
  });
1058
- return !e?.dryRun && p(o) && (this.emit("volo:unstake-success", {
1059
- vSuiAmount: t
1060
- }), this.walletClient.module("balance").updatePortfolio()), o;
1165
+ return !n?.dryRun && C(l) && (this.emit("volo:unstake-success", {
1166
+ vSuiAmount: e
1167
+ }), this.walletClient.module("balance").updatePortfolio()), l;
1061
1168
  }
1062
1169
  }
1063
- function It() {
1064
- const i = H(G);
1170
+ function Me() {
1171
+ const s = H(G);
1065
1172
  return {
1066
- effects: i.showEffects,
1067
- events: i.showEvents,
1068
- balanceChanges: i.showBalanceChanges,
1069
- objectTypes: i.showObjectChanges
1173
+ effects: s.showEffects,
1174
+ events: s.showEvents,
1175
+ balanceChanges: s.showBalanceChanges,
1176
+ objectTypes: s.showObjectChanges
1070
1177
  };
1071
1178
  }
1072
- function Jt(i) {
1073
- return i.core;
1179
+ function Le(s) {
1180
+ return s.core;
1074
1181
  }
1075
- class Lt extends k {
1182
+ class Qe extends k {
1076
1183
  constructor() {
1077
1184
  super(...arguments), this.name = "swap", this.defaultConfig = {
1078
1185
  apiKey: "",
@@ -1089,7 +1196,7 @@ class Lt extends k {
1089
1196
  * @returns Referral ID if API key is configured, otherwise 0
1090
1197
  */
1091
1198
  get referral() {
1092
- return this.config.apiKey ? Rt(this.config.apiKey) : 0;
1199
+ return this.config.apiKey ? Ae(this.config.apiKey) : 0;
1093
1200
  }
1094
1201
  /**
1095
1202
  * Get the swap options
@@ -1111,8 +1218,8 @@ class Lt extends k {
1111
1218
  * @param fromAmount - The amount of the coin being swapped from
1112
1219
  * @returns A promise that resolves with the quote
1113
1220
  */
1114
- async getQuote(t, e, n) {
1115
- return xt(t, e, n, this.config.apiKey, this.swapOptions);
1221
+ async getQuote(e, n, t) {
1222
+ return je(e, n, t, this.config.apiKey, this.swapOptions);
1116
1223
  }
1117
1224
  /**
1118
1225
  * Builds a swap transaction from a quote
@@ -1122,16 +1229,16 @@ class Lt extends k {
1122
1229
  * @param slippage - The slippage tolerance
1123
1230
  * @returns The swap transaction
1124
1231
  */
1125
- async buildSwapPTBFromQuote(t, e, n, s) {
1232
+ async buildSwapPTBFromQuote(e, n, t, i) {
1126
1233
  if (!this.walletClient)
1127
1234
  throw new Error("Wallet client not found");
1128
- const a = new E(e.amount_out).multipliedBy(1 - s).toFixed(0);
1129
- return await z(
1235
+ const a = new R(n.amount_out).multipliedBy(1 - i).toFixed(0);
1236
+ return await q(
1130
1237
  this.walletClient.address,
1131
- t,
1238
+ e,
1132
1239
  Number(a),
1240
+ t,
1133
1241
  n,
1134
- e,
1135
1242
  this.referral,
1136
1243
  !1,
1137
1244
  this.config.apiKey,
@@ -1155,74 +1262,76 @@ class Lt extends k {
1155
1262
  * @param options - Optional parameters including dry run mode
1156
1263
  * @returns Transaction response or dry run response
1157
1264
  */
1158
- async swap(t, e, n, s, a) {
1265
+ async swap(e, n, t, i, a) {
1159
1266
  if (!this.walletClient)
1160
1267
  throw new Error("Wallet client not found");
1161
1268
  await this.walletClient.module("balance").waitForUpdate();
1162
- const r = this.walletClient.module("balance").portfolio.getBalance(t), o = new h(), l = m(o, r.coins, {
1163
- balance: n,
1164
- useGasCoin: !0
1165
- }), c = await this.getQuote(t, e, n), u = await this.buildSwapPTBFromQuote(o, c, l, s);
1166
- if (o.transferObjects([u], this.walletClient.address), o.setSender(this.walletClient.address), a?.dryRun)
1269
+ const o = this.walletClient.module("balance").portfolio.getBalance(e), l = new f(), r = v(l, o.coins, {
1270
+ balance: t,
1271
+ useGasCoin: !0,
1272
+ addressBalance: o.addressBalance.toFixed(0),
1273
+ coinType: e
1274
+ }), c = await this.getQuote(e, n, t), w = await this.buildSwapPTBFromQuote(l, c, r, i);
1275
+ if (l.transferObjects([w], this.walletClient.address), l.setSender(this.walletClient.address), a?.dryRun)
1167
1276
  return await this.walletClient.signExecuteTransaction({
1168
- transaction: o,
1277
+ transaction: l,
1169
1278
  dryRun: !0
1170
1279
  });
1171
- const w = await o.build({
1280
+ const u = await l.build({
1172
1281
  client: this.walletClient.client
1173
- }), d = await this.walletClient.signer.signTransaction(w), f = [d.signature];
1282
+ }), d = await this.walletClient.signer.signTransaction(u), h = [d.signature];
1174
1283
  try {
1175
- await At(d.bytes, f);
1176
- } catch (g) {
1177
- console.error(g);
1284
+ await Fe(d.bytes, h);
1285
+ } catch (p) {
1286
+ console.error(p);
1178
1287
  }
1179
- const C = Jt(this.walletClient.client), y = typeof C?.executeTransaction == "function" ? await C.executeTransaction({
1180
- transaction: dt(d.bytes),
1181
- signatures: f,
1182
- include: It()
1288
+ const g = Le(this.walletClient.client), m = typeof g?.executeTransaction == "function" ? await g.executeTransaction({
1289
+ transaction: he(d.bytes),
1290
+ signatures: h,
1291
+ include: Me()
1183
1292
  }) : await (() => {
1184
- const g = this.walletClient.clientBundle.legacyJsonRpc;
1185
- if (!g)
1293
+ const p = this.walletClient.clientBundle.legacyJsonRpc;
1294
+ if (!p)
1186
1295
  throw new Error(
1187
1296
  "Swap execution requires core.executeTransaction or an explicit legacyJsonRpc client"
1188
1297
  );
1189
- return g.executeTransactionBlock({
1298
+ return p.executeTransactionBlock({
1190
1299
  transactionBlock: d.bytes,
1191
- signature: f,
1300
+ signature: h,
1192
1301
  options: G
1193
1302
  });
1194
- })(), b = x("execute", y);
1195
- if (p(b)) {
1196
- const g = b.events?.find((T) => T.type?.includes("::slippage::SwapEvent"));
1197
- g && this.emit("swap:swap-success", {
1198
- fromCoinType: t,
1199
- toCoinType: e,
1200
- fromAmount: n,
1201
- slippage: s,
1202
- toAmount: Number(g.parsedJson.amount_out)
1303
+ })(), B = A("execute", m);
1304
+ if (C(B)) {
1305
+ const p = B.events?.find((P) => P.type?.includes("::slippage::SwapEvent"));
1306
+ p && this.emit("swap:swap-success", {
1307
+ fromCoinType: e,
1308
+ toCoinType: n,
1309
+ fromAmount: t,
1310
+ slippage: i,
1311
+ toAmount: Number(p.parsedJson.amount_out)
1203
1312
  }), this.walletClient.module("balance").updatePortfolio();
1204
1313
  }
1205
- return b;
1314
+ return B;
1206
1315
  }
1207
1316
  }
1208
- class Mt extends k {
1317
+ class $e extends k {
1209
1318
  constructor() {
1210
1319
  super(...arguments), this.name = "haedal", this.defaultConfig = {
1211
1320
  packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
1212
1321
  configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
1213
1322
  coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
1214
- }, this.getApyCached = lt(
1215
- Q(async (t) => {
1216
- const e = { services: t?.services }, n = ct(e);
1217
- return (await fetch(ut("/haedal/stats", e), {
1218
- headers: ht({}, n)
1323
+ }, this.getApyCached = re(
1324
+ Q(async (e) => {
1325
+ const n = { services: e?.services }, t = ce(n);
1326
+ return (await fetch(ue("/haedal/stats", n), {
1327
+ headers: de({}, t)
1219
1328
  }).then((a) => a.json())).data.apy;
1220
1329
  })
1221
1330
  );
1222
1331
  }
1223
- getApy(t) {
1332
+ getApy(e) {
1224
1333
  return this.getApyCached({
1225
- services: t?.services ?? this.config.services
1334
+ services: e?.services ?? this.config.services
1226
1335
  });
1227
1336
  }
1228
1337
  /**
@@ -1232,18 +1341,18 @@ class Mt extends k {
1232
1341
  * @param suiCoin - Sui coin object to stake
1233
1342
  * @returns haSUI coin object
1234
1343
  */
1235
- async stakePTB(t, e) {
1236
- const [n] = t.moveCall({
1344
+ async stakePTB(e, n) {
1345
+ const [t] = e.moveCall({
1237
1346
  target: `${this.config.packageId}::staking::request_stake_coin`,
1238
1347
  arguments: [
1239
- t.object("0x05"),
1240
- t.object(this.config.configId),
1241
- F(e, t.object),
1242
- t.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
1348
+ e.object("0x05"),
1349
+ e.object(this.config.configId),
1350
+ _(n, e.object),
1351
+ e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
1243
1352
  ],
1244
1353
  typeArguments: []
1245
1354
  });
1246
- return n;
1355
+ return t;
1247
1356
  }
1248
1357
  /**
1249
1358
  * Builds a transaction block for unstaking haSUI to SUI
@@ -1252,17 +1361,17 @@ class Mt extends k {
1252
1361
  * @param haSUICoin - haSUI coin object to unstake
1253
1362
  * @returns SUI coin object
1254
1363
  */
1255
- async unstakePTB(t, e) {
1256
- const [n] = t.moveCall({
1364
+ async unstakePTB(e, n) {
1365
+ const [t] = e.moveCall({
1257
1366
  target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
1258
1367
  arguments: [
1259
- t.object("0x05"),
1260
- t.object(this.config.configId),
1261
- F(e, t.object)
1368
+ e.object("0x05"),
1369
+ e.object(this.config.configId),
1370
+ _(n, e.object)
1262
1371
  ],
1263
1372
  typeArguments: []
1264
1373
  });
1265
- return n;
1374
+ return t;
1266
1375
  }
1267
1376
  /**
1268
1377
  * Stake SUI for haSUI
@@ -1270,21 +1379,23 @@ class Mt extends k {
1270
1379
  * @param suiAmount - Amount of SUI to stake
1271
1380
  * @param options Optional dry run
1272
1381
  */
1273
- async stake(t, e) {
1382
+ async stake(e, n) {
1274
1383
  if (!this.walletClient)
1275
1384
  throw new Error("Wallet client not found");
1276
- const n = new h();
1385
+ const t = new f();
1277
1386
  await this.walletClient.module("balance").waitForUpdate();
1278
- const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
1279
- balance: t,
1280
- useGasCoin: !0
1281
- }), r = await this.stakePTB(n, a);
1282
- n.transferObjects([r], this.walletClient.address);
1283
- const o = await this.walletClient.signExecuteTransaction({
1284
- transaction: n,
1285
- dryRun: e?.dryRun ?? !1
1387
+ const i = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = v(t, i.coins, {
1388
+ balance: e,
1389
+ useGasCoin: !0,
1390
+ addressBalance: i.addressBalance.toFixed(0),
1391
+ coinType: "0x2::sui::SUI"
1392
+ }), o = await this.stakePTB(t, a);
1393
+ t.transferObjects([o], this.walletClient.address);
1394
+ const l = await this.walletClient.signExecuteTransaction({
1395
+ transaction: t,
1396
+ dryRun: n?.dryRun ?? !1
1286
1397
  });
1287
- return !e?.dryRun && p(o) && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
1398
+ return !n?.dryRun && C(l) && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
1288
1399
  }
1289
1400
  /**
1290
1401
  * Unstake haSUI for SUI
@@ -1292,75 +1403,77 @@ class Mt extends k {
1292
1403
  * @param haSUIAmount - Amount of haSUI to unstake
1293
1404
  * @param options Optional dry run
1294
1405
  */
1295
- async unstake(t, e) {
1406
+ async unstake(e, n) {
1296
1407
  if (!this.walletClient)
1297
1408
  throw new Error("Wallet client not found");
1298
1409
  await this.walletClient.module("balance").waitForUpdate();
1299
- const n = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
1300
- balance: t
1301
- }), r = await this.unstakePTB(n, a);
1302
- n.transferObjects([r], this.walletClient.address);
1303
- const o = await this.walletClient.signExecuteTransaction({
1304
- transaction: n,
1305
- dryRun: e?.dryRun ?? !1
1410
+ const t = new f(), i = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = v(t, i.coins, {
1411
+ balance: e,
1412
+ addressBalance: i.addressBalance.toFixed(0),
1413
+ coinType: this.config.coinType
1414
+ }), o = await this.unstakePTB(t, a);
1415
+ t.transferObjects([o], this.walletClient.address);
1416
+ const l = await this.walletClient.signExecuteTransaction({
1417
+ transaction: t,
1418
+ dryRun: n?.dryRun ?? !1
1306
1419
  });
1307
- return !e?.dryRun && p(o) && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
1420
+ return !n?.dryRun && C(l) && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
1308
1421
  }
1309
1422
  }
1310
- const Qt = {
1423
+ const ze = {
1311
1424
  /** Balance management module */
1312
- balance: new jt(),
1425
+ balance: new ke(),
1313
1426
  /** Lending protocol module */
1314
- lending: new Ut(),
1427
+ lending: new We(),
1315
1428
  /** Volo protocol module */
1316
- volo: new Wt(),
1429
+ volo: new Je(),
1317
1430
  /** DEX swapping module */
1318
- swap: new Lt(),
1431
+ swap: new Qe(),
1319
1432
  /** Haedal protocol module */
1320
- haedal: new Mt()
1433
+ haedal: new $e()
1321
1434
  };
1322
- function Z(i) {
1323
- const t = H(i);
1435
+ function Z(s) {
1436
+ const e = H(s);
1324
1437
  return {
1325
- effects: t.showEffects,
1326
- events: t.showEvents,
1327
- balanceChanges: t.showBalanceChanges,
1328
- objectTypes: t.showObjectChanges
1438
+ effects: e.showEffects,
1439
+ events: e.showEvents,
1440
+ balanceChanges: e.showBalanceChanges,
1441
+ objectTypes: e.showObjectChanges
1329
1442
  };
1330
1443
  }
1331
- function tt(i) {
1332
- return i.core;
1444
+ function ee(s) {
1445
+ return s.core;
1333
1446
  }
1334
- function $t(i) {
1335
- return "grpc" in i;
1447
+ function Ke(s) {
1448
+ return "grpc" in s;
1336
1449
  }
1337
- function Kt(i) {
1338
- if ($t(i))
1339
- return Ot(i);
1340
- const t = i.network ?? "mainnet", e = Et(t, i.legacyJsonRpc);
1450
+ function qe(s) {
1451
+ if (Ke(s))
1452
+ return Re(s);
1453
+ const e = s.network ?? "mainnet", n = xe(e, s.legacyJsonRpc);
1341
1454
  return {
1342
- network: t,
1343
- coreClient: e,
1344
- grpc: e,
1345
- legacyJsonRpc: e,
1346
- services: i.services
1455
+ network: e,
1456
+ coreClient: n,
1457
+ grpc: n,
1458
+ legacyJsonRpc: n,
1459
+ services: s.services
1347
1460
  };
1348
1461
  }
1349
- class Zt {
1462
+ class tt {
1350
1463
  /**
1351
1464
  * Creates a new wallet client instance
1352
1465
  * @param options - Configuration options for the wallet client
1353
1466
  */
1354
- constructor(t) {
1355
- this.modules = Qt, this.userConfigs = {}, this.events = mt();
1356
- const e = t.client ?? {
1467
+ constructor(e) {
1468
+ this.modules = ze, this.userConfigs = {}, this.events = me();
1469
+ const n = e.client ?? {
1357
1470
  network: "mainnet",
1358
- grpc: { url: St }
1471
+ grpc: { url: Ee }
1359
1472
  };
1360
- this.clientBundle = Kt(e), this.client = this.clientBundle.coreClient, this.clientUrl = "grpc" in e ? e.legacyJsonRpc && "url" in e.legacyJsonRpc ? e.legacyJsonRpc.url : void 0 : "url" in e.legacyJsonRpc ? e.legacyJsonRpc.url : void 0, this.signer = t.signer, this.userConfigs = t.configs || {}, Object.entries(this.modules).forEach(([n, s]) => {
1361
- if (n !== s.name)
1362
- throw new Error(`Module name ${n} does not match module name ${s.name}`);
1363
- s.install(this);
1473
+ this.clientBundle = qe(n), this.client = this.clientBundle.coreClient, this.clientUrl = "grpc" in n ? n.legacyJsonRpc && "url" in n.legacyJsonRpc ? n.legacyJsonRpc.url : void 0 : "url" in n.legacyJsonRpc ? n.legacyJsonRpc.url : void 0, this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, i]) => {
1474
+ if (t !== i.name)
1475
+ throw new Error(`Module name ${t} does not match module name ${i.name}`);
1476
+ i.install(this);
1364
1477
  });
1365
1478
  }
1366
1479
  get lending() {
@@ -1383,56 +1496,56 @@ class Zt {
1383
1496
  * @param options - Transaction execution options including dry run support
1384
1497
  * @returns Promise with transaction execution result
1385
1498
  */
1386
- async signExecuteTransaction(t) {
1387
- const { dryRun: e = !1, ...n } = t;
1388
- if (e) {
1389
- const o = tt(this.client);
1390
- if (typeof o?.simulateTransaction == "function") {
1391
- t.transaction instanceof h && t.transaction.setSenderIfNotSet(this.address);
1392
- const w = await o.simulateTransaction({
1393
- transaction: t.transaction,
1394
- include: Z(n.options)
1499
+ async signExecuteTransaction(e) {
1500
+ const { dryRun: n = !1, ...t } = e;
1501
+ if (n) {
1502
+ const l = ee(this.client);
1503
+ if (typeof l?.simulateTransaction == "function") {
1504
+ e.transaction instanceof f && e.transaction.setSenderIfNotSet(this.address);
1505
+ const u = await l.simulateTransaction({
1506
+ transaction: e.transaction,
1507
+ include: Z(t.options)
1395
1508
  });
1396
- return x("dryRun", w);
1509
+ return A("dryRun", u);
1397
1510
  }
1398
- const l = this.clientBundle.legacyJsonRpc;
1399
- if (!l)
1511
+ const r = this.clientBundle.legacyJsonRpc;
1512
+ if (!r)
1400
1513
  throw new Error(
1401
1514
  "WalletClient dry-run requires core.simulateTransaction or an explicit legacyJsonRpc client"
1402
1515
  );
1403
1516
  let c;
1404
- t.transaction instanceof h ? (t.transaction.setSenderIfNotSet(this.address), c = await t.transaction.build({
1405
- client: l
1406
- })) : c = t.transaction;
1407
- const u = await l.dryRunTransactionBlock({
1517
+ e.transaction instanceof f ? (e.transaction.setSenderIfNotSet(this.address), c = await e.transaction.build({
1518
+ client: r
1519
+ })) : c = e.transaction;
1520
+ const w = await r.dryRunTransactionBlock({
1408
1521
  transactionBlock: c
1409
1522
  });
1410
- return x("dryRun", u);
1523
+ return A("dryRun", w);
1411
1524
  }
1412
- const s = tt(this.client);
1413
- if (typeof s?.executeTransaction == "function") {
1414
- let o;
1415
- t.transaction instanceof h ? (t.transaction.setSenderIfNotSet(this.address), o = await t.transaction.build({
1525
+ const i = ee(this.client);
1526
+ if (typeof i?.executeTransaction == "function") {
1527
+ let l;
1528
+ e.transaction instanceof f ? (e.transaction.setSenderIfNotSet(this.address), l = await e.transaction.build({
1416
1529
  client: this.client
1417
- })) : o = t.transaction;
1418
- const l = await this.signer.signTransaction(o), c = await s.executeTransaction({
1419
- transaction: dt(l.bytes),
1420
- signatures: [l.signature],
1421
- include: Z(n.options)
1530
+ })) : l = e.transaction;
1531
+ const r = await this.signer.signTransaction(l), c = await i.executeTransaction({
1532
+ transaction: he(r.bytes),
1533
+ signatures: [r.signature],
1534
+ include: Z(t.options)
1422
1535
  });
1423
- return x("execute", c);
1536
+ return A("execute", c);
1424
1537
  }
1425
1538
  const a = this.clientBundle.legacyJsonRpc;
1426
1539
  if (!a)
1427
1540
  throw new Error(
1428
1541
  "WalletClient execution requires core.executeTransaction or an explicit legacyJsonRpc client"
1429
1542
  );
1430
- const r = await a.signAndExecuteTransaction({
1431
- ...n,
1432
- options: H(n.options),
1543
+ const o = await a.signAndExecuteTransaction({
1544
+ ...t,
1545
+ options: H(t.options),
1433
1546
  signer: this.signer
1434
1547
  });
1435
- return x("execute", r);
1548
+ return A("execute", o);
1436
1549
  }
1437
1550
  /**
1438
1551
  * Gets the wallet address from the signer's public key
@@ -1446,18 +1559,18 @@ class Zt {
1446
1559
  * @param name - The name of the module to retrieve
1447
1560
  * @returns The requested module instance
1448
1561
  */
1449
- module(t) {
1450
- return this.modules[t];
1562
+ module(e) {
1563
+ return this.modules[e];
1451
1564
  }
1452
1565
  /**
1453
1566
  * Gets the configuration for a specific module
1454
1567
  * @param name - The name of the module
1455
1568
  * @returns The merged configuration (default + user config)
1456
1569
  */
1457
- config(t) {
1570
+ config(e) {
1458
1571
  return {
1459
- ...this.modules[t].defaultConfig,
1460
- ...this.userConfigs[t]
1572
+ ...this.modules[e].defaultConfig,
1573
+ ...this.userConfigs[e]
1461
1574
  };
1462
1575
  }
1463
1576
  /**
@@ -1465,27 +1578,27 @@ class Zt {
1465
1578
  * @param name - The name of the module to check
1466
1579
  * @returns True if the module exists, false otherwise
1467
1580
  */
1468
- hasModule(t) {
1469
- return t in this.modules;
1581
+ hasModule(e) {
1582
+ return e in this.modules;
1470
1583
  }
1471
1584
  }
1472
- function ft(i) {
1585
+ function fe(s) {
1473
1586
  return {
1474
- toSuiAddress: () => i,
1587
+ toSuiAddress: () => s,
1475
1588
  toBytes: () => new Uint8Array(32),
1476
1589
  toRawBytes: () => new Uint8Array(32),
1477
1590
  flag: () => 0,
1478
1591
  verify: async () => !1
1479
1592
  };
1480
1593
  }
1481
- class te extends wt {
1594
+ class nt extends we {
1482
1595
  /**
1483
1596
  * Creates a new watch-only signer
1484
1597
  *
1485
1598
  * @param address - The wallet address to watch
1486
1599
  */
1487
- constructor(t) {
1488
- super(), this.address = t;
1600
+ constructor(e) {
1601
+ super(), this.address = e;
1489
1602
  }
1490
1603
  /**
1491
1604
  * Signs transaction bytes (not implemented for watch-only mode)
@@ -1496,7 +1609,7 @@ class te extends wt {
1496
1609
  * @param bytes - Transaction bytes to sign
1497
1610
  * @returns Promise<Uint8Array> - Empty signature (not valid)
1498
1611
  */
1499
- async sign(t) {
1612
+ async sign(e) {
1500
1613
  return Promise.resolve(new Uint8Array(0));
1501
1614
  }
1502
1615
  /**
@@ -1506,7 +1619,7 @@ class te extends wt {
1506
1619
  * but cannot be used for actual cryptographic operations.
1507
1620
  */
1508
1621
  getPublicKey() {
1509
- return ft(this.address);
1622
+ return fe(this.address);
1510
1623
  }
1511
1624
  /**
1512
1625
  * Gets the key scheme for this signer
@@ -1522,18 +1635,18 @@ class te extends wt {
1522
1635
  * This method is required by the Signer interface but cannot
1523
1636
  * actually sign and execute transactions in watch-only mode.
1524
1637
  */
1525
- async signAndExecuteTransaction(t) {
1638
+ async signAndExecuteTransaction(e) {
1526
1639
  return {};
1527
1640
  }
1528
1641
  }
1529
- class ee extends wt {
1642
+ class at extends we {
1530
1643
  /**
1531
1644
  * Creates a new watch-only signer
1532
1645
  *
1533
1646
  * @param address - The wallet address to watch
1534
1647
  */
1535
- constructor(t) {
1536
- super(), this.address = t;
1648
+ constructor(e) {
1649
+ super(), this.address = e;
1537
1650
  }
1538
1651
  /**
1539
1652
  * Signs transaction bytes (not implemented for watch-only mode)
@@ -1544,7 +1657,7 @@ class ee extends wt {
1544
1657
  * @param bytes - Transaction bytes to sign
1545
1658
  * @returns Promise<Uint8Array> - Empty signature (not valid)
1546
1659
  */
1547
- async sign(t) {
1660
+ async sign(e) {
1548
1661
  return Promise.resolve(new Uint8Array(0));
1549
1662
  }
1550
1663
  /**
@@ -1554,7 +1667,7 @@ class ee extends wt {
1554
1667
  * but cannot be used for actual cryptographic operations.
1555
1668
  */
1556
1669
  getPublicKey() {
1557
- return ft(this.address);
1670
+ return fe(this.address);
1558
1671
  }
1559
1672
  /**
1560
1673
  * Gets the key scheme for this signer
@@ -1566,8 +1679,8 @@ class ee extends wt {
1566
1679
  }
1567
1680
  }
1568
1681
  export {
1569
- Zt as WalletClient,
1570
- te as WatchSigner,
1571
- ee as WebSigner
1682
+ tt as WalletClient,
1683
+ nt as WatchSigner,
1684
+ at as WebSigner
1572
1685
  };
1573
1686
  //# sourceMappingURL=index.esm.js.map