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