@naviprotocol/wallet-client 1.4.9 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -9
- package/dist/client.d.ts +9 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/index.esm.js +295 -298
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/balanceModule/index.d.ts +6 -5
- package/dist/modules/balanceModule/index.d.ts.map +1 -1
- package/dist/modules/balanceModule/portfolio.d.ts +1 -1
- package/dist/modules/balanceModule/portfolio.d.ts.map +1 -1
- package/dist/modules/haedalModule/index.d.ts +5 -5
- package/dist/modules/haedalModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/index.d.ts +18 -9
- package/dist/modules/lendingModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/protocols/suilend.d.ts +7 -2
- package/dist/modules/lendingModule/protocols/suilend.d.ts.map +1 -1
- package/dist/modules/swapModule/index.d.ts +3 -3
- package/dist/modules/swapModule/index.d.ts.map +1 -1
- package/dist/modules/voloModule/index.d.ts +5 -5
- package/dist/modules/voloModule/index.d.ts.map +1 -1
- package/dist/signer.d.ts +2 -4
- package/dist/signer.d.ts.map +1 -1
- package/dist/suilend-Df4FukWs.js +80 -0
- package/dist/suilend-Df4FukWs.js.map +1 -0
- package/dist/transaction-result.d.ts +7 -0
- package/dist/transaction-result.d.ts.map +1 -0
- package/dist/transport.d.ts +3 -3
- package/dist/transport.d.ts.map +1 -1
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +35 -11
- package/dist/index.cjs.js +0 -2
- package/dist/index.cjs.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as
|
|
5
|
-
import E, { BigNumber as
|
|
6
|
-
import { normalizeStructTag as
|
|
7
|
-
import { Transaction as
|
|
8
|
-
import { buildSwapPTBFromQuote as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
import { Signer as it } from "@mysten/sui/cryptography";
|
|
13
|
-
const ot = wt.create({
|
|
1
|
+
import { getJsonRpcFullnodeUrl as ct, SuiJsonRpcClient as ut } from "@mysten/sui/jsonRpc";
|
|
2
|
+
import wt from "mitt";
|
|
3
|
+
import dt from "axios";
|
|
4
|
+
import { withSingleton as Q, getCoins as V, mergeCoinsPTB as m, getPriceFeeds as $, updateOraclePricesPTB as q, filterPriceFeeds as K, depositCoinPTB as A, getFlashLoanAsset as X, flashloanPTB as Y, repayFlashLoanPTB as Z, borrowCoinPTB as tt, withdrawCoinPTB as et, repayCoinPTB as nt, getPools as ht, getPool as P, getHealthFactor as ft, liquidatePTB as gt, getUserAvailableLendingRewards as G, getUserClaimedRewardHistory as pt, claimLendingRewardsPTB as mt, getLendingState as Ct, createAccountCapPTB as bt, withCache as at, parseTxValue as x } from "@naviprotocol/lending";
|
|
5
|
+
import E, { BigNumber as L } from "bignumber.js";
|
|
6
|
+
import { normalizeStructTag as b } from "@mysten/sui/utils";
|
|
7
|
+
import { Transaction as d } from "@mysten/sui/transactions";
|
|
8
|
+
import { buildSwapPTBFromQuote as z, generateRefId as yt, getQuote as Pt } from "@naviprotocol/astros-aggregator-sdk";
|
|
9
|
+
import { executeAuction as Bt } from "shio-sdk";
|
|
10
|
+
import { Signer as st } from "@mysten/sui/cryptography";
|
|
11
|
+
const it = dt.create({
|
|
14
12
|
timeout: 2e4
|
|
15
13
|
});
|
|
16
|
-
|
|
17
|
-
function(
|
|
18
|
-
if (
|
|
19
|
-
throw new Error(
|
|
20
|
-
if (
|
|
21
|
-
throw new Error(
|
|
22
|
-
return
|
|
14
|
+
it.interceptors.response.use(
|
|
15
|
+
function(i) {
|
|
16
|
+
if (i.data.err)
|
|
17
|
+
throw new Error(i.data.err);
|
|
18
|
+
if (i.data.error)
|
|
19
|
+
throw new Error(i.data.error.message);
|
|
20
|
+
return i;
|
|
23
21
|
},
|
|
24
|
-
function(
|
|
25
|
-
return Promise.reject(
|
|
22
|
+
function(i) {
|
|
23
|
+
return Promise.reject(i);
|
|
26
24
|
}
|
|
27
25
|
);
|
|
28
|
-
class
|
|
26
|
+
class Tt {
|
|
29
27
|
/**
|
|
30
28
|
* Creates a new custom transport instance
|
|
31
29
|
*
|
|
@@ -44,7 +42,7 @@ class Ot {
|
|
|
44
42
|
* @returns Promise<T> - The response data from the RPC call
|
|
45
43
|
*/
|
|
46
44
|
async request(t) {
|
|
47
|
-
return this.requestId += 1, (await
|
|
45
|
+
return this.requestId += 1, (await it.post(this.rpcUrl, {
|
|
48
46
|
jsonrpc: "2.0",
|
|
49
47
|
id: this.requestId,
|
|
50
48
|
method: t.method,
|
|
@@ -64,7 +62,7 @@ class Ot {
|
|
|
64
62
|
throw new Error("subscribe not implemented.");
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
|
-
class
|
|
65
|
+
class O {
|
|
68
66
|
/**
|
|
69
67
|
* Gets the current configuration for this module
|
|
70
68
|
*
|
|
@@ -118,11 +116,11 @@ class R {
|
|
|
118
116
|
else {
|
|
119
117
|
const e = {};
|
|
120
118
|
t?.forEach((n) => {
|
|
121
|
-
const s =
|
|
119
|
+
const s = b(n.coinType);
|
|
122
120
|
let a = e[s];
|
|
123
121
|
a || (a = {
|
|
124
122
|
coinType: s,
|
|
125
|
-
amount:
|
|
123
|
+
amount: L(0),
|
|
126
124
|
coins: []
|
|
127
125
|
}, e[s] = a), a.coins.push(n), a.amount = a.amount.plus(n.balance);
|
|
128
126
|
}), this.balances = e;
|
|
@@ -135,7 +133,7 @@ class R {
|
|
|
135
133
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
136
134
|
*/
|
|
137
135
|
getBalance(t) {
|
|
138
|
-
return t =
|
|
136
|
+
return t = b(t), this.balances[t] || { coinType: t, amount: L(0), coins: [] };
|
|
139
137
|
}
|
|
140
138
|
/**
|
|
141
139
|
* Gets all coin types in the portfolio
|
|
@@ -152,7 +150,7 @@ class R {
|
|
|
152
150
|
* @returns BigNumber representing the total balance
|
|
153
151
|
*/
|
|
154
152
|
balanceOf(t) {
|
|
155
|
-
return t =
|
|
153
|
+
return t = b(t), this.getBalance(t)?.amount || L(0);
|
|
156
154
|
}
|
|
157
155
|
/**
|
|
158
156
|
* Creates a deep copy of the portfolio
|
|
@@ -167,15 +165,15 @@ class R {
|
|
|
167
165
|
return e.balances = t, e;
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
|
-
class
|
|
168
|
+
class vt extends O {
|
|
171
169
|
constructor() {
|
|
172
170
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
173
171
|
coinPollingInterval: 6e3,
|
|
174
172
|
disableCoinPolling: !1
|
|
175
|
-
}, this.updatePortfolio =
|
|
173
|
+
}, this.updatePortfolio = Q(async () => {
|
|
176
174
|
if (!this.walletClient)
|
|
177
175
|
throw new Error("Wallet client not found");
|
|
178
|
-
this._coins = await
|
|
176
|
+
this._coins = await V(this.walletClient.address, {
|
|
179
177
|
client: this.walletClient.client
|
|
180
178
|
}), this._portfolio = new R(this._coins), this.emit("balance:portfolio-updated", {});
|
|
181
179
|
}), this._coins = [], this._portfolio = new R(), this.pollingTimer = null, this._updatePromise = null;
|
|
@@ -234,19 +232,19 @@ class At extends A {
|
|
|
234
232
|
if (e.length !== n.length)
|
|
235
233
|
throw new Error("Recipients and amounts must have the same length");
|
|
236
234
|
await this.waitForUpdate();
|
|
237
|
-
const a = this.portfolio.getBalance(t), l = n.reduce((
|
|
235
|
+
const a = this.portfolio.getBalance(t), l = n.reduce((f, w) => f.plus(w), E(0));
|
|
238
236
|
if (a.amount.lt(l))
|
|
239
237
|
throw new Error("Insufficient balance");
|
|
240
|
-
const
|
|
241
|
-
let r =
|
|
242
|
-
|
|
238
|
+
const o = new d();
|
|
239
|
+
let r = o.gas;
|
|
240
|
+
b(t) !== b("0x2::sui::SUI") && (r = m(o, a.coins, {
|
|
243
241
|
balance: l.toNumber()
|
|
244
242
|
}));
|
|
245
|
-
const
|
|
246
|
-
return e.forEach((
|
|
247
|
-
|
|
243
|
+
const u = o.splitCoins(r, n);
|
|
244
|
+
return e.forEach((f, w) => {
|
|
245
|
+
o.transferObjects([u[w]], f);
|
|
248
246
|
}), await this.walletClient.signExecuteTransaction({
|
|
249
|
-
transaction:
|
|
247
|
+
transaction: o,
|
|
250
248
|
dryRun: s?.dryRun ?? !1
|
|
251
249
|
});
|
|
252
250
|
}
|
|
@@ -278,9 +276,9 @@ class At extends A {
|
|
|
278
276
|
if (t.length !== e.length)
|
|
279
277
|
throw new Error("Objects and recipients must have the same length");
|
|
280
278
|
await this.waitForUpdate();
|
|
281
|
-
const s = new
|
|
282
|
-
return t.forEach((l,
|
|
283
|
-
s.transferObjects([s.object(l)], e[
|
|
279
|
+
const s = new d();
|
|
280
|
+
return t.forEach((l, o) => {
|
|
281
|
+
s.transferObjects([s.object(l)], e[o]);
|
|
284
282
|
}), await this.walletClient.signExecuteTransaction({
|
|
285
283
|
transaction: s,
|
|
286
284
|
dryRun: n?.dryRun ?? !1
|
|
@@ -324,186 +322,186 @@ class At extends A {
|
|
|
324
322
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
325
323
|
}
|
|
326
324
|
}
|
|
327
|
-
async function
|
|
325
|
+
async function J(i, t, e, n) {
|
|
328
326
|
if (!this.walletClient)
|
|
329
327
|
throw new Error("Wallet client not found");
|
|
330
|
-
const s = await this.getPool(t), a = await this.getPool(e), l = await this.getLendingState(),
|
|
331
|
-
if (!
|
|
328
|
+
const s = await this.getPool(t), a = await this.getPool(e), l = await this.getLendingState(), o = this.walletClient.address, r = n?.protocol ?? "navi", u = await this.getProtocol(r);
|
|
329
|
+
if (!u)
|
|
332
330
|
throw new Error(`Protocol ${r} not found`);
|
|
333
|
-
const
|
|
331
|
+
const c = await u.getPool(s.coinType);
|
|
334
332
|
if (console.log("migrateBetweenSupplyPTB", {
|
|
335
|
-
fromPoolLending:
|
|
336
|
-
}), r === "navi" &&
|
|
333
|
+
fromPoolLending: c
|
|
334
|
+
}), r === "navi" && c.supplyBalance === 0)
|
|
337
335
|
throw new Error("No supply balance");
|
|
338
|
-
if (n?.amount && n.amount >
|
|
336
|
+
if (n?.amount && n.amount > c.supplyBalance)
|
|
339
337
|
throw new Error("Amount is less than supply balance");
|
|
340
|
-
const
|
|
341
|
-
if (await
|
|
342
|
-
|
|
343
|
-
K(
|
|
338
|
+
const f = n?.slippage ?? 5e-3, w = n?.amount ?? Number(c.supplyBalance), h = await $(), p = await Promise.all([s, a]);
|
|
339
|
+
if (await q(
|
|
340
|
+
i,
|
|
341
|
+
K(h, {
|
|
344
342
|
lendingState: l,
|
|
345
|
-
pools:
|
|
343
|
+
pools: p
|
|
346
344
|
})
|
|
347
345
|
), r !== "navi" && s.id === a.id) {
|
|
348
|
-
const
|
|
349
|
-
|
|
346
|
+
const I = await u.withdrawCoinPTB(
|
|
347
|
+
i,
|
|
350
348
|
s.suiCoinType,
|
|
351
|
-
|
|
349
|
+
w
|
|
352
350
|
);
|
|
353
|
-
return await
|
|
354
|
-
amount:
|
|
355
|
-
}),
|
|
351
|
+
return await A(i, a, I, {
|
|
352
|
+
amount: w
|
|
353
|
+
}), i;
|
|
356
354
|
}
|
|
357
|
-
const
|
|
355
|
+
const g = await X(a, {
|
|
358
356
|
env: this.config.env
|
|
359
357
|
});
|
|
360
|
-
if (!
|
|
358
|
+
if (!g)
|
|
361
359
|
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
362
360
|
const y = await this.walletClient.swap.getQuote(
|
|
363
361
|
s.suiCoinType,
|
|
364
362
|
a.suiCoinType,
|
|
365
|
-
|
|
363
|
+
w
|
|
366
364
|
), B = Number(y.amount_out);
|
|
367
365
|
if (B <= 0)
|
|
368
366
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
369
|
-
const S = Math.floor(B * (1 -
|
|
370
|
-
if (
|
|
367
|
+
const S = Math.floor(B * (1 - f)), C = Math.floor(S / (1 + g.flashloanFee));
|
|
368
|
+
if (C <= 0)
|
|
371
369
|
throw new Error("The calculated borrow amount must be positive.");
|
|
372
|
-
const [T, v] = await
|
|
370
|
+
const [T, v] = await Y(i, a, C), [F] = i.moveCall({
|
|
373
371
|
target: "0x2::coin::from_balance",
|
|
374
372
|
arguments: [T],
|
|
375
373
|
typeArguments: [a.suiCoinType]
|
|
376
374
|
});
|
|
377
|
-
await
|
|
378
|
-
amount:
|
|
375
|
+
await A(i, a, F, {
|
|
376
|
+
amount: C
|
|
379
377
|
});
|
|
380
|
-
const
|
|
381
|
-
i,
|
|
378
|
+
const k = await u.withdrawCoinPTB(i, s.suiCoinType, w), _ = await z(
|
|
382
379
|
o,
|
|
380
|
+
i,
|
|
383
381
|
S,
|
|
384
|
-
|
|
382
|
+
k,
|
|
385
383
|
y
|
|
386
|
-
),
|
|
384
|
+
), U = i.moveCall({
|
|
387
385
|
target: "0x2::coin::into_balance",
|
|
388
|
-
arguments: [
|
|
386
|
+
arguments: [_],
|
|
389
387
|
typeArguments: [a.suiCoinType]
|
|
390
|
-
}), [
|
|
388
|
+
}), [N] = await Z(i, a, v, U), [W] = i.moveCall({
|
|
391
389
|
target: "0x2::coin::from_balance",
|
|
392
|
-
arguments: [
|
|
390
|
+
arguments: [N],
|
|
393
391
|
typeArguments: [a.suiCoinType]
|
|
394
392
|
});
|
|
395
|
-
return await
|
|
393
|
+
return await A(i, a, W), i;
|
|
396
394
|
}
|
|
397
|
-
async function
|
|
395
|
+
async function H(i, t, e, n) {
|
|
398
396
|
if (!this.walletClient)
|
|
399
397
|
throw new Error("Wallet client not found");
|
|
400
|
-
const s = this.walletClient.address, a = await this.getPool(t), l = await this.getPool(e),
|
|
401
|
-
if (!
|
|
398
|
+
const s = this.walletClient.address, a = await this.getPool(t), l = await this.getPool(e), o = await this.getLendingState(), r = n?.protocol ?? "navi", u = await this.getProtocol(r);
|
|
399
|
+
if (!u)
|
|
402
400
|
throw new Error(`Protocol ${r} not found`);
|
|
403
|
-
const
|
|
401
|
+
const c = await u.getPool(a.coinType);
|
|
404
402
|
if (console.log("migrateBetweenBorrowPTB", {
|
|
405
|
-
fromPoolLending:
|
|
406
|
-
}),
|
|
403
|
+
fromPoolLending: c
|
|
404
|
+
}), c.borrowBalance === 0)
|
|
407
405
|
throw new Error("No borrow balance");
|
|
408
|
-
if (n?.amount && n.amount >
|
|
406
|
+
if (n?.amount && n.amount > c.borrowBalance)
|
|
409
407
|
throw new Error("Amount is more than borrow balance");
|
|
410
|
-
const
|
|
411
|
-
await
|
|
412
|
-
|
|
413
|
-
K(
|
|
414
|
-
lendingState:
|
|
415
|
-
pools:
|
|
408
|
+
const f = await $(), w = await Promise.all([a, l]);
|
|
409
|
+
await q(
|
|
410
|
+
i,
|
|
411
|
+
K(f, {
|
|
412
|
+
lendingState: o,
|
|
413
|
+
pools: w
|
|
416
414
|
})
|
|
417
415
|
);
|
|
418
|
-
let
|
|
419
|
-
if (Number(
|
|
420
|
-
const rt =
|
|
421
|
-
|
|
422
|
-
new E(
|
|
416
|
+
let h = n?.amount ?? Number(c.borrowBalance);
|
|
417
|
+
if (Number(c.borrowBalance) === h) {
|
|
418
|
+
const rt = c.borrowAPR / 100;
|
|
419
|
+
h = Math.ceil(
|
|
420
|
+
new E(h).multipliedBy(rt * (60 * 3) / (365 * 24 * 3600)).plus(new E(1).shiftedBy(-a.token.decimals)).plus(h).toNumber()
|
|
423
421
|
);
|
|
424
422
|
}
|
|
425
|
-
const
|
|
423
|
+
const p = await X(a, {
|
|
426
424
|
env: this.config.env
|
|
427
425
|
});
|
|
428
|
-
if (!
|
|
426
|
+
if (!p)
|
|
429
427
|
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
430
428
|
if (!this.walletClient)
|
|
431
429
|
throw new Error("Wallet client not found");
|
|
432
|
-
const
|
|
430
|
+
const g = n?.slippage ?? 5e-3, y = Math.ceil(h * (1 + p.flashloanFee)), B = y, S = await this.walletClient.swap.getQuote(
|
|
433
431
|
a.suiCoinType,
|
|
434
432
|
l.suiCoinType,
|
|
435
433
|
B
|
|
436
434
|
);
|
|
437
|
-
let
|
|
435
|
+
let C = 1 + g, T = Math.ceil(Number(S.amount_out) * C), v = await this.walletClient.swap.getQuote(
|
|
438
436
|
l.suiCoinType,
|
|
439
437
|
a.suiCoinType,
|
|
440
438
|
T
|
|
441
439
|
);
|
|
442
440
|
for (; Number(v.amount_out) < B; )
|
|
443
|
-
|
|
441
|
+
C = C * Math.max(B / Number(v.amount_out), 1.001), T = Math.ceil(Number(S.amount_out) * C), v = await this.walletClient.swap.getQuote(
|
|
444
442
|
l.suiCoinType,
|
|
445
443
|
a.suiCoinType,
|
|
446
444
|
T
|
|
447
445
|
);
|
|
448
|
-
const [
|
|
446
|
+
const [F, k] = await Y(i, a, h), [_] = i.moveCall({
|
|
449
447
|
target: "0x2::coin::from_balance",
|
|
450
|
-
arguments: [
|
|
448
|
+
arguments: [F],
|
|
451
449
|
typeArguments: [a.suiCoinType]
|
|
452
450
|
});
|
|
453
|
-
await
|
|
454
|
-
const
|
|
451
|
+
await u.repayCoinPTB(i, a.suiCoinType, _, h);
|
|
452
|
+
const U = await tt(i, l, T), N = await z(
|
|
455
453
|
s,
|
|
456
|
-
|
|
454
|
+
i,
|
|
457
455
|
y,
|
|
458
|
-
|
|
456
|
+
U,
|
|
459
457
|
v
|
|
460
|
-
),
|
|
458
|
+
), W = i.moveCall({
|
|
461
459
|
target: "0x2::coin::into_balance",
|
|
462
|
-
arguments: [
|
|
460
|
+
arguments: [N],
|
|
463
461
|
typeArguments: [a.suiCoinType]
|
|
464
|
-
}), [
|
|
462
|
+
}), [I] = await Z(i, a, k, W), [lt] = i.moveCall({
|
|
465
463
|
target: "0x2::coin::from_balance",
|
|
466
|
-
arguments: [
|
|
464
|
+
arguments: [I],
|
|
467
465
|
typeArguments: [a.suiCoinType]
|
|
468
466
|
});
|
|
469
|
-
return
|
|
467
|
+
return i.transferObjects([lt], s), i;
|
|
470
468
|
}
|
|
471
|
-
async function
|
|
469
|
+
async function D(i, t, e, n) {
|
|
472
470
|
if (!this.walletClient)
|
|
473
471
|
throw new Error("Wallet client not found");
|
|
474
|
-
const s = await
|
|
472
|
+
const s = await V(this.walletClient.address, {
|
|
475
473
|
client: this.walletClient.client,
|
|
476
474
|
coinType: t
|
|
477
|
-
}), a = await this.getPool(e),
|
|
478
|
-
if (
|
|
475
|
+
}), a = await this.getPool(e), o = new R(s).getBalance(t);
|
|
476
|
+
if (o.amount.eq(0))
|
|
479
477
|
throw new Error(`No balance of ${t}`);
|
|
480
478
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
481
|
-
balance:
|
|
482
|
-
}), n?.amount &&
|
|
479
|
+
balance: o.amount.toNumber()
|
|
480
|
+
}), n?.amount && o.amount.lt(n.amount))
|
|
483
481
|
throw new Error("Amount is greater than balance");
|
|
484
|
-
const r = n?.amount ??
|
|
485
|
-
let
|
|
482
|
+
const r = n?.amount ?? o.amount.toNumber(), u = n?.slippage ?? 5e-3;
|
|
483
|
+
let c = await m(i, o.coins, {
|
|
486
484
|
balance: r,
|
|
487
485
|
useGasCoin: !0
|
|
488
486
|
});
|
|
489
|
-
if (
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
487
|
+
if (b(t) !== b(a.suiCoinType)) {
|
|
488
|
+
const f = await this.walletClient.swap.getQuote(t, a.suiCoinType, r);
|
|
489
|
+
c = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
490
|
+
i,
|
|
491
|
+
f,
|
|
492
|
+
c,
|
|
493
|
+
u
|
|
496
494
|
);
|
|
497
495
|
}
|
|
498
|
-
return await
|
|
496
|
+
return await A(i, a, c), i;
|
|
499
497
|
}
|
|
500
|
-
class
|
|
498
|
+
class Et {
|
|
501
499
|
constructor(t) {
|
|
502
500
|
this.name = "navi", this.walletClient = t;
|
|
503
501
|
}
|
|
504
502
|
async getPool(t) {
|
|
505
503
|
const e = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
|
|
506
|
-
(
|
|
504
|
+
(o) => o.pool.suiCoinType === b(t)
|
|
507
505
|
), a = s ? new E(s.supplyBalance).toNumber() : 0, l = s ? new E(s.borrowBalance).toNumber() : 0;
|
|
508
506
|
return {
|
|
509
507
|
supplyBalance: a,
|
|
@@ -515,85 +513,30 @@ class xt {
|
|
|
515
513
|
throw new Error("Not implemented");
|
|
516
514
|
}
|
|
517
515
|
async withdrawCoinPTB(t, e, n) {
|
|
518
|
-
return
|
|
516
|
+
return et(t, e, n);
|
|
519
517
|
}
|
|
520
518
|
async borrowCoinPTB(t, e, n) {
|
|
521
519
|
throw new Error("Not implemented");
|
|
522
520
|
}
|
|
523
521
|
async repayCoinPTB(t, e, n, s) {
|
|
524
|
-
|
|
522
|
+
nt(t, e, n, { amount: s });
|
|
525
523
|
}
|
|
526
524
|
}
|
|
527
|
-
class
|
|
528
|
-
constructor(t, e, n) {
|
|
529
|
-
this.name = "suilend", this.walletClient = t, this.obligationOwnerCap = e, this.suilendClient = n;
|
|
530
|
-
}
|
|
531
|
-
static async create(t) {
|
|
532
|
-
const [e, n] = await Promise.all([
|
|
533
|
-
z.initialize(Bt, H, t.client),
|
|
534
|
-
z.getObligationOwnerCaps(
|
|
535
|
-
t.address,
|
|
536
|
-
[H],
|
|
537
|
-
t.client
|
|
538
|
-
)
|
|
539
|
-
]);
|
|
540
|
-
if (n.length === 0)
|
|
541
|
-
throw new Error("No existing obligations found for wallet address: " + t.address);
|
|
542
|
-
return new q(t, n[0], e);
|
|
543
|
-
}
|
|
544
|
-
async getPool(t) {
|
|
545
|
-
const e = m(t), n = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
|
|
546
|
-
n.forEach((c) => {
|
|
547
|
-
s.add(m(c.coinType.name)), c.depositsPoolRewardManager.poolRewards.forEach((d) => {
|
|
548
|
-
d && s.add(m(d.coinType.name));
|
|
549
|
-
}), c.borrowsPoolRewardManager.poolRewards.forEach((d) => {
|
|
550
|
-
d && s.add(m(d.coinType.name));
|
|
551
|
-
});
|
|
552
|
-
});
|
|
553
|
-
const a = await Et(Array.from(s)), i = n.map((c) => Tt(c, a)).reduce(
|
|
554
|
-
(c, d) => (c[d.coinType] = d, c),
|
|
555
|
-
{}
|
|
556
|
-
), r = await this.suilendClient.getObligation(
|
|
557
|
-
this.obligationOwnerCap.obligationId
|
|
558
|
-
), w = vt(r, i), u = w.deposits.find((c) => c.coinType === e), g = w.borrows.find((c) => c.coinType === e), h = a[e].decimals;
|
|
559
|
-
return {
|
|
560
|
-
cTokenExchangeRate: i[e].cTokenExchangeRate.toNumber(),
|
|
561
|
-
supplyBalance: u?.depositedAmount.shiftedBy(h).decimalPlaces(0).toNumber() ?? 0,
|
|
562
|
-
borrowBalance: g?.borrowedAmount.shiftedBy(h).decimalPlaces(0).toNumber() ?? 0,
|
|
563
|
-
borrowAPR: i[e].borrowAprPercent.toNumber()
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
async depositCoinPTB(t, e, n, s) {
|
|
567
|
-
throw new Error("Not implemented");
|
|
568
|
-
}
|
|
569
|
-
async withdrawCoinPTB(t, e, n) {
|
|
570
|
-
const s = await this.getPool(e), a = n === s.supplyBalance;
|
|
571
|
-
return await this.suilendClient.withdraw(
|
|
572
|
-
this.obligationOwnerCap.id,
|
|
573
|
-
this.obligationOwnerCap.obligationId,
|
|
574
|
-
e,
|
|
575
|
-
a ? Rt.toString() : Math.ceil(n / s.cTokenExchangeRate).toString(),
|
|
576
|
-
t
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
async borrowCoinPTB(t, e, n) {
|
|
580
|
-
throw new Error("Not implemented");
|
|
581
|
-
}
|
|
582
|
-
async repayCoinPTB(t, e, n, s) {
|
|
583
|
-
this.suilendClient.repay(this.obligationOwnerCap.obligationId, e, n, t), t.transferObjects([n], t.pure.address(this.walletClient.address));
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
class kt extends A {
|
|
525
|
+
class Rt extends O {
|
|
587
526
|
constructor() {
|
|
588
527
|
super(), this.name = "lending", this.defaultConfig = {
|
|
589
528
|
env: "prod",
|
|
590
|
-
protocols: []
|
|
591
|
-
|
|
529
|
+
protocols: [],
|
|
530
|
+
enableSuilend: !0
|
|
531
|
+
}, this._protocols = [], this.migrateBetweenSupplyPTB = J, this.migrateBetweenBorrowPTB = H, this.migrateBalanceToSupplyPTB = D, this.migrateBetweenSupplyPTB = J.bind(this), this.migrateBetweenBorrowPTB = H.bind(this), this.migrateBalanceToSupplyPTB = D.bind(this);
|
|
592
532
|
}
|
|
593
533
|
/** Get protocols (either from internal storage or config) */
|
|
594
534
|
get protocols() {
|
|
595
535
|
return this._protocols.length > 0 ? this._protocols : this.config.protocols;
|
|
596
536
|
}
|
|
537
|
+
install(t) {
|
|
538
|
+
super.install(t), this._protocols = [];
|
|
539
|
+
}
|
|
597
540
|
async getProtocol(t) {
|
|
598
541
|
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((e) => e.name === t);
|
|
599
542
|
}
|
|
@@ -637,11 +580,11 @@ class kt extends A {
|
|
|
637
580
|
env: this.config.env
|
|
638
581
|
});
|
|
639
582
|
await this.walletClient.module("balance").waitForUpdate();
|
|
640
|
-
const a = new
|
|
583
|
+
const a = new d(), l = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, l.coins, {
|
|
641
584
|
balance: e,
|
|
642
585
|
useGasCoin: !0
|
|
643
586
|
});
|
|
644
|
-
await
|
|
587
|
+
await A(a, s, o, {
|
|
645
588
|
env: this.config.env,
|
|
646
589
|
amount: e,
|
|
647
590
|
accountCap: n?.accountCap
|
|
@@ -668,21 +611,21 @@ class kt extends A {
|
|
|
668
611
|
throw new Error("Wallet client not found");
|
|
669
612
|
const s = await P(t, {
|
|
670
613
|
env: this.config.env
|
|
671
|
-
}), a = new
|
|
614
|
+
}), a = new d();
|
|
672
615
|
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
673
|
-
const l = await
|
|
616
|
+
const l = await et(a, s, e, {
|
|
674
617
|
env: this.config.env,
|
|
675
618
|
accountCap: n?.accountCap
|
|
676
619
|
});
|
|
677
620
|
a.transferObjects([l], this.walletClient.address);
|
|
678
|
-
const
|
|
621
|
+
const o = await this.walletClient.signExecuteTransaction({
|
|
679
622
|
transaction: a,
|
|
680
623
|
dryRun: n?.dryRun ?? !1
|
|
681
624
|
});
|
|
682
|
-
return !n?.dryRun &&
|
|
625
|
+
return !n?.dryRun && o.effects?.status?.status === "success" && (this.emit("lending:withdraw-success", {
|
|
683
626
|
identifier: t,
|
|
684
627
|
amount: e
|
|
685
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
628
|
+
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
686
629
|
}
|
|
687
630
|
/**
|
|
688
631
|
* Borrows coins from a lending pool
|
|
@@ -697,21 +640,21 @@ class kt extends A {
|
|
|
697
640
|
throw new Error("Wallet client not found");
|
|
698
641
|
const s = await P(t, {
|
|
699
642
|
env: this.config.env
|
|
700
|
-
}), a = new
|
|
643
|
+
}), a = new d();
|
|
701
644
|
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
702
|
-
const l = await
|
|
645
|
+
const l = await tt(a, s, e, {
|
|
703
646
|
env: this.config.env,
|
|
704
647
|
accountCap: n?.accountCap
|
|
705
648
|
});
|
|
706
649
|
a.transferObjects([l], this.walletClient.address);
|
|
707
|
-
const
|
|
650
|
+
const o = await this.walletClient.signExecuteTransaction({
|
|
708
651
|
transaction: a,
|
|
709
652
|
dryRun: n?.dryRun ?? !1
|
|
710
653
|
});
|
|
711
|
-
return !n?.dryRun &&
|
|
654
|
+
return !n?.dryRun && o.effects?.status?.status === "success" && (this.emit("lending:borrow-success", {
|
|
712
655
|
identifier: t,
|
|
713
656
|
amount: e
|
|
714
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
657
|
+
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
715
658
|
}
|
|
716
659
|
/**
|
|
717
660
|
* Repays borrowed coins to a lending pool
|
|
@@ -727,11 +670,11 @@ class kt extends A {
|
|
|
727
670
|
await this.walletClient.module("balance").waitForUpdate();
|
|
728
671
|
const s = await P(t, {
|
|
729
672
|
env: this.config.env
|
|
730
|
-
}), a = new
|
|
673
|
+
}), a = new d(), l = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, l.coins, {
|
|
731
674
|
balance: e,
|
|
732
675
|
useGasCoin: !0
|
|
733
676
|
});
|
|
734
|
-
await
|
|
677
|
+
await nt(a, s, o, {
|
|
735
678
|
env: this.config.env,
|
|
736
679
|
amount: e,
|
|
737
680
|
accountCap: n?.accountCap
|
|
@@ -774,40 +717,40 @@ class kt extends A {
|
|
|
774
717
|
throw new Error("Wallet client not found");
|
|
775
718
|
const l = await P(t, {
|
|
776
719
|
env: this.config.env
|
|
777
|
-
}),
|
|
720
|
+
}), o = await P(n, {
|
|
778
721
|
env: this.config.env
|
|
779
|
-
}), r = new
|
|
722
|
+
}), r = new d(), u = this.walletClient.module("balance").portfolio.getBalance(l.suiCoinType), c = m(r, u.coins, {
|
|
780
723
|
balance: e,
|
|
781
724
|
useGasCoin: !0
|
|
782
|
-
}), [
|
|
725
|
+
}), [f, w] = await gt(
|
|
783
726
|
r,
|
|
784
727
|
l,
|
|
785
|
-
|
|
786
|
-
|
|
728
|
+
c,
|
|
729
|
+
o,
|
|
787
730
|
s,
|
|
788
731
|
{
|
|
789
732
|
env: this.config.env
|
|
790
733
|
}
|
|
791
|
-
), [
|
|
734
|
+
), [h] = r.moveCall({
|
|
792
735
|
target: "0x2::coin::from_balance",
|
|
793
|
-
arguments: [
|
|
794
|
-
typeArguments: [
|
|
795
|
-
}), [
|
|
736
|
+
arguments: [f],
|
|
737
|
+
typeArguments: [o.suiCoinType]
|
|
738
|
+
}), [p] = r.moveCall({
|
|
796
739
|
target: "0x2::coin::from_balance",
|
|
797
|
-
arguments: [
|
|
740
|
+
arguments: [w],
|
|
798
741
|
typeArguments: [l.suiCoinType]
|
|
799
742
|
});
|
|
800
|
-
r.transferObjects([
|
|
801
|
-
const
|
|
743
|
+
r.transferObjects([h, p], this.walletClient.address);
|
|
744
|
+
const g = await this.walletClient.signExecuteTransaction({
|
|
802
745
|
transaction: r,
|
|
803
746
|
dryRun: a?.dryRun ?? !1
|
|
804
747
|
});
|
|
805
|
-
return !a?.dryRun &&
|
|
748
|
+
return !a?.dryRun && g.effects?.status?.status === "success" && (this.emit("lending:liquidate-success", {
|
|
806
749
|
payIdentifier: t,
|
|
807
750
|
payAmount: e,
|
|
808
751
|
collateralIdentifier: n,
|
|
809
752
|
liquidationAddress: s
|
|
810
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
753
|
+
}), this.walletClient.module("balance").updatePortfolio()), g;
|
|
811
754
|
}
|
|
812
755
|
/**
|
|
813
756
|
* Gets the available lending rewards for the current user.
|
|
@@ -847,7 +790,7 @@ class kt extends A {
|
|
|
847
790
|
async claimAllRewards(t) {
|
|
848
791
|
if (!this.walletClient)
|
|
849
792
|
throw new Error("Wallet client not found");
|
|
850
|
-
const e = new
|
|
793
|
+
const e = new d(), n = await G(this.walletClient.address, {
|
|
851
794
|
env: this.config.env
|
|
852
795
|
});
|
|
853
796
|
await mt(e, n, {
|
|
@@ -863,7 +806,7 @@ class kt extends A {
|
|
|
863
806
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
864
807
|
}
|
|
865
808
|
async updateOraclePTB(t, e) {
|
|
866
|
-
const n = await
|
|
809
|
+
const n = await $({
|
|
867
810
|
env: this.config.env
|
|
868
811
|
}), s = await this.getLendingState({
|
|
869
812
|
cacheTime: 60 * 1e3
|
|
@@ -871,7 +814,7 @@ class kt extends A {
|
|
|
871
814
|
lendingState: s,
|
|
872
815
|
pools: e
|
|
873
816
|
});
|
|
874
|
-
await
|
|
817
|
+
await q(t, a, {
|
|
875
818
|
env: this.config.env,
|
|
876
819
|
updatePythPriceFeeds: !0
|
|
877
820
|
});
|
|
@@ -886,7 +829,7 @@ class kt extends A {
|
|
|
886
829
|
async updateOracle(t) {
|
|
887
830
|
if (!this.walletClient)
|
|
888
831
|
throw new Error("Wallet client not found");
|
|
889
|
-
const e = new
|
|
832
|
+
const e = new d();
|
|
890
833
|
return await this.updateOraclePTB(e, t?.pools), await this.walletClient.signExecuteTransaction({
|
|
891
834
|
transaction: e,
|
|
892
835
|
dryRun: t?.dryRun ?? !1
|
|
@@ -916,7 +859,7 @@ class kt extends A {
|
|
|
916
859
|
async createAccountCap(t) {
|
|
917
860
|
if (!this.walletClient)
|
|
918
861
|
throw new Error("Wallet client not found");
|
|
919
|
-
const e = new
|
|
862
|
+
const e = new d(), n = await bt(e);
|
|
920
863
|
return e.transferObjects([n], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
921
864
|
transaction: e,
|
|
922
865
|
dryRun: t?.dryRun ?? !1
|
|
@@ -928,24 +871,30 @@ class kt extends A {
|
|
|
928
871
|
return;
|
|
929
872
|
}
|
|
930
873
|
const t = [];
|
|
931
|
-
t.push(new
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
874
|
+
if (t.push(new Et(this.walletClient)), this.config.enableSuilend)
|
|
875
|
+
try {
|
|
876
|
+
const { default: e } = await import("./suilend-Df4FukWs.js");
|
|
877
|
+
t.push(
|
|
878
|
+
await e.create(this.walletClient, {
|
|
879
|
+
grpcClient: this.config.suilendGrpcClient,
|
|
880
|
+
grpcUrl: this.config.suilendGrpcUrl
|
|
881
|
+
})
|
|
882
|
+
);
|
|
883
|
+
} catch (e) {
|
|
884
|
+
console.warn("Failed to initialize SuilendProtocol:", e);
|
|
885
|
+
}
|
|
937
886
|
this._protocols = t;
|
|
938
887
|
}
|
|
939
888
|
}
|
|
940
|
-
class
|
|
889
|
+
class St extends O {
|
|
941
890
|
constructor() {
|
|
942
891
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
943
892
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
944
893
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
945
894
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
946
895
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
947
|
-
}, this.getStats =
|
|
948
|
-
|
|
896
|
+
}, this.getStats = at(
|
|
897
|
+
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((e) => e.json())).data)
|
|
949
898
|
);
|
|
950
899
|
}
|
|
951
900
|
/**
|
|
@@ -1001,20 +950,20 @@ class Nt extends A {
|
|
|
1001
950
|
throw new Error("Wallet client not found");
|
|
1002
951
|
if (t < 1e9)
|
|
1003
952
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
1004
|
-
const n = new
|
|
953
|
+
const n = new d();
|
|
1005
954
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1006
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a =
|
|
955
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
|
|
1007
956
|
balance: t,
|
|
1008
957
|
useGasCoin: !0
|
|
1009
958
|
}), l = await this.stakePTB(n, a);
|
|
1010
959
|
n.transferObjects([l], this.walletClient.address);
|
|
1011
|
-
const
|
|
960
|
+
const o = await this.walletClient.signExecuteTransaction({
|
|
1012
961
|
transaction: n,
|
|
1013
962
|
dryRun: e?.dryRun ?? !1
|
|
1014
963
|
});
|
|
1015
|
-
return !e?.dryRun &&
|
|
964
|
+
return !e?.dryRun && o.effects?.status?.status === "success" && (this.emit("volo:stake-success", {
|
|
1016
965
|
suiAmount: t
|
|
1017
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
966
|
+
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1018
967
|
}
|
|
1019
968
|
/**
|
|
1020
969
|
* Unstake vSUI tokens to receive SUI tokens
|
|
@@ -1030,20 +979,67 @@ class Nt extends A {
|
|
|
1030
979
|
if (t < 1e9)
|
|
1031
980
|
throw new Error("Unstake amount should >= 1vSui");
|
|
1032
981
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1033
|
-
const n = new
|
|
982
|
+
const n = new d(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
|
|
1034
983
|
balance: t
|
|
1035
984
|
}), l = await this.unstakePTB(n, a);
|
|
1036
985
|
n.transferObjects([l], this.walletClient.address);
|
|
1037
|
-
const
|
|
986
|
+
const o = await this.walletClient.signExecuteTransaction({
|
|
1038
987
|
transaction: n,
|
|
1039
988
|
dryRun: e?.dryRun ?? !1
|
|
1040
989
|
});
|
|
1041
|
-
return !e?.dryRun &&
|
|
990
|
+
return !e?.dryRun && o.effects?.status?.status === "success" && (this.emit("volo:unstake-success", {
|
|
1042
991
|
vSuiAmount: t
|
|
1043
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
992
|
+
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1044
993
|
}
|
|
1045
994
|
}
|
|
1046
|
-
|
|
995
|
+
const ot = {
|
|
996
|
+
showEffects: !0,
|
|
997
|
+
showEvents: !0,
|
|
998
|
+
showBalanceChanges: !0,
|
|
999
|
+
showObjectChanges: !0
|
|
1000
|
+
};
|
|
1001
|
+
function At(i) {
|
|
1002
|
+
return {
|
|
1003
|
+
...ot,
|
|
1004
|
+
...i
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
function M(i, t) {
|
|
1008
|
+
const n = jt(t ?? {}), s = Ot(n);
|
|
1009
|
+
return {
|
|
1010
|
+
...n,
|
|
1011
|
+
kind: i,
|
|
1012
|
+
effects: s,
|
|
1013
|
+
events: xt(n.events),
|
|
1014
|
+
balanceChanges: Array.isArray(n.balanceChanges) ? n.balanceChanges : [],
|
|
1015
|
+
objectChanges: Array.isArray(n.objectChanges) ? n.objectChanges : []
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
function jt(i) {
|
|
1019
|
+
const t = i.Transaction;
|
|
1020
|
+
if (j(t))
|
|
1021
|
+
return t;
|
|
1022
|
+
const e = i.FailedTransaction;
|
|
1023
|
+
return j(e) ? e : i;
|
|
1024
|
+
}
|
|
1025
|
+
function Ot(i) {
|
|
1026
|
+
if (j(i.effects))
|
|
1027
|
+
return i.effects;
|
|
1028
|
+
if (j(i.status))
|
|
1029
|
+
return {
|
|
1030
|
+
status: i.status
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
function xt(i) {
|
|
1034
|
+
return Array.isArray(i) ? i.map((t) => !j(t) || t.parsedJson !== void 0 || t.json === void 0 ? t : {
|
|
1035
|
+
...t,
|
|
1036
|
+
parsedJson: t.json
|
|
1037
|
+
}) : [];
|
|
1038
|
+
}
|
|
1039
|
+
function j(i) {
|
|
1040
|
+
return typeof i == "object" && i !== null;
|
|
1041
|
+
}
|
|
1042
|
+
class Ft extends O {
|
|
1047
1043
|
constructor() {
|
|
1048
1044
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1049
1045
|
apiKey: "",
|
|
@@ -1096,7 +1092,7 @@ class Ft extends A {
|
|
|
1096
1092
|
if (!this.walletClient)
|
|
1097
1093
|
throw new Error("Wallet client not found");
|
|
1098
1094
|
const a = new E(e.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1099
|
-
return await
|
|
1095
|
+
return await z(
|
|
1100
1096
|
this.walletClient.address,
|
|
1101
1097
|
t,
|
|
1102
1098
|
Number(a),
|
|
@@ -1129,53 +1125,49 @@ class Ft extends A {
|
|
|
1129
1125
|
if (!this.walletClient)
|
|
1130
1126
|
throw new Error("Wallet client not found");
|
|
1131
1127
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1132
|
-
const l = this.walletClient.module("balance").portfolio.getBalance(t),
|
|
1128
|
+
const l = this.walletClient.module("balance").portfolio.getBalance(t), o = new d(), r = m(o, l.coins, {
|
|
1133
1129
|
balance: n,
|
|
1134
1130
|
useGasCoin: !0
|
|
1135
|
-
}),
|
|
1136
|
-
if (
|
|
1131
|
+
}), u = await this.getQuote(t, e, n), c = await this.buildSwapPTBFromQuote(o, u, r, s);
|
|
1132
|
+
if (o.transferObjects([c], this.walletClient.address), o.setSender(this.walletClient.address), a?.dryRun)
|
|
1137
1133
|
return await this.walletClient.signExecuteTransaction({
|
|
1138
|
-
transaction:
|
|
1134
|
+
transaction: o,
|
|
1139
1135
|
dryRun: !0
|
|
1140
1136
|
});
|
|
1141
|
-
const
|
|
1137
|
+
const f = await o.build({
|
|
1142
1138
|
client: this.walletClient.client
|
|
1143
|
-
}),
|
|
1139
|
+
}), w = await this.walletClient.signer.signTransaction(f), h = [w.signature];
|
|
1144
1140
|
try {
|
|
1145
|
-
await
|
|
1146
|
-
} catch (
|
|
1147
|
-
console.error(
|
|
1141
|
+
await Bt(w.bytes, h);
|
|
1142
|
+
} catch (g) {
|
|
1143
|
+
console.error(g);
|
|
1148
1144
|
}
|
|
1149
|
-
const
|
|
1150
|
-
transactionBlock:
|
|
1151
|
-
signature:
|
|
1152
|
-
options:
|
|
1153
|
-
showEffects: !0,
|
|
1154
|
-
showEvents: !0,
|
|
1155
|
-
showBalanceChanges: !0
|
|
1156
|
-
}
|
|
1145
|
+
const p = await this.walletClient.client.executeTransactionBlock({
|
|
1146
|
+
transactionBlock: w.bytes,
|
|
1147
|
+
signature: h,
|
|
1148
|
+
options: ot
|
|
1157
1149
|
});
|
|
1158
|
-
if (
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1150
|
+
if (p.effects?.status?.status === "success") {
|
|
1151
|
+
const g = p.events?.find((y) => y.type.includes("::slippage::SwapEvent"));
|
|
1152
|
+
g && this.emit("swap:swap-success", {
|
|
1161
1153
|
fromCoinType: t,
|
|
1162
1154
|
toCoinType: e,
|
|
1163
1155
|
fromAmount: n,
|
|
1164
1156
|
slippage: s,
|
|
1165
|
-
toAmount: Number(
|
|
1157
|
+
toAmount: Number(g.parsedJson.amount_out)
|
|
1166
1158
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1167
1159
|
}
|
|
1168
|
-
return
|
|
1160
|
+
return M("execute", p);
|
|
1169
1161
|
}
|
|
1170
1162
|
}
|
|
1171
|
-
class
|
|
1163
|
+
class kt extends O {
|
|
1172
1164
|
constructor() {
|
|
1173
1165
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1174
1166
|
packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
|
|
1175
1167
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1176
1168
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1177
|
-
}, this.getApy =
|
|
1178
|
-
|
|
1169
|
+
}, this.getApy = at(
|
|
1170
|
+
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((e) => e.json())).data.apy)
|
|
1179
1171
|
);
|
|
1180
1172
|
}
|
|
1181
1173
|
/**
|
|
@@ -1226,18 +1218,18 @@ class _t extends A {
|
|
|
1226
1218
|
async stake(t, e) {
|
|
1227
1219
|
if (!this.walletClient)
|
|
1228
1220
|
throw new Error("Wallet client not found");
|
|
1229
|
-
const n = new
|
|
1221
|
+
const n = new d();
|
|
1230
1222
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1231
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a =
|
|
1223
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
|
|
1232
1224
|
balance: t,
|
|
1233
1225
|
useGasCoin: !0
|
|
1234
1226
|
}), l = await this.stakePTB(n, a);
|
|
1235
1227
|
n.transferObjects([l], this.walletClient.address);
|
|
1236
|
-
const
|
|
1228
|
+
const o = await this.walletClient.signExecuteTransaction({
|
|
1237
1229
|
transaction: n,
|
|
1238
1230
|
dryRun: e?.dryRun ?? !1
|
|
1239
1231
|
});
|
|
1240
|
-
return !e?.dryRun &&
|
|
1232
|
+
return !e?.dryRun && o.effects?.status?.status === "success" && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1241
1233
|
}
|
|
1242
1234
|
/**
|
|
1243
1235
|
* Unstake haSUI for SUI
|
|
@@ -1249,43 +1241,44 @@ class _t extends A {
|
|
|
1249
1241
|
if (!this.walletClient)
|
|
1250
1242
|
throw new Error("Wallet client not found");
|
|
1251
1243
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1252
|
-
const n = new
|
|
1244
|
+
const n = new d(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
|
|
1253
1245
|
balance: t
|
|
1254
1246
|
}), l = await this.unstakePTB(n, a);
|
|
1255
1247
|
n.transferObjects([l], this.walletClient.address);
|
|
1256
|
-
const
|
|
1248
|
+
const o = await this.walletClient.signExecuteTransaction({
|
|
1257
1249
|
transaction: n,
|
|
1258
1250
|
dryRun: e?.dryRun ?? !1
|
|
1259
1251
|
});
|
|
1260
|
-
return !e?.dryRun &&
|
|
1252
|
+
return !e?.dryRun && o.effects?.status?.status === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1261
1253
|
}
|
|
1262
1254
|
}
|
|
1263
|
-
const
|
|
1255
|
+
const _t = {
|
|
1264
1256
|
/** Balance management module */
|
|
1265
|
-
balance: new
|
|
1257
|
+
balance: new vt(),
|
|
1266
1258
|
/** Lending protocol module */
|
|
1267
|
-
lending: new
|
|
1259
|
+
lending: new Rt(),
|
|
1268
1260
|
/** Volo protocol module */
|
|
1269
|
-
volo: new
|
|
1261
|
+
volo: new St(),
|
|
1270
1262
|
/** DEX swapping module */
|
|
1271
1263
|
swap: new Ft(),
|
|
1272
1264
|
/** Haedal protocol module */
|
|
1273
|
-
haedal: new
|
|
1274
|
-
},
|
|
1265
|
+
haedal: new kt()
|
|
1266
|
+
}, Ut = {
|
|
1267
|
+
network: "mainnet",
|
|
1275
1268
|
url: ct("mainnet")
|
|
1276
1269
|
};
|
|
1277
|
-
class
|
|
1270
|
+
class Gt {
|
|
1278
1271
|
/**
|
|
1279
1272
|
* Creates a new wallet client instance
|
|
1280
1273
|
* @param options - Configuration options for the wallet client
|
|
1281
1274
|
*/
|
|
1282
1275
|
constructor(t) {
|
|
1283
|
-
this.modules =
|
|
1276
|
+
this.modules = _t, this.userConfigs = {}, this.events = wt();
|
|
1284
1277
|
const e = {
|
|
1285
|
-
...
|
|
1278
|
+
...Ut,
|
|
1286
1279
|
...t.client
|
|
1287
1280
|
};
|
|
1288
|
-
e.transport
|
|
1281
|
+
!e.transport && e.url && (e.transport = new Tt(e.url)), this.client = new ut(e), this.clientUrl = e.url, this.signer = t.signer, this.userConfigs = t.configs || {}, Object.entries(this.modules).forEach(([n, s]) => {
|
|
1289
1282
|
if (n !== s.name)
|
|
1290
1283
|
throw new Error(`Module name ${n} does not match module name ${s.name}`);
|
|
1291
1284
|
s.install(this);
|
|
@@ -1314,17 +1307,21 @@ class Jt {
|
|
|
1314
1307
|
async signExecuteTransaction(t) {
|
|
1315
1308
|
const { dryRun: e = !1, ...n } = t;
|
|
1316
1309
|
if (e) {
|
|
1317
|
-
let
|
|
1318
|
-
|
|
1310
|
+
let a;
|
|
1311
|
+
t.transaction instanceof d ? (t.transaction.setSenderIfNotSet(this.address), a = await t.transaction.build({
|
|
1319
1312
|
client: this.client
|
|
1320
|
-
})) :
|
|
1321
|
-
|
|
1313
|
+
})) : a = t.transaction;
|
|
1314
|
+
const l = await this.client.dryRunTransactionBlock({
|
|
1315
|
+
transactionBlock: a
|
|
1322
1316
|
});
|
|
1317
|
+
return M("dryRun", l);
|
|
1323
1318
|
}
|
|
1324
|
-
|
|
1319
|
+
const s = await this.client.signAndExecuteTransaction({
|
|
1325
1320
|
...n,
|
|
1321
|
+
options: At(n.options),
|
|
1326
1322
|
signer: this.signer
|
|
1327
1323
|
});
|
|
1324
|
+
return M("execute", s);
|
|
1328
1325
|
}
|
|
1329
1326
|
/**
|
|
1330
1327
|
* Gets the wallet address from the signer's public key
|
|
@@ -1361,7 +1358,7 @@ class Jt {
|
|
|
1361
1358
|
return t in this.modules;
|
|
1362
1359
|
}
|
|
1363
1360
|
}
|
|
1364
|
-
class
|
|
1361
|
+
class Jt extends st {
|
|
1365
1362
|
/**
|
|
1366
1363
|
* Creates a new watch-only signer
|
|
1367
1364
|
*
|
|
@@ -1425,7 +1422,7 @@ class Vt extends it {
|
|
|
1425
1422
|
return {};
|
|
1426
1423
|
}
|
|
1427
1424
|
}
|
|
1428
|
-
class
|
|
1425
|
+
class Ht extends st {
|
|
1429
1426
|
/**
|
|
1430
1427
|
* Creates a new watch-only signer
|
|
1431
1428
|
*
|
|
@@ -1478,8 +1475,8 @@ class Xt extends it {
|
|
|
1478
1475
|
}
|
|
1479
1476
|
}
|
|
1480
1477
|
export {
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1478
|
+
Gt as WalletClient,
|
|
1479
|
+
Jt as WatchSigner,
|
|
1480
|
+
Ht as WebSigner
|
|
1484
1481
|
};
|
|
1485
1482
|
//# sourceMappingURL=index.esm.js.map
|