@naviprotocol/wallet-client 2.0.6 → 2.0.8
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 +3 -3
- package/dist/client.js +160 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/balanceModule/index.d.ts +4 -4
- package/dist/modules/balanceModule/index.js +214 -0
- package/dist/modules/balanceModule/index.js.map +1 -0
- package/dist/modules/balanceModule/portfolio.js +105 -0
- package/dist/modules/balanceModule/portfolio.js.map +1 -0
- package/dist/modules/haedalModule/index.d.ts +2 -2
- package/dist/modules/haedalModule/index.js +114 -0
- package/dist/modules/haedalModule/index.js.map +1 -0
- package/dist/modules/index.d.ts +5 -5
- package/dist/modules/index.js +21 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/lendingModule/index.d.ts +5 -5
- package/dist/modules/lendingModule/index.js +410 -0
- package/dist/modules/lendingModule/index.js.map +1 -0
- package/dist/modules/lendingModule/migrate.js +225 -0
- package/dist/modules/lendingModule/migrate.js.map +1 -0
- package/dist/modules/lendingModule/protocols/navi.d.ts +1 -1
- package/dist/modules/lendingModule/protocols/navi.js +37 -0
- package/dist/modules/lendingModule/protocols/navi.js.map +1 -0
- package/dist/modules/lendingModule/protocols/suilend.d.ts +1 -1
- package/dist/{suilend-CWugUjwd.js → modules/lendingModule/protocols/suilend.js} +1 -1
- package/dist/{suilend-CWugUjwd.js.map → modules/lendingModule/protocols/suilend.js.map} +1 -1
- package/dist/modules/module.d.ts +1 -1
- package/dist/modules/module.js +46 -0
- package/dist/modules/module.js.map +1 -0
- package/dist/modules/swapModule/index.d.ts +2 -2
- package/dist/modules/swapModule/index.js +159 -0
- package/dist/modules/swapModule/index.js.map +1 -0
- package/dist/modules/voloModule/index.d.ts +2 -2
- package/dist/modules/voloModule/index.js +128 -0
- package/dist/modules/voloModule/index.js.map +1 -0
- package/dist/signer.d.ts +1 -1
- package/dist/signer.js +102 -0
- package/dist/signer.js.map +1 -0
- package/dist/transaction-result.d.ts +1 -1
- package/dist/transaction-result.js +59 -0
- package/dist/transaction-result.js.map +1 -0
- package/package.json +7 -7
- package/dist/index.esm.js +0 -1686
- package/dist/index.esm.js.map +0 -1
package/dist/index.esm.js
DELETED
|
@@ -1,1686 +0,0 @@
|
|
|
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
|
-
class k {
|
|
10
|
-
/**
|
|
11
|
-
* Gets the current configuration for this module
|
|
12
|
-
*
|
|
13
|
-
* This combines the default configuration with any user-provided overrides
|
|
14
|
-
* from the wallet client configuration.
|
|
15
|
-
*
|
|
16
|
-
* @returns The merged configuration for this module
|
|
17
|
-
*/
|
|
18
|
-
get config() {
|
|
19
|
-
return this.walletClient ? this.walletClient.config(this.name) : this.defaultConfig;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Emits an event through the wallet client's event system
|
|
23
|
-
*
|
|
24
|
-
* @param event - The event name to emit
|
|
25
|
-
* @param data - The event data to emit
|
|
26
|
-
*/
|
|
27
|
-
emit(e, n) {
|
|
28
|
-
this.walletClient?.events.emit(e, n);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Installs this module into a wallet client
|
|
32
|
-
*
|
|
33
|
-
* This method is called by the wallet client during initialization
|
|
34
|
-
* to establish the connection between the module and the client.
|
|
35
|
-
*
|
|
36
|
-
* @param walletClient - The wallet client instance to install into
|
|
37
|
-
*/
|
|
38
|
-
install(e) {
|
|
39
|
-
this.walletClient = e;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Uninstalls this module from the wallet client
|
|
43
|
-
*
|
|
44
|
-
* This method removes the reference to the wallet client,
|
|
45
|
-
* effectively disconnecting the module.
|
|
46
|
-
*/
|
|
47
|
-
uninstall() {
|
|
48
|
-
this.walletClient = void 0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
class x {
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new user portfolio
|
|
54
|
-
*
|
|
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.
|
|
61
|
-
*/
|
|
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
|
-
});
|
|
67
|
-
else {
|
|
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)
|
|
82
|
-
return;
|
|
83
|
-
const o = y(i);
|
|
84
|
-
let l = t[o];
|
|
85
|
-
l || (l = {
|
|
86
|
-
coinType: o,
|
|
87
|
-
amount: b(0),
|
|
88
|
-
addressBalance: b(0),
|
|
89
|
-
coins: []
|
|
90
|
-
}, t[o] = l), l.addressBalance = b(a);
|
|
91
|
-
}), this.balances = t;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Gets balance information for a specific coin type
|
|
96
|
-
*
|
|
97
|
-
* @param coinType - The coin type to query
|
|
98
|
-
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
99
|
-
*/
|
|
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);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Gets all coin types in the portfolio
|
|
123
|
-
*
|
|
124
|
-
* @returns Array of coin type strings
|
|
125
|
-
*/
|
|
126
|
-
getCoinTypes() {
|
|
127
|
-
return Object.values(this.balances).map((e) => e.coinType);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Gets the total balance amount for a specific coin type
|
|
131
|
-
*
|
|
132
|
-
* @param coinType - The coin type to query
|
|
133
|
-
* @returns BigNumber representing the total balance
|
|
134
|
-
*/
|
|
135
|
-
balanceOf(e) {
|
|
136
|
-
return e = y(e), this.getBalance(e)?.amount || b(0);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Creates a deep copy of the portfolio
|
|
140
|
-
*
|
|
141
|
-
* This method creates a completely independent copy of the portfolio
|
|
142
|
-
* that can be modified without affecting the original.
|
|
143
|
-
*
|
|
144
|
-
* @returns New UserPortfolio instance with copied data
|
|
145
|
-
*/
|
|
146
|
-
clone() {
|
|
147
|
-
return new x(this);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
class ke extends k {
|
|
151
|
-
constructor() {
|
|
152
|
-
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
153
|
-
coinPollingInterval: 6e3,
|
|
154
|
-
disableCoinPolling: !1
|
|
155
|
-
}, this.updatePortfolio = Q(async () => {
|
|
156
|
-
if (!this.walletClient)
|
|
157
|
-
throw new Error("Wallet client not found");
|
|
158
|
-
this._coins = await te(this.walletClient.address, {
|
|
159
|
-
client: this.walletClient.client
|
|
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;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Gets the current coin objects from the wallet
|
|
167
|
-
*
|
|
168
|
-
* @returns Array of coin objects owned by the wallet
|
|
169
|
-
*/
|
|
170
|
-
get coins() {
|
|
171
|
-
return this._coins;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Gets the current portfolio information
|
|
175
|
-
*
|
|
176
|
-
* @returns UserPortfolio instance with current balance information
|
|
177
|
-
*/
|
|
178
|
-
get portfolio() {
|
|
179
|
-
return this._portfolio;
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Waits for the next portfolio update to complete
|
|
183
|
-
*
|
|
184
|
-
* @returns Promise that resolves when the portfolio is updated
|
|
185
|
-
* @throws Error if no update promise is available
|
|
186
|
-
*/
|
|
187
|
-
async waitForUpdate() {
|
|
188
|
-
if (!this._updatePromise)
|
|
189
|
-
throw new Error("Update promise not found");
|
|
190
|
-
return await this._updatePromise;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Sends a single coin to a recipient
|
|
194
|
-
*
|
|
195
|
-
* @param coinType - Type of coin to send
|
|
196
|
-
* @param recipient - Recipient address
|
|
197
|
-
* @param amount - Amount to send
|
|
198
|
-
* @param options - Optional parameters including dry run mode
|
|
199
|
-
* @returns Transaction response or dry run response
|
|
200
|
-
*/
|
|
201
|
-
async sendCoin(e, n, t, i) {
|
|
202
|
-
return this.sendCoinBatch(e, [n], [t], i);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Sends coins to multiple recipients in a single transaction
|
|
206
|
-
*
|
|
207
|
-
* @param coinType - Type of coin to send
|
|
208
|
-
* @param recipients - Array of recipient addresses
|
|
209
|
-
* @param amounts - Array of amounts to send (must match recipients length)
|
|
210
|
-
* @param options - Optional parameters including dry run mode
|
|
211
|
-
* @returns Transaction response or dry run response
|
|
212
|
-
*/
|
|
213
|
-
async sendCoinBatch(e, n, t, i) {
|
|
214
|
-
if (!this.walletClient)
|
|
215
|
-
throw new Error("Wallet client not found");
|
|
216
|
-
if (n.length !== t.length)
|
|
217
|
-
throw new Error("Recipients and amounts must have the same length");
|
|
218
|
-
await this.waitForUpdate();
|
|
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))
|
|
221
|
-
throw new Error("Insufficient balance");
|
|
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
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Transfers a single object to a recipient
|
|
250
|
-
*
|
|
251
|
-
* @param object - Object ID to transfer
|
|
252
|
-
* @param recipient - Recipient address
|
|
253
|
-
* @param options - Optional parameters including dry run mode
|
|
254
|
-
* @returns Transaction response or dry run response
|
|
255
|
-
*/
|
|
256
|
-
async transferObject(e, n, t) {
|
|
257
|
-
return this.transferObjectBatch([e], [n], t);
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Transfers multiple objects to their respective recipients in a single transaction
|
|
261
|
-
*
|
|
262
|
-
* Each object is transferred to its corresponding recipient by index
|
|
263
|
-
* (first object → first recipient, second object → second recipient, etc.)
|
|
264
|
-
*
|
|
265
|
-
* @param objects - Object IDs to transfer
|
|
266
|
-
* @param recipients - Recipient addresses (must match objects array length)
|
|
267
|
-
* @param options - Optional parameters including dry run mode
|
|
268
|
-
* @returns Transaction response or dry run response
|
|
269
|
-
*/
|
|
270
|
-
async transferObjectBatch(e, n, t) {
|
|
271
|
-
if (!this.walletClient)
|
|
272
|
-
throw new Error("Wallet client not found");
|
|
273
|
-
if (e.length !== n.length)
|
|
274
|
-
throw new Error("Objects and recipients must have the same length");
|
|
275
|
-
await this.waitForUpdate();
|
|
276
|
-
const i = new f();
|
|
277
|
-
return e.forEach((o, l) => {
|
|
278
|
-
i.transferObjects([i.object(o)], n[l]);
|
|
279
|
-
}), await this.walletClient.signExecuteTransaction({
|
|
280
|
-
transaction: i,
|
|
281
|
-
dryRun: t?.dryRun ?? !1
|
|
282
|
-
});
|
|
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
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Starts polling for portfolio updates
|
|
319
|
-
*
|
|
320
|
-
* This method recursively schedules itself to run at the configured
|
|
321
|
-
* interval, ensuring regular balance updates.
|
|
322
|
-
*/
|
|
323
|
-
async startPolling() {
|
|
324
|
-
if (!this.config.disableCoinPolling)
|
|
325
|
-
try {
|
|
326
|
-
await this.updatePortfolio();
|
|
327
|
-
} catch (e) {
|
|
328
|
-
console.error(e);
|
|
329
|
-
} finally {
|
|
330
|
-
this.pollingTimer = setTimeout(this.startPolling, this.config.coinPollingInterval);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Installs the balance module into a wallet client
|
|
335
|
-
*
|
|
336
|
-
* @param walletClient - The wallet client instance to install into
|
|
337
|
-
*/
|
|
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();
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Uninstalls the balance module from the wallet client
|
|
347
|
-
*
|
|
348
|
-
* This method cleans up timers and stops polling to prevent memory leaks.
|
|
349
|
-
*/
|
|
350
|
-
uninstall() {
|
|
351
|
-
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const G = {
|
|
355
|
-
showEffects: !0,
|
|
356
|
-
showEvents: !0,
|
|
357
|
-
showBalanceChanges: !0,
|
|
358
|
-
showObjectChanges: !0
|
|
359
|
-
};
|
|
360
|
-
function H(s) {
|
|
361
|
-
return {
|
|
362
|
-
...G,
|
|
363
|
-
...s
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
function C(s) {
|
|
367
|
-
const e = s?.effects?.status;
|
|
368
|
-
return e?.status === "success" || e?.success === !0;
|
|
369
|
-
}
|
|
370
|
-
function A(s, e) {
|
|
371
|
-
const t = _e(e ?? {}), i = Ne(t);
|
|
372
|
-
return {
|
|
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 : []
|
|
379
|
-
};
|
|
380
|
-
}
|
|
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;
|
|
387
|
-
}
|
|
388
|
-
function Ne(s) {
|
|
389
|
-
if (F(s.effects))
|
|
390
|
-
return s.effects;
|
|
391
|
-
if (F(s.status))
|
|
392
|
-
return {
|
|
393
|
-
status: s.status
|
|
394
|
-
};
|
|
395
|
-
}
|
|
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) : [];
|
|
402
|
-
}
|
|
403
|
-
function F(s) {
|
|
404
|
-
return typeof s == "object" && s !== null;
|
|
405
|
-
}
|
|
406
|
-
async function V(s, e, n, t) {
|
|
407
|
-
if (!this.walletClient)
|
|
408
|
-
throw new Error("Wallet client not found");
|
|
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);
|
|
410
|
-
if (!c)
|
|
411
|
-
throw new Error(`Protocol ${r} not found`);
|
|
412
|
-
const w = await c.getPool(i.coinType);
|
|
413
|
-
if (console.log("migrateBetweenSupplyPTB", {
|
|
414
|
-
fromPoolLending: w
|
|
415
|
-
}), r === "navi" && w.supplyBalance === 0)
|
|
416
|
-
throw new Error("No supply balance");
|
|
417
|
-
if (t?.amount && t.amount > w.supplyBalance)
|
|
418
|
-
throw new Error("Amount is less than supply balance");
|
|
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
|
|
425
|
-
}),
|
|
426
|
-
this.naviServiceOptions
|
|
427
|
-
), r !== "navi" && i.id === a.id) {
|
|
428
|
-
const L = await c.withdrawCoinPTB(
|
|
429
|
-
s,
|
|
430
|
-
i.suiCoinType,
|
|
431
|
-
d
|
|
432
|
-
);
|
|
433
|
-
return await j(s, a, L, {
|
|
434
|
-
...this.naviServiceOptions,
|
|
435
|
-
amount: d
|
|
436
|
-
}), s;
|
|
437
|
-
}
|
|
438
|
-
const m = await ne(a, {
|
|
439
|
-
...this.naviServiceOptions,
|
|
440
|
-
env: this.config.env
|
|
441
|
-
});
|
|
442
|
-
if (!m)
|
|
443
|
-
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
444
|
-
const B = await this.walletClient.swap.getQuote(
|
|
445
|
-
i.suiCoinType,
|
|
446
|
-
a.suiCoinType,
|
|
447
|
-
d
|
|
448
|
-
), p = Number(B.amount_out);
|
|
449
|
-
if (p <= 0)
|
|
450
|
-
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
451
|
-
const P = Math.floor(p * (1 - u)), T = Math.floor(P / (1 + m.flashloanFee));
|
|
452
|
-
if (T <= 0)
|
|
453
|
-
throw new Error("The calculated borrow amount must be positive.");
|
|
454
|
-
const [O, E] = await ae(
|
|
455
|
-
s,
|
|
456
|
-
a,
|
|
457
|
-
T,
|
|
458
|
-
this.naviServiceOptions
|
|
459
|
-
), [N] = s.moveCall({
|
|
460
|
-
target: "0x2::coin::from_balance",
|
|
461
|
-
arguments: [O],
|
|
462
|
-
typeArguments: [a.suiCoinType]
|
|
463
|
-
});
|
|
464
|
-
await j(s, a, N, {
|
|
465
|
-
...this.naviServiceOptions,
|
|
466
|
-
amount: T
|
|
467
|
-
});
|
|
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({
|
|
475
|
-
target: "0x2::coin::into_balance",
|
|
476
|
-
arguments: [U],
|
|
477
|
-
typeArguments: [a.suiCoinType]
|
|
478
|
-
}), [J] = await ie(
|
|
479
|
-
s,
|
|
480
|
-
a,
|
|
481
|
-
E,
|
|
482
|
-
W,
|
|
483
|
-
this.naviServiceOptions
|
|
484
|
-
), [M] = s.moveCall({
|
|
485
|
-
target: "0x2::coin::from_balance",
|
|
486
|
-
arguments: [J],
|
|
487
|
-
typeArguments: [a.suiCoinType]
|
|
488
|
-
});
|
|
489
|
-
return await j(s, a, M, this.naviServiceOptions), s;
|
|
490
|
-
}
|
|
491
|
-
async function X(s, e, n, t) {
|
|
492
|
-
if (!this.walletClient)
|
|
493
|
-
throw new Error("Wallet client not found");
|
|
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);
|
|
495
|
-
if (!c)
|
|
496
|
-
throw new Error(`Protocol ${r} not found`);
|
|
497
|
-
const w = await c.getPool(a.coinType);
|
|
498
|
-
if (console.log("migrateBetweenBorrowPTB", {
|
|
499
|
-
fromPoolLending: w
|
|
500
|
-
}), w.borrowBalance === 0)
|
|
501
|
-
throw new Error("No borrow balance");
|
|
502
|
-
if (t?.amount && t.amount > w.borrowBalance)
|
|
503
|
-
throw new Error("Amount is more than borrow balance");
|
|
504
|
-
const u = await $(this.naviServiceOptions), d = await Promise.all([a, o]);
|
|
505
|
-
await z(
|
|
506
|
-
s,
|
|
507
|
-
K(u, {
|
|
508
|
-
lendingState: l,
|
|
509
|
-
pools: d
|
|
510
|
-
}),
|
|
511
|
-
this.naviServiceOptions
|
|
512
|
-
);
|
|
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()
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
const g = await ne(a, {
|
|
521
|
-
...this.naviServiceOptions,
|
|
522
|
-
env: this.config.env
|
|
523
|
-
});
|
|
524
|
-
if (!g)
|
|
525
|
-
throw new Error(`${a.token.symbol} pool not support flashloan`);
|
|
526
|
-
if (!this.walletClient)
|
|
527
|
-
throw new Error("Wallet client not found");
|
|
528
|
-
const m = t?.slippage ?? 5e-3, B = Math.ceil(h * (1 + g.flashloanFee)), p = B, P = await this.walletClient.swap.getQuote(
|
|
529
|
-
a.suiCoinType,
|
|
530
|
-
o.suiCoinType,
|
|
531
|
-
p
|
|
532
|
-
);
|
|
533
|
-
let T = 1 + m, O = Math.ceil(Number(P.amount_out) * T), E = await this.walletClient.swap.getQuote(
|
|
534
|
-
o.suiCoinType,
|
|
535
|
-
a.suiCoinType,
|
|
536
|
-
O
|
|
537
|
-
);
|
|
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,
|
|
541
|
-
a.suiCoinType,
|
|
542
|
-
O
|
|
543
|
-
);
|
|
544
|
-
const [N, I] = await ae(
|
|
545
|
-
s,
|
|
546
|
-
a,
|
|
547
|
-
h,
|
|
548
|
-
this.naviServiceOptions
|
|
549
|
-
), [U] = s.moveCall({
|
|
550
|
-
target: "0x2::coin::from_balance",
|
|
551
|
-
arguments: [N],
|
|
552
|
-
typeArguments: [a.suiCoinType]
|
|
553
|
-
});
|
|
554
|
-
await c.repayCoinPTB(s, a.suiCoinType, U, h);
|
|
555
|
-
const W = await se(s, o, O, this.naviServiceOptions), J = await q(
|
|
556
|
-
i,
|
|
557
|
-
s,
|
|
558
|
-
B,
|
|
559
|
-
W,
|
|
560
|
-
E
|
|
561
|
-
), M = s.moveCall({
|
|
562
|
-
target: "0x2::coin::into_balance",
|
|
563
|
-
arguments: [J],
|
|
564
|
-
typeArguments: [a.suiCoinType]
|
|
565
|
-
}), [L] = await ie(
|
|
566
|
-
s,
|
|
567
|
-
a,
|
|
568
|
-
I,
|
|
569
|
-
M,
|
|
570
|
-
this.naviServiceOptions
|
|
571
|
-
), [ge] = s.moveCall({
|
|
572
|
-
target: "0x2::coin::from_balance",
|
|
573
|
-
arguments: [L],
|
|
574
|
-
typeArguments: [a.suiCoinType]
|
|
575
|
-
});
|
|
576
|
-
return s.transferObjects([ge], i), s;
|
|
577
|
-
}
|
|
578
|
-
async function Y(s, e, n, t) {
|
|
579
|
-
if (!this.walletClient)
|
|
580
|
-
throw new Error("Wallet client not found");
|
|
581
|
-
const i = await te(this.walletClient.address, {
|
|
582
|
-
client: this.walletClient.client,
|
|
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}`);
|
|
598
|
-
if (console.log("migrateBalanceToSupplyPTB", {
|
|
599
|
-
balance: u.toNumber()
|
|
600
|
-
}), t?.amount && u.lt(t.amount))
|
|
601
|
-
throw new Error("Amount is greater than balance");
|
|
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
|
|
608
|
-
});
|
|
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
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
return await j(s, a, g, this.naviServiceOptions), s;
|
|
619
|
-
}
|
|
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;
|
|
628
|
-
return {
|
|
629
|
-
supplyBalance: a,
|
|
630
|
-
borrowBalance: o,
|
|
631
|
-
borrowAPR: parseFloat(n.borrowIncentiveApyInfo.apy)
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
async depositCoinPTB(e, n, t, i) {
|
|
635
|
-
throw new Error("Not implemented");
|
|
636
|
-
}
|
|
637
|
-
async withdrawCoinPTB(e, n, t) {
|
|
638
|
-
return oe(e, n, t, this.walletClient.lending.naviServiceOptions);
|
|
639
|
-
}
|
|
640
|
-
async borrowCoinPTB(e, n, t) {
|
|
641
|
-
throw new Error("Not implemented");
|
|
642
|
-
}
|
|
643
|
-
async repayCoinPTB(e, n, t, i) {
|
|
644
|
-
le(e, n, t, {
|
|
645
|
-
...this.walletClient.lending.naviServiceOptions,
|
|
646
|
-
amount: i
|
|
647
|
-
});
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
class We extends k {
|
|
651
|
-
constructor() {
|
|
652
|
-
super(), this.name = "lending", this.defaultConfig = {
|
|
653
|
-
env: "prod",
|
|
654
|
-
protocols: [],
|
|
655
|
-
enableSuilend: !0
|
|
656
|
-
}, 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);
|
|
657
|
-
}
|
|
658
|
-
/** Get protocols (either from internal storage or config) */
|
|
659
|
-
get protocols() {
|
|
660
|
-
return this._protocols.length > 0 ? this._protocols : this.config.protocols;
|
|
661
|
-
}
|
|
662
|
-
get naviServiceOptions() {
|
|
663
|
-
const e = this.config.services ?? this.walletClient?.clientBundle.services;
|
|
664
|
-
return {
|
|
665
|
-
...e ? { services: e } : {}
|
|
666
|
-
};
|
|
667
|
-
}
|
|
668
|
-
install(e) {
|
|
669
|
-
super.install(e), this._protocols = [];
|
|
670
|
-
}
|
|
671
|
-
async getProtocol(e) {
|
|
672
|
-
return (!this.protocols || this.protocols.length === 0) && await this.initializeProtocols(), this.protocols.find((n) => n.name === e);
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Gets all available lending pools
|
|
676
|
-
*
|
|
677
|
-
* @param options - Optional caching options
|
|
678
|
-
* @returns Array of pool information
|
|
679
|
-
*/
|
|
680
|
-
async getPools(e) {
|
|
681
|
-
return await be({
|
|
682
|
-
...this.naviServiceOptions,
|
|
683
|
-
env: this.config.env,
|
|
684
|
-
...e
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* Gets information for a specific lending pool
|
|
689
|
-
*
|
|
690
|
-
* @param identifier - Asset identifier (string, Pool object, or number)
|
|
691
|
-
* @param options - Optional caching options
|
|
692
|
-
* @returns Pool information
|
|
693
|
-
*/
|
|
694
|
-
async getPool(e, n) {
|
|
695
|
-
return await S(e, {
|
|
696
|
-
...this.naviServiceOptions,
|
|
697
|
-
env: this.config.env,
|
|
698
|
-
...n
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Deposits coins into a lending pool
|
|
703
|
-
*
|
|
704
|
-
* @param identifier - Asset identifier for the pool
|
|
705
|
-
* @param amount - Amount to deposit
|
|
706
|
-
* @param options - Optional parameters including dry run mode and account capability
|
|
707
|
-
* @returns Transaction response or dry run response
|
|
708
|
-
*/
|
|
709
|
-
async deposit(e, n, t) {
|
|
710
|
-
if (!this.walletClient)
|
|
711
|
-
throw new Error("Wallet client not found");
|
|
712
|
-
const i = await S(e, {
|
|
713
|
-
...this.naviServiceOptions,
|
|
714
|
-
env: this.config.env
|
|
715
|
-
});
|
|
716
|
-
await this.walletClient.module("balance").waitForUpdate();
|
|
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
|
|
722
|
-
});
|
|
723
|
-
await j(a, i, l, {
|
|
724
|
-
...this.naviServiceOptions,
|
|
725
|
-
env: this.config.env,
|
|
726
|
-
amount: n,
|
|
727
|
-
accountCap: t?.accountCap
|
|
728
|
-
});
|
|
729
|
-
const r = await this.walletClient.signExecuteTransaction({
|
|
730
|
-
transaction: a,
|
|
731
|
-
dryRun: t?.dryRun ?? !1
|
|
732
|
-
});
|
|
733
|
-
return !t?.dryRun && C(r) && (this.emit("lending:deposit-success", {
|
|
734
|
-
identifier: e,
|
|
735
|
-
amount: n
|
|
736
|
-
}), this.walletClient.module("balance").updatePortfolio()), r;
|
|
737
|
-
}
|
|
738
|
-
/**
|
|
739
|
-
* Withdraws coins from a lending pool
|
|
740
|
-
*
|
|
741
|
-
* @param identifier - Asset identifier for the pool
|
|
742
|
-
* @param amount - Amount to withdraw
|
|
743
|
-
* @param options - Optional parameters including dry run mode and account capability
|
|
744
|
-
* @returns Transaction response or dry run response
|
|
745
|
-
*/
|
|
746
|
-
async withdraw(e, n, t) {
|
|
747
|
-
if (!this.walletClient)
|
|
748
|
-
throw new Error("Wallet client not found");
|
|
749
|
-
const i = await S(e, {
|
|
750
|
-
...this.naviServiceOptions,
|
|
751
|
-
env: this.config.env
|
|
752
|
-
}), a = new f();
|
|
753
|
-
t?.disableUpdateOracle || await this.updateOraclePTB(a, [i]);
|
|
754
|
-
const o = await oe(a, i, n, {
|
|
755
|
-
...this.naviServiceOptions,
|
|
756
|
-
env: this.config.env,
|
|
757
|
-
accountCap: t?.accountCap
|
|
758
|
-
});
|
|
759
|
-
a.transferObjects([o], this.walletClient.address);
|
|
760
|
-
const l = await this.walletClient.signExecuteTransaction({
|
|
761
|
-
transaction: a,
|
|
762
|
-
dryRun: t?.dryRun ?? !1
|
|
763
|
-
});
|
|
764
|
-
return !t?.dryRun && C(l) && (this.emit("lending:withdraw-success", {
|
|
765
|
-
identifier: e,
|
|
766
|
-
amount: n
|
|
767
|
-
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Borrows coins from a lending pool
|
|
771
|
-
*
|
|
772
|
-
* @param identifier - Asset identifier for the pool
|
|
773
|
-
* @param amount - Amount to borrow
|
|
774
|
-
* @param options - Optional parameters including dry run mode and account capability
|
|
775
|
-
* @returns Transaction response or dry run response
|
|
776
|
-
*/
|
|
777
|
-
async borrow(e, n, t) {
|
|
778
|
-
if (!this.walletClient)
|
|
779
|
-
throw new Error("Wallet client not found");
|
|
780
|
-
const i = await S(e, {
|
|
781
|
-
...this.naviServiceOptions,
|
|
782
|
-
env: this.config.env
|
|
783
|
-
}), a = new f();
|
|
784
|
-
t?.disableUpdateOracle || await this.updateOraclePTB(a, [i]);
|
|
785
|
-
const o = await se(a, i, n, {
|
|
786
|
-
...this.naviServiceOptions,
|
|
787
|
-
env: this.config.env,
|
|
788
|
-
accountCap: t?.accountCap
|
|
789
|
-
});
|
|
790
|
-
a.transferObjects([o], this.walletClient.address);
|
|
791
|
-
const l = await this.walletClient.signExecuteTransaction({
|
|
792
|
-
transaction: a,
|
|
793
|
-
dryRun: t?.dryRun ?? !1
|
|
794
|
-
});
|
|
795
|
-
return !t?.dryRun && C(l) && (this.emit("lending:borrow-success", {
|
|
796
|
-
identifier: e,
|
|
797
|
-
amount: n
|
|
798
|
-
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Repays borrowed coins to a lending pool
|
|
802
|
-
*
|
|
803
|
-
* @param identifier - Asset identifier for the pool
|
|
804
|
-
* @param amount - Amount to repay
|
|
805
|
-
* @param options - Optional parameters including dry run mode and account capability
|
|
806
|
-
* @returns Transaction response or dry run response
|
|
807
|
-
*/
|
|
808
|
-
async repay(e, n, t) {
|
|
809
|
-
if (!this.walletClient)
|
|
810
|
-
throw new Error("Wallet client not found");
|
|
811
|
-
await this.walletClient.module("balance").waitForUpdate();
|
|
812
|
-
const i = await S(e, {
|
|
813
|
-
...this.naviServiceOptions,
|
|
814
|
-
env: this.config.env
|
|
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
|
|
820
|
-
});
|
|
821
|
-
await le(a, i, l, {
|
|
822
|
-
...this.naviServiceOptions,
|
|
823
|
-
env: this.config.env,
|
|
824
|
-
amount: n,
|
|
825
|
-
accountCap: t?.accountCap
|
|
826
|
-
});
|
|
827
|
-
const r = await this.walletClient.signExecuteTransaction({
|
|
828
|
-
transaction: a,
|
|
829
|
-
dryRun: t?.dryRun ?? !1
|
|
830
|
-
});
|
|
831
|
-
return !t?.dryRun && C(r) && (this.emit("lending:repay-success", {
|
|
832
|
-
identifier: e,
|
|
833
|
-
amount: n
|
|
834
|
-
}), this.walletClient.module("balance").updatePortfolio()), r;
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Gets the current health factor for the user
|
|
838
|
-
*
|
|
839
|
-
* @returns Current health factor value
|
|
840
|
-
*/
|
|
841
|
-
async getHealthFactor() {
|
|
842
|
-
if (!this.walletClient)
|
|
843
|
-
throw new Error("Wallet client not found");
|
|
844
|
-
const e = this.walletClient.address;
|
|
845
|
-
return await ve(e, {
|
|
846
|
-
...this.naviServiceOptions,
|
|
847
|
-
env: this.config.env,
|
|
848
|
-
client: this.walletClient.client
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
/**
|
|
852
|
-
* Initiates a liquidation process
|
|
853
|
-
*
|
|
854
|
-
* @param payIdentifier - Asset identifier for the debt being paid
|
|
855
|
-
* @param payAmount - Amount of debt to pay
|
|
856
|
-
* @param collateralIdentifier - Asset identifier for the collateral being liquidated
|
|
857
|
-
* @param liquidationAddress - Address of the account being liquidated
|
|
858
|
-
* @param options - Optional parameters including dry run mode
|
|
859
|
-
* @returns Transaction response or dry run response
|
|
860
|
-
*/
|
|
861
|
-
async liquidate(e, n, t, i, a) {
|
|
862
|
-
if (!this.walletClient)
|
|
863
|
-
throw new Error("Wallet client not found");
|
|
864
|
-
const o = await S(e, {
|
|
865
|
-
...this.naviServiceOptions,
|
|
866
|
-
env: this.config.env
|
|
867
|
-
}), l = await S(t, {
|
|
868
|
-
...this.naviServiceOptions,
|
|
869
|
-
env: this.config.env
|
|
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(
|
|
876
|
-
r,
|
|
877
|
-
o,
|
|
878
|
-
w,
|
|
879
|
-
l,
|
|
880
|
-
i,
|
|
881
|
-
{
|
|
882
|
-
...this.naviServiceOptions,
|
|
883
|
-
env: this.config.env
|
|
884
|
-
}
|
|
885
|
-
), [h] = r.moveCall({
|
|
886
|
-
target: "0x2::coin::from_balance",
|
|
887
|
-
arguments: [u],
|
|
888
|
-
typeArguments: [l.suiCoinType]
|
|
889
|
-
}), [g] = r.moveCall({
|
|
890
|
-
target: "0x2::coin::from_balance",
|
|
891
|
-
arguments: [d],
|
|
892
|
-
typeArguments: [o.suiCoinType]
|
|
893
|
-
});
|
|
894
|
-
r.transferObjects([h, g], this.walletClient.address);
|
|
895
|
-
const m = await this.walletClient.signExecuteTransaction({
|
|
896
|
-
transaction: r,
|
|
897
|
-
dryRun: a?.dryRun ?? !1
|
|
898
|
-
});
|
|
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;
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Gets the available lending rewards for the current user.
|
|
908
|
-
*
|
|
909
|
-
* @param options - Optional cache options.
|
|
910
|
-
* @returns The available lending rewards for the user.
|
|
911
|
-
* @throws If the wallet client is not found.
|
|
912
|
-
*/
|
|
913
|
-
async getAvailableRewards(e) {
|
|
914
|
-
if (!this.walletClient)
|
|
915
|
-
throw new Error("Wallet client not found");
|
|
916
|
-
return D(this.walletClient.address, {
|
|
917
|
-
...this.naviServiceOptions,
|
|
918
|
-
...e,
|
|
919
|
-
env: this.config.env,
|
|
920
|
-
client: this.walletClient.client
|
|
921
|
-
});
|
|
922
|
-
}
|
|
923
|
-
/**
|
|
924
|
-
* Gets the claimed reward history for the current user.
|
|
925
|
-
*
|
|
926
|
-
* @param options - Optional cache options.
|
|
927
|
-
* @returns The claimed reward history for the user.
|
|
928
|
-
* @throws If the wallet client is not found.
|
|
929
|
-
*/
|
|
930
|
-
async getClaimedRewardHistory(e) {
|
|
931
|
-
if (!this.walletClient)
|
|
932
|
-
throw new Error("Wallet client not found");
|
|
933
|
-
return Te(this.walletClient.address, {
|
|
934
|
-
...this.naviServiceOptions,
|
|
935
|
-
...e
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Claims all available lending rewards for the user
|
|
940
|
-
*
|
|
941
|
-
* @param options - Optional parameters including dry run mode and account capability
|
|
942
|
-
* @returns Transaction response or dry run response
|
|
943
|
-
*/
|
|
944
|
-
async claimAllRewards(e) {
|
|
945
|
-
if (!this.walletClient)
|
|
946
|
-
throw new Error("Wallet client not found");
|
|
947
|
-
const n = new f(), t = await D(this.walletClient.address, {
|
|
948
|
-
...this.naviServiceOptions,
|
|
949
|
-
env: this.config.env,
|
|
950
|
-
client: this.walletClient.client
|
|
951
|
-
});
|
|
952
|
-
await Pe(n, t, {
|
|
953
|
-
...this.naviServiceOptions,
|
|
954
|
-
env: this.config.env,
|
|
955
|
-
accountCap: e?.accountCap
|
|
956
|
-
});
|
|
957
|
-
const i = await this.walletClient.signExecuteTransaction({
|
|
958
|
-
transaction: n,
|
|
959
|
-
dryRun: e?.dryRun ?? !1
|
|
960
|
-
});
|
|
961
|
-
return !e?.dryRun && C(i) && (this.emit("lending:claim-rewards-success", {
|
|
962
|
-
rewards: t
|
|
963
|
-
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
964
|
-
}
|
|
965
|
-
async updateOraclePTB(e, n) {
|
|
966
|
-
const t = await $({
|
|
967
|
-
...this.naviServiceOptions,
|
|
968
|
-
env: this.config.env
|
|
969
|
-
}), i = await this.getLendingState({
|
|
970
|
-
cacheTime: 60 * 1e3
|
|
971
|
-
}), a = K(t, {
|
|
972
|
-
lendingState: i,
|
|
973
|
-
pools: n
|
|
974
|
-
});
|
|
975
|
-
await z(e, a, {
|
|
976
|
-
...this.naviServiceOptions,
|
|
977
|
-
env: this.config.env,
|
|
978
|
-
updatePythPriceFeeds: !0,
|
|
979
|
-
client: this.walletClient?.client
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
/**
|
|
983
|
-
* Updates the oracle prices for the lending protocol
|
|
984
|
-
*
|
|
985
|
-
* @param options - Optional parameters including dry run mode and pools
|
|
986
|
-
* @param options.dryRun - Whether to perform a dry run
|
|
987
|
-
* @returns Transaction response or dry run response
|
|
988
|
-
*/
|
|
989
|
-
async updateOracle(e) {
|
|
990
|
-
if (!this.walletClient)
|
|
991
|
-
throw new Error("Wallet client not found");
|
|
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
|
|
996
|
-
});
|
|
997
|
-
}
|
|
998
|
-
/**
|
|
999
|
-
* Gets all active lending positions for the user
|
|
1000
|
-
*
|
|
1001
|
-
* @param options - Optional caching options
|
|
1002
|
-
* @returns User's lending state information
|
|
1003
|
-
*/
|
|
1004
|
-
async getLendingState(e) {
|
|
1005
|
-
if (!this.walletClient)
|
|
1006
|
-
throw new Error("Wallet client not found");
|
|
1007
|
-
return await Se(this.walletClient.address, {
|
|
1008
|
-
...this.naviServiceOptions,
|
|
1009
|
-
env: this.config.env,
|
|
1010
|
-
...e,
|
|
1011
|
-
client: this.walletClient.client
|
|
1012
|
-
});
|
|
1013
|
-
}
|
|
1014
|
-
/**
|
|
1015
|
-
* Creates an account capability for the lending protocol
|
|
1016
|
-
*
|
|
1017
|
-
* @param options - Optional parameters including dry run mode
|
|
1018
|
-
* @returns Transaction response or dry run response
|
|
1019
|
-
*/
|
|
1020
|
-
async createAccountCap(e) {
|
|
1021
|
-
if (!this.walletClient)
|
|
1022
|
-
throw new Error("Wallet client not found");
|
|
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
|
|
1027
|
-
});
|
|
1028
|
-
}
|
|
1029
|
-
async initializeProtocols() {
|
|
1030
|
-
if (!this.walletClient) {
|
|
1031
|
-
console.warn("Wallet client not available during protocol initialization");
|
|
1032
|
-
return;
|
|
1033
|
-
}
|
|
1034
|
-
const e = [];
|
|
1035
|
-
if (e.push(new Ue(this.walletClient)), this.config.enableSuilend)
|
|
1036
|
-
try {
|
|
1037
|
-
const { default: n } = await import("./suilend-CWugUjwd.js");
|
|
1038
|
-
e.push(
|
|
1039
|
-
await n.create(this.walletClient, {
|
|
1040
|
-
grpcClient: this.config.suilendGrpcClient,
|
|
1041
|
-
grpcUrl: this.config.suilendGrpcUrl
|
|
1042
|
-
})
|
|
1043
|
-
);
|
|
1044
|
-
} catch (n) {
|
|
1045
|
-
console.warn("Failed to initialize SuilendProtocol:", n);
|
|
1046
|
-
}
|
|
1047
|
-
this._protocols = e;
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
class Je extends k {
|
|
1051
|
-
constructor() {
|
|
1052
|
-
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
1053
|
-
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
1054
|
-
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
1055
|
-
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
1056
|
-
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
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)
|
|
1062
|
-
}).then((a) => a.json())).data;
|
|
1063
|
-
})
|
|
1064
|
-
);
|
|
1065
|
-
}
|
|
1066
|
-
getStats(e) {
|
|
1067
|
-
return this.getStatsCached({
|
|
1068
|
-
services: e?.services ?? this.config.services
|
|
1069
|
-
});
|
|
1070
|
-
}
|
|
1071
|
-
/**
|
|
1072
|
-
* Adds staking operation to a transaction black
|
|
1073
|
-
*
|
|
1074
|
-
* @param tx - The transaction block to add the staking operation to
|
|
1075
|
-
* @param suiCoin - The SUI coin object to stake
|
|
1076
|
-
* @returns The vSUI coin object received from staking
|
|
1077
|
-
*/
|
|
1078
|
-
async stakePTB(e, n) {
|
|
1079
|
-
const [t] = e.moveCall({
|
|
1080
|
-
target: `${this.config.packageId}::stake_pool::stake`,
|
|
1081
|
-
arguments: [
|
|
1082
|
-
e.object(this.config.poolId),
|
|
1083
|
-
e.object(this.config.metadataId),
|
|
1084
|
-
e.object("0x05"),
|
|
1085
|
-
_(n, e.object)
|
|
1086
|
-
],
|
|
1087
|
-
typeArguments: []
|
|
1088
|
-
});
|
|
1089
|
-
return t;
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Adds unstaking operation to a transaction black
|
|
1093
|
-
*
|
|
1094
|
-
* @param tx - The transaction block to add the unstaking operation to
|
|
1095
|
-
* @param vSuiCoin - The vSUI coin object to unstake
|
|
1096
|
-
* @returns The SUI coin object received from unstaking
|
|
1097
|
-
*/
|
|
1098
|
-
async unstakePTB(e, n) {
|
|
1099
|
-
const [t] = e.moveCall({
|
|
1100
|
-
target: `${this.config.packageId}::stake_pool::unstake`,
|
|
1101
|
-
arguments: [
|
|
1102
|
-
e.object(this.config.poolId),
|
|
1103
|
-
e.object(this.config.metadataId),
|
|
1104
|
-
e.object("0x05"),
|
|
1105
|
-
_(n, e.object)
|
|
1106
|
-
],
|
|
1107
|
-
typeArguments: []
|
|
1108
|
-
});
|
|
1109
|
-
return t;
|
|
1110
|
-
}
|
|
1111
|
-
/**
|
|
1112
|
-
* Stake SUI tokens to receive vSUI tokens
|
|
1113
|
-
*
|
|
1114
|
-
* @param suiAmount - Amount of SUI to stake (in MIST units)
|
|
1115
|
-
* @param options - Optional parameters including dryRun flag
|
|
1116
|
-
* @returns Transaction response or dry run response
|
|
1117
|
-
* @throws Error if wallet client not found or stake amount is too low
|
|
1118
|
-
*/
|
|
1119
|
-
async stake(e, n) {
|
|
1120
|
-
if (!this.walletClient)
|
|
1121
|
-
throw new Error("Wallet client not found");
|
|
1122
|
-
if (e < 1e9)
|
|
1123
|
-
throw new Error("Stake amount should be greater than 1Sui");
|
|
1124
|
-
const t = new f();
|
|
1125
|
-
await this.walletClient.module("balance").waitForUpdate();
|
|
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
|
|
1136
|
-
});
|
|
1137
|
-
return !n?.dryRun && C(l) && (this.emit("volo:stake-success", {
|
|
1138
|
-
suiAmount: e
|
|
1139
|
-
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
1140
|
-
}
|
|
1141
|
-
/**
|
|
1142
|
-
* Unstake vSUI tokens to receive SUI tokens
|
|
1143
|
-
*
|
|
1144
|
-
* @param vSuiAmount - Amount of vSUI to unstake (in MIST units)
|
|
1145
|
-
* @param options - Optional parameters including dryRun flag
|
|
1146
|
-
* @returns Transaction response or dry run response
|
|
1147
|
-
* @throws Error if wallet client not found or unstake amount is too low
|
|
1148
|
-
*/
|
|
1149
|
-
async unstake(e, n) {
|
|
1150
|
-
if (!this.walletClient)
|
|
1151
|
-
throw new Error("Wallet client not found");
|
|
1152
|
-
if (e < 1e9)
|
|
1153
|
-
throw new Error("Unstake amount should >= 1vSui");
|
|
1154
|
-
await this.walletClient.module("balance").waitForUpdate();
|
|
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
|
|
1164
|
-
});
|
|
1165
|
-
return !n?.dryRun && C(l) && (this.emit("volo:unstake-success", {
|
|
1166
|
-
vSuiAmount: e
|
|
1167
|
-
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
function Me() {
|
|
1171
|
-
const s = H(G);
|
|
1172
|
-
return {
|
|
1173
|
-
effects: s.showEffects,
|
|
1174
|
-
events: s.showEvents,
|
|
1175
|
-
balanceChanges: s.showBalanceChanges,
|
|
1176
|
-
objectTypes: s.showObjectChanges
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
function Le(s) {
|
|
1180
|
-
return s.core;
|
|
1181
|
-
}
|
|
1182
|
-
class Qe extends k {
|
|
1183
|
-
constructor() {
|
|
1184
|
-
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1185
|
-
apiKey: "",
|
|
1186
|
-
baseUrl: "https://open-aggregator-api.naviprotocol.io/find_routes",
|
|
1187
|
-
dexList: [],
|
|
1188
|
-
depth: 3,
|
|
1189
|
-
serviceFee: void 0,
|
|
1190
|
-
env: "prod"
|
|
1191
|
-
};
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Gets the referral ID for this swap module
|
|
1195
|
-
*
|
|
1196
|
-
* @returns Referral ID if API key is configured, otherwise 0
|
|
1197
|
-
*/
|
|
1198
|
-
get referral() {
|
|
1199
|
-
return this.config.apiKey ? Ae(this.config.apiKey) : 0;
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Get the swap options
|
|
1203
|
-
* @returns The swap options
|
|
1204
|
-
*/
|
|
1205
|
-
get swapOptions() {
|
|
1206
|
-
return {
|
|
1207
|
-
baseUrl: this.config.baseUrl,
|
|
1208
|
-
dexList: this.config.dexList,
|
|
1209
|
-
depth: this.config.depth,
|
|
1210
|
-
serviceFee: this.config.serviceFee,
|
|
1211
|
-
services: this.config.services ?? this.walletClient?.clientBundle.services
|
|
1212
|
-
};
|
|
1213
|
-
}
|
|
1214
|
-
/**
|
|
1215
|
-
* Get a quote for a swap
|
|
1216
|
-
* @param fromCoinType - The type of the coin being swapped from
|
|
1217
|
-
* @param toCoinType - The type of the coin being swapped to
|
|
1218
|
-
* @param fromAmount - The amount of the coin being swapped from
|
|
1219
|
-
* @returns A promise that resolves with the quote
|
|
1220
|
-
*/
|
|
1221
|
-
async getQuote(e, n, t) {
|
|
1222
|
-
return je(e, n, t, this.config.apiKey, this.swapOptions);
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
* Builds a swap transaction from a quote
|
|
1226
|
-
* @param tx - The transaction to build the swap from
|
|
1227
|
-
* @param quote - The quote to build the swap from
|
|
1228
|
-
* @param fromCoin - The coin to swap from
|
|
1229
|
-
* @param slippage - The slippage tolerance
|
|
1230
|
-
* @returns The swap transaction
|
|
1231
|
-
*/
|
|
1232
|
-
async buildSwapPTBFromQuote(e, n, t, i) {
|
|
1233
|
-
if (!this.walletClient)
|
|
1234
|
-
throw new Error("Wallet client not found");
|
|
1235
|
-
const a = new R(n.amount_out).multipliedBy(1 - i).toFixed(0);
|
|
1236
|
-
return await q(
|
|
1237
|
-
this.walletClient.address,
|
|
1238
|
-
e,
|
|
1239
|
-
Number(a),
|
|
1240
|
-
t,
|
|
1241
|
-
n,
|
|
1242
|
-
this.referral,
|
|
1243
|
-
!1,
|
|
1244
|
-
this.config.apiKey,
|
|
1245
|
-
this.swapOptions
|
|
1246
|
-
);
|
|
1247
|
-
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Executes a swap between two coin types
|
|
1250
|
-
*
|
|
1251
|
-
* This method performs a complete swap operation including:
|
|
1252
|
-
* - Balance validation
|
|
1253
|
-
* - Quote retrieval from aggregator
|
|
1254
|
-
* - Transaction building with slippage protection
|
|
1255
|
-
* - Transaction execution
|
|
1256
|
-
* - Event emission on success
|
|
1257
|
-
*
|
|
1258
|
-
* @param fromCoinType - Source coin type
|
|
1259
|
-
* @param toCoinType - Target coin type
|
|
1260
|
-
* @param fromAmount - Amount to swap
|
|
1261
|
-
* @param slippage - Slippage tolerance (0-1)
|
|
1262
|
-
* @param options - Optional parameters including dry run mode
|
|
1263
|
-
* @returns Transaction response or dry run response
|
|
1264
|
-
*/
|
|
1265
|
-
async swap(e, n, t, i, a) {
|
|
1266
|
-
if (!this.walletClient)
|
|
1267
|
-
throw new Error("Wallet client not found");
|
|
1268
|
-
await this.walletClient.module("balance").waitForUpdate();
|
|
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)
|
|
1276
|
-
return await this.walletClient.signExecuteTransaction({
|
|
1277
|
-
transaction: l,
|
|
1278
|
-
dryRun: !0
|
|
1279
|
-
});
|
|
1280
|
-
const u = await l.build({
|
|
1281
|
-
client: this.walletClient.client
|
|
1282
|
-
}), d = await this.walletClient.signer.signTransaction(u), h = [d.signature];
|
|
1283
|
-
try {
|
|
1284
|
-
await Fe(d.bytes, h);
|
|
1285
|
-
} catch (p) {
|
|
1286
|
-
console.error(p);
|
|
1287
|
-
}
|
|
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()
|
|
1292
|
-
}) : await (() => {
|
|
1293
|
-
const p = this.walletClient.clientBundle.legacyJsonRpc;
|
|
1294
|
-
if (!p)
|
|
1295
|
-
throw new Error(
|
|
1296
|
-
"Swap execution requires core.executeTransaction or an explicit legacyJsonRpc client"
|
|
1297
|
-
);
|
|
1298
|
-
return p.executeTransactionBlock({
|
|
1299
|
-
transactionBlock: d.bytes,
|
|
1300
|
-
signature: h,
|
|
1301
|
-
options: G
|
|
1302
|
-
});
|
|
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)
|
|
1312
|
-
}), this.walletClient.module("balance").updatePortfolio();
|
|
1313
|
-
}
|
|
1314
|
-
return B;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
class $e extends k {
|
|
1318
|
-
constructor() {
|
|
1319
|
-
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1320
|
-
packageId: "0x19e6ea7f5ced4f090e20da794cc80349a03e638940ddb95155a4e301f5f4967c",
|
|
1321
|
-
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1322
|
-
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
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)
|
|
1328
|
-
}).then((a) => a.json())).data.apy;
|
|
1329
|
-
})
|
|
1330
|
-
);
|
|
1331
|
-
}
|
|
1332
|
-
getApy(e) {
|
|
1333
|
-
return this.getApyCached({
|
|
1334
|
-
services: e?.services ?? this.config.services
|
|
1335
|
-
});
|
|
1336
|
-
}
|
|
1337
|
-
/**
|
|
1338
|
-
* Builds a transaction block for staking SUI to haSUI
|
|
1339
|
-
*
|
|
1340
|
-
* @param tx - Transaction to add staking operation to
|
|
1341
|
-
* @param suiCoin - Sui coin object to stake
|
|
1342
|
-
* @returns haSUI coin object
|
|
1343
|
-
*/
|
|
1344
|
-
async stakePTB(e, n) {
|
|
1345
|
-
const [t] = e.moveCall({
|
|
1346
|
-
target: `${this.config.packageId}::staking::request_stake_coin`,
|
|
1347
|
-
arguments: [
|
|
1348
|
-
e.object("0x05"),
|
|
1349
|
-
e.object(this.config.configId),
|
|
1350
|
-
_(n, e.object),
|
|
1351
|
-
e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1352
|
-
],
|
|
1353
|
-
typeArguments: []
|
|
1354
|
-
});
|
|
1355
|
-
return t;
|
|
1356
|
-
}
|
|
1357
|
-
/**
|
|
1358
|
-
* Builds a transaction block for unstaking haSUI to SUI
|
|
1359
|
-
*
|
|
1360
|
-
* @param tx - Transaction to add unstaking operation to
|
|
1361
|
-
* @param haSUICoin - haSUI coin object to unstake
|
|
1362
|
-
* @returns SUI coin object
|
|
1363
|
-
*/
|
|
1364
|
-
async unstakePTB(e, n) {
|
|
1365
|
-
const [t] = e.moveCall({
|
|
1366
|
-
target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
|
|
1367
|
-
arguments: [
|
|
1368
|
-
e.object("0x05"),
|
|
1369
|
-
e.object(this.config.configId),
|
|
1370
|
-
_(n, e.object)
|
|
1371
|
-
],
|
|
1372
|
-
typeArguments: []
|
|
1373
|
-
});
|
|
1374
|
-
return t;
|
|
1375
|
-
}
|
|
1376
|
-
/**
|
|
1377
|
-
* Stake SUI for haSUI
|
|
1378
|
-
*
|
|
1379
|
-
* @param suiAmount - Amount of SUI to stake
|
|
1380
|
-
* @param options Optional dry run
|
|
1381
|
-
*/
|
|
1382
|
-
async stake(e, n) {
|
|
1383
|
-
if (!this.walletClient)
|
|
1384
|
-
throw new Error("Wallet client not found");
|
|
1385
|
-
const t = new f();
|
|
1386
|
-
await this.walletClient.module("balance").waitForUpdate();
|
|
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
|
|
1397
|
-
});
|
|
1398
|
-
return !n?.dryRun && C(l) && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
|
|
1399
|
-
}
|
|
1400
|
-
/**
|
|
1401
|
-
* Unstake haSUI for SUI
|
|
1402
|
-
*
|
|
1403
|
-
* @param haSUIAmount - Amount of haSUI to unstake
|
|
1404
|
-
* @param options Optional dry run
|
|
1405
|
-
*/
|
|
1406
|
-
async unstake(e, n) {
|
|
1407
|
-
if (!this.walletClient)
|
|
1408
|
-
throw new Error("Wallet client not found");
|
|
1409
|
-
await this.walletClient.module("balance").waitForUpdate();
|
|
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
|
|
1419
|
-
});
|
|
1420
|
-
return !n?.dryRun && C(l) && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
const ze = {
|
|
1424
|
-
/** Balance management module */
|
|
1425
|
-
balance: new ke(),
|
|
1426
|
-
/** Lending protocol module */
|
|
1427
|
-
lending: new We(),
|
|
1428
|
-
/** Volo protocol module */
|
|
1429
|
-
volo: new Je(),
|
|
1430
|
-
/** DEX swapping module */
|
|
1431
|
-
swap: new Qe(),
|
|
1432
|
-
/** Haedal protocol module */
|
|
1433
|
-
haedal: new $e()
|
|
1434
|
-
};
|
|
1435
|
-
function Z(s) {
|
|
1436
|
-
const e = H(s);
|
|
1437
|
-
return {
|
|
1438
|
-
effects: e.showEffects,
|
|
1439
|
-
events: e.showEvents,
|
|
1440
|
-
balanceChanges: e.showBalanceChanges,
|
|
1441
|
-
objectTypes: e.showObjectChanges
|
|
1442
|
-
};
|
|
1443
|
-
}
|
|
1444
|
-
function ee(s) {
|
|
1445
|
-
return s.core;
|
|
1446
|
-
}
|
|
1447
|
-
function Ke(s) {
|
|
1448
|
-
return "grpc" in s;
|
|
1449
|
-
}
|
|
1450
|
-
function qe(s) {
|
|
1451
|
-
if (Ke(s))
|
|
1452
|
-
return Re(s);
|
|
1453
|
-
const e = s.network ?? "mainnet", n = xe(e, s.legacyJsonRpc);
|
|
1454
|
-
return {
|
|
1455
|
-
network: e,
|
|
1456
|
-
coreClient: n,
|
|
1457
|
-
grpc: n,
|
|
1458
|
-
legacyJsonRpc: n,
|
|
1459
|
-
services: s.services
|
|
1460
|
-
};
|
|
1461
|
-
}
|
|
1462
|
-
class tt {
|
|
1463
|
-
/**
|
|
1464
|
-
* Creates a new wallet client instance
|
|
1465
|
-
* @param options - Configuration options for the wallet client
|
|
1466
|
-
*/
|
|
1467
|
-
constructor(e) {
|
|
1468
|
-
this.modules = ze, this.userConfigs = {}, this.events = me();
|
|
1469
|
-
const n = e.client ?? {
|
|
1470
|
-
network: "mainnet",
|
|
1471
|
-
grpc: { url: Ee }
|
|
1472
|
-
};
|
|
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);
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
get lending() {
|
|
1480
|
-
return this.modules.lending;
|
|
1481
|
-
}
|
|
1482
|
-
get balance() {
|
|
1483
|
-
return this.modules.balance;
|
|
1484
|
-
}
|
|
1485
|
-
get volo() {
|
|
1486
|
-
return this.modules.volo;
|
|
1487
|
-
}
|
|
1488
|
-
get swap() {
|
|
1489
|
-
return this.modules.swap;
|
|
1490
|
-
}
|
|
1491
|
-
get haedal() {
|
|
1492
|
-
return this.modules.haedal;
|
|
1493
|
-
}
|
|
1494
|
-
/**
|
|
1495
|
-
* Signs and executes a transaction block
|
|
1496
|
-
* @param options - Transaction execution options including dry run support
|
|
1497
|
-
* @returns Promise with transaction execution result
|
|
1498
|
-
*/
|
|
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)
|
|
1508
|
-
});
|
|
1509
|
-
return A("dryRun", u);
|
|
1510
|
-
}
|
|
1511
|
-
const r = this.clientBundle.legacyJsonRpc;
|
|
1512
|
-
if (!r)
|
|
1513
|
-
throw new Error(
|
|
1514
|
-
"WalletClient dry-run requires core.simulateTransaction or an explicit legacyJsonRpc client"
|
|
1515
|
-
);
|
|
1516
|
-
let c;
|
|
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({
|
|
1521
|
-
transactionBlock: c
|
|
1522
|
-
});
|
|
1523
|
-
return A("dryRun", w);
|
|
1524
|
-
}
|
|
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({
|
|
1529
|
-
client: this.client
|
|
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)
|
|
1535
|
-
});
|
|
1536
|
-
return A("execute", c);
|
|
1537
|
-
}
|
|
1538
|
-
const a = this.clientBundle.legacyJsonRpc;
|
|
1539
|
-
if (!a)
|
|
1540
|
-
throw new Error(
|
|
1541
|
-
"WalletClient execution requires core.executeTransaction or an explicit legacyJsonRpc client"
|
|
1542
|
-
);
|
|
1543
|
-
const o = await a.signAndExecuteTransaction({
|
|
1544
|
-
...t,
|
|
1545
|
-
options: H(t.options),
|
|
1546
|
-
signer: this.signer
|
|
1547
|
-
});
|
|
1548
|
-
return A("execute", o);
|
|
1549
|
-
}
|
|
1550
|
-
/**
|
|
1551
|
-
* Gets the wallet address from the signer's public key
|
|
1552
|
-
* @returns The wallet address as a string
|
|
1553
|
-
*/
|
|
1554
|
-
get address() {
|
|
1555
|
-
return this.signer.getPublicKey().toSuiAddress();
|
|
1556
|
-
}
|
|
1557
|
-
/**
|
|
1558
|
-
* Gets a specific module by name
|
|
1559
|
-
* @param name - The name of the module to retrieve
|
|
1560
|
-
* @returns The requested module instance
|
|
1561
|
-
*/
|
|
1562
|
-
module(e) {
|
|
1563
|
-
return this.modules[e];
|
|
1564
|
-
}
|
|
1565
|
-
/**
|
|
1566
|
-
* Gets the configuration for a specific module
|
|
1567
|
-
* @param name - The name of the module
|
|
1568
|
-
* @returns The merged configuration (default + user config)
|
|
1569
|
-
*/
|
|
1570
|
-
config(e) {
|
|
1571
|
-
return {
|
|
1572
|
-
...this.modules[e].defaultConfig,
|
|
1573
|
-
...this.userConfigs[e]
|
|
1574
|
-
};
|
|
1575
|
-
}
|
|
1576
|
-
/**
|
|
1577
|
-
* Checks if a module is available
|
|
1578
|
-
* @param name - The name of the module to check
|
|
1579
|
-
* @returns True if the module exists, false otherwise
|
|
1580
|
-
*/
|
|
1581
|
-
hasModule(e) {
|
|
1582
|
-
return e in this.modules;
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
function fe(s) {
|
|
1586
|
-
return {
|
|
1587
|
-
toSuiAddress: () => s,
|
|
1588
|
-
toBytes: () => new Uint8Array(32),
|
|
1589
|
-
toRawBytes: () => new Uint8Array(32),
|
|
1590
|
-
flag: () => 0,
|
|
1591
|
-
verify: async () => !1
|
|
1592
|
-
};
|
|
1593
|
-
}
|
|
1594
|
-
class nt extends we {
|
|
1595
|
-
/**
|
|
1596
|
-
* Creates a new watch-only signer
|
|
1597
|
-
*
|
|
1598
|
-
* @param address - The wallet address to watch
|
|
1599
|
-
*/
|
|
1600
|
-
constructor(e) {
|
|
1601
|
-
super(), this.address = e;
|
|
1602
|
-
}
|
|
1603
|
-
/**
|
|
1604
|
-
* Signs transaction bytes (not implemented for watch-only mode)
|
|
1605
|
-
*
|
|
1606
|
-
* This method is required by the Signer interface but cannot
|
|
1607
|
-
* actually sign transactions in watch-only mode.
|
|
1608
|
-
*
|
|
1609
|
-
* @param bytes - Transaction bytes to sign
|
|
1610
|
-
* @returns Promise<Uint8Array> - Empty signature (not valid)
|
|
1611
|
-
*/
|
|
1612
|
-
async sign(e) {
|
|
1613
|
-
return Promise.resolve(new Uint8Array(0));
|
|
1614
|
-
}
|
|
1615
|
-
/**
|
|
1616
|
-
* Gets the public key information for this signer
|
|
1617
|
-
*
|
|
1618
|
-
* Returns a mock public key object that provides the wallet address
|
|
1619
|
-
* but cannot be used for actual cryptographic operations.
|
|
1620
|
-
*/
|
|
1621
|
-
getPublicKey() {
|
|
1622
|
-
return fe(this.address);
|
|
1623
|
-
}
|
|
1624
|
-
/**
|
|
1625
|
-
* Gets the key scheme for this signer
|
|
1626
|
-
*
|
|
1627
|
-
* @returns Key scheme (ed25519 for compatibility)
|
|
1628
|
-
*/
|
|
1629
|
-
getKeyScheme() {
|
|
1630
|
-
return "ED25519";
|
|
1631
|
-
}
|
|
1632
|
-
/**
|
|
1633
|
-
* Signs and executes a transaction (not implemented for watch-only mode)
|
|
1634
|
-
*
|
|
1635
|
-
* This method is required by the Signer interface but cannot
|
|
1636
|
-
* actually sign and execute transactions in watch-only mode.
|
|
1637
|
-
*/
|
|
1638
|
-
async signAndExecuteTransaction(e) {
|
|
1639
|
-
return {};
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
class at extends we {
|
|
1643
|
-
/**
|
|
1644
|
-
* Creates a new watch-only signer
|
|
1645
|
-
*
|
|
1646
|
-
* @param address - The wallet address to watch
|
|
1647
|
-
*/
|
|
1648
|
-
constructor(e) {
|
|
1649
|
-
super(), this.address = e;
|
|
1650
|
-
}
|
|
1651
|
-
/**
|
|
1652
|
-
* Signs transaction bytes (not implemented for watch-only mode)
|
|
1653
|
-
*
|
|
1654
|
-
* This method is required by the Signer interface but cannot
|
|
1655
|
-
* actually sign transactions in watch-only mode.
|
|
1656
|
-
*
|
|
1657
|
-
* @param bytes - Transaction bytes to sign
|
|
1658
|
-
* @returns Promise<Uint8Array> - Empty signature (not valid)
|
|
1659
|
-
*/
|
|
1660
|
-
async sign(e) {
|
|
1661
|
-
return Promise.resolve(new Uint8Array(0));
|
|
1662
|
-
}
|
|
1663
|
-
/**
|
|
1664
|
-
* Gets the public key information for this signer
|
|
1665
|
-
*
|
|
1666
|
-
* Returns a mock public key object that provides the wallet address
|
|
1667
|
-
* but cannot be used for actual cryptographic operations.
|
|
1668
|
-
*/
|
|
1669
|
-
getPublicKey() {
|
|
1670
|
-
return fe(this.address);
|
|
1671
|
-
}
|
|
1672
|
-
/**
|
|
1673
|
-
* Gets the key scheme for this signer
|
|
1674
|
-
*
|
|
1675
|
-
* @returns Key scheme (ed25519 for compatibility)
|
|
1676
|
-
*/
|
|
1677
|
-
getKeyScheme() {
|
|
1678
|
-
return "ED25519";
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
export {
|
|
1682
|
-
tt as WalletClient,
|
|
1683
|
-
nt as WatchSigner,
|
|
1684
|
-
at as WebSigner
|
|
1685
|
-
};
|
|
1686
|
-
//# sourceMappingURL=index.esm.js.map
|