@naviprotocol/wallet-client 1.4.6 → 1.4.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 +507 -529
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { getFullnodeUrl as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as
|
|
5
|
-
import
|
|
6
|
-
import { normalizeStructTag as
|
|
7
|
-
import { Transaction as
|
|
8
|
-
import { buildSwapPTBFromQuote as
|
|
9
|
-
import { SuilendClient as
|
|
10
|
-
import { getCoinMetadataMap as
|
|
11
|
-
import { executeAuction as
|
|
12
|
-
import { Signer as
|
|
13
|
-
const
|
|
1
|
+
import { getFullnodeUrl as ct, SuiClient as ut } from "@mysten/sui/client";
|
|
2
|
+
import dt from "mitt";
|
|
3
|
+
import wt from "axios";
|
|
4
|
+
import { withSingleton as W, getCoins as X, mergeCoinsPTB as C, getPriceFeeds as L, updateOraclePricesPTB as Q, filterPriceFeeds as K, depositCoinPTB as O, getFlashLoanAsset as Y, flashloanPTB as Z, repayFlashLoanPTB as tt, borrowCoinPTB as et, withdrawCoinPTB as nt, repayCoinPTB as at, getPools as ht, getPool as P, getHealthFactor as ft, liquidatePTB as gt, getUserAvailableLendingRewards as G, getUserClaimedRewardHistory as pt, claimLendingRewardsPTB as mt, getLendingState as Ct, createAccountCapPTB as bt, withCache as st, parseTxValue as x } from "@naviprotocol/lending";
|
|
5
|
+
import E, { BigNumber as M } from "bignumber.js";
|
|
6
|
+
import { normalizeStructTag as m } from "@mysten/sui/utils";
|
|
7
|
+
import { Transaction as f } from "@mysten/sui/transactions";
|
|
8
|
+
import { buildSwapPTBFromQuote as $, generateRefId as yt, getQuote as Pt } from "@naviprotocol/astros-aggregator-sdk";
|
|
9
|
+
import { SuilendClient as z, LENDING_MARKET_ID as Bt, LENDING_MARKET_TYPE as H, parseReserve as Tt, parseObligation as vt } from "@suilend/sdk";
|
|
10
|
+
import { getCoinMetadataMap as Et, MAX_U64 as Rt } from "@suilend/sui-fe";
|
|
11
|
+
import { executeAuction as St } from "shio-sdk";
|
|
12
|
+
import { Signer as it } from "@mysten/sui/cryptography";
|
|
13
|
+
const ot = wt.create({
|
|
14
14
|
timeout: 2e4
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
function(
|
|
18
|
-
if (
|
|
19
|
-
throw new Error(
|
|
20
|
-
if (
|
|
21
|
-
throw new Error(
|
|
22
|
-
return
|
|
16
|
+
ot.interceptors.response.use(
|
|
17
|
+
function(o) {
|
|
18
|
+
if (o.data.err)
|
|
19
|
+
throw new Error(o.data.err);
|
|
20
|
+
if (o.data.error)
|
|
21
|
+
throw new Error(o.data.error.message);
|
|
22
|
+
return o;
|
|
23
23
|
},
|
|
24
|
-
function(
|
|
25
|
-
return Promise.reject(
|
|
24
|
+
function(o) {
|
|
25
|
+
return Promise.reject(o);
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
|
-
class
|
|
28
|
+
class Ot {
|
|
29
29
|
/**
|
|
30
30
|
* Creates a new custom transport instance
|
|
31
31
|
*
|
|
32
32
|
* @param rpcUrl - The RPC endpoint URL for the Sui node
|
|
33
33
|
*/
|
|
34
|
-
constructor(
|
|
35
|
-
this.requestId = 0, this.rpcUrl =
|
|
34
|
+
constructor(t) {
|
|
35
|
+
this.requestId = 0, this.rpcUrl = t;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Makes an RPC request to the Sui node
|
|
@@ -43,12 +43,12 @@ class ke {
|
|
|
43
43
|
* @param input - The transport request options containing method and parameters
|
|
44
44
|
* @returns Promise<T> - The response data from the RPC call
|
|
45
45
|
*/
|
|
46
|
-
async request(
|
|
47
|
-
return this.requestId += 1, (await
|
|
46
|
+
async request(t) {
|
|
47
|
+
return this.requestId += 1, (await ot.post(this.rpcUrl, {
|
|
48
48
|
jsonrpc: "2.0",
|
|
49
49
|
id: this.requestId,
|
|
50
|
-
method:
|
|
51
|
-
params:
|
|
50
|
+
method: t.method,
|
|
51
|
+
params: t.params
|
|
52
52
|
})).data.result;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
@@ -64,7 +64,7 @@ class ke {
|
|
|
64
64
|
throw new Error("subscribe not implemented.");
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
class
|
|
67
|
+
class A {
|
|
68
68
|
/**
|
|
69
69
|
* Gets the current configuration for this module
|
|
70
70
|
*
|
|
@@ -82,9 +82,8 @@ class x {
|
|
|
82
82
|
* @param event - The event name to emit
|
|
83
83
|
* @param data - The event data to emit
|
|
84
84
|
*/
|
|
85
|
-
emit(
|
|
86
|
-
|
|
87
|
-
(t = this.walletClient) == null || t.events.emit(e, a);
|
|
85
|
+
emit(t, e) {
|
|
86
|
+
this.walletClient?.events.emit(t, e);
|
|
88
87
|
}
|
|
89
88
|
/**
|
|
90
89
|
* Installs this module into a wallet client
|
|
@@ -94,8 +93,8 @@ class x {
|
|
|
94
93
|
*
|
|
95
94
|
* @param walletClient - The wallet client instance to install into
|
|
96
95
|
*/
|
|
97
|
-
install(
|
|
98
|
-
this.walletClient =
|
|
96
|
+
install(t) {
|
|
97
|
+
this.walletClient = t;
|
|
99
98
|
}
|
|
100
99
|
/**
|
|
101
100
|
* Uninstalls this module from the wallet client
|
|
@@ -107,26 +106,26 @@ class x {
|
|
|
107
106
|
this.walletClient = void 0;
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
|
-
class
|
|
109
|
+
class R {
|
|
111
110
|
/**
|
|
112
111
|
* Creates a new user portfolio
|
|
113
112
|
*
|
|
114
113
|
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
115
114
|
*/
|
|
116
|
-
constructor(
|
|
117
|
-
if (
|
|
118
|
-
this.balances = JSON.parse(JSON.stringify(
|
|
115
|
+
constructor(t) {
|
|
116
|
+
if (t instanceof R)
|
|
117
|
+
this.balances = JSON.parse(JSON.stringify(t.balances));
|
|
119
118
|
else {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
const s =
|
|
123
|
-
let
|
|
124
|
-
|
|
119
|
+
const e = {};
|
|
120
|
+
t?.forEach((n) => {
|
|
121
|
+
const s = m(n.coinType);
|
|
122
|
+
let a = e[s];
|
|
123
|
+
a || (a = {
|
|
125
124
|
coinType: s,
|
|
126
|
-
amount:
|
|
125
|
+
amount: M(0),
|
|
127
126
|
coins: []
|
|
128
|
-
},
|
|
129
|
-
}), this.balances =
|
|
127
|
+
}, e[s] = a), a.coins.push(n), a.amount = a.amount.plus(n.balance);
|
|
128
|
+
}), this.balances = e;
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
/**
|
|
@@ -135,8 +134,8 @@ class S {
|
|
|
135
134
|
* @param coinType - The coin type to query
|
|
136
135
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
137
136
|
*/
|
|
138
|
-
getBalance(
|
|
139
|
-
return
|
|
137
|
+
getBalance(t) {
|
|
138
|
+
return t = m(t), this.balances[t] || { coinType: t, amount: M(0), coins: [] };
|
|
140
139
|
}
|
|
141
140
|
/**
|
|
142
141
|
* Gets all coin types in the portfolio
|
|
@@ -144,7 +143,7 @@ class S {
|
|
|
144
143
|
* @returns Array of coin type strings
|
|
145
144
|
*/
|
|
146
145
|
getCoinTypes() {
|
|
147
|
-
return Object.values(this.balances).map((
|
|
146
|
+
return Object.values(this.balances).map((t) => t.coinType);
|
|
148
147
|
}
|
|
149
148
|
/**
|
|
150
149
|
* Gets the total balance amount for a specific coin type
|
|
@@ -152,10 +151,8 @@ class S {
|
|
|
152
151
|
* @param coinType - The coin type to query
|
|
153
152
|
* @returns BigNumber representing the total balance
|
|
154
153
|
*/
|
|
155
|
-
balanceOf(
|
|
156
|
-
|
|
157
|
-
const a = this.getBalance(e);
|
|
158
|
-
return (a == null ? void 0 : a.amount) || Q(0);
|
|
154
|
+
balanceOf(t) {
|
|
155
|
+
return t = m(t), this.getBalance(t)?.amount || M(0);
|
|
159
156
|
}
|
|
160
157
|
/**
|
|
161
158
|
* Creates a deep copy of the portfolio
|
|
@@ -166,22 +163,22 @@ class S {
|
|
|
166
163
|
* @returns New UserPortfolio instance with copied data
|
|
167
164
|
*/
|
|
168
165
|
clone() {
|
|
169
|
-
const
|
|
170
|
-
return
|
|
166
|
+
const t = JSON.parse(JSON.stringify(this.balances)), e = new R();
|
|
167
|
+
return e.balances = t, e;
|
|
171
168
|
}
|
|
172
169
|
}
|
|
173
|
-
class
|
|
170
|
+
class At extends A {
|
|
174
171
|
constructor() {
|
|
175
172
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
176
173
|
coinPollingInterval: 6e3,
|
|
177
174
|
disableCoinPolling: !1
|
|
178
|
-
}, this.updatePortfolio =
|
|
175
|
+
}, this.updatePortfolio = W(async () => {
|
|
179
176
|
if (!this.walletClient)
|
|
180
177
|
throw new Error("Wallet client not found");
|
|
181
|
-
this._coins = await
|
|
178
|
+
this._coins = await X(this.walletClient.address, {
|
|
182
179
|
client: this.walletClient.client
|
|
183
|
-
}), this._portfolio = new
|
|
184
|
-
}), this._coins = [], this._portfolio = new
|
|
180
|
+
}), this._portfolio = new R(this._coins), this.emit("balance:portfolio-updated", {});
|
|
181
|
+
}), this._coins = [], this._portfolio = new R(), this.pollingTimer = null, this._updatePromise = null;
|
|
185
182
|
}
|
|
186
183
|
/**
|
|
187
184
|
* Gets the current coin objects from the wallet
|
|
@@ -219,8 +216,8 @@ class Ne extends x {
|
|
|
219
216
|
* @param options - Optional parameters including dry run mode
|
|
220
217
|
* @returns Transaction response or dry run response
|
|
221
218
|
*/
|
|
222
|
-
async sendCoin(
|
|
223
|
-
return this.sendCoinBatch(
|
|
219
|
+
async sendCoin(t, e, n, s) {
|
|
220
|
+
return this.sendCoinBatch(t, [e], [n], s);
|
|
224
221
|
}
|
|
225
222
|
/**
|
|
226
223
|
* Sends coins to multiple recipients in a single transaction
|
|
@@ -231,27 +228,26 @@ class Ne extends x {
|
|
|
231
228
|
* @param options - Optional parameters including dry run mode
|
|
232
229
|
* @returns Transaction response or dry run response
|
|
233
230
|
*/
|
|
234
|
-
async sendCoinBatch(
|
|
235
|
-
var w;
|
|
231
|
+
async sendCoinBatch(t, e, n, s) {
|
|
236
232
|
if (!this.walletClient)
|
|
237
233
|
throw new Error("Wallet client not found");
|
|
238
|
-
if (
|
|
234
|
+
if (e.length !== n.length)
|
|
239
235
|
throw new Error("Recipients and amounts must have the same length");
|
|
240
236
|
await this.waitForUpdate();
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
237
|
+
const a = this.portfolio.getBalance(t), l = n.reduce((g, h) => g.plus(h), E(0));
|
|
238
|
+
if (a.amount.lt(l))
|
|
243
239
|
throw new Error("Insufficient balance");
|
|
244
|
-
const i = new
|
|
240
|
+
const i = new f();
|
|
245
241
|
let r = i.gas;
|
|
246
|
-
|
|
247
|
-
balance:
|
|
242
|
+
m(t) !== m("0x2::sui::SUI") && (r = C(i, a.coins, {
|
|
243
|
+
balance: l.toNumber()
|
|
248
244
|
}));
|
|
249
|
-
const
|
|
250
|
-
return
|
|
251
|
-
i.transferObjects([
|
|
245
|
+
const w = i.splitCoins(r, n);
|
|
246
|
+
return e.forEach((g, h) => {
|
|
247
|
+
i.transferObjects([w[h]], g);
|
|
252
248
|
}), await this.walletClient.signExecuteTransaction({
|
|
253
249
|
transaction: i,
|
|
254
|
-
dryRun:
|
|
250
|
+
dryRun: s?.dryRun ?? !1
|
|
255
251
|
});
|
|
256
252
|
}
|
|
257
253
|
/**
|
|
@@ -262,8 +258,8 @@ class Ne extends x {
|
|
|
262
258
|
* @param options - Optional parameters including dry run mode
|
|
263
259
|
* @returns Transaction response or dry run response
|
|
264
260
|
*/
|
|
265
|
-
async transferObject(
|
|
266
|
-
return this.transferObjectBatch([
|
|
261
|
+
async transferObject(t, e, n) {
|
|
262
|
+
return this.transferObjectBatch([t], [e], n);
|
|
267
263
|
}
|
|
268
264
|
/**
|
|
269
265
|
* Transfers multiple objects to their respective recipients in a single transaction
|
|
@@ -276,19 +272,18 @@ class Ne extends x {
|
|
|
276
272
|
* @param options - Optional parameters including dry run mode
|
|
277
273
|
* @returns Transaction response or dry run response
|
|
278
274
|
*/
|
|
279
|
-
async transferObjectBatch(
|
|
280
|
-
var u;
|
|
275
|
+
async transferObjectBatch(t, e, n) {
|
|
281
276
|
if (!this.walletClient)
|
|
282
277
|
throw new Error("Wallet client not found");
|
|
283
|
-
if (
|
|
278
|
+
if (t.length !== e.length)
|
|
284
279
|
throw new Error("Objects and recipients must have the same length");
|
|
285
280
|
await this.waitForUpdate();
|
|
286
|
-
const s = new
|
|
287
|
-
return
|
|
288
|
-
s.transferObjects([s.object(
|
|
281
|
+
const s = new f();
|
|
282
|
+
return t.forEach((l, i) => {
|
|
283
|
+
s.transferObjects([s.object(l)], e[i]);
|
|
289
284
|
}), await this.walletClient.signExecuteTransaction({
|
|
290
285
|
transaction: s,
|
|
291
|
-
dryRun:
|
|
286
|
+
dryRun: n?.dryRun ?? !1
|
|
292
287
|
});
|
|
293
288
|
}
|
|
294
289
|
/**
|
|
@@ -302,8 +297,8 @@ class Ne extends x {
|
|
|
302
297
|
if (this.config.disableCoinPolling)
|
|
303
298
|
return;
|
|
304
299
|
await this.updatePortfolio();
|
|
305
|
-
} catch (
|
|
306
|
-
console.error(
|
|
300
|
+
} catch (t) {
|
|
301
|
+
console.error(t);
|
|
307
302
|
} finally {
|
|
308
303
|
this.pollingTimer = setTimeout(this.startPolling, this.config.coinPollingInterval);
|
|
309
304
|
}
|
|
@@ -313,10 +308,10 @@ class Ne extends x {
|
|
|
313
308
|
*
|
|
314
309
|
* @param walletClient - The wallet client instance to install into
|
|
315
310
|
*/
|
|
316
|
-
install(
|
|
317
|
-
super.install(
|
|
318
|
-
|
|
319
|
-
|
|
311
|
+
install(t) {
|
|
312
|
+
super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((e) => {
|
|
313
|
+
t.events.on("balance:portfolio-updated", () => {
|
|
314
|
+
e();
|
|
320
315
|
});
|
|
321
316
|
});
|
|
322
317
|
}
|
|
@@ -329,282 +324,278 @@ class Ne extends x {
|
|
|
329
324
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
330
325
|
}
|
|
331
326
|
}
|
|
332
|
-
async function
|
|
333
|
-
var k, N, O;
|
|
327
|
+
async function D(o, t, e, n) {
|
|
334
328
|
if (!this.walletClient)
|
|
335
329
|
throw new Error("Wallet client not found");
|
|
336
|
-
const s = await this.getPool(
|
|
337
|
-
if (!
|
|
330
|
+
const s = await this.getPool(t), a = await this.getPool(e), l = await this.getLendingState(), i = this.walletClient.address, r = n?.protocol ?? "navi", w = await this.getProtocol(r);
|
|
331
|
+
if (!w)
|
|
338
332
|
throw new Error(`Protocol ${r} not found`);
|
|
339
|
-
const
|
|
333
|
+
const u = await w.getPool(s.coinType);
|
|
340
334
|
if (console.log("migrateBetweenSupplyPTB", {
|
|
341
|
-
fromPoolLending:
|
|
342
|
-
}), r === "navi" &&
|
|
335
|
+
fromPoolLending: u
|
|
336
|
+
}), r === "navi" && u.supplyBalance === 0)
|
|
343
337
|
throw new Error("No supply balance");
|
|
344
|
-
if (
|
|
338
|
+
if (n?.amount && n.amount > u.supplyBalance)
|
|
345
339
|
throw new Error("Amount is less than supply balance");
|
|
346
|
-
const
|
|
347
|
-
if (await
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
lendingState:
|
|
351
|
-
pools:
|
|
340
|
+
const g = n?.slippage ?? 5e-3, h = n?.amount ?? Number(u.supplyBalance), p = await L(), c = await Promise.all([s, a]);
|
|
341
|
+
if (await Q(
|
|
342
|
+
o,
|
|
343
|
+
K(p, {
|
|
344
|
+
lendingState: l,
|
|
345
|
+
pools: c
|
|
352
346
|
})
|
|
353
|
-
), r !== "navi" && s.id ===
|
|
354
|
-
const
|
|
355
|
-
|
|
347
|
+
), r !== "navi" && s.id === a.id) {
|
|
348
|
+
const U = await w.withdrawCoinPTB(
|
|
349
|
+
o,
|
|
356
350
|
s.suiCoinType,
|
|
357
351
|
h
|
|
358
352
|
);
|
|
359
|
-
return await
|
|
353
|
+
return await O(o, a, U, {
|
|
360
354
|
amount: h
|
|
361
|
-
}),
|
|
355
|
+
}), o;
|
|
362
356
|
}
|
|
363
|
-
const
|
|
357
|
+
const d = await Y(a, {
|
|
364
358
|
env: this.config.env
|
|
365
359
|
});
|
|
366
|
-
if (!
|
|
367
|
-
throw new Error(`${
|
|
368
|
-
const
|
|
360
|
+
if (!d)
|
|
361
|
+
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
362
|
+
const y = await this.walletClient.swap.getQuote(
|
|
369
363
|
s.suiCoinType,
|
|
370
|
-
|
|
364
|
+
a.suiCoinType,
|
|
371
365
|
h
|
|
372
|
-
),
|
|
373
|
-
if (
|
|
366
|
+
), B = Number(y.amount_out);
|
|
367
|
+
if (B <= 0)
|
|
374
368
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
375
|
-
const
|
|
376
|
-
if (
|
|
369
|
+
const S = Math.floor(B * (1 - g)), b = Math.floor(S / (1 + d.flashloanFee));
|
|
370
|
+
if (b <= 0)
|
|
377
371
|
throw new Error("The calculated borrow amount must be positive.");
|
|
378
|
-
const [
|
|
372
|
+
const [T, v] = await Z(o, a, b), [k] = o.moveCall({
|
|
379
373
|
target: "0x2::coin::from_balance",
|
|
380
|
-
arguments: [
|
|
381
|
-
typeArguments: [
|
|
374
|
+
arguments: [T],
|
|
375
|
+
typeArguments: [a.suiCoinType]
|
|
382
376
|
});
|
|
383
|
-
await
|
|
384
|
-
amount:
|
|
377
|
+
await O(o, a, k, {
|
|
378
|
+
amount: b
|
|
385
379
|
});
|
|
386
|
-
const
|
|
380
|
+
const N = await w.withdrawCoinPTB(o, s.suiCoinType, h), F = await $(
|
|
387
381
|
i,
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
),
|
|
382
|
+
o,
|
|
383
|
+
S,
|
|
384
|
+
N,
|
|
385
|
+
y
|
|
386
|
+
), _ = o.moveCall({
|
|
393
387
|
target: "0x2::coin::into_balance",
|
|
394
|
-
arguments: [
|
|
395
|
-
typeArguments: [
|
|
396
|
-
}), [
|
|
388
|
+
arguments: [F],
|
|
389
|
+
typeArguments: [a.suiCoinType]
|
|
390
|
+
}), [j] = await tt(o, a, v, _), [I] = o.moveCall({
|
|
397
391
|
target: "0x2::coin::from_balance",
|
|
398
|
-
arguments: [
|
|
399
|
-
typeArguments: [
|
|
392
|
+
arguments: [j],
|
|
393
|
+
typeArguments: [a.suiCoinType]
|
|
400
394
|
});
|
|
401
|
-
return await
|
|
395
|
+
return await O(o, a, I), o;
|
|
402
396
|
}
|
|
403
|
-
async function
|
|
404
|
-
var O, F, D;
|
|
397
|
+
async function J(o, t, e, n) {
|
|
405
398
|
if (!this.walletClient)
|
|
406
399
|
throw new Error("Wallet client not found");
|
|
407
|
-
const s = this.walletClient.address,
|
|
408
|
-
if (!
|
|
400
|
+
const s = this.walletClient.address, a = await this.getPool(t), l = await this.getPool(e), i = await this.getLendingState(), r = n?.protocol ?? "navi", w = await this.getProtocol(r);
|
|
401
|
+
if (!w)
|
|
409
402
|
throw new Error(`Protocol ${r} not found`);
|
|
410
|
-
const
|
|
403
|
+
const u = await w.getPool(a.coinType);
|
|
411
404
|
if (console.log("migrateBetweenBorrowPTB", {
|
|
412
|
-
fromPoolLending:
|
|
413
|
-
}),
|
|
405
|
+
fromPoolLending: u
|
|
406
|
+
}), u.borrowBalance === 0)
|
|
414
407
|
throw new Error("No borrow balance");
|
|
415
|
-
if (
|
|
408
|
+
if (n?.amount && n.amount > u.borrowBalance)
|
|
416
409
|
throw new Error("Amount is more than borrow balance");
|
|
417
|
-
const
|
|
418
|
-
await
|
|
419
|
-
|
|
420
|
-
|
|
410
|
+
const g = await L(), h = await Promise.all([a, l]);
|
|
411
|
+
await Q(
|
|
412
|
+
o,
|
|
413
|
+
K(g, {
|
|
421
414
|
lendingState: i,
|
|
422
415
|
pools: h
|
|
423
416
|
})
|
|
424
417
|
);
|
|
425
|
-
let
|
|
426
|
-
if (Number(
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
new
|
|
418
|
+
let p = n?.amount ?? Number(u.borrowBalance);
|
|
419
|
+
if (Number(u.borrowBalance) === p) {
|
|
420
|
+
const rt = u.borrowAPR / 100;
|
|
421
|
+
p = Math.ceil(
|
|
422
|
+
new E(p).multipliedBy(rt * (60 * 3) / (365 * 24 * 3600)).plus(new E(1).shiftedBy(-a.token.decimals)).plus(p).toNumber()
|
|
430
423
|
);
|
|
431
424
|
}
|
|
432
|
-
const
|
|
425
|
+
const c = await Y(a, {
|
|
433
426
|
env: this.config.env
|
|
434
427
|
});
|
|
435
|
-
if (!
|
|
436
|
-
throw new Error(`${
|
|
428
|
+
if (!c)
|
|
429
|
+
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
437
430
|
if (!this.walletClient)
|
|
438
431
|
throw new Error("Wallet client not found");
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
432
|
+
const d = n?.slippage ?? 5e-3, y = Math.ceil(p * (1 + c.flashloanFee)), B = y, S = await this.walletClient.swap.getQuote(
|
|
433
|
+
a.suiCoinType,
|
|
434
|
+
l.suiCoinType,
|
|
435
|
+
B
|
|
443
436
|
);
|
|
444
|
-
let
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
437
|
+
let b = 1 + d, T = Math.ceil(Number(S.amount_out) * b), v = await this.walletClient.swap.getQuote(
|
|
438
|
+
l.suiCoinType,
|
|
439
|
+
a.suiCoinType,
|
|
440
|
+
T
|
|
448
441
|
);
|
|
449
|
-
for (; Number(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
442
|
+
for (; Number(v.amount_out) < B; )
|
|
443
|
+
b = b * Math.max(B / Number(v.amount_out), 1.001), T = Math.ceil(Number(S.amount_out) * b), v = await this.walletClient.swap.getQuote(
|
|
444
|
+
l.suiCoinType,
|
|
445
|
+
a.suiCoinType,
|
|
446
|
+
T
|
|
454
447
|
);
|
|
455
|
-
const [
|
|
448
|
+
const [k, N] = await Z(o, a, p), [F] = o.moveCall({
|
|
456
449
|
target: "0x2::coin::from_balance",
|
|
457
|
-
arguments: [
|
|
458
|
-
typeArguments: [
|
|
450
|
+
arguments: [k],
|
|
451
|
+
typeArguments: [a.suiCoinType]
|
|
459
452
|
});
|
|
460
|
-
await
|
|
461
|
-
const
|
|
453
|
+
await w.repayCoinPTB(o, a.suiCoinType, F, p);
|
|
454
|
+
const _ = await et(o, l, T), j = await $(
|
|
462
455
|
s,
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
),
|
|
456
|
+
o,
|
|
457
|
+
y,
|
|
458
|
+
_,
|
|
459
|
+
v
|
|
460
|
+
), I = o.moveCall({
|
|
468
461
|
target: "0x2::coin::into_balance",
|
|
469
|
-
arguments: [
|
|
470
|
-
typeArguments: [
|
|
471
|
-
}), [
|
|
462
|
+
arguments: [j],
|
|
463
|
+
typeArguments: [a.suiCoinType]
|
|
464
|
+
}), [U] = await tt(o, a, N, I), [lt] = o.moveCall({
|
|
472
465
|
target: "0x2::coin::from_balance",
|
|
473
|
-
arguments: [
|
|
474
|
-
typeArguments: [
|
|
466
|
+
arguments: [U],
|
|
467
|
+
typeArguments: [a.suiCoinType]
|
|
475
468
|
});
|
|
476
|
-
return
|
|
469
|
+
return o.transferObjects([lt], s), o;
|
|
477
470
|
}
|
|
478
|
-
async function
|
|
479
|
-
var w, h;
|
|
471
|
+
async function V(o, t, e, n) {
|
|
480
472
|
if (!this.walletClient)
|
|
481
473
|
throw new Error("Wallet client not found");
|
|
482
|
-
const s = await
|
|
474
|
+
const s = await X(this.walletClient.address, {
|
|
483
475
|
client: this.walletClient.client,
|
|
484
|
-
coinType:
|
|
485
|
-
}),
|
|
476
|
+
coinType: t
|
|
477
|
+
}), a = await this.getPool(e), i = new R(s).getBalance(t);
|
|
486
478
|
if (i.amount.eq(0))
|
|
487
|
-
throw new Error(`No balance of ${
|
|
479
|
+
throw new Error(`No balance of ${t}`);
|
|
488
480
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
489
481
|
balance: i.amount.toNumber()
|
|
490
|
-
}),
|
|
482
|
+
}), n?.amount && i.amount.lt(n.amount))
|
|
491
483
|
throw new Error("Amount is greater than balance");
|
|
492
|
-
const r =
|
|
493
|
-
let
|
|
484
|
+
const r = n?.amount ?? i.amount.toNumber(), w = n?.slippage ?? 5e-3;
|
|
485
|
+
let u = await C(o, i.coins, {
|
|
494
486
|
balance: r,
|
|
495
487
|
useGasCoin: !0
|
|
496
488
|
});
|
|
497
|
-
if (
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
l,
|
|
501
|
-
f,
|
|
489
|
+
if (m(t) !== m(a.suiCoinType)) {
|
|
490
|
+
const g = await this.walletClient.swap.getQuote(t, a.suiCoinType, r);
|
|
491
|
+
u = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
502
492
|
o,
|
|
503
|
-
|
|
493
|
+
g,
|
|
494
|
+
u,
|
|
495
|
+
w
|
|
504
496
|
);
|
|
505
497
|
}
|
|
506
|
-
return await
|
|
498
|
+
return await O(o, a, u), o;
|
|
507
499
|
}
|
|
508
|
-
class
|
|
509
|
-
constructor(
|
|
510
|
-
this.name = "navi", this.walletClient =
|
|
511
|
-
}
|
|
512
|
-
async getPool(
|
|
513
|
-
const
|
|
514
|
-
(i) => i.pool.suiCoinType ===
|
|
515
|
-
),
|
|
500
|
+
class xt {
|
|
501
|
+
constructor(t) {
|
|
502
|
+
this.name = "navi", this.walletClient = t;
|
|
503
|
+
}
|
|
504
|
+
async getPool(t) {
|
|
505
|
+
const e = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
|
|
506
|
+
(i) => i.pool.suiCoinType === m(t)
|
|
507
|
+
), a = s ? new E(s.supplyBalance).toNumber() : 0, l = s ? new E(s.borrowBalance).toNumber() : 0;
|
|
516
508
|
return {
|
|
517
|
-
supplyBalance:
|
|
518
|
-
borrowBalance:
|
|
519
|
-
borrowAPR: parseFloat(
|
|
509
|
+
supplyBalance: a,
|
|
510
|
+
borrowBalance: l,
|
|
511
|
+
borrowAPR: parseFloat(e.borrowIncentiveApyInfo.apy)
|
|
520
512
|
};
|
|
521
513
|
}
|
|
522
|
-
async depositCoinPTB(
|
|
514
|
+
async depositCoinPTB(t, e, n, s) {
|
|
523
515
|
throw new Error("Not implemented");
|
|
524
516
|
}
|
|
525
|
-
async withdrawCoinPTB(
|
|
526
|
-
return
|
|
517
|
+
async withdrawCoinPTB(t, e, n) {
|
|
518
|
+
return nt(t, e, n);
|
|
527
519
|
}
|
|
528
|
-
async borrowCoinPTB(
|
|
520
|
+
async borrowCoinPTB(t, e, n) {
|
|
529
521
|
throw new Error("Not implemented");
|
|
530
522
|
}
|
|
531
|
-
async repayCoinPTB(
|
|
532
|
-
|
|
523
|
+
async repayCoinPTB(t, e, n, s) {
|
|
524
|
+
at(t, e, n, { amount: s });
|
|
533
525
|
}
|
|
534
526
|
}
|
|
535
|
-
class
|
|
536
|
-
constructor(
|
|
537
|
-
this.name = "suilend", this.walletClient =
|
|
538
|
-
}
|
|
539
|
-
static async create(
|
|
540
|
-
const [
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
[
|
|
545
|
-
|
|
527
|
+
class q {
|
|
528
|
+
constructor(t, e, n) {
|
|
529
|
+
this.name = "suilend", this.walletClient = t, this.obligationOwnerCap = e, this.suilendClient = n;
|
|
530
|
+
}
|
|
531
|
+
static async create(t) {
|
|
532
|
+
const [e, n] = await Promise.all([
|
|
533
|
+
z.initialize(Bt, H, t.client),
|
|
534
|
+
z.getObligationOwnerCaps(
|
|
535
|
+
t.address,
|
|
536
|
+
[H],
|
|
537
|
+
t.client
|
|
546
538
|
)
|
|
547
539
|
]);
|
|
548
|
-
if (
|
|
549
|
-
throw new Error("No existing obligations found for wallet address: " +
|
|
550
|
-
return new
|
|
551
|
-
}
|
|
552
|
-
async getPool(
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
g && s.add(p(g.coinType.name));
|
|
540
|
+
if (n.length === 0)
|
|
541
|
+
throw new Error("No existing obligations found for wallet address: " + t.address);
|
|
542
|
+
return new q(t, n[0], e);
|
|
543
|
+
}
|
|
544
|
+
async getPool(t) {
|
|
545
|
+
const e = m(t), n = this.suilendClient.lendingMarket.reserves, s = /* @__PURE__ */ new Set();
|
|
546
|
+
n.forEach((c) => {
|
|
547
|
+
s.add(m(c.coinType.name)), c.depositsPoolRewardManager.poolRewards.forEach((d) => {
|
|
548
|
+
d && s.add(m(d.coinType.name));
|
|
549
|
+
}), c.borrowsPoolRewardManager.poolRewards.forEach((d) => {
|
|
550
|
+
d && s.add(m(d.coinType.name));
|
|
560
551
|
});
|
|
561
552
|
});
|
|
562
|
-
const
|
|
563
|
-
(
|
|
553
|
+
const a = await Et(Array.from(s)), i = n.map((c) => Tt(c, a)).reduce(
|
|
554
|
+
(c, d) => (c[d.coinType] = d, c),
|
|
564
555
|
{}
|
|
565
556
|
), r = await this.suilendClient.getObligation(
|
|
566
557
|
this.obligationOwnerCap.obligationId
|
|
567
|
-
),
|
|
558
|
+
), w = vt(r, i), u = w.deposits.find((c) => c.coinType === e), g = w.borrows.find((c) => c.coinType === e), h = a[e].decimals;
|
|
568
559
|
return {
|
|
569
|
-
cTokenExchangeRate: i[
|
|
570
|
-
supplyBalance:
|
|
571
|
-
borrowBalance:
|
|
572
|
-
borrowAPR: i[
|
|
560
|
+
cTokenExchangeRate: i[e].cTokenExchangeRate.toNumber(),
|
|
561
|
+
supplyBalance: u?.depositedAmount.shiftedBy(h).decimalPlaces(0).toNumber() ?? 0,
|
|
562
|
+
borrowBalance: g?.borrowedAmount.shiftedBy(h).decimalPlaces(0).toNumber() ?? 0,
|
|
563
|
+
borrowAPR: i[e].borrowAprPercent.toNumber()
|
|
573
564
|
};
|
|
574
565
|
}
|
|
575
|
-
async depositCoinPTB(
|
|
566
|
+
async depositCoinPTB(t, e, n, s) {
|
|
576
567
|
throw new Error("Not implemented");
|
|
577
568
|
}
|
|
578
|
-
async withdrawCoinPTB(
|
|
579
|
-
const s = await this.getPool(
|
|
569
|
+
async withdrawCoinPTB(t, e, n) {
|
|
570
|
+
const s = await this.getPool(e), a = n === s.supplyBalance;
|
|
580
571
|
return await this.suilendClient.withdraw(
|
|
581
572
|
this.obligationOwnerCap.id,
|
|
582
573
|
this.obligationOwnerCap.obligationId,
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
574
|
+
e,
|
|
575
|
+
a ? Rt.toString() : Math.ceil(n / s.cTokenExchangeRate).toString(),
|
|
576
|
+
t
|
|
586
577
|
);
|
|
587
578
|
}
|
|
588
|
-
async borrowCoinPTB(
|
|
579
|
+
async borrowCoinPTB(t, e, n) {
|
|
589
580
|
throw new Error("Not implemented");
|
|
590
581
|
}
|
|
591
|
-
async repayCoinPTB(
|
|
592
|
-
this.suilendClient.repay(this.obligationOwnerCap.obligationId,
|
|
582
|
+
async repayCoinPTB(t, e, n, s) {
|
|
583
|
+
this.suilendClient.repay(this.obligationOwnerCap.obligationId, e, n, t), t.transferObjects([n], t.pure.address(this.walletClient.address));
|
|
593
584
|
}
|
|
594
585
|
}
|
|
595
|
-
class
|
|
586
|
+
class kt extends A {
|
|
596
587
|
constructor() {
|
|
597
588
|
super(), this.name = "lending", this.defaultConfig = {
|
|
598
589
|
env: "prod",
|
|
599
590
|
protocols: []
|
|
600
|
-
}, this._protocols = [], this.migrateBetweenSupplyPTB =
|
|
591
|
+
}, this._protocols = [], this.migrateBetweenSupplyPTB = D, this.migrateBetweenBorrowPTB = J, this.migrateBalanceToSupplyPTB = V, this.migrateBetweenSupplyPTB = D.bind(this), this.migrateBetweenBorrowPTB = J.bind(this), this.migrateBalanceToSupplyPTB = V.bind(this);
|
|
601
592
|
}
|
|
602
593
|
/** Get protocols (either from internal storage or config) */
|
|
603
594
|
get protocols() {
|
|
604
595
|
return this._protocols.length > 0 ? this._protocols : this.config.protocols;
|
|
605
596
|
}
|
|
606
|
-
async getProtocol(
|
|
607
|
-
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((
|
|
597
|
+
async getProtocol(t) {
|
|
598
|
+
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((e) => e.name === t);
|
|
608
599
|
}
|
|
609
600
|
/**
|
|
610
601
|
* Gets all available lending pools
|
|
@@ -612,10 +603,10 @@ class _e extends x {
|
|
|
612
603
|
* @param options - Optional caching options
|
|
613
604
|
* @returns Array of pool information
|
|
614
605
|
*/
|
|
615
|
-
async getPools(
|
|
616
|
-
return await
|
|
606
|
+
async getPools(t) {
|
|
607
|
+
return await ht({
|
|
617
608
|
env: this.config.env,
|
|
618
|
-
...
|
|
609
|
+
...t
|
|
619
610
|
});
|
|
620
611
|
}
|
|
621
612
|
/**
|
|
@@ -625,10 +616,10 @@ class _e extends x {
|
|
|
625
616
|
* @param options - Optional caching options
|
|
626
617
|
* @returns Pool information
|
|
627
618
|
*/
|
|
628
|
-
async getPool(
|
|
629
|
-
return await
|
|
619
|
+
async getPool(t, e) {
|
|
620
|
+
return await P(t, {
|
|
630
621
|
env: this.config.env,
|
|
631
|
-
...
|
|
622
|
+
...e
|
|
632
623
|
});
|
|
633
624
|
}
|
|
634
625
|
/**
|
|
@@ -639,30 +630,29 @@ class _e extends x {
|
|
|
639
630
|
* @param options - Optional parameters including dry run mode and account capability
|
|
640
631
|
* @returns Transaction response or dry run response
|
|
641
632
|
*/
|
|
642
|
-
async deposit(
|
|
643
|
-
var c, o, w;
|
|
633
|
+
async deposit(t, e, n) {
|
|
644
634
|
if (!this.walletClient)
|
|
645
635
|
throw new Error("Wallet client not found");
|
|
646
|
-
const s = await
|
|
636
|
+
const s = await P(t, {
|
|
647
637
|
env: this.config.env
|
|
648
638
|
});
|
|
649
639
|
await this.walletClient.module("balance").waitForUpdate();
|
|
650
|
-
const
|
|
651
|
-
balance:
|
|
640
|
+
const a = new f(), l = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = C(a, l.coins, {
|
|
641
|
+
balance: e,
|
|
652
642
|
useGasCoin: !0
|
|
653
643
|
});
|
|
654
|
-
await
|
|
644
|
+
await O(a, s, i, {
|
|
655
645
|
env: this.config.env,
|
|
656
|
-
amount:
|
|
657
|
-
accountCap:
|
|
646
|
+
amount: e,
|
|
647
|
+
accountCap: n?.accountCap
|
|
658
648
|
});
|
|
659
649
|
const r = await this.walletClient.signExecuteTransaction({
|
|
660
|
-
transaction:
|
|
661
|
-
dryRun:
|
|
650
|
+
transaction: a,
|
|
651
|
+
dryRun: n?.dryRun ?? !1
|
|
662
652
|
});
|
|
663
|
-
return !
|
|
664
|
-
identifier:
|
|
665
|
-
amount:
|
|
653
|
+
return !n?.dryRun && r.effects?.status?.status === "success" && (this.emit("lending:deposit-success", {
|
|
654
|
+
identifier: t,
|
|
655
|
+
amount: e
|
|
666
656
|
}), this.walletClient.module("balance").updatePortfolio()), r;
|
|
667
657
|
}
|
|
668
658
|
/**
|
|
@@ -673,26 +663,25 @@ class _e extends x {
|
|
|
673
663
|
* @param options - Optional parameters including dry run mode and account capability
|
|
674
664
|
* @returns Transaction response or dry run response
|
|
675
665
|
*/
|
|
676
|
-
async withdraw(
|
|
677
|
-
var r, c, o;
|
|
666
|
+
async withdraw(t, e, n) {
|
|
678
667
|
if (!this.walletClient)
|
|
679
668
|
throw new Error("Wallet client not found");
|
|
680
|
-
const s = await
|
|
669
|
+
const s = await P(t, {
|
|
681
670
|
env: this.config.env
|
|
682
|
-
}),
|
|
683
|
-
|
|
684
|
-
const
|
|
671
|
+
}), a = new f();
|
|
672
|
+
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
673
|
+
const l = await nt(a, s, e, {
|
|
685
674
|
env: this.config.env,
|
|
686
|
-
accountCap:
|
|
675
|
+
accountCap: n?.accountCap
|
|
687
676
|
});
|
|
688
|
-
|
|
677
|
+
a.transferObjects([l], this.walletClient.address);
|
|
689
678
|
const i = await this.walletClient.signExecuteTransaction({
|
|
690
|
-
transaction:
|
|
691
|
-
dryRun:
|
|
679
|
+
transaction: a,
|
|
680
|
+
dryRun: n?.dryRun ?? !1
|
|
692
681
|
});
|
|
693
|
-
return !
|
|
694
|
-
identifier:
|
|
695
|
-
amount:
|
|
682
|
+
return !n?.dryRun && i.effects?.status?.status === "success" && (this.emit("lending:withdraw-success", {
|
|
683
|
+
identifier: t,
|
|
684
|
+
amount: e
|
|
696
685
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
697
686
|
}
|
|
698
687
|
/**
|
|
@@ -703,26 +692,25 @@ class _e extends x {
|
|
|
703
692
|
* @param options - Optional parameters including dry run mode and account capability
|
|
704
693
|
* @returns Transaction response or dry run response
|
|
705
694
|
*/
|
|
706
|
-
async borrow(
|
|
707
|
-
var r, c, o;
|
|
695
|
+
async borrow(t, e, n) {
|
|
708
696
|
if (!this.walletClient)
|
|
709
697
|
throw new Error("Wallet client not found");
|
|
710
|
-
const s = await
|
|
698
|
+
const s = await P(t, {
|
|
711
699
|
env: this.config.env
|
|
712
|
-
}),
|
|
713
|
-
|
|
714
|
-
const
|
|
700
|
+
}), a = new f();
|
|
701
|
+
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
702
|
+
const l = await et(a, s, e, {
|
|
715
703
|
env: this.config.env,
|
|
716
|
-
accountCap:
|
|
704
|
+
accountCap: n?.accountCap
|
|
717
705
|
});
|
|
718
|
-
|
|
706
|
+
a.transferObjects([l], this.walletClient.address);
|
|
719
707
|
const i = await this.walletClient.signExecuteTransaction({
|
|
720
|
-
transaction:
|
|
721
|
-
dryRun:
|
|
708
|
+
transaction: a,
|
|
709
|
+
dryRun: n?.dryRun ?? !1
|
|
722
710
|
});
|
|
723
|
-
return !
|
|
724
|
-
identifier:
|
|
725
|
-
amount:
|
|
711
|
+
return !n?.dryRun && i.effects?.status?.status === "success" && (this.emit("lending:borrow-success", {
|
|
712
|
+
identifier: t,
|
|
713
|
+
amount: e
|
|
726
714
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
727
715
|
}
|
|
728
716
|
/**
|
|
@@ -733,29 +721,28 @@ class _e extends x {
|
|
|
733
721
|
* @param options - Optional parameters including dry run mode and account capability
|
|
734
722
|
* @returns Transaction response or dry run response
|
|
735
723
|
*/
|
|
736
|
-
async repay(
|
|
737
|
-
var c, o, w;
|
|
724
|
+
async repay(t, e, n) {
|
|
738
725
|
if (!this.walletClient)
|
|
739
726
|
throw new Error("Wallet client not found");
|
|
740
727
|
await this.walletClient.module("balance").waitForUpdate();
|
|
741
|
-
const s = await
|
|
728
|
+
const s = await P(t, {
|
|
742
729
|
env: this.config.env
|
|
743
|
-
}),
|
|
744
|
-
balance:
|
|
730
|
+
}), a = new f(), l = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), i = C(a, l.coins, {
|
|
731
|
+
balance: e,
|
|
745
732
|
useGasCoin: !0
|
|
746
733
|
});
|
|
747
|
-
await
|
|
734
|
+
await at(a, s, i, {
|
|
748
735
|
env: this.config.env,
|
|
749
|
-
amount:
|
|
750
|
-
accountCap:
|
|
736
|
+
amount: e,
|
|
737
|
+
accountCap: n?.accountCap
|
|
751
738
|
});
|
|
752
739
|
const r = await this.walletClient.signExecuteTransaction({
|
|
753
|
-
transaction:
|
|
754
|
-
dryRun:
|
|
740
|
+
transaction: a,
|
|
741
|
+
dryRun: n?.dryRun ?? !1
|
|
755
742
|
});
|
|
756
|
-
return !
|
|
757
|
-
identifier:
|
|
758
|
-
amount:
|
|
743
|
+
return !n?.dryRun && r.effects?.status?.status === "success" && (this.emit("lending:repay-success", {
|
|
744
|
+
identifier: t,
|
|
745
|
+
amount: e
|
|
759
746
|
}), this.walletClient.module("balance").updatePortfolio()), r;
|
|
760
747
|
}
|
|
761
748
|
/**
|
|
@@ -766,8 +753,8 @@ class _e extends x {
|
|
|
766
753
|
async getHealthFactor() {
|
|
767
754
|
if (!this.walletClient)
|
|
768
755
|
throw new Error("Wallet client not found");
|
|
769
|
-
const
|
|
770
|
-
return await
|
|
756
|
+
const t = this.walletClient.address;
|
|
757
|
+
return await ft(t, {
|
|
771
758
|
env: this.config.env,
|
|
772
759
|
client: this.walletClient.client
|
|
773
760
|
});
|
|
@@ -782,46 +769,45 @@ class _e extends x {
|
|
|
782
769
|
* @param options - Optional parameters including dry run mode
|
|
783
770
|
* @returns Transaction response or dry run response
|
|
784
771
|
*/
|
|
785
|
-
async liquidate(
|
|
786
|
-
var d, g, C;
|
|
772
|
+
async liquidate(t, e, n, s, a) {
|
|
787
773
|
if (!this.walletClient)
|
|
788
774
|
throw new Error("Wallet client not found");
|
|
789
|
-
const
|
|
775
|
+
const l = await P(t, {
|
|
790
776
|
env: this.config.env
|
|
791
|
-
}), i = await
|
|
777
|
+
}), i = await P(n, {
|
|
792
778
|
env: this.config.env
|
|
793
|
-
}), r = new
|
|
794
|
-
balance:
|
|
779
|
+
}), r = new f(), w = this.walletClient.module("balance").portfolio.getBalance(l.suiCoinType), u = C(r, w.coins, {
|
|
780
|
+
balance: e,
|
|
795
781
|
useGasCoin: !0
|
|
796
|
-
}), [
|
|
782
|
+
}), [g, h] = await gt(
|
|
797
783
|
r,
|
|
784
|
+
l,
|
|
798
785
|
u,
|
|
799
|
-
o,
|
|
800
786
|
i,
|
|
801
787
|
s,
|
|
802
788
|
{
|
|
803
789
|
env: this.config.env
|
|
804
790
|
}
|
|
805
|
-
), [
|
|
791
|
+
), [p] = r.moveCall({
|
|
806
792
|
target: "0x2::coin::from_balance",
|
|
807
|
-
arguments: [
|
|
793
|
+
arguments: [g],
|
|
808
794
|
typeArguments: [i.suiCoinType]
|
|
809
|
-
}), [
|
|
795
|
+
}), [c] = r.moveCall({
|
|
810
796
|
target: "0x2::coin::from_balance",
|
|
811
797
|
arguments: [h],
|
|
812
|
-
typeArguments: [
|
|
798
|
+
typeArguments: [l.suiCoinType]
|
|
813
799
|
});
|
|
814
|
-
r.transferObjects([
|
|
815
|
-
const
|
|
800
|
+
r.transferObjects([p, c], this.walletClient.address);
|
|
801
|
+
const d = await this.walletClient.signExecuteTransaction({
|
|
816
802
|
transaction: r,
|
|
817
|
-
dryRun:
|
|
803
|
+
dryRun: a?.dryRun ?? !1
|
|
818
804
|
});
|
|
819
|
-
return !
|
|
820
|
-
payIdentifier:
|
|
821
|
-
payAmount:
|
|
822
|
-
collateralIdentifier:
|
|
805
|
+
return !a?.dryRun && d.effects?.status?.status === "success" && (this.emit("lending:liquidate-success", {
|
|
806
|
+
payIdentifier: t,
|
|
807
|
+
payAmount: e,
|
|
808
|
+
collateralIdentifier: n,
|
|
823
809
|
liquidationAddress: s
|
|
824
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
810
|
+
}), this.walletClient.module("balance").updatePortfolio()), d;
|
|
825
811
|
}
|
|
826
812
|
/**
|
|
827
813
|
* Gets the available lending rewards for the current user.
|
|
@@ -830,11 +816,11 @@ class _e extends x {
|
|
|
830
816
|
* @returns The available lending rewards for the user.
|
|
831
817
|
* @throws If the wallet client is not found.
|
|
832
818
|
*/
|
|
833
|
-
async getAvailableRewards(
|
|
819
|
+
async getAvailableRewards(t) {
|
|
834
820
|
if (!this.walletClient)
|
|
835
821
|
throw new Error("Wallet client not found");
|
|
836
|
-
return
|
|
837
|
-
...
|
|
822
|
+
return G(this.walletClient.address, {
|
|
823
|
+
...t,
|
|
838
824
|
env: this.config.env
|
|
839
825
|
});
|
|
840
826
|
}
|
|
@@ -845,11 +831,11 @@ class _e extends x {
|
|
|
845
831
|
* @returns The claimed reward history for the user.
|
|
846
832
|
* @throws If the wallet client is not found.
|
|
847
833
|
*/
|
|
848
|
-
async getClaimedRewardHistory(
|
|
834
|
+
async getClaimedRewardHistory(t) {
|
|
849
835
|
if (!this.walletClient)
|
|
850
836
|
throw new Error("Wallet client not found");
|
|
851
|
-
return
|
|
852
|
-
...
|
|
837
|
+
return pt(this.walletClient.address, {
|
|
838
|
+
...t
|
|
853
839
|
});
|
|
854
840
|
}
|
|
855
841
|
/**
|
|
@@ -858,35 +844,34 @@ class _e extends x {
|
|
|
858
844
|
* @param options - Optional parameters including dry run mode and account capability
|
|
859
845
|
* @returns Transaction response or dry run response
|
|
860
846
|
*/
|
|
861
|
-
async claimAllRewards(
|
|
862
|
-
var n, u, i;
|
|
847
|
+
async claimAllRewards(t) {
|
|
863
848
|
if (!this.walletClient)
|
|
864
849
|
throw new Error("Wallet client not found");
|
|
865
|
-
const
|
|
850
|
+
const e = new f(), n = await G(this.walletClient.address, {
|
|
866
851
|
env: this.config.env
|
|
867
852
|
});
|
|
868
|
-
await
|
|
853
|
+
await mt(e, n, {
|
|
869
854
|
env: this.config.env,
|
|
870
|
-
accountCap:
|
|
855
|
+
accountCap: t?.accountCap
|
|
871
856
|
});
|
|
872
857
|
const s = await this.walletClient.signExecuteTransaction({
|
|
873
|
-
transaction:
|
|
874
|
-
dryRun:
|
|
858
|
+
transaction: e,
|
|
859
|
+
dryRun: t?.dryRun ?? !1
|
|
875
860
|
});
|
|
876
|
-
return !
|
|
877
|
-
rewards:
|
|
861
|
+
return !t?.dryRun && s.effects?.status?.status === "success" && (this.emit("lending:claim-rewards-success", {
|
|
862
|
+
rewards: n
|
|
878
863
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
879
864
|
}
|
|
880
|
-
async updateOraclePTB(
|
|
881
|
-
const
|
|
865
|
+
async updateOraclePTB(t, e) {
|
|
866
|
+
const n = await L({
|
|
882
867
|
env: this.config.env
|
|
883
868
|
}), s = await this.getLendingState({
|
|
884
869
|
cacheTime: 60 * 1e3
|
|
885
|
-
}),
|
|
870
|
+
}), a = K(n, {
|
|
886
871
|
lendingState: s,
|
|
887
|
-
pools:
|
|
872
|
+
pools: e
|
|
888
873
|
});
|
|
889
|
-
await
|
|
874
|
+
await Q(t, a, {
|
|
890
875
|
env: this.config.env,
|
|
891
876
|
updatePythPriceFeeds: !0
|
|
892
877
|
});
|
|
@@ -898,14 +883,13 @@ class _e extends x {
|
|
|
898
883
|
* @param options.dryRun - Whether to perform a dry run
|
|
899
884
|
* @returns Transaction response or dry run response
|
|
900
885
|
*/
|
|
901
|
-
async updateOracle(
|
|
902
|
-
var s;
|
|
886
|
+
async updateOracle(t) {
|
|
903
887
|
if (!this.walletClient)
|
|
904
888
|
throw new Error("Wallet client not found");
|
|
905
|
-
const
|
|
906
|
-
return await this.updateOraclePTB(
|
|
907
|
-
transaction:
|
|
908
|
-
dryRun:
|
|
889
|
+
const e = new f();
|
|
890
|
+
return await this.updateOraclePTB(e, t?.pools), await this.walletClient.signExecuteTransaction({
|
|
891
|
+
transaction: e,
|
|
892
|
+
dryRun: t?.dryRun ?? !1
|
|
909
893
|
});
|
|
910
894
|
}
|
|
911
895
|
/**
|
|
@@ -914,12 +898,12 @@ class _e extends x {
|
|
|
914
898
|
* @param options - Optional caching options
|
|
915
899
|
* @returns User's lending state information
|
|
916
900
|
*/
|
|
917
|
-
async getLendingState(
|
|
901
|
+
async getLendingState(t) {
|
|
918
902
|
if (!this.walletClient)
|
|
919
903
|
throw new Error("Wallet client not found");
|
|
920
|
-
return await
|
|
904
|
+
return await Ct(this.walletClient.address, {
|
|
921
905
|
env: this.config.env,
|
|
922
|
-
...
|
|
906
|
+
...t,
|
|
923
907
|
client: this.walletClient.client
|
|
924
908
|
});
|
|
925
909
|
}
|
|
@@ -929,14 +913,13 @@ class _e extends x {
|
|
|
929
913
|
* @param options - Optional parameters including dry run mode
|
|
930
914
|
* @returns Transaction response or dry run response
|
|
931
915
|
*/
|
|
932
|
-
async createAccountCap(
|
|
933
|
-
var n;
|
|
916
|
+
async createAccountCap(t) {
|
|
934
917
|
if (!this.walletClient)
|
|
935
918
|
throw new Error("Wallet client not found");
|
|
936
|
-
const
|
|
937
|
-
return
|
|
938
|
-
transaction:
|
|
939
|
-
dryRun:
|
|
919
|
+
const e = new f(), n = await bt(e);
|
|
920
|
+
return e.transferObjects([n], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
921
|
+
transaction: e,
|
|
922
|
+
dryRun: t?.dryRun ?? !1
|
|
940
923
|
});
|
|
941
924
|
}
|
|
942
925
|
async initializeProtocols() {
|
|
@@ -944,25 +927,25 @@ class _e extends x {
|
|
|
944
927
|
console.warn("Wallet client not available during protocol initialization");
|
|
945
928
|
return;
|
|
946
929
|
}
|
|
947
|
-
const
|
|
948
|
-
|
|
930
|
+
const t = [];
|
|
931
|
+
t.push(new xt(this.walletClient));
|
|
949
932
|
try {
|
|
950
|
-
|
|
951
|
-
} catch (
|
|
952
|
-
console.warn("Failed to initialize SuilendProtocol:",
|
|
933
|
+
t.push(await q.create(this.walletClient));
|
|
934
|
+
} catch (e) {
|
|
935
|
+
console.warn("Failed to initialize SuilendProtocol:", e);
|
|
953
936
|
}
|
|
954
|
-
this._protocols =
|
|
937
|
+
this._protocols = t;
|
|
955
938
|
}
|
|
956
939
|
}
|
|
957
|
-
class
|
|
940
|
+
class Nt extends A {
|
|
958
941
|
constructor() {
|
|
959
942
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
960
943
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
961
944
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
962
945
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
963
946
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
964
|
-
}, this.getStats =
|
|
965
|
-
|
|
947
|
+
}, this.getStats = st(
|
|
948
|
+
W(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((e) => e.json())).data)
|
|
966
949
|
);
|
|
967
950
|
}
|
|
968
951
|
/**
|
|
@@ -972,18 +955,18 @@ class je extends x {
|
|
|
972
955
|
* @param suiCoin - The SUI coin object to stake
|
|
973
956
|
* @returns The vSUI coin object received from staking
|
|
974
957
|
*/
|
|
975
|
-
async stakePTB(
|
|
976
|
-
const [
|
|
958
|
+
async stakePTB(t, e) {
|
|
959
|
+
const [n] = t.moveCall({
|
|
977
960
|
target: `${this.config.packageId}::stake_pool::stake`,
|
|
978
961
|
arguments: [
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
962
|
+
t.object(this.config.poolId),
|
|
963
|
+
t.object(this.config.metadataId),
|
|
964
|
+
t.object("0x05"),
|
|
965
|
+
x(e, t.object)
|
|
983
966
|
],
|
|
984
967
|
typeArguments: []
|
|
985
968
|
});
|
|
986
|
-
return
|
|
969
|
+
return n;
|
|
987
970
|
}
|
|
988
971
|
/**
|
|
989
972
|
* Adds unstaking operation to a transaction black
|
|
@@ -992,18 +975,18 @@ class je extends x {
|
|
|
992
975
|
* @param vSuiCoin - The vSUI coin object to unstake
|
|
993
976
|
* @returns The SUI coin object received from unstaking
|
|
994
977
|
*/
|
|
995
|
-
async unstakePTB(
|
|
996
|
-
const [
|
|
978
|
+
async unstakePTB(t, e) {
|
|
979
|
+
const [n] = t.moveCall({
|
|
997
980
|
target: `${this.config.packageId}::stake_pool::unstake`,
|
|
998
981
|
arguments: [
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
982
|
+
t.object(this.config.poolId),
|
|
983
|
+
t.object(this.config.metadataId),
|
|
984
|
+
t.object("0x05"),
|
|
985
|
+
x(e, t.object)
|
|
1003
986
|
],
|
|
1004
987
|
typeArguments: []
|
|
1005
988
|
});
|
|
1006
|
-
return
|
|
989
|
+
return n;
|
|
1007
990
|
}
|
|
1008
991
|
/**
|
|
1009
992
|
* Stake SUI tokens to receive vSUI tokens
|
|
@@ -1013,25 +996,24 @@ class je extends x {
|
|
|
1013
996
|
* @returns Transaction response or dry run response
|
|
1014
997
|
* @throws Error if wallet client not found or stake amount is too low
|
|
1015
998
|
*/
|
|
1016
|
-
async stake(
|
|
1017
|
-
var r, c, o;
|
|
999
|
+
async stake(t, e) {
|
|
1018
1000
|
if (!this.walletClient)
|
|
1019
1001
|
throw new Error("Wallet client not found");
|
|
1020
|
-
if (
|
|
1002
|
+
if (t < 1e9)
|
|
1021
1003
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
1022
|
-
const
|
|
1004
|
+
const n = new f();
|
|
1023
1005
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1024
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"),
|
|
1025
|
-
balance:
|
|
1006
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = C(n, s.coins, {
|
|
1007
|
+
balance: t,
|
|
1026
1008
|
useGasCoin: !0
|
|
1027
|
-
}),
|
|
1028
|
-
|
|
1009
|
+
}), l = await this.stakePTB(n, a);
|
|
1010
|
+
n.transferObjects([l], this.walletClient.address);
|
|
1029
1011
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1030
|
-
transaction:
|
|
1031
|
-
dryRun:
|
|
1012
|
+
transaction: n,
|
|
1013
|
+
dryRun: e?.dryRun ?? !1
|
|
1032
1014
|
});
|
|
1033
|
-
return !
|
|
1034
|
-
suiAmount:
|
|
1015
|
+
return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("volo:stake-success", {
|
|
1016
|
+
suiAmount: t
|
|
1035
1017
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1036
1018
|
}
|
|
1037
1019
|
/**
|
|
@@ -1042,27 +1024,26 @@ class je extends x {
|
|
|
1042
1024
|
* @returns Transaction response or dry run response
|
|
1043
1025
|
* @throws Error if wallet client not found or unstake amount is too low
|
|
1044
1026
|
*/
|
|
1045
|
-
async unstake(
|
|
1046
|
-
var r, c, o;
|
|
1027
|
+
async unstake(t, e) {
|
|
1047
1028
|
if (!this.walletClient)
|
|
1048
1029
|
throw new Error("Wallet client not found");
|
|
1049
|
-
if (
|
|
1030
|
+
if (t < 1e9)
|
|
1050
1031
|
throw new Error("Unstake amount should >= 1vSui");
|
|
1051
1032
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1052
|
-
const
|
|
1053
|
-
balance:
|
|
1054
|
-
}),
|
|
1055
|
-
|
|
1033
|
+
const n = new f(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = C(n, s.coins, {
|
|
1034
|
+
balance: t
|
|
1035
|
+
}), l = await this.unstakePTB(n, a);
|
|
1036
|
+
n.transferObjects([l], this.walletClient.address);
|
|
1056
1037
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1057
|
-
transaction:
|
|
1058
|
-
dryRun:
|
|
1038
|
+
transaction: n,
|
|
1039
|
+
dryRun: e?.dryRun ?? !1
|
|
1059
1040
|
});
|
|
1060
|
-
return !
|
|
1061
|
-
vSuiAmount:
|
|
1041
|
+
return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("volo:unstake-success", {
|
|
1042
|
+
vSuiAmount: t
|
|
1062
1043
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1063
1044
|
}
|
|
1064
1045
|
}
|
|
1065
|
-
class
|
|
1046
|
+
class Ft extends A {
|
|
1066
1047
|
constructor() {
|
|
1067
1048
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1068
1049
|
apiKey: "",
|
|
@@ -1079,7 +1060,7 @@ class Ie extends x {
|
|
|
1079
1060
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
1080
1061
|
*/
|
|
1081
1062
|
get referral() {
|
|
1082
|
-
return this.config.apiKey ?
|
|
1063
|
+
return this.config.apiKey ? yt(this.config.apiKey) : 0;
|
|
1083
1064
|
}
|
|
1084
1065
|
/**
|
|
1085
1066
|
* Get the swap options
|
|
@@ -1100,8 +1081,8 @@ class Ie extends x {
|
|
|
1100
1081
|
* @param fromAmount - The amount of the coin being swapped from
|
|
1101
1082
|
* @returns A promise that resolves with the quote
|
|
1102
1083
|
*/
|
|
1103
|
-
async getQuote(
|
|
1104
|
-
return
|
|
1084
|
+
async getQuote(t, e, n) {
|
|
1085
|
+
return Pt(t, e, n, this.config.apiKey, this.swapOptions);
|
|
1105
1086
|
}
|
|
1106
1087
|
/**
|
|
1107
1088
|
* Builds a swap transaction from a quote
|
|
@@ -1111,16 +1092,16 @@ class Ie extends x {
|
|
|
1111
1092
|
* @param slippage - The slippage tolerance
|
|
1112
1093
|
* @returns The swap transaction
|
|
1113
1094
|
*/
|
|
1114
|
-
async buildSwapPTBFromQuote(
|
|
1095
|
+
async buildSwapPTBFromQuote(t, e, n, s) {
|
|
1115
1096
|
if (!this.walletClient)
|
|
1116
1097
|
throw new Error("Wallet client not found");
|
|
1117
|
-
const
|
|
1118
|
-
return await
|
|
1098
|
+
const a = new E(e.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1099
|
+
return await $(
|
|
1119
1100
|
this.walletClient.address,
|
|
1120
|
-
e,
|
|
1121
|
-
Number(n),
|
|
1122
1101
|
t,
|
|
1123
|
-
a,
|
|
1102
|
+
Number(a),
|
|
1103
|
+
n,
|
|
1104
|
+
e,
|
|
1124
1105
|
this.referral,
|
|
1125
1106
|
!1,
|
|
1126
1107
|
this.config.apiKey,
|
|
@@ -1144,58 +1125,57 @@ class Ie extends x {
|
|
|
1144
1125
|
* @param options - Optional parameters including dry run mode
|
|
1145
1126
|
* @returns Transaction response or dry run response
|
|
1146
1127
|
*/
|
|
1147
|
-
async swap(
|
|
1148
|
-
var y, d, g;
|
|
1128
|
+
async swap(t, e, n, s, a) {
|
|
1149
1129
|
if (!this.walletClient)
|
|
1150
1130
|
throw new Error("Wallet client not found");
|
|
1151
1131
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1152
|
-
const
|
|
1153
|
-
balance:
|
|
1132
|
+
const l = this.walletClient.module("balance").portfolio.getBalance(t), i = new f(), r = C(i, l.coins, {
|
|
1133
|
+
balance: n,
|
|
1154
1134
|
useGasCoin: !0
|
|
1155
|
-
}),
|
|
1156
|
-
if (i.transferObjects([
|
|
1135
|
+
}), w = await this.getQuote(t, e, n), u = await this.buildSwapPTBFromQuote(i, w, r, s);
|
|
1136
|
+
if (i.transferObjects([u], this.walletClient.address), i.setSender(this.walletClient.address), a?.dryRun)
|
|
1157
1137
|
return await this.walletClient.signExecuteTransaction({
|
|
1158
1138
|
transaction: i,
|
|
1159
1139
|
dryRun: !0
|
|
1160
1140
|
});
|
|
1161
|
-
const
|
|
1141
|
+
const g = await i.build({
|
|
1162
1142
|
client: this.walletClient.client
|
|
1163
|
-
}), h = await this.walletClient.signer.signTransaction(
|
|
1143
|
+
}), h = await this.walletClient.signer.signTransaction(g), p = [h.signature];
|
|
1164
1144
|
try {
|
|
1165
|
-
await
|
|
1166
|
-
} catch (
|
|
1167
|
-
console.error(
|
|
1145
|
+
await St(h.bytes, p);
|
|
1146
|
+
} catch (d) {
|
|
1147
|
+
console.error(d);
|
|
1168
1148
|
}
|
|
1169
|
-
const
|
|
1149
|
+
const c = await this.walletClient.client.executeTransactionBlock({
|
|
1170
1150
|
transactionBlock: h.bytes,
|
|
1171
|
-
signature:
|
|
1151
|
+
signature: p,
|
|
1172
1152
|
options: {
|
|
1173
1153
|
showEffects: !0,
|
|
1174
1154
|
showEvents: !0,
|
|
1175
1155
|
showBalanceChanges: !0
|
|
1176
1156
|
}
|
|
1177
1157
|
});
|
|
1178
|
-
if (
|
|
1179
|
-
const
|
|
1180
|
-
|
|
1181
|
-
fromCoinType:
|
|
1182
|
-
toCoinType:
|
|
1183
|
-
fromAmount:
|
|
1158
|
+
if (c.effects?.status?.status === "success") {
|
|
1159
|
+
const d = c.events?.find((y) => y.type.includes("::slippage::SwapEvent"));
|
|
1160
|
+
d && this.emit("swap:swap-success", {
|
|
1161
|
+
fromCoinType: t,
|
|
1162
|
+
toCoinType: e,
|
|
1163
|
+
fromAmount: n,
|
|
1184
1164
|
slippage: s,
|
|
1185
|
-
toAmount: Number(
|
|
1165
|
+
toAmount: Number(d.parsedJson.amount_out)
|
|
1186
1166
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1187
1167
|
}
|
|
1188
|
-
return
|
|
1168
|
+
return c;
|
|
1189
1169
|
}
|
|
1190
1170
|
}
|
|
1191
|
-
class
|
|
1171
|
+
class _t extends A {
|
|
1192
1172
|
constructor() {
|
|
1193
1173
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1194
1174
|
packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
|
|
1195
1175
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1196
1176
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1197
|
-
}, this.getApy =
|
|
1198
|
-
|
|
1177
|
+
}, this.getApy = st(
|
|
1178
|
+
W(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((e) => e.json())).data.apy)
|
|
1199
1179
|
);
|
|
1200
1180
|
}
|
|
1201
1181
|
/**
|
|
@@ -1205,18 +1185,18 @@ class Ue extends x {
|
|
|
1205
1185
|
* @param suiCoin - Sui coin object to stake
|
|
1206
1186
|
* @returns haSUI coin object
|
|
1207
1187
|
*/
|
|
1208
|
-
async stakePTB(
|
|
1209
|
-
const [
|
|
1188
|
+
async stakePTB(t, e) {
|
|
1189
|
+
const [n] = t.moveCall({
|
|
1210
1190
|
target: `${this.config.packageId}::staking::request_stake_coin`,
|
|
1211
1191
|
arguments: [
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1192
|
+
t.object("0x05"),
|
|
1193
|
+
t.object(this.config.configId),
|
|
1194
|
+
x(e, t.object),
|
|
1195
|
+
t.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1216
1196
|
],
|
|
1217
1197
|
typeArguments: []
|
|
1218
1198
|
});
|
|
1219
|
-
return
|
|
1199
|
+
return n;
|
|
1220
1200
|
}
|
|
1221
1201
|
/**
|
|
1222
1202
|
* Builds a transaction block for unstaking haSUI to SUI
|
|
@@ -1225,17 +1205,17 @@ class Ue extends x {
|
|
|
1225
1205
|
* @param haSUICoin - haSUI coin object to unstake
|
|
1226
1206
|
* @returns SUI coin object
|
|
1227
1207
|
*/
|
|
1228
|
-
async unstakePTB(
|
|
1229
|
-
const [
|
|
1208
|
+
async unstakePTB(t, e) {
|
|
1209
|
+
const [n] = t.moveCall({
|
|
1230
1210
|
target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
|
|
1231
1211
|
arguments: [
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1212
|
+
t.object("0x05"),
|
|
1213
|
+
t.object(this.config.configId),
|
|
1214
|
+
x(e, t.object)
|
|
1235
1215
|
],
|
|
1236
1216
|
typeArguments: []
|
|
1237
1217
|
});
|
|
1238
|
-
return
|
|
1218
|
+
return n;
|
|
1239
1219
|
}
|
|
1240
1220
|
/**
|
|
1241
1221
|
* Stake SUI for haSUI
|
|
@@ -1243,22 +1223,21 @@ class Ue extends x {
|
|
|
1243
1223
|
* @param suiAmount - Amount of SUI to stake
|
|
1244
1224
|
* @param options Optional dry run
|
|
1245
1225
|
*/
|
|
1246
|
-
async stake(
|
|
1247
|
-
var r, c, o;
|
|
1226
|
+
async stake(t, e) {
|
|
1248
1227
|
if (!this.walletClient)
|
|
1249
1228
|
throw new Error("Wallet client not found");
|
|
1250
|
-
const
|
|
1229
|
+
const n = new f();
|
|
1251
1230
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1252
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"),
|
|
1253
|
-
balance:
|
|
1231
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = C(n, s.coins, {
|
|
1232
|
+
balance: t,
|
|
1254
1233
|
useGasCoin: !0
|
|
1255
|
-
}),
|
|
1256
|
-
|
|
1234
|
+
}), l = await this.stakePTB(n, a);
|
|
1235
|
+
n.transferObjects([l], this.walletClient.address);
|
|
1257
1236
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1258
|
-
transaction:
|
|
1259
|
-
dryRun:
|
|
1237
|
+
transaction: n,
|
|
1238
|
+
dryRun: e?.dryRun ?? !1
|
|
1260
1239
|
});
|
|
1261
|
-
return !
|
|
1240
|
+
return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1262
1241
|
}
|
|
1263
1242
|
/**
|
|
1264
1243
|
* Unstake haSUI for SUI
|
|
@@ -1266,50 +1245,49 @@ class Ue extends x {
|
|
|
1266
1245
|
* @param haSUIAmount - Amount of haSUI to unstake
|
|
1267
1246
|
* @param options Optional dry run
|
|
1268
1247
|
*/
|
|
1269
|
-
async unstake(
|
|
1270
|
-
var r, c, o;
|
|
1248
|
+
async unstake(t, e) {
|
|
1271
1249
|
if (!this.walletClient)
|
|
1272
1250
|
throw new Error("Wallet client not found");
|
|
1273
1251
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1274
|
-
const
|
|
1275
|
-
balance:
|
|
1276
|
-
}),
|
|
1277
|
-
|
|
1252
|
+
const n = new f(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = C(n, s.coins, {
|
|
1253
|
+
balance: t
|
|
1254
|
+
}), l = await this.unstakePTB(n, a);
|
|
1255
|
+
n.transferObjects([l], this.walletClient.address);
|
|
1278
1256
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1279
|
-
transaction:
|
|
1280
|
-
dryRun:
|
|
1257
|
+
transaction: n,
|
|
1258
|
+
dryRun: e?.dryRun ?? !1
|
|
1281
1259
|
});
|
|
1282
|
-
return !
|
|
1260
|
+
return !e?.dryRun && i.effects?.status?.status === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1283
1261
|
}
|
|
1284
1262
|
}
|
|
1285
|
-
const
|
|
1263
|
+
const jt = {
|
|
1286
1264
|
/** Balance management module */
|
|
1287
|
-
balance: new
|
|
1265
|
+
balance: new At(),
|
|
1288
1266
|
/** Lending protocol module */
|
|
1289
|
-
lending: new
|
|
1267
|
+
lending: new kt(),
|
|
1290
1268
|
/** Volo protocol module */
|
|
1291
|
-
volo: new
|
|
1269
|
+
volo: new Nt(),
|
|
1292
1270
|
/** DEX swapping module */
|
|
1293
|
-
swap: new
|
|
1271
|
+
swap: new Ft(),
|
|
1294
1272
|
/** Haedal protocol module */
|
|
1295
|
-
haedal: new
|
|
1296
|
-
},
|
|
1297
|
-
url:
|
|
1273
|
+
haedal: new _t()
|
|
1274
|
+
}, It = {
|
|
1275
|
+
url: ct("mainnet")
|
|
1298
1276
|
};
|
|
1299
|
-
class
|
|
1277
|
+
class Jt {
|
|
1300
1278
|
/**
|
|
1301
1279
|
* Creates a new wallet client instance
|
|
1302
1280
|
* @param options - Configuration options for the wallet client
|
|
1303
1281
|
*/
|
|
1304
|
-
constructor(
|
|
1305
|
-
this.modules =
|
|
1306
|
-
const
|
|
1307
|
-
...
|
|
1308
|
-
...
|
|
1282
|
+
constructor(t) {
|
|
1283
|
+
this.modules = jt, this.userConfigs = {}, this.events = dt();
|
|
1284
|
+
const e = {
|
|
1285
|
+
...It,
|
|
1286
|
+
...t.client
|
|
1309
1287
|
};
|
|
1310
|
-
|
|
1311
|
-
if (
|
|
1312
|
-
throw new Error(`Module name ${
|
|
1288
|
+
e.transport = e.transport || new Ot(e.url), this.client = new ut(e), this.signer = t.signer, this.userConfigs = t.configs || {}, Object.entries(this.modules).forEach(([n, s]) => {
|
|
1289
|
+
if (n !== s.name)
|
|
1290
|
+
throw new Error(`Module name ${n} does not match module name ${s.name}`);
|
|
1313
1291
|
s.install(this);
|
|
1314
1292
|
});
|
|
1315
1293
|
}
|
|
@@ -1333,18 +1311,18 @@ class Ye {
|
|
|
1333
1311
|
* @param options - Transaction execution options including dry run support
|
|
1334
1312
|
* @returns Promise with transaction execution result
|
|
1335
1313
|
*/
|
|
1336
|
-
async signExecuteTransaction(
|
|
1337
|
-
const { dryRun:
|
|
1338
|
-
if (
|
|
1314
|
+
async signExecuteTransaction(t) {
|
|
1315
|
+
const { dryRun: e = !1, ...n } = t;
|
|
1316
|
+
if (e) {
|
|
1339
1317
|
let s;
|
|
1340
|
-
return
|
|
1318
|
+
return t.transaction instanceof f ? (t.transaction.setSenderIfNotSet(this.address), s = await t.transaction.build({
|
|
1341
1319
|
client: this.client
|
|
1342
|
-
})) : s =
|
|
1320
|
+
})) : s = t.transaction, this.client.dryRunTransactionBlock({
|
|
1343
1321
|
transactionBlock: s
|
|
1344
1322
|
});
|
|
1345
1323
|
}
|
|
1346
1324
|
return this.client.signAndExecuteTransaction({
|
|
1347
|
-
...
|
|
1325
|
+
...n,
|
|
1348
1326
|
signer: this.signer
|
|
1349
1327
|
});
|
|
1350
1328
|
}
|
|
@@ -1360,18 +1338,18 @@ class Ye {
|
|
|
1360
1338
|
* @param name - The name of the module to retrieve
|
|
1361
1339
|
* @returns The requested module instance
|
|
1362
1340
|
*/
|
|
1363
|
-
module(
|
|
1364
|
-
return this.modules[
|
|
1341
|
+
module(t) {
|
|
1342
|
+
return this.modules[t];
|
|
1365
1343
|
}
|
|
1366
1344
|
/**
|
|
1367
1345
|
* Gets the configuration for a specific module
|
|
1368
1346
|
* @param name - The name of the module
|
|
1369
1347
|
* @returns The merged configuration (default + user config)
|
|
1370
1348
|
*/
|
|
1371
|
-
config(
|
|
1349
|
+
config(t) {
|
|
1372
1350
|
return {
|
|
1373
|
-
...this.modules[
|
|
1374
|
-
...this.userConfigs[
|
|
1351
|
+
...this.modules[t].defaultConfig,
|
|
1352
|
+
...this.userConfigs[t]
|
|
1375
1353
|
};
|
|
1376
1354
|
}
|
|
1377
1355
|
/**
|
|
@@ -1379,18 +1357,18 @@ class Ye {
|
|
|
1379
1357
|
* @param name - The name of the module to check
|
|
1380
1358
|
* @returns True if the module exists, false otherwise
|
|
1381
1359
|
*/
|
|
1382
|
-
hasModule(
|
|
1383
|
-
return
|
|
1360
|
+
hasModule(t) {
|
|
1361
|
+
return t in this.modules;
|
|
1384
1362
|
}
|
|
1385
1363
|
}
|
|
1386
|
-
class
|
|
1364
|
+
class Vt extends it {
|
|
1387
1365
|
/**
|
|
1388
1366
|
* Creates a new watch-only signer
|
|
1389
1367
|
*
|
|
1390
1368
|
* @param address - The wallet address to watch
|
|
1391
1369
|
*/
|
|
1392
|
-
constructor(
|
|
1393
|
-
super(), this.address =
|
|
1370
|
+
constructor(t) {
|
|
1371
|
+
super(), this.address = t;
|
|
1394
1372
|
}
|
|
1395
1373
|
/**
|
|
1396
1374
|
* Signs transaction bytes (not implemented for watch-only mode)
|
|
@@ -1401,7 +1379,7 @@ class Ze extends ce {
|
|
|
1401
1379
|
* @param bytes - Transaction bytes to sign
|
|
1402
1380
|
* @returns Promise<Uint8Array> - Empty signature (not valid)
|
|
1403
1381
|
*/
|
|
1404
|
-
async sign(
|
|
1382
|
+
async sign(t) {
|
|
1405
1383
|
return Promise.resolve(new Uint8Array(0));
|
|
1406
1384
|
}
|
|
1407
1385
|
/**
|
|
@@ -1443,18 +1421,18 @@ class Ze extends ce {
|
|
|
1443
1421
|
* @param options - Sign and execute options
|
|
1444
1422
|
* @returns Promise<any> - Empty result (not a real transaction result)
|
|
1445
1423
|
*/
|
|
1446
|
-
async signAndExecuteTransaction({ transaction:
|
|
1424
|
+
async signAndExecuteTransaction({ transaction: t, client: e }) {
|
|
1447
1425
|
return {};
|
|
1448
1426
|
}
|
|
1449
1427
|
}
|
|
1450
|
-
class
|
|
1428
|
+
class Xt extends it {
|
|
1451
1429
|
/**
|
|
1452
1430
|
* Creates a new watch-only signer
|
|
1453
1431
|
*
|
|
1454
1432
|
* @param address - The wallet address to watch
|
|
1455
1433
|
*/
|
|
1456
|
-
constructor(
|
|
1457
|
-
super(), this.address =
|
|
1434
|
+
constructor(t) {
|
|
1435
|
+
super(), this.address = t;
|
|
1458
1436
|
}
|
|
1459
1437
|
/**
|
|
1460
1438
|
* Signs transaction bytes (not implemented for watch-only mode)
|
|
@@ -1465,7 +1443,7 @@ class et extends ce {
|
|
|
1465
1443
|
* @param bytes - Transaction bytes to sign
|
|
1466
1444
|
* @returns Promise<Uint8Array> - Empty signature (not valid)
|
|
1467
1445
|
*/
|
|
1468
|
-
async sign(
|
|
1446
|
+
async sign(t) {
|
|
1469
1447
|
return Promise.resolve(new Uint8Array(0));
|
|
1470
1448
|
}
|
|
1471
1449
|
/**
|
|
@@ -1500,8 +1478,8 @@ class et extends ce {
|
|
|
1500
1478
|
}
|
|
1501
1479
|
}
|
|
1502
1480
|
export {
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1481
|
+
Jt as WalletClient,
|
|
1482
|
+
Vt as WatchSigner,
|
|
1483
|
+
Xt as WebSigner
|
|
1506
1484
|
};
|
|
1507
1485
|
//# sourceMappingURL=index.esm.js.map
|