@naviprotocol/wallet-client 1.4.11 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +62 -9
  2. package/dist/client.d.ts +18 -6
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/index.esm.js +612 -512
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/modules/balanceModule/index.d.ts +6 -5
  7. package/dist/modules/balanceModule/index.d.ts.map +1 -1
  8. package/dist/modules/balanceModule/portfolio.d.ts +1 -1
  9. package/dist/modules/balanceModule/portfolio.d.ts.map +1 -1
  10. package/dist/modules/haedalModule/index.d.ts +14 -12
  11. package/dist/modules/haedalModule/index.d.ts.map +1 -1
  12. package/dist/modules/lendingModule/index.d.ts +24 -10
  13. package/dist/modules/lendingModule/index.d.ts.map +1 -1
  14. package/dist/modules/lendingModule/migrate.d.ts.map +1 -1
  15. package/dist/modules/lendingModule/protocols/navi.d.ts.map +1 -1
  16. package/dist/modules/lendingModule/protocols/suilend.d.ts +7 -2
  17. package/dist/modules/lendingModule/protocols/suilend.d.ts.map +1 -1
  18. package/dist/modules/swapModule/index.d.ts +7 -3
  19. package/dist/modules/swapModule/index.d.ts.map +1 -1
  20. package/dist/modules/voloModule/index.d.ts +14 -13
  21. package/dist/modules/voloModule/index.d.ts.map +1 -1
  22. package/dist/signer.d.ts +2 -4
  23. package/dist/signer.d.ts.map +1 -1
  24. package/dist/suilend-CWugUjwd.js +85 -0
  25. package/dist/suilend-CWugUjwd.js.map +1 -0
  26. package/dist/transaction-result.d.ts +7 -0
  27. package/dist/transaction-result.d.ts.map +1 -0
  28. package/dist/transport.d.ts +3 -3
  29. package/dist/transport.d.ts.map +1 -1
  30. package/dist/types.d.ts +57 -0
  31. package/dist/types.d.ts.map +1 -1
  32. package/package.json +36 -12
  33. package/dist/index.cjs.js +0 -2
  34. package/dist/index.cjs.js.map +0 -1
package/dist/index.esm.js CHANGED
@@ -1,70 +1,12 @@
1
- import { getFullnodeUrl as ct, SuiClient as ut } from "@mysten/sui/client";
2
- import dt from "mitt";
3
- import wt from "axios";
4
- import { withSingleton as W, getCoins as X, mergeCoinsPTB as C, getPriceFeeds as L, updateOraclePricesPTB as Q, filterPriceFeeds as K, depositCoinPTB as O, getFlashLoanAsset as Y, flashloanPTB as Z, repayFlashLoanPTB as tt, borrowCoinPTB as et, withdrawCoinPTB as nt, repayCoinPTB as at, getPools as ht, getPool as P, getHealthFactor as ft, liquidatePTB as gt, getUserAvailableLendingRewards as G, getUserClaimedRewardHistory as pt, claimLendingRewardsPTB as mt, getLendingState as Ct, createAccountCapPTB as bt, withCache as st, parseTxValue as x } from "@naviprotocol/lending";
5
- import E, { BigNumber as M } from "bignumber.js";
6
- import { normalizeStructTag as m } from "@mysten/sui/utils";
7
- import { Transaction as f } from "@mysten/sui/transactions";
8
- import { buildSwapPTBFromQuote as $, generateRefId as yt, getQuote as Pt } from "@naviprotocol/astros-aggregator-sdk";
9
- import { SuilendClient as z, LENDING_MARKET_ID as Bt, LENDING_MARKET_TYPE as H, parseReserve as Tt, parseObligation as vt } from "@suilend/sdk";
10
- import { getCoinMetadataMap as Et, MAX_U64 as Rt } from "@suilend/sui-fe";
11
- import { executeAuction as St } from "shio-sdk";
12
- import { Signer as it } from "@mysten/sui/cryptography";
13
- const ot = wt.create({
14
- timeout: 2e4
15
- });
16
- ot.interceptors.response.use(
17
- function(o) {
18
- if (o.data.err)
19
- throw new Error(o.data.err);
20
- if (o.data.error)
21
- throw new Error(o.data.error.message);
22
- return o;
23
- },
24
- function(o) {
25
- return Promise.reject(o);
26
- }
27
- );
28
- class Ot {
29
- /**
30
- * Creates a new custom transport instance
31
- *
32
- * @param rpcUrl - The RPC endpoint URL for the Sui node
33
- */
34
- constructor(t) {
35
- this.requestId = 0, this.rpcUrl = t;
36
- }
37
- /**
38
- * Makes an RPC request to the Sui node
39
- *
40
- * This method formats the request according to JSON-RPC 2.0 specification
41
- * and sends it to the configured RPC endpoint.
42
- *
43
- * @param input - The transport request options containing method and parameters
44
- * @returns Promise<T> - The response data from the RPC call
45
- */
46
- async request(t) {
47
- return this.requestId += 1, (await ot.post(this.rpcUrl, {
48
- jsonrpc: "2.0",
49
- id: this.requestId,
50
- method: t.method,
51
- params: t.params
52
- })).data.result;
53
- }
54
- /**
55
- * Subscribe to events (not implemented)
56
- *
57
- * This method is required by the SuiTransport interface but is not
58
- * implemented in this custom transport. It throws an error if called.
59
- *
60
- * @returns Promise<() => Promise<boolean>> - Unsubscribe function
61
- * @throws Error - Always throws "subscribe not implemented" error
62
- */
63
- async subscribe() {
64
- throw new Error("subscribe not implemented.");
65
- }
66
- }
67
- class A {
1
+ import gt from "mitt";
2
+ import { withSingleton as M, getCoins as tt, mergeCoinsPTB as p, getPriceFeeds as Q, updateOraclePricesPTB as $, filterPriceFeeds as q, depositCoinPTB as x, getFlashLoanAsset as et, flashloanPTB as nt, repayFlashLoanPTB as at, borrowCoinPTB as it, withdrawCoinPTB as st, repayCoinPTB as ot, getPools as pt, getPool as T, getHealthFactor as mt, liquidatePTB as Ct, getUserAvailableLendingRewards as H, getUserClaimedRewardHistory as yt, claimLendingRewardsPTB as bt, getLendingState as vt, createAccountCapPTB as Bt, withCache as rt, resolveNaviOpenApiEndpoint as lt, buildNaviOpenApiUrl as ct, mergeServiceHeaders as ut, parseTxValue as k, createNaviSuiClientBundle as Tt, createNaviLegacyJsonRpcClient as Pt } from "@naviprotocol/lending";
3
+ import O, { BigNumber as L } from "bignumber.js";
4
+ import { normalizeStructTag as v, fromBase64 as ht } from "@mysten/sui/utils";
5
+ import { Transaction as h } from "@mysten/sui/transactions";
6
+ import { buildSwapPTBFromQuote as z, generateRefId as St, getQuote as Ot } from "@naviprotocol/astros-aggregator-sdk";
7
+ import { executeAuction as Et } from "shio-sdk";
8
+ import { Signer as dt } from "@mysten/sui/cryptography";
9
+ class j {
68
10
  /**
69
11
  * Gets the current configuration for this module
70
12
  *
@@ -82,8 +24,8 @@ class A {
82
24
  * @param event - The event name to emit
83
25
  * @param data - The event data to emit
84
26
  */
85
- emit(t, e) {
86
- this.walletClient?.events.emit(t, e);
27
+ emit(t, n) {
28
+ this.walletClient?.events.emit(t, n);
87
29
  }
88
30
  /**
89
31
  * Installs this module into a wallet client
@@ -106,26 +48,28 @@ class A {
106
48
  this.walletClient = void 0;
107
49
  }
108
50
  }
109
- class R {
51
+ class E {
110
52
  /**
111
53
  * Creates a new user portfolio
112
54
  *
113
55
  * @param coins - Array of coin objects or existing portfolio to copy from
114
56
  */
115
57
  constructor(t) {
116
- if (t instanceof R)
58
+ if (t instanceof E)
117
59
  this.balances = JSON.parse(JSON.stringify(t.balances));
118
60
  else {
119
- const e = {};
120
- t?.forEach((n) => {
121
- const s = m(n.coinType);
122
- let a = e[s];
61
+ const n = {};
62
+ t?.forEach((e) => {
63
+ if (!e.coinType || e.balance === void 0 || e.balance === null)
64
+ return;
65
+ const s = v(e.coinType);
66
+ let a = n[s];
123
67
  a || (a = {
124
68
  coinType: s,
125
- amount: M(0),
69
+ amount: L(0),
126
70
  coins: []
127
- }, e[s] = a), a.coins.push(n), a.amount = a.amount.plus(n.balance);
128
- }), this.balances = e;
71
+ }, n[s] = a), a.coins.push(e), a.amount = a.amount.plus(e.balance);
72
+ }), this.balances = n;
129
73
  }
130
74
  }
131
75
  /**
@@ -135,7 +79,7 @@ class R {
135
79
  * @returns UserCoinBalance object with coin type, total amount, and coin objects
136
80
  */
137
81
  getBalance(t) {
138
- return t = m(t), this.balances[t] || { coinType: t, amount: M(0), coins: [] };
82
+ return t = v(t), this.balances[t] || { coinType: t, amount: L(0), coins: [] };
139
83
  }
140
84
  /**
141
85
  * Gets all coin types in the portfolio
@@ -152,7 +96,7 @@ class R {
152
96
  * @returns BigNumber representing the total balance
153
97
  */
154
98
  balanceOf(t) {
155
- return t = m(t), this.getBalance(t)?.amount || M(0);
99
+ return t = v(t), this.getBalance(t)?.amount || L(0);
156
100
  }
157
101
  /**
158
102
  * Creates a deep copy of the portfolio
@@ -163,22 +107,22 @@ class R {
163
107
  * @returns New UserPortfolio instance with copied data
164
108
  */
165
109
  clone() {
166
- const t = JSON.parse(JSON.stringify(this.balances)), e = new R();
167
- return e.balances = t, e;
110
+ const t = JSON.parse(JSON.stringify(this.balances)), n = new E();
111
+ return n.balances = t, n;
168
112
  }
169
113
  }
170
- class At extends A {
114
+ class Rt extends j {
171
115
  constructor() {
172
116
  super(...arguments), this.name = "balance", this.defaultConfig = {
173
117
  coinPollingInterval: 6e3,
174
118
  disableCoinPolling: !1
175
- }, this.updatePortfolio = W(async () => {
119
+ }, this.updatePortfolio = M(async () => {
176
120
  if (!this.walletClient)
177
121
  throw new Error("Wallet client not found");
178
- this._coins = await X(this.walletClient.address, {
122
+ this._coins = await tt(this.walletClient.address, {
179
123
  client: this.walletClient.client
180
- }), this._portfolio = new R(this._coins), this.emit("balance:portfolio-updated", {});
181
- }), this._coins = [], this._portfolio = new R(), this.pollingTimer = null, this._updatePromise = null;
124
+ }), this._portfolio = new E(this._coins), this.emit("balance:portfolio-updated", {});
125
+ }), this._coins = [], this._portfolio = new E(), this.pollingTimer = null, this._updatePromise = null;
182
126
  }
183
127
  /**
184
128
  * Gets the current coin objects from the wallet
@@ -216,8 +160,8 @@ class At extends A {
216
160
  * @param options - Optional parameters including dry run mode
217
161
  * @returns Transaction response or dry run response
218
162
  */
219
- async sendCoin(t, e, n, s) {
220
- return this.sendCoinBatch(t, [e], [n], s);
163
+ async sendCoin(t, n, e, s) {
164
+ return this.sendCoinBatch(t, [n], [e], s);
221
165
  }
222
166
  /**
223
167
  * Sends coins to multiple recipients in a single transaction
@@ -228,25 +172,25 @@ class At extends A {
228
172
  * @param options - Optional parameters including dry run mode
229
173
  * @returns Transaction response or dry run response
230
174
  */
231
- async sendCoinBatch(t, e, n, s) {
175
+ async sendCoinBatch(t, n, e, s) {
232
176
  if (!this.walletClient)
233
177
  throw new Error("Wallet client not found");
234
- if (e.length !== n.length)
178
+ if (n.length !== e.length)
235
179
  throw new Error("Recipients and amounts must have the same length");
236
180
  await this.waitForUpdate();
237
- const a = this.portfolio.getBalance(t), l = n.reduce((g, h) => g.plus(h), E(0));
238
- if (a.amount.lt(l))
181
+ const a = this.portfolio.getBalance(t), r = e.reduce((w, d) => w.plus(d), O(0));
182
+ if (a.amount.lt(r))
239
183
  throw new Error("Insufficient balance");
240
- const i = new f();
241
- let r = i.gas;
242
- m(t) !== m("0x2::sui::SUI") && (r = C(i, a.coins, {
243
- balance: l.toNumber()
184
+ const o = new h();
185
+ let l = o.gas;
186
+ v(t) !== v("0x2::sui::SUI") && (l = p(o, a.coins, {
187
+ balance: r.toNumber()
244
188
  }));
245
- const w = i.splitCoins(r, n);
246
- return e.forEach((g, h) => {
247
- i.transferObjects([w[h]], g);
189
+ const c = o.splitCoins(l, e);
190
+ return n.forEach((w, d) => {
191
+ o.transferObjects([c[d]], w);
248
192
  }), await this.walletClient.signExecuteTransaction({
249
- transaction: i,
193
+ transaction: o,
250
194
  dryRun: s?.dryRun ?? !1
251
195
  });
252
196
  }
@@ -258,8 +202,8 @@ class At extends A {
258
202
  * @param options - Optional parameters including dry run mode
259
203
  * @returns Transaction response or dry run response
260
204
  */
261
- async transferObject(t, e, n) {
262
- return this.transferObjectBatch([t], [e], n);
205
+ async transferObject(t, n, e) {
206
+ return this.transferObjectBatch([t], [n], e);
263
207
  }
264
208
  /**
265
209
  * Transfers multiple objects to their respective recipients in a single transaction
@@ -272,18 +216,18 @@ class At extends A {
272
216
  * @param options - Optional parameters including dry run mode
273
217
  * @returns Transaction response or dry run response
274
218
  */
275
- async transferObjectBatch(t, e, n) {
219
+ async transferObjectBatch(t, n, e) {
276
220
  if (!this.walletClient)
277
221
  throw new Error("Wallet client not found");
278
- if (t.length !== e.length)
222
+ if (t.length !== n.length)
279
223
  throw new Error("Objects and recipients must have the same length");
280
224
  await this.waitForUpdate();
281
- const s = new f();
282
- return t.forEach((l, i) => {
283
- s.transferObjects([s.object(l)], e[i]);
225
+ const s = new h();
226
+ return t.forEach((r, o) => {
227
+ s.transferObjects([s.object(r)], n[o]);
284
228
  }), await this.walletClient.signExecuteTransaction({
285
229
  transaction: s,
286
- dryRun: n?.dryRun ?? !1
230
+ dryRun: e?.dryRun ?? !1
287
231
  });
288
232
  }
289
233
  /**
@@ -293,15 +237,14 @@ class At extends A {
293
237
  * interval, ensuring regular balance updates.
294
238
  */
295
239
  async startPolling() {
296
- try {
297
- if (this.config.disableCoinPolling)
298
- return;
299
- await this.updatePortfolio();
300
- } catch (t) {
301
- console.error(t);
302
- } finally {
303
- this.pollingTimer = setTimeout(this.startPolling, this.config.coinPollingInterval);
304
- }
240
+ if (!this.config.disableCoinPolling)
241
+ try {
242
+ await this.updatePortfolio();
243
+ } catch (t) {
244
+ console.error(t);
245
+ } finally {
246
+ this.pollingTimer = setTimeout(this.startPolling, this.config.coinPollingInterval);
247
+ }
305
248
  }
306
249
  /**
307
250
  * Installs the balance module into a wallet client
@@ -309,9 +252,9 @@ class At extends A {
309
252
  * @param walletClient - The wallet client instance to install into
310
253
  */
311
254
  install(t) {
312
- super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((e) => {
255
+ super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((n) => {
313
256
  t.events.on("balance:portfolio-updated", () => {
314
- e();
257
+ n();
315
258
  });
316
259
  });
317
260
  }
@@ -324,278 +267,260 @@ class At extends A {
324
267
  super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
325
268
  }
326
269
  }
327
- async function D(o, t, e, n) {
270
+ async function D(i, t, n, e) {
328
271
  if (!this.walletClient)
329
272
  throw new Error("Wallet client not found");
330
- const s = await this.getPool(t), a = await this.getPool(e), l = await this.getLendingState(), i = this.walletClient.address, r = n?.protocol ?? "navi", w = await this.getProtocol(r);
331
- if (!w)
332
- throw new Error(`Protocol ${r} not found`);
333
- const u = await w.getPool(s.coinType);
273
+ const s = await this.getPool(t), a = await this.getPool(n), r = await this.getLendingState(), o = this.walletClient.address, l = e?.protocol ?? "navi", c = await this.getProtocol(l);
274
+ if (!c)
275
+ throw new Error(`Protocol ${l} not found`);
276
+ const u = await c.getPool(s.coinType);
334
277
  if (console.log("migrateBetweenSupplyPTB", {
335
278
  fromPoolLending: u
336
- }), r === "navi" && u.supplyBalance === 0)
279
+ }), l === "navi" && u.supplyBalance === 0)
337
280
  throw new Error("No supply balance");
338
- if (n?.amount && n.amount > u.supplyBalance)
281
+ if (e?.amount && e.amount > u.supplyBalance)
339
282
  throw new Error("Amount is less than supply balance");
340
- const g = n?.slippage ?? 5e-3, h = n?.amount ?? Number(u.supplyBalance), p = await L(), c = await Promise.all([s, a]);
341
- if (await Q(
342
- o,
343
- K(p, {
344
- lendingState: l,
345
- pools: c
346
- })
347
- ), r !== "navi" && s.id === a.id) {
348
- const U = await w.withdrawCoinPTB(
349
- o,
283
+ const w = e?.slippage ?? 5e-3, d = e?.amount ?? Number(u.supplyBalance), f = await Q(this.naviServiceOptions), m = await Promise.all([s, a]);
284
+ if (await $(
285
+ i,
286
+ q(f, {
287
+ lendingState: r,
288
+ pools: m
289
+ }),
290
+ this.naviServiceOptions
291
+ ), l !== "navi" && s.id === a.id) {
292
+ const J = await c.withdrawCoinPTB(
293
+ i,
350
294
  s.suiCoinType,
351
- h
295
+ d
352
296
  );
353
- return await O(o, a, U, {
354
- amount: h
355
- }), o;
297
+ return await x(i, a, J, {
298
+ ...this.naviServiceOptions,
299
+ amount: d
300
+ }), i;
356
301
  }
357
- const d = await Y(a, {
302
+ const C = await et(a, {
303
+ ...this.naviServiceOptions,
358
304
  env: this.config.env
359
305
  });
360
- if (!d)
306
+ if (!C)
361
307
  throw new Error(`${a.token.symbol} pool not support flashloan`);
362
308
  const y = await this.walletClient.swap.getQuote(
363
309
  s.suiCoinType,
364
310
  a.suiCoinType,
365
- h
366
- ), B = Number(y.amount_out);
367
- if (B <= 0)
311
+ d
312
+ ), g = Number(y.amount_out);
313
+ if (g <= 0)
368
314
  throw new Error("The amount of swapAmountOut must be greater than 0.");
369
- const S = Math.floor(B * (1 - g)), b = Math.floor(S / (1 + d.flashloanFee));
315
+ const B = Math.floor(g * (1 - w)), b = Math.floor(B / (1 + C.flashloanFee));
370
316
  if (b <= 0)
371
317
  throw new Error("The calculated borrow amount must be positive.");
372
- const [T, v] = await Z(o, a, b), [k] = o.moveCall({
318
+ const [P, S] = await nt(
319
+ i,
320
+ a,
321
+ b,
322
+ this.naviServiceOptions
323
+ ), [F] = i.moveCall({
373
324
  target: "0x2::coin::from_balance",
374
- arguments: [T],
325
+ arguments: [P],
375
326
  typeArguments: [a.suiCoinType]
376
327
  });
377
- await O(o, a, k, {
328
+ await x(i, a, F, {
329
+ ...this.naviServiceOptions,
378
330
  amount: b
379
331
  });
380
- const N = await w.withdrawCoinPTB(o, s.suiCoinType, h), F = await $(
381
- i,
332
+ const N = await c.withdrawCoinPTB(i, s.suiCoinType, d), _ = await z(
382
333
  o,
383
- S,
334
+ i,
335
+ B,
384
336
  N,
385
337
  y
386
- ), _ = o.moveCall({
338
+ ), U = i.moveCall({
387
339
  target: "0x2::coin::into_balance",
388
- arguments: [F],
340
+ arguments: [_],
389
341
  typeArguments: [a.suiCoinType]
390
- }), [j] = await tt(o, a, v, _), [I] = o.moveCall({
342
+ }), [W] = await at(
343
+ i,
344
+ a,
345
+ S,
346
+ U,
347
+ this.naviServiceOptions
348
+ ), [I] = i.moveCall({
391
349
  target: "0x2::coin::from_balance",
392
- arguments: [j],
350
+ arguments: [W],
393
351
  typeArguments: [a.suiCoinType]
394
352
  });
395
- return await O(o, a, I), o;
353
+ return await x(i, a, I, this.naviServiceOptions), i;
396
354
  }
397
- async function J(o, t, e, n) {
355
+ async function V(i, t, n, e) {
398
356
  if (!this.walletClient)
399
357
  throw new Error("Wallet client not found");
400
- const s = this.walletClient.address, a = await this.getPool(t), l = await this.getPool(e), i = await this.getLendingState(), r = n?.protocol ?? "navi", w = await this.getProtocol(r);
401
- if (!w)
402
- throw new Error(`Protocol ${r} not found`);
403
- const u = await w.getPool(a.coinType);
358
+ const s = this.walletClient.address, a = await this.getPool(t), r = await this.getPool(n), o = await this.getLendingState(), l = e?.protocol ?? "navi", c = await this.getProtocol(l);
359
+ if (!c)
360
+ throw new Error(`Protocol ${l} not found`);
361
+ const u = await c.getPool(a.coinType);
404
362
  if (console.log("migrateBetweenBorrowPTB", {
405
363
  fromPoolLending: u
406
364
  }), u.borrowBalance === 0)
407
365
  throw new Error("No borrow balance");
408
- if (n?.amount && n.amount > u.borrowBalance)
366
+ if (e?.amount && e.amount > u.borrowBalance)
409
367
  throw new Error("Amount is more than borrow balance");
410
- const g = await L(), h = await Promise.all([a, l]);
411
- await Q(
412
- o,
413
- K(g, {
414
- lendingState: i,
415
- pools: h
416
- })
368
+ const w = await Q(this.naviServiceOptions), d = await Promise.all([a, r]);
369
+ await $(
370
+ i,
371
+ q(w, {
372
+ lendingState: o,
373
+ pools: d
374
+ }),
375
+ this.naviServiceOptions
417
376
  );
418
- let p = n?.amount ?? Number(u.borrowBalance);
419
- if (Number(u.borrowBalance) === p) {
420
- const rt = u.borrowAPR / 100;
421
- p = Math.ceil(
422
- new E(p).multipliedBy(rt * (60 * 3) / (365 * 24 * 3600)).plus(new E(1).shiftedBy(-a.token.decimals)).plus(p).toNumber()
377
+ let f = e?.amount ?? Number(u.borrowBalance);
378
+ if (Number(u.borrowBalance) === f) {
379
+ const ft = u.borrowAPR / 100;
380
+ f = Math.ceil(
381
+ new O(f).multipliedBy(ft * (60 * 3) / (365 * 24 * 3600)).plus(new O(1).shiftedBy(-a.token.decimals)).plus(f).toNumber()
423
382
  );
424
383
  }
425
- const c = await Y(a, {
384
+ const m = await et(a, {
385
+ ...this.naviServiceOptions,
426
386
  env: this.config.env
427
387
  });
428
- if (!c)
388
+ if (!m)
429
389
  throw new Error(`${a.token.symbol} pool not support flashloan`);
430
390
  if (!this.walletClient)
431
391
  throw new Error("Wallet client not found");
432
- const d = n?.slippage ?? 5e-3, y = Math.ceil(p * (1 + c.flashloanFee)), B = y, S = await this.walletClient.swap.getQuote(
392
+ const C = e?.slippage ?? 5e-3, y = Math.ceil(f * (1 + m.flashloanFee)), g = y, B = await this.walletClient.swap.getQuote(
433
393
  a.suiCoinType,
434
- l.suiCoinType,
435
- B
394
+ r.suiCoinType,
395
+ g
436
396
  );
437
- let b = 1 + d, T = Math.ceil(Number(S.amount_out) * b), v = await this.walletClient.swap.getQuote(
438
- l.suiCoinType,
397
+ let b = 1 + C, P = Math.ceil(Number(B.amount_out) * b), S = await this.walletClient.swap.getQuote(
398
+ r.suiCoinType,
439
399
  a.suiCoinType,
440
- T
400
+ P
441
401
  );
442
- for (; Number(v.amount_out) < B; )
443
- b = b * Math.max(B / Number(v.amount_out), 1.001), T = Math.ceil(Number(S.amount_out) * b), v = await this.walletClient.swap.getQuote(
444
- l.suiCoinType,
402
+ for (; Number(S.amount_out) < g; )
403
+ b = b * Math.max(g / Number(S.amount_out), 1.001), P = Math.ceil(Number(B.amount_out) * b), S = await this.walletClient.swap.getQuote(
404
+ r.suiCoinType,
445
405
  a.suiCoinType,
446
- T
406
+ P
447
407
  );
448
- const [k, N] = await Z(o, a, p), [F] = o.moveCall({
408
+ const [F, N] = await nt(
409
+ i,
410
+ a,
411
+ f,
412
+ this.naviServiceOptions
413
+ ), [_] = i.moveCall({
449
414
  target: "0x2::coin::from_balance",
450
- arguments: [k],
415
+ arguments: [F],
451
416
  typeArguments: [a.suiCoinType]
452
417
  });
453
- await w.repayCoinPTB(o, a.suiCoinType, F, p);
454
- const _ = await et(o, l, T), j = await $(
418
+ await c.repayCoinPTB(i, a.suiCoinType, _, f);
419
+ const U = await it(i, r, P, this.naviServiceOptions), W = await z(
455
420
  s,
456
- o,
421
+ i,
457
422
  y,
458
- _,
459
- v
460
- ), I = o.moveCall({
423
+ U,
424
+ S
425
+ ), I = i.moveCall({
461
426
  target: "0x2::coin::into_balance",
462
- arguments: [j],
427
+ arguments: [W],
463
428
  typeArguments: [a.suiCoinType]
464
- }), [U] = await tt(o, a, N, I), [lt] = o.moveCall({
429
+ }), [J] = await at(
430
+ i,
431
+ a,
432
+ N,
433
+ I,
434
+ this.naviServiceOptions
435
+ ), [wt] = i.moveCall({
465
436
  target: "0x2::coin::from_balance",
466
- arguments: [U],
437
+ arguments: [J],
467
438
  typeArguments: [a.suiCoinType]
468
439
  });
469
- return o.transferObjects([lt], s), o;
440
+ return i.transferObjects([wt], s), i;
470
441
  }
471
- async function V(o, t, e, n) {
442
+ async function X(i, t, n, e) {
472
443
  if (!this.walletClient)
473
444
  throw new Error("Wallet client not found");
474
- const s = await X(this.walletClient.address, {
445
+ const s = await tt(this.walletClient.address, {
475
446
  client: this.walletClient.client,
476
447
  coinType: t
477
- }), a = await this.getPool(e), i = new R(s).getBalance(t);
478
- if (i.amount.eq(0))
448
+ }), a = await this.getPool(n), o = new E(s).getBalance(t);
449
+ if (o.amount.eq(0))
479
450
  throw new Error(`No balance of ${t}`);
480
451
  if (console.log("migrateBalanceToSupplyPTB", {
481
- balance: i.amount.toNumber()
482
- }), n?.amount && i.amount.lt(n.amount))
452
+ balance: o.amount.toNumber()
453
+ }), e?.amount && o.amount.lt(e.amount))
483
454
  throw new Error("Amount is greater than balance");
484
- const r = n?.amount ?? i.amount.toNumber(), w = n?.slippage ?? 5e-3;
485
- let u = await C(o, i.coins, {
486
- balance: r,
455
+ const l = e?.amount ?? o.amount.toNumber(), c = e?.slippage ?? 5e-3;
456
+ let u = await p(i, o.coins, {
457
+ balance: l,
487
458
  useGasCoin: !0
488
459
  });
489
- if (m(t) !== m(a.suiCoinType)) {
490
- const g = await this.walletClient.swap.getQuote(t, a.suiCoinType, r);
460
+ if (v(t) !== v(a.suiCoinType)) {
461
+ const w = await this.walletClient.swap.getQuote(t, a.suiCoinType, l);
491
462
  u = await this.walletClient.swap.buildSwapPTBFromQuote(
492
- o,
493
- g,
463
+ i,
464
+ w,
494
465
  u,
495
- w
466
+ c
496
467
  );
497
468
  }
498
- return await O(o, a, u), o;
469
+ return await x(i, a, u, this.naviServiceOptions), i;
499
470
  }
500
471
  class xt {
501
472
  constructor(t) {
502
473
  this.name = "navi", this.walletClient = t;
503
474
  }
504
475
  async getPool(t) {
505
- const e = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
506
- (i) => i.pool.suiCoinType === m(t)
507
- ), a = s ? new E(s.supplyBalance).toNumber() : 0, l = s ? new E(s.borrowBalance).toNumber() : 0;
476
+ const n = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
477
+ (o) => o.pool.suiCoinType === v(t)
478
+ ), a = s ? new O(s.supplyBalance).toNumber() : 0, r = s ? new O(s.borrowBalance).toNumber() : 0;
508
479
  return {
509
480
  supplyBalance: a,
510
- borrowBalance: l,
511
- borrowAPR: parseFloat(e.borrowIncentiveApyInfo.apy)
481
+ borrowBalance: r,
482
+ borrowAPR: parseFloat(n.borrowIncentiveApyInfo.apy)
512
483
  };
513
484
  }
514
- async depositCoinPTB(t, e, n, s) {
485
+ async depositCoinPTB(t, n, e, s) {
515
486
  throw new Error("Not implemented");
516
487
  }
517
- async withdrawCoinPTB(t, e, n) {
518
- return nt(t, e, n);
488
+ async withdrawCoinPTB(t, n, e) {
489
+ return st(t, n, e, this.walletClient.lending.naviServiceOptions);
519
490
  }
520
- async borrowCoinPTB(t, e, n) {
491
+ async borrowCoinPTB(t, n, e) {
521
492
  throw new Error("Not implemented");
522
493
  }
523
- async repayCoinPTB(t, e, n, s) {
524
- at(t, e, n, { amount: s });
525
- }
526
- }
527
- class q {
528
- constructor(t, e, n) {
529
- this.name = "suilend", this.walletClient = t, this.obligationOwnerCap = e, this.suilendClient = n;
530
- }
531
- static async create(t) {
532
- const [e, n] = await Promise.all([
533
- z.initialize(Bt, H, t.client),
534
- z.getObligationOwnerCaps(
535
- t.address,
536
- [H],
537
- t.client
538
- )
539
- ]);
540
- if (n.length === 0)
541
- throw new Error("No existing obligations found for wallet address: " + t.address);
542
- return new q(t, n[0], e);
543
- }
544
- async getPool(t) {
545
- const e = m(t), n = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
546
- n.forEach((c) => {
547
- s.add(m(c.coinType.name)), c.depositsPoolRewardManager.poolRewards.forEach((d) => {
548
- d && s.add(m(d.coinType.name));
549
- }), c.borrowsPoolRewardManager.poolRewards.forEach((d) => {
550
- d && s.add(m(d.coinType.name));
551
- });
494
+ async repayCoinPTB(t, n, e, s) {
495
+ ot(t, n, e, {
496
+ ...this.walletClient.lending.naviServiceOptions,
497
+ amount: s
552
498
  });
553
- const a = await Et(Array.from(s)), i = n.map((c) => Tt(c, a)).reduce(
554
- (c, d) => (c[d.coinType] = d, c),
555
- {}
556
- ), r = await this.suilendClient.getObligation(
557
- this.obligationOwnerCap.obligationId
558
- ), w = vt(r, i), u = w.deposits.find((c) => c.coinType === e), g = w.borrows.find((c) => c.coinType === e), h = a[e].decimals;
559
- return {
560
- cTokenExchangeRate: i[e].cTokenExchangeRate.toNumber(),
561
- supplyBalance: u?.depositedAmount.shiftedBy(h).decimalPlaces(0).toNumber() ?? 0,
562
- borrowBalance: g?.borrowedAmount.shiftedBy(h).decimalPlaces(0).toNumber() ?? 0,
563
- borrowAPR: i[e].borrowAprPercent.toNumber()
564
- };
565
- }
566
- async depositCoinPTB(t, e, n, s) {
567
- throw new Error("Not implemented");
568
- }
569
- async withdrawCoinPTB(t, e, n) {
570
- const s = await this.getPool(e), a = n === s.supplyBalance;
571
- return await this.suilendClient.withdraw(
572
- this.obligationOwnerCap.id,
573
- this.obligationOwnerCap.obligationId,
574
- e,
575
- a ? Rt.toString() : Math.ceil(n / s.cTokenExchangeRate).toString(),
576
- t
577
- );
578
- }
579
- async borrowCoinPTB(t, e, n) {
580
- throw new Error("Not implemented");
581
- }
582
- async repayCoinPTB(t, e, n, s) {
583
- this.suilendClient.repay(this.obligationOwnerCap.obligationId, e, n, t), t.transferObjects([n], t.pure.address(this.walletClient.address));
584
499
  }
585
500
  }
586
- class kt extends A {
501
+ class At extends j {
587
502
  constructor() {
588
503
  super(), this.name = "lending", this.defaultConfig = {
589
504
  env: "prod",
590
- protocols: []
591
- }, this._protocols = [], this.migrateBetweenSupplyPTB = D, this.migrateBetweenBorrowPTB = J, this.migrateBalanceToSupplyPTB = V, this.migrateBetweenSupplyPTB = D.bind(this), this.migrateBetweenBorrowPTB = J.bind(this), this.migrateBalanceToSupplyPTB = V.bind(this);
505
+ protocols: [],
506
+ enableSuilend: !0
507
+ }, this._protocols = [], this.migrateBetweenSupplyPTB = D, this.migrateBetweenBorrowPTB = V, this.migrateBalanceToSupplyPTB = X, this.migrateBetweenSupplyPTB = D.bind(this), this.migrateBetweenBorrowPTB = V.bind(this), this.migrateBalanceToSupplyPTB = X.bind(this);
592
508
  }
593
509
  /** Get protocols (either from internal storage or config) */
594
510
  get protocols() {
595
511
  return this._protocols.length > 0 ? this._protocols : this.config.protocols;
596
512
  }
513
+ get naviServiceOptions() {
514
+ const t = this.config.services ?? this.walletClient?.clientBundle.services;
515
+ return {
516
+ ...t ? { services: t } : {}
517
+ };
518
+ }
519
+ install(t) {
520
+ super.install(t), this._protocols = [];
521
+ }
597
522
  async getProtocol(t) {
598
- return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((e) => e.name === t);
523
+ return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((n) => n.name === t);
599
524
  }
600
525
  /**
601
526
  * Gets all available lending pools
@@ -604,7 +529,8 @@ class kt extends A {
604
529
  * @returns Array of pool information
605
530
  */
606
531
  async getPools(t) {
607
- return await ht({
532
+ return await pt({
533
+ ...this.naviServiceOptions,
608
534
  env: this.config.env,
609
535
  ...t
610
536
  });
@@ -616,10 +542,11 @@ class kt extends A {
616
542
  * @param options - Optional caching options
617
543
  * @returns Pool information
618
544
  */
619
- async getPool(t, e) {
620
- return await P(t, {
545
+ async getPool(t, n) {
546
+ return await T(t, {
547
+ ...this.naviServiceOptions,
621
548
  env: this.config.env,
622
- ...e
549
+ ...n
623
550
  });
624
551
  }
625
552
  /**
@@ -630,30 +557,32 @@ class kt extends A {
630
557
  * @param options - Optional parameters including dry run mode and account capability
631
558
  * @returns Transaction response or dry run response
632
559
  */
633
- async deposit(t, e, n) {
560
+ async deposit(t, n, e) {
634
561
  if (!this.walletClient)
635
562
  throw new Error("Wallet client not found");
636
- const s = await P(t, {
563
+ const s = await T(t, {
564
+ ...this.naviServiceOptions,
637
565
  env: this.config.env
638
566
  });
639
567
  await this.walletClient.module("balance").waitForUpdate();
640
- const a = new f(), l = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = C(a, l.coins, {
641
- balance: e,
568
+ const a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = p(a, r.coins, {
569
+ balance: n,
642
570
  useGasCoin: !0
643
571
  });
644
- await O(a, s, i, {
572
+ await x(a, s, o, {
573
+ ...this.naviServiceOptions,
645
574
  env: this.config.env,
646
- amount: e,
647
- accountCap: n?.accountCap
575
+ amount: n,
576
+ accountCap: e?.accountCap
648
577
  });
649
- const r = await this.walletClient.signExecuteTransaction({
578
+ const l = await this.walletClient.signExecuteTransaction({
650
579
  transaction: a,
651
- dryRun: n?.dryRun ?? !1
580
+ dryRun: e?.dryRun ?? !1
652
581
  });
653
- return !n?.dryRun && r.effects?.status?.status === "success" && (this.emit("lending:deposit-success", {
582
+ return !e?.dryRun && l.effects?.status?.status === "success" && (this.emit("lending:deposit-success", {
654
583
  identifier: t,
655
- amount: e
656
- }), this.walletClient.module("balance").updatePortfolio()), r;
584
+ amount: n
585
+ }), this.walletClient.module("balance").updatePortfolio()), l;
657
586
  }
658
587
  /**
659
588
  * Withdraws coins from a lending pool
@@ -663,26 +592,28 @@ class kt extends A {
663
592
  * @param options - Optional parameters including dry run mode and account capability
664
593
  * @returns Transaction response or dry run response
665
594
  */
666
- async withdraw(t, e, n) {
595
+ async withdraw(t, n, e) {
667
596
  if (!this.walletClient)
668
597
  throw new Error("Wallet client not found");
669
- const s = await P(t, {
598
+ const s = await T(t, {
599
+ ...this.naviServiceOptions,
670
600
  env: this.config.env
671
- }), a = new f();
672
- n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
673
- const l = await nt(a, s, e, {
601
+ }), a = new h();
602
+ e?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
603
+ const r = await st(a, s, n, {
604
+ ...this.naviServiceOptions,
674
605
  env: this.config.env,
675
- accountCap: n?.accountCap
606
+ accountCap: e?.accountCap
676
607
  });
677
- a.transferObjects([l], this.walletClient.address);
678
- const i = await this.walletClient.signExecuteTransaction({
608
+ a.transferObjects([r], this.walletClient.address);
609
+ const o = await this.walletClient.signExecuteTransaction({
679
610
  transaction: a,
680
- dryRun: n?.dryRun ?? !1
611
+ dryRun: e?.dryRun ?? !1
681
612
  });
682
- return !n?.dryRun && i.effects?.status?.status === "success" && (this.emit("lending:withdraw-success", {
613
+ return !e?.dryRun && o.effects?.status?.status === "success" && (this.emit("lending:withdraw-success", {
683
614
  identifier: t,
684
- amount: e
685
- }), this.walletClient.module("balance").updatePortfolio()), i;
615
+ amount: n
616
+ }), this.walletClient.module("balance").updatePortfolio()), o;
686
617
  }
687
618
  /**
688
619
  * Borrows coins from a lending pool
@@ -692,26 +623,28 @@ class kt extends A {
692
623
  * @param options - Optional parameters including dry run mode and account capability
693
624
  * @returns Transaction response or dry run response
694
625
  */
695
- async borrow(t, e, n) {
626
+ async borrow(t, n, e) {
696
627
  if (!this.walletClient)
697
628
  throw new Error("Wallet client not found");
698
- const s = await P(t, {
629
+ const s = await T(t, {
630
+ ...this.naviServiceOptions,
699
631
  env: this.config.env
700
- }), a = new f();
701
- n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
702
- const l = await et(a, s, e, {
632
+ }), a = new h();
633
+ e?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
634
+ const r = await it(a, s, n, {
635
+ ...this.naviServiceOptions,
703
636
  env: this.config.env,
704
- accountCap: n?.accountCap
637
+ accountCap: e?.accountCap
705
638
  });
706
- a.transferObjects([l], this.walletClient.address);
707
- const i = await this.walletClient.signExecuteTransaction({
639
+ a.transferObjects([r], this.walletClient.address);
640
+ const o = await this.walletClient.signExecuteTransaction({
708
641
  transaction: a,
709
- dryRun: n?.dryRun ?? !1
642
+ dryRun: e?.dryRun ?? !1
710
643
  });
711
- return !n?.dryRun && i.effects?.status?.status === "success" && (this.emit("lending:borrow-success", {
644
+ return !e?.dryRun && o.effects?.status?.status === "success" && (this.emit("lending:borrow-success", {
712
645
  identifier: t,
713
- amount: e
714
- }), this.walletClient.module("balance").updatePortfolio()), i;
646
+ amount: n
647
+ }), this.walletClient.module("balance").updatePortfolio()), o;
715
648
  }
716
649
  /**
717
650
  * Repays borrowed coins to a lending pool
@@ -721,29 +654,31 @@ class kt extends A {
721
654
  * @param options - Optional parameters including dry run mode and account capability
722
655
  * @returns Transaction response or dry run response
723
656
  */
724
- async repay(t, e, n) {
657
+ async repay(t, n, e) {
725
658
  if (!this.walletClient)
726
659
  throw new Error("Wallet client not found");
727
660
  await this.walletClient.module("balance").waitForUpdate();
728
- const s = await P(t, {
661
+ const s = await T(t, {
662
+ ...this.naviServiceOptions,
729
663
  env: this.config.env
730
- }), a = new f(), l = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = C(a, l.coins, {
731
- balance: e,
664
+ }), a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = p(a, r.coins, {
665
+ balance: n,
732
666
  useGasCoin: !0
733
667
  });
734
- await at(a, s, i, {
668
+ await ot(a, s, o, {
669
+ ...this.naviServiceOptions,
735
670
  env: this.config.env,
736
- amount: e,
737
- accountCap: n?.accountCap
671
+ amount: n,
672
+ accountCap: e?.accountCap
738
673
  });
739
- const r = await this.walletClient.signExecuteTransaction({
674
+ const l = await this.walletClient.signExecuteTransaction({
740
675
  transaction: a,
741
- dryRun: n?.dryRun ?? !1
676
+ dryRun: e?.dryRun ?? !1
742
677
  });
743
- return !n?.dryRun && r.effects?.status?.status === "success" && (this.emit("lending:repay-success", {
678
+ return !e?.dryRun && l.effects?.status?.status === "success" && (this.emit("lending:repay-success", {
744
679
  identifier: t,
745
- amount: e
746
- }), this.walletClient.module("balance").updatePortfolio()), r;
680
+ amount: n
681
+ }), this.walletClient.module("balance").updatePortfolio()), l;
747
682
  }
748
683
  /**
749
684
  * Gets the current health factor for the user
@@ -754,7 +689,8 @@ class kt extends A {
754
689
  if (!this.walletClient)
755
690
  throw new Error("Wallet client not found");
756
691
  const t = this.walletClient.address;
757
- return await ft(t, {
692
+ return await mt(t, {
693
+ ...this.naviServiceOptions,
758
694
  env: this.config.env,
759
695
  client: this.walletClient.client
760
696
  });
@@ -769,45 +705,48 @@ class kt extends A {
769
705
  * @param options - Optional parameters including dry run mode
770
706
  * @returns Transaction response or dry run response
771
707
  */
772
- async liquidate(t, e, n, s, a) {
708
+ async liquidate(t, n, e, s, a) {
773
709
  if (!this.walletClient)
774
710
  throw new Error("Wallet client not found");
775
- const l = await P(t, {
711
+ const r = await T(t, {
712
+ ...this.naviServiceOptions,
776
713
  env: this.config.env
777
- }), i = await P(n, {
714
+ }), o = await T(e, {
715
+ ...this.naviServiceOptions,
778
716
  env: this.config.env
779
- }), r = new f(), w = this.walletClient.module("balance").portfolio.getBalance(l.suiCoinType), u = C(r, w.coins, {
780
- balance: e,
717
+ }), l = new h(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u = p(l, c.coins, {
718
+ balance: n,
781
719
  useGasCoin: !0
782
- }), [g, h] = await gt(
783
- r,
720
+ }), [w, d] = await Ct(
784
721
  l,
722
+ r,
785
723
  u,
786
- i,
724
+ o,
787
725
  s,
788
726
  {
727
+ ...this.naviServiceOptions,
789
728
  env: this.config.env
790
729
  }
791
- ), [p] = r.moveCall({
730
+ ), [f] = l.moveCall({
792
731
  target: "0x2::coin::from_balance",
793
- arguments: [g],
794
- typeArguments: [i.suiCoinType]
795
- }), [c] = r.moveCall({
732
+ arguments: [w],
733
+ typeArguments: [o.suiCoinType]
734
+ }), [m] = l.moveCall({
796
735
  target: "0x2::coin::from_balance",
797
- arguments: [h],
798
- typeArguments: [l.suiCoinType]
736
+ arguments: [d],
737
+ typeArguments: [r.suiCoinType]
799
738
  });
800
- r.transferObjects([p, c], this.walletClient.address);
801
- const d = await this.walletClient.signExecuteTransaction({
802
- transaction: r,
739
+ l.transferObjects([f, m], this.walletClient.address);
740
+ const C = await this.walletClient.signExecuteTransaction({
741
+ transaction: l,
803
742
  dryRun: a?.dryRun ?? !1
804
743
  });
805
- return !a?.dryRun && d.effects?.status?.status === "success" && (this.emit("lending:liquidate-success", {
744
+ return !a?.dryRun && C.effects?.status?.status === "success" && (this.emit("lending:liquidate-success", {
806
745
  payIdentifier: t,
807
- payAmount: e,
808
- collateralIdentifier: n,
746
+ payAmount: n,
747
+ collateralIdentifier: e,
809
748
  liquidationAddress: s
810
- }), this.walletClient.module("balance").updatePortfolio()), d;
749
+ }), this.walletClient.module("balance").updatePortfolio()), C;
811
750
  }
812
751
  /**
813
752
  * Gets the available lending rewards for the current user.
@@ -819,7 +758,8 @@ class kt extends A {
819
758
  async getAvailableRewards(t) {
820
759
  if (!this.walletClient)
821
760
  throw new Error("Wallet client not found");
822
- return G(this.walletClient.address, {
761
+ return H(this.walletClient.address, {
762
+ ...this.naviServiceOptions,
823
763
  ...t,
824
764
  env: this.config.env
825
765
  });
@@ -834,7 +774,8 @@ class kt extends A {
834
774
  async getClaimedRewardHistory(t) {
835
775
  if (!this.walletClient)
836
776
  throw new Error("Wallet client not found");
837
- return pt(this.walletClient.address, {
777
+ return yt(this.walletClient.address, {
778
+ ...this.naviServiceOptions,
838
779
  ...t
839
780
  });
840
781
  }
@@ -847,31 +788,35 @@ class kt extends A {
847
788
  async claimAllRewards(t) {
848
789
  if (!this.walletClient)
849
790
  throw new Error("Wallet client not found");
850
- const e = new f(), n = await G(this.walletClient.address, {
791
+ const n = new h(), e = await H(this.walletClient.address, {
792
+ ...this.naviServiceOptions,
851
793
  env: this.config.env
852
794
  });
853
- await mt(e, n, {
795
+ await bt(n, e, {
796
+ ...this.naviServiceOptions,
854
797
  env: this.config.env,
855
798
  accountCap: t?.accountCap
856
799
  });
857
800
  const s = await this.walletClient.signExecuteTransaction({
858
- transaction: e,
801
+ transaction: n,
859
802
  dryRun: t?.dryRun ?? !1
860
803
  });
861
804
  return !t?.dryRun && s.effects?.status?.status === "success" && (this.emit("lending:claim-rewards-success", {
862
- rewards: n
805
+ rewards: e
863
806
  }), this.walletClient.module("balance").updatePortfolio()), s;
864
807
  }
865
- async updateOraclePTB(t, e) {
866
- const n = await L({
808
+ async updateOraclePTB(t, n) {
809
+ const e = await Q({
810
+ ...this.naviServiceOptions,
867
811
  env: this.config.env
868
812
  }), s = await this.getLendingState({
869
813
  cacheTime: 60 * 1e3
870
- }), a = K(n, {
814
+ }), a = q(e, {
871
815
  lendingState: s,
872
- pools: e
816
+ pools: n
873
817
  });
874
- await Q(t, a, {
818
+ await $(t, a, {
819
+ ...this.naviServiceOptions,
875
820
  env: this.config.env,
876
821
  updatePythPriceFeeds: !0
877
822
  });
@@ -886,9 +831,9 @@ class kt extends A {
886
831
  async updateOracle(t) {
887
832
  if (!this.walletClient)
888
833
  throw new Error("Wallet client not found");
889
- const e = new f();
890
- return await this.updateOraclePTB(e, t?.pools), await this.walletClient.signExecuteTransaction({
891
- transaction: e,
834
+ const n = new h();
835
+ return await this.updateOraclePTB(n, t?.pools), await this.walletClient.signExecuteTransaction({
836
+ transaction: n,
892
837
  dryRun: t?.dryRun ?? !1
893
838
  });
894
839
  }
@@ -901,7 +846,8 @@ class kt extends A {
901
846
  async getLendingState(t) {
902
847
  if (!this.walletClient)
903
848
  throw new Error("Wallet client not found");
904
- return await Ct(this.walletClient.address, {
849
+ return await vt(this.walletClient.address, {
850
+ ...this.naviServiceOptions,
905
851
  env: this.config.env,
906
852
  ...t,
907
853
  client: this.walletClient.client
@@ -916,9 +862,9 @@ class kt extends A {
916
862
  async createAccountCap(t) {
917
863
  if (!this.walletClient)
918
864
  throw new Error("Wallet client not found");
919
- const e = new f(), n = await bt(e);
920
- return e.transferObjects([n], this.walletClient.address), await this.walletClient.signExecuteTransaction({
921
- transaction: e,
865
+ const n = new h(), e = await Bt(n);
866
+ return n.transferObjects([e], this.walletClient.address), await this.walletClient.signExecuteTransaction({
867
+ transaction: n,
922
868
  dryRun: t?.dryRun ?? !1
923
869
  });
924
870
  }
@@ -928,26 +874,42 @@ class kt extends A {
928
874
  return;
929
875
  }
930
876
  const t = [];
931
- t.push(new xt(this.walletClient));
932
- try {
933
- t.push(await q.create(this.walletClient));
934
- } catch (e) {
935
- console.warn("Failed to initialize SuilendProtocol:", e);
936
- }
877
+ if (t.push(new xt(this.walletClient)), this.config.enableSuilend)
878
+ try {
879
+ const { default: n } = await import("./suilend-CWugUjwd.js");
880
+ t.push(
881
+ await n.create(this.walletClient, {
882
+ grpcClient: this.config.suilendGrpcClient,
883
+ grpcUrl: this.config.suilendGrpcUrl
884
+ })
885
+ );
886
+ } catch (n) {
887
+ console.warn("Failed to initialize SuilendProtocol:", n);
888
+ }
937
889
  this._protocols = t;
938
890
  }
939
891
  }
940
- class Nt extends A {
892
+ class jt extends j {
941
893
  constructor() {
942
894
  super(...arguments), this.name = "volo", this.defaultConfig = {
943
895
  packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
944
896
  poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
945
897
  metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
946
898
  coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
947
- }, this.getStats = st(
948
- W(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((e) => e.json())).data)
899
+ }, this.getStatsCached = rt(
900
+ M(async (t) => {
901
+ const n = { services: t?.services }, e = lt(n);
902
+ return (await fetch(ct("/volo/stats", n), {
903
+ headers: ut({}, e)
904
+ }).then((a) => a.json())).data;
905
+ })
949
906
  );
950
907
  }
908
+ getStats(t) {
909
+ return this.getStatsCached({
910
+ services: t?.services ?? this.config.services
911
+ });
912
+ }
951
913
  /**
952
914
  * Adds staking operation to a transaction black
953
915
  *
@@ -955,18 +917,18 @@ class Nt extends A {
955
917
  * @param suiCoin - The SUI coin object to stake
956
918
  * @returns The vSUI coin object received from staking
957
919
  */
958
- async stakePTB(t, e) {
959
- const [n] = t.moveCall({
920
+ async stakePTB(t, n) {
921
+ const [e] = t.moveCall({
960
922
  target: `${this.config.packageId}::stake_pool::stake`,
961
923
  arguments: [
962
924
  t.object(this.config.poolId),
963
925
  t.object(this.config.metadataId),
964
926
  t.object("0x05"),
965
- x(e, t.object)
927
+ k(n, t.object)
966
928
  ],
967
929
  typeArguments: []
968
930
  });
969
- return n;
931
+ return e;
970
932
  }
971
933
  /**
972
934
  * Adds unstaking operation to a transaction black
@@ -975,18 +937,18 @@ class Nt extends A {
975
937
  * @param vSuiCoin - The vSUI coin object to unstake
976
938
  * @returns The SUI coin object received from unstaking
977
939
  */
978
- async unstakePTB(t, e) {
979
- const [n] = t.moveCall({
940
+ async unstakePTB(t, n) {
941
+ const [e] = t.moveCall({
980
942
  target: `${this.config.packageId}::stake_pool::unstake`,
981
943
  arguments: [
982
944
  t.object(this.config.poolId),
983
945
  t.object(this.config.metadataId),
984
946
  t.object("0x05"),
985
- x(e, t.object)
947
+ k(n, t.object)
986
948
  ],
987
949
  typeArguments: []
988
950
  });
989
- return n;
951
+ return e;
990
952
  }
991
953
  /**
992
954
  * Stake SUI tokens to receive vSUI tokens
@@ -996,25 +958,25 @@ class Nt extends A {
996
958
  * @returns Transaction response or dry run response
997
959
  * @throws Error if wallet client not found or stake amount is too low
998
960
  */
999
- async stake(t, e) {
961
+ async stake(t, n) {
1000
962
  if (!this.walletClient)
1001
963
  throw new Error("Wallet client not found");
1002
964
  if (t < 1e9)
1003
965
  throw new Error("Stake amount should be greater than 1Sui");
1004
- const n = new f();
966
+ const e = new h();
1005
967
  await this.walletClient.module("balance").waitForUpdate();
1006
- const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = C(n, s.coins, {
968
+ const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = p(e, s.coins, {
1007
969
  balance: t,
1008
970
  useGasCoin: !0
1009
- }), l = await this.stakePTB(n, a);
1010
- n.transferObjects([l], this.walletClient.address);
1011
- const i = await this.walletClient.signExecuteTransaction({
1012
- transaction: n,
1013
- dryRun: e?.dryRun ?? !1
971
+ }), r = await this.stakePTB(e, a);
972
+ e.transferObjects([r], this.walletClient.address);
973
+ const o = await this.walletClient.signExecuteTransaction({
974
+ transaction: e,
975
+ dryRun: n?.dryRun ?? !1
1014
976
  });
1015
- return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("volo:stake-success", {
977
+ return !n?.dryRun && o.effects?.status?.status === "success" && (this.emit("volo:stake-success", {
1016
978
  suiAmount: t
1017
- }), this.walletClient.module("balance").updatePortfolio()), i;
979
+ }), this.walletClient.module("balance").updatePortfolio()), o;
1018
980
  }
1019
981
  /**
1020
982
  * Unstake vSUI tokens to receive SUI tokens
@@ -1024,26 +986,90 @@ class Nt extends A {
1024
986
  * @returns Transaction response or dry run response
1025
987
  * @throws Error if wallet client not found or unstake amount is too low
1026
988
  */
1027
- async unstake(t, e) {
989
+ async unstake(t, n) {
1028
990
  if (!this.walletClient)
1029
991
  throw new Error("Wallet client not found");
1030
992
  if (t < 1e9)
1031
993
  throw new Error("Unstake amount should >= 1vSui");
1032
994
  await this.walletClient.module("balance").waitForUpdate();
1033
- const n = new f(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = C(n, s.coins, {
995
+ const e = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = p(e, s.coins, {
1034
996
  balance: t
1035
- }), l = await this.unstakePTB(n, a);
1036
- n.transferObjects([l], this.walletClient.address);
1037
- const i = await this.walletClient.signExecuteTransaction({
1038
- transaction: n,
1039
- dryRun: e?.dryRun ?? !1
997
+ }), r = await this.unstakePTB(e, a);
998
+ e.transferObjects([r], this.walletClient.address);
999
+ const o = await this.walletClient.signExecuteTransaction({
1000
+ transaction: e,
1001
+ dryRun: n?.dryRun ?? !1
1040
1002
  });
1041
- return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("volo:unstake-success", {
1003
+ return !n?.dryRun && o.effects?.status?.status === "success" && (this.emit("volo:unstake-success", {
1042
1004
  vSuiAmount: t
1043
- }), this.walletClient.module("balance").updatePortfolio()), i;
1005
+ }), this.walletClient.module("balance").updatePortfolio()), o;
1044
1006
  }
1045
1007
  }
1046
- class Ft extends A {
1008
+ const K = {
1009
+ showEffects: !0,
1010
+ showEvents: !0,
1011
+ showBalanceChanges: !0,
1012
+ showObjectChanges: !0
1013
+ };
1014
+ function G(i) {
1015
+ return {
1016
+ ...K,
1017
+ ...i
1018
+ };
1019
+ }
1020
+ function R(i, t) {
1021
+ const e = kt(t ?? {}), s = Ft(e);
1022
+ return {
1023
+ ...e,
1024
+ kind: i,
1025
+ effects: s,
1026
+ events: Nt(e.events),
1027
+ balanceChanges: Array.isArray(e.balanceChanges) ? e.balanceChanges : [],
1028
+ objectChanges: Array.isArray(e.objectChanges) ? e.objectChanges : []
1029
+ };
1030
+ }
1031
+ function kt(i) {
1032
+ const t = i.Transaction;
1033
+ if (A(t))
1034
+ return t;
1035
+ const n = i.FailedTransaction;
1036
+ return A(n) ? n : i;
1037
+ }
1038
+ function Ft(i) {
1039
+ if (A(i.effects))
1040
+ return i.effects;
1041
+ if (A(i.status))
1042
+ return {
1043
+ status: i.status
1044
+ };
1045
+ }
1046
+ function Nt(i) {
1047
+ return Array.isArray(i) ? i.map((t) => A(t) ? {
1048
+ ...t,
1049
+ type: t.type ?? t.eventType,
1050
+ parsedJson: t.parsedJson ?? t.json
1051
+ } : t) : [];
1052
+ }
1053
+ function A(i) {
1054
+ return typeof i == "object" && i !== null;
1055
+ }
1056
+ function _t() {
1057
+ const i = G(K);
1058
+ return {
1059
+ effects: i.showEffects,
1060
+ events: i.showEvents,
1061
+ balanceChanges: i.showBalanceChanges,
1062
+ objectTypes: i.showObjectChanges
1063
+ };
1064
+ }
1065
+ function Ut(i) {
1066
+ return i.core;
1067
+ }
1068
+ function Wt(i) {
1069
+ const t = i.effects?.status;
1070
+ return t?.status === "success" || t?.success === !0;
1071
+ }
1072
+ class It extends j {
1047
1073
  constructor() {
1048
1074
  super(...arguments), this.name = "swap", this.defaultConfig = {
1049
1075
  apiKey: "",
@@ -1060,7 +1086,7 @@ class Ft extends A {
1060
1086
  * @returns Referral ID if API key is configured, otherwise 0
1061
1087
  */
1062
1088
  get referral() {
1063
- return this.config.apiKey ? yt(this.config.apiKey) : 0;
1089
+ return this.config.apiKey ? St(this.config.apiKey) : 0;
1064
1090
  }
1065
1091
  /**
1066
1092
  * Get the swap options
@@ -1071,7 +1097,8 @@ class Ft extends A {
1071
1097
  baseUrl: this.config.baseUrl,
1072
1098
  dexList: this.config.dexList,
1073
1099
  depth: this.config.depth,
1074
- serviceFee: this.config.serviceFee
1100
+ serviceFee: this.config.serviceFee,
1101
+ services: this.config.services ?? this.walletClient?.clientBundle.services
1075
1102
  };
1076
1103
  }
1077
1104
  /**
@@ -1081,8 +1108,8 @@ class Ft extends A {
1081
1108
  * @param fromAmount - The amount of the coin being swapped from
1082
1109
  * @returns A promise that resolves with the quote
1083
1110
  */
1084
- async getQuote(t, e, n) {
1085
- return Pt(t, e, n, this.config.apiKey, this.swapOptions);
1111
+ async getQuote(t, n, e) {
1112
+ return Ot(t, n, e, this.config.apiKey, this.swapOptions);
1086
1113
  }
1087
1114
  /**
1088
1115
  * Builds a swap transaction from a quote
@@ -1092,16 +1119,16 @@ class Ft extends A {
1092
1119
  * @param slippage - The slippage tolerance
1093
1120
  * @returns The swap transaction
1094
1121
  */
1095
- async buildSwapPTBFromQuote(t, e, n, s) {
1122
+ async buildSwapPTBFromQuote(t, n, e, s) {
1096
1123
  if (!this.walletClient)
1097
1124
  throw new Error("Wallet client not found");
1098
- const a = new E(e.amount_out).multipliedBy(1 - s).toFixed(0);
1099
- return await $(
1125
+ const a = new O(n.amount_out).multipliedBy(1 - s).toFixed(0);
1126
+ return await z(
1100
1127
  this.walletClient.address,
1101
1128
  t,
1102
1129
  Number(a),
1103
- n,
1104
1130
  e,
1131
+ n,
1105
1132
  this.referral,
1106
1133
  !1,
1107
1134
  this.config.apiKey,
@@ -1125,59 +1152,76 @@ class Ft extends A {
1125
1152
  * @param options - Optional parameters including dry run mode
1126
1153
  * @returns Transaction response or dry run response
1127
1154
  */
1128
- async swap(t, e, n, s, a) {
1155
+ async swap(t, n, e, s, a) {
1129
1156
  if (!this.walletClient)
1130
1157
  throw new Error("Wallet client not found");
1131
1158
  await this.walletClient.module("balance").waitForUpdate();
1132
- const l = this.walletClient.module("balance").portfolio.getBalance(t), i = new f(), r = C(i, l.coins, {
1133
- balance: n,
1159
+ const r = this.walletClient.module("balance").portfolio.getBalance(t), o = new h(), l = p(o, r.coins, {
1160
+ balance: e,
1134
1161
  useGasCoin: !0
1135
- }), w = await this.getQuote(t, e, n), u = await this.buildSwapPTBFromQuote(i, w, r, s);
1136
- if (i.transferObjects([u], this.walletClient.address), i.setSender(this.walletClient.address), a?.dryRun)
1162
+ }), c = await this.getQuote(t, n, e), u = await this.buildSwapPTBFromQuote(o, c, l, s);
1163
+ if (o.transferObjects([u], this.walletClient.address), o.setSender(this.walletClient.address), a?.dryRun)
1137
1164
  return await this.walletClient.signExecuteTransaction({
1138
- transaction: i,
1165
+ transaction: o,
1139
1166
  dryRun: !0
1140
1167
  });
1141
- const g = await i.build({
1168
+ const w = await o.build({
1142
1169
  client: this.walletClient.client
1143
- }), h = await this.walletClient.signer.signTransaction(g), p = [h.signature];
1170
+ }), d = await this.walletClient.signer.signTransaction(w), f = [d.signature];
1144
1171
  try {
1145
- await St(h.bytes, p);
1146
- } catch (d) {
1147
- console.error(d);
1172
+ await Et(d.bytes, f);
1173
+ } catch (g) {
1174
+ console.error(g);
1148
1175
  }
1149
- const c = await this.walletClient.client.executeTransactionBlock({
1150
- transactionBlock: h.bytes,
1151
- signature: p,
1152
- options: {
1153
- showEffects: !0,
1154
- showEvents: !0,
1155
- showBalanceChanges: !0
1156
- }
1157
- });
1158
- if (c.effects?.status?.status === "success") {
1159
- const d = c.events?.find((y) => y.type.includes("::slippage::SwapEvent"));
1160
- d && this.emit("swap:swap-success", {
1176
+ const m = Ut(this.walletClient.client), C = typeof m?.executeTransaction == "function" ? await m.executeTransaction({
1177
+ transaction: ht(d.bytes),
1178
+ signatures: f,
1179
+ include: _t()
1180
+ }) : await (() => {
1181
+ const g = this.walletClient.clientBundle.legacyJsonRpc;
1182
+ if (!g)
1183
+ throw new Error(
1184
+ "Swap execution requires core.executeTransaction or an explicit legacyJsonRpc client"
1185
+ );
1186
+ return g.executeTransactionBlock({
1187
+ transactionBlock: d.bytes,
1188
+ signature: f,
1189
+ options: K
1190
+ });
1191
+ })(), y = R("execute", C);
1192
+ if (Wt(y)) {
1193
+ const g = y.events?.find((B) => B.type?.includes("::slippage::SwapEvent"));
1194
+ g && this.emit("swap:swap-success", {
1161
1195
  fromCoinType: t,
1162
- toCoinType: e,
1163
- fromAmount: n,
1196
+ toCoinType: n,
1197
+ fromAmount: e,
1164
1198
  slippage: s,
1165
- toAmount: Number(d.parsedJson.amount_out)
1199
+ toAmount: Number(g.parsedJson.amount_out)
1166
1200
  }), this.walletClient.module("balance").updatePortfolio();
1167
1201
  }
1168
- return c;
1202
+ return y;
1169
1203
  }
1170
1204
  }
1171
- class _t extends A {
1205
+ class Jt extends j {
1172
1206
  constructor() {
1173
1207
  super(...arguments), this.name = "haedal", this.defaultConfig = {
1174
1208
  packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
1175
1209
  configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
1176
1210
  coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
1177
- }, this.getApy = st(
1178
- W(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((e) => e.json())).data.apy)
1211
+ }, this.getApyCached = rt(
1212
+ M(async (t) => {
1213
+ const n = { services: t?.services }, e = lt(n);
1214
+ return (await fetch(ct("/haedal/stats", n), {
1215
+ headers: ut({}, e)
1216
+ }).then((a) => a.json())).data.apy;
1217
+ })
1179
1218
  );
1180
1219
  }
1220
+ getApy(t) {
1221
+ return this.getApyCached({
1222
+ services: t?.services ?? this.config.services
1223
+ });
1224
+ }
1181
1225
  /**
1182
1226
  * Builds a transaction block for staking SUI to haSUI
1183
1227
  *
@@ -1185,18 +1229,18 @@ class _t extends A {
1185
1229
  * @param suiCoin - Sui coin object to stake
1186
1230
  * @returns haSUI coin object
1187
1231
  */
1188
- async stakePTB(t, e) {
1189
- const [n] = t.moveCall({
1232
+ async stakePTB(t, n) {
1233
+ const [e] = t.moveCall({
1190
1234
  target: `${this.config.packageId}::staking::request_stake_coin`,
1191
1235
  arguments: [
1192
1236
  t.object("0x05"),
1193
1237
  t.object(this.config.configId),
1194
- x(e, t.object),
1238
+ k(n, t.object),
1195
1239
  t.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
1196
1240
  ],
1197
1241
  typeArguments: []
1198
1242
  });
1199
- return n;
1243
+ return e;
1200
1244
  }
1201
1245
  /**
1202
1246
  * Builds a transaction block for unstaking haSUI to SUI
@@ -1205,17 +1249,17 @@ class _t extends A {
1205
1249
  * @param haSUICoin - haSUI coin object to unstake
1206
1250
  * @returns SUI coin object
1207
1251
  */
1208
- async unstakePTB(t, e) {
1209
- const [n] = t.moveCall({
1252
+ async unstakePTB(t, n) {
1253
+ const [e] = t.moveCall({
1210
1254
  target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
1211
1255
  arguments: [
1212
1256
  t.object("0x05"),
1213
1257
  t.object(this.config.configId),
1214
- x(e, t.object)
1258
+ k(n, t.object)
1215
1259
  ],
1216
1260
  typeArguments: []
1217
1261
  });
1218
- return n;
1262
+ return e;
1219
1263
  }
1220
1264
  /**
1221
1265
  * Stake SUI for haSUI
@@ -1223,21 +1267,21 @@ class _t extends A {
1223
1267
  * @param suiAmount - Amount of SUI to stake
1224
1268
  * @param options Optional dry run
1225
1269
  */
1226
- async stake(t, e) {
1270
+ async stake(t, n) {
1227
1271
  if (!this.walletClient)
1228
1272
  throw new Error("Wallet client not found");
1229
- const n = new f();
1273
+ const e = new h();
1230
1274
  await this.walletClient.module("balance").waitForUpdate();
1231
- const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = C(n, s.coins, {
1275
+ const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = p(e, s.coins, {
1232
1276
  balance: t,
1233
1277
  useGasCoin: !0
1234
- }), l = await this.stakePTB(n, a);
1235
- n.transferObjects([l], this.walletClient.address);
1236
- const i = await this.walletClient.signExecuteTransaction({
1237
- transaction: n,
1238
- dryRun: e?.dryRun ?? !1
1278
+ }), r = await this.stakePTB(e, a);
1279
+ e.transferObjects([r], this.walletClient.address);
1280
+ const o = await this.walletClient.signExecuteTransaction({
1281
+ transaction: e,
1282
+ dryRun: n?.dryRun ?? !1
1239
1283
  });
1240
- return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), i;
1284
+ return !n?.dryRun && o.effects?.status?.status === "success" && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
1241
1285
  }
1242
1286
  /**
1243
1287
  * Unstake haSUI for SUI
@@ -1245,50 +1289,70 @@ class _t extends A {
1245
1289
  * @param haSUIAmount - Amount of haSUI to unstake
1246
1290
  * @param options Optional dry run
1247
1291
  */
1248
- async unstake(t, e) {
1292
+ async unstake(t, n) {
1249
1293
  if (!this.walletClient)
1250
1294
  throw new Error("Wallet client not found");
1251
1295
  await this.walletClient.module("balance").waitForUpdate();
1252
- const n = new f(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = C(n, s.coins, {
1296
+ const e = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = p(e, s.coins, {
1253
1297
  balance: t
1254
- }), l = await this.unstakePTB(n, a);
1255
- n.transferObjects([l], this.walletClient.address);
1256
- const i = await this.walletClient.signExecuteTransaction({
1257
- transaction: n,
1258
- dryRun: e?.dryRun ?? !1
1298
+ }), r = await this.unstakePTB(e, a);
1299
+ e.transferObjects([r], this.walletClient.address);
1300
+ const o = await this.walletClient.signExecuteTransaction({
1301
+ transaction: e,
1302
+ dryRun: n?.dryRun ?? !1
1259
1303
  });
1260
- return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), i;
1304
+ return !n?.dryRun && o.effects?.status?.status === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
1261
1305
  }
1262
1306
  }
1263
- const jt = {
1307
+ const Lt = {
1264
1308
  /** Balance management module */
1265
- balance: new At(),
1309
+ balance: new Rt(),
1266
1310
  /** Lending protocol module */
1267
- lending: new kt(),
1311
+ lending: new At(),
1268
1312
  /** Volo protocol module */
1269
- volo: new Nt(),
1313
+ volo: new jt(),
1270
1314
  /** DEX swapping module */
1271
- swap: new Ft(),
1315
+ swap: new It(),
1272
1316
  /** Haedal protocol module */
1273
- haedal: new _t()
1274
- }, It = {
1275
- url: ct("mainnet")
1317
+ haedal: new Jt()
1276
1318
  };
1277
- class Jt {
1319
+ function Y(i) {
1320
+ const t = G(i);
1321
+ return {
1322
+ effects: t.showEffects,
1323
+ events: t.showEvents,
1324
+ balanceChanges: t.showBalanceChanges,
1325
+ objectTypes: t.showObjectChanges
1326
+ };
1327
+ }
1328
+ function Z(i) {
1329
+ return i.core;
1330
+ }
1331
+ function Mt(i) {
1332
+ return "grpc" in i;
1333
+ }
1334
+ function Qt(i) {
1335
+ if (Mt(i))
1336
+ return Tt(i);
1337
+ const t = i.network ?? "mainnet", n = Pt(t, i.legacyJsonRpc);
1338
+ return {
1339
+ network: t,
1340
+ coreClient: n,
1341
+ grpc: n,
1342
+ legacyJsonRpc: n,
1343
+ services: i.services
1344
+ };
1345
+ }
1346
+ class Xt {
1278
1347
  /**
1279
1348
  * Creates a new wallet client instance
1280
1349
  * @param options - Configuration options for the wallet client
1281
1350
  */
1282
1351
  constructor(t) {
1283
- this.modules = jt, this.userConfigs = {}, this.events = dt();
1284
- const e = {
1285
- ...It,
1286
- ...t.client
1287
- };
1288
- e.transport = e.transport || new Ot(e.url), this.client = new ut(e), this.signer = t.signer, this.userConfigs = t.configs || {}, Object.entries(this.modules).forEach(([n, s]) => {
1289
- if (n !== s.name)
1290
- throw new Error(`Module name ${n} does not match module name ${s.name}`);
1291
- s.install(this);
1352
+ this.modules = Lt, this.userConfigs = {}, this.events = gt(), this.clientBundle = Qt(t.client), this.client = this.clientBundle.coreClient, this.clientUrl = "grpc" in t.client ? t.client.legacyJsonRpc && "url" in t.client.legacyJsonRpc ? t.client.legacyJsonRpc.url : void 0 : "url" in t.client.legacyJsonRpc ? t.client.legacyJsonRpc.url : void 0, this.signer = t.signer, this.userConfigs = t.configs || {}, Object.entries(this.modules).forEach(([n, e]) => {
1353
+ if (n !== e.name)
1354
+ throw new Error(`Module name ${n} does not match module name ${e.name}`);
1355
+ e.install(this);
1292
1356
  });
1293
1357
  }
1294
1358
  get lending() {
@@ -1312,19 +1376,55 @@ class Jt {
1312
1376
  * @returns Promise with transaction execution result
1313
1377
  */
1314
1378
  async signExecuteTransaction(t) {
1315
- const { dryRun: e = !1, ...n } = t;
1316
- if (e) {
1317
- let s;
1318
- return t.transaction instanceof f ? (t.transaction.setSenderIfNotSet(this.address), s = await t.transaction.build({
1379
+ const { dryRun: n = !1, ...e } = t;
1380
+ if (n) {
1381
+ const o = Z(this.client);
1382
+ if (typeof o?.simulateTransaction == "function") {
1383
+ t.transaction instanceof h && t.transaction.setSenderIfNotSet(this.address);
1384
+ const w = await o.simulateTransaction({
1385
+ transaction: t.transaction,
1386
+ include: Y(e.options)
1387
+ });
1388
+ return R("dryRun", w);
1389
+ }
1390
+ const l = this.clientBundle.legacyJsonRpc;
1391
+ if (!l)
1392
+ throw new Error(
1393
+ "WalletClient dry-run requires core.simulateTransaction or an explicit legacyJsonRpc client"
1394
+ );
1395
+ let c;
1396
+ t.transaction instanceof h ? (t.transaction.setSenderIfNotSet(this.address), c = await t.transaction.build({
1397
+ client: l
1398
+ })) : c = t.transaction;
1399
+ const u = await l.dryRunTransactionBlock({
1400
+ transactionBlock: c
1401
+ });
1402
+ return R("dryRun", u);
1403
+ }
1404
+ const s = Z(this.client);
1405
+ if (typeof s?.executeTransaction == "function") {
1406
+ let o;
1407
+ t.transaction instanceof h ? (t.transaction.setSenderIfNotSet(this.address), o = await t.transaction.build({
1319
1408
  client: this.client
1320
- })) : s = t.transaction, this.client.dryRunTransactionBlock({
1321
- transactionBlock: s
1409
+ })) : o = t.transaction;
1410
+ const l = await this.signer.signTransaction(o), c = await s.executeTransaction({
1411
+ transaction: ht(l.bytes),
1412
+ signatures: [l.signature],
1413
+ include: Y(e.options)
1322
1414
  });
1415
+ return R("execute", c);
1323
1416
  }
1324
- return this.client.signAndExecuteTransaction({
1325
- ...n,
1417
+ const a = this.clientBundle.legacyJsonRpc;
1418
+ if (!a)
1419
+ throw new Error(
1420
+ "WalletClient execution requires core.executeTransaction or an explicit legacyJsonRpc client"
1421
+ );
1422
+ const r = await a.signAndExecuteTransaction({
1423
+ ...e,
1424
+ options: G(e.options),
1326
1425
  signer: this.signer
1327
1426
  });
1427
+ return R("execute", r);
1328
1428
  }
1329
1429
  /**
1330
1430
  * Gets the wallet address from the signer's public key
@@ -1361,7 +1461,7 @@ class Jt {
1361
1461
  return t in this.modules;
1362
1462
  }
1363
1463
  }
1364
- class Vt extends it {
1464
+ class Yt extends dt {
1365
1465
  /**
1366
1466
  * Creates a new watch-only signer
1367
1467
  *
@@ -1421,11 +1521,11 @@ class Vt extends it {
1421
1521
  * @param options - Sign and execute options
1422
1522
  * @returns Promise<any> - Empty result (not a real transaction result)
1423
1523
  */
1424
- async signAndExecuteTransaction({ transaction: t, client: e }) {
1524
+ async signAndExecuteTransaction({ transaction: t, client: n }) {
1425
1525
  return {};
1426
1526
  }
1427
1527
  }
1428
- class Xt extends it {
1528
+ class Zt extends dt {
1429
1529
  /**
1430
1530
  * Creates a new watch-only signer
1431
1531
  *
@@ -1478,8 +1578,8 @@ class Xt extends it {
1478
1578
  }
1479
1579
  }
1480
1580
  export {
1481
- Jt as WalletClient,
1482
- Vt as WatchSigner,
1483
- Xt as WebSigner
1581
+ Xt as WalletClient,
1582
+ Yt as WatchSigner,
1583
+ Zt as WebSigner
1484
1584
  };
1485
1585
  //# sourceMappingURL=index.esm.js.map