@naviprotocol/wallet-client 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +6 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/index.esm.js +230 -225
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
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,
|
|
2
|
+
import { withSingleton as Q, getCoins as et, mergeCoinsPTB as m, getPriceFeeds as $, updateOraclePricesPTB as K, filterPriceFeeds as q, depositCoinPTB as A, getFlashLoanAsset as nt, flashloanPTB as at, repayFlashLoanPTB as it, borrowCoinPTB as st, withdrawCoinPTB as ot, repayCoinPTB as rt, getPools as Ct, getPool as P, getHealthFactor as yt, liquidatePTB as bt, getUserAvailableLendingRewards as D, getUserClaimedRewardHistory as vt, claimLendingRewardsPTB as Bt, getLendingState as Tt, createAccountCapPTB as Pt, withCache as lt, resolveNaviOpenApiEndpoint as ct, buildNaviOpenApiUrl as ut, mergeServiceHeaders as ht, parseTxValue as F, PUBLIC_MAINNET_GRPC_URL as St, createNaviSuiClientBundle as Ot, createNaviLegacyJsonRpcClient as Et } from "@naviprotocol/lending";
|
|
3
3
|
import E, { BigNumber as M } from "bignumber.js";
|
|
4
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
|
|
6
|
+
import { buildSwapPTBFromQuote as z, generateRefId as Rt, getQuote as xt } from "@naviprotocol/astros-aggregator-sdk";
|
|
7
|
+
import { executeAuction as At } from "shio-sdk";
|
|
8
8
|
import { Signer as wt } from "@mysten/sui/cryptography";
|
|
9
9
|
class k {
|
|
10
10
|
/**
|
|
@@ -24,8 +24,8 @@ class k {
|
|
|
24
24
|
* @param event - The event name to emit
|
|
25
25
|
* @param data - The event data to emit
|
|
26
26
|
*/
|
|
27
|
-
emit(t,
|
|
28
|
-
this.walletClient?.events.emit(t,
|
|
27
|
+
emit(t, e) {
|
|
28
|
+
this.walletClient?.events.emit(t, e);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Installs this module into a wallet client
|
|
@@ -58,18 +58,18 @@ class R {
|
|
|
58
58
|
if (t instanceof R)
|
|
59
59
|
this.balances = JSON.parse(JSON.stringify(t.balances));
|
|
60
60
|
else {
|
|
61
|
-
const
|
|
62
|
-
t?.forEach((
|
|
63
|
-
if (!
|
|
61
|
+
const e = {};
|
|
62
|
+
t?.forEach((n) => {
|
|
63
|
+
if (!n.coinType || n.balance === void 0 || n.balance === null)
|
|
64
64
|
return;
|
|
65
|
-
const s = B(
|
|
66
|
-
let a =
|
|
65
|
+
const s = B(n.coinType);
|
|
66
|
+
let a = e[s];
|
|
67
67
|
a || (a = {
|
|
68
68
|
coinType: s,
|
|
69
69
|
amount: M(0),
|
|
70
70
|
coins: []
|
|
71
|
-
},
|
|
72
|
-
}), this.balances =
|
|
71
|
+
}, e[s] = a), a.coins.push(n), a.amount = a.amount.plus(n.balance);
|
|
72
|
+
}), this.balances = e;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -107,11 +107,11 @@ class R {
|
|
|
107
107
|
* @returns New UserPortfolio instance with copied data
|
|
108
108
|
*/
|
|
109
109
|
clone() {
|
|
110
|
-
const t = JSON.parse(JSON.stringify(this.balances)),
|
|
111
|
-
return
|
|
110
|
+
const t = JSON.parse(JSON.stringify(this.balances)), e = new R();
|
|
111
|
+
return e.balances = t, e;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
class
|
|
114
|
+
class jt extends k {
|
|
115
115
|
constructor() {
|
|
116
116
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
117
117
|
coinPollingInterval: 6e3,
|
|
@@ -160,8 +160,8 @@ class At extends k {
|
|
|
160
160
|
* @param options - Optional parameters including dry run mode
|
|
161
161
|
* @returns Transaction response or dry run response
|
|
162
162
|
*/
|
|
163
|
-
async sendCoin(t,
|
|
164
|
-
return this.sendCoinBatch(t, [
|
|
163
|
+
async sendCoin(t, e, n, s) {
|
|
164
|
+
return this.sendCoinBatch(t, [e], [n], s);
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
167
|
* Sends coins to multiple recipients in a single transaction
|
|
@@ -172,13 +172,13 @@ class At extends k {
|
|
|
172
172
|
* @param options - Optional parameters including dry run mode
|
|
173
173
|
* @returns Transaction response or dry run response
|
|
174
174
|
*/
|
|
175
|
-
async sendCoinBatch(t,
|
|
175
|
+
async sendCoinBatch(t, e, n, s) {
|
|
176
176
|
if (!this.walletClient)
|
|
177
177
|
throw new Error("Wallet client not found");
|
|
178
|
-
if (
|
|
178
|
+
if (e.length !== n.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 =
|
|
181
|
+
const a = this.portfolio.getBalance(t), r = n.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();
|
|
@@ -186,8 +186,8 @@ class At extends k {
|
|
|
186
186
|
B(t) !== B("0x2::sui::SUI") && (l = m(o, a.coins, {
|
|
187
187
|
balance: r.toNumber()
|
|
188
188
|
}));
|
|
189
|
-
const c = o.splitCoins(l,
|
|
190
|
-
return
|
|
189
|
+
const c = o.splitCoins(l, n);
|
|
190
|
+
return e.forEach((w, d) => {
|
|
191
191
|
o.transferObjects([c[d]], w);
|
|
192
192
|
}), await this.walletClient.signExecuteTransaction({
|
|
193
193
|
transaction: o,
|
|
@@ -202,8 +202,8 @@ class At extends k {
|
|
|
202
202
|
* @param options - Optional parameters including dry run mode
|
|
203
203
|
* @returns Transaction response or dry run response
|
|
204
204
|
*/
|
|
205
|
-
async transferObject(t,
|
|
206
|
-
return this.transferObjectBatch([t], [
|
|
205
|
+
async transferObject(t, e, n) {
|
|
206
|
+
return this.transferObjectBatch([t], [e], n);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Transfers multiple objects to their respective recipients in a single transaction
|
|
@@ -216,18 +216,18 @@ class At extends k {
|
|
|
216
216
|
* @param options - Optional parameters including dry run mode
|
|
217
217
|
* @returns Transaction response or dry run response
|
|
218
218
|
*/
|
|
219
|
-
async transferObjectBatch(t,
|
|
219
|
+
async transferObjectBatch(t, e, n) {
|
|
220
220
|
if (!this.walletClient)
|
|
221
221
|
throw new Error("Wallet client not found");
|
|
222
|
-
if (t.length !==
|
|
222
|
+
if (t.length !== e.length)
|
|
223
223
|
throw new Error("Objects and recipients must have the same length");
|
|
224
224
|
await this.waitForUpdate();
|
|
225
225
|
const s = new h();
|
|
226
226
|
return t.forEach((r, o) => {
|
|
227
|
-
s.transferObjects([s.object(r)],
|
|
227
|
+
s.transferObjects([s.object(r)], e[o]);
|
|
228
228
|
}), await this.walletClient.signExecuteTransaction({
|
|
229
229
|
transaction: s,
|
|
230
|
-
dryRun:
|
|
230
|
+
dryRun: n?.dryRun ?? !1
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
/**
|
|
@@ -252,9 +252,9 @@ class At extends k {
|
|
|
252
252
|
* @param walletClient - The wallet client instance to install into
|
|
253
253
|
*/
|
|
254
254
|
install(t) {
|
|
255
|
-
super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((
|
|
255
|
+
super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((e) => {
|
|
256
256
|
t.events.on("balance:portfolio-updated", () => {
|
|
257
|
-
|
|
257
|
+
e();
|
|
258
258
|
});
|
|
259
259
|
});
|
|
260
260
|
}
|
|
@@ -284,24 +284,24 @@ function p(i) {
|
|
|
284
284
|
return t?.status === "success" || t?.success === !0;
|
|
285
285
|
}
|
|
286
286
|
function x(i, t) {
|
|
287
|
-
const
|
|
287
|
+
const n = kt(t ?? {}), s = Ft(n);
|
|
288
288
|
return {
|
|
289
|
-
...
|
|
289
|
+
...n,
|
|
290
290
|
kind: i,
|
|
291
291
|
effects: s,
|
|
292
|
-
events:
|
|
293
|
-
balanceChanges: Array.isArray(
|
|
294
|
-
objectChanges: Array.isArray(
|
|
292
|
+
events: Nt(n.events),
|
|
293
|
+
balanceChanges: Array.isArray(n.balanceChanges) ? n.balanceChanges : [],
|
|
294
|
+
objectChanges: Array.isArray(n.objectChanges) ? n.objectChanges : []
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
|
-
function
|
|
297
|
+
function kt(i) {
|
|
298
298
|
const t = i.Transaction;
|
|
299
299
|
if (j(t))
|
|
300
300
|
return t;
|
|
301
|
-
const
|
|
302
|
-
return j(
|
|
301
|
+
const e = i.FailedTransaction;
|
|
302
|
+
return j(e) ? e : i;
|
|
303
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function Ft(i) {
|
|
305
305
|
if (j(i.effects))
|
|
306
306
|
return i.effects;
|
|
307
307
|
if (j(i.status))
|
|
@@ -309,7 +309,7 @@ function kt(i) {
|
|
|
309
309
|
status: i.status
|
|
310
310
|
};
|
|
311
311
|
}
|
|
312
|
-
function
|
|
312
|
+
function Nt(i) {
|
|
313
313
|
return Array.isArray(i) ? i.map((t) => j(t) ? {
|
|
314
314
|
...t,
|
|
315
315
|
type: t.type ?? t.eventType,
|
|
@@ -319,10 +319,10 @@ function Ft(i) {
|
|
|
319
319
|
function j(i) {
|
|
320
320
|
return typeof i == "object" && i !== null;
|
|
321
321
|
}
|
|
322
|
-
async function V(i, t,
|
|
322
|
+
async function V(i, t, e, n) {
|
|
323
323
|
if (!this.walletClient)
|
|
324
324
|
throw new Error("Wallet client not found");
|
|
325
|
-
const s = await this.getPool(t), a = await this.getPool(
|
|
325
|
+
const s = await this.getPool(t), a = await this.getPool(e), r = await this.getLendingState(), o = this.walletClient.address, l = n?.protocol ?? "navi", c = await this.getProtocol(l);
|
|
326
326
|
if (!c)
|
|
327
327
|
throw new Error(`Protocol ${l} not found`);
|
|
328
328
|
const u = await c.getPool(s.coinType);
|
|
@@ -330,9 +330,9 @@ async function V(i, t, n, e) {
|
|
|
330
330
|
fromPoolLending: u
|
|
331
331
|
}), l === "navi" && u.supplyBalance === 0)
|
|
332
332
|
throw new Error("No supply balance");
|
|
333
|
-
if (
|
|
333
|
+
if (n?.amount && n.amount > u.supplyBalance)
|
|
334
334
|
throw new Error("Amount is less than supply balance");
|
|
335
|
-
const w =
|
|
335
|
+
const w = n?.slippage ?? 5e-3, d = n?.amount ?? Number(u.supplyBalance), f = await $(this.naviServiceOptions), C = await Promise.all([s, a]);
|
|
336
336
|
if (await K(
|
|
337
337
|
i,
|
|
338
338
|
q(f, {
|
|
@@ -381,21 +381,21 @@ async function V(i, t, n, e) {
|
|
|
381
381
|
...this.naviServiceOptions,
|
|
382
382
|
amount: v
|
|
383
383
|
});
|
|
384
|
-
const _ = await c.withdrawCoinPTB(i, s.suiCoinType, d),
|
|
384
|
+
const _ = await c.withdrawCoinPTB(i, s.suiCoinType, d), U = await z(
|
|
385
385
|
o,
|
|
386
386
|
i,
|
|
387
387
|
T,
|
|
388
388
|
_,
|
|
389
389
|
b
|
|
390
|
-
),
|
|
390
|
+
), W = i.moveCall({
|
|
391
391
|
target: "0x2::coin::into_balance",
|
|
392
|
-
arguments: [
|
|
392
|
+
arguments: [U],
|
|
393
393
|
typeArguments: [a.suiCoinType]
|
|
394
394
|
}), [I] = await it(
|
|
395
395
|
i,
|
|
396
396
|
a,
|
|
397
397
|
O,
|
|
398
|
-
|
|
398
|
+
W,
|
|
399
399
|
this.naviServiceOptions
|
|
400
400
|
), [J] = i.moveCall({
|
|
401
401
|
target: "0x2::coin::from_balance",
|
|
@@ -404,10 +404,10 @@ async function V(i, t, n, e) {
|
|
|
404
404
|
});
|
|
405
405
|
return await A(i, a, J, this.naviServiceOptions), i;
|
|
406
406
|
}
|
|
407
|
-
async function X(i, t,
|
|
407
|
+
async function X(i, t, e, n) {
|
|
408
408
|
if (!this.walletClient)
|
|
409
409
|
throw new Error("Wallet client not found");
|
|
410
|
-
const s = this.walletClient.address, a = await this.getPool(t), r = await this.getPool(
|
|
410
|
+
const s = this.walletClient.address, a = await this.getPool(t), r = await this.getPool(e), o = await this.getLendingState(), l = n?.protocol ?? "navi", c = await this.getProtocol(l);
|
|
411
411
|
if (!c)
|
|
412
412
|
throw new Error(`Protocol ${l} not found`);
|
|
413
413
|
const u = await c.getPool(a.coinType);
|
|
@@ -415,7 +415,7 @@ async function X(i, t, n, e) {
|
|
|
415
415
|
fromPoolLending: u
|
|
416
416
|
}), u.borrowBalance === 0)
|
|
417
417
|
throw new Error("No borrow balance");
|
|
418
|
-
if (
|
|
418
|
+
if (n?.amount && n.amount > u.borrowBalance)
|
|
419
419
|
throw new Error("Amount is more than borrow balance");
|
|
420
420
|
const w = await $(this.naviServiceOptions), d = await Promise.all([a, r]);
|
|
421
421
|
await K(
|
|
@@ -426,7 +426,7 @@ async function X(i, t, n, e) {
|
|
|
426
426
|
}),
|
|
427
427
|
this.naviServiceOptions
|
|
428
428
|
);
|
|
429
|
-
let f =
|
|
429
|
+
let f = n?.amount ?? Number(u.borrowBalance);
|
|
430
430
|
if (Number(u.borrowBalance) === f) {
|
|
431
431
|
const pt = u.borrowAPR / 100;
|
|
432
432
|
f = Math.ceil(
|
|
@@ -441,7 +441,7 @@ async function X(i, t, n, e) {
|
|
|
441
441
|
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
442
442
|
if (!this.walletClient)
|
|
443
443
|
throw new Error("Wallet client not found");
|
|
444
|
-
const y =
|
|
444
|
+
const y = n?.slippage ?? 5e-3, b = Math.ceil(f * (1 + C.flashloanFee)), g = b, T = await this.walletClient.swap.getQuote(
|
|
445
445
|
a.suiCoinType,
|
|
446
446
|
r.suiCoinType,
|
|
447
447
|
g
|
|
@@ -462,17 +462,17 @@ async function X(i, t, n, e) {
|
|
|
462
462
|
a,
|
|
463
463
|
f,
|
|
464
464
|
this.naviServiceOptions
|
|
465
|
-
), [
|
|
465
|
+
), [U] = i.moveCall({
|
|
466
466
|
target: "0x2::coin::from_balance",
|
|
467
467
|
arguments: [N],
|
|
468
468
|
typeArguments: [a.suiCoinType]
|
|
469
469
|
});
|
|
470
|
-
await c.repayCoinPTB(i, a.suiCoinType,
|
|
471
|
-
const
|
|
470
|
+
await c.repayCoinPTB(i, a.suiCoinType, U, f);
|
|
471
|
+
const W = await st(i, r, S, this.naviServiceOptions), I = await z(
|
|
472
472
|
s,
|
|
473
473
|
i,
|
|
474
474
|
b,
|
|
475
|
-
|
|
475
|
+
W,
|
|
476
476
|
O
|
|
477
477
|
), J = i.moveCall({
|
|
478
478
|
target: "0x2::coin::into_balance",
|
|
@@ -491,20 +491,20 @@ async function X(i, t, n, e) {
|
|
|
491
491
|
});
|
|
492
492
|
return i.transferObjects([gt], s), i;
|
|
493
493
|
}
|
|
494
|
-
async function Y(i, t,
|
|
494
|
+
async function Y(i, t, e, n) {
|
|
495
495
|
if (!this.walletClient)
|
|
496
496
|
throw new Error("Wallet client not found");
|
|
497
497
|
const s = await et(this.walletClient.address, {
|
|
498
498
|
client: this.walletClient.client,
|
|
499
499
|
coinType: t
|
|
500
|
-
}), a = await this.getPool(
|
|
500
|
+
}), a = await this.getPool(e), o = new R(s).getBalance(t);
|
|
501
501
|
if (o.amount.eq(0))
|
|
502
502
|
throw new Error(`No balance of ${t}`);
|
|
503
503
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
504
504
|
balance: o.amount.toNumber()
|
|
505
|
-
}),
|
|
505
|
+
}), n?.amount && o.amount.lt(n.amount))
|
|
506
506
|
throw new Error("Amount is greater than balance");
|
|
507
|
-
const l =
|
|
507
|
+
const l = n?.amount ?? o.amount.toNumber(), c = n?.slippage ?? 5e-3;
|
|
508
508
|
let u = await m(i, o.coins, {
|
|
509
509
|
balance: l,
|
|
510
510
|
useGasCoin: !0
|
|
@@ -520,37 +520,37 @@ async function Y(i, t, n, e) {
|
|
|
520
520
|
}
|
|
521
521
|
return await A(i, a, u, this.naviServiceOptions), i;
|
|
522
522
|
}
|
|
523
|
-
class
|
|
523
|
+
class _t {
|
|
524
524
|
constructor(t) {
|
|
525
525
|
this.name = "navi", this.walletClient = t;
|
|
526
526
|
}
|
|
527
527
|
async getPool(t) {
|
|
528
|
-
const
|
|
528
|
+
const e = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
|
|
529
529
|
(o) => o.pool.suiCoinType === B(t)
|
|
530
530
|
), a = s ? new E(s.supplyBalance).toNumber() : 0, r = s ? new E(s.borrowBalance).toNumber() : 0;
|
|
531
531
|
return {
|
|
532
532
|
supplyBalance: a,
|
|
533
533
|
borrowBalance: r,
|
|
534
|
-
borrowAPR: parseFloat(
|
|
534
|
+
borrowAPR: parseFloat(e.borrowIncentiveApyInfo.apy)
|
|
535
535
|
};
|
|
536
536
|
}
|
|
537
|
-
async depositCoinPTB(t,
|
|
537
|
+
async depositCoinPTB(t, e, n, s) {
|
|
538
538
|
throw new Error("Not implemented");
|
|
539
539
|
}
|
|
540
|
-
async withdrawCoinPTB(t,
|
|
541
|
-
return ot(t,
|
|
540
|
+
async withdrawCoinPTB(t, e, n) {
|
|
541
|
+
return ot(t, e, n, this.walletClient.lending.naviServiceOptions);
|
|
542
542
|
}
|
|
543
|
-
async borrowCoinPTB(t,
|
|
543
|
+
async borrowCoinPTB(t, e, n) {
|
|
544
544
|
throw new Error("Not implemented");
|
|
545
545
|
}
|
|
546
|
-
async repayCoinPTB(t,
|
|
547
|
-
rt(t,
|
|
546
|
+
async repayCoinPTB(t, e, n, s) {
|
|
547
|
+
rt(t, e, n, {
|
|
548
548
|
...this.walletClient.lending.naviServiceOptions,
|
|
549
549
|
amount: s
|
|
550
550
|
});
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
|
-
class
|
|
553
|
+
class Ut extends k {
|
|
554
554
|
constructor() {
|
|
555
555
|
super(), this.name = "lending", this.defaultConfig = {
|
|
556
556
|
env: "prod",
|
|
@@ -572,7 +572,7 @@ class _t extends k {
|
|
|
572
572
|
super.install(t), this._protocols = [];
|
|
573
573
|
}
|
|
574
574
|
async getProtocol(t) {
|
|
575
|
-
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((
|
|
575
|
+
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((e) => e.name === t);
|
|
576
576
|
}
|
|
577
577
|
/**
|
|
578
578
|
* Gets all available lending pools
|
|
@@ -594,11 +594,11 @@ class _t extends k {
|
|
|
594
594
|
* @param options - Optional caching options
|
|
595
595
|
* @returns Pool information
|
|
596
596
|
*/
|
|
597
|
-
async getPool(t,
|
|
597
|
+
async getPool(t, e) {
|
|
598
598
|
return await P(t, {
|
|
599
599
|
...this.naviServiceOptions,
|
|
600
600
|
env: this.config.env,
|
|
601
|
-
...
|
|
601
|
+
...e
|
|
602
602
|
});
|
|
603
603
|
}
|
|
604
604
|
/**
|
|
@@ -609,7 +609,7 @@ class _t extends k {
|
|
|
609
609
|
* @param options - Optional parameters including dry run mode and account capability
|
|
610
610
|
* @returns Transaction response or dry run response
|
|
611
611
|
*/
|
|
612
|
-
async deposit(t,
|
|
612
|
+
async deposit(t, e, n) {
|
|
613
613
|
if (!this.walletClient)
|
|
614
614
|
throw new Error("Wallet client not found");
|
|
615
615
|
const s = await P(t, {
|
|
@@ -618,22 +618,22 @@ class _t extends k {
|
|
|
618
618
|
});
|
|
619
619
|
await this.walletClient.module("balance").waitForUpdate();
|
|
620
620
|
const a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
|
|
621
|
-
balance:
|
|
621
|
+
balance: e,
|
|
622
622
|
useGasCoin: !0
|
|
623
623
|
});
|
|
624
624
|
await A(a, s, o, {
|
|
625
625
|
...this.naviServiceOptions,
|
|
626
626
|
env: this.config.env,
|
|
627
|
-
amount:
|
|
628
|
-
accountCap:
|
|
627
|
+
amount: e,
|
|
628
|
+
accountCap: n?.accountCap
|
|
629
629
|
});
|
|
630
630
|
const l = await this.walletClient.signExecuteTransaction({
|
|
631
631
|
transaction: a,
|
|
632
|
-
dryRun:
|
|
632
|
+
dryRun: n?.dryRun ?? !1
|
|
633
633
|
});
|
|
634
|
-
return !
|
|
634
|
+
return !n?.dryRun && p(l) && (this.emit("lending:deposit-success", {
|
|
635
635
|
identifier: t,
|
|
636
|
-
amount:
|
|
636
|
+
amount: e
|
|
637
637
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
638
638
|
}
|
|
639
639
|
/**
|
|
@@ -644,27 +644,27 @@ class _t extends k {
|
|
|
644
644
|
* @param options - Optional parameters including dry run mode and account capability
|
|
645
645
|
* @returns Transaction response or dry run response
|
|
646
646
|
*/
|
|
647
|
-
async withdraw(t,
|
|
647
|
+
async withdraw(t, e, n) {
|
|
648
648
|
if (!this.walletClient)
|
|
649
649
|
throw new Error("Wallet client not found");
|
|
650
650
|
const s = await P(t, {
|
|
651
651
|
...this.naviServiceOptions,
|
|
652
652
|
env: this.config.env
|
|
653
653
|
}), a = new h();
|
|
654
|
-
|
|
655
|
-
const r = await ot(a, s,
|
|
654
|
+
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
655
|
+
const r = await ot(a, s, e, {
|
|
656
656
|
...this.naviServiceOptions,
|
|
657
657
|
env: this.config.env,
|
|
658
|
-
accountCap:
|
|
658
|
+
accountCap: n?.accountCap
|
|
659
659
|
});
|
|
660
660
|
a.transferObjects([r], this.walletClient.address);
|
|
661
661
|
const o = await this.walletClient.signExecuteTransaction({
|
|
662
662
|
transaction: a,
|
|
663
|
-
dryRun:
|
|
663
|
+
dryRun: n?.dryRun ?? !1
|
|
664
664
|
});
|
|
665
|
-
return !
|
|
665
|
+
return !n?.dryRun && p(o) && (this.emit("lending:withdraw-success", {
|
|
666
666
|
identifier: t,
|
|
667
|
-
amount:
|
|
667
|
+
amount: e
|
|
668
668
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
669
669
|
}
|
|
670
670
|
/**
|
|
@@ -675,27 +675,27 @@ class _t extends k {
|
|
|
675
675
|
* @param options - Optional parameters including dry run mode and account capability
|
|
676
676
|
* @returns Transaction response or dry run response
|
|
677
677
|
*/
|
|
678
|
-
async borrow(t,
|
|
678
|
+
async borrow(t, e, n) {
|
|
679
679
|
if (!this.walletClient)
|
|
680
680
|
throw new Error("Wallet client not found");
|
|
681
681
|
const s = await P(t, {
|
|
682
682
|
...this.naviServiceOptions,
|
|
683
683
|
env: this.config.env
|
|
684
684
|
}), a = new h();
|
|
685
|
-
|
|
686
|
-
const r = await st(a, s,
|
|
685
|
+
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
686
|
+
const r = await st(a, s, e, {
|
|
687
687
|
...this.naviServiceOptions,
|
|
688
688
|
env: this.config.env,
|
|
689
|
-
accountCap:
|
|
689
|
+
accountCap: n?.accountCap
|
|
690
690
|
});
|
|
691
691
|
a.transferObjects([r], this.walletClient.address);
|
|
692
692
|
const o = await this.walletClient.signExecuteTransaction({
|
|
693
693
|
transaction: a,
|
|
694
|
-
dryRun:
|
|
694
|
+
dryRun: n?.dryRun ?? !1
|
|
695
695
|
});
|
|
696
|
-
return !
|
|
696
|
+
return !n?.dryRun && p(o) && (this.emit("lending:borrow-success", {
|
|
697
697
|
identifier: t,
|
|
698
|
-
amount:
|
|
698
|
+
amount: e
|
|
699
699
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
700
700
|
}
|
|
701
701
|
/**
|
|
@@ -706,7 +706,7 @@ class _t extends k {
|
|
|
706
706
|
* @param options - Optional parameters including dry run mode and account capability
|
|
707
707
|
* @returns Transaction response or dry run response
|
|
708
708
|
*/
|
|
709
|
-
async repay(t,
|
|
709
|
+
async repay(t, e, n) {
|
|
710
710
|
if (!this.walletClient)
|
|
711
711
|
throw new Error("Wallet client not found");
|
|
712
712
|
await this.walletClient.module("balance").waitForUpdate();
|
|
@@ -714,22 +714,22 @@ class _t extends k {
|
|
|
714
714
|
...this.naviServiceOptions,
|
|
715
715
|
env: this.config.env
|
|
716
716
|
}), a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
|
|
717
|
-
balance:
|
|
717
|
+
balance: e,
|
|
718
718
|
useGasCoin: !0
|
|
719
719
|
});
|
|
720
720
|
await rt(a, s, o, {
|
|
721
721
|
...this.naviServiceOptions,
|
|
722
722
|
env: this.config.env,
|
|
723
|
-
amount:
|
|
724
|
-
accountCap:
|
|
723
|
+
amount: e,
|
|
724
|
+
accountCap: n?.accountCap
|
|
725
725
|
});
|
|
726
726
|
const l = await this.walletClient.signExecuteTransaction({
|
|
727
727
|
transaction: a,
|
|
728
|
-
dryRun:
|
|
728
|
+
dryRun: n?.dryRun ?? !1
|
|
729
729
|
});
|
|
730
|
-
return !
|
|
730
|
+
return !n?.dryRun && p(l) && (this.emit("lending:repay-success", {
|
|
731
731
|
identifier: t,
|
|
732
|
-
amount:
|
|
732
|
+
amount: e
|
|
733
733
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
734
734
|
}
|
|
735
735
|
/**
|
|
@@ -757,17 +757,17 @@ class _t extends k {
|
|
|
757
757
|
* @param options - Optional parameters including dry run mode
|
|
758
758
|
* @returns Transaction response or dry run response
|
|
759
759
|
*/
|
|
760
|
-
async liquidate(t,
|
|
760
|
+
async liquidate(t, e, n, s, a) {
|
|
761
761
|
if (!this.walletClient)
|
|
762
762
|
throw new Error("Wallet client not found");
|
|
763
763
|
const r = await P(t, {
|
|
764
764
|
...this.naviServiceOptions,
|
|
765
765
|
env: this.config.env
|
|
766
|
-
}), o = await P(
|
|
766
|
+
}), o = await P(n, {
|
|
767
767
|
...this.naviServiceOptions,
|
|
768
768
|
env: this.config.env
|
|
769
769
|
}), l = new h(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u = m(l, c.coins, {
|
|
770
|
-
balance:
|
|
770
|
+
balance: e,
|
|
771
771
|
useGasCoin: !0
|
|
772
772
|
}), [w, d] = await bt(
|
|
773
773
|
l,
|
|
@@ -795,8 +795,8 @@ class _t extends k {
|
|
|
795
795
|
});
|
|
796
796
|
return !a?.dryRun && p(y) && (this.emit("lending:liquidate-success", {
|
|
797
797
|
payIdentifier: t,
|
|
798
|
-
payAmount:
|
|
799
|
-
collateralIdentifier:
|
|
798
|
+
payAmount: e,
|
|
799
|
+
collateralIdentifier: n,
|
|
800
800
|
liquidationAddress: s
|
|
801
801
|
}), this.walletClient.module("balance").updatePortfolio()), y;
|
|
802
802
|
}
|
|
@@ -841,33 +841,33 @@ class _t extends k {
|
|
|
841
841
|
async claimAllRewards(t) {
|
|
842
842
|
if (!this.walletClient)
|
|
843
843
|
throw new Error("Wallet client not found");
|
|
844
|
-
const
|
|
844
|
+
const e = new h(), n = await D(this.walletClient.address, {
|
|
845
845
|
...this.naviServiceOptions,
|
|
846
846
|
env: this.config.env,
|
|
847
847
|
client: this.walletClient.client
|
|
848
848
|
});
|
|
849
|
-
await Bt(
|
|
849
|
+
await Bt(e, n, {
|
|
850
850
|
...this.naviServiceOptions,
|
|
851
851
|
env: this.config.env,
|
|
852
852
|
accountCap: t?.accountCap
|
|
853
853
|
});
|
|
854
854
|
const s = await this.walletClient.signExecuteTransaction({
|
|
855
|
-
transaction:
|
|
855
|
+
transaction: e,
|
|
856
856
|
dryRun: t?.dryRun ?? !1
|
|
857
857
|
});
|
|
858
858
|
return !t?.dryRun && p(s) && (this.emit("lending:claim-rewards-success", {
|
|
859
|
-
rewards:
|
|
859
|
+
rewards: n
|
|
860
860
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
861
861
|
}
|
|
862
|
-
async updateOraclePTB(t,
|
|
863
|
-
const
|
|
862
|
+
async updateOraclePTB(t, e) {
|
|
863
|
+
const n = await $({
|
|
864
864
|
...this.naviServiceOptions,
|
|
865
865
|
env: this.config.env
|
|
866
866
|
}), s = await this.getLendingState({
|
|
867
867
|
cacheTime: 60 * 1e3
|
|
868
|
-
}), a = q(
|
|
868
|
+
}), a = q(n, {
|
|
869
869
|
lendingState: s,
|
|
870
|
-
pools:
|
|
870
|
+
pools: e
|
|
871
871
|
});
|
|
872
872
|
await K(t, a, {
|
|
873
873
|
...this.naviServiceOptions,
|
|
@@ -886,9 +886,9 @@ class _t extends k {
|
|
|
886
886
|
async updateOracle(t) {
|
|
887
887
|
if (!this.walletClient)
|
|
888
888
|
throw new Error("Wallet client not found");
|
|
889
|
-
const
|
|
890
|
-
return await this.updateOraclePTB(
|
|
891
|
-
transaction:
|
|
889
|
+
const e = new h();
|
|
890
|
+
return await this.updateOraclePTB(e, t?.pools), await this.walletClient.signExecuteTransaction({
|
|
891
|
+
transaction: e,
|
|
892
892
|
dryRun: t?.dryRun ?? !1
|
|
893
893
|
});
|
|
894
894
|
}
|
|
@@ -917,9 +917,9 @@ class _t extends k {
|
|
|
917
917
|
async createAccountCap(t) {
|
|
918
918
|
if (!this.walletClient)
|
|
919
919
|
throw new Error("Wallet client not found");
|
|
920
|
-
const
|
|
921
|
-
return
|
|
922
|
-
transaction:
|
|
920
|
+
const e = new h(), n = await Pt(e);
|
|
921
|
+
return e.transferObjects([n], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
922
|
+
transaction: e,
|
|
923
923
|
dryRun: t?.dryRun ?? !1
|
|
924
924
|
});
|
|
925
925
|
}
|
|
@@ -929,17 +929,17 @@ class _t extends k {
|
|
|
929
929
|
return;
|
|
930
930
|
}
|
|
931
931
|
const t = [];
|
|
932
|
-
if (t.push(new
|
|
932
|
+
if (t.push(new _t(this.walletClient)), this.config.enableSuilend)
|
|
933
933
|
try {
|
|
934
|
-
const { default:
|
|
934
|
+
const { default: e } = await import("./suilend-CWugUjwd.js");
|
|
935
935
|
t.push(
|
|
936
|
-
await
|
|
936
|
+
await e.create(this.walletClient, {
|
|
937
937
|
grpcClient: this.config.suilendGrpcClient,
|
|
938
938
|
grpcUrl: this.config.suilendGrpcUrl
|
|
939
939
|
})
|
|
940
940
|
);
|
|
941
|
-
} catch (
|
|
942
|
-
console.warn("Failed to initialize SuilendProtocol:",
|
|
941
|
+
} catch (e) {
|
|
942
|
+
console.warn("Failed to initialize SuilendProtocol:", e);
|
|
943
943
|
}
|
|
944
944
|
this._protocols = t;
|
|
945
945
|
}
|
|
@@ -953,9 +953,9 @@ class Wt extends k {
|
|
|
953
953
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
954
954
|
}, this.getStatsCached = lt(
|
|
955
955
|
Q(async (t) => {
|
|
956
|
-
const
|
|
957
|
-
return (await fetch(ut("/volo/stats",
|
|
958
|
-
headers: ht({},
|
|
956
|
+
const e = { services: t?.services }, n = ct(e);
|
|
957
|
+
return (await fetch(ut("/volo/stats", e), {
|
|
958
|
+
headers: ht({}, n)
|
|
959
959
|
}).then((a) => a.json())).data;
|
|
960
960
|
})
|
|
961
961
|
);
|
|
@@ -972,18 +972,18 @@ class Wt extends k {
|
|
|
972
972
|
* @param suiCoin - The SUI coin object to stake
|
|
973
973
|
* @returns The vSUI coin object received from staking
|
|
974
974
|
*/
|
|
975
|
-
async stakePTB(t,
|
|
976
|
-
const [
|
|
975
|
+
async stakePTB(t, e) {
|
|
976
|
+
const [n] = t.moveCall({
|
|
977
977
|
target: `${this.config.packageId}::stake_pool::stake`,
|
|
978
978
|
arguments: [
|
|
979
979
|
t.object(this.config.poolId),
|
|
980
980
|
t.object(this.config.metadataId),
|
|
981
981
|
t.object("0x05"),
|
|
982
|
-
F(
|
|
982
|
+
F(e, t.object)
|
|
983
983
|
],
|
|
984
984
|
typeArguments: []
|
|
985
985
|
});
|
|
986
|
-
return
|
|
986
|
+
return n;
|
|
987
987
|
}
|
|
988
988
|
/**
|
|
989
989
|
* Adds unstaking operation to a transaction black
|
|
@@ -992,18 +992,18 @@ class Wt extends k {
|
|
|
992
992
|
* @param vSuiCoin - The vSUI coin object to unstake
|
|
993
993
|
* @returns The SUI coin object received from unstaking
|
|
994
994
|
*/
|
|
995
|
-
async unstakePTB(t,
|
|
996
|
-
const [
|
|
995
|
+
async unstakePTB(t, e) {
|
|
996
|
+
const [n] = t.moveCall({
|
|
997
997
|
target: `${this.config.packageId}::stake_pool::unstake`,
|
|
998
998
|
arguments: [
|
|
999
999
|
t.object(this.config.poolId),
|
|
1000
1000
|
t.object(this.config.metadataId),
|
|
1001
1001
|
t.object("0x05"),
|
|
1002
|
-
F(
|
|
1002
|
+
F(e, t.object)
|
|
1003
1003
|
],
|
|
1004
1004
|
typeArguments: []
|
|
1005
1005
|
});
|
|
1006
|
-
return
|
|
1006
|
+
return n;
|
|
1007
1007
|
}
|
|
1008
1008
|
/**
|
|
1009
1009
|
* Stake SUI tokens to receive vSUI tokens
|
|
@@ -1013,23 +1013,23 @@ class Wt extends k {
|
|
|
1013
1013
|
* @returns Transaction response or dry run response
|
|
1014
1014
|
* @throws Error if wallet client not found or stake amount is too low
|
|
1015
1015
|
*/
|
|
1016
|
-
async stake(t,
|
|
1016
|
+
async stake(t, e) {
|
|
1017
1017
|
if (!this.walletClient)
|
|
1018
1018
|
throw new Error("Wallet client not found");
|
|
1019
1019
|
if (t < 1e9)
|
|
1020
1020
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
1021
|
-
const
|
|
1021
|
+
const n = new h();
|
|
1022
1022
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1023
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(
|
|
1023
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
|
|
1024
1024
|
balance: t,
|
|
1025
1025
|
useGasCoin: !0
|
|
1026
|
-
}), r = await this.stakePTB(
|
|
1027
|
-
|
|
1026
|
+
}), r = await this.stakePTB(n, a);
|
|
1027
|
+
n.transferObjects([r], this.walletClient.address);
|
|
1028
1028
|
const o = await this.walletClient.signExecuteTransaction({
|
|
1029
|
-
transaction:
|
|
1030
|
-
dryRun:
|
|
1029
|
+
transaction: n,
|
|
1030
|
+
dryRun: e?.dryRun ?? !1
|
|
1031
1031
|
});
|
|
1032
|
-
return !
|
|
1032
|
+
return !e?.dryRun && p(o) && (this.emit("volo:stake-success", {
|
|
1033
1033
|
suiAmount: t
|
|
1034
1034
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1035
1035
|
}
|
|
@@ -1041,26 +1041,26 @@ class Wt extends k {
|
|
|
1041
1041
|
* @returns Transaction response or dry run response
|
|
1042
1042
|
* @throws Error if wallet client not found or unstake amount is too low
|
|
1043
1043
|
*/
|
|
1044
|
-
async unstake(t,
|
|
1044
|
+
async unstake(t, e) {
|
|
1045
1045
|
if (!this.walletClient)
|
|
1046
1046
|
throw new Error("Wallet client not found");
|
|
1047
1047
|
if (t < 1e9)
|
|
1048
1048
|
throw new Error("Unstake amount should >= 1vSui");
|
|
1049
1049
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1050
|
-
const
|
|
1050
|
+
const n = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
|
|
1051
1051
|
balance: t
|
|
1052
|
-
}), r = await this.unstakePTB(
|
|
1053
|
-
|
|
1052
|
+
}), r = await this.unstakePTB(n, a);
|
|
1053
|
+
n.transferObjects([r], this.walletClient.address);
|
|
1054
1054
|
const o = await this.walletClient.signExecuteTransaction({
|
|
1055
|
-
transaction:
|
|
1056
|
-
dryRun:
|
|
1055
|
+
transaction: n,
|
|
1056
|
+
dryRun: e?.dryRun ?? !1
|
|
1057
1057
|
});
|
|
1058
|
-
return !
|
|
1058
|
+
return !e?.dryRun && p(o) && (this.emit("volo:unstake-success", {
|
|
1059
1059
|
vSuiAmount: t
|
|
1060
1060
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1061
1061
|
}
|
|
1062
1062
|
}
|
|
1063
|
-
function
|
|
1063
|
+
function It() {
|
|
1064
1064
|
const i = H(G);
|
|
1065
1065
|
return {
|
|
1066
1066
|
effects: i.showEffects,
|
|
@@ -1069,10 +1069,10 @@ function Ut() {
|
|
|
1069
1069
|
objectTypes: i.showObjectChanges
|
|
1070
1070
|
};
|
|
1071
1071
|
}
|
|
1072
|
-
function
|
|
1072
|
+
function Jt(i) {
|
|
1073
1073
|
return i.core;
|
|
1074
1074
|
}
|
|
1075
|
-
class
|
|
1075
|
+
class Lt extends k {
|
|
1076
1076
|
constructor() {
|
|
1077
1077
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1078
1078
|
apiKey: "",
|
|
@@ -1089,7 +1089,7 @@ class Jt extends k {
|
|
|
1089
1089
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
1090
1090
|
*/
|
|
1091
1091
|
get referral() {
|
|
1092
|
-
return this.config.apiKey ?
|
|
1092
|
+
return this.config.apiKey ? Rt(this.config.apiKey) : 0;
|
|
1093
1093
|
}
|
|
1094
1094
|
/**
|
|
1095
1095
|
* Get the swap options
|
|
@@ -1111,8 +1111,8 @@ class Jt extends k {
|
|
|
1111
1111
|
* @param fromAmount - The amount of the coin being swapped from
|
|
1112
1112
|
* @returns A promise that resolves with the quote
|
|
1113
1113
|
*/
|
|
1114
|
-
async getQuote(t,
|
|
1115
|
-
return
|
|
1114
|
+
async getQuote(t, e, n) {
|
|
1115
|
+
return xt(t, e, n, this.config.apiKey, this.swapOptions);
|
|
1116
1116
|
}
|
|
1117
1117
|
/**
|
|
1118
1118
|
* Builds a swap transaction from a quote
|
|
@@ -1122,16 +1122,16 @@ class Jt extends k {
|
|
|
1122
1122
|
* @param slippage - The slippage tolerance
|
|
1123
1123
|
* @returns The swap transaction
|
|
1124
1124
|
*/
|
|
1125
|
-
async buildSwapPTBFromQuote(t,
|
|
1125
|
+
async buildSwapPTBFromQuote(t, e, n, s) {
|
|
1126
1126
|
if (!this.walletClient)
|
|
1127
1127
|
throw new Error("Wallet client not found");
|
|
1128
|
-
const a = new E(
|
|
1128
|
+
const a = new E(e.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1129
1129
|
return await z(
|
|
1130
1130
|
this.walletClient.address,
|
|
1131
1131
|
t,
|
|
1132
1132
|
Number(a),
|
|
1133
|
-
e,
|
|
1134
1133
|
n,
|
|
1134
|
+
e,
|
|
1135
1135
|
this.referral,
|
|
1136
1136
|
!1,
|
|
1137
1137
|
this.config.apiKey,
|
|
@@ -1155,14 +1155,14 @@ class Jt extends k {
|
|
|
1155
1155
|
* @param options - Optional parameters including dry run mode
|
|
1156
1156
|
* @returns Transaction response or dry run response
|
|
1157
1157
|
*/
|
|
1158
|
-
async swap(t,
|
|
1158
|
+
async swap(t, e, n, s, a) {
|
|
1159
1159
|
if (!this.walletClient)
|
|
1160
1160
|
throw new Error("Wallet client not found");
|
|
1161
1161
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1162
1162
|
const r = this.walletClient.module("balance").portfolio.getBalance(t), o = new h(), l = m(o, r.coins, {
|
|
1163
|
-
balance:
|
|
1163
|
+
balance: n,
|
|
1164
1164
|
useGasCoin: !0
|
|
1165
|
-
}), c = await this.getQuote(t,
|
|
1165
|
+
}), c = await this.getQuote(t, e, n), u = await this.buildSwapPTBFromQuote(o, c, l, s);
|
|
1166
1166
|
if (o.transferObjects([u], this.walletClient.address), o.setSender(this.walletClient.address), a?.dryRun)
|
|
1167
1167
|
return await this.walletClient.signExecuteTransaction({
|
|
1168
1168
|
transaction: o,
|
|
@@ -1172,14 +1172,14 @@ class Jt extends k {
|
|
|
1172
1172
|
client: this.walletClient.client
|
|
1173
1173
|
}), d = await this.walletClient.signer.signTransaction(w), f = [d.signature];
|
|
1174
1174
|
try {
|
|
1175
|
-
await
|
|
1175
|
+
await At(d.bytes, f);
|
|
1176
1176
|
} catch (g) {
|
|
1177
1177
|
console.error(g);
|
|
1178
1178
|
}
|
|
1179
|
-
const C =
|
|
1179
|
+
const C = Jt(this.walletClient.client), y = typeof C?.executeTransaction == "function" ? await C.executeTransaction({
|
|
1180
1180
|
transaction: dt(d.bytes),
|
|
1181
1181
|
signatures: f,
|
|
1182
|
-
include:
|
|
1182
|
+
include: It()
|
|
1183
1183
|
}) : await (() => {
|
|
1184
1184
|
const g = this.walletClient.clientBundle.legacyJsonRpc;
|
|
1185
1185
|
if (!g)
|
|
@@ -1196,8 +1196,8 @@ class Jt extends k {
|
|
|
1196
1196
|
const g = b.events?.find((T) => T.type?.includes("::slippage::SwapEvent"));
|
|
1197
1197
|
g && this.emit("swap:swap-success", {
|
|
1198
1198
|
fromCoinType: t,
|
|
1199
|
-
toCoinType:
|
|
1200
|
-
fromAmount:
|
|
1199
|
+
toCoinType: e,
|
|
1200
|
+
fromAmount: n,
|
|
1201
1201
|
slippage: s,
|
|
1202
1202
|
toAmount: Number(g.parsedJson.amount_out)
|
|
1203
1203
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
@@ -1205,7 +1205,7 @@ class Jt extends k {
|
|
|
1205
1205
|
return b;
|
|
1206
1206
|
}
|
|
1207
1207
|
}
|
|
1208
|
-
class
|
|
1208
|
+
class Mt extends k {
|
|
1209
1209
|
constructor() {
|
|
1210
1210
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1211
1211
|
packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
|
|
@@ -1213,9 +1213,9 @@ class Lt extends k {
|
|
|
1213
1213
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1214
1214
|
}, this.getApyCached = lt(
|
|
1215
1215
|
Q(async (t) => {
|
|
1216
|
-
const
|
|
1217
|
-
return (await fetch(ut("/haedal/stats",
|
|
1218
|
-
headers: ht({},
|
|
1216
|
+
const e = { services: t?.services }, n = ct(e);
|
|
1217
|
+
return (await fetch(ut("/haedal/stats", e), {
|
|
1218
|
+
headers: ht({}, n)
|
|
1219
1219
|
}).then((a) => a.json())).data.apy;
|
|
1220
1220
|
})
|
|
1221
1221
|
);
|
|
@@ -1232,18 +1232,18 @@ class Lt extends k {
|
|
|
1232
1232
|
* @param suiCoin - Sui coin object to stake
|
|
1233
1233
|
* @returns haSUI coin object
|
|
1234
1234
|
*/
|
|
1235
|
-
async stakePTB(t,
|
|
1236
|
-
const [
|
|
1235
|
+
async stakePTB(t, e) {
|
|
1236
|
+
const [n] = t.moveCall({
|
|
1237
1237
|
target: `${this.config.packageId}::staking::request_stake_coin`,
|
|
1238
1238
|
arguments: [
|
|
1239
1239
|
t.object("0x05"),
|
|
1240
1240
|
t.object(this.config.configId),
|
|
1241
|
-
F(
|
|
1241
|
+
F(e, t.object),
|
|
1242
1242
|
t.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1243
1243
|
],
|
|
1244
1244
|
typeArguments: []
|
|
1245
1245
|
});
|
|
1246
|
-
return
|
|
1246
|
+
return n;
|
|
1247
1247
|
}
|
|
1248
1248
|
/**
|
|
1249
1249
|
* Builds a transaction block for unstaking haSUI to SUI
|
|
@@ -1252,17 +1252,17 @@ class Lt extends k {
|
|
|
1252
1252
|
* @param haSUICoin - haSUI coin object to unstake
|
|
1253
1253
|
* @returns SUI coin object
|
|
1254
1254
|
*/
|
|
1255
|
-
async unstakePTB(t,
|
|
1256
|
-
const [
|
|
1255
|
+
async unstakePTB(t, e) {
|
|
1256
|
+
const [n] = t.moveCall({
|
|
1257
1257
|
target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
|
|
1258
1258
|
arguments: [
|
|
1259
1259
|
t.object("0x05"),
|
|
1260
1260
|
t.object(this.config.configId),
|
|
1261
|
-
F(
|
|
1261
|
+
F(e, t.object)
|
|
1262
1262
|
],
|
|
1263
1263
|
typeArguments: []
|
|
1264
1264
|
});
|
|
1265
|
-
return
|
|
1265
|
+
return n;
|
|
1266
1266
|
}
|
|
1267
1267
|
/**
|
|
1268
1268
|
* Stake SUI for haSUI
|
|
@@ -1270,21 +1270,21 @@ class Lt extends k {
|
|
|
1270
1270
|
* @param suiAmount - Amount of SUI to stake
|
|
1271
1271
|
* @param options Optional dry run
|
|
1272
1272
|
*/
|
|
1273
|
-
async stake(t,
|
|
1273
|
+
async stake(t, e) {
|
|
1274
1274
|
if (!this.walletClient)
|
|
1275
1275
|
throw new Error("Wallet client not found");
|
|
1276
|
-
const
|
|
1276
|
+
const n = new h();
|
|
1277
1277
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1278
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(
|
|
1278
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
|
|
1279
1279
|
balance: t,
|
|
1280
1280
|
useGasCoin: !0
|
|
1281
|
-
}), r = await this.stakePTB(
|
|
1282
|
-
|
|
1281
|
+
}), r = await this.stakePTB(n, a);
|
|
1282
|
+
n.transferObjects([r], this.walletClient.address);
|
|
1283
1283
|
const o = await this.walletClient.signExecuteTransaction({
|
|
1284
|
-
transaction:
|
|
1285
|
-
dryRun:
|
|
1284
|
+
transaction: n,
|
|
1285
|
+
dryRun: e?.dryRun ?? !1
|
|
1286
1286
|
});
|
|
1287
|
-
return !
|
|
1287
|
+
return !e?.dryRun && p(o) && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1288
1288
|
}
|
|
1289
1289
|
/**
|
|
1290
1290
|
* Unstake haSUI for SUI
|
|
@@ -1292,32 +1292,32 @@ class Lt extends k {
|
|
|
1292
1292
|
* @param haSUIAmount - Amount of haSUI to unstake
|
|
1293
1293
|
* @param options Optional dry run
|
|
1294
1294
|
*/
|
|
1295
|
-
async unstake(t,
|
|
1295
|
+
async unstake(t, e) {
|
|
1296
1296
|
if (!this.walletClient)
|
|
1297
1297
|
throw new Error("Wallet client not found");
|
|
1298
1298
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1299
|
-
const
|
|
1299
|
+
const n = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
|
|
1300
1300
|
balance: t
|
|
1301
|
-
}), r = await this.unstakePTB(
|
|
1302
|
-
|
|
1301
|
+
}), r = await this.unstakePTB(n, a);
|
|
1302
|
+
n.transferObjects([r], this.walletClient.address);
|
|
1303
1303
|
const o = await this.walletClient.signExecuteTransaction({
|
|
1304
|
-
transaction:
|
|
1305
|
-
dryRun:
|
|
1304
|
+
transaction: n,
|
|
1305
|
+
dryRun: e?.dryRun ?? !1
|
|
1306
1306
|
});
|
|
1307
|
-
return !
|
|
1307
|
+
return !e?.dryRun && p(o) && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1308
1308
|
}
|
|
1309
1309
|
}
|
|
1310
|
-
const
|
|
1310
|
+
const Qt = {
|
|
1311
1311
|
/** Balance management module */
|
|
1312
|
-
balance: new
|
|
1312
|
+
balance: new jt(),
|
|
1313
1313
|
/** Lending protocol module */
|
|
1314
|
-
lending: new
|
|
1314
|
+
lending: new Ut(),
|
|
1315
1315
|
/** Volo protocol module */
|
|
1316
1316
|
volo: new Wt(),
|
|
1317
1317
|
/** DEX swapping module */
|
|
1318
|
-
swap: new
|
|
1318
|
+
swap: new Lt(),
|
|
1319
1319
|
/** Haedal protocol module */
|
|
1320
|
-
haedal: new
|
|
1320
|
+
haedal: new Mt()
|
|
1321
1321
|
};
|
|
1322
1322
|
function Z(i) {
|
|
1323
1323
|
const t = H(i);
|
|
@@ -1331,31 +1331,36 @@ function Z(i) {
|
|
|
1331
1331
|
function tt(i) {
|
|
1332
1332
|
return i.core;
|
|
1333
1333
|
}
|
|
1334
|
-
function
|
|
1334
|
+
function $t(i) {
|
|
1335
1335
|
return "grpc" in i;
|
|
1336
1336
|
}
|
|
1337
|
-
function
|
|
1338
|
-
if (
|
|
1339
|
-
return
|
|
1340
|
-
const t = i.network ?? "mainnet",
|
|
1337
|
+
function Kt(i) {
|
|
1338
|
+
if ($t(i))
|
|
1339
|
+
return Ot(i);
|
|
1340
|
+
const t = i.network ?? "mainnet", e = Et(t, i.legacyJsonRpc);
|
|
1341
1341
|
return {
|
|
1342
1342
|
network: t,
|
|
1343
|
-
coreClient:
|
|
1344
|
-
grpc:
|
|
1345
|
-
legacyJsonRpc:
|
|
1343
|
+
coreClient: e,
|
|
1344
|
+
grpc: e,
|
|
1345
|
+
legacyJsonRpc: e,
|
|
1346
1346
|
services: i.services
|
|
1347
1347
|
};
|
|
1348
1348
|
}
|
|
1349
|
-
class
|
|
1349
|
+
class Zt {
|
|
1350
1350
|
/**
|
|
1351
1351
|
* Creates a new wallet client instance
|
|
1352
1352
|
* @param options - Configuration options for the wallet client
|
|
1353
1353
|
*/
|
|
1354
1354
|
constructor(t) {
|
|
1355
|
-
this.modules =
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1355
|
+
this.modules = Qt, this.userConfigs = {}, this.events = mt();
|
|
1356
|
+
const e = t.client ?? {
|
|
1357
|
+
network: "mainnet",
|
|
1358
|
+
grpc: { url: St }
|
|
1359
|
+
};
|
|
1360
|
+
this.clientBundle = Kt(e), this.client = this.clientBundle.coreClient, this.clientUrl = "grpc" in e ? e.legacyJsonRpc && "url" in e.legacyJsonRpc ? e.legacyJsonRpc.url : void 0 : "url" in e.legacyJsonRpc ? e.legacyJsonRpc.url : void 0, this.signer = t.signer, this.userConfigs = t.configs || {}, Object.entries(this.modules).forEach(([n, s]) => {
|
|
1361
|
+
if (n !== s.name)
|
|
1362
|
+
throw new Error(`Module name ${n} does not match module name ${s.name}`);
|
|
1363
|
+
s.install(this);
|
|
1359
1364
|
});
|
|
1360
1365
|
}
|
|
1361
1366
|
get lending() {
|
|
@@ -1379,14 +1384,14 @@ class Yt {
|
|
|
1379
1384
|
* @returns Promise with transaction execution result
|
|
1380
1385
|
*/
|
|
1381
1386
|
async signExecuteTransaction(t) {
|
|
1382
|
-
const { dryRun:
|
|
1383
|
-
if (
|
|
1387
|
+
const { dryRun: e = !1, ...n } = t;
|
|
1388
|
+
if (e) {
|
|
1384
1389
|
const o = tt(this.client);
|
|
1385
1390
|
if (typeof o?.simulateTransaction == "function") {
|
|
1386
1391
|
t.transaction instanceof h && t.transaction.setSenderIfNotSet(this.address);
|
|
1387
1392
|
const w = await o.simulateTransaction({
|
|
1388
1393
|
transaction: t.transaction,
|
|
1389
|
-
include: Z(
|
|
1394
|
+
include: Z(n.options)
|
|
1390
1395
|
});
|
|
1391
1396
|
return x("dryRun", w);
|
|
1392
1397
|
}
|
|
@@ -1413,7 +1418,7 @@ class Yt {
|
|
|
1413
1418
|
const l = await this.signer.signTransaction(o), c = await s.executeTransaction({
|
|
1414
1419
|
transaction: dt(l.bytes),
|
|
1415
1420
|
signatures: [l.signature],
|
|
1416
|
-
include: Z(
|
|
1421
|
+
include: Z(n.options)
|
|
1417
1422
|
});
|
|
1418
1423
|
return x("execute", c);
|
|
1419
1424
|
}
|
|
@@ -1423,8 +1428,8 @@ class Yt {
|
|
|
1423
1428
|
"WalletClient execution requires core.executeTransaction or an explicit legacyJsonRpc client"
|
|
1424
1429
|
);
|
|
1425
1430
|
const r = await a.signAndExecuteTransaction({
|
|
1426
|
-
...
|
|
1427
|
-
options: H(
|
|
1431
|
+
...n,
|
|
1432
|
+
options: H(n.options),
|
|
1428
1433
|
signer: this.signer
|
|
1429
1434
|
});
|
|
1430
1435
|
return x("execute", r);
|
|
@@ -1473,7 +1478,7 @@ function ft(i) {
|
|
|
1473
1478
|
verify: async () => !1
|
|
1474
1479
|
};
|
|
1475
1480
|
}
|
|
1476
|
-
class
|
|
1481
|
+
class te extends wt {
|
|
1477
1482
|
/**
|
|
1478
1483
|
* Creates a new watch-only signer
|
|
1479
1484
|
*
|
|
@@ -1521,7 +1526,7 @@ class Zt extends wt {
|
|
|
1521
1526
|
return {};
|
|
1522
1527
|
}
|
|
1523
1528
|
}
|
|
1524
|
-
class
|
|
1529
|
+
class ee extends wt {
|
|
1525
1530
|
/**
|
|
1526
1531
|
* Creates a new watch-only signer
|
|
1527
1532
|
*
|
|
@@ -1561,8 +1566,8 @@ class te extends wt {
|
|
|
1561
1566
|
}
|
|
1562
1567
|
}
|
|
1563
1568
|
export {
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1569
|
+
Zt as WalletClient,
|
|
1570
|
+
te as WatchSigner,
|
|
1571
|
+
ee as WebSigner
|
|
1567
1572
|
};
|
|
1568
1573
|
//# sourceMappingURL=index.esm.js.map
|