@naviprotocol/wallet-client 1.3.0-dev.2 → 1.3.1-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +185 -195
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/lendingModule/migrate.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { getFullnodeUrl as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as Q, getCoins as
|
|
1
|
+
import { getFullnodeUrl as we, SuiClient as he } from "@mysten/sui/client";
|
|
2
|
+
import fe from "mitt";
|
|
3
|
+
import ge from "axios";
|
|
4
|
+
import { withSingleton as Q, getCoins as te, mergeCoinsPTB as B, getPriceFeeds as K, updateOraclePricesPTB as $, filterPriceFeeds as q, getFlashLoanAsset as ae, flashloanPTB as ne, depositCoinPTB as N, repayFlashLoanPTB as se, borrowCoinPTB as ie, withdrawCoinPTB as le, repayCoinPTB as re, getPools as me, getPool as T, getHealthFactor as Ce, liquidatePTB as be, getUserAvailableLendingRewards as J, getUserClaimedRewardHistory as ye, claimLendingRewardsPTB as pe, getLendingState as Pe, createAccountCapPTB as Be, withCache as oe, parseTxValue as _ } from "@naviprotocol/lending";
|
|
5
5
|
import R, { BigNumber as L } from "bignumber.js";
|
|
6
|
-
import { normalizeStructTag as
|
|
6
|
+
import { normalizeStructTag as p } from "@mysten/sui/utils";
|
|
7
7
|
import { Transaction as m } from "@mysten/sui/transactions";
|
|
8
8
|
import { buildSwapPTBFromQuote as G, generateRefId as Te, getQuote as ve } from "@naviprotocol/astros-aggregator-sdk";
|
|
9
9
|
import { SuilendClient as V, LENDING_MARKET_ID as Ee, LENDING_MARKET_TYPE as X, parseReserve as Re, parseObligation as Se } from "@suilend/sdk";
|
|
10
|
-
import { getCoinMetadataMap as
|
|
10
|
+
import { getCoinMetadataMap as Oe, MAX_U64 as Ae } from "@suilend/sui-fe";
|
|
11
11
|
import { executeAuction as xe } from "shio-sdk";
|
|
12
|
-
import { Signer as
|
|
13
|
-
const
|
|
12
|
+
import { Signer as ce } from "@mysten/sui/cryptography";
|
|
13
|
+
const ue = ge.create({
|
|
14
14
|
timeout: 2e4
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
function(
|
|
18
|
-
if (
|
|
19
|
-
throw new Error(
|
|
20
|
-
if (
|
|
21
|
-
throw new Error(
|
|
22
|
-
return
|
|
16
|
+
ue.interceptors.response.use(
|
|
17
|
+
function(o) {
|
|
18
|
+
if (o.data.err)
|
|
19
|
+
throw new Error(o.data.err);
|
|
20
|
+
if (o.data.error)
|
|
21
|
+
throw new Error(o.data.error.message);
|
|
22
|
+
return o;
|
|
23
23
|
},
|
|
24
|
-
function(
|
|
25
|
-
return Promise.reject(
|
|
24
|
+
function(o) {
|
|
25
|
+
return Promise.reject(o);
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
28
|
class ke {
|
|
@@ -44,7 +44,7 @@ class ke {
|
|
|
44
44
|
* @returns Promise<T> - The response data from the RPC call
|
|
45
45
|
*/
|
|
46
46
|
async request(e) {
|
|
47
|
-
return this.requestId += 1, (await
|
|
47
|
+
return this.requestId += 1, (await ue.post(this.rpcUrl, {
|
|
48
48
|
jsonrpc: "2.0",
|
|
49
49
|
id: this.requestId,
|
|
50
50
|
method: e.method,
|
|
@@ -64,7 +64,7 @@ class ke {
|
|
|
64
64
|
throw new Error("subscribe not implemented.");
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
class
|
|
67
|
+
class A {
|
|
68
68
|
/**
|
|
69
69
|
* Gets the current configuration for this module
|
|
70
70
|
*
|
|
@@ -107,19 +107,19 @@ class O {
|
|
|
107
107
|
this.walletClient = void 0;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class S {
|
|
111
111
|
/**
|
|
112
112
|
* Creates a new user portfolio
|
|
113
113
|
*
|
|
114
114
|
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
115
115
|
*/
|
|
116
116
|
constructor(e) {
|
|
117
|
-
if (e instanceof
|
|
117
|
+
if (e instanceof S)
|
|
118
118
|
this.balances = JSON.parse(JSON.stringify(e.balances));
|
|
119
119
|
else {
|
|
120
120
|
const a = {};
|
|
121
121
|
e == null || e.forEach((t) => {
|
|
122
|
-
const s =
|
|
122
|
+
const s = p(t.coinType);
|
|
123
123
|
let n = a[s];
|
|
124
124
|
n || (n = {
|
|
125
125
|
coinType: s,
|
|
@@ -136,7 +136,7 @@ class A {
|
|
|
136
136
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
137
137
|
*/
|
|
138
138
|
getBalance(e) {
|
|
139
|
-
return e =
|
|
139
|
+
return e = p(e), this.balances[e] || { coinType: e, amount: L(0), coins: [] };
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Gets all coin types in the portfolio
|
|
@@ -153,7 +153,7 @@ class A {
|
|
|
153
153
|
* @returns BigNumber representing the total balance
|
|
154
154
|
*/
|
|
155
155
|
balanceOf(e) {
|
|
156
|
-
e =
|
|
156
|
+
e = p(e);
|
|
157
157
|
const a = this.getBalance(e);
|
|
158
158
|
return (a == null ? void 0 : a.amount) || L(0);
|
|
159
159
|
}
|
|
@@ -166,11 +166,11 @@ class A {
|
|
|
166
166
|
* @returns New UserPortfolio instance with copied data
|
|
167
167
|
*/
|
|
168
168
|
clone() {
|
|
169
|
-
const e = JSON.parse(JSON.stringify(this.balances)), a = new
|
|
169
|
+
const e = JSON.parse(JSON.stringify(this.balances)), a = new S();
|
|
170
170
|
return a.balances = e, a;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
class Ne extends
|
|
173
|
+
class Ne extends A {
|
|
174
174
|
constructor() {
|
|
175
175
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
176
176
|
coinPollingInterval: 6e3,
|
|
@@ -178,10 +178,10 @@ class Ne extends O {
|
|
|
178
178
|
}, this.updatePortfolio = Q(async () => {
|
|
179
179
|
if (!this.walletClient)
|
|
180
180
|
throw new Error("Wallet client not found");
|
|
181
|
-
this._coins = await
|
|
181
|
+
this._coins = await te(this.walletClient.address, {
|
|
182
182
|
client: this.walletClient.client
|
|
183
|
-
}), this._portfolio = new
|
|
184
|
-
}), this._coins = [], this._portfolio = new
|
|
183
|
+
}), this._portfolio = new S(this._coins), this.emit("balance:portfolio-updated", {});
|
|
184
|
+
}), this._coins = [], this._portfolio = new S(), this.pollingTimer = null, this._updatePromise = null;
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* Gets the current coin objects from the wallet
|
|
@@ -232,26 +232,26 @@ class Ne extends O {
|
|
|
232
232
|
* @returns Transaction response or dry run response
|
|
233
233
|
*/
|
|
234
234
|
async sendCoinBatch(e, a, t, s) {
|
|
235
|
-
var
|
|
235
|
+
var w;
|
|
236
236
|
if (!this.walletClient)
|
|
237
237
|
throw new Error("Wallet client not found");
|
|
238
238
|
if (a.length !== t.length)
|
|
239
239
|
throw new Error("Recipients and amounts must have the same length");
|
|
240
240
|
await this.waitForUpdate();
|
|
241
|
-
const n = this.portfolio.getBalance(e), c = t.reduce((g,
|
|
241
|
+
const n = this.portfolio.getBalance(e), c = t.reduce((g, h) => g.plus(h), R(0));
|
|
242
242
|
if (n.amount.lt(c))
|
|
243
243
|
throw new Error("Insufficient balance");
|
|
244
244
|
const i = new m();
|
|
245
245
|
let l = i.gas;
|
|
246
|
-
|
|
246
|
+
p(e) !== p("0x2::sui::SUI") && (l = B(i, n.coins, {
|
|
247
247
|
balance: c.toNumber()
|
|
248
248
|
}));
|
|
249
249
|
const u = i.splitCoins(l, t);
|
|
250
|
-
return a.forEach((g,
|
|
251
|
-
i.transferObjects([u[
|
|
250
|
+
return a.forEach((g, h) => {
|
|
251
|
+
i.transferObjects([u[h]], g);
|
|
252
252
|
}), await this.walletClient.signExecuteTransaction({
|
|
253
253
|
transaction: i,
|
|
254
|
-
dryRun: (
|
|
254
|
+
dryRun: (w = s == null ? void 0 : s.dryRun) != null ? w : !1
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
@@ -329,182 +329,172 @@ class Ne extends O {
|
|
|
329
329
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
async function Y(
|
|
333
|
-
var x, k,
|
|
332
|
+
async function Y(o, e, a, t) {
|
|
333
|
+
var x, k, O;
|
|
334
334
|
if (!this.walletClient)
|
|
335
335
|
throw new Error("Wallet client not found");
|
|
336
|
-
await this.walletClient.balance.updatePortfolio();
|
|
337
336
|
const s = await this.getPool(e), n = await this.getPool(a), c = await this.getLendingState(), i = this.walletClient.address, l = (x = t == null ? void 0 : t.protocol) != null ? x : "navi", u = await this.getProtocol(l);
|
|
338
337
|
if (!u)
|
|
339
338
|
throw new Error(`Protocol ${l} not found`);
|
|
340
|
-
const
|
|
339
|
+
const r = await u.getPool(s.coinType);
|
|
341
340
|
if (console.log("migrateBetweenSupplyPTB", {
|
|
342
|
-
fromPoolLending:
|
|
343
|
-
}), l === "navi" &&
|
|
341
|
+
fromPoolLending: r
|
|
342
|
+
}), l === "navi" && r.supplyBalance === 0)
|
|
344
343
|
throw new Error("No supply balance");
|
|
345
|
-
if (t != null && t.amount && t.amount >
|
|
344
|
+
if (t != null && t.amount && t.amount > r.supplyBalance)
|
|
346
345
|
throw new Error("Amount is less than supply balance");
|
|
347
|
-
const
|
|
346
|
+
const w = await K(), g = await Promise.all([s, n]);
|
|
348
347
|
await $(
|
|
349
|
-
|
|
350
|
-
q(
|
|
348
|
+
o,
|
|
349
|
+
q(w, {
|
|
351
350
|
lendingState: c,
|
|
352
351
|
pools: g
|
|
353
352
|
})
|
|
354
353
|
);
|
|
355
|
-
const
|
|
354
|
+
const h = await ae(n, {
|
|
356
355
|
env: this.config.env
|
|
357
356
|
});
|
|
358
|
-
if (!
|
|
357
|
+
if (!h)
|
|
359
358
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
360
|
-
const b = (k = t == null ? void 0 : t.slippage) != null ? k : 5e-3, y = (
|
|
359
|
+
const b = (k = t == null ? void 0 : t.slippage) != null ? k : 5e-3, y = (O = t == null ? void 0 : t.amount) != null ? O : Number(r.supplyBalance), d = await this.walletClient.swap.getQuote(
|
|
361
360
|
s.suiCoinType,
|
|
362
361
|
n.suiCoinType,
|
|
363
362
|
y
|
|
364
|
-
),
|
|
365
|
-
if (
|
|
363
|
+
), f = Number(d.amount_out);
|
|
364
|
+
if (f <= 0)
|
|
366
365
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
367
|
-
const C = Math.floor(
|
|
368
|
-
if (
|
|
366
|
+
const C = Math.floor(f * (1 - b)), P = Math.floor(C / (1 + h.flashloanFee));
|
|
367
|
+
if (P <= 0)
|
|
369
368
|
throw new Error("The calculated borrow amount must be positive.");
|
|
370
|
-
const [
|
|
369
|
+
const [v, E] = await ne(o, n, P), [F] = o.moveCall({
|
|
371
370
|
target: "0x2::coin::from_balance",
|
|
372
|
-
arguments: [
|
|
371
|
+
arguments: [v],
|
|
373
372
|
typeArguments: [n.suiCoinType]
|
|
374
373
|
});
|
|
375
|
-
await N(
|
|
376
|
-
amount:
|
|
374
|
+
await N(o, n, F, {
|
|
375
|
+
amount: P
|
|
377
376
|
});
|
|
378
|
-
const j = await u.withdrawCoinPTB(
|
|
377
|
+
const j = await u.withdrawCoinPTB(o, s.suiCoinType, y), I = await G(
|
|
379
378
|
i,
|
|
380
|
-
|
|
379
|
+
o,
|
|
381
380
|
C,
|
|
382
381
|
j,
|
|
383
382
|
d
|
|
384
|
-
), U =
|
|
383
|
+
), U = o.moveCall({
|
|
385
384
|
target: "0x2::coin::into_balance",
|
|
386
385
|
arguments: [I],
|
|
387
386
|
typeArguments: [n.suiCoinType]
|
|
388
|
-
}), [M] = await
|
|
387
|
+
}), [M] = await se(o, n, E, U), [W] = o.moveCall({
|
|
389
388
|
target: "0x2::coin::from_balance",
|
|
390
389
|
arguments: [M],
|
|
391
390
|
typeArguments: [n.suiCoinType]
|
|
392
391
|
});
|
|
393
|
-
return await N(
|
|
392
|
+
return await N(o, n, W), o;
|
|
394
393
|
}
|
|
395
|
-
async function Z(
|
|
396
|
-
var
|
|
394
|
+
async function Z(o, e, a, t) {
|
|
395
|
+
var O, H, D;
|
|
397
396
|
if (!this.walletClient)
|
|
398
397
|
throw new Error("Wallet client not found");
|
|
399
|
-
|
|
400
|
-
const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a), i = await this.getLendingState(), l = (S = t == null ? void 0 : t.protocol) != null ? S : "navi", u = await this.getProtocol(l);
|
|
398
|
+
const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a), i = await this.getLendingState(), l = (O = t == null ? void 0 : t.protocol) != null ? O : "navi", u = await this.getProtocol(l);
|
|
401
399
|
if (!u)
|
|
402
400
|
throw new Error(`Protocol ${l} not found`);
|
|
403
|
-
const
|
|
401
|
+
const r = await u.getPool(n.coinType);
|
|
404
402
|
if (console.log("migrateBetweenBorrowPTB", {
|
|
405
|
-
fromPoolLending:
|
|
406
|
-
}),
|
|
403
|
+
fromPoolLending: r
|
|
404
|
+
}), r.borrowBalance === 0)
|
|
407
405
|
throw new Error("No borrow balance");
|
|
408
|
-
if (t != null && t.amount && t.amount >
|
|
406
|
+
if (t != null && t.amount && t.amount > r.borrowBalance)
|
|
409
407
|
throw new Error("Amount is more than borrow balance");
|
|
410
|
-
const
|
|
408
|
+
const w = await K(), g = await Promise.all([n, c]);
|
|
411
409
|
await $(
|
|
412
|
-
|
|
413
|
-
q(
|
|
410
|
+
o,
|
|
411
|
+
q(w, {
|
|
414
412
|
lendingState: i,
|
|
415
413
|
pools: g
|
|
416
414
|
})
|
|
417
415
|
);
|
|
418
|
-
let
|
|
419
|
-
if (Number(
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
new R(
|
|
416
|
+
let h = (H = t == null ? void 0 : t.amount) != null ? H : Number(r.borrowBalance);
|
|
417
|
+
if (Number(r.borrowBalance) === h) {
|
|
418
|
+
const de = r.borrowAPR / 100;
|
|
419
|
+
h = Math.ceil(
|
|
420
|
+
new R(h).multipliedBy(de * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-n.token.decimals)).plus(h).toNumber()
|
|
423
421
|
);
|
|
424
422
|
}
|
|
425
|
-
const b = await
|
|
423
|
+
const b = await ae(n, {
|
|
426
424
|
env: this.config.env
|
|
427
425
|
});
|
|
428
426
|
if (!b)
|
|
429
427
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
430
428
|
if (!this.walletClient)
|
|
431
429
|
throw new Error("Wallet client not found");
|
|
432
|
-
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(
|
|
430
|
+
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(h * (1 + b.flashloanFee)), f = d, C = await this.walletClient.swap.getQuote(
|
|
433
431
|
n.suiCoinType,
|
|
434
432
|
c.suiCoinType,
|
|
435
|
-
|
|
433
|
+
f
|
|
436
434
|
);
|
|
437
|
-
let
|
|
435
|
+
let P = 1 + y, v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
438
436
|
c.suiCoinType,
|
|
439
437
|
n.suiCoinType,
|
|
440
|
-
|
|
438
|
+
v
|
|
441
439
|
);
|
|
442
|
-
for (
|
|
443
|
-
|
|
444
|
-
minSwapAmount: w,
|
|
445
|
-
toQuoteAmount: Number(B.amount_out),
|
|
446
|
-
rate: p
|
|
447
|
-
}); Number(B.amount_out) < w; )
|
|
448
|
-
p = p * Math.max(w / Number(B.amount_out), 1.001), E = Math.ceil(Number(C.amount_out) * p), B = await this.walletClient.swap.getQuote(
|
|
440
|
+
for (; Number(E.amount_out) < f; )
|
|
441
|
+
P = P * Math.max(f / Number(E.amount_out), 1.001), v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
449
442
|
c.suiCoinType,
|
|
450
443
|
n.suiCoinType,
|
|
451
|
-
|
|
452
|
-
)
|
|
453
|
-
|
|
454
|
-
minSwapAmount: w,
|
|
455
|
-
toQuoteAmount: Number(B.amount_out),
|
|
456
|
-
rate: p
|
|
457
|
-
});
|
|
458
|
-
const [F, j] = await ae(r, n, f), [I] = r.moveCall({
|
|
444
|
+
v
|
|
445
|
+
);
|
|
446
|
+
const [F, j] = await ne(o, n, h), [I] = o.moveCall({
|
|
459
447
|
target: "0x2::coin::from_balance",
|
|
460
448
|
arguments: [F],
|
|
461
449
|
typeArguments: [n.suiCoinType]
|
|
462
450
|
});
|
|
463
|
-
await u.repayCoinPTB(
|
|
464
|
-
const U = await
|
|
451
|
+
await u.repayCoinPTB(o, n.suiCoinType, I, h);
|
|
452
|
+
const U = await ie(o, c, v), M = await G(
|
|
465
453
|
s,
|
|
466
|
-
|
|
454
|
+
o,
|
|
467
455
|
d,
|
|
468
456
|
U,
|
|
469
|
-
|
|
470
|
-
), W =
|
|
457
|
+
E
|
|
458
|
+
), W = o.moveCall({
|
|
471
459
|
target: "0x2::coin::into_balance",
|
|
472
460
|
arguments: [M],
|
|
473
461
|
typeArguments: [n.suiCoinType]
|
|
474
|
-
}), [x] = await
|
|
462
|
+
}), [x] = await se(o, n, j, W), [k] = o.moveCall({
|
|
475
463
|
target: "0x2::coin::from_balance",
|
|
476
464
|
arguments: [x],
|
|
477
465
|
typeArguments: [n.suiCoinType]
|
|
478
466
|
});
|
|
479
|
-
return
|
|
467
|
+
return o.transferObjects([k], s), o;
|
|
480
468
|
}
|
|
481
|
-
async function ee(
|
|
482
|
-
var
|
|
469
|
+
async function ee(o, e, a, t) {
|
|
470
|
+
var w, g;
|
|
483
471
|
if (!this.walletClient)
|
|
484
472
|
throw new Error("Wallet client not found");
|
|
485
|
-
await this.walletClient.
|
|
486
|
-
|
|
487
|
-
|
|
473
|
+
const s = await te(this.walletClient.address, {
|
|
474
|
+
client: this.walletClient.client,
|
|
475
|
+
coinType: e
|
|
476
|
+
}), n = await this.getPool(a), i = new S(s).getBalance(e);
|
|
477
|
+
if (i.amount.eq(0))
|
|
488
478
|
throw new Error(`No balance of ${e}`);
|
|
489
479
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
490
|
-
balance:
|
|
491
|
-
}), t != null && t.amount &&
|
|
480
|
+
balance: i.amount.toNumber()
|
|
481
|
+
}), t != null && t.amount && i.amount.lt(t.amount))
|
|
492
482
|
throw new Error("Amount is greater than balance");
|
|
493
|
-
const
|
|
494
|
-
let
|
|
495
|
-
balance:
|
|
483
|
+
const l = (w = t == null ? void 0 : t.amount) != null ? w : i.amount.toNumber(), u = (g = t == null ? void 0 : t.slippage) != null ? g : 5e-3;
|
|
484
|
+
let r = await B(o, i.coins, {
|
|
485
|
+
balance: l,
|
|
496
486
|
useGasCoin: !0
|
|
497
487
|
});
|
|
498
|
-
if (
|
|
499
|
-
const h = await this.walletClient.swap.getQuote(e,
|
|
500
|
-
|
|
501
|
-
|
|
488
|
+
if (p(e) !== p(n.suiCoinType)) {
|
|
489
|
+
const h = await this.walletClient.swap.getQuote(e, n.suiCoinType, l);
|
|
490
|
+
r = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
491
|
+
o,
|
|
502
492
|
h,
|
|
503
|
-
|
|
504
|
-
|
|
493
|
+
r,
|
|
494
|
+
u
|
|
505
495
|
);
|
|
506
496
|
}
|
|
507
|
-
return await N(
|
|
497
|
+
return await N(o, n, r), o;
|
|
508
498
|
}
|
|
509
499
|
class _e {
|
|
510
500
|
constructor(e) {
|
|
@@ -512,7 +502,7 @@ class _e {
|
|
|
512
502
|
}
|
|
513
503
|
async getPool(e) {
|
|
514
504
|
const a = await this.walletClient.lending.getPool(e), s = (await this.walletClient.lending.getLendingState()).find(
|
|
515
|
-
(i) => i.pool.suiCoinType ===
|
|
505
|
+
(i) => i.pool.suiCoinType === p(e)
|
|
516
506
|
), n = s ? new R(s.supplyBalance).toNumber() : 0, c = s ? new R(s.borrowBalance).toNumber() : 0;
|
|
517
507
|
return {
|
|
518
508
|
supplyBalance: n,
|
|
@@ -524,13 +514,13 @@ class _e {
|
|
|
524
514
|
throw new Error("Not implemented");
|
|
525
515
|
}
|
|
526
516
|
async withdrawCoinPTB(e, a, t) {
|
|
527
|
-
return
|
|
517
|
+
return le(e, a, t);
|
|
528
518
|
}
|
|
529
519
|
async borrowCoinPTB(e, a, t) {
|
|
530
520
|
throw new Error("Not implemented");
|
|
531
521
|
}
|
|
532
522
|
async repayCoinPTB(e, a, t, s) {
|
|
533
|
-
|
|
523
|
+
re(e, a, t, { amount: s });
|
|
534
524
|
}
|
|
535
525
|
}
|
|
536
526
|
class z {
|
|
@@ -552,24 +542,24 @@ class z {
|
|
|
552
542
|
}
|
|
553
543
|
async getPool(e) {
|
|
554
544
|
var b, y;
|
|
555
|
-
const a =
|
|
545
|
+
const a = p(e), t = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
|
|
556
546
|
t.forEach((d) => {
|
|
557
|
-
s.add(
|
|
558
|
-
|
|
559
|
-
}), d.borrowsPoolRewardManager.poolRewards.forEach((
|
|
560
|
-
|
|
547
|
+
s.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((f) => {
|
|
548
|
+
f && s.add(p(f.coinType.name));
|
|
549
|
+
}), d.borrowsPoolRewardManager.poolRewards.forEach((f) => {
|
|
550
|
+
f && s.add(p(f.coinType.name));
|
|
561
551
|
});
|
|
562
552
|
});
|
|
563
|
-
const n = await
|
|
564
|
-
(d,
|
|
553
|
+
const n = await Oe(Array.from(s)), i = t.map((d) => Re(d, n)).reduce(
|
|
554
|
+
(d, f) => (d[f.coinType] = f, d),
|
|
565
555
|
{}
|
|
566
556
|
), l = await this.suilendClient.getObligation(
|
|
567
557
|
this.obligationOwnerCap.obligationId
|
|
568
|
-
), u = Se(l, i),
|
|
558
|
+
), u = Se(l, i), r = u.deposits.find((d) => d.coinType === a), w = u.borrows.find((d) => d.coinType === a), g = n[a].decimals;
|
|
569
559
|
return {
|
|
570
560
|
cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
|
|
571
|
-
supplyBalance: (b =
|
|
572
|
-
borrowBalance: (y =
|
|
561
|
+
supplyBalance: (b = r == null ? void 0 : r.depositedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? b : 0,
|
|
562
|
+
borrowBalance: (y = w == null ? void 0 : w.borrowedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? y : 0,
|
|
573
563
|
borrowAPR: i[a].borrowAprPercent.toNumber()
|
|
574
564
|
};
|
|
575
565
|
}
|
|
@@ -582,7 +572,7 @@ class z {
|
|
|
582
572
|
this.obligationOwnerCap.id,
|
|
583
573
|
this.obligationOwnerCap.obligationId,
|
|
584
574
|
a,
|
|
585
|
-
n ?
|
|
575
|
+
n ? Ae.toString() : Math.ceil(t / s.cTokenExchangeRate).toString(),
|
|
586
576
|
e
|
|
587
577
|
);
|
|
588
578
|
}
|
|
@@ -593,7 +583,7 @@ class z {
|
|
|
593
583
|
this.suilendClient.repay(this.obligationOwnerCap.obligationId, a, t, e), e.transferObjects([t], e.pure.address(this.walletClient.address));
|
|
594
584
|
}
|
|
595
585
|
}
|
|
596
|
-
class Fe extends
|
|
586
|
+
class Fe extends A {
|
|
597
587
|
constructor() {
|
|
598
588
|
super(), this.name = "lending", this.defaultConfig = {
|
|
599
589
|
env: "prod",
|
|
@@ -627,7 +617,7 @@ class Fe extends O {
|
|
|
627
617
|
* @returns Pool information
|
|
628
618
|
*/
|
|
629
619
|
async getPool(e, a) {
|
|
630
|
-
return await
|
|
620
|
+
return await T(e, {
|
|
631
621
|
env: this.config.env,
|
|
632
622
|
...a
|
|
633
623
|
});
|
|
@@ -641,14 +631,14 @@ class Fe extends O {
|
|
|
641
631
|
* @returns Transaction response or dry run response
|
|
642
632
|
*/
|
|
643
633
|
async deposit(e, a, t) {
|
|
644
|
-
var u,
|
|
634
|
+
var u, r, w;
|
|
645
635
|
if (!this.walletClient)
|
|
646
636
|
throw new Error("Wallet client not found");
|
|
647
|
-
const s = await
|
|
637
|
+
const s = await T(e, {
|
|
648
638
|
env: this.config.env
|
|
649
639
|
});
|
|
650
640
|
await this.walletClient.module("balance").waitForUpdate();
|
|
651
|
-
const n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i =
|
|
641
|
+
const n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
|
|
652
642
|
balance: a,
|
|
653
643
|
useGasCoin: !0
|
|
654
644
|
});
|
|
@@ -661,7 +651,7 @@ class Fe extends O {
|
|
|
661
651
|
transaction: n,
|
|
662
652
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
663
653
|
});
|
|
664
|
-
return !(t != null && t.dryRun) && ((
|
|
654
|
+
return !(t != null && t.dryRun) && ((w = (r = l.effects) == null ? void 0 : r.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:deposit-success", {
|
|
665
655
|
identifier: e,
|
|
666
656
|
amount: a
|
|
667
657
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -675,14 +665,14 @@ class Fe extends O {
|
|
|
675
665
|
* @returns Transaction response or dry run response
|
|
676
666
|
*/
|
|
677
667
|
async withdraw(e, a, t) {
|
|
678
|
-
var l, u,
|
|
668
|
+
var l, u, r;
|
|
679
669
|
if (!this.walletClient)
|
|
680
670
|
throw new Error("Wallet client not found");
|
|
681
|
-
const s = await
|
|
671
|
+
const s = await T(e, {
|
|
682
672
|
env: this.config.env
|
|
683
673
|
}), n = new m();
|
|
684
674
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
685
|
-
const c = await
|
|
675
|
+
const c = await le(n, s, a, {
|
|
686
676
|
env: this.config.env,
|
|
687
677
|
accountCap: t == null ? void 0 : t.accountCap
|
|
688
678
|
});
|
|
@@ -691,7 +681,7 @@ class Fe extends O {
|
|
|
691
681
|
transaction: n,
|
|
692
682
|
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
693
683
|
});
|
|
694
|
-
return !(t != null && t.dryRun) && ((
|
|
684
|
+
return !(t != null && t.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("lending:withdraw-success", {
|
|
695
685
|
identifier: e,
|
|
696
686
|
amount: a
|
|
697
687
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
@@ -705,14 +695,14 @@ class Fe extends O {
|
|
|
705
695
|
* @returns Transaction response or dry run response
|
|
706
696
|
*/
|
|
707
697
|
async borrow(e, a, t) {
|
|
708
|
-
var l, u,
|
|
698
|
+
var l, u, r;
|
|
709
699
|
if (!this.walletClient)
|
|
710
700
|
throw new Error("Wallet client not found");
|
|
711
|
-
const s = await
|
|
701
|
+
const s = await T(e, {
|
|
712
702
|
env: this.config.env
|
|
713
703
|
}), n = new m();
|
|
714
704
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
715
|
-
const c = await
|
|
705
|
+
const c = await ie(n, s, a, {
|
|
716
706
|
env: this.config.env,
|
|
717
707
|
accountCap: t == null ? void 0 : t.accountCap
|
|
718
708
|
});
|
|
@@ -721,7 +711,7 @@ class Fe extends O {
|
|
|
721
711
|
transaction: n,
|
|
722
712
|
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
723
713
|
});
|
|
724
|
-
return !(t != null && t.dryRun) && ((
|
|
714
|
+
return !(t != null && t.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("lending:borrow-success", {
|
|
725
715
|
identifier: e,
|
|
726
716
|
amount: a
|
|
727
717
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
@@ -735,17 +725,17 @@ class Fe extends O {
|
|
|
735
725
|
* @returns Transaction response or dry run response
|
|
736
726
|
*/
|
|
737
727
|
async repay(e, a, t) {
|
|
738
|
-
var u,
|
|
728
|
+
var u, r, w;
|
|
739
729
|
if (!this.walletClient)
|
|
740
730
|
throw new Error("Wallet client not found");
|
|
741
731
|
await this.walletClient.module("balance").waitForUpdate();
|
|
742
|
-
const s = await
|
|
732
|
+
const s = await T(e, {
|
|
743
733
|
env: this.config.env
|
|
744
|
-
}), n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i =
|
|
734
|
+
}), n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
|
|
745
735
|
balance: a,
|
|
746
736
|
useGasCoin: !0
|
|
747
737
|
});
|
|
748
|
-
await
|
|
738
|
+
await re(n, s, i, {
|
|
749
739
|
env: this.config.env,
|
|
750
740
|
amount: a,
|
|
751
741
|
accountCap: t == null ? void 0 : t.accountCap
|
|
@@ -754,7 +744,7 @@ class Fe extends O {
|
|
|
754
744
|
transaction: n,
|
|
755
745
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
756
746
|
});
|
|
757
|
-
return !(t != null && t.dryRun) && ((
|
|
747
|
+
return !(t != null && t.dryRun) && ((w = (r = l.effects) == null ? void 0 : r.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:repay-success", {
|
|
758
748
|
identifier: e,
|
|
759
749
|
amount: a
|
|
760
750
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
@@ -784,40 +774,40 @@ class Fe extends O {
|
|
|
784
774
|
* @returns Transaction response or dry run response
|
|
785
775
|
*/
|
|
786
776
|
async liquidate(e, a, t, s, n) {
|
|
787
|
-
var d,
|
|
777
|
+
var d, f, C;
|
|
788
778
|
if (!this.walletClient)
|
|
789
779
|
throw new Error("Wallet client not found");
|
|
790
|
-
const c = await
|
|
780
|
+
const c = await T(e, {
|
|
791
781
|
env: this.config.env
|
|
792
|
-
}), i = await
|
|
782
|
+
}), i = await T(t, {
|
|
793
783
|
env: this.config.env
|
|
794
|
-
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType),
|
|
784
|
+
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), r = B(l, u.coins, {
|
|
795
785
|
balance: a,
|
|
796
786
|
useGasCoin: !0
|
|
797
|
-
}), [
|
|
787
|
+
}), [w, g] = await be(
|
|
798
788
|
l,
|
|
799
789
|
c,
|
|
800
|
-
|
|
790
|
+
r,
|
|
801
791
|
i,
|
|
802
792
|
s,
|
|
803
793
|
{
|
|
804
794
|
env: this.config.env
|
|
805
795
|
}
|
|
806
|
-
), [
|
|
796
|
+
), [h] = l.moveCall({
|
|
807
797
|
target: "0x2::coin::from_balance",
|
|
808
|
-
arguments: [
|
|
798
|
+
arguments: [w],
|
|
809
799
|
typeArguments: [i.suiCoinType]
|
|
810
800
|
}), [b] = l.moveCall({
|
|
811
801
|
target: "0x2::coin::from_balance",
|
|
812
802
|
arguments: [g],
|
|
813
803
|
typeArguments: [c.suiCoinType]
|
|
814
804
|
});
|
|
815
|
-
l.transferObjects([
|
|
805
|
+
l.transferObjects([h, b], this.walletClient.address);
|
|
816
806
|
const y = await this.walletClient.signExecuteTransaction({
|
|
817
807
|
transaction: l,
|
|
818
808
|
dryRun: (d = n == null ? void 0 : n.dryRun) != null ? d : !1
|
|
819
809
|
});
|
|
820
|
-
return !(n != null && n.dryRun) && ((C = (
|
|
810
|
+
return !(n != null && n.dryRun) && ((C = (f = y.effects) == null ? void 0 : f.status) == null ? void 0 : C.status) === "success" && (this.emit("lending:liquidate-success", {
|
|
821
811
|
payIdentifier: e,
|
|
822
812
|
payAmount: a,
|
|
823
813
|
collateralIdentifier: t,
|
|
@@ -955,14 +945,14 @@ class Fe extends O {
|
|
|
955
945
|
this._protocols = e;
|
|
956
946
|
}
|
|
957
947
|
}
|
|
958
|
-
class je extends
|
|
948
|
+
class je extends A {
|
|
959
949
|
constructor() {
|
|
960
950
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
961
951
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
962
952
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
963
953
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
964
954
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
965
|
-
}, this.getStats =
|
|
955
|
+
}, this.getStats = oe(
|
|
966
956
|
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
967
957
|
);
|
|
968
958
|
}
|
|
@@ -1015,14 +1005,14 @@ class je extends O {
|
|
|
1015
1005
|
* @throws Error if wallet client not found or stake amount is too low
|
|
1016
1006
|
*/
|
|
1017
1007
|
async stake(e, a) {
|
|
1018
|
-
var l, u,
|
|
1008
|
+
var l, u, r;
|
|
1019
1009
|
if (!this.walletClient)
|
|
1020
1010
|
throw new Error("Wallet client not found");
|
|
1021
1011
|
if (e < 1e9)
|
|
1022
1012
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
1023
1013
|
const t = new m();
|
|
1024
1014
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1025
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n =
|
|
1015
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
|
|
1026
1016
|
balance: e,
|
|
1027
1017
|
useGasCoin: !0
|
|
1028
1018
|
}), c = await this.stakePTB(t, n);
|
|
@@ -1031,7 +1021,7 @@ class je extends O {
|
|
|
1031
1021
|
transaction: t,
|
|
1032
1022
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1033
1023
|
});
|
|
1034
|
-
return !(a != null && a.dryRun) && ((
|
|
1024
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("volo:stake-success", {
|
|
1035
1025
|
suiAmount: e
|
|
1036
1026
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1037
1027
|
}
|
|
@@ -1044,13 +1034,13 @@ class je extends O {
|
|
|
1044
1034
|
* @throws Error if wallet client not found or unstake amount is too low
|
|
1045
1035
|
*/
|
|
1046
1036
|
async unstake(e, a) {
|
|
1047
|
-
var l, u,
|
|
1037
|
+
var l, u, r;
|
|
1048
1038
|
if (!this.walletClient)
|
|
1049
1039
|
throw new Error("Wallet client not found");
|
|
1050
1040
|
if (e < 1e9)
|
|
1051
1041
|
throw new Error("Unstake amount should >= 1vSui");
|
|
1052
1042
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1053
|
-
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n =
|
|
1043
|
+
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
|
|
1054
1044
|
balance: e
|
|
1055
1045
|
}), c = await this.unstakePTB(t, n);
|
|
1056
1046
|
t.transferObjects([c], this.walletClient.address);
|
|
@@ -1058,12 +1048,12 @@ class je extends O {
|
|
|
1058
1048
|
transaction: t,
|
|
1059
1049
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1060
1050
|
});
|
|
1061
|
-
return !(a != null && a.dryRun) && ((
|
|
1051
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("volo:unstake-success", {
|
|
1062
1052
|
vSuiAmount: e
|
|
1063
1053
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1064
1054
|
}
|
|
1065
1055
|
}
|
|
1066
|
-
class Ie extends
|
|
1056
|
+
class Ie extends A {
|
|
1067
1057
|
constructor() {
|
|
1068
1058
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1069
1059
|
apiKey: "",
|
|
@@ -1146,30 +1136,30 @@ class Ie extends O {
|
|
|
1146
1136
|
* @returns Transaction response or dry run response
|
|
1147
1137
|
*/
|
|
1148
1138
|
async swap(e, a, t, s, n) {
|
|
1149
|
-
var y, d,
|
|
1139
|
+
var y, d, f;
|
|
1150
1140
|
if (!this.walletClient)
|
|
1151
1141
|
throw new Error("Wallet client not found");
|
|
1152
1142
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1153
|
-
const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l =
|
|
1143
|
+
const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l = B(i, c.coins, {
|
|
1154
1144
|
balance: t,
|
|
1155
1145
|
useGasCoin: !0
|
|
1156
|
-
}), u = await this.getQuote(e, a, t),
|
|
1157
|
-
if (i.transferObjects([
|
|
1146
|
+
}), u = await this.getQuote(e, a, t), r = await this.buildSwapPTBFromQuote(i, u, l, s);
|
|
1147
|
+
if (i.transferObjects([r], this.walletClient.address), i.setSender(this.walletClient.address), n != null && n.dryRun)
|
|
1158
1148
|
return await this.walletClient.signExecuteTransaction({
|
|
1159
1149
|
transaction: i,
|
|
1160
1150
|
dryRun: !0
|
|
1161
1151
|
});
|
|
1162
|
-
const
|
|
1152
|
+
const w = await i.build({
|
|
1163
1153
|
client: this.walletClient.client
|
|
1164
|
-
}), g = await this.walletClient.signer.signTransaction(
|
|
1154
|
+
}), g = await this.walletClient.signer.signTransaction(w), h = [g.signature];
|
|
1165
1155
|
try {
|
|
1166
|
-
await xe(g.bytes,
|
|
1156
|
+
await xe(g.bytes, h);
|
|
1167
1157
|
} catch (C) {
|
|
1168
1158
|
console.error(C);
|
|
1169
1159
|
}
|
|
1170
1160
|
const b = await this.walletClient.client.executeTransactionBlock({
|
|
1171
1161
|
transactionBlock: g.bytes,
|
|
1172
|
-
signature:
|
|
1162
|
+
signature: h,
|
|
1173
1163
|
options: {
|
|
1174
1164
|
showEffects: !0,
|
|
1175
1165
|
showEvents: !0,
|
|
@@ -1177,7 +1167,7 @@ class Ie extends O {
|
|
|
1177
1167
|
}
|
|
1178
1168
|
});
|
|
1179
1169
|
if (((d = (y = b.effects) == null ? void 0 : y.status) == null ? void 0 : d.status) === "success") {
|
|
1180
|
-
const C = (
|
|
1170
|
+
const C = (f = b.events) == null ? void 0 : f.find((P) => P.type.includes("::slippage::SwapEvent"));
|
|
1181
1171
|
C && this.emit("swap:swap-success", {
|
|
1182
1172
|
fromCoinType: e,
|
|
1183
1173
|
toCoinType: a,
|
|
@@ -1189,13 +1179,13 @@ class Ie extends O {
|
|
|
1189
1179
|
return b;
|
|
1190
1180
|
}
|
|
1191
1181
|
}
|
|
1192
|
-
class Ue extends
|
|
1182
|
+
class Ue extends A {
|
|
1193
1183
|
constructor() {
|
|
1194
1184
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1195
1185
|
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
1196
1186
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1197
1187
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1198
|
-
}, this.getApy =
|
|
1188
|
+
}, this.getApy = oe(
|
|
1199
1189
|
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
1200
1190
|
);
|
|
1201
1191
|
}
|
|
@@ -1245,12 +1235,12 @@ class Ue extends O {
|
|
|
1245
1235
|
* @param options Optional dry run
|
|
1246
1236
|
*/
|
|
1247
1237
|
async stake(e, a) {
|
|
1248
|
-
var l, u,
|
|
1238
|
+
var l, u, r;
|
|
1249
1239
|
if (!this.walletClient)
|
|
1250
1240
|
throw new Error("Wallet client not found");
|
|
1251
1241
|
const t = new m();
|
|
1252
1242
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1253
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n =
|
|
1243
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
|
|
1254
1244
|
balance: e,
|
|
1255
1245
|
useGasCoin: !0
|
|
1256
1246
|
}), c = await this.stakePTB(t, n);
|
|
@@ -1259,7 +1249,7 @@ class Ue extends O {
|
|
|
1259
1249
|
transaction: t,
|
|
1260
1250
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1261
1251
|
});
|
|
1262
|
-
return !(a != null && a.dryRun) && ((
|
|
1252
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1263
1253
|
}
|
|
1264
1254
|
/**
|
|
1265
1255
|
* Unstake haSUI for SUI
|
|
@@ -1268,11 +1258,11 @@ class Ue extends O {
|
|
|
1268
1258
|
* @param options Optional dry run
|
|
1269
1259
|
*/
|
|
1270
1260
|
async unstake(e, a) {
|
|
1271
|
-
var l, u,
|
|
1261
|
+
var l, u, r;
|
|
1272
1262
|
if (!this.walletClient)
|
|
1273
1263
|
throw new Error("Wallet client not found");
|
|
1274
1264
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1275
|
-
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n =
|
|
1265
|
+
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
|
|
1276
1266
|
balance: e
|
|
1277
1267
|
}), c = await this.unstakePTB(t, n);
|
|
1278
1268
|
t.transferObjects([c], this.walletClient.address);
|
|
@@ -1280,7 +1270,7 @@ class Ue extends O {
|
|
|
1280
1270
|
transaction: t,
|
|
1281
1271
|
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1282
1272
|
});
|
|
1283
|
-
return !(a != null && a.dryRun) && ((
|
|
1273
|
+
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1284
1274
|
}
|
|
1285
1275
|
}
|
|
1286
1276
|
const Me = {
|
|
@@ -1295,7 +1285,7 @@ const Me = {
|
|
|
1295
1285
|
/** Haedal protocol module */
|
|
1296
1286
|
haedal: new Ue()
|
|
1297
1287
|
}, We = {
|
|
1298
|
-
url:
|
|
1288
|
+
url: we("mainnet")
|
|
1299
1289
|
};
|
|
1300
1290
|
class Ye {
|
|
1301
1291
|
/**
|
|
@@ -1303,12 +1293,12 @@ class Ye {
|
|
|
1303
1293
|
* @param options - Configuration options for the wallet client
|
|
1304
1294
|
*/
|
|
1305
1295
|
constructor(e) {
|
|
1306
|
-
this.modules = Me, this.userConfigs = {}, this.events =
|
|
1296
|
+
this.modules = Me, this.userConfigs = {}, this.events = fe();
|
|
1307
1297
|
const a = {
|
|
1308
1298
|
...We,
|
|
1309
1299
|
...e.client
|
|
1310
1300
|
};
|
|
1311
|
-
a.transport = a.transport || new ke(a.url), this.client = new
|
|
1301
|
+
a.transport = a.transport || new ke(a.url), this.client = new he(a), this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, s]) => {
|
|
1312
1302
|
if (t !== s.name)
|
|
1313
1303
|
throw new Error(`Module name ${t} does not match module name ${s.name}`);
|
|
1314
1304
|
s.install(this);
|
|
@@ -1384,7 +1374,7 @@ class Ye {
|
|
|
1384
1374
|
return e in this.modules;
|
|
1385
1375
|
}
|
|
1386
1376
|
}
|
|
1387
|
-
class Ze extends
|
|
1377
|
+
class Ze extends ce {
|
|
1388
1378
|
/**
|
|
1389
1379
|
* Creates a new watch-only signer
|
|
1390
1380
|
*
|
|
@@ -1448,7 +1438,7 @@ class Ze extends oe {
|
|
|
1448
1438
|
return {};
|
|
1449
1439
|
}
|
|
1450
1440
|
}
|
|
1451
|
-
class et extends
|
|
1441
|
+
class et extends ce {
|
|
1452
1442
|
/**
|
|
1453
1443
|
* Creates a new watch-only signer
|
|
1454
1444
|
*
|