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