@naviprotocol/wallet-client 1.1.3 → 1.1.5-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/LICENSE +21 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +368 -263
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/lendingModule/index.d.ts +9 -0
- package/dist/modules/lendingModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/migrate.d.ts +2 -0
- package/dist/modules/lendingModule/migrate.d.ts.map +1 -1
- package/dist/modules/lendingModule/protocols/index.d.ts +17 -0
- package/dist/modules/lendingModule/protocols/index.d.ts.map +1 -0
- package/dist/modules/lendingModule/protocols/navi.d.ts +17 -0
- package/dist/modules/lendingModule/protocols/navi.d.ts.map +1 -0
- package/dist/modules/lendingModule/protocols/suilend.d.ts +23 -0
- package/dist/modules/lendingModule/protocols/suilend.d.ts.map +1 -0
- package/package.json +22 -18
package/dist/index.esm.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { getFullnodeUrl as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as
|
|
5
|
-
import
|
|
1
|
+
import { getFullnodeUrl as de, SuiClient as we } from "@mysten/sui/client";
|
|
2
|
+
import he from "mitt";
|
|
3
|
+
import fe from "axios";
|
|
4
|
+
import { withSingleton as Q, getCoins as ge, mergeCoinsPTB as B, getPriceFeeds as K, updateOraclePricesPTB as $, filterPriceFeeds as q, getFlashLoanAsset as te, flashloanPTB as ae, depositCoinPTB as N, repayFlashLoanPTB as ne, borrowCoinPTB as se, withdrawCoinPTB as ie, repayCoinPTB as le, 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 re, parseTxValue as _ } from "@naviprotocol/lending";
|
|
5
|
+
import R, { BigNumber as L } from "bignumber.js";
|
|
6
6
|
import { normalizeStructTag as p } from "@mysten/sui/utils";
|
|
7
|
-
import { Transaction as
|
|
8
|
-
import { buildSwapPTBFromQuote as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
7
|
+
import { Transaction as m } from "@mysten/sui/transactions";
|
|
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 oe } from "@mysten/sui/cryptography";
|
|
13
|
+
const ce = fe.create({
|
|
12
14
|
timeout: 2e4
|
|
13
15
|
});
|
|
14
|
-
|
|
16
|
+
ce.interceptors.response.use(
|
|
15
17
|
function(r) {
|
|
16
18
|
if (r.data.err)
|
|
17
19
|
throw new Error(r.data.err);
|
|
@@ -23,7 +25,7 @@ se.interceptors.response.use(
|
|
|
23
25
|
return Promise.reject(r);
|
|
24
26
|
}
|
|
25
27
|
);
|
|
26
|
-
class
|
|
28
|
+
class ke {
|
|
27
29
|
/**
|
|
28
30
|
* Creates a new custom transport instance
|
|
29
31
|
*
|
|
@@ -42,7 +44,7 @@ class Be {
|
|
|
42
44
|
* @returns Promise<T> - The response data from the RPC call
|
|
43
45
|
*/
|
|
44
46
|
async request(e) {
|
|
45
|
-
return this.requestId += 1, (await
|
|
47
|
+
return this.requestId += 1, (await ce.post(this.rpcUrl, {
|
|
46
48
|
jsonrpc: "2.0",
|
|
47
49
|
id: this.requestId,
|
|
48
50
|
method: e.method,
|
|
@@ -62,7 +64,7 @@ class Be {
|
|
|
62
64
|
throw new Error("subscribe not implemented.");
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
class
|
|
67
|
+
class A {
|
|
66
68
|
/**
|
|
67
69
|
* Gets the current configuration for this module
|
|
68
70
|
*
|
|
@@ -105,14 +107,14 @@ class R {
|
|
|
105
107
|
this.walletClient = void 0;
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
|
-
class
|
|
110
|
+
class O {
|
|
109
111
|
/**
|
|
110
112
|
* Creates a new user portfolio
|
|
111
113
|
*
|
|
112
114
|
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
113
115
|
*/
|
|
114
116
|
constructor(e) {
|
|
115
|
-
if (e instanceof
|
|
117
|
+
if (e instanceof O)
|
|
116
118
|
this.balances = JSON.parse(JSON.stringify(e.balances));
|
|
117
119
|
else {
|
|
118
120
|
const a = {};
|
|
@@ -121,7 +123,7 @@ class E {
|
|
|
121
123
|
let n = a[s];
|
|
122
124
|
n || (n = {
|
|
123
125
|
coinType: s,
|
|
124
|
-
amount:
|
|
126
|
+
amount: L(0),
|
|
125
127
|
coins: []
|
|
126
128
|
}, a[s] = n), n.coins.push(t), n.amount = n.amount.plus(t.balance);
|
|
127
129
|
}), this.balances = a;
|
|
@@ -134,7 +136,7 @@ class E {
|
|
|
134
136
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
135
137
|
*/
|
|
136
138
|
getBalance(e) {
|
|
137
|
-
return e = p(e), this.balances[e] || { coinType: e, amount:
|
|
139
|
+
return e = p(e), this.balances[e] || { coinType: e, amount: L(0), coins: [] };
|
|
138
140
|
}
|
|
139
141
|
/**
|
|
140
142
|
* Gets all coin types in the portfolio
|
|
@@ -153,7 +155,7 @@ class E {
|
|
|
153
155
|
balanceOf(e) {
|
|
154
156
|
e = p(e);
|
|
155
157
|
const a = this.getBalance(e);
|
|
156
|
-
return (a == null ? void 0 : a.amount) ||
|
|
158
|
+
return (a == null ? void 0 : a.amount) || L(0);
|
|
157
159
|
}
|
|
158
160
|
/**
|
|
159
161
|
* Creates a deep copy of the portfolio
|
|
@@ -164,22 +166,22 @@ class E {
|
|
|
164
166
|
* @returns New UserPortfolio instance with copied data
|
|
165
167
|
*/
|
|
166
168
|
clone() {
|
|
167
|
-
const e = JSON.parse(JSON.stringify(this.balances)), a = new
|
|
169
|
+
const e = JSON.parse(JSON.stringify(this.balances)), a = new O();
|
|
168
170
|
return a.balances = e, a;
|
|
169
171
|
}
|
|
170
172
|
}
|
|
171
|
-
class
|
|
173
|
+
class Ne extends A {
|
|
172
174
|
constructor() {
|
|
173
175
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
174
176
|
coinPollingInterval: 6e3,
|
|
175
177
|
disableCoinPolling: !1
|
|
176
|
-
}, this.updatePortfolio =
|
|
178
|
+
}, this.updatePortfolio = Q(async () => {
|
|
177
179
|
if (!this.walletClient)
|
|
178
180
|
throw new Error("Wallet client not found");
|
|
179
|
-
this._coins = await
|
|
181
|
+
this._coins = await ge(this.walletClient.address, {
|
|
180
182
|
client: this.walletClient.client
|
|
181
|
-
}), this._portfolio = new
|
|
182
|
-
}), this._coins = [], this._portfolio = new
|
|
183
|
+
}), this._portfolio = new O(this._coins), this.emit("balance:portfolio-updated", {});
|
|
184
|
+
}), this._coins = [], this._portfolio = new O(), this.pollingTimer = null, this._updatePromise = null;
|
|
183
185
|
}
|
|
184
186
|
/**
|
|
185
187
|
* Gets the current coin objects from the wallet
|
|
@@ -230,26 +232,26 @@ class Pe extends R {
|
|
|
230
232
|
* @returns Transaction response or dry run response
|
|
231
233
|
*/
|
|
232
234
|
async sendCoinBatch(e, a, t, s) {
|
|
233
|
-
var
|
|
235
|
+
var w;
|
|
234
236
|
if (!this.walletClient)
|
|
235
237
|
throw new Error("Wallet client not found");
|
|
236
238
|
if (a.length !== t.length)
|
|
237
239
|
throw new Error("Recipients and amounts must have the same length");
|
|
238
240
|
await this.waitForUpdate();
|
|
239
|
-
const n = this.portfolio.getBalance(e), c = t.reduce((
|
|
241
|
+
const n = this.portfolio.getBalance(e), c = t.reduce((g, f) => g.plus(f), R(0));
|
|
240
242
|
if (n.amount.lt(c))
|
|
241
243
|
throw new Error("Insufficient balance");
|
|
242
|
-
const
|
|
243
|
-
let
|
|
244
|
-
p(e) !== p("0x2::sui::SUI") && (
|
|
244
|
+
const i = new m();
|
|
245
|
+
let l = i.gas;
|
|
246
|
+
p(e) !== p("0x2::sui::SUI") && (l = B(i, n.coins, {
|
|
245
247
|
balance: c.toNumber()
|
|
246
248
|
}));
|
|
247
|
-
const
|
|
248
|
-
return a.forEach((
|
|
249
|
-
|
|
249
|
+
const u = i.splitCoins(l, t);
|
|
250
|
+
return a.forEach((g, f) => {
|
|
251
|
+
i.transferObjects([u[f]], g);
|
|
250
252
|
}), await this.walletClient.signExecuteTransaction({
|
|
251
|
-
transaction:
|
|
252
|
-
dryRun: (
|
|
253
|
+
transaction: i,
|
|
254
|
+
dryRun: (w = s == null ? void 0 : s.dryRun) != null ? w : !1
|
|
253
255
|
});
|
|
254
256
|
}
|
|
255
257
|
/**
|
|
@@ -281,9 +283,9 @@ class Pe extends R {
|
|
|
281
283
|
if (e.length !== a.length)
|
|
282
284
|
throw new Error("Objects and recipients must have the same length");
|
|
283
285
|
await this.waitForUpdate();
|
|
284
|
-
const s = new
|
|
285
|
-
return e.forEach((
|
|
286
|
-
s.transferObjects([s.object(
|
|
286
|
+
const s = new m();
|
|
287
|
+
return e.forEach((i, l) => {
|
|
288
|
+
s.transferObjects([s.object(i)], a[l]);
|
|
287
289
|
}), await this.walletClient.signExecuteTransaction({
|
|
288
290
|
transaction: s,
|
|
289
291
|
dryRun: (c = t == null ? void 0 : t.dryRun) != null ? c : !1
|
|
@@ -327,184 +329,273 @@ class Pe extends R {
|
|
|
327
329
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
328
330
|
}
|
|
329
331
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return r ? new v(r.toString()).shiftedBy(-1 * Te).multipliedBy(100).decimalPlaces(e, v.ROUND_DOWN).toFixed(e) : "0.00";
|
|
333
|
-
}
|
|
334
|
-
async function D(r, e, a, t) {
|
|
335
|
-
var S, O;
|
|
332
|
+
async function Y(r, e, a, t) {
|
|
333
|
+
var x, k, S;
|
|
336
334
|
if (!this.walletClient)
|
|
337
335
|
throw new Error("Wallet client not found");
|
|
338
336
|
await this.walletClient.balance.updatePortfolio();
|
|
339
|
-
const s = await this.getPool(e), n = await this.getPool(a), c = await this.getLendingState(), l =
|
|
337
|
+
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
|
+
if (!u)
|
|
339
|
+
throw new Error(`Protocol ${l} not found`);
|
|
340
|
+
const o = await u.getPool(s.coinType);
|
|
340
341
|
if (console.log("migrateBetweenSupplyPTB", {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
fromPool: s,
|
|
344
|
-
toPool: n,
|
|
345
|
-
address: i
|
|
346
|
-
}), !l || l.supplyBalance === "0")
|
|
342
|
+
fromPoolLending: o
|
|
343
|
+
}), l === "navi" && o.supplyBalance === 0)
|
|
347
344
|
throw new Error("No supply balance");
|
|
348
|
-
if (t != null && t.amount && t.amount >
|
|
345
|
+
if (t != null && t.amount && t.amount > o.supplyBalance)
|
|
349
346
|
throw new Error("Amount is less than supply balance");
|
|
350
|
-
const
|
|
351
|
-
await
|
|
347
|
+
const w = await K(), g = await Promise.all([s, n]);
|
|
348
|
+
await $(
|
|
352
349
|
r,
|
|
353
|
-
|
|
350
|
+
q(w, {
|
|
354
351
|
lendingState: c,
|
|
355
|
-
pools:
|
|
352
|
+
pools: g
|
|
356
353
|
})
|
|
357
354
|
);
|
|
358
|
-
const
|
|
355
|
+
const f = await te(n, {
|
|
359
356
|
env: this.config.env
|
|
360
357
|
});
|
|
361
|
-
if (!
|
|
358
|
+
if (!f)
|
|
362
359
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
363
|
-
const
|
|
360
|
+
const b = (k = t == null ? void 0 : t.slippage) != null ? k : 5e-3, y = (S = t == null ? void 0 : t.amount) != null ? S : Number(o.supplyBalance), d = await this.walletClient.swap.getQuote(
|
|
364
361
|
s.suiCoinType,
|
|
365
362
|
n.suiCoinType,
|
|
366
|
-
|
|
367
|
-
),
|
|
368
|
-
if (
|
|
363
|
+
y
|
|
364
|
+
), h = Number(d.amount_out);
|
|
365
|
+
if (h <= 0)
|
|
369
366
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
370
|
-
const
|
|
371
|
-
if (
|
|
367
|
+
const C = Math.floor(h * (1 - b)), P = Math.floor(C / (1 + f.flashloanFee));
|
|
368
|
+
if (P <= 0)
|
|
372
369
|
throw new Error("The calculated borrow amount must be positive.");
|
|
373
|
-
const [
|
|
370
|
+
const [v, E] = await ae(r, n, P), [F] = r.moveCall({
|
|
374
371
|
target: "0x2::coin::from_balance",
|
|
375
|
-
arguments: [
|
|
372
|
+
arguments: [v],
|
|
376
373
|
typeArguments: [n.suiCoinType]
|
|
377
374
|
});
|
|
378
|
-
await
|
|
379
|
-
amount:
|
|
375
|
+
await N(r, n, F, {
|
|
376
|
+
amount: P
|
|
380
377
|
});
|
|
381
|
-
const j = await
|
|
378
|
+
const j = await u.withdrawCoinPTB(r, s.suiCoinType, y), I = await G(
|
|
382
379
|
i,
|
|
383
380
|
r,
|
|
384
|
-
|
|
381
|
+
C,
|
|
385
382
|
j,
|
|
386
|
-
|
|
383
|
+
d
|
|
387
384
|
), U = r.moveCall({
|
|
388
385
|
target: "0x2::coin::into_balance",
|
|
389
|
-
arguments: [
|
|
386
|
+
arguments: [I],
|
|
390
387
|
typeArguments: [n.suiCoinType]
|
|
391
|
-
}), [
|
|
388
|
+
}), [M] = await ne(r, n, E, U), [W] = r.moveCall({
|
|
392
389
|
target: "0x2::coin::from_balance",
|
|
393
|
-
arguments: [
|
|
390
|
+
arguments: [M],
|
|
394
391
|
typeArguments: [n.suiCoinType]
|
|
395
392
|
});
|
|
396
|
-
return await
|
|
393
|
+
return await N(r, n, W), r;
|
|
397
394
|
}
|
|
398
|
-
async function
|
|
399
|
-
var
|
|
395
|
+
async function Z(r, e, a, t) {
|
|
396
|
+
var S, H, D;
|
|
400
397
|
if (!this.walletClient)
|
|
401
398
|
throw new Error("Wallet client not found");
|
|
402
399
|
await this.walletClient.balance.updatePortfolio();
|
|
403
|
-
const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a),
|
|
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);
|
|
401
|
+
if (!u)
|
|
402
|
+
throw new Error(`Protocol ${l} not found`);
|
|
403
|
+
const o = await u.getPool(n.coinType);
|
|
404
404
|
if (console.log("migrateBetweenBorrowPTB", {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
fromPool: n,
|
|
408
|
-
toPool: c,
|
|
409
|
-
address: s
|
|
410
|
-
}), !i || i.borrowBalance === "0")
|
|
405
|
+
fromPoolLending: o
|
|
406
|
+
}), o.borrowBalance === 0)
|
|
411
407
|
throw new Error("No borrow balance");
|
|
412
|
-
if (t != null && t.amount && t.amount >
|
|
413
|
-
throw new Error("Amount is
|
|
414
|
-
const
|
|
415
|
-
await
|
|
408
|
+
if (t != null && t.amount && t.amount > o.borrowBalance)
|
|
409
|
+
throw new Error("Amount is more than borrow balance");
|
|
410
|
+
const w = await K(), g = await Promise.all([n, c]);
|
|
411
|
+
await $(
|
|
416
412
|
r,
|
|
417
|
-
|
|
418
|
-
lendingState:
|
|
419
|
-
pools:
|
|
413
|
+
q(w, {
|
|
414
|
+
lendingState: i,
|
|
415
|
+
pools: g
|
|
420
416
|
})
|
|
421
417
|
);
|
|
422
|
-
let
|
|
423
|
-
if (Number(
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
new
|
|
418
|
+
let f = (H = t == null ? void 0 : t.amount) != null ? H : Number(o.borrowBalance);
|
|
419
|
+
if (Number(o.borrowBalance) === f) {
|
|
420
|
+
const ue = o.borrowAPR / 100;
|
|
421
|
+
f = Math.ceil(
|
|
422
|
+
new R(f).multipliedBy(ue * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-n.token.decimals)).plus(f).toNumber()
|
|
427
423
|
);
|
|
428
424
|
}
|
|
429
|
-
const
|
|
425
|
+
const b = await te(n, {
|
|
430
426
|
env: this.config.env
|
|
431
427
|
});
|
|
432
|
-
if (!
|
|
428
|
+
if (!b)
|
|
433
429
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
434
430
|
if (!this.walletClient)
|
|
435
431
|
throw new Error("Wallet client not found");
|
|
436
|
-
const
|
|
432
|
+
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(f * (1 + b.flashloanFee)), h = d, C = await this.walletClient.swap.getQuote(
|
|
437
433
|
n.suiCoinType,
|
|
438
434
|
c.suiCoinType,
|
|
439
|
-
|
|
435
|
+
h
|
|
440
436
|
);
|
|
441
|
-
let
|
|
437
|
+
let P = 1 + y, v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
442
438
|
c.suiCoinType,
|
|
443
439
|
n.suiCoinType,
|
|
444
|
-
|
|
440
|
+
v
|
|
445
441
|
);
|
|
446
|
-
for (; Number(
|
|
447
|
-
|
|
442
|
+
for (; Number(E.amount_out) < h; )
|
|
443
|
+
P = P * Math.max(h / Number(E.amount_out), 1.001), v = Math.ceil(Number(C.amount_out) * P), E = await this.walletClient.swap.getQuote(
|
|
448
444
|
c.suiCoinType,
|
|
449
445
|
n.suiCoinType,
|
|
450
|
-
|
|
446
|
+
v
|
|
451
447
|
);
|
|
452
|
-
const [F, j] = await
|
|
448
|
+
const [F, j] = await ae(r, n, f), [I] = r.moveCall({
|
|
453
449
|
target: "0x2::coin::from_balance",
|
|
454
450
|
arguments: [F],
|
|
455
451
|
typeArguments: [n.suiCoinType]
|
|
456
452
|
});
|
|
457
|
-
await
|
|
458
|
-
|
|
459
|
-
});
|
|
460
|
-
const U = await te(r, c, h), W = await $(
|
|
453
|
+
await u.repayCoinPTB(r, n.suiCoinType, I, f);
|
|
454
|
+
const U = await se(r, c, v), M = await G(
|
|
461
455
|
s,
|
|
462
456
|
r,
|
|
463
|
-
|
|
457
|
+
d,
|
|
464
458
|
U,
|
|
465
|
-
|
|
466
|
-
),
|
|
459
|
+
E
|
|
460
|
+
), W = r.moveCall({
|
|
467
461
|
target: "0x2::coin::into_balance",
|
|
468
|
-
arguments: [
|
|
462
|
+
arguments: [M],
|
|
469
463
|
typeArguments: [n.suiCoinType]
|
|
470
|
-
}), [
|
|
464
|
+
}), [x] = await ne(r, n, j, W), [k] = r.moveCall({
|
|
471
465
|
target: "0x2::coin::from_balance",
|
|
472
|
-
arguments: [
|
|
466
|
+
arguments: [x],
|
|
473
467
|
typeArguments: [n.suiCoinType]
|
|
474
468
|
});
|
|
475
|
-
return r.transferObjects([
|
|
469
|
+
return r.transferObjects([k], s), r;
|
|
476
470
|
}
|
|
477
|
-
async function
|
|
478
|
-
var
|
|
471
|
+
async function ee(r, e, a, t) {
|
|
472
|
+
var u, o;
|
|
479
473
|
if (!this.walletClient)
|
|
480
474
|
throw new Error("Wallet client not found");
|
|
481
475
|
await this.walletClient.balance.updatePortfolio(), this.walletClient.address;
|
|
482
476
|
const s = await this.getPool(a), n = this.walletClient.balance.portfolio.getBalance(e);
|
|
483
477
|
if (n.amount.eq(0))
|
|
484
478
|
throw new Error(`No balance of ${e}`);
|
|
485
|
-
if (
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
479
|
+
if (console.log("migrateBalanceToSupplyPTB", {
|
|
480
|
+
balance: n.amount.toNumber()
|
|
481
|
+
}), t != null && t.amount && n.amount.lt(t.amount))
|
|
482
|
+
throw new Error("Amount is greater than balance");
|
|
483
|
+
const c = (u = t == null ? void 0 : t.amount) != null ? u : n.amount.toNumber(), i = (o = t == null ? void 0 : t.slippage) != null ? o : 5e-3;
|
|
484
|
+
let l = await B(r, n.coins, {
|
|
489
485
|
balance: c,
|
|
490
486
|
useGasCoin: !0
|
|
491
487
|
});
|
|
492
488
|
if (p(e) !== p(s.suiCoinType)) {
|
|
493
|
-
const
|
|
494
|
-
|
|
489
|
+
const w = await this.walletClient.swap.getQuote(e, s.suiCoinType, c);
|
|
490
|
+
l = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
495
491
|
r,
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
492
|
+
w,
|
|
493
|
+
l,
|
|
494
|
+
i
|
|
499
495
|
);
|
|
500
496
|
}
|
|
501
|
-
return await
|
|
497
|
+
return await N(r, s, l), r;
|
|
502
498
|
}
|
|
503
|
-
class
|
|
499
|
+
class _e {
|
|
500
|
+
constructor(e) {
|
|
501
|
+
this.name = "navi", this.walletClient = e;
|
|
502
|
+
}
|
|
503
|
+
async getPool(e) {
|
|
504
|
+
const a = await this.walletClient.lending.getPool(e), s = (await this.walletClient.lending.getLendingState()).find(
|
|
505
|
+
(i) => i.pool.suiCoinType === p(e)
|
|
506
|
+
), n = s ? new R(s.supplyBalance).toNumber() : 0, c = s ? new R(s.borrowBalance).toNumber() : 0;
|
|
507
|
+
return {
|
|
508
|
+
supplyBalance: n,
|
|
509
|
+
borrowBalance: c,
|
|
510
|
+
borrowAPR: parseFloat(a.borrowIncentiveApyInfo.apy)
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
async depositCoinPTB(e, a, t, s) {
|
|
514
|
+
throw new Error("Not implemented");
|
|
515
|
+
}
|
|
516
|
+
async withdrawCoinPTB(e, a, t) {
|
|
517
|
+
return ie(e, a, t);
|
|
518
|
+
}
|
|
519
|
+
async borrowCoinPTB(e, a, t) {
|
|
520
|
+
throw new Error("Not implemented");
|
|
521
|
+
}
|
|
522
|
+
async repayCoinPTB(e, a, t, s) {
|
|
523
|
+
le(e, a, t, { amount: s });
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
class z {
|
|
527
|
+
constructor(e, a, t) {
|
|
528
|
+
this.name = "suilend", this.walletClient = e, this.obligationOwnerCap = a, this.suilendClient = t;
|
|
529
|
+
}
|
|
530
|
+
static async create(e) {
|
|
531
|
+
const [a, t] = await Promise.all([
|
|
532
|
+
V.initialize(Ee, X, e.client),
|
|
533
|
+
V.getObligationOwnerCaps(
|
|
534
|
+
e.address,
|
|
535
|
+
[X],
|
|
536
|
+
e.client
|
|
537
|
+
)
|
|
538
|
+
]);
|
|
539
|
+
if (t.length === 0)
|
|
540
|
+
throw new Error("No existing obligations found for wallet address: " + e.address);
|
|
541
|
+
return new z(e, t[0], a);
|
|
542
|
+
}
|
|
543
|
+
async getPool(e) {
|
|
544
|
+
var b, y;
|
|
545
|
+
const a = p(e), t = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
|
|
546
|
+
t.forEach((d) => {
|
|
547
|
+
s.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((h) => {
|
|
548
|
+
h && s.add(p(h.coinType.name));
|
|
549
|
+
}), d.borrowsPoolRewardManager.poolRewards.forEach((h) => {
|
|
550
|
+
h && s.add(p(h.coinType.name));
|
|
551
|
+
});
|
|
552
|
+
});
|
|
553
|
+
const n = await Oe(Array.from(s)), i = t.map((d) => Re(d, n)).reduce(
|
|
554
|
+
(d, h) => (d[h.coinType] = h, d),
|
|
555
|
+
{}
|
|
556
|
+
), l = await this.suilendClient.getObligation(
|
|
557
|
+
this.obligationOwnerCap.obligationId
|
|
558
|
+
), u = Se(l, i), o = u.deposits.find((d) => d.coinType === a), w = u.borrows.find((d) => d.coinType === a), g = n[a].decimals;
|
|
559
|
+
return {
|
|
560
|
+
cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
|
|
561
|
+
supplyBalance: (b = o == null ? void 0 : o.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,
|
|
563
|
+
borrowAPR: i[a].borrowAprPercent.toNumber()
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
async depositCoinPTB(e, a, t, s) {
|
|
567
|
+
throw new Error("Not implemented");
|
|
568
|
+
}
|
|
569
|
+
async withdrawCoinPTB(e, a, t) {
|
|
570
|
+
const s = await this.getPool(a), n = t === s.supplyBalance;
|
|
571
|
+
return await this.suilendClient.withdraw(
|
|
572
|
+
this.obligationOwnerCap.id,
|
|
573
|
+
this.obligationOwnerCap.obligationId,
|
|
574
|
+
a,
|
|
575
|
+
n ? Ae.toString() : Math.ceil(t / s.cTokenExchangeRate).toString(),
|
|
576
|
+
e
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
async borrowCoinPTB(e, a, t) {
|
|
580
|
+
throw new Error("Not implemented");
|
|
581
|
+
}
|
|
582
|
+
async repayCoinPTB(e, a, t, s) {
|
|
583
|
+
this.suilendClient.repay(this.obligationOwnerCap.obligationId, a, t, e), e.transferObjects([t], e.pure.address(this.walletClient.address));
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
class Fe extends A {
|
|
504
587
|
constructor() {
|
|
505
588
|
super(), this.name = "lending", this.defaultConfig = {
|
|
506
|
-
env: "prod"
|
|
507
|
-
|
|
589
|
+
env: "prod",
|
|
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);
|
|
592
|
+
}
|
|
593
|
+
/** Get protocols (either from internal storage or config) */
|
|
594
|
+
get protocols() {
|
|
595
|
+
return this._protocols.length > 0 ? this._protocols : this.config.protocols;
|
|
596
|
+
}
|
|
597
|
+
async getProtocol(e) {
|
|
598
|
+
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((a) => a.name === e);
|
|
508
599
|
}
|
|
509
600
|
/**
|
|
510
601
|
* Gets all available lending pools
|
|
@@ -513,7 +604,7 @@ class ve extends R {
|
|
|
513
604
|
* @returns Array of pool information
|
|
514
605
|
*/
|
|
515
606
|
async getPools(e) {
|
|
516
|
-
return await
|
|
607
|
+
return await me({
|
|
517
608
|
env: this.config.env,
|
|
518
609
|
...e
|
|
519
610
|
});
|
|
@@ -540,30 +631,30 @@ class ve extends R {
|
|
|
540
631
|
* @returns Transaction response or dry run response
|
|
541
632
|
*/
|
|
542
633
|
async deposit(e, a, t) {
|
|
543
|
-
var
|
|
634
|
+
var u, o, w;
|
|
544
635
|
if (!this.walletClient)
|
|
545
636
|
throw new Error("Wallet client not found");
|
|
546
637
|
const s = await T(e, {
|
|
547
638
|
env: this.config.env
|
|
548
639
|
});
|
|
549
640
|
await this.walletClient.module("balance").waitForUpdate();
|
|
550
|
-
const n = new
|
|
641
|
+
const n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
|
|
551
642
|
balance: a,
|
|
552
643
|
useGasCoin: !0
|
|
553
644
|
});
|
|
554
|
-
await
|
|
645
|
+
await N(n, s, i, {
|
|
555
646
|
env: this.config.env,
|
|
556
647
|
amount: a,
|
|
557
648
|
accountCap: t == null ? void 0 : t.accountCap
|
|
558
649
|
});
|
|
559
|
-
const
|
|
650
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
560
651
|
transaction: n,
|
|
561
|
-
dryRun: (
|
|
652
|
+
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
562
653
|
});
|
|
563
|
-
return !(t != null && t.dryRun) && ((
|
|
654
|
+
return !(t != null && t.dryRun) && ((w = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:deposit-success", {
|
|
564
655
|
identifier: e,
|
|
565
656
|
amount: a
|
|
566
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
657
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
567
658
|
}
|
|
568
659
|
/**
|
|
569
660
|
* Withdraws coins from a lending pool
|
|
@@ -574,26 +665,26 @@ class ve extends R {
|
|
|
574
665
|
* @returns Transaction response or dry run response
|
|
575
666
|
*/
|
|
576
667
|
async withdraw(e, a, t) {
|
|
577
|
-
var
|
|
668
|
+
var l, u, o;
|
|
578
669
|
if (!this.walletClient)
|
|
579
670
|
throw new Error("Wallet client not found");
|
|
580
671
|
const s = await T(e, {
|
|
581
672
|
env: this.config.env
|
|
582
|
-
}), n = new
|
|
673
|
+
}), n = new m();
|
|
583
674
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
584
|
-
const c = await
|
|
675
|
+
const c = await ie(n, s, a, {
|
|
585
676
|
env: this.config.env,
|
|
586
677
|
accountCap: t == null ? void 0 : t.accountCap
|
|
587
678
|
});
|
|
588
679
|
n.transferObjects([c], this.walletClient.address);
|
|
589
|
-
const
|
|
680
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
590
681
|
transaction: n,
|
|
591
|
-
dryRun: (
|
|
682
|
+
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
592
683
|
});
|
|
593
|
-
return !(t != null && t.dryRun) && ((
|
|
684
|
+
return !(t != null && t.dryRun) && ((o = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : o.status) === "success" && (this.emit("lending:withdraw-success", {
|
|
594
685
|
identifier: e,
|
|
595
686
|
amount: a
|
|
596
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
687
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
597
688
|
}
|
|
598
689
|
/**
|
|
599
690
|
* Borrows coins from a lending pool
|
|
@@ -604,26 +695,26 @@ class ve extends R {
|
|
|
604
695
|
* @returns Transaction response or dry run response
|
|
605
696
|
*/
|
|
606
697
|
async borrow(e, a, t) {
|
|
607
|
-
var
|
|
698
|
+
var l, u, o;
|
|
608
699
|
if (!this.walletClient)
|
|
609
700
|
throw new Error("Wallet client not found");
|
|
610
701
|
const s = await T(e, {
|
|
611
702
|
env: this.config.env
|
|
612
|
-
}), n = new
|
|
703
|
+
}), n = new m();
|
|
613
704
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
614
|
-
const c = await
|
|
705
|
+
const c = await se(n, s, a, {
|
|
615
706
|
env: this.config.env,
|
|
616
707
|
accountCap: t == null ? void 0 : t.accountCap
|
|
617
708
|
});
|
|
618
709
|
n.transferObjects([c], this.walletClient.address);
|
|
619
|
-
const
|
|
710
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
620
711
|
transaction: n,
|
|
621
|
-
dryRun: (
|
|
712
|
+
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
622
713
|
});
|
|
623
|
-
return !(t != null && t.dryRun) && ((
|
|
714
|
+
return !(t != null && t.dryRun) && ((o = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : o.status) === "success" && (this.emit("lending:borrow-success", {
|
|
624
715
|
identifier: e,
|
|
625
716
|
amount: a
|
|
626
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
717
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
627
718
|
}
|
|
628
719
|
/**
|
|
629
720
|
* Repays borrowed coins to a lending pool
|
|
@@ -634,29 +725,29 @@ class ve extends R {
|
|
|
634
725
|
* @returns Transaction response or dry run response
|
|
635
726
|
*/
|
|
636
727
|
async repay(e, a, t) {
|
|
637
|
-
var
|
|
728
|
+
var u, o, w;
|
|
638
729
|
if (!this.walletClient)
|
|
639
730
|
throw new Error("Wallet client not found");
|
|
640
731
|
await this.walletClient.module("balance").waitForUpdate();
|
|
641
732
|
const s = await T(e, {
|
|
642
733
|
env: this.config.env
|
|
643
|
-
}), n = new
|
|
734
|
+
}), n = new m(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = B(n, c.coins, {
|
|
644
735
|
balance: a,
|
|
645
736
|
useGasCoin: !0
|
|
646
737
|
});
|
|
647
|
-
await
|
|
738
|
+
await le(n, s, i, {
|
|
648
739
|
env: this.config.env,
|
|
649
740
|
amount: a,
|
|
650
741
|
accountCap: t == null ? void 0 : t.accountCap
|
|
651
742
|
});
|
|
652
|
-
const
|
|
743
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
653
744
|
transaction: n,
|
|
654
|
-
dryRun: (
|
|
745
|
+
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
655
746
|
});
|
|
656
|
-
return !(t != null && t.dryRun) && ((
|
|
747
|
+
return !(t != null && t.dryRun) && ((w = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:repay-success", {
|
|
657
748
|
identifier: e,
|
|
658
749
|
amount: a
|
|
659
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
750
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
660
751
|
}
|
|
661
752
|
/**
|
|
662
753
|
* Gets the current health factor for the user
|
|
@@ -667,7 +758,7 @@ class ve extends R {
|
|
|
667
758
|
if (!this.walletClient)
|
|
668
759
|
throw new Error("Wallet client not found");
|
|
669
760
|
const e = this.walletClient.address;
|
|
670
|
-
return await
|
|
761
|
+
return await Ce(e, {
|
|
671
762
|
env: this.config.env,
|
|
672
763
|
client: this.walletClient.client
|
|
673
764
|
});
|
|
@@ -683,45 +774,45 @@ class ve extends R {
|
|
|
683
774
|
* @returns Transaction response or dry run response
|
|
684
775
|
*/
|
|
685
776
|
async liquidate(e, a, t, s, n) {
|
|
686
|
-
var
|
|
777
|
+
var d, h, C;
|
|
687
778
|
if (!this.walletClient)
|
|
688
779
|
throw new Error("Wallet client not found");
|
|
689
780
|
const c = await T(e, {
|
|
690
781
|
env: this.config.env
|
|
691
|
-
}),
|
|
782
|
+
}), i = await T(t, {
|
|
692
783
|
env: this.config.env
|
|
693
|
-
}),
|
|
784
|
+
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), o = B(l, u.coins, {
|
|
694
785
|
balance: a,
|
|
695
786
|
useGasCoin: !0
|
|
696
|
-
}), [
|
|
697
|
-
i,
|
|
698
|
-
c,
|
|
699
|
-
u,
|
|
787
|
+
}), [w, g] = await be(
|
|
700
788
|
l,
|
|
789
|
+
c,
|
|
790
|
+
o,
|
|
791
|
+
i,
|
|
701
792
|
s,
|
|
702
793
|
{
|
|
703
794
|
env: this.config.env
|
|
704
795
|
}
|
|
705
|
-
), [
|
|
796
|
+
), [f] = l.moveCall({
|
|
706
797
|
target: "0x2::coin::from_balance",
|
|
707
|
-
arguments: [
|
|
708
|
-
typeArguments: [
|
|
709
|
-
}), [b] =
|
|
798
|
+
arguments: [w],
|
|
799
|
+
typeArguments: [i.suiCoinType]
|
|
800
|
+
}), [b] = l.moveCall({
|
|
710
801
|
target: "0x2::coin::from_balance",
|
|
711
|
-
arguments: [
|
|
802
|
+
arguments: [g],
|
|
712
803
|
typeArguments: [c.suiCoinType]
|
|
713
804
|
});
|
|
714
|
-
|
|
715
|
-
const
|
|
716
|
-
transaction:
|
|
717
|
-
dryRun: (
|
|
805
|
+
l.transferObjects([f, b], this.walletClient.address);
|
|
806
|
+
const y = await this.walletClient.signExecuteTransaction({
|
|
807
|
+
transaction: l,
|
|
808
|
+
dryRun: (d = n == null ? void 0 : n.dryRun) != null ? d : !1
|
|
718
809
|
});
|
|
719
|
-
return !(n != null && n.dryRun) && ((
|
|
810
|
+
return !(n != null && n.dryRun) && ((C = (h = y.effects) == null ? void 0 : h.status) == null ? void 0 : C.status) === "success" && (this.emit("lending:liquidate-success", {
|
|
720
811
|
payIdentifier: e,
|
|
721
812
|
payAmount: a,
|
|
722
813
|
collateralIdentifier: t,
|
|
723
814
|
liquidationAddress: s
|
|
724
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
815
|
+
}), this.walletClient.module("balance").updatePortfolio()), y;
|
|
725
816
|
}
|
|
726
817
|
/**
|
|
727
818
|
* Gets the available lending rewards for the current user.
|
|
@@ -733,7 +824,7 @@ class ve extends R {
|
|
|
733
824
|
async getAvailableRewards(e) {
|
|
734
825
|
if (!this.walletClient)
|
|
735
826
|
throw new Error("Wallet client not found");
|
|
736
|
-
return
|
|
827
|
+
return J(this.walletClient.address, {
|
|
737
828
|
...e,
|
|
738
829
|
env: this.config.env
|
|
739
830
|
});
|
|
@@ -748,7 +839,7 @@ class ve extends R {
|
|
|
748
839
|
async getClaimedRewardHistory(e) {
|
|
749
840
|
if (!this.walletClient)
|
|
750
841
|
throw new Error("Wallet client not found");
|
|
751
|
-
return
|
|
842
|
+
return ye(this.walletClient.address, {
|
|
752
843
|
...e
|
|
753
844
|
});
|
|
754
845
|
}
|
|
@@ -759,13 +850,13 @@ class ve extends R {
|
|
|
759
850
|
* @returns Transaction response or dry run response
|
|
760
851
|
*/
|
|
761
852
|
async claimAllRewards(e) {
|
|
762
|
-
var n, c,
|
|
853
|
+
var n, c, i;
|
|
763
854
|
if (!this.walletClient)
|
|
764
855
|
throw new Error("Wallet client not found");
|
|
765
|
-
const a = new
|
|
856
|
+
const a = new m(), t = await J(this.walletClient.address, {
|
|
766
857
|
env: this.config.env
|
|
767
858
|
});
|
|
768
|
-
await
|
|
859
|
+
await pe(a, t, {
|
|
769
860
|
env: this.config.env,
|
|
770
861
|
accountCap: e == null ? void 0 : e.accountCap
|
|
771
862
|
});
|
|
@@ -773,20 +864,20 @@ class ve extends R {
|
|
|
773
864
|
transaction: a,
|
|
774
865
|
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
775
866
|
});
|
|
776
|
-
return !(e != null && e.dryRun) && ((
|
|
867
|
+
return !(e != null && e.dryRun) && ((i = (c = s.effects) == null ? void 0 : c.status) == null ? void 0 : i.status) === "success" && (this.emit("lending:claim-rewards-success", {
|
|
777
868
|
rewards: t
|
|
778
869
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
779
870
|
}
|
|
780
871
|
async updateOraclePTB(e, a) {
|
|
781
|
-
const t = await
|
|
872
|
+
const t = await K({
|
|
782
873
|
env: this.config.env
|
|
783
874
|
}), s = await this.getLendingState({
|
|
784
875
|
cacheTime: 60 * 1e3
|
|
785
|
-
}), n =
|
|
876
|
+
}), n = q(t, {
|
|
786
877
|
lendingState: s,
|
|
787
878
|
pools: a
|
|
788
879
|
});
|
|
789
|
-
await
|
|
880
|
+
await $(e, n, {
|
|
790
881
|
env: this.config.env,
|
|
791
882
|
updatePythPriceFeeds: !0
|
|
792
883
|
});
|
|
@@ -802,7 +893,7 @@ class ve extends R {
|
|
|
802
893
|
var s;
|
|
803
894
|
if (!this.walletClient)
|
|
804
895
|
throw new Error("Wallet client not found");
|
|
805
|
-
const a = new
|
|
896
|
+
const a = new m();
|
|
806
897
|
return await this.updateOraclePTB(a, e == null ? void 0 : e.pools), await this.walletClient.signExecuteTransaction({
|
|
807
898
|
transaction: a,
|
|
808
899
|
dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
|
|
@@ -817,7 +908,7 @@ class ve extends R {
|
|
|
817
908
|
async getLendingState(e) {
|
|
818
909
|
if (!this.walletClient)
|
|
819
910
|
throw new Error("Wallet client not found");
|
|
820
|
-
return await
|
|
911
|
+
return await Pe(this.walletClient.address, {
|
|
821
912
|
env: this.config.env,
|
|
822
913
|
...e,
|
|
823
914
|
client: this.walletClient.client
|
|
@@ -833,22 +924,36 @@ class ve extends R {
|
|
|
833
924
|
var n;
|
|
834
925
|
if (!this.walletClient)
|
|
835
926
|
throw new Error("Wallet client not found");
|
|
836
|
-
const a = new
|
|
927
|
+
const a = new m(), t = await Be(a);
|
|
837
928
|
return a.transferObjects([t], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
838
929
|
transaction: a,
|
|
839
930
|
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
840
931
|
});
|
|
841
932
|
}
|
|
933
|
+
async initializeProtocols() {
|
|
934
|
+
if (!this.walletClient) {
|
|
935
|
+
console.warn("Wallet client not available during protocol initialization");
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
const e = [];
|
|
939
|
+
e.push(new _e(this.walletClient));
|
|
940
|
+
try {
|
|
941
|
+
e.push(await z.create(this.walletClient));
|
|
942
|
+
} catch (a) {
|
|
943
|
+
console.warn("Failed to initialize SuilendProtocol:", a);
|
|
944
|
+
}
|
|
945
|
+
this._protocols = e;
|
|
946
|
+
}
|
|
842
947
|
}
|
|
843
|
-
class
|
|
948
|
+
class je extends A {
|
|
844
949
|
constructor() {
|
|
845
950
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
846
951
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
847
952
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
848
953
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
849
954
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
850
|
-
}, this.getStats =
|
|
851
|
-
|
|
955
|
+
}, this.getStats = re(
|
|
956
|
+
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
852
957
|
);
|
|
853
958
|
}
|
|
854
959
|
/**
|
|
@@ -865,7 +970,7 @@ class Ee extends R {
|
|
|
865
970
|
e.object(this.config.poolId),
|
|
866
971
|
e.object(this.config.metadataId),
|
|
867
972
|
e.object("0x05"),
|
|
868
|
-
|
|
973
|
+
_(a, e.object)
|
|
869
974
|
],
|
|
870
975
|
typeArguments: []
|
|
871
976
|
});
|
|
@@ -885,7 +990,7 @@ class Ee extends R {
|
|
|
885
990
|
e.object(this.config.poolId),
|
|
886
991
|
e.object(this.config.metadataId),
|
|
887
992
|
e.object("0x05"),
|
|
888
|
-
|
|
993
|
+
_(a, e.object)
|
|
889
994
|
],
|
|
890
995
|
typeArguments: []
|
|
891
996
|
});
|
|
@@ -900,25 +1005,25 @@ class Ee extends R {
|
|
|
900
1005
|
* @throws Error if wallet client not found or stake amount is too low
|
|
901
1006
|
*/
|
|
902
1007
|
async stake(e, a) {
|
|
903
|
-
var
|
|
1008
|
+
var l, u, o;
|
|
904
1009
|
if (!this.walletClient)
|
|
905
1010
|
throw new Error("Wallet client not found");
|
|
906
1011
|
if (e < 1e9)
|
|
907
1012
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
908
|
-
const t = new
|
|
1013
|
+
const t = new m();
|
|
909
1014
|
await this.walletClient.module("balance").waitForUpdate();
|
|
910
1015
|
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
|
|
911
1016
|
balance: e,
|
|
912
1017
|
useGasCoin: !0
|
|
913
1018
|
}), c = await this.stakePTB(t, n);
|
|
914
1019
|
t.transferObjects([c], this.walletClient.address);
|
|
915
|
-
const
|
|
1020
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
916
1021
|
transaction: t,
|
|
917
|
-
dryRun: (
|
|
1022
|
+
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
918
1023
|
});
|
|
919
|
-
return !(a != null && a.dryRun) && ((
|
|
1024
|
+
return !(a != null && a.dryRun) && ((o = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : o.status) === "success" && (this.emit("volo:stake-success", {
|
|
920
1025
|
suiAmount: e
|
|
921
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
1026
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
922
1027
|
}
|
|
923
1028
|
/**
|
|
924
1029
|
* Unstake vSUI tokens to receive SUI tokens
|
|
@@ -929,26 +1034,26 @@ class Ee extends R {
|
|
|
929
1034
|
* @throws Error if wallet client not found or unstake amount is too low
|
|
930
1035
|
*/
|
|
931
1036
|
async unstake(e, a) {
|
|
932
|
-
var
|
|
1037
|
+
var l, u, o;
|
|
933
1038
|
if (!this.walletClient)
|
|
934
1039
|
throw new Error("Wallet client not found");
|
|
935
1040
|
if (e < 1e9)
|
|
936
1041
|
throw new Error("Unstake amount should >= 1vSui");
|
|
937
1042
|
await this.walletClient.module("balance").waitForUpdate();
|
|
938
|
-
const t = new
|
|
1043
|
+
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
|
|
939
1044
|
balance: e
|
|
940
1045
|
}), c = await this.unstakePTB(t, n);
|
|
941
1046
|
t.transferObjects([c], this.walletClient.address);
|
|
942
|
-
const
|
|
1047
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
943
1048
|
transaction: t,
|
|
944
|
-
dryRun: (
|
|
1049
|
+
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
945
1050
|
});
|
|
946
|
-
return !(a != null && a.dryRun) && ((
|
|
1051
|
+
return !(a != null && a.dryRun) && ((o = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : o.status) === "success" && (this.emit("volo:unstake-success", {
|
|
947
1052
|
vSuiAmount: e
|
|
948
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
1053
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
949
1054
|
}
|
|
950
1055
|
}
|
|
951
|
-
class
|
|
1056
|
+
class Ie extends A {
|
|
952
1057
|
constructor() {
|
|
953
1058
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
954
1059
|
apiKey: "",
|
|
@@ -965,7 +1070,7 @@ class Re extends R {
|
|
|
965
1070
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
966
1071
|
*/
|
|
967
1072
|
get referral() {
|
|
968
|
-
return this.config.apiKey ?
|
|
1073
|
+
return this.config.apiKey ? Te(this.config.apiKey) : 0;
|
|
969
1074
|
}
|
|
970
1075
|
/**
|
|
971
1076
|
* Get the swap options
|
|
@@ -987,7 +1092,7 @@ class Re extends R {
|
|
|
987
1092
|
* @returns A promise that resolves with the quote
|
|
988
1093
|
*/
|
|
989
1094
|
async getQuote(e, a, t) {
|
|
990
|
-
return
|
|
1095
|
+
return ve(e, a, t, this.config.apiKey, this.swapOptions);
|
|
991
1096
|
}
|
|
992
1097
|
/**
|
|
993
1098
|
* Builds a swap transaction from a quote
|
|
@@ -1000,8 +1105,8 @@ class Re extends R {
|
|
|
1000
1105
|
async buildSwapPTBFromQuote(e, a, t, s) {
|
|
1001
1106
|
if (!this.walletClient)
|
|
1002
1107
|
throw new Error("Wallet client not found");
|
|
1003
|
-
const n = new
|
|
1004
|
-
return await
|
|
1108
|
+
const n = new R(a.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1109
|
+
return await G(
|
|
1005
1110
|
this.walletClient.address,
|
|
1006
1111
|
e,
|
|
1007
1112
|
Number(n),
|
|
@@ -1031,57 +1136,57 @@ class Re extends R {
|
|
|
1031
1136
|
* @returns Transaction response or dry run response
|
|
1032
1137
|
*/
|
|
1033
1138
|
async swap(e, a, t, s, n) {
|
|
1034
|
-
var
|
|
1139
|
+
var y, d, h;
|
|
1035
1140
|
if (!this.walletClient)
|
|
1036
1141
|
throw new Error("Wallet client not found");
|
|
1037
1142
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1038
|
-
const c = this.walletClient.module("balance").portfolio.getBalance(e),
|
|
1143
|
+
const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l = B(i, c.coins, {
|
|
1039
1144
|
balance: t,
|
|
1040
1145
|
useGasCoin: !0
|
|
1041
|
-
}),
|
|
1042
|
-
if (
|
|
1146
|
+
}), u = await this.getQuote(e, a, t), o = await this.buildSwapPTBFromQuote(i, u, l, s);
|
|
1147
|
+
if (i.transferObjects([o], this.walletClient.address), i.setSender(this.walletClient.address), n != null && n.dryRun)
|
|
1043
1148
|
return await this.walletClient.signExecuteTransaction({
|
|
1044
|
-
transaction:
|
|
1149
|
+
transaction: i,
|
|
1045
1150
|
dryRun: !0
|
|
1046
1151
|
});
|
|
1047
|
-
const
|
|
1152
|
+
const w = await i.build({
|
|
1048
1153
|
client: this.walletClient.client
|
|
1049
|
-
}),
|
|
1154
|
+
}), g = await this.walletClient.signer.signTransaction(w), f = [g.signature];
|
|
1050
1155
|
try {
|
|
1051
|
-
await
|
|
1052
|
-
} catch (
|
|
1053
|
-
console.error(
|
|
1156
|
+
await xe(g.bytes, f);
|
|
1157
|
+
} catch (C) {
|
|
1158
|
+
console.error(C);
|
|
1054
1159
|
}
|
|
1055
1160
|
const b = await this.walletClient.client.executeTransactionBlock({
|
|
1056
|
-
transactionBlock:
|
|
1057
|
-
signature:
|
|
1161
|
+
transactionBlock: g.bytes,
|
|
1162
|
+
signature: f,
|
|
1058
1163
|
options: {
|
|
1059
1164
|
showEffects: !0,
|
|
1060
1165
|
showEvents: !0,
|
|
1061
1166
|
showBalanceChanges: !0
|
|
1062
1167
|
}
|
|
1063
1168
|
});
|
|
1064
|
-
if (((
|
|
1065
|
-
const
|
|
1066
|
-
|
|
1169
|
+
if (((d = (y = b.effects) == null ? void 0 : y.status) == null ? void 0 : d.status) === "success") {
|
|
1170
|
+
const C = (h = b.events) == null ? void 0 : h.find((P) => P.type.includes("::slippage::SwapEvent"));
|
|
1171
|
+
C && this.emit("swap:swap-success", {
|
|
1067
1172
|
fromCoinType: e,
|
|
1068
1173
|
toCoinType: a,
|
|
1069
1174
|
fromAmount: t,
|
|
1070
1175
|
slippage: s,
|
|
1071
|
-
toAmount: Number(
|
|
1176
|
+
toAmount: Number(C.parsedJson.amount_out)
|
|
1072
1177
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1073
1178
|
}
|
|
1074
1179
|
return b;
|
|
1075
1180
|
}
|
|
1076
1181
|
}
|
|
1077
|
-
class
|
|
1182
|
+
class Ue extends A {
|
|
1078
1183
|
constructor() {
|
|
1079
1184
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1080
1185
|
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
1081
1186
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1082
1187
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1083
|
-
}, this.getApy =
|
|
1084
|
-
|
|
1188
|
+
}, this.getApy = re(
|
|
1189
|
+
Q(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
1085
1190
|
);
|
|
1086
1191
|
}
|
|
1087
1192
|
/**
|
|
@@ -1097,7 +1202,7 @@ class Se extends R {
|
|
|
1097
1202
|
arguments: [
|
|
1098
1203
|
e.object("0x05"),
|
|
1099
1204
|
e.object(this.config.configId),
|
|
1100
|
-
|
|
1205
|
+
_(a, e.object),
|
|
1101
1206
|
e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1102
1207
|
],
|
|
1103
1208
|
typeArguments: []
|
|
@@ -1117,7 +1222,7 @@ class Se extends R {
|
|
|
1117
1222
|
arguments: [
|
|
1118
1223
|
e.object("0x05"),
|
|
1119
1224
|
e.object(this.config.configId),
|
|
1120
|
-
|
|
1225
|
+
_(a, e.object)
|
|
1121
1226
|
],
|
|
1122
1227
|
typeArguments: []
|
|
1123
1228
|
});
|
|
@@ -1130,21 +1235,21 @@ class Se extends R {
|
|
|
1130
1235
|
* @param options Optional dry run
|
|
1131
1236
|
*/
|
|
1132
1237
|
async stake(e, a) {
|
|
1133
|
-
var
|
|
1238
|
+
var l, u, o;
|
|
1134
1239
|
if (!this.walletClient)
|
|
1135
1240
|
throw new Error("Wallet client not found");
|
|
1136
|
-
const t = new
|
|
1241
|
+
const t = new m();
|
|
1137
1242
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1138
1243
|
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = B(t, s.coins, {
|
|
1139
1244
|
balance: e,
|
|
1140
1245
|
useGasCoin: !0
|
|
1141
1246
|
}), c = await this.stakePTB(t, n);
|
|
1142
1247
|
t.transferObjects([c], this.walletClient.address);
|
|
1143
|
-
const
|
|
1248
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
1144
1249
|
transaction: t,
|
|
1145
|
-
dryRun: (
|
|
1250
|
+
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1146
1251
|
});
|
|
1147
|
-
return !(a != null && a.dryRun) && ((
|
|
1252
|
+
return !(a != null && a.dryRun) && ((o = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : o.status) === "success" && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1148
1253
|
}
|
|
1149
1254
|
/**
|
|
1150
1255
|
* Unstake haSUI for SUI
|
|
@@ -1153,47 +1258,47 @@ class Se extends R {
|
|
|
1153
1258
|
* @param options Optional dry run
|
|
1154
1259
|
*/
|
|
1155
1260
|
async unstake(e, a) {
|
|
1156
|
-
var
|
|
1261
|
+
var l, u, o;
|
|
1157
1262
|
if (!this.walletClient)
|
|
1158
1263
|
throw new Error("Wallet client not found");
|
|
1159
1264
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1160
|
-
const t = new
|
|
1265
|
+
const t = new m(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = B(t, s.coins, {
|
|
1161
1266
|
balance: e
|
|
1162
1267
|
}), c = await this.unstakePTB(t, n);
|
|
1163
1268
|
t.transferObjects([c], this.walletClient.address);
|
|
1164
|
-
const
|
|
1269
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
1165
1270
|
transaction: t,
|
|
1166
|
-
dryRun: (
|
|
1271
|
+
dryRun: (l = a == null ? void 0 : a.dryRun) != null ? l : !1
|
|
1167
1272
|
});
|
|
1168
|
-
return !(a != null && a.dryRun) && ((
|
|
1273
|
+
return !(a != null && a.dryRun) && ((o = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : o.status) === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1169
1274
|
}
|
|
1170
1275
|
}
|
|
1171
|
-
const
|
|
1276
|
+
const Me = {
|
|
1172
1277
|
/** Balance management module */
|
|
1173
|
-
balance: new
|
|
1278
|
+
balance: new Ne(),
|
|
1174
1279
|
/** Lending protocol module */
|
|
1175
|
-
lending: new
|
|
1280
|
+
lending: new Fe(),
|
|
1176
1281
|
/** Volo protocol module */
|
|
1177
|
-
volo: new
|
|
1282
|
+
volo: new je(),
|
|
1178
1283
|
/** DEX swapping module */
|
|
1179
|
-
swap: new
|
|
1284
|
+
swap: new Ie(),
|
|
1180
1285
|
/** Haedal protocol module */
|
|
1181
|
-
haedal: new
|
|
1182
|
-
},
|
|
1183
|
-
url:
|
|
1286
|
+
haedal: new Ue()
|
|
1287
|
+
}, We = {
|
|
1288
|
+
url: de("mainnet")
|
|
1184
1289
|
};
|
|
1185
|
-
class
|
|
1290
|
+
class Ye {
|
|
1186
1291
|
/**
|
|
1187
1292
|
* Creates a new wallet client instance
|
|
1188
1293
|
* @param options - Configuration options for the wallet client
|
|
1189
1294
|
*/
|
|
1190
1295
|
constructor(e) {
|
|
1191
|
-
this.modules =
|
|
1296
|
+
this.modules = Me, this.userConfigs = {}, this.events = he();
|
|
1192
1297
|
const a = {
|
|
1193
|
-
...
|
|
1298
|
+
...We,
|
|
1194
1299
|
...e.client
|
|
1195
1300
|
};
|
|
1196
|
-
a.transport = a.transport || new
|
|
1301
|
+
a.transport = a.transport || new ke(a.url), this.client = new we(a), this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, s]) => {
|
|
1197
1302
|
if (t !== s.name)
|
|
1198
1303
|
throw new Error(`Module name ${t} does not match module name ${s.name}`);
|
|
1199
1304
|
s.install(this);
|
|
@@ -1223,7 +1328,7 @@ class Le {
|
|
|
1223
1328
|
const { dryRun: a = !1, ...t } = e;
|
|
1224
1329
|
if (a) {
|
|
1225
1330
|
let s;
|
|
1226
|
-
return e.transaction instanceof
|
|
1331
|
+
return e.transaction instanceof m ? (e.transaction.setSenderIfNotSet(this.address), s = await e.transaction.build({
|
|
1227
1332
|
client: this.client
|
|
1228
1333
|
})) : s = e.transaction, this.client.dryRunTransactionBlock({
|
|
1229
1334
|
transactionBlock: s
|
|
@@ -1269,7 +1374,7 @@ class Le {
|
|
|
1269
1374
|
return e in this.modules;
|
|
1270
1375
|
}
|
|
1271
1376
|
}
|
|
1272
|
-
class
|
|
1377
|
+
class Ze extends oe {
|
|
1273
1378
|
/**
|
|
1274
1379
|
* Creates a new watch-only signer
|
|
1275
1380
|
*
|
|
@@ -1333,7 +1438,7 @@ class Qe extends ne {
|
|
|
1333
1438
|
return {};
|
|
1334
1439
|
}
|
|
1335
1440
|
}
|
|
1336
|
-
class
|
|
1441
|
+
class et extends oe {
|
|
1337
1442
|
/**
|
|
1338
1443
|
* Creates a new watch-only signer
|
|
1339
1444
|
*
|
|
@@ -1386,8 +1491,8 @@ class qe extends ne {
|
|
|
1386
1491
|
}
|
|
1387
1492
|
}
|
|
1388
1493
|
export {
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1494
|
+
Ye as WalletClient,
|
|
1495
|
+
Ze as WatchSigner,
|
|
1496
|
+
et as WebSigner
|
|
1392
1497
|
};
|
|
1393
1498
|
//# sourceMappingURL=index.esm.js.map
|