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