@naviprotocol/wallet-client 1.3.2-dev.2 → 1.3.2-dev.6
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 +212 -217
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/lendingModule/index.d.ts +0 -1
- package/dist/modules/lendingModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/migrate.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { getFullnodeUrl as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as
|
|
5
|
-
import
|
|
6
|
-
import { normalizeStructTag 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
|
+
import R, { BigNumber as L } from "bignumber.js";
|
|
6
|
+
import { normalizeStructTag as p } from "@mysten/sui/utils";
|
|
7
7
|
import { Transaction as m } from "@mysten/sui/transactions";
|
|
8
|
-
import { buildSwapPTBFromQuote as
|
|
9
|
-
import { SuilendClient as
|
|
10
|
-
import { getCoinMetadataMap as
|
|
11
|
-
import { executeAuction as
|
|
12
|
-
import { Signer as
|
|
13
|
-
const
|
|
8
|
+
import { buildSwapPTBFromQuote as G, generateRefId as Te, getQuote as ve } from "@naviprotocol/astros-aggregator-sdk";
|
|
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 Oe, MAX_U64 as Ae } from "@suilend/sui-fe";
|
|
11
|
+
import { executeAuction as xe } from "shio-sdk";
|
|
12
|
+
import { Signer as ce } from "@mysten/sui/cryptography";
|
|
13
|
+
const ue = ge.create({
|
|
14
14
|
timeout: 2e4
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
ue.interceptors.response.use(
|
|
17
17
|
function(o) {
|
|
18
18
|
if (o.data.err)
|
|
19
19
|
throw new Error(o.data.err);
|
|
@@ -25,7 +25,7 @@ ge.interceptors.response.use(
|
|
|
25
25
|
return Promise.reject(o);
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
|
-
class
|
|
28
|
+
class ke {
|
|
29
29
|
/**
|
|
30
30
|
* Creates a new custom transport instance
|
|
31
31
|
*
|
|
@@ -44,7 +44,7 @@ class Me {
|
|
|
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,
|
|
@@ -107,23 +107,23 @@ class A {
|
|
|
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,
|
|
126
|
-
amount:
|
|
126
|
+
amount: L(0),
|
|
127
127
|
coins: []
|
|
128
128
|
}, a[s] = n), n.coins.push(t), n.amount = n.amount.plus(t.balance);
|
|
129
129
|
}), this.balances = a;
|
|
@@ -136,7 +136,7 @@ class E {
|
|
|
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,9 +153,9 @@ class E {
|
|
|
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
|
-
return (a == null ? void 0 : a.amount) ||
|
|
158
|
+
return (a == null ? void 0 : a.amount) || L(0);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Creates a deep copy of the portfolio
|
|
@@ -166,22 +166,22 @@ class E {
|
|
|
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
|
|
173
|
+
class Ne extends A {
|
|
174
174
|
constructor() {
|
|
175
175
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
176
176
|
coinPollingInterval: 6e3,
|
|
177
177
|
disableCoinPolling: !1
|
|
178
|
-
}, this.updatePortfolio =
|
|
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
|
|
@@ -238,17 +238,17 @@ class Le extends A {
|
|
|
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((
|
|
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((
|
|
251
|
-
i.transferObjects([u[h]],
|
|
250
|
+
return a.forEach((g, h) => {
|
|
251
|
+
i.transferObjects([u[h]], g);
|
|
252
252
|
}), await this.walletClient.signExecuteTransaction({
|
|
253
253
|
transaction: i,
|
|
254
254
|
dryRun: (w = s == null ? void 0 : s.dryRun) != null ? w : !1
|
|
@@ -329,11 +329,11 @@ class Le extends A {
|
|
|
329
329
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
async function
|
|
333
|
-
var
|
|
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
|
-
const s = await this.getPool(e), n = await this.getPool(a), c = await this.getLendingState(), i = this.walletClient.address, l = (
|
|
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);
|
|
337
337
|
if (!u)
|
|
338
338
|
throw new Error(`Protocol ${l} not found`);
|
|
339
339
|
const r = await u.getPool(s.coinType);
|
|
@@ -343,59 +343,59 @@ async function ne(o, e, a, t) {
|
|
|
343
343
|
throw new Error("No supply balance");
|
|
344
344
|
if (t != null && t.amount && t.amount > r.supplyBalance)
|
|
345
345
|
throw new Error("Amount is less than supply balance");
|
|
346
|
-
const w = await K(),
|
|
347
|
-
await
|
|
346
|
+
const w = await K(), g = await Promise.all([s, n]);
|
|
347
|
+
await $(
|
|
348
348
|
o,
|
|
349
|
-
|
|
349
|
+
q(w, {
|
|
350
350
|
lendingState: c,
|
|
351
|
-
pools:
|
|
351
|
+
pools: g
|
|
352
352
|
})
|
|
353
353
|
);
|
|
354
|
-
const h = await
|
|
354
|
+
const h = await ae(n, {
|
|
355
355
|
env: this.config.env
|
|
356
356
|
});
|
|
357
357
|
if (!h)
|
|
358
358
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
359
|
-
const
|
|
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(
|
|
360
360
|
s.suiCoinType,
|
|
361
361
|
n.suiCoinType,
|
|
362
|
-
|
|
363
|
-
),
|
|
364
|
-
if (
|
|
362
|
+
y
|
|
363
|
+
), f = Number(d.amount_out);
|
|
364
|
+
if (f <= 0)
|
|
365
365
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
366
|
+
const C = Math.floor(f * (1 - b)), P = Math.floor(C / (1 + h.flashloanFee));
|
|
367
|
+
if (P <= 0)
|
|
368
368
|
throw new Error("The calculated borrow amount must be positive.");
|
|
369
|
-
const [
|
|
369
|
+
const [v, E] = await ne(o, n, P), [F] = o.moveCall({
|
|
370
370
|
target: "0x2::coin::from_balance",
|
|
371
|
-
arguments: [
|
|
371
|
+
arguments: [v],
|
|
372
372
|
typeArguments: [n.suiCoinType]
|
|
373
373
|
});
|
|
374
|
-
await
|
|
375
|
-
amount:
|
|
374
|
+
await N(o, n, F, {
|
|
375
|
+
amount: P
|
|
376
376
|
});
|
|
377
|
-
const
|
|
377
|
+
const j = await u.withdrawCoinPTB(o, s.suiCoinType, y), I = await G(
|
|
378
378
|
i,
|
|
379
379
|
o,
|
|
380
|
-
|
|
381
|
-
|
|
380
|
+
C,
|
|
381
|
+
j,
|
|
382
382
|
d
|
|
383
|
-
),
|
|
383
|
+
), U = o.moveCall({
|
|
384
384
|
target: "0x2::coin::into_balance",
|
|
385
|
-
arguments: [
|
|
385
|
+
arguments: [I],
|
|
386
386
|
typeArguments: [n.suiCoinType]
|
|
387
|
-
}), [M] = await
|
|
387
|
+
}), [M] = await se(o, n, E, U), [W] = o.moveCall({
|
|
388
388
|
target: "0x2::coin::from_balance",
|
|
389
389
|
arguments: [M],
|
|
390
390
|
typeArguments: [n.suiCoinType]
|
|
391
391
|
});
|
|
392
|
-
return await
|
|
392
|
+
return await N(o, n, W), o;
|
|
393
393
|
}
|
|
394
|
-
async function
|
|
395
|
-
var
|
|
394
|
+
async function Z(o, e, a, t) {
|
|
395
|
+
var O, H, D;
|
|
396
396
|
if (!this.walletClient)
|
|
397
397
|
throw new Error("Wallet client not found");
|
|
398
|
-
const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a), i = await this.getLendingState(), 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);
|
|
399
399
|
if (!u)
|
|
400
400
|
throw new Error(`Protocol ${l} not found`);
|
|
401
401
|
const r = await u.getPool(n.coinType);
|
|
@@ -405,91 +405,87 @@ async function se(o, e, a, t) {
|
|
|
405
405
|
throw new Error("No borrow balance");
|
|
406
406
|
if (t != null && t.amount && t.amount > r.borrowBalance)
|
|
407
407
|
throw new Error("Amount is more than borrow balance");
|
|
408
|
-
const w = await K(),
|
|
409
|
-
await
|
|
408
|
+
const w = await K(), g = await Promise.all([n, c]);
|
|
409
|
+
await $(
|
|
410
410
|
o,
|
|
411
|
-
|
|
411
|
+
q(w, {
|
|
412
412
|
lendingState: i,
|
|
413
|
-
pools:
|
|
413
|
+
pools: g
|
|
414
414
|
})
|
|
415
415
|
);
|
|
416
|
-
let h = (
|
|
416
|
+
let h = (H = t == null ? void 0 : t.amount) != null ? H : Number(r.borrowBalance);
|
|
417
417
|
if (Number(r.borrowBalance) === h) {
|
|
418
|
-
const
|
|
418
|
+
const de = r.borrowAPR / 100;
|
|
419
419
|
h = Math.ceil(
|
|
420
|
-
new
|
|
420
|
+
new R(h).multipliedBy(de * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-n.token.decimals)).plus(h).toNumber()
|
|
421
421
|
);
|
|
422
422
|
}
|
|
423
|
-
const
|
|
423
|
+
const b = await ae(n, {
|
|
424
424
|
env: this.config.env
|
|
425
425
|
});
|
|
426
|
-
if (!
|
|
426
|
+
if (!b)
|
|
427
427
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
428
428
|
if (!this.walletClient)
|
|
429
429
|
throw new Error("Wallet client not found");
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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(
|
|
431
|
+
n.suiCoinType,
|
|
432
|
+
c.suiCoinType,
|
|
433
|
+
f
|
|
434
|
+
);
|
|
435
|
+
let P = 1 + y, v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
436
|
+
c.suiCoinType,
|
|
437
|
+
n.suiCoinType,
|
|
438
|
+
v
|
|
439
|
+
);
|
|
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(
|
|
442
|
+
c.suiCoinType,
|
|
443
|
+
n.suiCoinType,
|
|
444
|
+
v
|
|
445
|
+
);
|
|
446
|
+
const [F, j] = await ne(o, n, h), [I] = o.moveCall({
|
|
447
447
|
target: "0x2::coin::from_balance",
|
|
448
|
-
arguments: [
|
|
448
|
+
arguments: [F],
|
|
449
449
|
typeArguments: [n.suiCoinType]
|
|
450
450
|
});
|
|
451
|
-
await u.repayCoinPTB(o, n.suiCoinType,
|
|
452
|
-
const
|
|
453
|
-
c.suiCoinType,
|
|
454
|
-
n.suiCoinType,
|
|
455
|
-
k
|
|
456
|
-
), me = await z(
|
|
451
|
+
await u.repayCoinPTB(o, n.suiCoinType, I, h);
|
|
452
|
+
const U = await ie(o, c, v), M = await G(
|
|
457
453
|
s,
|
|
458
454
|
o,
|
|
459
455
|
d,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
),
|
|
456
|
+
U,
|
|
457
|
+
E
|
|
458
|
+
), W = o.moveCall({
|
|
463
459
|
target: "0x2::coin::into_balance",
|
|
464
|
-
arguments: [
|
|
460
|
+
arguments: [M],
|
|
465
461
|
typeArguments: [n.suiCoinType]
|
|
466
|
-
}), [
|
|
462
|
+
}), [x] = await se(o, n, j, W), [k] = o.moveCall({
|
|
467
463
|
target: "0x2::coin::from_balance",
|
|
468
|
-
arguments: [
|
|
464
|
+
arguments: [x],
|
|
469
465
|
typeArguments: [n.suiCoinType]
|
|
470
466
|
});
|
|
471
|
-
return o.transferObjects([
|
|
467
|
+
return o.transferObjects([k], s), o;
|
|
472
468
|
}
|
|
473
|
-
async function
|
|
474
|
-
var w,
|
|
469
|
+
async function ee(o, e, a, t) {
|
|
470
|
+
var w, g;
|
|
475
471
|
if (!this.walletClient)
|
|
476
472
|
throw new Error("Wallet client not found");
|
|
477
|
-
const s = await
|
|
473
|
+
const s = await te(this.walletClient.address, {
|
|
478
474
|
client: this.walletClient.client,
|
|
479
475
|
coinType: e
|
|
480
|
-
}), n = await this.getPool(a), i = new
|
|
476
|
+
}), n = await this.getPool(a), i = new S(s).getBalance(e);
|
|
481
477
|
if (i.amount.eq(0))
|
|
482
478
|
throw new Error(`No balance of ${e}`);
|
|
483
479
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
484
480
|
balance: i.amount.toNumber()
|
|
485
481
|
}), t != null && t.amount && i.amount.lt(t.amount))
|
|
486
482
|
throw new Error("Amount is greater than balance");
|
|
487
|
-
const l = (w = t == null ? void 0 : t.amount) != null ? w : i.amount.toNumber(), u = (
|
|
488
|
-
let r = await
|
|
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, {
|
|
489
485
|
balance: l,
|
|
490
486
|
useGasCoin: !0
|
|
491
487
|
});
|
|
492
|
-
if (
|
|
488
|
+
if (p(e) !== p(n.suiCoinType)) {
|
|
493
489
|
const h = await this.walletClient.swap.getQuote(e, n.suiCoinType, l);
|
|
494
490
|
r = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
495
491
|
o,
|
|
@@ -498,16 +494,16 @@ async function ie(o, e, a, t) {
|
|
|
498
494
|
u
|
|
499
495
|
);
|
|
500
496
|
}
|
|
501
|
-
return await
|
|
497
|
+
return await N(o, n, r), o;
|
|
502
498
|
}
|
|
503
|
-
class
|
|
499
|
+
class _e {
|
|
504
500
|
constructor(e) {
|
|
505
501
|
this.name = "navi", this.walletClient = e;
|
|
506
502
|
}
|
|
507
503
|
async getPool(e) {
|
|
508
504
|
const a = await this.walletClient.lending.getPool(e), s = (await this.walletClient.lending.getLendingState()).find(
|
|
509
|
-
(i) => i.pool.suiCoinType ===
|
|
510
|
-
), n = s ? new
|
|
505
|
+
(i) => i.pool.suiCoinType === p(e)
|
|
506
|
+
), n = s ? new R(s.supplyBalance).toNumber() : 0, c = s ? new R(s.borrowBalance).toNumber() : 0;
|
|
511
507
|
return {
|
|
512
508
|
supplyBalance: n,
|
|
513
509
|
borrowBalance: c,
|
|
@@ -518,52 +514,52 @@ class $e {
|
|
|
518
514
|
throw new Error("Not implemented");
|
|
519
515
|
}
|
|
520
516
|
async withdrawCoinPTB(e, a, t) {
|
|
521
|
-
return
|
|
517
|
+
return le(e, a, t);
|
|
522
518
|
}
|
|
523
519
|
async borrowCoinPTB(e, a, t) {
|
|
524
520
|
throw new Error("Not implemented");
|
|
525
521
|
}
|
|
526
522
|
async repayCoinPTB(e, a, t, s) {
|
|
527
|
-
|
|
523
|
+
re(e, a, t, { amount: s });
|
|
528
524
|
}
|
|
529
525
|
}
|
|
530
|
-
class
|
|
526
|
+
class z {
|
|
531
527
|
constructor(e, a, t) {
|
|
532
528
|
this.name = "suilend", this.walletClient = e, this.obligationOwnerCap = a, this.suilendClient = t;
|
|
533
529
|
}
|
|
534
530
|
static async create(e) {
|
|
535
531
|
const [a, t] = await Promise.all([
|
|
536
|
-
|
|
537
|
-
|
|
532
|
+
V.initialize(Ee, X, e.client),
|
|
533
|
+
V.getObligationOwnerCaps(
|
|
538
534
|
e.address,
|
|
539
|
-
[
|
|
535
|
+
[X],
|
|
540
536
|
e.client
|
|
541
537
|
)
|
|
542
538
|
]);
|
|
543
539
|
if (t.length === 0)
|
|
544
540
|
throw new Error("No existing obligations found for wallet address: " + e.address);
|
|
545
|
-
return new
|
|
541
|
+
return new z(e, t[0], a);
|
|
546
542
|
}
|
|
547
543
|
async getPool(e) {
|
|
548
|
-
var
|
|
549
|
-
const a =
|
|
544
|
+
var b, y;
|
|
545
|
+
const a = p(e), t = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
|
|
550
546
|
t.forEach((d) => {
|
|
551
|
-
s.add(
|
|
552
|
-
|
|
553
|
-
}), d.borrowsPoolRewardManager.poolRewards.forEach((
|
|
554
|
-
|
|
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));
|
|
555
551
|
});
|
|
556
552
|
});
|
|
557
|
-
const n = await
|
|
558
|
-
(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),
|
|
559
555
|
{}
|
|
560
556
|
), l = await this.suilendClient.getObligation(
|
|
561
557
|
this.obligationOwnerCap.obligationId
|
|
562
|
-
), u =
|
|
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;
|
|
563
559
|
return {
|
|
564
560
|
cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
|
|
565
|
-
supplyBalance: (
|
|
566
|
-
borrowBalance: (
|
|
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,
|
|
567
563
|
borrowAPR: i[a].borrowAprPercent.toNumber()
|
|
568
564
|
};
|
|
569
565
|
}
|
|
@@ -576,7 +572,7 @@ class H {
|
|
|
576
572
|
this.obligationOwnerCap.id,
|
|
577
573
|
this.obligationOwnerCap.obligationId,
|
|
578
574
|
a,
|
|
579
|
-
n ?
|
|
575
|
+
n ? Ae.toString() : Math.ceil(t / s.cTokenExchangeRate).toString(),
|
|
580
576
|
e
|
|
581
577
|
);
|
|
582
578
|
}
|
|
@@ -587,13 +583,12 @@ class H {
|
|
|
587
583
|
this.suilendClient.repay(this.obligationOwnerCap.obligationId, a, t, e), e.transferObjects([t], e.pure.address(this.walletClient.address));
|
|
588
584
|
}
|
|
589
585
|
}
|
|
590
|
-
class
|
|
586
|
+
class Fe extends A {
|
|
591
587
|
constructor() {
|
|
592
588
|
super(), this.name = "lending", this.defaultConfig = {
|
|
593
589
|
env: "prod",
|
|
594
|
-
protocols: []
|
|
595
|
-
|
|
596
|
-
}, this._protocols = [], this.migrateBetweenSupplyPTB = ne, this.migrateBetweenBorrowPTB = se, this.migrateBalanceToSupplyPTB = ie, this.migrateBetweenSupplyPTB = ne.bind(this), this.migrateBetweenBorrowPTB = se.bind(this), this.migrateBalanceToSupplyPTB = ie.bind(this);
|
|
590
|
+
protocols: []
|
|
591
|
+
}, this._protocols = [], this.migrateBetweenSupplyPTB = Y, this.migrateBetweenBorrowPTB = Z, this.migrateBalanceToSupplyPTB = ee, this.migrateBetweenSupplyPTB = Y.bind(this), this.migrateBetweenBorrowPTB = Z.bind(this), this.migrateBalanceToSupplyPTB = ee.bind(this);
|
|
597
592
|
}
|
|
598
593
|
/** Get protocols (either from internal storage or config) */
|
|
599
594
|
get protocols() {
|
|
@@ -609,7 +604,7 @@ class qe extends A {
|
|
|
609
604
|
* @returns Array of pool information
|
|
610
605
|
*/
|
|
611
606
|
async getPools(e) {
|
|
612
|
-
return await
|
|
607
|
+
return await me({
|
|
613
608
|
env: this.config.env,
|
|
614
609
|
...e
|
|
615
610
|
});
|
|
@@ -622,7 +617,7 @@ class qe extends A {
|
|
|
622
617
|
* @returns Pool information
|
|
623
618
|
*/
|
|
624
619
|
async getPool(e, a) {
|
|
625
|
-
return await
|
|
620
|
+
return await T(e, {
|
|
626
621
|
env: this.config.env,
|
|
627
622
|
...a
|
|
628
623
|
});
|
|
@@ -639,15 +634,15 @@ class qe extends A {
|
|
|
639
634
|
var u, r, w;
|
|
640
635
|
if (!this.walletClient)
|
|
641
636
|
throw new Error("Wallet client not found");
|
|
642
|
-
const s = await
|
|
637
|
+
const s = await T(e, {
|
|
643
638
|
env: this.config.env
|
|
644
639
|
});
|
|
645
640
|
await this.walletClient.module("balance").waitForUpdate();
|
|
646
|
-
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, {
|
|
647
642
|
balance: a,
|
|
648
643
|
useGasCoin: !0
|
|
649
644
|
});
|
|
650
|
-
await
|
|
645
|
+
await N(n, s, i, {
|
|
651
646
|
env: this.config.env,
|
|
652
647
|
amount: a,
|
|
653
648
|
accountCap: t == null ? void 0 : t.accountCap
|
|
@@ -673,11 +668,11 @@ class qe extends A {
|
|
|
673
668
|
var l, u, r;
|
|
674
669
|
if (!this.walletClient)
|
|
675
670
|
throw new Error("Wallet client not found");
|
|
676
|
-
const s = await
|
|
671
|
+
const s = await T(e, {
|
|
677
672
|
env: this.config.env
|
|
678
673
|
}), n = new m();
|
|
679
674
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
680
|
-
const c = await
|
|
675
|
+
const c = await le(n, s, a, {
|
|
681
676
|
env: this.config.env,
|
|
682
677
|
accountCap: t == null ? void 0 : t.accountCap
|
|
683
678
|
});
|
|
@@ -703,11 +698,11 @@ class qe extends A {
|
|
|
703
698
|
var l, u, r;
|
|
704
699
|
if (!this.walletClient)
|
|
705
700
|
throw new Error("Wallet client not found");
|
|
706
|
-
const s = await
|
|
701
|
+
const s = await T(e, {
|
|
707
702
|
env: this.config.env
|
|
708
703
|
}), n = new m();
|
|
709
704
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
710
|
-
const c = await
|
|
705
|
+
const c = await ie(n, s, a, {
|
|
711
706
|
env: this.config.env,
|
|
712
707
|
accountCap: t == null ? void 0 : t.accountCap
|
|
713
708
|
});
|
|
@@ -734,13 +729,13 @@ class qe extends A {
|
|
|
734
729
|
if (!this.walletClient)
|
|
735
730
|
throw new Error("Wallet client not found");
|
|
736
731
|
await this.walletClient.module("balance").waitForUpdate();
|
|
737
|
-
const s = await
|
|
732
|
+
const s = await T(e, {
|
|
738
733
|
env: this.config.env
|
|
739
|
-
}), 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, {
|
|
740
735
|
balance: a,
|
|
741
736
|
useGasCoin: !0
|
|
742
737
|
});
|
|
743
|
-
await
|
|
738
|
+
await re(n, s, i, {
|
|
744
739
|
env: this.config.env,
|
|
745
740
|
amount: a,
|
|
746
741
|
accountCap: t == null ? void 0 : t.accountCap
|
|
@@ -763,7 +758,7 @@ class qe extends A {
|
|
|
763
758
|
if (!this.walletClient)
|
|
764
759
|
throw new Error("Wallet client not found");
|
|
765
760
|
const e = this.walletClient.address;
|
|
766
|
-
return await
|
|
761
|
+
return await Ce(e, {
|
|
767
762
|
env: this.config.env,
|
|
768
763
|
client: this.walletClient.client
|
|
769
764
|
});
|
|
@@ -779,17 +774,17 @@ class qe extends A {
|
|
|
779
774
|
* @returns Transaction response or dry run response
|
|
780
775
|
*/
|
|
781
776
|
async liquidate(e, a, t, s, n) {
|
|
782
|
-
var d,
|
|
777
|
+
var d, f, C;
|
|
783
778
|
if (!this.walletClient)
|
|
784
779
|
throw new Error("Wallet client not found");
|
|
785
|
-
const c = await
|
|
780
|
+
const c = await T(e, {
|
|
786
781
|
env: this.config.env
|
|
787
|
-
}), i = await
|
|
782
|
+
}), i = await T(t, {
|
|
788
783
|
env: this.config.env
|
|
789
|
-
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), r =
|
|
784
|
+
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), r = B(l, u.coins, {
|
|
790
785
|
balance: a,
|
|
791
786
|
useGasCoin: !0
|
|
792
|
-
}), [w,
|
|
787
|
+
}), [w, g] = await be(
|
|
793
788
|
l,
|
|
794
789
|
c,
|
|
795
790
|
r,
|
|
@@ -802,22 +797,22 @@ class qe extends A {
|
|
|
802
797
|
target: "0x2::coin::from_balance",
|
|
803
798
|
arguments: [w],
|
|
804
799
|
typeArguments: [i.suiCoinType]
|
|
805
|
-
}), [
|
|
800
|
+
}), [b] = l.moveCall({
|
|
806
801
|
target: "0x2::coin::from_balance",
|
|
807
|
-
arguments: [
|
|
802
|
+
arguments: [g],
|
|
808
803
|
typeArguments: [c.suiCoinType]
|
|
809
804
|
});
|
|
810
|
-
l.transferObjects([h,
|
|
811
|
-
const
|
|
805
|
+
l.transferObjects([h, b], this.walletClient.address);
|
|
806
|
+
const y = await this.walletClient.signExecuteTransaction({
|
|
812
807
|
transaction: l,
|
|
813
808
|
dryRun: (d = n == null ? void 0 : n.dryRun) != null ? d : !1
|
|
814
809
|
});
|
|
815
|
-
return !(n != null && n.dryRun) && ((
|
|
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", {
|
|
816
811
|
payIdentifier: e,
|
|
817
812
|
payAmount: a,
|
|
818
813
|
collateralIdentifier: t,
|
|
819
814
|
liquidationAddress: s
|
|
820
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
815
|
+
}), this.walletClient.module("balance").updatePortfolio()), y;
|
|
821
816
|
}
|
|
822
817
|
/**
|
|
823
818
|
* Gets the available lending rewards for the current user.
|
|
@@ -829,7 +824,7 @@ class qe extends A {
|
|
|
829
824
|
async getAvailableRewards(e) {
|
|
830
825
|
if (!this.walletClient)
|
|
831
826
|
throw new Error("Wallet client not found");
|
|
832
|
-
return
|
|
827
|
+
return J(this.walletClient.address, {
|
|
833
828
|
...e,
|
|
834
829
|
env: this.config.env
|
|
835
830
|
});
|
|
@@ -844,7 +839,7 @@ class qe extends A {
|
|
|
844
839
|
async getClaimedRewardHistory(e) {
|
|
845
840
|
if (!this.walletClient)
|
|
846
841
|
throw new Error("Wallet client not found");
|
|
847
|
-
return
|
|
842
|
+
return ye(this.walletClient.address, {
|
|
848
843
|
...e
|
|
849
844
|
});
|
|
850
845
|
}
|
|
@@ -858,10 +853,10 @@ class qe extends A {
|
|
|
858
853
|
var n, c, i;
|
|
859
854
|
if (!this.walletClient)
|
|
860
855
|
throw new Error("Wallet client not found");
|
|
861
|
-
const a = new m(), t = await
|
|
856
|
+
const a = new m(), t = await J(this.walletClient.address, {
|
|
862
857
|
env: this.config.env
|
|
863
858
|
});
|
|
864
|
-
await
|
|
859
|
+
await pe(a, t, {
|
|
865
860
|
env: this.config.env,
|
|
866
861
|
accountCap: e == null ? void 0 : e.accountCap
|
|
867
862
|
});
|
|
@@ -878,11 +873,11 @@ class qe extends A {
|
|
|
878
873
|
env: this.config.env
|
|
879
874
|
}), s = await this.getLendingState({
|
|
880
875
|
cacheTime: 60 * 1e3
|
|
881
|
-
}), n =
|
|
876
|
+
}), n = q(t, {
|
|
882
877
|
lendingState: s,
|
|
883
878
|
pools: a
|
|
884
879
|
});
|
|
885
|
-
await
|
|
880
|
+
await $(e, n, {
|
|
886
881
|
env: this.config.env,
|
|
887
882
|
updatePythPriceFeeds: !0
|
|
888
883
|
});
|
|
@@ -913,7 +908,7 @@ class qe extends A {
|
|
|
913
908
|
async getLendingState(e) {
|
|
914
909
|
if (!this.walletClient)
|
|
915
910
|
throw new Error("Wallet client not found");
|
|
916
|
-
return await
|
|
911
|
+
return await Pe(this.walletClient.address, {
|
|
917
912
|
env: this.config.env,
|
|
918
913
|
...e,
|
|
919
914
|
client: this.walletClient.client
|
|
@@ -929,7 +924,7 @@ class qe extends A {
|
|
|
929
924
|
var n;
|
|
930
925
|
if (!this.walletClient)
|
|
931
926
|
throw new Error("Wallet client not found");
|
|
932
|
-
const a = new m(), t = await
|
|
927
|
+
const a = new m(), t = await Be(a);
|
|
933
928
|
return a.transferObjects([t], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
934
929
|
transaction: a,
|
|
935
930
|
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
@@ -941,24 +936,24 @@ class qe extends A {
|
|
|
941
936
|
return;
|
|
942
937
|
}
|
|
943
938
|
const e = [];
|
|
944
|
-
e.push(new
|
|
939
|
+
e.push(new _e(this.walletClient));
|
|
945
940
|
try {
|
|
946
|
-
e.push(await
|
|
941
|
+
e.push(await z.create(this.walletClient));
|
|
947
942
|
} catch (a) {
|
|
948
943
|
console.warn("Failed to initialize SuilendProtocol:", a);
|
|
949
944
|
}
|
|
950
945
|
this._protocols = e;
|
|
951
946
|
}
|
|
952
947
|
}
|
|
953
|
-
class
|
|
948
|
+
class je extends A {
|
|
954
949
|
constructor() {
|
|
955
950
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
956
951
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
957
952
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
958
953
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
959
954
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
960
|
-
}, this.getStats =
|
|
961
|
-
|
|
955
|
+
}, this.getStats = oe(
|
|
956
|
+
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
962
957
|
);
|
|
963
958
|
}
|
|
964
959
|
/**
|
|
@@ -975,7 +970,7 @@ class Ke extends A {
|
|
|
975
970
|
e.object(this.config.poolId),
|
|
976
971
|
e.object(this.config.metadataId),
|
|
977
972
|
e.object("0x05"),
|
|
978
|
-
|
|
973
|
+
_(a, e.object)
|
|
979
974
|
],
|
|
980
975
|
typeArguments: []
|
|
981
976
|
});
|
|
@@ -995,7 +990,7 @@ class Ke extends A {
|
|
|
995
990
|
e.object(this.config.poolId),
|
|
996
991
|
e.object(this.config.metadataId),
|
|
997
992
|
e.object("0x05"),
|
|
998
|
-
|
|
993
|
+
_(a, e.object)
|
|
999
994
|
],
|
|
1000
995
|
typeArguments: []
|
|
1001
996
|
});
|
|
@@ -1017,7 +1012,7 @@ class Ke extends A {
|
|
|
1017
1012
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
1018
1013
|
const t = new m();
|
|
1019
1014
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1020
|
-
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, {
|
|
1021
1016
|
balance: e,
|
|
1022
1017
|
useGasCoin: !0
|
|
1023
1018
|
}), c = await this.stakePTB(t, n);
|
|
@@ -1045,7 +1040,7 @@ class Ke extends A {
|
|
|
1045
1040
|
if (e < 1e9)
|
|
1046
1041
|
throw new Error("Unstake amount should >= 1vSui");
|
|
1047
1042
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1048
|
-
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, {
|
|
1049
1044
|
balance: e
|
|
1050
1045
|
}), c = await this.unstakePTB(t, n);
|
|
1051
1046
|
t.transferObjects([c], this.walletClient.address);
|
|
@@ -1058,7 +1053,7 @@ class Ke extends A {
|
|
|
1058
1053
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1059
1054
|
}
|
|
1060
1055
|
}
|
|
1061
|
-
class
|
|
1056
|
+
class Ie extends A {
|
|
1062
1057
|
constructor() {
|
|
1063
1058
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1064
1059
|
apiKey: "",
|
|
@@ -1075,7 +1070,7 @@ class Qe extends A {
|
|
|
1075
1070
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
1076
1071
|
*/
|
|
1077
1072
|
get referral() {
|
|
1078
|
-
return this.config.apiKey ?
|
|
1073
|
+
return this.config.apiKey ? Te(this.config.apiKey) : 0;
|
|
1079
1074
|
}
|
|
1080
1075
|
/**
|
|
1081
1076
|
* Get the swap options
|
|
@@ -1097,7 +1092,7 @@ class Qe extends A {
|
|
|
1097
1092
|
* @returns A promise that resolves with the quote
|
|
1098
1093
|
*/
|
|
1099
1094
|
async getQuote(e, a, t) {
|
|
1100
|
-
return
|
|
1095
|
+
return ve(e, a, t, this.config.apiKey, this.swapOptions);
|
|
1101
1096
|
}
|
|
1102
1097
|
/**
|
|
1103
1098
|
* Builds a swap transaction from a quote
|
|
@@ -1110,8 +1105,8 @@ class Qe extends A {
|
|
|
1110
1105
|
async buildSwapPTBFromQuote(e, a, t, s) {
|
|
1111
1106
|
if (!this.walletClient)
|
|
1112
1107
|
throw new Error("Wallet client not found");
|
|
1113
|
-
const n = new
|
|
1114
|
-
return await
|
|
1108
|
+
const n = new R(a.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1109
|
+
return await G(
|
|
1115
1110
|
this.walletClient.address,
|
|
1116
1111
|
e,
|
|
1117
1112
|
Number(n),
|
|
@@ -1141,11 +1136,11 @@ class Qe extends A {
|
|
|
1141
1136
|
* @returns Transaction response or dry run response
|
|
1142
1137
|
*/
|
|
1143
1138
|
async swap(e, a, t, s, n) {
|
|
1144
|
-
var
|
|
1139
|
+
var y, d, f;
|
|
1145
1140
|
if (!this.walletClient)
|
|
1146
1141
|
throw new Error("Wallet client not found");
|
|
1147
1142
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1148
|
-
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, {
|
|
1149
1144
|
balance: t,
|
|
1150
1145
|
useGasCoin: !0
|
|
1151
1146
|
}), u = await this.getQuote(e, a, t), r = await this.buildSwapPTBFromQuote(i, u, l, s);
|
|
@@ -1156,14 +1151,14 @@ class Qe extends A {
|
|
|
1156
1151
|
});
|
|
1157
1152
|
const w = await i.build({
|
|
1158
1153
|
client: this.walletClient.client
|
|
1159
|
-
}),
|
|
1154
|
+
}), g = await this.walletClient.signer.signTransaction(w), h = [g.signature];
|
|
1160
1155
|
try {
|
|
1161
|
-
await
|
|
1162
|
-
} catch (
|
|
1163
|
-
console.error(
|
|
1156
|
+
await xe(g.bytes, h);
|
|
1157
|
+
} catch (C) {
|
|
1158
|
+
console.error(C);
|
|
1164
1159
|
}
|
|
1165
|
-
const
|
|
1166
|
-
transactionBlock:
|
|
1160
|
+
const b = await this.walletClient.client.executeTransactionBlock({
|
|
1161
|
+
transactionBlock: g.bytes,
|
|
1167
1162
|
signature: h,
|
|
1168
1163
|
options: {
|
|
1169
1164
|
showEffects: !0,
|
|
@@ -1171,27 +1166,27 @@ class Qe extends A {
|
|
|
1171
1166
|
showBalanceChanges: !0
|
|
1172
1167
|
}
|
|
1173
1168
|
});
|
|
1174
|
-
if (((d = (
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1169
|
+
if (((d = (y = b.effects) == null ? void 0 : y.status) == null ? void 0 : d.status) === "success") {
|
|
1170
|
+
const C = (f = b.events) == null ? void 0 : f.find((P) => P.type.includes("::slippage::SwapEvent"));
|
|
1171
|
+
C && this.emit("swap:swap-success", {
|
|
1177
1172
|
fromCoinType: e,
|
|
1178
1173
|
toCoinType: a,
|
|
1179
1174
|
fromAmount: t,
|
|
1180
1175
|
slippage: s,
|
|
1181
|
-
toAmount: Number(
|
|
1176
|
+
toAmount: Number(C.parsedJson.amount_out)
|
|
1182
1177
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1183
1178
|
}
|
|
1184
|
-
return
|
|
1179
|
+
return b;
|
|
1185
1180
|
}
|
|
1186
1181
|
}
|
|
1187
|
-
class
|
|
1182
|
+
class Ue extends A {
|
|
1188
1183
|
constructor() {
|
|
1189
1184
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1190
1185
|
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
1191
1186
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1192
1187
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1193
|
-
}, this.getApy =
|
|
1194
|
-
|
|
1188
|
+
}, this.getApy = oe(
|
|
1189
|
+
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
1195
1190
|
);
|
|
1196
1191
|
}
|
|
1197
1192
|
/**
|
|
@@ -1207,7 +1202,7 @@ class Ge extends A {
|
|
|
1207
1202
|
arguments: [
|
|
1208
1203
|
e.object("0x05"),
|
|
1209
1204
|
e.object(this.config.configId),
|
|
1210
|
-
|
|
1205
|
+
_(a, e.object),
|
|
1211
1206
|
e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1212
1207
|
],
|
|
1213
1208
|
typeArguments: []
|
|
@@ -1227,7 +1222,7 @@ class Ge extends A {
|
|
|
1227
1222
|
arguments: [
|
|
1228
1223
|
e.object("0x05"),
|
|
1229
1224
|
e.object(this.config.configId),
|
|
1230
|
-
|
|
1225
|
+
_(a, e.object)
|
|
1231
1226
|
],
|
|
1232
1227
|
typeArguments: []
|
|
1233
1228
|
});
|
|
@@ -1245,7 +1240,7 @@ class Ge extends A {
|
|
|
1245
1240
|
throw new Error("Wallet client not found");
|
|
1246
1241
|
const t = new m();
|
|
1247
1242
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1248
|
-
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, {
|
|
1249
1244
|
balance: e,
|
|
1250
1245
|
useGasCoin: !0
|
|
1251
1246
|
}), c = await this.stakePTB(t, n);
|
|
@@ -1267,7 +1262,7 @@ class Ge extends A {
|
|
|
1267
1262
|
if (!this.walletClient)
|
|
1268
1263
|
throw new Error("Wallet client not found");
|
|
1269
1264
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1270
|
-
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, {
|
|
1271
1266
|
balance: e
|
|
1272
1267
|
}), c = await this.unstakePTB(t, n);
|
|
1273
1268
|
t.transferObjects([c], this.walletClient.address);
|
|
@@ -1278,32 +1273,32 @@ class Ge extends A {
|
|
|
1278
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;
|
|
1279
1274
|
}
|
|
1280
1275
|
}
|
|
1281
|
-
const
|
|
1276
|
+
const Me = {
|
|
1282
1277
|
/** Balance management module */
|
|
1283
|
-
balance: new
|
|
1278
|
+
balance: new Ne(),
|
|
1284
1279
|
/** Lending protocol module */
|
|
1285
|
-
lending: new
|
|
1280
|
+
lending: new Fe(),
|
|
1286
1281
|
/** Volo protocol module */
|
|
1287
|
-
volo: new
|
|
1282
|
+
volo: new je(),
|
|
1288
1283
|
/** DEX swapping module */
|
|
1289
|
-
swap: new
|
|
1284
|
+
swap: new Ie(),
|
|
1290
1285
|
/** Haedal protocol module */
|
|
1291
|
-
haedal: new
|
|
1292
|
-
},
|
|
1293
|
-
url:
|
|
1286
|
+
haedal: new Ue()
|
|
1287
|
+
}, We = {
|
|
1288
|
+
url: we("mainnet")
|
|
1294
1289
|
};
|
|
1295
|
-
class
|
|
1290
|
+
class Ye {
|
|
1296
1291
|
/**
|
|
1297
1292
|
* Creates a new wallet client instance
|
|
1298
1293
|
* @param options - Configuration options for the wallet client
|
|
1299
1294
|
*/
|
|
1300
1295
|
constructor(e) {
|
|
1301
|
-
this.modules =
|
|
1296
|
+
this.modules = Me, this.userConfigs = {}, this.events = fe();
|
|
1302
1297
|
const a = {
|
|
1303
|
-
...
|
|
1298
|
+
...We,
|
|
1304
1299
|
...e.client
|
|
1305
1300
|
};
|
|
1306
|
-
a.transport = a.transport || 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]) => {
|
|
1307
1302
|
if (t !== s.name)
|
|
1308
1303
|
throw new Error(`Module name ${t} does not match module name ${s.name}`);
|
|
1309
1304
|
s.install(this);
|
|
@@ -1379,7 +1374,7 @@ class lt {
|
|
|
1379
1374
|
return e in this.modules;
|
|
1380
1375
|
}
|
|
1381
1376
|
}
|
|
1382
|
-
class
|
|
1377
|
+
class Ze extends ce {
|
|
1383
1378
|
/**
|
|
1384
1379
|
* Creates a new watch-only signer
|
|
1385
1380
|
*
|
|
@@ -1443,7 +1438,7 @@ class rt extends fe {
|
|
|
1443
1438
|
return {};
|
|
1444
1439
|
}
|
|
1445
1440
|
}
|
|
1446
|
-
class
|
|
1441
|
+
class et extends ce {
|
|
1447
1442
|
/**
|
|
1448
1443
|
* Creates a new watch-only signer
|
|
1449
1444
|
*
|
|
@@ -1496,8 +1491,8 @@ class ot extends fe {
|
|
|
1496
1491
|
}
|
|
1497
1492
|
}
|
|
1498
1493
|
export {
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1494
|
+
Ye as WalletClient,
|
|
1495
|
+
Ze as WatchSigner,
|
|
1496
|
+
et as WebSigner
|
|
1502
1497
|
};
|
|
1503
1498
|
//# sourceMappingURL=index.esm.js.map
|