@naviprotocol/wallet-client 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +6 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/index.esm.js +411 -423
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/haedalModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/index.d.ts.map +1 -1
- package/dist/modules/swapModule/index.d.ts.map +1 -1
- package/dist/modules/voloModule/index.d.ts.map +1 -1
- package/dist/signer.d.ts +10 -17
- package/dist/signer.d.ts.map +1 -1
- package/dist/transaction-result.d.ts +12 -0
- package/dist/transaction-result.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { withSingleton as
|
|
3
|
-
import
|
|
4
|
-
import { normalizeStructTag as
|
|
1
|
+
import mt from "mitt";
|
|
2
|
+
import { withSingleton as Q, getCoins as et, mergeCoinsPTB as m, getPriceFeeds as $, updateOraclePricesPTB as K, filterPriceFeeds as q, depositCoinPTB as A, getFlashLoanAsset as nt, flashloanPTB as at, repayFlashLoanPTB as it, borrowCoinPTB as st, withdrawCoinPTB as ot, repayCoinPTB as rt, getPools as Ct, getPool as P, getHealthFactor as yt, liquidatePTB as bt, getUserAvailableLendingRewards as D, getUserClaimedRewardHistory as vt, claimLendingRewardsPTB as Bt, getLendingState as Tt, createAccountCapPTB as Pt, withCache as lt, resolveNaviOpenApiEndpoint as ct, buildNaviOpenApiUrl as ut, mergeServiceHeaders as ht, parseTxValue as F, PUBLIC_MAINNET_GRPC_URL as St, createNaviSuiClientBundle as Ot, createNaviLegacyJsonRpcClient as Et } from "@naviprotocol/lending";
|
|
3
|
+
import E, { BigNumber as M } from "bignumber.js";
|
|
4
|
+
import { normalizeStructTag as B, fromBase64 as dt } from "@mysten/sui/utils";
|
|
5
5
|
import { Transaction as h } from "@mysten/sui/transactions";
|
|
6
|
-
import { buildSwapPTBFromQuote as z, generateRefId as
|
|
7
|
-
import { executeAuction as
|
|
8
|
-
import { Signer as
|
|
9
|
-
class
|
|
6
|
+
import { buildSwapPTBFromQuote as z, generateRefId as Rt, getQuote as xt } from "@naviprotocol/astros-aggregator-sdk";
|
|
7
|
+
import { executeAuction as At } from "shio-sdk";
|
|
8
|
+
import { Signer as wt } from "@mysten/sui/cryptography";
|
|
9
|
+
class k {
|
|
10
10
|
/**
|
|
11
11
|
* Gets the current configuration for this module
|
|
12
12
|
*
|
|
@@ -24,8 +24,8 @@ class j {
|
|
|
24
24
|
* @param event - The event name to emit
|
|
25
25
|
* @param data - The event data to emit
|
|
26
26
|
*/
|
|
27
|
-
emit(t,
|
|
28
|
-
this.walletClient?.events.emit(t,
|
|
27
|
+
emit(t, e) {
|
|
28
|
+
this.walletClient?.events.emit(t, e);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Installs this module into a wallet client
|
|
@@ -48,28 +48,28 @@ class j {
|
|
|
48
48
|
this.walletClient = void 0;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
class
|
|
51
|
+
class R {
|
|
52
52
|
/**
|
|
53
53
|
* Creates a new user portfolio
|
|
54
54
|
*
|
|
55
55
|
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
56
56
|
*/
|
|
57
57
|
constructor(t) {
|
|
58
|
-
if (t instanceof
|
|
58
|
+
if (t instanceof R)
|
|
59
59
|
this.balances = JSON.parse(JSON.stringify(t.balances));
|
|
60
60
|
else {
|
|
61
|
-
const
|
|
62
|
-
t?.forEach((
|
|
63
|
-
if (!
|
|
61
|
+
const e = {};
|
|
62
|
+
t?.forEach((n) => {
|
|
63
|
+
if (!n.coinType || n.balance === void 0 || n.balance === null)
|
|
64
64
|
return;
|
|
65
|
-
const s =
|
|
66
|
-
let a =
|
|
65
|
+
const s = B(n.coinType);
|
|
66
|
+
let a = e[s];
|
|
67
67
|
a || (a = {
|
|
68
68
|
coinType: s,
|
|
69
|
-
amount:
|
|
69
|
+
amount: M(0),
|
|
70
70
|
coins: []
|
|
71
|
-
},
|
|
72
|
-
}), this.balances =
|
|
71
|
+
}, e[s] = a), a.coins.push(n), a.amount = a.amount.plus(n.balance);
|
|
72
|
+
}), this.balances = e;
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -79,7 +79,7 @@ class E {
|
|
|
79
79
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
80
80
|
*/
|
|
81
81
|
getBalance(t) {
|
|
82
|
-
return t =
|
|
82
|
+
return t = B(t), this.balances[t] || { coinType: t, amount: M(0), coins: [] };
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Gets all coin types in the portfolio
|
|
@@ -96,7 +96,7 @@ class E {
|
|
|
96
96
|
* @returns BigNumber representing the total balance
|
|
97
97
|
*/
|
|
98
98
|
balanceOf(t) {
|
|
99
|
-
return t =
|
|
99
|
+
return t = B(t), this.getBalance(t)?.amount || M(0);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Creates a deep copy of the portfolio
|
|
@@ -107,22 +107,22 @@ class E {
|
|
|
107
107
|
* @returns New UserPortfolio instance with copied data
|
|
108
108
|
*/
|
|
109
109
|
clone() {
|
|
110
|
-
const t = JSON.parse(JSON.stringify(this.balances)),
|
|
111
|
-
return
|
|
110
|
+
const t = JSON.parse(JSON.stringify(this.balances)), e = new R();
|
|
111
|
+
return e.balances = t, e;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
-
class
|
|
114
|
+
class jt extends k {
|
|
115
115
|
constructor() {
|
|
116
116
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
117
117
|
coinPollingInterval: 6e3,
|
|
118
118
|
disableCoinPolling: !1
|
|
119
|
-
}, this.updatePortfolio =
|
|
119
|
+
}, this.updatePortfolio = Q(async () => {
|
|
120
120
|
if (!this.walletClient)
|
|
121
121
|
throw new Error("Wallet client not found");
|
|
122
|
-
this._coins = await
|
|
122
|
+
this._coins = await et(this.walletClient.address, {
|
|
123
123
|
client: this.walletClient.client
|
|
124
|
-
}), this._portfolio = new
|
|
125
|
-
}), this._coins = [], this._portfolio = new
|
|
124
|
+
}), this._portfolio = new R(this._coins), this.emit("balance:portfolio-updated", {});
|
|
125
|
+
}), this._coins = [], this._portfolio = new R(), this.pollingTimer = null, this._updatePromise = null;
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Gets the current coin objects from the wallet
|
|
@@ -160,8 +160,8 @@ class Rt extends j {
|
|
|
160
160
|
* @param options - Optional parameters including dry run mode
|
|
161
161
|
* @returns Transaction response or dry run response
|
|
162
162
|
*/
|
|
163
|
-
async sendCoin(t,
|
|
164
|
-
return this.sendCoinBatch(t, [
|
|
163
|
+
async sendCoin(t, e, n, s) {
|
|
164
|
+
return this.sendCoinBatch(t, [e], [n], s);
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
167
|
* Sends coins to multiple recipients in a single transaction
|
|
@@ -172,22 +172,22 @@ class Rt extends j {
|
|
|
172
172
|
* @param options - Optional parameters including dry run mode
|
|
173
173
|
* @returns Transaction response or dry run response
|
|
174
174
|
*/
|
|
175
|
-
async sendCoinBatch(t,
|
|
175
|
+
async sendCoinBatch(t, e, n, s) {
|
|
176
176
|
if (!this.walletClient)
|
|
177
177
|
throw new Error("Wallet client not found");
|
|
178
|
-
if (
|
|
178
|
+
if (e.length !== n.length)
|
|
179
179
|
throw new Error("Recipients and amounts must have the same length");
|
|
180
180
|
await this.waitForUpdate();
|
|
181
|
-
const a = this.portfolio.getBalance(t), r =
|
|
181
|
+
const a = this.portfolio.getBalance(t), r = n.reduce((w, d) => w.plus(d), E(0));
|
|
182
182
|
if (a.amount.lt(r))
|
|
183
183
|
throw new Error("Insufficient balance");
|
|
184
184
|
const o = new h();
|
|
185
185
|
let l = o.gas;
|
|
186
|
-
|
|
186
|
+
B(t) !== B("0x2::sui::SUI") && (l = m(o, a.coins, {
|
|
187
187
|
balance: r.toNumber()
|
|
188
188
|
}));
|
|
189
|
-
const c = o.splitCoins(l,
|
|
190
|
-
return
|
|
189
|
+
const c = o.splitCoins(l, n);
|
|
190
|
+
return e.forEach((w, d) => {
|
|
191
191
|
o.transferObjects([c[d]], w);
|
|
192
192
|
}), await this.walletClient.signExecuteTransaction({
|
|
193
193
|
transaction: o,
|
|
@@ -202,8 +202,8 @@ class Rt extends j {
|
|
|
202
202
|
* @param options - Optional parameters including dry run mode
|
|
203
203
|
* @returns Transaction response or dry run response
|
|
204
204
|
*/
|
|
205
|
-
async transferObject(t,
|
|
206
|
-
return this.transferObjectBatch([t], [
|
|
205
|
+
async transferObject(t, e, n) {
|
|
206
|
+
return this.transferObjectBatch([t], [e], n);
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* Transfers multiple objects to their respective recipients in a single transaction
|
|
@@ -216,18 +216,18 @@ class Rt extends j {
|
|
|
216
216
|
* @param options - Optional parameters including dry run mode
|
|
217
217
|
* @returns Transaction response or dry run response
|
|
218
218
|
*/
|
|
219
|
-
async transferObjectBatch(t,
|
|
219
|
+
async transferObjectBatch(t, e, n) {
|
|
220
220
|
if (!this.walletClient)
|
|
221
221
|
throw new Error("Wallet client not found");
|
|
222
|
-
if (t.length !==
|
|
222
|
+
if (t.length !== e.length)
|
|
223
223
|
throw new Error("Objects and recipients must have the same length");
|
|
224
224
|
await this.waitForUpdate();
|
|
225
225
|
const s = new h();
|
|
226
226
|
return t.forEach((r, o) => {
|
|
227
|
-
s.transferObjects([s.object(r)],
|
|
227
|
+
s.transferObjects([s.object(r)], e[o]);
|
|
228
228
|
}), await this.walletClient.signExecuteTransaction({
|
|
229
229
|
transaction: s,
|
|
230
|
-
dryRun:
|
|
230
|
+
dryRun: n?.dryRun ?? !1
|
|
231
231
|
});
|
|
232
232
|
}
|
|
233
233
|
/**
|
|
@@ -252,9 +252,9 @@ class Rt extends j {
|
|
|
252
252
|
* @param walletClient - The wallet client instance to install into
|
|
253
253
|
*/
|
|
254
254
|
install(t) {
|
|
255
|
-
super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((
|
|
255
|
+
super.install(t), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((e) => {
|
|
256
256
|
t.events.on("balance:portfolio-updated", () => {
|
|
257
|
-
|
|
257
|
+
e();
|
|
258
258
|
});
|
|
259
259
|
});
|
|
260
260
|
}
|
|
@@ -267,10 +267,62 @@ class Rt extends j {
|
|
|
267
267
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
|
|
270
|
+
const G = {
|
|
271
|
+
showEffects: !0,
|
|
272
|
+
showEvents: !0,
|
|
273
|
+
showBalanceChanges: !0,
|
|
274
|
+
showObjectChanges: !0
|
|
275
|
+
};
|
|
276
|
+
function H(i) {
|
|
277
|
+
return {
|
|
278
|
+
...G,
|
|
279
|
+
...i
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
function p(i) {
|
|
283
|
+
const t = i?.effects?.status;
|
|
284
|
+
return t?.status === "success" || t?.success === !0;
|
|
285
|
+
}
|
|
286
|
+
function x(i, t) {
|
|
287
|
+
const n = kt(t ?? {}), s = Ft(n);
|
|
288
|
+
return {
|
|
289
|
+
...n,
|
|
290
|
+
kind: i,
|
|
291
|
+
effects: s,
|
|
292
|
+
events: Nt(n.events),
|
|
293
|
+
balanceChanges: Array.isArray(n.balanceChanges) ? n.balanceChanges : [],
|
|
294
|
+
objectChanges: Array.isArray(n.objectChanges) ? n.objectChanges : []
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function kt(i) {
|
|
298
|
+
const t = i.Transaction;
|
|
299
|
+
if (j(t))
|
|
300
|
+
return t;
|
|
301
|
+
const e = i.FailedTransaction;
|
|
302
|
+
return j(e) ? e : i;
|
|
303
|
+
}
|
|
304
|
+
function Ft(i) {
|
|
305
|
+
if (j(i.effects))
|
|
306
|
+
return i.effects;
|
|
307
|
+
if (j(i.status))
|
|
308
|
+
return {
|
|
309
|
+
status: i.status
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function Nt(i) {
|
|
313
|
+
return Array.isArray(i) ? i.map((t) => j(t) ? {
|
|
314
|
+
...t,
|
|
315
|
+
type: t.type ?? t.eventType,
|
|
316
|
+
parsedJson: t.parsedJson ?? t.json
|
|
317
|
+
} : t) : [];
|
|
318
|
+
}
|
|
319
|
+
function j(i) {
|
|
320
|
+
return typeof i == "object" && i !== null;
|
|
321
|
+
}
|
|
322
|
+
async function V(i, t, e, n) {
|
|
271
323
|
if (!this.walletClient)
|
|
272
324
|
throw new Error("Wallet client not found");
|
|
273
|
-
const s = await this.getPool(t), a = await this.getPool(
|
|
325
|
+
const s = await this.getPool(t), a = await this.getPool(e), r = await this.getLendingState(), o = this.walletClient.address, l = n?.protocol ?? "navi", c = await this.getProtocol(l);
|
|
274
326
|
if (!c)
|
|
275
327
|
throw new Error(`Protocol ${l} not found`);
|
|
276
328
|
const u = await c.getPool(s.coinType);
|
|
@@ -278,84 +330,84 @@ async function D(i, t, n, e) {
|
|
|
278
330
|
fromPoolLending: u
|
|
279
331
|
}), l === "navi" && u.supplyBalance === 0)
|
|
280
332
|
throw new Error("No supply balance");
|
|
281
|
-
if (
|
|
333
|
+
if (n?.amount && n.amount > u.supplyBalance)
|
|
282
334
|
throw new Error("Amount is less than supply balance");
|
|
283
|
-
const w =
|
|
284
|
-
if (await
|
|
335
|
+
const w = n?.slippage ?? 5e-3, d = n?.amount ?? Number(u.supplyBalance), f = await $(this.naviServiceOptions), C = await Promise.all([s, a]);
|
|
336
|
+
if (await K(
|
|
285
337
|
i,
|
|
286
338
|
q(f, {
|
|
287
339
|
lendingState: r,
|
|
288
|
-
pools:
|
|
340
|
+
pools: C
|
|
289
341
|
}),
|
|
290
342
|
this.naviServiceOptions
|
|
291
343
|
), l !== "navi" && s.id === a.id) {
|
|
292
|
-
const
|
|
344
|
+
const L = await c.withdrawCoinPTB(
|
|
293
345
|
i,
|
|
294
346
|
s.suiCoinType,
|
|
295
347
|
d
|
|
296
348
|
);
|
|
297
|
-
return await
|
|
349
|
+
return await A(i, a, L, {
|
|
298
350
|
...this.naviServiceOptions,
|
|
299
351
|
amount: d
|
|
300
352
|
}), i;
|
|
301
353
|
}
|
|
302
|
-
const
|
|
354
|
+
const y = await nt(a, {
|
|
303
355
|
...this.naviServiceOptions,
|
|
304
356
|
env: this.config.env
|
|
305
357
|
});
|
|
306
|
-
if (!
|
|
358
|
+
if (!y)
|
|
307
359
|
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
308
|
-
const
|
|
360
|
+
const b = await this.walletClient.swap.getQuote(
|
|
309
361
|
s.suiCoinType,
|
|
310
362
|
a.suiCoinType,
|
|
311
363
|
d
|
|
312
|
-
), g = Number(
|
|
364
|
+
), g = Number(b.amount_out);
|
|
313
365
|
if (g <= 0)
|
|
314
366
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
367
|
+
const T = Math.floor(g * (1 - w)), v = Math.floor(T / (1 + y.flashloanFee));
|
|
368
|
+
if (v <= 0)
|
|
317
369
|
throw new Error("The calculated borrow amount must be positive.");
|
|
318
|
-
const [
|
|
370
|
+
const [S, O] = await at(
|
|
319
371
|
i,
|
|
320
372
|
a,
|
|
321
|
-
|
|
373
|
+
v,
|
|
322
374
|
this.naviServiceOptions
|
|
323
|
-
), [
|
|
375
|
+
), [N] = i.moveCall({
|
|
324
376
|
target: "0x2::coin::from_balance",
|
|
325
|
-
arguments: [
|
|
377
|
+
arguments: [S],
|
|
326
378
|
typeArguments: [a.suiCoinType]
|
|
327
379
|
});
|
|
328
|
-
await
|
|
380
|
+
await A(i, a, N, {
|
|
329
381
|
...this.naviServiceOptions,
|
|
330
|
-
amount:
|
|
382
|
+
amount: v
|
|
331
383
|
});
|
|
332
|
-
const
|
|
384
|
+
const _ = await c.withdrawCoinPTB(i, s.suiCoinType, d), U = await z(
|
|
333
385
|
o,
|
|
334
386
|
i,
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
),
|
|
387
|
+
T,
|
|
388
|
+
_,
|
|
389
|
+
b
|
|
390
|
+
), W = i.moveCall({
|
|
339
391
|
target: "0x2::coin::into_balance",
|
|
340
|
-
arguments: [
|
|
392
|
+
arguments: [U],
|
|
341
393
|
typeArguments: [a.suiCoinType]
|
|
342
|
-
}), [
|
|
394
|
+
}), [I] = await it(
|
|
343
395
|
i,
|
|
344
396
|
a,
|
|
345
|
-
|
|
346
|
-
|
|
397
|
+
O,
|
|
398
|
+
W,
|
|
347
399
|
this.naviServiceOptions
|
|
348
|
-
), [
|
|
400
|
+
), [J] = i.moveCall({
|
|
349
401
|
target: "0x2::coin::from_balance",
|
|
350
|
-
arguments: [
|
|
402
|
+
arguments: [I],
|
|
351
403
|
typeArguments: [a.suiCoinType]
|
|
352
404
|
});
|
|
353
|
-
return await
|
|
405
|
+
return await A(i, a, J, this.naviServiceOptions), i;
|
|
354
406
|
}
|
|
355
|
-
async function
|
|
407
|
+
async function X(i, t, e, n) {
|
|
356
408
|
if (!this.walletClient)
|
|
357
409
|
throw new Error("Wallet client not found");
|
|
358
|
-
const s = this.walletClient.address, a = await this.getPool(t), r = await this.getPool(
|
|
410
|
+
const s = this.walletClient.address, a = await this.getPool(t), r = await this.getPool(e), o = await this.getLendingState(), l = n?.protocol ?? "navi", c = await this.getProtocol(l);
|
|
359
411
|
if (!c)
|
|
360
412
|
throw new Error(`Protocol ${l} not found`);
|
|
361
413
|
const u = await c.getPool(a.coinType);
|
|
@@ -363,10 +415,10 @@ async function V(i, t, n, e) {
|
|
|
363
415
|
fromPoolLending: u
|
|
364
416
|
}), u.borrowBalance === 0)
|
|
365
417
|
throw new Error("No borrow balance");
|
|
366
|
-
if (
|
|
418
|
+
if (n?.amount && n.amount > u.borrowBalance)
|
|
367
419
|
throw new Error("Amount is more than borrow balance");
|
|
368
|
-
const w = await
|
|
369
|
-
await
|
|
420
|
+
const w = await $(this.naviServiceOptions), d = await Promise.all([a, r]);
|
|
421
|
+
await K(
|
|
370
422
|
i,
|
|
371
423
|
q(w, {
|
|
372
424
|
lendingState: o,
|
|
@@ -374,90 +426,90 @@ async function V(i, t, n, e) {
|
|
|
374
426
|
}),
|
|
375
427
|
this.naviServiceOptions
|
|
376
428
|
);
|
|
377
|
-
let f =
|
|
429
|
+
let f = n?.amount ?? Number(u.borrowBalance);
|
|
378
430
|
if (Number(u.borrowBalance) === f) {
|
|
379
|
-
const
|
|
431
|
+
const pt = u.borrowAPR / 100;
|
|
380
432
|
f = Math.ceil(
|
|
381
|
-
new
|
|
433
|
+
new E(f).multipliedBy(pt * (60 * 3) / (365 * 24 * 3600)).plus(new E(1).shiftedBy(-a.token.decimals)).plus(f).toNumber()
|
|
382
434
|
);
|
|
383
435
|
}
|
|
384
|
-
const
|
|
436
|
+
const C = await nt(a, {
|
|
385
437
|
...this.naviServiceOptions,
|
|
386
438
|
env: this.config.env
|
|
387
439
|
});
|
|
388
|
-
if (!
|
|
440
|
+
if (!C)
|
|
389
441
|
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
390
442
|
if (!this.walletClient)
|
|
391
443
|
throw new Error("Wallet client not found");
|
|
392
|
-
const
|
|
444
|
+
const y = n?.slippage ?? 5e-3, b = Math.ceil(f * (1 + C.flashloanFee)), g = b, T = await this.walletClient.swap.getQuote(
|
|
393
445
|
a.suiCoinType,
|
|
394
446
|
r.suiCoinType,
|
|
395
447
|
g
|
|
396
448
|
);
|
|
397
|
-
let
|
|
449
|
+
let v = 1 + y, S = Math.ceil(Number(T.amount_out) * v), O = await this.walletClient.swap.getQuote(
|
|
398
450
|
r.suiCoinType,
|
|
399
451
|
a.suiCoinType,
|
|
400
|
-
|
|
452
|
+
S
|
|
401
453
|
);
|
|
402
|
-
for (; Number(
|
|
403
|
-
|
|
454
|
+
for (; Number(O.amount_out) < g; )
|
|
455
|
+
v = v * Math.max(g / Number(O.amount_out), 1.001), S = Math.ceil(Number(T.amount_out) * v), O = await this.walletClient.swap.getQuote(
|
|
404
456
|
r.suiCoinType,
|
|
405
457
|
a.suiCoinType,
|
|
406
|
-
|
|
458
|
+
S
|
|
407
459
|
);
|
|
408
|
-
const [
|
|
460
|
+
const [N, _] = await at(
|
|
409
461
|
i,
|
|
410
462
|
a,
|
|
411
463
|
f,
|
|
412
464
|
this.naviServiceOptions
|
|
413
|
-
), [
|
|
465
|
+
), [U] = i.moveCall({
|
|
414
466
|
target: "0x2::coin::from_balance",
|
|
415
|
-
arguments: [
|
|
467
|
+
arguments: [N],
|
|
416
468
|
typeArguments: [a.suiCoinType]
|
|
417
469
|
});
|
|
418
|
-
await c.repayCoinPTB(i, a.suiCoinType,
|
|
419
|
-
const
|
|
470
|
+
await c.repayCoinPTB(i, a.suiCoinType, U, f);
|
|
471
|
+
const W = await st(i, r, S, this.naviServiceOptions), I = await z(
|
|
420
472
|
s,
|
|
421
473
|
i,
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
),
|
|
474
|
+
b,
|
|
475
|
+
W,
|
|
476
|
+
O
|
|
477
|
+
), J = i.moveCall({
|
|
426
478
|
target: "0x2::coin::into_balance",
|
|
427
|
-
arguments: [
|
|
479
|
+
arguments: [I],
|
|
428
480
|
typeArguments: [a.suiCoinType]
|
|
429
|
-
}), [
|
|
481
|
+
}), [L] = await it(
|
|
430
482
|
i,
|
|
431
483
|
a,
|
|
432
|
-
|
|
433
|
-
|
|
484
|
+
_,
|
|
485
|
+
J,
|
|
434
486
|
this.naviServiceOptions
|
|
435
|
-
), [
|
|
487
|
+
), [gt] = i.moveCall({
|
|
436
488
|
target: "0x2::coin::from_balance",
|
|
437
|
-
arguments: [
|
|
489
|
+
arguments: [L],
|
|
438
490
|
typeArguments: [a.suiCoinType]
|
|
439
491
|
});
|
|
440
|
-
return i.transferObjects([
|
|
492
|
+
return i.transferObjects([gt], s), i;
|
|
441
493
|
}
|
|
442
|
-
async function
|
|
494
|
+
async function Y(i, t, e, n) {
|
|
443
495
|
if (!this.walletClient)
|
|
444
496
|
throw new Error("Wallet client not found");
|
|
445
|
-
const s = await
|
|
497
|
+
const s = await et(this.walletClient.address, {
|
|
446
498
|
client: this.walletClient.client,
|
|
447
499
|
coinType: t
|
|
448
|
-
}), a = await this.getPool(
|
|
500
|
+
}), a = await this.getPool(e), o = new R(s).getBalance(t);
|
|
449
501
|
if (o.amount.eq(0))
|
|
450
502
|
throw new Error(`No balance of ${t}`);
|
|
451
503
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
452
504
|
balance: o.amount.toNumber()
|
|
453
|
-
}),
|
|
505
|
+
}), n?.amount && o.amount.lt(n.amount))
|
|
454
506
|
throw new Error("Amount is greater than balance");
|
|
455
|
-
const l =
|
|
456
|
-
let u = await
|
|
507
|
+
const l = n?.amount ?? o.amount.toNumber(), c = n?.slippage ?? 5e-3;
|
|
508
|
+
let u = await m(i, o.coins, {
|
|
457
509
|
balance: l,
|
|
458
510
|
useGasCoin: !0
|
|
459
511
|
});
|
|
460
|
-
if (
|
|
512
|
+
if (B(t) !== B(a.suiCoinType)) {
|
|
461
513
|
const w = await this.walletClient.swap.getQuote(t, a.suiCoinType, l);
|
|
462
514
|
u = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
463
515
|
i,
|
|
@@ -466,45 +518,45 @@ async function X(i, t, n, e) {
|
|
|
466
518
|
c
|
|
467
519
|
);
|
|
468
520
|
}
|
|
469
|
-
return await
|
|
521
|
+
return await A(i, a, u, this.naviServiceOptions), i;
|
|
470
522
|
}
|
|
471
|
-
class
|
|
523
|
+
class _t {
|
|
472
524
|
constructor(t) {
|
|
473
525
|
this.name = "navi", this.walletClient = t;
|
|
474
526
|
}
|
|
475
527
|
async getPool(t) {
|
|
476
|
-
const
|
|
477
|
-
(o) => o.pool.suiCoinType ===
|
|
478
|
-
), a = s ? new
|
|
528
|
+
const e = await this.walletClient.lending.getPool(t), s = (await this.walletClient.lending.getLendingState()).find(
|
|
529
|
+
(o) => o.pool.suiCoinType === B(t)
|
|
530
|
+
), a = s ? new E(s.supplyBalance).toNumber() : 0, r = s ? new E(s.borrowBalance).toNumber() : 0;
|
|
479
531
|
return {
|
|
480
532
|
supplyBalance: a,
|
|
481
533
|
borrowBalance: r,
|
|
482
|
-
borrowAPR: parseFloat(
|
|
534
|
+
borrowAPR: parseFloat(e.borrowIncentiveApyInfo.apy)
|
|
483
535
|
};
|
|
484
536
|
}
|
|
485
|
-
async depositCoinPTB(t,
|
|
537
|
+
async depositCoinPTB(t, e, n, s) {
|
|
486
538
|
throw new Error("Not implemented");
|
|
487
539
|
}
|
|
488
|
-
async withdrawCoinPTB(t,
|
|
489
|
-
return
|
|
540
|
+
async withdrawCoinPTB(t, e, n) {
|
|
541
|
+
return ot(t, e, n, this.walletClient.lending.naviServiceOptions);
|
|
490
542
|
}
|
|
491
|
-
async borrowCoinPTB(t,
|
|
543
|
+
async borrowCoinPTB(t, e, n) {
|
|
492
544
|
throw new Error("Not implemented");
|
|
493
545
|
}
|
|
494
|
-
async repayCoinPTB(t,
|
|
495
|
-
|
|
546
|
+
async repayCoinPTB(t, e, n, s) {
|
|
547
|
+
rt(t, e, n, {
|
|
496
548
|
...this.walletClient.lending.naviServiceOptions,
|
|
497
549
|
amount: s
|
|
498
550
|
});
|
|
499
551
|
}
|
|
500
552
|
}
|
|
501
|
-
class
|
|
553
|
+
class Ut extends k {
|
|
502
554
|
constructor() {
|
|
503
555
|
super(), this.name = "lending", this.defaultConfig = {
|
|
504
556
|
env: "prod",
|
|
505
557
|
protocols: [],
|
|
506
558
|
enableSuilend: !0
|
|
507
|
-
}, this._protocols = [], this.migrateBetweenSupplyPTB =
|
|
559
|
+
}, this._protocols = [], this.migrateBetweenSupplyPTB = V, this.migrateBetweenBorrowPTB = X, this.migrateBalanceToSupplyPTB = Y, this.migrateBetweenSupplyPTB = V.bind(this), this.migrateBetweenBorrowPTB = X.bind(this), this.migrateBalanceToSupplyPTB = Y.bind(this);
|
|
508
560
|
}
|
|
509
561
|
/** Get protocols (either from internal storage or config) */
|
|
510
562
|
get protocols() {
|
|
@@ -520,7 +572,7 @@ class At extends j {
|
|
|
520
572
|
super.install(t), this._protocols = [];
|
|
521
573
|
}
|
|
522
574
|
async getProtocol(t) {
|
|
523
|
-
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((
|
|
575
|
+
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((e) => e.name === t);
|
|
524
576
|
}
|
|
525
577
|
/**
|
|
526
578
|
* Gets all available lending pools
|
|
@@ -529,7 +581,7 @@ class At extends j {
|
|
|
529
581
|
* @returns Array of pool information
|
|
530
582
|
*/
|
|
531
583
|
async getPools(t) {
|
|
532
|
-
return await
|
|
584
|
+
return await Ct({
|
|
533
585
|
...this.naviServiceOptions,
|
|
534
586
|
env: this.config.env,
|
|
535
587
|
...t
|
|
@@ -542,11 +594,11 @@ class At extends j {
|
|
|
542
594
|
* @param options - Optional caching options
|
|
543
595
|
* @returns Pool information
|
|
544
596
|
*/
|
|
545
|
-
async getPool(t,
|
|
546
|
-
return await
|
|
597
|
+
async getPool(t, e) {
|
|
598
|
+
return await P(t, {
|
|
547
599
|
...this.naviServiceOptions,
|
|
548
600
|
env: this.config.env,
|
|
549
|
-
...
|
|
601
|
+
...e
|
|
550
602
|
});
|
|
551
603
|
}
|
|
552
604
|
/**
|
|
@@ -557,31 +609,31 @@ class At extends j {
|
|
|
557
609
|
* @param options - Optional parameters including dry run mode and account capability
|
|
558
610
|
* @returns Transaction response or dry run response
|
|
559
611
|
*/
|
|
560
|
-
async deposit(t,
|
|
612
|
+
async deposit(t, e, n) {
|
|
561
613
|
if (!this.walletClient)
|
|
562
614
|
throw new Error("Wallet client not found");
|
|
563
|
-
const s = await
|
|
615
|
+
const s = await P(t, {
|
|
564
616
|
...this.naviServiceOptions,
|
|
565
617
|
env: this.config.env
|
|
566
618
|
});
|
|
567
619
|
await this.walletClient.module("balance").waitForUpdate();
|
|
568
|
-
const a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o =
|
|
569
|
-
balance:
|
|
620
|
+
const a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
|
|
621
|
+
balance: e,
|
|
570
622
|
useGasCoin: !0
|
|
571
623
|
});
|
|
572
|
-
await
|
|
624
|
+
await A(a, s, o, {
|
|
573
625
|
...this.naviServiceOptions,
|
|
574
626
|
env: this.config.env,
|
|
575
|
-
amount:
|
|
576
|
-
accountCap:
|
|
627
|
+
amount: e,
|
|
628
|
+
accountCap: n?.accountCap
|
|
577
629
|
});
|
|
578
630
|
const l = await this.walletClient.signExecuteTransaction({
|
|
579
631
|
transaction: a,
|
|
580
|
-
dryRun:
|
|
632
|
+
dryRun: n?.dryRun ?? !1
|
|
581
633
|
});
|
|
582
|
-
return !
|
|
634
|
+
return !n?.dryRun && p(l) && (this.emit("lending:deposit-success", {
|
|
583
635
|
identifier: t,
|
|
584
|
-
amount:
|
|
636
|
+
amount: e
|
|
585
637
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
586
638
|
}
|
|
587
639
|
/**
|
|
@@ -592,27 +644,27 @@ class At extends j {
|
|
|
592
644
|
* @param options - Optional parameters including dry run mode and account capability
|
|
593
645
|
* @returns Transaction response or dry run response
|
|
594
646
|
*/
|
|
595
|
-
async withdraw(t,
|
|
647
|
+
async withdraw(t, e, n) {
|
|
596
648
|
if (!this.walletClient)
|
|
597
649
|
throw new Error("Wallet client not found");
|
|
598
|
-
const s = await
|
|
650
|
+
const s = await P(t, {
|
|
599
651
|
...this.naviServiceOptions,
|
|
600
652
|
env: this.config.env
|
|
601
653
|
}), a = new h();
|
|
602
|
-
|
|
603
|
-
const r = await
|
|
654
|
+
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
655
|
+
const r = await ot(a, s, e, {
|
|
604
656
|
...this.naviServiceOptions,
|
|
605
657
|
env: this.config.env,
|
|
606
|
-
accountCap:
|
|
658
|
+
accountCap: n?.accountCap
|
|
607
659
|
});
|
|
608
660
|
a.transferObjects([r], this.walletClient.address);
|
|
609
661
|
const o = await this.walletClient.signExecuteTransaction({
|
|
610
662
|
transaction: a,
|
|
611
|
-
dryRun:
|
|
663
|
+
dryRun: n?.dryRun ?? !1
|
|
612
664
|
});
|
|
613
|
-
return !
|
|
665
|
+
return !n?.dryRun && p(o) && (this.emit("lending:withdraw-success", {
|
|
614
666
|
identifier: t,
|
|
615
|
-
amount:
|
|
667
|
+
amount: e
|
|
616
668
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
617
669
|
}
|
|
618
670
|
/**
|
|
@@ -623,27 +675,27 @@ class At extends j {
|
|
|
623
675
|
* @param options - Optional parameters including dry run mode and account capability
|
|
624
676
|
* @returns Transaction response or dry run response
|
|
625
677
|
*/
|
|
626
|
-
async borrow(t,
|
|
678
|
+
async borrow(t, e, n) {
|
|
627
679
|
if (!this.walletClient)
|
|
628
680
|
throw new Error("Wallet client not found");
|
|
629
|
-
const s = await
|
|
681
|
+
const s = await P(t, {
|
|
630
682
|
...this.naviServiceOptions,
|
|
631
683
|
env: this.config.env
|
|
632
684
|
}), a = new h();
|
|
633
|
-
|
|
634
|
-
const r = await
|
|
685
|
+
n?.disableUpdateOracle || await this.updateOraclePTB(a, [s]);
|
|
686
|
+
const r = await st(a, s, e, {
|
|
635
687
|
...this.naviServiceOptions,
|
|
636
688
|
env: this.config.env,
|
|
637
|
-
accountCap:
|
|
689
|
+
accountCap: n?.accountCap
|
|
638
690
|
});
|
|
639
691
|
a.transferObjects([r], this.walletClient.address);
|
|
640
692
|
const o = await this.walletClient.signExecuteTransaction({
|
|
641
693
|
transaction: a,
|
|
642
|
-
dryRun:
|
|
694
|
+
dryRun: n?.dryRun ?? !1
|
|
643
695
|
});
|
|
644
|
-
return !
|
|
696
|
+
return !n?.dryRun && p(o) && (this.emit("lending:borrow-success", {
|
|
645
697
|
identifier: t,
|
|
646
|
-
amount:
|
|
698
|
+
amount: e
|
|
647
699
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
648
700
|
}
|
|
649
701
|
/**
|
|
@@ -654,30 +706,30 @@ class At extends j {
|
|
|
654
706
|
* @param options - Optional parameters including dry run mode and account capability
|
|
655
707
|
* @returns Transaction response or dry run response
|
|
656
708
|
*/
|
|
657
|
-
async repay(t,
|
|
709
|
+
async repay(t, e, n) {
|
|
658
710
|
if (!this.walletClient)
|
|
659
711
|
throw new Error("Wallet client not found");
|
|
660
712
|
await this.walletClient.module("balance").waitForUpdate();
|
|
661
|
-
const s = await
|
|
713
|
+
const s = await P(t, {
|
|
662
714
|
...this.naviServiceOptions,
|
|
663
715
|
env: this.config.env
|
|
664
|
-
}), a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o =
|
|
665
|
-
balance:
|
|
716
|
+
}), a = new h(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), o = m(a, r.coins, {
|
|
717
|
+
balance: e,
|
|
666
718
|
useGasCoin: !0
|
|
667
719
|
});
|
|
668
|
-
await
|
|
720
|
+
await rt(a, s, o, {
|
|
669
721
|
...this.naviServiceOptions,
|
|
670
722
|
env: this.config.env,
|
|
671
|
-
amount:
|
|
672
|
-
accountCap:
|
|
723
|
+
amount: e,
|
|
724
|
+
accountCap: n?.accountCap
|
|
673
725
|
});
|
|
674
726
|
const l = await this.walletClient.signExecuteTransaction({
|
|
675
727
|
transaction: a,
|
|
676
|
-
dryRun:
|
|
728
|
+
dryRun: n?.dryRun ?? !1
|
|
677
729
|
});
|
|
678
|
-
return !
|
|
730
|
+
return !n?.dryRun && p(l) && (this.emit("lending:repay-success", {
|
|
679
731
|
identifier: t,
|
|
680
|
-
amount:
|
|
732
|
+
amount: e
|
|
681
733
|
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
682
734
|
}
|
|
683
735
|
/**
|
|
@@ -689,7 +741,7 @@ class At extends j {
|
|
|
689
741
|
if (!this.walletClient)
|
|
690
742
|
throw new Error("Wallet client not found");
|
|
691
743
|
const t = this.walletClient.address;
|
|
692
|
-
return await
|
|
744
|
+
return await yt(t, {
|
|
693
745
|
...this.naviServiceOptions,
|
|
694
746
|
env: this.config.env,
|
|
695
747
|
client: this.walletClient.client
|
|
@@ -705,19 +757,19 @@ class At extends j {
|
|
|
705
757
|
* @param options - Optional parameters including dry run mode
|
|
706
758
|
* @returns Transaction response or dry run response
|
|
707
759
|
*/
|
|
708
|
-
async liquidate(t,
|
|
760
|
+
async liquidate(t, e, n, s, a) {
|
|
709
761
|
if (!this.walletClient)
|
|
710
762
|
throw new Error("Wallet client not found");
|
|
711
|
-
const r = await
|
|
763
|
+
const r = await P(t, {
|
|
712
764
|
...this.naviServiceOptions,
|
|
713
765
|
env: this.config.env
|
|
714
|
-
}), o = await
|
|
766
|
+
}), o = await P(n, {
|
|
715
767
|
...this.naviServiceOptions,
|
|
716
768
|
env: this.config.env
|
|
717
|
-
}), l = new h(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u =
|
|
718
|
-
balance:
|
|
769
|
+
}), l = new h(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u = m(l, c.coins, {
|
|
770
|
+
balance: e,
|
|
719
771
|
useGasCoin: !0
|
|
720
|
-
}), [w, d] = await
|
|
772
|
+
}), [w, d] = await bt(
|
|
721
773
|
l,
|
|
722
774
|
r,
|
|
723
775
|
u,
|
|
@@ -731,22 +783,22 @@ class At extends j {
|
|
|
731
783
|
target: "0x2::coin::from_balance",
|
|
732
784
|
arguments: [w],
|
|
733
785
|
typeArguments: [o.suiCoinType]
|
|
734
|
-
}), [
|
|
786
|
+
}), [C] = l.moveCall({
|
|
735
787
|
target: "0x2::coin::from_balance",
|
|
736
788
|
arguments: [d],
|
|
737
789
|
typeArguments: [r.suiCoinType]
|
|
738
790
|
});
|
|
739
|
-
l.transferObjects([f,
|
|
740
|
-
const
|
|
791
|
+
l.transferObjects([f, C], this.walletClient.address);
|
|
792
|
+
const y = await this.walletClient.signExecuteTransaction({
|
|
741
793
|
transaction: l,
|
|
742
794
|
dryRun: a?.dryRun ?? !1
|
|
743
795
|
});
|
|
744
|
-
return !a?.dryRun &&
|
|
796
|
+
return !a?.dryRun && p(y) && (this.emit("lending:liquidate-success", {
|
|
745
797
|
payIdentifier: t,
|
|
746
|
-
payAmount:
|
|
747
|
-
collateralIdentifier:
|
|
798
|
+
payAmount: e,
|
|
799
|
+
collateralIdentifier: n,
|
|
748
800
|
liquidationAddress: s
|
|
749
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
801
|
+
}), this.walletClient.module("balance").updatePortfolio()), y;
|
|
750
802
|
}
|
|
751
803
|
/**
|
|
752
804
|
* Gets the available lending rewards for the current user.
|
|
@@ -758,10 +810,11 @@ class At extends j {
|
|
|
758
810
|
async getAvailableRewards(t) {
|
|
759
811
|
if (!this.walletClient)
|
|
760
812
|
throw new Error("Wallet client not found");
|
|
761
|
-
return
|
|
813
|
+
return D(this.walletClient.address, {
|
|
762
814
|
...this.naviServiceOptions,
|
|
763
815
|
...t,
|
|
764
|
-
env: this.config.env
|
|
816
|
+
env: this.config.env,
|
|
817
|
+
client: this.walletClient.client
|
|
765
818
|
});
|
|
766
819
|
}
|
|
767
820
|
/**
|
|
@@ -774,7 +827,7 @@ class At extends j {
|
|
|
774
827
|
async getClaimedRewardHistory(t) {
|
|
775
828
|
if (!this.walletClient)
|
|
776
829
|
throw new Error("Wallet client not found");
|
|
777
|
-
return
|
|
830
|
+
return vt(this.walletClient.address, {
|
|
778
831
|
...this.naviServiceOptions,
|
|
779
832
|
...t
|
|
780
833
|
});
|
|
@@ -788,37 +841,39 @@ class At extends j {
|
|
|
788
841
|
async claimAllRewards(t) {
|
|
789
842
|
if (!this.walletClient)
|
|
790
843
|
throw new Error("Wallet client not found");
|
|
791
|
-
const
|
|
844
|
+
const e = new h(), n = await D(this.walletClient.address, {
|
|
792
845
|
...this.naviServiceOptions,
|
|
793
|
-
env: this.config.env
|
|
846
|
+
env: this.config.env,
|
|
847
|
+
client: this.walletClient.client
|
|
794
848
|
});
|
|
795
|
-
await
|
|
849
|
+
await Bt(e, n, {
|
|
796
850
|
...this.naviServiceOptions,
|
|
797
851
|
env: this.config.env,
|
|
798
852
|
accountCap: t?.accountCap
|
|
799
853
|
});
|
|
800
854
|
const s = await this.walletClient.signExecuteTransaction({
|
|
801
|
-
transaction:
|
|
855
|
+
transaction: e,
|
|
802
856
|
dryRun: t?.dryRun ?? !1
|
|
803
857
|
});
|
|
804
|
-
return !t?.dryRun && s
|
|
805
|
-
rewards:
|
|
858
|
+
return !t?.dryRun && p(s) && (this.emit("lending:claim-rewards-success", {
|
|
859
|
+
rewards: n
|
|
806
860
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
807
861
|
}
|
|
808
|
-
async updateOraclePTB(t,
|
|
809
|
-
const
|
|
862
|
+
async updateOraclePTB(t, e) {
|
|
863
|
+
const n = await $({
|
|
810
864
|
...this.naviServiceOptions,
|
|
811
865
|
env: this.config.env
|
|
812
866
|
}), s = await this.getLendingState({
|
|
813
867
|
cacheTime: 60 * 1e3
|
|
814
|
-
}), a = q(
|
|
868
|
+
}), a = q(n, {
|
|
815
869
|
lendingState: s,
|
|
816
|
-
pools:
|
|
870
|
+
pools: e
|
|
817
871
|
});
|
|
818
|
-
await
|
|
872
|
+
await K(t, a, {
|
|
819
873
|
...this.naviServiceOptions,
|
|
820
874
|
env: this.config.env,
|
|
821
|
-
updatePythPriceFeeds: !0
|
|
875
|
+
updatePythPriceFeeds: !0,
|
|
876
|
+
client: this.walletClient?.client
|
|
822
877
|
});
|
|
823
878
|
}
|
|
824
879
|
/**
|
|
@@ -831,9 +886,9 @@ class At extends j {
|
|
|
831
886
|
async updateOracle(t) {
|
|
832
887
|
if (!this.walletClient)
|
|
833
888
|
throw new Error("Wallet client not found");
|
|
834
|
-
const
|
|
835
|
-
return await this.updateOraclePTB(
|
|
836
|
-
transaction:
|
|
889
|
+
const e = new h();
|
|
890
|
+
return await this.updateOraclePTB(e, t?.pools), await this.walletClient.signExecuteTransaction({
|
|
891
|
+
transaction: e,
|
|
837
892
|
dryRun: t?.dryRun ?? !1
|
|
838
893
|
});
|
|
839
894
|
}
|
|
@@ -846,7 +901,7 @@ class At extends j {
|
|
|
846
901
|
async getLendingState(t) {
|
|
847
902
|
if (!this.walletClient)
|
|
848
903
|
throw new Error("Wallet client not found");
|
|
849
|
-
return await
|
|
904
|
+
return await Tt(this.walletClient.address, {
|
|
850
905
|
...this.naviServiceOptions,
|
|
851
906
|
env: this.config.env,
|
|
852
907
|
...t,
|
|
@@ -862,9 +917,9 @@ class At extends j {
|
|
|
862
917
|
async createAccountCap(t) {
|
|
863
918
|
if (!this.walletClient)
|
|
864
919
|
throw new Error("Wallet client not found");
|
|
865
|
-
const
|
|
866
|
-
return
|
|
867
|
-
transaction:
|
|
920
|
+
const e = new h(), n = await Pt(e);
|
|
921
|
+
return e.transferObjects([n], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
922
|
+
transaction: e,
|
|
868
923
|
dryRun: t?.dryRun ?? !1
|
|
869
924
|
});
|
|
870
925
|
}
|
|
@@ -874,33 +929,33 @@ class At extends j {
|
|
|
874
929
|
return;
|
|
875
930
|
}
|
|
876
931
|
const t = [];
|
|
877
|
-
if (t.push(new
|
|
932
|
+
if (t.push(new _t(this.walletClient)), this.config.enableSuilend)
|
|
878
933
|
try {
|
|
879
|
-
const { default:
|
|
934
|
+
const { default: e } = await import("./suilend-CWugUjwd.js");
|
|
880
935
|
t.push(
|
|
881
|
-
await
|
|
936
|
+
await e.create(this.walletClient, {
|
|
882
937
|
grpcClient: this.config.suilendGrpcClient,
|
|
883
938
|
grpcUrl: this.config.suilendGrpcUrl
|
|
884
939
|
})
|
|
885
940
|
);
|
|
886
|
-
} catch (
|
|
887
|
-
console.warn("Failed to initialize SuilendProtocol:",
|
|
941
|
+
} catch (e) {
|
|
942
|
+
console.warn("Failed to initialize SuilendProtocol:", e);
|
|
888
943
|
}
|
|
889
944
|
this._protocols = t;
|
|
890
945
|
}
|
|
891
946
|
}
|
|
892
|
-
class
|
|
947
|
+
class Wt extends k {
|
|
893
948
|
constructor() {
|
|
894
949
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
895
950
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
896
951
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
897
952
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
898
953
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
899
|
-
}, this.getStatsCached =
|
|
900
|
-
|
|
901
|
-
const
|
|
902
|
-
return (await fetch(
|
|
903
|
-
headers:
|
|
954
|
+
}, this.getStatsCached = lt(
|
|
955
|
+
Q(async (t) => {
|
|
956
|
+
const e = { services: t?.services }, n = ct(e);
|
|
957
|
+
return (await fetch(ut("/volo/stats", e), {
|
|
958
|
+
headers: ht({}, n)
|
|
904
959
|
}).then((a) => a.json())).data;
|
|
905
960
|
})
|
|
906
961
|
);
|
|
@@ -917,18 +972,18 @@ class jt extends j {
|
|
|
917
972
|
* @param suiCoin - The SUI coin object to stake
|
|
918
973
|
* @returns The vSUI coin object received from staking
|
|
919
974
|
*/
|
|
920
|
-
async stakePTB(t,
|
|
921
|
-
const [
|
|
975
|
+
async stakePTB(t, e) {
|
|
976
|
+
const [n] = t.moveCall({
|
|
922
977
|
target: `${this.config.packageId}::stake_pool::stake`,
|
|
923
978
|
arguments: [
|
|
924
979
|
t.object(this.config.poolId),
|
|
925
980
|
t.object(this.config.metadataId),
|
|
926
981
|
t.object("0x05"),
|
|
927
|
-
|
|
982
|
+
F(e, t.object)
|
|
928
983
|
],
|
|
929
984
|
typeArguments: []
|
|
930
985
|
});
|
|
931
|
-
return
|
|
986
|
+
return n;
|
|
932
987
|
}
|
|
933
988
|
/**
|
|
934
989
|
* Adds unstaking operation to a transaction black
|
|
@@ -937,18 +992,18 @@ class jt extends j {
|
|
|
937
992
|
* @param vSuiCoin - The vSUI coin object to unstake
|
|
938
993
|
* @returns The SUI coin object received from unstaking
|
|
939
994
|
*/
|
|
940
|
-
async unstakePTB(t,
|
|
941
|
-
const [
|
|
995
|
+
async unstakePTB(t, e) {
|
|
996
|
+
const [n] = t.moveCall({
|
|
942
997
|
target: `${this.config.packageId}::stake_pool::unstake`,
|
|
943
998
|
arguments: [
|
|
944
999
|
t.object(this.config.poolId),
|
|
945
1000
|
t.object(this.config.metadataId),
|
|
946
1001
|
t.object("0x05"),
|
|
947
|
-
|
|
1002
|
+
F(e, t.object)
|
|
948
1003
|
],
|
|
949
1004
|
typeArguments: []
|
|
950
1005
|
});
|
|
951
|
-
return
|
|
1006
|
+
return n;
|
|
952
1007
|
}
|
|
953
1008
|
/**
|
|
954
1009
|
* Stake SUI tokens to receive vSUI tokens
|
|
@@ -958,23 +1013,23 @@ class jt extends j {
|
|
|
958
1013
|
* @returns Transaction response or dry run response
|
|
959
1014
|
* @throws Error if wallet client not found or stake amount is too low
|
|
960
1015
|
*/
|
|
961
|
-
async stake(t,
|
|
1016
|
+
async stake(t, e) {
|
|
962
1017
|
if (!this.walletClient)
|
|
963
1018
|
throw new Error("Wallet client not found");
|
|
964
1019
|
if (t < 1e9)
|
|
965
1020
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
966
|
-
const
|
|
1021
|
+
const n = new h();
|
|
967
1022
|
await this.walletClient.module("balance").waitForUpdate();
|
|
968
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a =
|
|
1023
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
|
|
969
1024
|
balance: t,
|
|
970
1025
|
useGasCoin: !0
|
|
971
|
-
}), r = await this.stakePTB(
|
|
972
|
-
|
|
1026
|
+
}), r = await this.stakePTB(n, a);
|
|
1027
|
+
n.transferObjects([r], this.walletClient.address);
|
|
973
1028
|
const o = await this.walletClient.signExecuteTransaction({
|
|
974
|
-
transaction:
|
|
975
|
-
dryRun:
|
|
1029
|
+
transaction: n,
|
|
1030
|
+
dryRun: e?.dryRun ?? !1
|
|
976
1031
|
});
|
|
977
|
-
return !
|
|
1032
|
+
return !e?.dryRun && p(o) && (this.emit("volo:stake-success", {
|
|
978
1033
|
suiAmount: t
|
|
979
1034
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
980
1035
|
}
|
|
@@ -986,75 +1041,27 @@ class jt extends j {
|
|
|
986
1041
|
* @returns Transaction response or dry run response
|
|
987
1042
|
* @throws Error if wallet client not found or unstake amount is too low
|
|
988
1043
|
*/
|
|
989
|
-
async unstake(t,
|
|
1044
|
+
async unstake(t, e) {
|
|
990
1045
|
if (!this.walletClient)
|
|
991
1046
|
throw new Error("Wallet client not found");
|
|
992
1047
|
if (t < 1e9)
|
|
993
1048
|
throw new Error("Unstake amount should >= 1vSui");
|
|
994
1049
|
await this.walletClient.module("balance").waitForUpdate();
|
|
995
|
-
const
|
|
1050
|
+
const n = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
|
|
996
1051
|
balance: t
|
|
997
|
-
}), r = await this.unstakePTB(
|
|
998
|
-
|
|
1052
|
+
}), r = await this.unstakePTB(n, a);
|
|
1053
|
+
n.transferObjects([r], this.walletClient.address);
|
|
999
1054
|
const o = await this.walletClient.signExecuteTransaction({
|
|
1000
|
-
transaction:
|
|
1001
|
-
dryRun:
|
|
1055
|
+
transaction: n,
|
|
1056
|
+
dryRun: e?.dryRun ?? !1
|
|
1002
1057
|
});
|
|
1003
|
-
return !
|
|
1058
|
+
return !e?.dryRun && p(o) && (this.emit("volo:unstake-success", {
|
|
1004
1059
|
vSuiAmount: t
|
|
1005
1060
|
}), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1006
1061
|
}
|
|
1007
1062
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
showEvents: !0,
|
|
1011
|
-
showBalanceChanges: !0,
|
|
1012
|
-
showObjectChanges: !0
|
|
1013
|
-
};
|
|
1014
|
-
function G(i) {
|
|
1015
|
-
return {
|
|
1016
|
-
...K,
|
|
1017
|
-
...i
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
function R(i, t) {
|
|
1021
|
-
const e = kt(t ?? {}), s = Ft(e);
|
|
1022
|
-
return {
|
|
1023
|
-
...e,
|
|
1024
|
-
kind: i,
|
|
1025
|
-
effects: s,
|
|
1026
|
-
events: Nt(e.events),
|
|
1027
|
-
balanceChanges: Array.isArray(e.balanceChanges) ? e.balanceChanges : [],
|
|
1028
|
-
objectChanges: Array.isArray(e.objectChanges) ? e.objectChanges : []
|
|
1029
|
-
};
|
|
1030
|
-
}
|
|
1031
|
-
function kt(i) {
|
|
1032
|
-
const t = i.Transaction;
|
|
1033
|
-
if (A(t))
|
|
1034
|
-
return t;
|
|
1035
|
-
const n = i.FailedTransaction;
|
|
1036
|
-
return A(n) ? n : i;
|
|
1037
|
-
}
|
|
1038
|
-
function Ft(i) {
|
|
1039
|
-
if (A(i.effects))
|
|
1040
|
-
return i.effects;
|
|
1041
|
-
if (A(i.status))
|
|
1042
|
-
return {
|
|
1043
|
-
status: i.status
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
function Nt(i) {
|
|
1047
|
-
return Array.isArray(i) ? i.map((t) => A(t) ? {
|
|
1048
|
-
...t,
|
|
1049
|
-
type: t.type ?? t.eventType,
|
|
1050
|
-
parsedJson: t.parsedJson ?? t.json
|
|
1051
|
-
} : t) : [];
|
|
1052
|
-
}
|
|
1053
|
-
function A(i) {
|
|
1054
|
-
return typeof i == "object" && i !== null;
|
|
1055
|
-
}
|
|
1056
|
-
function _t() {
|
|
1057
|
-
const i = G(K);
|
|
1063
|
+
function It() {
|
|
1064
|
+
const i = H(G);
|
|
1058
1065
|
return {
|
|
1059
1066
|
effects: i.showEffects,
|
|
1060
1067
|
events: i.showEvents,
|
|
@@ -1062,14 +1069,10 @@ function _t() {
|
|
|
1062
1069
|
objectTypes: i.showObjectChanges
|
|
1063
1070
|
};
|
|
1064
1071
|
}
|
|
1065
|
-
function
|
|
1072
|
+
function Jt(i) {
|
|
1066
1073
|
return i.core;
|
|
1067
1074
|
}
|
|
1068
|
-
|
|
1069
|
-
const t = i.effects?.status;
|
|
1070
|
-
return t?.status === "success" || t?.success === !0;
|
|
1071
|
-
}
|
|
1072
|
-
class It extends j {
|
|
1075
|
+
class Lt extends k {
|
|
1073
1076
|
constructor() {
|
|
1074
1077
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1075
1078
|
apiKey: "",
|
|
@@ -1086,7 +1089,7 @@ class It extends j {
|
|
|
1086
1089
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
1087
1090
|
*/
|
|
1088
1091
|
get referral() {
|
|
1089
|
-
return this.config.apiKey ?
|
|
1092
|
+
return this.config.apiKey ? Rt(this.config.apiKey) : 0;
|
|
1090
1093
|
}
|
|
1091
1094
|
/**
|
|
1092
1095
|
* Get the swap options
|
|
@@ -1108,8 +1111,8 @@ class It extends j {
|
|
|
1108
1111
|
* @param fromAmount - The amount of the coin being swapped from
|
|
1109
1112
|
* @returns A promise that resolves with the quote
|
|
1110
1113
|
*/
|
|
1111
|
-
async getQuote(t,
|
|
1112
|
-
return
|
|
1114
|
+
async getQuote(t, e, n) {
|
|
1115
|
+
return xt(t, e, n, this.config.apiKey, this.swapOptions);
|
|
1113
1116
|
}
|
|
1114
1117
|
/**
|
|
1115
1118
|
* Builds a swap transaction from a quote
|
|
@@ -1119,16 +1122,16 @@ class It extends j {
|
|
|
1119
1122
|
* @param slippage - The slippage tolerance
|
|
1120
1123
|
* @returns The swap transaction
|
|
1121
1124
|
*/
|
|
1122
|
-
async buildSwapPTBFromQuote(t,
|
|
1125
|
+
async buildSwapPTBFromQuote(t, e, n, s) {
|
|
1123
1126
|
if (!this.walletClient)
|
|
1124
1127
|
throw new Error("Wallet client not found");
|
|
1125
|
-
const a = new
|
|
1128
|
+
const a = new E(e.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
1126
1129
|
return await z(
|
|
1127
1130
|
this.walletClient.address,
|
|
1128
1131
|
t,
|
|
1129
1132
|
Number(a),
|
|
1130
|
-
e,
|
|
1131
1133
|
n,
|
|
1134
|
+
e,
|
|
1132
1135
|
this.referral,
|
|
1133
1136
|
!1,
|
|
1134
1137
|
this.config.apiKey,
|
|
@@ -1152,14 +1155,14 @@ class It extends j {
|
|
|
1152
1155
|
* @param options - Optional parameters including dry run mode
|
|
1153
1156
|
* @returns Transaction response or dry run response
|
|
1154
1157
|
*/
|
|
1155
|
-
async swap(t,
|
|
1158
|
+
async swap(t, e, n, s, a) {
|
|
1156
1159
|
if (!this.walletClient)
|
|
1157
1160
|
throw new Error("Wallet client not found");
|
|
1158
1161
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1159
|
-
const r = this.walletClient.module("balance").portfolio.getBalance(t), o = new h(), l =
|
|
1160
|
-
balance:
|
|
1162
|
+
const r = this.walletClient.module("balance").portfolio.getBalance(t), o = new h(), l = m(o, r.coins, {
|
|
1163
|
+
balance: n,
|
|
1161
1164
|
useGasCoin: !0
|
|
1162
|
-
}), c = await this.getQuote(t,
|
|
1165
|
+
}), c = await this.getQuote(t, e, n), u = await this.buildSwapPTBFromQuote(o, c, l, s);
|
|
1163
1166
|
if (o.transferObjects([u], this.walletClient.address), o.setSender(this.walletClient.address), a?.dryRun)
|
|
1164
1167
|
return await this.walletClient.signExecuteTransaction({
|
|
1165
1168
|
transaction: o,
|
|
@@ -1169,14 +1172,14 @@ class It extends j {
|
|
|
1169
1172
|
client: this.walletClient.client
|
|
1170
1173
|
}), d = await this.walletClient.signer.signTransaction(w), f = [d.signature];
|
|
1171
1174
|
try {
|
|
1172
|
-
await
|
|
1175
|
+
await At(d.bytes, f);
|
|
1173
1176
|
} catch (g) {
|
|
1174
1177
|
console.error(g);
|
|
1175
1178
|
}
|
|
1176
|
-
const
|
|
1177
|
-
transaction:
|
|
1179
|
+
const C = Jt(this.walletClient.client), y = typeof C?.executeTransaction == "function" ? await C.executeTransaction({
|
|
1180
|
+
transaction: dt(d.bytes),
|
|
1178
1181
|
signatures: f,
|
|
1179
|
-
include:
|
|
1182
|
+
include: It()
|
|
1180
1183
|
}) : await (() => {
|
|
1181
1184
|
const g = this.walletClient.clientBundle.legacyJsonRpc;
|
|
1182
1185
|
if (!g)
|
|
@@ -1186,33 +1189,33 @@ class It extends j {
|
|
|
1186
1189
|
return g.executeTransactionBlock({
|
|
1187
1190
|
transactionBlock: d.bytes,
|
|
1188
1191
|
signature: f,
|
|
1189
|
-
options:
|
|
1192
|
+
options: G
|
|
1190
1193
|
});
|
|
1191
|
-
})(),
|
|
1192
|
-
if (
|
|
1193
|
-
const g =
|
|
1194
|
+
})(), b = x("execute", y);
|
|
1195
|
+
if (p(b)) {
|
|
1196
|
+
const g = b.events?.find((T) => T.type?.includes("::slippage::SwapEvent"));
|
|
1194
1197
|
g && this.emit("swap:swap-success", {
|
|
1195
1198
|
fromCoinType: t,
|
|
1196
|
-
toCoinType:
|
|
1197
|
-
fromAmount:
|
|
1199
|
+
toCoinType: e,
|
|
1200
|
+
fromAmount: n,
|
|
1198
1201
|
slippage: s,
|
|
1199
1202
|
toAmount: Number(g.parsedJson.amount_out)
|
|
1200
1203
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1201
1204
|
}
|
|
1202
|
-
return
|
|
1205
|
+
return b;
|
|
1203
1206
|
}
|
|
1204
1207
|
}
|
|
1205
|
-
class
|
|
1208
|
+
class Mt extends k {
|
|
1206
1209
|
constructor() {
|
|
1207
1210
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1208
1211
|
packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
|
|
1209
1212
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1210
1213
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1211
|
-
}, this.getApyCached =
|
|
1212
|
-
|
|
1213
|
-
const
|
|
1214
|
-
return (await fetch(
|
|
1215
|
-
headers:
|
|
1214
|
+
}, this.getApyCached = lt(
|
|
1215
|
+
Q(async (t) => {
|
|
1216
|
+
const e = { services: t?.services }, n = ct(e);
|
|
1217
|
+
return (await fetch(ut("/haedal/stats", e), {
|
|
1218
|
+
headers: ht({}, n)
|
|
1216
1219
|
}).then((a) => a.json())).data.apy;
|
|
1217
1220
|
})
|
|
1218
1221
|
);
|
|
@@ -1229,18 +1232,18 @@ class Jt extends j {
|
|
|
1229
1232
|
* @param suiCoin - Sui coin object to stake
|
|
1230
1233
|
* @returns haSUI coin object
|
|
1231
1234
|
*/
|
|
1232
|
-
async stakePTB(t,
|
|
1233
|
-
const [
|
|
1235
|
+
async stakePTB(t, e) {
|
|
1236
|
+
const [n] = t.moveCall({
|
|
1234
1237
|
target: `${this.config.packageId}::staking::request_stake_coin`,
|
|
1235
1238
|
arguments: [
|
|
1236
1239
|
t.object("0x05"),
|
|
1237
1240
|
t.object(this.config.configId),
|
|
1238
|
-
|
|
1241
|
+
F(e, t.object),
|
|
1239
1242
|
t.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1240
1243
|
],
|
|
1241
1244
|
typeArguments: []
|
|
1242
1245
|
});
|
|
1243
|
-
return
|
|
1246
|
+
return n;
|
|
1244
1247
|
}
|
|
1245
1248
|
/**
|
|
1246
1249
|
* Builds a transaction block for unstaking haSUI to SUI
|
|
@@ -1249,17 +1252,17 @@ class Jt extends j {
|
|
|
1249
1252
|
* @param haSUICoin - haSUI coin object to unstake
|
|
1250
1253
|
* @returns SUI coin object
|
|
1251
1254
|
*/
|
|
1252
|
-
async unstakePTB(t,
|
|
1253
|
-
const [
|
|
1255
|
+
async unstakePTB(t, e) {
|
|
1256
|
+
const [n] = t.moveCall({
|
|
1254
1257
|
target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
|
|
1255
1258
|
arguments: [
|
|
1256
1259
|
t.object("0x05"),
|
|
1257
1260
|
t.object(this.config.configId),
|
|
1258
|
-
|
|
1261
|
+
F(e, t.object)
|
|
1259
1262
|
],
|
|
1260
1263
|
typeArguments: []
|
|
1261
1264
|
});
|
|
1262
|
-
return
|
|
1265
|
+
return n;
|
|
1263
1266
|
}
|
|
1264
1267
|
/**
|
|
1265
1268
|
* Stake SUI for haSUI
|
|
@@ -1267,21 +1270,21 @@ class Jt extends j {
|
|
|
1267
1270
|
* @param suiAmount - Amount of SUI to stake
|
|
1268
1271
|
* @param options Optional dry run
|
|
1269
1272
|
*/
|
|
1270
|
-
async stake(t,
|
|
1273
|
+
async stake(t, e) {
|
|
1271
1274
|
if (!this.walletClient)
|
|
1272
1275
|
throw new Error("Wallet client not found");
|
|
1273
|
-
const
|
|
1276
|
+
const n = new h();
|
|
1274
1277
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1275
|
-
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a =
|
|
1278
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), a = m(n, s.coins, {
|
|
1276
1279
|
balance: t,
|
|
1277
1280
|
useGasCoin: !0
|
|
1278
|
-
}), r = await this.stakePTB(
|
|
1279
|
-
|
|
1281
|
+
}), r = await this.stakePTB(n, a);
|
|
1282
|
+
n.transferObjects([r], this.walletClient.address);
|
|
1280
1283
|
const o = await this.walletClient.signExecuteTransaction({
|
|
1281
|
-
transaction:
|
|
1282
|
-
dryRun:
|
|
1284
|
+
transaction: n,
|
|
1285
|
+
dryRun: e?.dryRun ?? !1
|
|
1283
1286
|
});
|
|
1284
|
-
return !
|
|
1287
|
+
return !e?.dryRun && p(o) && (this.emit("haedal:stake-success", { suiAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1285
1288
|
}
|
|
1286
1289
|
/**
|
|
1287
1290
|
* Unstake haSUI for SUI
|
|
@@ -1289,35 +1292,35 @@ class Jt extends j {
|
|
|
1289
1292
|
* @param haSUIAmount - Amount of haSUI to unstake
|
|
1290
1293
|
* @param options Optional dry run
|
|
1291
1294
|
*/
|
|
1292
|
-
async unstake(t,
|
|
1295
|
+
async unstake(t, e) {
|
|
1293
1296
|
if (!this.walletClient)
|
|
1294
1297
|
throw new Error("Wallet client not found");
|
|
1295
1298
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1296
|
-
const
|
|
1299
|
+
const n = new h(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), a = m(n, s.coins, {
|
|
1297
1300
|
balance: t
|
|
1298
|
-
}), r = await this.unstakePTB(
|
|
1299
|
-
|
|
1301
|
+
}), r = await this.unstakePTB(n, a);
|
|
1302
|
+
n.transferObjects([r], this.walletClient.address);
|
|
1300
1303
|
const o = await this.walletClient.signExecuteTransaction({
|
|
1301
|
-
transaction:
|
|
1302
|
-
dryRun:
|
|
1304
|
+
transaction: n,
|
|
1305
|
+
dryRun: e?.dryRun ?? !1
|
|
1303
1306
|
});
|
|
1304
|
-
return !
|
|
1307
|
+
return !e?.dryRun && p(o) && (this.emit("haedal:unstake-success", { haSUIAmount: t }), this.walletClient.module("balance").updatePortfolio()), o;
|
|
1305
1308
|
}
|
|
1306
1309
|
}
|
|
1307
|
-
const
|
|
1310
|
+
const Qt = {
|
|
1308
1311
|
/** Balance management module */
|
|
1309
|
-
balance: new
|
|
1312
|
+
balance: new jt(),
|
|
1310
1313
|
/** Lending protocol module */
|
|
1311
|
-
lending: new
|
|
1314
|
+
lending: new Ut(),
|
|
1312
1315
|
/** Volo protocol module */
|
|
1313
|
-
volo: new
|
|
1316
|
+
volo: new Wt(),
|
|
1314
1317
|
/** DEX swapping module */
|
|
1315
|
-
swap: new
|
|
1318
|
+
swap: new Lt(),
|
|
1316
1319
|
/** Haedal protocol module */
|
|
1317
|
-
haedal: new
|
|
1320
|
+
haedal: new Mt()
|
|
1318
1321
|
};
|
|
1319
|
-
function
|
|
1320
|
-
const t =
|
|
1322
|
+
function Z(i) {
|
|
1323
|
+
const t = H(i);
|
|
1321
1324
|
return {
|
|
1322
1325
|
effects: t.showEffects,
|
|
1323
1326
|
events: t.showEvents,
|
|
@@ -1325,34 +1328,39 @@ function Y(i) {
|
|
|
1325
1328
|
objectTypes: t.showObjectChanges
|
|
1326
1329
|
};
|
|
1327
1330
|
}
|
|
1328
|
-
function
|
|
1331
|
+
function tt(i) {
|
|
1329
1332
|
return i.core;
|
|
1330
1333
|
}
|
|
1331
|
-
function
|
|
1334
|
+
function $t(i) {
|
|
1332
1335
|
return "grpc" in i;
|
|
1333
1336
|
}
|
|
1334
|
-
function
|
|
1335
|
-
if (
|
|
1336
|
-
return
|
|
1337
|
-
const t = i.network ?? "mainnet",
|
|
1337
|
+
function Kt(i) {
|
|
1338
|
+
if ($t(i))
|
|
1339
|
+
return Ot(i);
|
|
1340
|
+
const t = i.network ?? "mainnet", e = Et(t, i.legacyJsonRpc);
|
|
1338
1341
|
return {
|
|
1339
1342
|
network: t,
|
|
1340
|
-
coreClient:
|
|
1341
|
-
grpc:
|
|
1342
|
-
legacyJsonRpc:
|
|
1343
|
+
coreClient: e,
|
|
1344
|
+
grpc: e,
|
|
1345
|
+
legacyJsonRpc: e,
|
|
1343
1346
|
services: i.services
|
|
1344
1347
|
};
|
|
1345
1348
|
}
|
|
1346
|
-
class
|
|
1349
|
+
class Zt {
|
|
1347
1350
|
/**
|
|
1348
1351
|
* Creates a new wallet client instance
|
|
1349
1352
|
* @param options - Configuration options for the wallet client
|
|
1350
1353
|
*/
|
|
1351
1354
|
constructor(t) {
|
|
1352
|
-
this.modules =
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1355
|
+
this.modules = Qt, this.userConfigs = {}, this.events = mt();
|
|
1356
|
+
const e = t.client ?? {
|
|
1357
|
+
network: "mainnet",
|
|
1358
|
+
grpc: { url: St }
|
|
1359
|
+
};
|
|
1360
|
+
this.clientBundle = Kt(e), this.client = this.clientBundle.coreClient, this.clientUrl = "grpc" in e ? e.legacyJsonRpc && "url" in e.legacyJsonRpc ? e.legacyJsonRpc.url : void 0 : "url" in e.legacyJsonRpc ? e.legacyJsonRpc.url : void 0, this.signer = t.signer, this.userConfigs = t.configs || {}, Object.entries(this.modules).forEach(([n, s]) => {
|
|
1361
|
+
if (n !== s.name)
|
|
1362
|
+
throw new Error(`Module name ${n} does not match module name ${s.name}`);
|
|
1363
|
+
s.install(this);
|
|
1356
1364
|
});
|
|
1357
1365
|
}
|
|
1358
1366
|
get lending() {
|
|
@@ -1376,16 +1384,16 @@ class Xt {
|
|
|
1376
1384
|
* @returns Promise with transaction execution result
|
|
1377
1385
|
*/
|
|
1378
1386
|
async signExecuteTransaction(t) {
|
|
1379
|
-
const { dryRun:
|
|
1380
|
-
if (
|
|
1381
|
-
const o =
|
|
1387
|
+
const { dryRun: e = !1, ...n } = t;
|
|
1388
|
+
if (e) {
|
|
1389
|
+
const o = tt(this.client);
|
|
1382
1390
|
if (typeof o?.simulateTransaction == "function") {
|
|
1383
1391
|
t.transaction instanceof h && t.transaction.setSenderIfNotSet(this.address);
|
|
1384
1392
|
const w = await o.simulateTransaction({
|
|
1385
1393
|
transaction: t.transaction,
|
|
1386
|
-
include:
|
|
1394
|
+
include: Z(n.options)
|
|
1387
1395
|
});
|
|
1388
|
-
return
|
|
1396
|
+
return x("dryRun", w);
|
|
1389
1397
|
}
|
|
1390
1398
|
const l = this.clientBundle.legacyJsonRpc;
|
|
1391
1399
|
if (!l)
|
|
@@ -1399,20 +1407,20 @@ class Xt {
|
|
|
1399
1407
|
const u = await l.dryRunTransactionBlock({
|
|
1400
1408
|
transactionBlock: c
|
|
1401
1409
|
});
|
|
1402
|
-
return
|
|
1410
|
+
return x("dryRun", u);
|
|
1403
1411
|
}
|
|
1404
|
-
const s =
|
|
1412
|
+
const s = tt(this.client);
|
|
1405
1413
|
if (typeof s?.executeTransaction == "function") {
|
|
1406
1414
|
let o;
|
|
1407
1415
|
t.transaction instanceof h ? (t.transaction.setSenderIfNotSet(this.address), o = await t.transaction.build({
|
|
1408
1416
|
client: this.client
|
|
1409
1417
|
})) : o = t.transaction;
|
|
1410
1418
|
const l = await this.signer.signTransaction(o), c = await s.executeTransaction({
|
|
1411
|
-
transaction:
|
|
1419
|
+
transaction: dt(l.bytes),
|
|
1412
1420
|
signatures: [l.signature],
|
|
1413
|
-
include:
|
|
1421
|
+
include: Z(n.options)
|
|
1414
1422
|
});
|
|
1415
|
-
return
|
|
1423
|
+
return x("execute", c);
|
|
1416
1424
|
}
|
|
1417
1425
|
const a = this.clientBundle.legacyJsonRpc;
|
|
1418
1426
|
if (!a)
|
|
@@ -1420,11 +1428,11 @@ class Xt {
|
|
|
1420
1428
|
"WalletClient execution requires core.executeTransaction or an explicit legacyJsonRpc client"
|
|
1421
1429
|
);
|
|
1422
1430
|
const r = await a.signAndExecuteTransaction({
|
|
1423
|
-
...
|
|
1424
|
-
options:
|
|
1431
|
+
...n,
|
|
1432
|
+
options: H(n.options),
|
|
1425
1433
|
signer: this.signer
|
|
1426
1434
|
});
|
|
1427
|
-
return
|
|
1435
|
+
return x("execute", r);
|
|
1428
1436
|
}
|
|
1429
1437
|
/**
|
|
1430
1438
|
* Gets the wallet address from the signer's public key
|
|
@@ -1461,7 +1469,16 @@ class Xt {
|
|
|
1461
1469
|
return t in this.modules;
|
|
1462
1470
|
}
|
|
1463
1471
|
}
|
|
1464
|
-
|
|
1472
|
+
function ft(i) {
|
|
1473
|
+
return {
|
|
1474
|
+
toSuiAddress: () => i,
|
|
1475
|
+
toBytes: () => new Uint8Array(32),
|
|
1476
|
+
toRawBytes: () => new Uint8Array(32),
|
|
1477
|
+
flag: () => 0,
|
|
1478
|
+
verify: async () => !1
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
class te extends wt {
|
|
1465
1482
|
/**
|
|
1466
1483
|
* Creates a new watch-only signer
|
|
1467
1484
|
*
|
|
@@ -1487,45 +1504,29 @@ class Yt extends dt {
|
|
|
1487
1504
|
*
|
|
1488
1505
|
* Returns a mock public key object that provides the wallet address
|
|
1489
1506
|
* but cannot be used for actual cryptographic operations.
|
|
1490
|
-
*
|
|
1491
|
-
* @returns Mock public key object
|
|
1492
1507
|
*/
|
|
1493
1508
|
getPublicKey() {
|
|
1494
|
-
return
|
|
1495
|
-
/** Returns the wallet address */
|
|
1496
|
-
toSuiAddress: () => this.address,
|
|
1497
|
-
/** Returns empty bytes (not a real public key) */
|
|
1498
|
-
toBytes: () => new Uint8Array(32),
|
|
1499
|
-
/** Returns empty raw bytes (not a real public key) */
|
|
1500
|
-
toRawBytes: () => new Uint8Array(32),
|
|
1501
|
-
/** Public key flag (0 for mock) */
|
|
1502
|
-
flag: 0,
|
|
1503
|
-
/** Verification always returns false (not a real public key) */
|
|
1504
|
-
verify: async () => !1
|
|
1505
|
-
};
|
|
1509
|
+
return ft(this.address);
|
|
1506
1510
|
}
|
|
1507
1511
|
/**
|
|
1508
1512
|
* Gets the key scheme for this signer
|
|
1509
1513
|
*
|
|
1510
|
-
* @returns Key scheme
|
|
1514
|
+
* @returns Key scheme (ed25519 for compatibility)
|
|
1511
1515
|
*/
|
|
1512
1516
|
getKeyScheme() {
|
|
1513
|
-
return "
|
|
1517
|
+
return "ED25519";
|
|
1514
1518
|
}
|
|
1515
1519
|
/**
|
|
1516
1520
|
* Signs and executes a transaction (not implemented for watch-only mode)
|
|
1517
1521
|
*
|
|
1518
1522
|
* This method is required by the Signer interface but cannot
|
|
1519
1523
|
* actually sign and execute transactions in watch-only mode.
|
|
1520
|
-
*
|
|
1521
|
-
* @param options - Sign and execute options
|
|
1522
|
-
* @returns Promise<any> - Empty result (not a real transaction result)
|
|
1523
1524
|
*/
|
|
1524
|
-
async signAndExecuteTransaction(
|
|
1525
|
+
async signAndExecuteTransaction(t) {
|
|
1525
1526
|
return {};
|
|
1526
1527
|
}
|
|
1527
1528
|
}
|
|
1528
|
-
class
|
|
1529
|
+
class ee extends wt {
|
|
1529
1530
|
/**
|
|
1530
1531
|
* Creates a new watch-only signer
|
|
1531
1532
|
*
|
|
@@ -1551,35 +1552,22 @@ class Zt extends dt {
|
|
|
1551
1552
|
*
|
|
1552
1553
|
* Returns a mock public key object that provides the wallet address
|
|
1553
1554
|
* but cannot be used for actual cryptographic operations.
|
|
1554
|
-
*
|
|
1555
|
-
* @returns Mock public key object
|
|
1556
1555
|
*/
|
|
1557
1556
|
getPublicKey() {
|
|
1558
|
-
return
|
|
1559
|
-
/** Returns the wallet address */
|
|
1560
|
-
toSuiAddress: () => this.address,
|
|
1561
|
-
/** Returns empty bytes (not a real public key) */
|
|
1562
|
-
toBytes: () => new Uint8Array(32),
|
|
1563
|
-
/** Returns empty raw bytes (not a real public key) */
|
|
1564
|
-
toRawBytes: () => new Uint8Array(32),
|
|
1565
|
-
/** Public key flag (0 for mock) */
|
|
1566
|
-
flag: 0,
|
|
1567
|
-
/** Verification always returns false (not a real public key) */
|
|
1568
|
-
verify: async () => !1
|
|
1569
|
-
};
|
|
1557
|
+
return ft(this.address);
|
|
1570
1558
|
}
|
|
1571
1559
|
/**
|
|
1572
1560
|
* Gets the key scheme for this signer
|
|
1573
1561
|
*
|
|
1574
|
-
* @returns Key scheme
|
|
1562
|
+
* @returns Key scheme (ed25519 for compatibility)
|
|
1575
1563
|
*/
|
|
1576
1564
|
getKeyScheme() {
|
|
1577
|
-
return "
|
|
1565
|
+
return "ED25519";
|
|
1578
1566
|
}
|
|
1579
1567
|
}
|
|
1580
1568
|
export {
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1569
|
+
Zt as WalletClient,
|
|
1570
|
+
te as WatchSigner,
|
|
1571
|
+
ee as WebSigner
|
|
1584
1572
|
};
|
|
1585
1573
|
//# sourceMappingURL=index.esm.js.map
|