@naviprotocol/wallet-client 2.0.0 → 2.0.2
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 +273 -290
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/haedalModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/index.d.ts.map +1 -1
- package/dist/modules/swapModule/index.d.ts.map +1 -1
- package/dist/modules/voloModule/index.d.ts.map +1 -1
- package/dist/signer.d.ts +10 -17
- package/dist/signer.d.ts.map +1 -1
- package/dist/transaction-result.d.ts +12 -0
- package/dist/transaction-result.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { withSingleton as
|
|
3
|
-
import
|
|
4
|
-
import { normalizeStructTag as
|
|
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, createNaviSuiClientBundle as St, createNaviLegacyJsonRpcClient as Ot } 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
5
|
import { Transaction as h } from "@mysten/sui/transactions";
|
|
6
|
-
import { buildSwapPTBFromQuote as z, generateRefId as
|
|
7
|
-
import { executeAuction as
|
|
8
|
-
import { Signer as
|
|
9
|
-
class
|
|
6
|
+
import { buildSwapPTBFromQuote as z, generateRefId as Et, getQuote as Rt } from "@naviprotocol/astros-aggregator-sdk";
|
|
7
|
+
import { executeAuction as xt } from "shio-sdk";
|
|
8
|
+
import { Signer as wt } from "@mysten/sui/cryptography";
|
|
9
|
+
class k {
|
|
10
10
|
/**
|
|
11
11
|
* Gets the current configuration for this module
|
|
12
12
|
*
|
|
@@ -48,25 +48,25 @@ class j {
|
|
|
48
48
|
this.walletClient = void 0;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
class
|
|
51
|
+
class R {
|
|
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
56
|
*/
|
|
57
57
|
constructor(t) {
|
|
58
|
-
if (t instanceof
|
|
58
|
+
if (t instanceof R)
|
|
59
59
|
this.balances = JSON.parse(JSON.stringify(t.balances));
|
|
60
60
|
else {
|
|
61
61
|
const n = {};
|
|
62
62
|
t?.forEach((e) => {
|
|
63
63
|
if (!e.coinType || e.balance === void 0 || e.balance === null)
|
|
64
64
|
return;
|
|
65
|
-
const s =
|
|
65
|
+
const s = B(e.coinType);
|
|
66
66
|
let a = n[s];
|
|
67
67
|
a || (a = {
|
|
68
68
|
coinType: s,
|
|
69
|
-
amount:
|
|
69
|
+
amount: M(0),
|
|
70
70
|
coins: []
|
|
71
71
|
}, n[s] = a), a.coins.push(e), a.amount = a.amount.plus(e.balance);
|
|
72
72
|
}), this.balances = n;
|
|
@@ -79,7 +79,7 @@ class E {
|
|
|
79
79
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
80
80
|
*/
|
|
81
81
|
getBalance(t) {
|
|
82
|
-
return t =
|
|
82
|
+
return t = B(t), this.balances[t] || { coinType: t, amount: M(0), coins: [] };
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Gets all coin types in the portfolio
|
|
@@ -96,7 +96,7 @@ class E {
|
|
|
96
96
|
* @returns BigNumber representing the total balance
|
|
97
97
|
*/
|
|
98
98
|
balanceOf(t) {
|
|
99
|
-
return t =
|
|
99
|
+
return t = B(t), this.getBalance(t)?.amount || M(0);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Creates a deep copy of the portfolio
|
|
@@ -107,22 +107,22 @@ class E {
|
|
|
107
107
|
* @returns New UserPortfolio instance with copied data
|
|
108
108
|
*/
|
|
109
109
|
clone() {
|
|
110
|
-
const t = JSON.parse(JSON.stringify(this.balances)), n = new
|
|
110
|
+
const t = JSON.parse(JSON.stringify(this.balances)), n = new R();
|
|
111
111
|
return n.balances = t, n;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
class
|
|
114
|
+
class At extends k {
|
|
115
115
|
constructor() {
|
|
116
116
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
117
117
|
coinPollingInterval: 6e3,
|
|
118
118
|
disableCoinPolling: !1
|
|
119
|
-
}, this.updatePortfolio =
|
|
119
|
+
}, this.updatePortfolio = Q(async () => {
|
|
120
120
|
if (!this.walletClient)
|
|
121
121
|
throw new Error("Wallet client not found");
|
|
122
|
-
this._coins = await
|
|
122
|
+
this._coins = await et(this.walletClient.address, {
|
|
123
123
|
client: this.walletClient.client
|
|
124
|
-
}), this._portfolio = new
|
|
125
|
-
}), this._coins = [], this._portfolio = new
|
|
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;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Gets the current coin objects from the wallet
|
|
@@ -178,12 +178,12 @@ class Rt extends j {
|
|
|
178
178
|
if (n.length !== e.length)
|
|
179
179
|
throw new Error("Recipients and amounts must have the same length");
|
|
180
180
|
await this.waitForUpdate();
|
|
181
|
-
const a = this.portfolio.getBalance(t), r = e.reduce((w, d) => w.plus(d),
|
|
181
|
+
const a = this.portfolio.getBalance(t), r = e.reduce((w, d) => w.plus(d), E(0));
|
|
182
182
|
if (a.amount.lt(r))
|
|
183
183
|
throw new Error("Insufficient balance");
|
|
184
184
|
const o = new h();
|
|
185
185
|
let l = o.gas;
|
|
186
|
-
|
|
186
|
+
B(t) !== B("0x2::sui::SUI") && (l = m(o, a.coins, {
|
|
187
187
|
balance: r.toNumber()
|
|
188
188
|
}));
|
|
189
189
|
const c = o.splitCoins(l, e);
|
|
@@ -267,7 +267,59 @@ class Rt extends j {
|
|
|
267
267
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
|
|
270
|
+
const G = {
|
|
271
|
+
showEffects: !0,
|
|
272
|
+
showEvents: !0,
|
|
273
|
+
showBalanceChanges: !0,
|
|
274
|
+
showObjectChanges: !0
|
|
275
|
+
};
|
|
276
|
+
function H(i) {
|
|
277
|
+
return {
|
|
278
|
+
...G,
|
|
279
|
+
...i
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function p(i) {
|
|
283
|
+
const t = i?.effects?.status;
|
|
284
|
+
return t?.status === "success" || t?.success === !0;
|
|
285
|
+
}
|
|
286
|
+
function x(i, t) {
|
|
287
|
+
const e = jt(t ?? {}), s = kt(e);
|
|
288
|
+
return {
|
|
289
|
+
...e,
|
|
290
|
+
kind: i,
|
|
291
|
+
effects: s,
|
|
292
|
+
events: Ft(e.events),
|
|
293
|
+
balanceChanges: Array.isArray(e.balanceChanges) ? e.balanceChanges : [],
|
|
294
|
+
objectChanges: Array.isArray(e.objectChanges) ? e.objectChanges : []
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function jt(i) {
|
|
298
|
+
const t = i.Transaction;
|
|
299
|
+
if (j(t))
|
|
300
|
+
return t;
|
|
301
|
+
const n = i.FailedTransaction;
|
|
302
|
+
return j(n) ? n : i;
|
|
303
|
+
}
|
|
304
|
+
function kt(i) {
|
|
305
|
+
if (j(i.effects))
|
|
306
|
+
return i.effects;
|
|
307
|
+
if (j(i.status))
|
|
308
|
+
return {
|
|
309
|
+
status: i.status
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function Ft(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) : [];
|
|
318
|
+
}
|
|
319
|
+
function j(i) {
|
|
320
|
+
return typeof i == "object" && i !== null;
|
|
321
|
+
}
|
|
322
|
+
async function V(i, t, n, e) {
|
|
271
323
|
if (!this.walletClient)
|
|
272
324
|
throw new Error("Wallet client not found");
|
|
273
325
|
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);
|
|
@@ -280,79 +332,79 @@ async function D(i, t, n, e) {
|
|
|
280
332
|
throw new Error("No supply balance");
|
|
281
333
|
if (e?.amount && e.amount > u.supplyBalance)
|
|
282
334
|
throw new Error("Amount is less than supply balance");
|
|
283
|
-
const w = e?.slippage ?? 5e-3, d = e?.amount ?? Number(u.supplyBalance), f = await
|
|
284
|
-
if (await
|
|
335
|
+
const w = e?.slippage ?? 5e-3, d = e?.amount ?? Number(u.supplyBalance), f = await $(this.naviServiceOptions), C = await Promise.all([s, a]);
|
|
336
|
+
if (await K(
|
|
285
337
|
i,
|
|
286
338
|
q(f, {
|
|
287
339
|
lendingState: r,
|
|
288
|
-
pools:
|
|
340
|
+
pools: C
|
|
289
341
|
}),
|
|
290
342
|
this.naviServiceOptions
|
|
291
343
|
), l !== "navi" && s.id === a.id) {
|
|
292
|
-
const
|
|
344
|
+
const L = await c.withdrawCoinPTB(
|
|
293
345
|
i,
|
|
294
346
|
s.suiCoinType,
|
|
295
347
|
d
|
|
296
348
|
);
|
|
297
|
-
return await
|
|
349
|
+
return await A(i, a, L, {
|
|
298
350
|
...this.naviServiceOptions,
|
|
299
351
|
amount: d
|
|
300
352
|
}), i;
|
|
301
353
|
}
|
|
302
|
-
const
|
|
354
|
+
const y = await nt(a, {
|
|
303
355
|
...this.naviServiceOptions,
|
|
304
356
|
env: this.config.env
|
|
305
357
|
});
|
|
306
|
-
if (!
|
|
358
|
+
if (!y)
|
|
307
359
|
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
308
|
-
const
|
|
360
|
+
const b = await this.walletClient.swap.getQuote(
|
|
309
361
|
s.suiCoinType,
|
|
310
362
|
a.suiCoinType,
|
|
311
363
|
d
|
|
312
|
-
), g = Number(
|
|
364
|
+
), g = Number(b.amount_out);
|
|
313
365
|
if (g <= 0)
|
|
314
366
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
367
|
+
const T = Math.floor(g * (1 - w)), v = Math.floor(T / (1 + y.flashloanFee));
|
|
368
|
+
if (v <= 0)
|
|
317
369
|
throw new Error("The calculated borrow amount must be positive.");
|
|
318
|
-
const [
|
|
370
|
+
const [S, O] = await at(
|
|
319
371
|
i,
|
|
320
372
|
a,
|
|
321
|
-
|
|
373
|
+
v,
|
|
322
374
|
this.naviServiceOptions
|
|
323
|
-
), [
|
|
375
|
+
), [N] = i.moveCall({
|
|
324
376
|
target: "0x2::coin::from_balance",
|
|
325
|
-
arguments: [
|
|
377
|
+
arguments: [S],
|
|
326
378
|
typeArguments: [a.suiCoinType]
|
|
327
379
|
});
|
|
328
|
-
await
|
|
380
|
+
await A(i, a, N, {
|
|
329
381
|
...this.naviServiceOptions,
|
|
330
|
-
amount:
|
|
382
|
+
amount: v
|
|
331
383
|
});
|
|
332
|
-
const
|
|
384
|
+
const _ = await c.withdrawCoinPTB(i, s.suiCoinType, d), W = await z(
|
|
333
385
|
o,
|
|
334
386
|
i,
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
387
|
+
T,
|
|
388
|
+
_,
|
|
389
|
+
b
|
|
338
390
|
), U = i.moveCall({
|
|
339
391
|
target: "0x2::coin::into_balance",
|
|
340
|
-
arguments: [
|
|
392
|
+
arguments: [W],
|
|
341
393
|
typeArguments: [a.suiCoinType]
|
|
342
|
-
}), [
|
|
394
|
+
}), [I] = await it(
|
|
343
395
|
i,
|
|
344
396
|
a,
|
|
345
|
-
|
|
397
|
+
O,
|
|
346
398
|
U,
|
|
347
399
|
this.naviServiceOptions
|
|
348
|
-
), [
|
|
400
|
+
), [J] = i.moveCall({
|
|
349
401
|
target: "0x2::coin::from_balance",
|
|
350
|
-
arguments: [
|
|
402
|
+
arguments: [I],
|
|
351
403
|
typeArguments: [a.suiCoinType]
|
|
352
404
|
});
|
|
353
|
-
return await
|
|
405
|
+
return await A(i, a, J, this.naviServiceOptions), i;
|
|
354
406
|
}
|
|
355
|
-
async function
|
|
407
|
+
async function X(i, t, n, e) {
|
|
356
408
|
if (!this.walletClient)
|
|
357
409
|
throw new Error("Wallet client not found");
|
|
358
410
|
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);
|
|
@@ -365,8 +417,8 @@ async function V(i, t, n, e) {
|
|
|
365
417
|
throw new Error("No borrow balance");
|
|
366
418
|
if (e?.amount && e.amount > u.borrowBalance)
|
|
367
419
|
throw new Error("Amount is more than borrow balance");
|
|
368
|
-
const w = await
|
|
369
|
-
await
|
|
420
|
+
const w = await $(this.naviServiceOptions), d = await Promise.all([a, r]);
|
|
421
|
+
await K(
|
|
370
422
|
i,
|
|
371
423
|
q(w, {
|
|
372
424
|
lendingState: o,
|
|
@@ -376,76 +428,76 @@ async function V(i, t, n, e) {
|
|
|
376
428
|
);
|
|
377
429
|
let f = e?.amount ?? Number(u.borrowBalance);
|
|
378
430
|
if (Number(u.borrowBalance) === f) {
|
|
379
|
-
const
|
|
431
|
+
const pt = u.borrowAPR / 100;
|
|
380
432
|
f = Math.ceil(
|
|
381
|
-
new
|
|
433
|
+
new E(f).multipliedBy(pt * (60 * 3) / (365 * 24 * 3600)).plus(new E(1).shiftedBy(-a.token.decimals)).plus(f).toNumber()
|
|
382
434
|
);
|
|
383
435
|
}
|
|
384
|
-
const
|
|
436
|
+
const C = await nt(a, {
|
|
385
437
|
...this.naviServiceOptions,
|
|
386
438
|
env: this.config.env
|
|
387
439
|
});
|
|
388
|
-
if (!
|
|
440
|
+
if (!C)
|
|
389
441
|
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
390
442
|
if (!this.walletClient)
|
|
391
443
|
throw new Error("Wallet client not found");
|
|
392
|
-
const
|
|
444
|
+
const y = e?.slippage ?? 5e-3, b = Math.ceil(f * (1 + C.flashloanFee)), g = b, T = await this.walletClient.swap.getQuote(
|
|
393
445
|
a.suiCoinType,
|
|
394
446
|
r.suiCoinType,
|
|
395
447
|
g
|
|
396
448
|
);
|
|
397
|
-
let
|
|
449
|
+
let v = 1 + y, S = Math.ceil(Number(T.amount_out) * v), O = await this.walletClient.swap.getQuote(
|
|
398
450
|
r.suiCoinType,
|
|
399
451
|
a.suiCoinType,
|
|
400
|
-
|
|
452
|
+
S
|
|
401
453
|
);
|
|
402
|
-
for (; Number(
|
|
403
|
-
|
|
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(
|
|
404
456
|
r.suiCoinType,
|
|
405
457
|
a.suiCoinType,
|
|
406
|
-
|
|
458
|
+
S
|
|
407
459
|
);
|
|
408
|
-
const [
|
|
460
|
+
const [N, _] = await at(
|
|
409
461
|
i,
|
|
410
462
|
a,
|
|
411
463
|
f,
|
|
412
464
|
this.naviServiceOptions
|
|
413
|
-
), [
|
|
465
|
+
), [W] = i.moveCall({
|
|
414
466
|
target: "0x2::coin::from_balance",
|
|
415
|
-
arguments: [
|
|
467
|
+
arguments: [N],
|
|
416
468
|
typeArguments: [a.suiCoinType]
|
|
417
469
|
});
|
|
418
|
-
await c.repayCoinPTB(i, a.suiCoinType,
|
|
419
|
-
const U = await
|
|
470
|
+
await c.repayCoinPTB(i, a.suiCoinType, W, f);
|
|
471
|
+
const U = await st(i, r, S, this.naviServiceOptions), I = await z(
|
|
420
472
|
s,
|
|
421
473
|
i,
|
|
422
|
-
|
|
474
|
+
b,
|
|
423
475
|
U,
|
|
424
|
-
|
|
425
|
-
),
|
|
476
|
+
O
|
|
477
|
+
), J = i.moveCall({
|
|
426
478
|
target: "0x2::coin::into_balance",
|
|
427
|
-
arguments: [
|
|
479
|
+
arguments: [I],
|
|
428
480
|
typeArguments: [a.suiCoinType]
|
|
429
|
-
}), [
|
|
481
|
+
}), [L] = await it(
|
|
430
482
|
i,
|
|
431
483
|
a,
|
|
432
|
-
|
|
433
|
-
|
|
484
|
+
_,
|
|
485
|
+
J,
|
|
434
486
|
this.naviServiceOptions
|
|
435
|
-
), [
|
|
487
|
+
), [gt] = i.moveCall({
|
|
436
488
|
target: "0x2::coin::from_balance",
|
|
437
|
-
arguments: [
|
|
489
|
+
arguments: [L],
|
|
438
490
|
typeArguments: [a.suiCoinType]
|
|
439
491
|
});
|
|
440
|
-
return i.transferObjects([
|
|
492
|
+
return i.transferObjects([gt], s), i;
|
|
441
493
|
}
|
|
442
|
-
async function
|
|
494
|
+
async function Y(i, t, n, e) {
|
|
443
495
|
if (!this.walletClient)
|
|
444
496
|
throw new Error("Wallet client not found");
|
|
445
|
-
const s = await
|
|
497
|
+
const s = await et(this.walletClient.address, {
|
|
446
498
|
client: this.walletClient.client,
|
|
447
499
|
coinType: t
|
|
448
|
-
}), a = await this.getPool(n), o = new
|
|
500
|
+
}), a = await this.getPool(n), o = new R(s).getBalance(t);
|
|
449
501
|
if (o.amount.eq(0))
|
|
450
502
|
throw new Error(`No balance of ${t}`);
|
|
451
503
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
@@ -453,11 +505,11 @@ async function X(i, t, n, e) {
|
|
|
453
505
|
}), e?.amount && o.amount.lt(e.amount))
|
|
454
506
|
throw new Error("Amount is greater than balance");
|
|
455
507
|
const l = e?.amount ?? o.amount.toNumber(), c = e?.slippage ?? 5e-3;
|
|
456
|
-
let u = await
|
|
508
|
+
let u = await m(i, o.coins, {
|
|
457
509
|
balance: l,
|
|
458
510
|
useGasCoin: !0
|
|
459
511
|
});
|
|
460
|
-
if (
|
|
512
|
+
if (B(t) !== B(a.suiCoinType)) {
|
|
461
513
|
const w = await this.walletClient.swap.getQuote(t, a.suiCoinType, l);
|
|
462
514
|
u = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
463
515
|
i,
|
|
@@ -466,16 +518,16 @@ async function X(i, t, n, e) {
|
|
|
466
518
|
c
|
|
467
519
|
);
|
|
468
520
|
}
|
|
469
|
-
return await
|
|
521
|
+
return await A(i, a, u, this.naviServiceOptions), i;
|
|
470
522
|
}
|
|
471
|
-
class
|
|
523
|
+
class Nt {
|
|
472
524
|
constructor(t) {
|
|
473
525
|
this.name = "navi", this.walletClient = t;
|
|
474
526
|
}
|
|
475
527
|
async getPool(t) {
|
|
476
528
|
const n = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
|
|
477
|
-
(o) => o.pool.suiCoinType ===
|
|
478
|
-
), a = s ? new
|
|
529
|
+
(o) => o.pool.suiCoinType === B(t)
|
|
530
|
+
), a = s ? new E(s.supplyBalance).toNumber() : 0, r = s ? new E(s.borrowBalance).toNumber() : 0;
|
|
479
531
|
return {
|
|
480
532
|
supplyBalance: a,
|
|
481
533
|
borrowBalance: r,
|
|
@@ -486,25 +538,25 @@ class xt {
|
|
|
486
538
|
throw new Error("Not implemented");
|
|
487
539
|
}
|
|
488
540
|
async withdrawCoinPTB(t, n, e) {
|
|
489
|
-
return
|
|
541
|
+
return ot(t, n, e, this.walletClient.lending.naviServiceOptions);
|
|
490
542
|
}
|
|
491
543
|
async borrowCoinPTB(t, n, e) {
|
|
492
544
|
throw new Error("Not implemented");
|
|
493
545
|
}
|
|
494
546
|
async repayCoinPTB(t, n, e, s) {
|
|
495
|
-
|
|
547
|
+
rt(t, n, e, {
|
|
496
548
|
...this.walletClient.lending.naviServiceOptions,
|
|
497
549
|
amount: s
|
|
498
550
|
});
|
|
499
551
|
}
|
|
500
552
|
}
|
|
501
|
-
class
|
|
553
|
+
class _t extends k {
|
|
502
554
|
constructor() {
|
|
503
555
|
super(), this.name = "lending", this.defaultConfig = {
|
|
504
556
|
env: "prod",
|
|
505
557
|
protocols: [],
|
|
506
558
|
enableSuilend: !0
|
|
507
|
-
}, this._protocols = [], this.migrateBetweenSupplyPTB =
|
|
559
|
+
}, this._protocols = [], this.migrateBetweenSupplyPTB = V, this.migrateBetweenBorrowPTB = X, this.migrateBalanceToSupplyPTB = Y, this.migrateBetweenSupplyPTB = V.bind(this), this.migrateBetweenBorrowPTB = X.bind(this), this.migrateBalanceToSupplyPTB = Y.bind(this);
|
|
508
560
|
}
|
|
509
561
|
/** Get protocols (either from internal storage or config) */
|
|
510
562
|
get protocols() {
|
|
@@ -529,7 +581,7 @@ class At extends j {
|
|
|
529
581
|
* @returns Array of pool information
|
|
530
582
|
*/
|
|
531
583
|
async getPools(t) {
|
|
532
|
-
return await
|
|
584
|
+
return await Ct({
|
|
533
585
|
...this.naviServiceOptions,
|
|
534
586
|
env: this.config.env,
|
|
535
587
|
...t
|
|
@@ -543,7 +595,7 @@ class At extends j {
|
|
|
543
595
|
* @returns Pool information
|
|
544
596
|
*/
|
|
545
597
|
async getPool(t, n) {
|
|
546
|
-
return await
|
|
598
|
+
return await P(t, {
|
|
547
599
|
...this.naviServiceOptions,
|
|
548
600
|
env: this.config.env,
|
|
549
601
|
...n
|
|
@@ -560,16 +612,16 @@ class At extends j {
|
|
|
560
612
|
async deposit(t, n, e) {
|
|
561
613
|
if (!this.walletClient)
|
|
562
614
|
throw new Error("Wallet client not found");
|
|
563
|
-
const s = await
|
|
615
|
+
const s = await P(t, {
|
|
564
616
|
...this.naviServiceOptions,
|
|
565
617
|
env: this.config.env
|
|
566
618
|
});
|
|
567
619
|
await this.walletClient.module("balance").waitForUpdate();
|
|
568
|
-
const a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o =
|
|
620
|
+
const a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
|
|
569
621
|
balance: n,
|
|
570
622
|
useGasCoin: !0
|
|
571
623
|
});
|
|
572
|
-
await
|
|
624
|
+
await A(a, s, o, {
|
|
573
625
|
...this.naviServiceOptions,
|
|
574
626
|
env: this.config.env,
|
|
575
627
|
amount: n,
|
|
@@ -579,7 +631,7 @@ class At extends j {
|
|
|
579
631
|
transaction: a,
|
|
580
632
|
dryRun: e?.dryRun ?? !1
|
|
581
633
|
});
|
|
582
|
-
return !e?.dryRun && l
|
|
634
|
+
return !e?.dryRun && p(l) && (this.emit("lending:deposit-success", {
|
|
583
635
|
identifier: t,
|
|
584
636
|
amount: n
|
|
585
637
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -595,12 +647,12 @@ class At extends j {
|
|
|
595
647
|
async withdraw(t, n, e) {
|
|
596
648
|
if (!this.walletClient)
|
|
597
649
|
throw new Error("Wallet client not found");
|
|
598
|
-
const s = await
|
|
650
|
+
const s = await P(t, {
|
|
599
651
|
...this.naviServiceOptions,
|
|
600
652
|
env: this.config.env
|
|
601
653
|
}), a = new h();
|
|
602
654
|
e?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
603
|
-
const r = await
|
|
655
|
+
const r = await ot(a, s, n, {
|
|
604
656
|
...this.naviServiceOptions,
|
|
605
657
|
env: this.config.env,
|
|
606
658
|
accountCap: e?.accountCap
|
|
@@ -610,7 +662,7 @@ class At extends j {
|
|
|
610
662
|
transaction: a,
|
|
611
663
|
dryRun: e?.dryRun ?? !1
|
|
612
664
|
});
|
|
613
|
-
return !e?.dryRun && o
|
|
665
|
+
return !e?.dryRun && p(o) && (this.emit("lending:withdraw-success", {
|
|
614
666
|
identifier: t,
|
|
615
667
|
amount: n
|
|
616
668
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
@@ -626,12 +678,12 @@ class At extends j {
|
|
|
626
678
|
async borrow(t, n, e) {
|
|
627
679
|
if (!this.walletClient)
|
|
628
680
|
throw new Error("Wallet client not found");
|
|
629
|
-
const s = await
|
|
681
|
+
const s = await P(t, {
|
|
630
682
|
...this.naviServiceOptions,
|
|
631
683
|
env: this.config.env
|
|
632
684
|
}), a = new h();
|
|
633
685
|
e?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
634
|
-
const r = await
|
|
686
|
+
const r = await st(a, s, n, {
|
|
635
687
|
...this.naviServiceOptions,
|
|
636
688
|
env: this.config.env,
|
|
637
689
|
accountCap: e?.accountCap
|
|
@@ -641,7 +693,7 @@ class At extends j {
|
|
|
641
693
|
transaction: a,
|
|
642
694
|
dryRun: e?.dryRun ?? !1
|
|
643
695
|
});
|
|
644
|
-
return !e?.dryRun && o
|
|
696
|
+
return !e?.dryRun && p(o) && (this.emit("lending:borrow-success", {
|
|
645
697
|
identifier: t,
|
|
646
698
|
amount: n
|
|
647
699
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
@@ -658,14 +710,14 @@ class At extends j {
|
|
|
658
710
|
if (!this.walletClient)
|
|
659
711
|
throw new Error("Wallet client not found");
|
|
660
712
|
await this.walletClient.module("balance").waitForUpdate();
|
|
661
|
-
const s = await
|
|
713
|
+
const s = await P(t, {
|
|
662
714
|
...this.naviServiceOptions,
|
|
663
715
|
env: this.config.env
|
|
664
|
-
}), a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o =
|
|
716
|
+
}), a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
|
|
665
717
|
balance: n,
|
|
666
718
|
useGasCoin: !0
|
|
667
719
|
});
|
|
668
|
-
await
|
|
720
|
+
await rt(a, s, o, {
|
|
669
721
|
...this.naviServiceOptions,
|
|
670
722
|
env: this.config.env,
|
|
671
723
|
amount: n,
|
|
@@ -675,7 +727,7 @@ class At extends j {
|
|
|
675
727
|
transaction: a,
|
|
676
728
|
dryRun: e?.dryRun ?? !1
|
|
677
729
|
});
|
|
678
|
-
return !e?.dryRun && l
|
|
730
|
+
return !e?.dryRun && p(l) && (this.emit("lending:repay-success", {
|
|
679
731
|
identifier: t,
|
|
680
732
|
amount: n
|
|
681
733
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -689,7 +741,7 @@ class At extends j {
|
|
|
689
741
|
if (!this.walletClient)
|
|
690
742
|
throw new Error("Wallet client not found");
|
|
691
743
|
const t = this.walletClient.address;
|
|
692
|
-
return await
|
|
744
|
+
return await yt(t, {
|
|
693
745
|
...this.naviServiceOptions,
|
|
694
746
|
env: this.config.env,
|
|
695
747
|
client: this.walletClient.client
|
|
@@ -708,16 +760,16 @@ class At extends j {
|
|
|
708
760
|
async liquidate(t, n, e, s, a) {
|
|
709
761
|
if (!this.walletClient)
|
|
710
762
|
throw new Error("Wallet client not found");
|
|
711
|
-
const r = await
|
|
763
|
+
const r = await P(t, {
|
|
712
764
|
...this.naviServiceOptions,
|
|
713
765
|
env: this.config.env
|
|
714
|
-
}), o = await
|
|
766
|
+
}), o = await P(e, {
|
|
715
767
|
...this.naviServiceOptions,
|
|
716
768
|
env: this.config.env
|
|
717
|
-
}), l = new h(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u =
|
|
769
|
+
}), l = new h(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u = m(l, c.coins, {
|
|
718
770
|
balance: n,
|
|
719
771
|
useGasCoin: !0
|
|
720
|
-
}), [w, d] = await
|
|
772
|
+
}), [w, d] = await bt(
|
|
721
773
|
l,
|
|
722
774
|
r,
|
|
723
775
|
u,
|
|
@@ -731,22 +783,22 @@ class At extends j {
|
|
|
731
783
|
target: "0x2::coin::from_balance",
|
|
732
784
|
arguments: [w],
|
|
733
785
|
typeArguments: [o.suiCoinType]
|
|
734
|
-
}), [
|
|
786
|
+
}), [C] = l.moveCall({
|
|
735
787
|
target: "0x2::coin::from_balance",
|
|
736
788
|
arguments: [d],
|
|
737
789
|
typeArguments: [r.suiCoinType]
|
|
738
790
|
});
|
|
739
|
-
l.transferObjects([f,
|
|
740
|
-
const
|
|
791
|
+
l.transferObjects([f, C], this.walletClient.address);
|
|
792
|
+
const y = await this.walletClient.signExecuteTransaction({
|
|
741
793
|
transaction: l,
|
|
742
794
|
dryRun: a?.dryRun ?? !1
|
|
743
795
|
});
|
|
744
|
-
return !a?.dryRun &&
|
|
796
|
+
return !a?.dryRun && p(y) && (this.emit("lending:liquidate-success", {
|
|
745
797
|
payIdentifier: t,
|
|
746
798
|
payAmount: n,
|
|
747
799
|
collateralIdentifier: e,
|
|
748
800
|
liquidationAddress: s
|
|
749
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
801
|
+
}), this.walletClient.module("balance").updatePortfolio()), y;
|
|
750
802
|
}
|
|
751
803
|
/**
|
|
752
804
|
* Gets the available lending rewards for the current user.
|
|
@@ -758,10 +810,11 @@ class At extends j {
|
|
|
758
810
|
async getAvailableRewards(t) {
|
|
759
811
|
if (!this.walletClient)
|
|
760
812
|
throw new Error("Wallet client not found");
|
|
761
|
-
return
|
|
813
|
+
return D(this.walletClient.address, {
|
|
762
814
|
...this.naviServiceOptions,
|
|
763
815
|
...t,
|
|
764
|
-
env: this.config.env
|
|
816
|
+
env: this.config.env,
|
|
817
|
+
client: this.walletClient.client
|
|
765
818
|
});
|
|
766
819
|
}
|
|
767
820
|
/**
|
|
@@ -774,7 +827,7 @@ class At extends j {
|
|
|
774
827
|
async getClaimedRewardHistory(t) {
|
|
775
828
|
if (!this.walletClient)
|
|
776
829
|
throw new Error("Wallet client not found");
|
|
777
|
-
return
|
|
830
|
+
return vt(this.walletClient.address, {
|
|
778
831
|
...this.naviServiceOptions,
|
|
779
832
|
...t
|
|
780
833
|
});
|
|
@@ -788,11 +841,12 @@ class At extends j {
|
|
|
788
841
|
async claimAllRewards(t) {
|
|
789
842
|
if (!this.walletClient)
|
|
790
843
|
throw new Error("Wallet client not found");
|
|
791
|
-
const n = new h(), e = await
|
|
844
|
+
const n = new h(), e = await D(this.walletClient.address, {
|
|
792
845
|
...this.naviServiceOptions,
|
|
793
|
-
env: this.config.env
|
|
846
|
+
env: this.config.env,
|
|
847
|
+
client: this.walletClient.client
|
|
794
848
|
});
|
|
795
|
-
await
|
|
849
|
+
await Bt(n, e, {
|
|
796
850
|
...this.naviServiceOptions,
|
|
797
851
|
env: this.config.env,
|
|
798
852
|
accountCap: t?.accountCap
|
|
@@ -801,12 +855,12 @@ class At extends j {
|
|
|
801
855
|
transaction: n,
|
|
802
856
|
dryRun: t?.dryRun ?? !1
|
|
803
857
|
});
|
|
804
|
-
return !t?.dryRun && s
|
|
858
|
+
return !t?.dryRun && p(s) && (this.emit("lending:claim-rewards-success", {
|
|
805
859
|
rewards: e
|
|
806
860
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
807
861
|
}
|
|
808
862
|
async updateOraclePTB(t, n) {
|
|
809
|
-
const e = await
|
|
863
|
+
const e = await $({
|
|
810
864
|
...this.naviServiceOptions,
|
|
811
865
|
env: this.config.env
|
|
812
866
|
}), s = await this.getLendingState({
|
|
@@ -815,10 +869,11 @@ class At extends j {
|
|
|
815
869
|
lendingState: s,
|
|
816
870
|
pools: n
|
|
817
871
|
});
|
|
818
|
-
await
|
|
872
|
+
await K(t, a, {
|
|
819
873
|
...this.naviServiceOptions,
|
|
820
874
|
env: this.config.env,
|
|
821
|
-
updatePythPriceFeeds: !0
|
|
875
|
+
updatePythPriceFeeds: !0,
|
|
876
|
+
client: this.walletClient?.client
|
|
822
877
|
});
|
|
823
878
|
}
|
|
824
879
|
/**
|
|
@@ -846,7 +901,7 @@ class At extends j {
|
|
|
846
901
|
async getLendingState(t) {
|
|
847
902
|
if (!this.walletClient)
|
|
848
903
|
throw new Error("Wallet client not found");
|
|
849
|
-
return await
|
|
904
|
+
return await Tt(this.walletClient.address, {
|
|
850
905
|
...this.naviServiceOptions,
|
|
851
906
|
env: this.config.env,
|
|
852
907
|
...t,
|
|
@@ -862,7 +917,7 @@ class At extends j {
|
|
|
862
917
|
async createAccountCap(t) {
|
|
863
918
|
if (!this.walletClient)
|
|
864
919
|
throw new Error("Wallet client not found");
|
|
865
|
-
const n = new h(), e = await
|
|
920
|
+
const n = new h(), e = await Pt(n);
|
|
866
921
|
return n.transferObjects([e], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
867
922
|
transaction: n,
|
|
868
923
|
dryRun: t?.dryRun ?? !1
|
|
@@ -874,7 +929,7 @@ class At extends j {
|
|
|
874
929
|
return;
|
|
875
930
|
}
|
|
876
931
|
const t = [];
|
|
877
|
-
if (t.push(new
|
|
932
|
+
if (t.push(new Nt(this.walletClient)), this.config.enableSuilend)
|
|
878
933
|
try {
|
|
879
934
|
const { default: n } = await import("./suilend-CWugUjwd.js");
|
|
880
935
|
t.push(
|
|
@@ -889,18 +944,18 @@ class At extends j {
|
|
|
889
944
|
this._protocols = t;
|
|
890
945
|
}
|
|
891
946
|
}
|
|
892
|
-
class
|
|
947
|
+
class Wt extends k {
|
|
893
948
|
constructor() {
|
|
894
949
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
895
950
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
896
951
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
897
952
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
898
953
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
899
|
-
}, this.getStatsCached =
|
|
900
|
-
|
|
901
|
-
const n = { services: t?.services }, e =
|
|
902
|
-
return (await fetch(
|
|
903
|
-
headers:
|
|
954
|
+
}, this.getStatsCached = lt(
|
|
955
|
+
Q(async (t) => {
|
|
956
|
+
const n = { services: t?.services }, e = ct(n);
|
|
957
|
+
return (await fetch(ut("/volo/stats", n), {
|
|
958
|
+
headers: ht({}, e)
|
|
904
959
|
}).then((a) => a.json())).data;
|
|
905
960
|
})
|
|
906
961
|
);
|
|
@@ -924,7 +979,7 @@ class jt extends j {
|
|
|
924
979
|
t.object(this.config.poolId),
|
|
925
980
|
t.object(this.config.metadataId),
|
|
926
981
|
t.object("0x05"),
|
|
927
|
-
|
|
982
|
+
F(n, t.object)
|
|
928
983
|
],
|
|
929
984
|
typeArguments: []
|
|
930
985
|
});
|
|
@@ -944,7 +999,7 @@ class jt extends j {
|
|
|
944
999
|
t.object(this.config.poolId),
|
|
945
1000
|
t.object(this.config.metadataId),
|
|
946
1001
|
t.object("0x05"),
|
|
947
|
-
|
|
1002
|
+
F(n, t.object)
|
|
948
1003
|
],
|
|
949
1004
|
typeArguments: []
|
|
950
1005
|
});
|
|
@@ -965,7 +1020,7 @@ class jt extends j {
|
|
|
965
1020
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
966
1021
|
const e = new h();
|
|
967
1022
|
await this.walletClient.module("balance").waitForUpdate();
|
|
968
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a =
|
|
1023
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(e, s.coins, {
|
|
969
1024
|
balance: t,
|
|
970
1025
|
useGasCoin: !0
|
|
971
1026
|
}), r = await this.stakePTB(e, a);
|
|
@@ -974,7 +1029,7 @@ class jt extends j {
|
|
|
974
1029
|
transaction: e,
|
|
975
1030
|
dryRun: n?.dryRun ?? !1
|
|
976
1031
|
});
|
|
977
|
-
return !n?.dryRun && o
|
|
1032
|
+
return !n?.dryRun && p(o) && (this.emit("volo:stake-success", {
|
|
978
1033
|
suiAmount: t
|
|
979
1034
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
980
1035
|
}
|
|
@@ -992,7 +1047,7 @@ class jt extends j {
|
|
|
992
1047
|
if (t < 1e9)
|
|
993
1048
|
throw new Error("Unstake amount should >= 1vSui");
|
|
994
1049
|
await this.walletClient.module("balance").waitForUpdate();
|
|
995
|
-
const e = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a =
|
|
1050
|
+
const e = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(e, s.coins, {
|
|
996
1051
|
balance: t
|
|
997
1052
|
}), r = await this.unstakePTB(e, a);
|
|
998
1053
|
e.transferObjects([r], this.walletClient.address);
|
|
@@ -1000,61 +1055,13 @@ class jt extends j {
|
|
|
1000
1055
|
transaction: e,
|
|
1001
1056
|
dryRun: n?.dryRun ?? !1
|
|
1002
1057
|
});
|
|
1003
|
-
return !n?.dryRun && o
|
|
1058
|
+
return !n?.dryRun && p(o) && (this.emit("volo:unstake-success", {
|
|
1004
1059
|
vSuiAmount: t
|
|
1005
1060
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1006
1061
|
}
|
|
1007
1062
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
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);
|
|
1063
|
+
function Ut() {
|
|
1064
|
+
const i = H(G);
|
|
1058
1065
|
return {
|
|
1059
1066
|
effects: i.showEffects,
|
|
1060
1067
|
events: i.showEvents,
|
|
@@ -1062,14 +1069,10 @@ function _t() {
|
|
|
1062
1069
|
objectTypes: i.showObjectChanges
|
|
1063
1070
|
};
|
|
1064
1071
|
}
|
|
1065
|
-
function
|
|
1072
|
+
function It(i) {
|
|
1066
1073
|
return i.core;
|
|
1067
1074
|
}
|
|
1068
|
-
|
|
1069
|
-
const t = i.effects?.status;
|
|
1070
|
-
return t?.status === "success" || t?.success === !0;
|
|
1071
|
-
}
|
|
1072
|
-
class It extends j {
|
|
1075
|
+
class Jt extends k {
|
|
1073
1076
|
constructor() {
|
|
1074
1077
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1075
1078
|
apiKey: "",
|
|
@@ -1086,7 +1089,7 @@ class It extends j {
|
|
|
1086
1089
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
1087
1090
|
*/
|
|
1088
1091
|
get referral() {
|
|
1089
|
-
return this.config.apiKey ?
|
|
1092
|
+
return this.config.apiKey ? Et(this.config.apiKey) : 0;
|
|
1090
1093
|
}
|
|
1091
1094
|
/**
|
|
1092
1095
|
* Get the swap options
|
|
@@ -1109,7 +1112,7 @@ class It extends j {
|
|
|
1109
1112
|
* @returns A promise that resolves with the quote
|
|
1110
1113
|
*/
|
|
1111
1114
|
async getQuote(t, n, e) {
|
|
1112
|
-
return
|
|
1115
|
+
return Rt(t, n, e, this.config.apiKey, this.swapOptions);
|
|
1113
1116
|
}
|
|
1114
1117
|
/**
|
|
1115
1118
|
* Builds a swap transaction from a quote
|
|
@@ -1122,7 +1125,7 @@ class It extends j {
|
|
|
1122
1125
|
async buildSwapPTBFromQuote(t, n, e, s) {
|
|
1123
1126
|
if (!this.walletClient)
|
|
1124
1127
|
throw new Error("Wallet client not found");
|
|
1125
|
-
const a = new
|
|
1128
|
+
const a = new E(n.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1126
1129
|
return await z(
|
|
1127
1130
|
this.walletClient.address,
|
|
1128
1131
|
t,
|
|
@@ -1156,7 +1159,7 @@ class It extends j {
|
|
|
1156
1159
|
if (!this.walletClient)
|
|
1157
1160
|
throw new Error("Wallet client not found");
|
|
1158
1161
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1159
|
-
const r = this.walletClient.module("balance").portfolio.getBalance(t), o = new h(), l =
|
|
1162
|
+
const r = this.walletClient.module("balance").portfolio.getBalance(t), o = new h(), l = m(o, r.coins, {
|
|
1160
1163
|
balance: e,
|
|
1161
1164
|
useGasCoin: !0
|
|
1162
1165
|
}), c = await this.getQuote(t, n, e), u = await this.buildSwapPTBFromQuote(o, c, l, s);
|
|
@@ -1169,14 +1172,14 @@ class It extends j {
|
|
|
1169
1172
|
client: this.walletClient.client
|
|
1170
1173
|
}), d = await this.walletClient.signer.signTransaction(w), f = [d.signature];
|
|
1171
1174
|
try {
|
|
1172
|
-
await
|
|
1175
|
+
await xt(d.bytes, f);
|
|
1173
1176
|
} catch (g) {
|
|
1174
1177
|
console.error(g);
|
|
1175
1178
|
}
|
|
1176
|
-
const
|
|
1177
|
-
transaction:
|
|
1179
|
+
const C = It(this.walletClient.client), y = typeof C?.executeTransaction == "function" ? await C.executeTransaction({
|
|
1180
|
+
transaction: dt(d.bytes),
|
|
1178
1181
|
signatures: f,
|
|
1179
|
-
include:
|
|
1182
|
+
include: Ut()
|
|
1180
1183
|
}) : await (() => {
|
|
1181
1184
|
const g = this.walletClient.clientBundle.legacyJsonRpc;
|
|
1182
1185
|
if (!g)
|
|
@@ -1186,11 +1189,11 @@ class It extends j {
|
|
|
1186
1189
|
return g.executeTransactionBlock({
|
|
1187
1190
|
transactionBlock: d.bytes,
|
|
1188
1191
|
signature: f,
|
|
1189
|
-
options:
|
|
1192
|
+
options: G
|
|
1190
1193
|
});
|
|
1191
|
-
})(),
|
|
1192
|
-
if (
|
|
1193
|
-
const g =
|
|
1194
|
+
})(), b = x("execute", y);
|
|
1195
|
+
if (p(b)) {
|
|
1196
|
+
const g = b.events?.find((T) => T.type?.includes("::slippage::SwapEvent"));
|
|
1194
1197
|
g && this.emit("swap:swap-success", {
|
|
1195
1198
|
fromCoinType: t,
|
|
1196
1199
|
toCoinType: n,
|
|
@@ -1199,20 +1202,20 @@ class It extends j {
|
|
|
1199
1202
|
toAmount: Number(g.parsedJson.amount_out)
|
|
1200
1203
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1201
1204
|
}
|
|
1202
|
-
return
|
|
1205
|
+
return b;
|
|
1203
1206
|
}
|
|
1204
1207
|
}
|
|
1205
|
-
class
|
|
1208
|
+
class Lt extends k {
|
|
1206
1209
|
constructor() {
|
|
1207
1210
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1208
1211
|
packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
|
|
1209
1212
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1210
1213
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1211
|
-
}, this.getApyCached =
|
|
1212
|
-
|
|
1213
|
-
const n = { services: t?.services }, e =
|
|
1214
|
-
return (await fetch(
|
|
1215
|
-
headers:
|
|
1214
|
+
}, this.getApyCached = lt(
|
|
1215
|
+
Q(async (t) => {
|
|
1216
|
+
const n = { services: t?.services }, e = ct(n);
|
|
1217
|
+
return (await fetch(ut("/haedal/stats", n), {
|
|
1218
|
+
headers: ht({}, e)
|
|
1216
1219
|
}).then((a) => a.json())).data.apy;
|
|
1217
1220
|
})
|
|
1218
1221
|
);
|
|
@@ -1235,7 +1238,7 @@ class Jt extends j {
|
|
|
1235
1238
|
arguments: [
|
|
1236
1239
|
t.object("0x05"),
|
|
1237
1240
|
t.object(this.config.configId),
|
|
1238
|
-
|
|
1241
|
+
F(n, t.object),
|
|
1239
1242
|
t.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1240
1243
|
],
|
|
1241
1244
|
typeArguments: []
|
|
@@ -1255,7 +1258,7 @@ class Jt extends j {
|
|
|
1255
1258
|
arguments: [
|
|
1256
1259
|
t.object("0x05"),
|
|
1257
1260
|
t.object(this.config.configId),
|
|
1258
|
-
|
|
1261
|
+
F(n, t.object)
|
|
1259
1262
|
],
|
|
1260
1263
|
typeArguments: []
|
|
1261
1264
|
});
|
|
@@ -1272,7 +1275,7 @@ class Jt extends j {
|
|
|
1272
1275
|
throw new Error("Wallet client not found");
|
|
1273
1276
|
const e = new h();
|
|
1274
1277
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1275
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a =
|
|
1278
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(e, s.coins, {
|
|
1276
1279
|
balance: t,
|
|
1277
1280
|
useGasCoin: !0
|
|
1278
1281
|
}), r = await this.stakePTB(e, a);
|
|
@@ -1281,7 +1284,7 @@ class Jt extends j {
|
|
|
1281
1284
|
transaction: e,
|
|
1282
1285
|
dryRun: n?.dryRun ?? !1
|
|
1283
1286
|
});
|
|
1284
|
-
return !n?.dryRun && o
|
|
1287
|
+
return !n?.dryRun && p(o) && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1285
1288
|
}
|
|
1286
1289
|
/**
|
|
1287
1290
|
* Unstake haSUI for SUI
|
|
@@ -1293,7 +1296,7 @@ class Jt extends j {
|
|
|
1293
1296
|
if (!this.walletClient)
|
|
1294
1297
|
throw new Error("Wallet client not found");
|
|
1295
1298
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1296
|
-
const e = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a =
|
|
1299
|
+
const e = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(e, s.coins, {
|
|
1297
1300
|
balance: t
|
|
1298
1301
|
}), r = await this.unstakePTB(e, a);
|
|
1299
1302
|
e.transferObjects([r], this.walletClient.address);
|
|
@@ -1301,23 +1304,23 @@ class Jt extends j {
|
|
|
1301
1304
|
transaction: e,
|
|
1302
1305
|
dryRun: n?.dryRun ?? !1
|
|
1303
1306
|
});
|
|
1304
|
-
return !n?.dryRun && o
|
|
1307
|
+
return !n?.dryRun && p(o) && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1305
1308
|
}
|
|
1306
1309
|
}
|
|
1307
|
-
const
|
|
1310
|
+
const Mt = {
|
|
1308
1311
|
/** Balance management module */
|
|
1309
|
-
balance: new
|
|
1312
|
+
balance: new At(),
|
|
1310
1313
|
/** Lending protocol module */
|
|
1311
|
-
lending: new
|
|
1314
|
+
lending: new _t(),
|
|
1312
1315
|
/** Volo protocol module */
|
|
1313
|
-
volo: new
|
|
1316
|
+
volo: new Wt(),
|
|
1314
1317
|
/** DEX swapping module */
|
|
1315
|
-
swap: new
|
|
1318
|
+
swap: new Jt(),
|
|
1316
1319
|
/** Haedal protocol module */
|
|
1317
|
-
haedal: new
|
|
1320
|
+
haedal: new Lt()
|
|
1318
1321
|
};
|
|
1319
|
-
function
|
|
1320
|
-
const t =
|
|
1322
|
+
function Z(i) {
|
|
1323
|
+
const t = H(i);
|
|
1321
1324
|
return {
|
|
1322
1325
|
effects: t.showEffects,
|
|
1323
1326
|
events: t.showEvents,
|
|
@@ -1325,16 +1328,16 @@ function Y(i) {
|
|
|
1325
1328
|
objectTypes: t.showObjectChanges
|
|
1326
1329
|
};
|
|
1327
1330
|
}
|
|
1328
|
-
function
|
|
1331
|
+
function tt(i) {
|
|
1329
1332
|
return i.core;
|
|
1330
1333
|
}
|
|
1331
|
-
function
|
|
1334
|
+
function Qt(i) {
|
|
1332
1335
|
return "grpc" in i;
|
|
1333
1336
|
}
|
|
1334
|
-
function
|
|
1335
|
-
if (
|
|
1336
|
-
return
|
|
1337
|
-
const t = i.network ?? "mainnet", n =
|
|
1337
|
+
function $t(i) {
|
|
1338
|
+
if (Qt(i))
|
|
1339
|
+
return St(i);
|
|
1340
|
+
const t = i.network ?? "mainnet", n = Ot(t, i.legacyJsonRpc);
|
|
1338
1341
|
return {
|
|
1339
1342
|
network: t,
|
|
1340
1343
|
coreClient: n,
|
|
@@ -1343,13 +1346,13 @@ function Qt(i) {
|
|
|
1343
1346
|
services: i.services
|
|
1344
1347
|
};
|
|
1345
1348
|
}
|
|
1346
|
-
class
|
|
1349
|
+
class Yt {
|
|
1347
1350
|
/**
|
|
1348
1351
|
* Creates a new wallet client instance
|
|
1349
1352
|
* @param options - Configuration options for the wallet client
|
|
1350
1353
|
*/
|
|
1351
1354
|
constructor(t) {
|
|
1352
|
-
this.modules =
|
|
1355
|
+
this.modules = Mt, this.userConfigs = {}, this.events = mt(), this.clientBundle = $t(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
1356
|
if (n !== e.name)
|
|
1354
1357
|
throw new Error(`Module name ${n} does not match module name ${e.name}`);
|
|
1355
1358
|
e.install(this);
|
|
@@ -1378,14 +1381,14 @@ class Xt {
|
|
|
1378
1381
|
async signExecuteTransaction(t) {
|
|
1379
1382
|
const { dryRun: n = !1, ...e } = t;
|
|
1380
1383
|
if (n) {
|
|
1381
|
-
const o =
|
|
1384
|
+
const o = tt(this.client);
|
|
1382
1385
|
if (typeof o?.simulateTransaction == "function") {
|
|
1383
1386
|
t.transaction instanceof h && t.transaction.setSenderIfNotSet(this.address);
|
|
1384
1387
|
const w = await o.simulateTransaction({
|
|
1385
1388
|
transaction: t.transaction,
|
|
1386
|
-
include:
|
|
1389
|
+
include: Z(e.options)
|
|
1387
1390
|
});
|
|
1388
|
-
return
|
|
1391
|
+
return x("dryRun", w);
|
|
1389
1392
|
}
|
|
1390
1393
|
const l = this.clientBundle.legacyJsonRpc;
|
|
1391
1394
|
if (!l)
|
|
@@ -1399,20 +1402,20 @@ class Xt {
|
|
|
1399
1402
|
const u = await l.dryRunTransactionBlock({
|
|
1400
1403
|
transactionBlock: c
|
|
1401
1404
|
});
|
|
1402
|
-
return
|
|
1405
|
+
return x("dryRun", u);
|
|
1403
1406
|
}
|
|
1404
|
-
const s =
|
|
1407
|
+
const s = tt(this.client);
|
|
1405
1408
|
if (typeof s?.executeTransaction == "function") {
|
|
1406
1409
|
let o;
|
|
1407
1410
|
t.transaction instanceof h ? (t.transaction.setSenderIfNotSet(this.address), o = await t.transaction.build({
|
|
1408
1411
|
client: this.client
|
|
1409
1412
|
})) : o = t.transaction;
|
|
1410
1413
|
const l = await this.signer.signTransaction(o), c = await s.executeTransaction({
|
|
1411
|
-
transaction:
|
|
1414
|
+
transaction: dt(l.bytes),
|
|
1412
1415
|
signatures: [l.signature],
|
|
1413
|
-
include:
|
|
1416
|
+
include: Z(e.options)
|
|
1414
1417
|
});
|
|
1415
|
-
return
|
|
1418
|
+
return x("execute", c);
|
|
1416
1419
|
}
|
|
1417
1420
|
const a = this.clientBundle.legacyJsonRpc;
|
|
1418
1421
|
if (!a)
|
|
@@ -1421,10 +1424,10 @@ class Xt {
|
|
|
1421
1424
|
);
|
|
1422
1425
|
const r = await a.signAndExecuteTransaction({
|
|
1423
1426
|
...e,
|
|
1424
|
-
options:
|
|
1427
|
+
options: H(e.options),
|
|
1425
1428
|
signer: this.signer
|
|
1426
1429
|
});
|
|
1427
|
-
return
|
|
1430
|
+
return x("execute", r);
|
|
1428
1431
|
}
|
|
1429
1432
|
/**
|
|
1430
1433
|
* Gets the wallet address from the signer's public key
|
|
@@ -1461,7 +1464,16 @@ class Xt {
|
|
|
1461
1464
|
return t in this.modules;
|
|
1462
1465
|
}
|
|
1463
1466
|
}
|
|
1464
|
-
|
|
1467
|
+
function ft(i) {
|
|
1468
|
+
return {
|
|
1469
|
+
toSuiAddress: () => i,
|
|
1470
|
+
toBytes: () => new Uint8Array(32),
|
|
1471
|
+
toRawBytes: () => new Uint8Array(32),
|
|
1472
|
+
flag: () => 0,
|
|
1473
|
+
verify: async () => !1
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
class Zt extends wt {
|
|
1465
1477
|
/**
|
|
1466
1478
|
* Creates a new watch-only signer
|
|
1467
1479
|
*
|
|
@@ -1487,45 +1499,29 @@ class Yt extends dt {
|
|
|
1487
1499
|
*
|
|
1488
1500
|
* Returns a mock public key object that provides the wallet address
|
|
1489
1501
|
* but cannot be used for actual cryptographic operations.
|
|
1490
|
-
*
|
|
1491
|
-
* @returns Mock public key object
|
|
1492
1502
|
*/
|
|
1493
1503
|
getPublicKey() {
|
|
1494
|
-
return
|
|
1495
|
-
/** Returns the wallet address */
|
|
1496
|
-
toSuiAddress: () => this.address,
|
|
1497
|
-
/** Returns empty bytes (not a real public key) */
|
|
1498
|
-
toBytes: () => new Uint8Array(32),
|
|
1499
|
-
/** Returns empty raw bytes (not a real public key) */
|
|
1500
|
-
toRawBytes: () => new Uint8Array(32),
|
|
1501
|
-
/** Public key flag (0 for mock) */
|
|
1502
|
-
flag: 0,
|
|
1503
|
-
/** Verification always returns false (not a real public key) */
|
|
1504
|
-
verify: async () => !1
|
|
1505
|
-
};
|
|
1504
|
+
return ft(this.address);
|
|
1506
1505
|
}
|
|
1507
1506
|
/**
|
|
1508
1507
|
* Gets the key scheme for this signer
|
|
1509
1508
|
*
|
|
1510
|
-
* @returns Key scheme
|
|
1509
|
+
* @returns Key scheme (ed25519 for compatibility)
|
|
1511
1510
|
*/
|
|
1512
1511
|
getKeyScheme() {
|
|
1513
|
-
return "
|
|
1512
|
+
return "ED25519";
|
|
1514
1513
|
}
|
|
1515
1514
|
/**
|
|
1516
1515
|
* Signs and executes a transaction (not implemented for watch-only mode)
|
|
1517
1516
|
*
|
|
1518
1517
|
* This method is required by the Signer interface but cannot
|
|
1519
1518
|
* actually sign and execute transactions in watch-only mode.
|
|
1520
|
-
*
|
|
1521
|
-
* @param options - Sign and execute options
|
|
1522
|
-
* @returns Promise<any> - Empty result (not a real transaction result)
|
|
1523
1519
|
*/
|
|
1524
|
-
async signAndExecuteTransaction(
|
|
1520
|
+
async signAndExecuteTransaction(t) {
|
|
1525
1521
|
return {};
|
|
1526
1522
|
}
|
|
1527
1523
|
}
|
|
1528
|
-
class
|
|
1524
|
+
class te extends wt {
|
|
1529
1525
|
/**
|
|
1530
1526
|
* Creates a new watch-only signer
|
|
1531
1527
|
*
|
|
@@ -1551,35 +1547,22 @@ class Zt extends dt {
|
|
|
1551
1547
|
*
|
|
1552
1548
|
* Returns a mock public key object that provides the wallet address
|
|
1553
1549
|
* but cannot be used for actual cryptographic operations.
|
|
1554
|
-
*
|
|
1555
|
-
* @returns Mock public key object
|
|
1556
1550
|
*/
|
|
1557
1551
|
getPublicKey() {
|
|
1558
|
-
return
|
|
1559
|
-
/** Returns the wallet address */
|
|
1560
|
-
toSuiAddress: () => this.address,
|
|
1561
|
-
/** Returns empty bytes (not a real public key) */
|
|
1562
|
-
toBytes: () => new Uint8Array(32),
|
|
1563
|
-
/** Returns empty raw bytes (not a real public key) */
|
|
1564
|
-
toRawBytes: () => new Uint8Array(32),
|
|
1565
|
-
/** Public key flag (0 for mock) */
|
|
1566
|
-
flag: 0,
|
|
1567
|
-
/** Verification always returns false (not a real public key) */
|
|
1568
|
-
verify: async () => !1
|
|
1569
|
-
};
|
|
1552
|
+
return ft(this.address);
|
|
1570
1553
|
}
|
|
1571
1554
|
/**
|
|
1572
1555
|
* Gets the key scheme for this signer
|
|
1573
1556
|
*
|
|
1574
|
-
* @returns Key scheme
|
|
1557
|
+
* @returns Key scheme (ed25519 for compatibility)
|
|
1575
1558
|
*/
|
|
1576
1559
|
getKeyScheme() {
|
|
1577
|
-
return "
|
|
1560
|
+
return "ED25519";
|
|
1578
1561
|
}
|
|
1579
1562
|
}
|
|
1580
1563
|
export {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1564
|
+
Yt as WalletClient,
|
|
1565
|
+
Zt as WatchSigner,
|
|
1566
|
+
te as WebSigner
|
|
1584
1567
|
};
|
|
1585
1568
|
//# sourceMappingURL=index.esm.js.map
|