@naviprotocol/wallet-client 1.0.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/README.md +140 -0
- package/dist/client.d.ts +91 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +1174 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/modules/balanceModule/index.d.ts +140 -0
- package/dist/modules/balanceModule/index.d.ts.map +1 -0
- package/dist/modules/balanceModule/portfolio.d.ts +68 -0
- package/dist/modules/balanceModule/portfolio.d.ts.map +1 -0
- package/dist/modules/haedalModule/index.d.ts +89 -0
- package/dist/modules/haedalModule/index.d.ts.map +1 -0
- package/dist/modules/index.d.ts +53 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/lendingModule/index.d.ts +218 -0
- package/dist/modules/lendingModule/index.d.ts.map +1 -0
- package/dist/modules/module.d.ts +69 -0
- package/dist/modules/module.d.ts.map +1 -0
- package/dist/modules/swapModule/index.d.ts +81 -0
- package/dist/modules/swapModule/index.d.ts.map +1 -0
- package/dist/modules/voloModule/index.d.ts +148 -0
- package/dist/modules/voloModule/index.d.ts.map +1 -0
- package/dist/signer.d.ts +113 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/transport.d.ts +42 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,1174 @@
|
|
|
1
|
+
import { getFullnodeUrl as F, SuiClient as W } from "@mysten/sui/client";
|
|
2
|
+
import _ from "mitt";
|
|
3
|
+
import A from "axios";
|
|
4
|
+
import { withSingleton as j, getCoins as K, mergeCoinsPTB as w, getPools as N, getPool as m, depositCoinPTB as q, withdrawCoinPTB as L, borrowCoinPTB as M, repayCoinPTB as $, getHealthFactor as G, liquidatePTB as H, getUserAvailableLendingRewards as O, getUserClaimedRewardHistory as J, claimLendingRewardsPTB as z, getPriceFeeds as D, filterPriceFeeds as Q, updateOraclePricesPTB as V, getLendingState as X, createAccountCapPTB as Y, withCache as k, parseTxValue as R } from "@naviprotocol/lending";
|
|
5
|
+
import S, { BigNumber as x } from "bignumber.js";
|
|
6
|
+
import { normalizeStructTag as P } from "@mysten/sui/utils";
|
|
7
|
+
import { Transaction as d } from "@mysten/sui/transactions";
|
|
8
|
+
import { generateRefId as Z, getQuote as ee, buildSwapPTBFromQuote as te } from "@naviprotocol/astros-aggregator-sdk";
|
|
9
|
+
import { Signer as U } from "@mysten/sui/cryptography";
|
|
10
|
+
const p = A.create({
|
|
11
|
+
timeout: 2e4
|
|
12
|
+
});
|
|
13
|
+
p.interceptors.response.use(
|
|
14
|
+
function(o) {
|
|
15
|
+
if (o.data.err)
|
|
16
|
+
throw new Error(o.data.err);
|
|
17
|
+
if (o.data.error)
|
|
18
|
+
throw new Error(o.data.error.message);
|
|
19
|
+
return o;
|
|
20
|
+
},
|
|
21
|
+
function(o) {
|
|
22
|
+
return Promise.reject(o);
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
class ae {
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new custom transport instance
|
|
28
|
+
*
|
|
29
|
+
* @param rpcUrl - The RPC endpoint URL for the Sui node
|
|
30
|
+
*/
|
|
31
|
+
constructor(e) {
|
|
32
|
+
this.requestId = 0, this.rpcUrl = e;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Makes an RPC request to the Sui node
|
|
36
|
+
*
|
|
37
|
+
* This method formats the request according to JSON-RPC 2.0 specification
|
|
38
|
+
* and sends it to the configured RPC endpoint.
|
|
39
|
+
*
|
|
40
|
+
* @param input - The transport request options containing method and parameters
|
|
41
|
+
* @returns Promise<T> - The response data from the RPC call
|
|
42
|
+
*/
|
|
43
|
+
async request(e) {
|
|
44
|
+
return this.requestId += 1, (await p.post(this.rpcUrl, {
|
|
45
|
+
jsonrpc: "2.0",
|
|
46
|
+
id: this.requestId,
|
|
47
|
+
method: e.method,
|
|
48
|
+
params: e.params
|
|
49
|
+
})).data.result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Subscribe to events (not implemented)
|
|
53
|
+
*
|
|
54
|
+
* This method is required by the SuiTransport interface but is not
|
|
55
|
+
* implemented in this custom transport. It throws an error if called.
|
|
56
|
+
*
|
|
57
|
+
* @returns Promise<() => Promise<boolean>> - Unsubscribe function
|
|
58
|
+
* @throws Error - Always throws "subscribe not implemented" error
|
|
59
|
+
*/
|
|
60
|
+
async subscribe() {
|
|
61
|
+
throw new Error("subscribe not implemented.");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class T {
|
|
65
|
+
/**
|
|
66
|
+
* Gets the current configuration for this module
|
|
67
|
+
*
|
|
68
|
+
* This combines the default configuration with any user-provided overrides
|
|
69
|
+
* from the wallet client configuration.
|
|
70
|
+
*
|
|
71
|
+
* @returns The merged configuration for this module
|
|
72
|
+
*/
|
|
73
|
+
get config() {
|
|
74
|
+
return this.walletClient ? this.walletClient.config(this.name) : this.defaultConfig;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Emits an event through the wallet client's event system
|
|
78
|
+
*
|
|
79
|
+
* @param event - The event name to emit
|
|
80
|
+
* @param data - The event data to emit
|
|
81
|
+
*/
|
|
82
|
+
emit(e, a) {
|
|
83
|
+
var t;
|
|
84
|
+
(t = this.walletClient) == null || t.events.emit(e, a);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Installs this module into a wallet client
|
|
88
|
+
*
|
|
89
|
+
* This method is called by the wallet client during initialization
|
|
90
|
+
* to establish the connection between the module and the client.
|
|
91
|
+
*
|
|
92
|
+
* @param walletClient - The wallet client instance to install into
|
|
93
|
+
*/
|
|
94
|
+
install(e) {
|
|
95
|
+
this.walletClient = e;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Uninstalls this module from the wallet client
|
|
99
|
+
*
|
|
100
|
+
* This method removes the reference to the wallet client,
|
|
101
|
+
* effectively disconnecting the module.
|
|
102
|
+
*/
|
|
103
|
+
uninstall() {
|
|
104
|
+
this.walletClient = void 0;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
class B {
|
|
108
|
+
/**
|
|
109
|
+
* Creates a new user portfolio
|
|
110
|
+
*
|
|
111
|
+
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
112
|
+
*/
|
|
113
|
+
constructor(e) {
|
|
114
|
+
if (e instanceof B)
|
|
115
|
+
this.balances = JSON.parse(JSON.stringify(e.balances));
|
|
116
|
+
else {
|
|
117
|
+
const a = {};
|
|
118
|
+
e == null || e.forEach((t) => {
|
|
119
|
+
const s = P(t.coinType);
|
|
120
|
+
let n = a[s];
|
|
121
|
+
n || (n = {
|
|
122
|
+
coinType: s,
|
|
123
|
+
amount: x(0),
|
|
124
|
+
coins: []
|
|
125
|
+
}, a[s] = n), n.coins.push(t), n.amount = n.amount.plus(t.balance);
|
|
126
|
+
}), this.balances = a;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Gets balance information for a specific coin type
|
|
131
|
+
*
|
|
132
|
+
* @param coinType - The coin type to query
|
|
133
|
+
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
134
|
+
*/
|
|
135
|
+
getBalance(e) {
|
|
136
|
+
return e = P(e), this.balances[e] || { coinType: e, amount: x(0), coins: [] };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Gets all coin types in the portfolio
|
|
140
|
+
*
|
|
141
|
+
* @returns Array of coin type strings
|
|
142
|
+
*/
|
|
143
|
+
getCoinTypes() {
|
|
144
|
+
return Object.values(this.balances).map((e) => e.coinType);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Gets the total balance amount for a specific coin type
|
|
148
|
+
*
|
|
149
|
+
* @param coinType - The coin type to query
|
|
150
|
+
* @returns BigNumber representing the total balance
|
|
151
|
+
*/
|
|
152
|
+
balanceOf(e) {
|
|
153
|
+
e = P(e);
|
|
154
|
+
const a = this.getBalance(e);
|
|
155
|
+
return (a == null ? void 0 : a.amount) || x(0);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates a deep copy of the portfolio
|
|
159
|
+
*
|
|
160
|
+
* This method creates a completely independent copy of the portfolio
|
|
161
|
+
* that can be modified without affecting the original.
|
|
162
|
+
*
|
|
163
|
+
* @returns New UserPortfolio instance with copied data
|
|
164
|
+
*/
|
|
165
|
+
clone() {
|
|
166
|
+
const e = JSON.parse(JSON.stringify(this.balances)), a = new B();
|
|
167
|
+
return a.balances = e, a;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
class ne extends T {
|
|
171
|
+
constructor() {
|
|
172
|
+
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
173
|
+
coinPollingInterval: 6e3
|
|
174
|
+
}, this.updatePortfolio = j(async () => {
|
|
175
|
+
if (!this.walletClient)
|
|
176
|
+
throw new Error("Wallet client not found");
|
|
177
|
+
this._coins = await K(this.walletClient.address, {
|
|
178
|
+
client: this.walletClient.client
|
|
179
|
+
}), this._portfolio = new B(this._coins), this.emit("balance:portfolio-updated", {});
|
|
180
|
+
}), this._coins = [], this._portfolio = new B(), this.pollingTimer = null, this._updatePromise = null;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Gets the current coin objects from the wallet
|
|
184
|
+
*
|
|
185
|
+
* @returns Array of coin objects owned by the wallet
|
|
186
|
+
*/
|
|
187
|
+
get coins() {
|
|
188
|
+
return this._coins;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Gets the current portfolio information
|
|
192
|
+
*
|
|
193
|
+
* @returns UserPortfolio instance with current balance information
|
|
194
|
+
*/
|
|
195
|
+
get portfolio() {
|
|
196
|
+
return this._portfolio;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Waits for the next portfolio update to complete
|
|
200
|
+
*
|
|
201
|
+
* @returns Promise that resolves when the portfolio is updated
|
|
202
|
+
* @throws Error if no update promise is available
|
|
203
|
+
*/
|
|
204
|
+
async waitForUpdate() {
|
|
205
|
+
if (!this._updatePromise)
|
|
206
|
+
throw new Error("Update promise not found");
|
|
207
|
+
return await this._updatePromise;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Sends a single coin to a recipient
|
|
211
|
+
*
|
|
212
|
+
* @param coinType - Type of coin to send
|
|
213
|
+
* @param recipient - Recipient address
|
|
214
|
+
* @param amount - Amount to send
|
|
215
|
+
* @param options - Optional parameters including dry run mode
|
|
216
|
+
* @returns Transaction response or dry run response
|
|
217
|
+
*/
|
|
218
|
+
async sendCoin(e, a, t, s) {
|
|
219
|
+
return this.sendCoinBatch(e, [a], [t], s);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Sends coins to multiple recipients in a single transaction
|
|
223
|
+
*
|
|
224
|
+
* @param coinType - Type of coin to send
|
|
225
|
+
* @param recipients - Array of recipient addresses
|
|
226
|
+
* @param amounts - Array of amounts to send (must match recipients length)
|
|
227
|
+
* @param options - Optional parameters including dry run mode
|
|
228
|
+
* @returns Transaction response or dry run response
|
|
229
|
+
*/
|
|
230
|
+
async sendCoinBatch(e, a, t, s) {
|
|
231
|
+
var h;
|
|
232
|
+
if (!this.walletClient)
|
|
233
|
+
throw new Error("Wallet client not found");
|
|
234
|
+
if (a.length !== t.length)
|
|
235
|
+
throw new Error("Recipients and amounts must have the same length");
|
|
236
|
+
await this.waitForUpdate();
|
|
237
|
+
const n = this.portfolio.getBalance(e), r = t.reduce((g, f) => g.plus(f), S(0));
|
|
238
|
+
if (n.amount.lt(r))
|
|
239
|
+
throw new Error("Insufficient balance");
|
|
240
|
+
const l = new d();
|
|
241
|
+
let i = l.gas;
|
|
242
|
+
P(e) !== P("0x2::sui::SUI") && (i = w(l, n.coins, {
|
|
243
|
+
balance: r.toNumber()
|
|
244
|
+
}));
|
|
245
|
+
const c = l.splitCoins(i, t);
|
|
246
|
+
return a.forEach((g, f) => {
|
|
247
|
+
l.transferObjects([c[f]], g);
|
|
248
|
+
}), await this.walletClient.signExecuteTransaction({
|
|
249
|
+
transaction: l,
|
|
250
|
+
dryRun: (h = s == null ? void 0 : s.dryRun) != null ? h : !1
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Transfers a single object to a recipient
|
|
255
|
+
*
|
|
256
|
+
* @param object - Object ID to transfer
|
|
257
|
+
* @param recipient - Recipient address
|
|
258
|
+
* @param options - Optional parameters including dry run mode
|
|
259
|
+
* @returns Transaction response or dry run response
|
|
260
|
+
*/
|
|
261
|
+
async transferObject(e, a, t) {
|
|
262
|
+
return this.transferObjectBatch([e], [a], t);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Transfers multiple objects to their respective recipients in a single transaction
|
|
266
|
+
*
|
|
267
|
+
* Each object is transferred to its corresponding recipient by index
|
|
268
|
+
* (first object → first recipient, second object → second recipient, etc.)
|
|
269
|
+
*
|
|
270
|
+
* @param objects - Object IDs to transfer
|
|
271
|
+
* @param recipients - Recipient addresses (must match objects array length)
|
|
272
|
+
* @param options - Optional parameters including dry run mode
|
|
273
|
+
* @returns Transaction response or dry run response
|
|
274
|
+
*/
|
|
275
|
+
async transferObjectBatch(e, a, t) {
|
|
276
|
+
var r;
|
|
277
|
+
if (!this.walletClient)
|
|
278
|
+
throw new Error("Wallet client not found");
|
|
279
|
+
if (e.length !== a.length)
|
|
280
|
+
throw new Error("Objects and recipients must have the same length");
|
|
281
|
+
await this.waitForUpdate();
|
|
282
|
+
const s = new d();
|
|
283
|
+
return e.forEach((l, i) => {
|
|
284
|
+
s.transferObjects([s.object(l)], a[i]);
|
|
285
|
+
}), await this.walletClient.signExecuteTransaction({
|
|
286
|
+
transaction: s,
|
|
287
|
+
dryRun: (r = t == null ? void 0 : t.dryRun) != null ? r : !1
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Starts polling for portfolio updates
|
|
292
|
+
*
|
|
293
|
+
* This method recursively schedules itself to run at the configured
|
|
294
|
+
* interval, ensuring regular balance updates.
|
|
295
|
+
*/
|
|
296
|
+
async startPolling() {
|
|
297
|
+
try {
|
|
298
|
+
await this.updatePortfolio();
|
|
299
|
+
} catch (e) {
|
|
300
|
+
console.error(e);
|
|
301
|
+
} finally {
|
|
302
|
+
this.pollingTimer = setTimeout(this.startPolling, this.config.coinPollingInterval);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Installs the balance module into a wallet client
|
|
307
|
+
*
|
|
308
|
+
* @param walletClient - The wallet client instance to install into
|
|
309
|
+
*/
|
|
310
|
+
install(e) {
|
|
311
|
+
super.install(e), this.startPolling = this.startPolling.bind(this), this.startPolling(), this._updatePromise = new Promise((a) => {
|
|
312
|
+
e.events.on("balance:portfolio-updated", () => {
|
|
313
|
+
a();
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Uninstalls the balance module from the wallet client
|
|
319
|
+
*
|
|
320
|
+
* This method cleans up timers and stops polling to prevent memory leaks.
|
|
321
|
+
*/
|
|
322
|
+
uninstall() {
|
|
323
|
+
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
class se extends T {
|
|
327
|
+
constructor() {
|
|
328
|
+
super(...arguments), this.name = "lending", this.defaultConfig = {
|
|
329
|
+
env: "prod"
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Gets all available lending pools
|
|
334
|
+
*
|
|
335
|
+
* @param options - Optional caching options
|
|
336
|
+
* @returns Array of pool information
|
|
337
|
+
*/
|
|
338
|
+
async getPools(e) {
|
|
339
|
+
return await N({
|
|
340
|
+
env: this.config.env,
|
|
341
|
+
...e
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Gets information for a specific lending pool
|
|
346
|
+
*
|
|
347
|
+
* @param identifier - Asset identifier (string, Pool object, or number)
|
|
348
|
+
* @param options - Optional caching options
|
|
349
|
+
* @returns Pool information
|
|
350
|
+
*/
|
|
351
|
+
async getPool(e, a) {
|
|
352
|
+
return await m(e, {
|
|
353
|
+
env: this.config.env,
|
|
354
|
+
...a
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Deposits coins into a lending pool
|
|
359
|
+
*
|
|
360
|
+
* @param identifier - Asset identifier for the pool
|
|
361
|
+
* @param amount - Amount to deposit
|
|
362
|
+
* @param options - Optional parameters including dry run mode and account capability
|
|
363
|
+
* @returns Transaction response or dry run response
|
|
364
|
+
*/
|
|
365
|
+
async deposit(e, a, t) {
|
|
366
|
+
var c, u, h;
|
|
367
|
+
if (!this.walletClient)
|
|
368
|
+
throw new Error("Wallet client not found");
|
|
369
|
+
const s = await m(e, {
|
|
370
|
+
env: this.config.env
|
|
371
|
+
});
|
|
372
|
+
await this.walletClient.module("balance").waitForUpdate();
|
|
373
|
+
const n = new d(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), l = w(n, r.coins, {
|
|
374
|
+
balance: a,
|
|
375
|
+
useGasCoin: !0
|
|
376
|
+
});
|
|
377
|
+
await q(n, s, l, {
|
|
378
|
+
env: this.config.env,
|
|
379
|
+
amount: a,
|
|
380
|
+
accountCap: t == null ? void 0 : t.accountCap
|
|
381
|
+
});
|
|
382
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
383
|
+
transaction: n,
|
|
384
|
+
dryRun: (c = t == null ? void 0 : t.dryRun) != null ? c : !1
|
|
385
|
+
});
|
|
386
|
+
return !(t != null && t.dryRun) && ((h = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : h.status) === "success" && (this.emit("lending:deposit-success", {
|
|
387
|
+
identifier: e,
|
|
388
|
+
amount: a
|
|
389
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Withdraws coins from a lending pool
|
|
393
|
+
*
|
|
394
|
+
* @param identifier - Asset identifier for the pool
|
|
395
|
+
* @param amount - Amount to withdraw
|
|
396
|
+
* @param options - Optional parameters including dry run mode and account capability
|
|
397
|
+
* @returns Transaction response or dry run response
|
|
398
|
+
*/
|
|
399
|
+
async withdraw(e, a, t) {
|
|
400
|
+
var i, c, u;
|
|
401
|
+
if (!this.walletClient)
|
|
402
|
+
throw new Error("Wallet client not found");
|
|
403
|
+
const s = await m(e, {
|
|
404
|
+
env: this.config.env
|
|
405
|
+
}), n = new d();
|
|
406
|
+
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
407
|
+
const r = await L(n, s, a, {
|
|
408
|
+
env: this.config.env,
|
|
409
|
+
accountCap: t == null ? void 0 : t.accountCap
|
|
410
|
+
});
|
|
411
|
+
n.transferObjects([r], this.walletClient.address);
|
|
412
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
413
|
+
transaction: n,
|
|
414
|
+
dryRun: (i = t == null ? void 0 : t.dryRun) != null ? i : !1
|
|
415
|
+
});
|
|
416
|
+
return !(t != null && t.dryRun) && ((u = (c = l.effects) == null ? void 0 : c.status) == null ? void 0 : u.status) === "success" && (this.emit("lending:withdraw-success", {
|
|
417
|
+
identifier: e,
|
|
418
|
+
amount: a
|
|
419
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Borrows coins from a lending pool
|
|
423
|
+
*
|
|
424
|
+
* @param identifier - Asset identifier for the pool
|
|
425
|
+
* @param amount - Amount to borrow
|
|
426
|
+
* @param options - Optional parameters including dry run mode and account capability
|
|
427
|
+
* @returns Transaction response or dry run response
|
|
428
|
+
*/
|
|
429
|
+
async borrow(e, a, t) {
|
|
430
|
+
var i, c, u;
|
|
431
|
+
if (!this.walletClient)
|
|
432
|
+
throw new Error("Wallet client not found");
|
|
433
|
+
const s = await m(e, {
|
|
434
|
+
env: this.config.env
|
|
435
|
+
}), n = new d();
|
|
436
|
+
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
437
|
+
const r = await M(n, s, a, {
|
|
438
|
+
env: this.config.env,
|
|
439
|
+
accountCap: t == null ? void 0 : t.accountCap
|
|
440
|
+
});
|
|
441
|
+
n.transferObjects([r], this.walletClient.address);
|
|
442
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
443
|
+
transaction: n,
|
|
444
|
+
dryRun: (i = t == null ? void 0 : t.dryRun) != null ? i : !1
|
|
445
|
+
});
|
|
446
|
+
return !(t != null && t.dryRun) && ((u = (c = l.effects) == null ? void 0 : c.status) == null ? void 0 : u.status) === "success" && (this.emit("lending:borrow-success", {
|
|
447
|
+
identifier: e,
|
|
448
|
+
amount: a
|
|
449
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Repays borrowed coins to a lending pool
|
|
453
|
+
*
|
|
454
|
+
* @param identifier - Asset identifier for the pool
|
|
455
|
+
* @param amount - Amount to repay
|
|
456
|
+
* @param options - Optional parameters including dry run mode and account capability
|
|
457
|
+
* @returns Transaction response or dry run response
|
|
458
|
+
*/
|
|
459
|
+
async repay(e, a, t) {
|
|
460
|
+
var c, u, h;
|
|
461
|
+
if (!this.walletClient)
|
|
462
|
+
throw new Error("Wallet client not found");
|
|
463
|
+
await this.walletClient.module("balance").waitForUpdate();
|
|
464
|
+
const s = await m(e, {
|
|
465
|
+
env: this.config.env
|
|
466
|
+
}), n = new d(), r = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), l = w(n, r.coins, {
|
|
467
|
+
balance: a,
|
|
468
|
+
useGasCoin: !0
|
|
469
|
+
});
|
|
470
|
+
await $(n, s, l, {
|
|
471
|
+
env: this.config.env,
|
|
472
|
+
amount: a,
|
|
473
|
+
accountCap: t == null ? void 0 : t.accountCap
|
|
474
|
+
});
|
|
475
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
476
|
+
transaction: n,
|
|
477
|
+
dryRun: (c = t == null ? void 0 : t.dryRun) != null ? c : !1
|
|
478
|
+
});
|
|
479
|
+
return !(t != null && t.dryRun) && ((h = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : h.status) === "success" && (this.emit("lending:repay-success", {
|
|
480
|
+
identifier: e,
|
|
481
|
+
amount: a
|
|
482
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Gets the current health factor for the user
|
|
486
|
+
*
|
|
487
|
+
* @returns Current health factor value
|
|
488
|
+
*/
|
|
489
|
+
async getHealthFactor() {
|
|
490
|
+
if (!this.walletClient)
|
|
491
|
+
throw new Error("Wallet client not found");
|
|
492
|
+
const e = this.walletClient.address;
|
|
493
|
+
return await G(e, {
|
|
494
|
+
env: this.config.env,
|
|
495
|
+
client: this.walletClient.client
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Initiates a liquidation process
|
|
500
|
+
*
|
|
501
|
+
* @param payIdentifier - Asset identifier for the debt being paid
|
|
502
|
+
* @param payAmount - Amount of debt to pay
|
|
503
|
+
* @param collateralIdentifier - Asset identifier for the collateral being liquidated
|
|
504
|
+
* @param liquidationAddress - Address of the account being liquidated
|
|
505
|
+
* @param options - Optional parameters including dry run mode
|
|
506
|
+
* @returns Transaction response or dry run response
|
|
507
|
+
*/
|
|
508
|
+
async liquidate(e, a, t, s, n) {
|
|
509
|
+
var b, y, v;
|
|
510
|
+
if (!this.walletClient)
|
|
511
|
+
throw new Error("Wallet client not found");
|
|
512
|
+
const r = await m(e, {
|
|
513
|
+
env: this.config.env
|
|
514
|
+
}), l = await m(t, {
|
|
515
|
+
env: this.config.env
|
|
516
|
+
}), i = new d(), c = this.walletClient.module("balance").portfolio.getBalance(r.suiCoinType), u = w(i, c.coins, {
|
|
517
|
+
balance: a,
|
|
518
|
+
useGasCoin: !0
|
|
519
|
+
}), [h, g] = await H(
|
|
520
|
+
i,
|
|
521
|
+
r,
|
|
522
|
+
u,
|
|
523
|
+
l,
|
|
524
|
+
s,
|
|
525
|
+
{
|
|
526
|
+
env: this.config.env
|
|
527
|
+
}
|
|
528
|
+
), [f] = i.moveCall({
|
|
529
|
+
target: "0x2::coin::from_balance",
|
|
530
|
+
arguments: [h],
|
|
531
|
+
typeArguments: [l.suiCoinType]
|
|
532
|
+
}), [E] = i.moveCall({
|
|
533
|
+
target: "0x2::coin::from_balance",
|
|
534
|
+
arguments: [g],
|
|
535
|
+
typeArguments: [r.suiCoinType]
|
|
536
|
+
});
|
|
537
|
+
i.transferObjects([f, E], this.walletClient.address);
|
|
538
|
+
const C = await this.walletClient.signExecuteTransaction({
|
|
539
|
+
transaction: i,
|
|
540
|
+
dryRun: (b = n == null ? void 0 : n.dryRun) != null ? b : !1
|
|
541
|
+
});
|
|
542
|
+
return !(n != null && n.dryRun) && ((v = (y = C.effects) == null ? void 0 : y.status) == null ? void 0 : v.status) === "success" && (this.emit("lending:liquidate-success", {
|
|
543
|
+
payIdentifier: e,
|
|
544
|
+
payAmount: a,
|
|
545
|
+
collateralIdentifier: t,
|
|
546
|
+
liquidationAddress: s
|
|
547
|
+
}), this.walletClient.module("balance").updatePortfolio()), C;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Gets the available lending rewards for the current user.
|
|
551
|
+
*
|
|
552
|
+
* @param options - Optional cache options.
|
|
553
|
+
* @returns The available lending rewards for the user.
|
|
554
|
+
* @throws If the wallet client is not found.
|
|
555
|
+
*/
|
|
556
|
+
async getAvailableRewards(e) {
|
|
557
|
+
if (!this.walletClient)
|
|
558
|
+
throw new Error("Wallet client not found");
|
|
559
|
+
return O(this.walletClient.address, {
|
|
560
|
+
...e,
|
|
561
|
+
env: this.config.env
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Gets the claimed reward history for the current user.
|
|
566
|
+
*
|
|
567
|
+
* @param options - Optional cache options.
|
|
568
|
+
* @returns The claimed reward history for the user.
|
|
569
|
+
* @throws If the wallet client is not found.
|
|
570
|
+
*/
|
|
571
|
+
async getClaimedRewardHistory(e) {
|
|
572
|
+
if (!this.walletClient)
|
|
573
|
+
throw new Error("Wallet client not found");
|
|
574
|
+
return J(this.walletClient.address, {
|
|
575
|
+
...e
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Claims all available lending rewards for the user
|
|
580
|
+
*
|
|
581
|
+
* @param options - Optional parameters including dry run mode and account capability
|
|
582
|
+
* @returns Transaction response or dry run response
|
|
583
|
+
*/
|
|
584
|
+
async claimAllRewards(e) {
|
|
585
|
+
var n, r, l;
|
|
586
|
+
if (!this.walletClient)
|
|
587
|
+
throw new Error("Wallet client not found");
|
|
588
|
+
const a = new d(), t = await O(this.walletClient.address, {
|
|
589
|
+
env: this.config.env
|
|
590
|
+
});
|
|
591
|
+
await z(a, t, {
|
|
592
|
+
env: this.config.env,
|
|
593
|
+
accountCap: e == null ? void 0 : e.accountCap
|
|
594
|
+
});
|
|
595
|
+
const s = await this.walletClient.signExecuteTransaction({
|
|
596
|
+
transaction: a,
|
|
597
|
+
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
598
|
+
});
|
|
599
|
+
return !(e != null && e.dryRun) && ((l = (r = s.effects) == null ? void 0 : r.status) == null ? void 0 : l.status) === "success" && (this.emit("lending:claim-rewards-success", {
|
|
600
|
+
rewards: t
|
|
601
|
+
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
602
|
+
}
|
|
603
|
+
async updateOraclePTB(e, a) {
|
|
604
|
+
const t = await D({
|
|
605
|
+
env: this.config.env
|
|
606
|
+
}), s = await this.getLendingState({
|
|
607
|
+
cacheTime: 60 * 1e3
|
|
608
|
+
}), n = Q(t, {
|
|
609
|
+
lendingState: s,
|
|
610
|
+
pools: a
|
|
611
|
+
});
|
|
612
|
+
await V(e, n, {
|
|
613
|
+
env: this.config.env,
|
|
614
|
+
updatePythPriceFeeds: !0
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Updates the oracle prices for the lending protocol
|
|
619
|
+
*
|
|
620
|
+
* @param options - Optional parameters including dry run mode and pools
|
|
621
|
+
* @param options.dryRun - Whether to perform a dry run
|
|
622
|
+
* @returns Transaction response or dry run response
|
|
623
|
+
*/
|
|
624
|
+
async updateOracle(e) {
|
|
625
|
+
var s;
|
|
626
|
+
if (!this.walletClient)
|
|
627
|
+
throw new Error("Wallet client not found");
|
|
628
|
+
const a = new d();
|
|
629
|
+
return await this.updateOraclePTB(a, e == null ? void 0 : e.pools), await this.walletClient.signExecuteTransaction({
|
|
630
|
+
transaction: a,
|
|
631
|
+
dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Gets all active lending positions for the user
|
|
636
|
+
*
|
|
637
|
+
* @param options - Optional caching options
|
|
638
|
+
* @returns User's lending state information
|
|
639
|
+
*/
|
|
640
|
+
async getLendingState(e) {
|
|
641
|
+
if (!this.walletClient)
|
|
642
|
+
throw new Error("Wallet client not found");
|
|
643
|
+
return await X(this.walletClient.address, {
|
|
644
|
+
env: this.config.env,
|
|
645
|
+
...e,
|
|
646
|
+
client: this.walletClient.client
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Creates an account capability for the lending protocol
|
|
651
|
+
*
|
|
652
|
+
* @param options - Optional parameters including dry run mode
|
|
653
|
+
* @returns Transaction response or dry run response
|
|
654
|
+
*/
|
|
655
|
+
async createAccountCap(e) {
|
|
656
|
+
var n;
|
|
657
|
+
if (!this.walletClient)
|
|
658
|
+
throw new Error("Wallet client not found");
|
|
659
|
+
const a = new d(), t = await Y(a);
|
|
660
|
+
return a.transferObjects([t], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
661
|
+
transaction: a,
|
|
662
|
+
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
class le extends T {
|
|
667
|
+
constructor() {
|
|
668
|
+
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
669
|
+
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
670
|
+
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
671
|
+
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
672
|
+
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
673
|
+
}, this.getStats = k(
|
|
674
|
+
j(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Adds staking operation to a transaction black
|
|
679
|
+
*
|
|
680
|
+
* @param tx - The transaction block to add the staking operation to
|
|
681
|
+
* @param suiCoin - The SUI coin object to stake
|
|
682
|
+
* @returns The vSUI coin object received from staking
|
|
683
|
+
*/
|
|
684
|
+
async stakePTB(e, a) {
|
|
685
|
+
const [t] = e.moveCall({
|
|
686
|
+
target: `${this.config.packageId}::stake_pool::stake`,
|
|
687
|
+
arguments: [
|
|
688
|
+
e.object(this.config.poolId),
|
|
689
|
+
e.object(this.config.metadataId),
|
|
690
|
+
e.object("0x05"),
|
|
691
|
+
R(a, e.object)
|
|
692
|
+
],
|
|
693
|
+
typeArguments: []
|
|
694
|
+
});
|
|
695
|
+
return t;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Adds unstaking operation to a transaction black
|
|
699
|
+
*
|
|
700
|
+
* @param tx - The transaction block to add the unstaking operation to
|
|
701
|
+
* @param vSuiCoin - The vSUI coin object to unstake
|
|
702
|
+
* @returns The SUI coin object received from unstaking
|
|
703
|
+
*/
|
|
704
|
+
async unstakePTB(e, a) {
|
|
705
|
+
const [t] = e.moveCall({
|
|
706
|
+
target: `${this.config.packageId}::stake_pool::unstake`,
|
|
707
|
+
arguments: [
|
|
708
|
+
e.object(this.config.poolId),
|
|
709
|
+
e.object(this.config.metadataId),
|
|
710
|
+
e.object("0x05"),
|
|
711
|
+
R(a, e.object)
|
|
712
|
+
],
|
|
713
|
+
typeArguments: []
|
|
714
|
+
});
|
|
715
|
+
return t;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Stake SUI tokens to receive vSUI tokens
|
|
719
|
+
*
|
|
720
|
+
* @param suiAmount - Amount of SUI to stake (in MIST units)
|
|
721
|
+
* @param options - Optional parameters including dryRun flag
|
|
722
|
+
* @returns Transaction response or dry run response
|
|
723
|
+
* @throws Error if wallet client not found or stake amount is too low
|
|
724
|
+
*/
|
|
725
|
+
async stake(e, a) {
|
|
726
|
+
var i, c, u;
|
|
727
|
+
if (!this.walletClient)
|
|
728
|
+
throw new Error("Wallet client not found");
|
|
729
|
+
if (e < 1e9)
|
|
730
|
+
throw new Error("Stake amount should be greater than 1Sui");
|
|
731
|
+
const t = new d();
|
|
732
|
+
await this.walletClient.module("balance").waitForUpdate();
|
|
733
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = w(t, s.coins, {
|
|
734
|
+
balance: e,
|
|
735
|
+
useGasCoin: !0
|
|
736
|
+
}), r = await this.stakePTB(t, n);
|
|
737
|
+
t.transferObjects([r], this.walletClient.address);
|
|
738
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
739
|
+
transaction: t,
|
|
740
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
741
|
+
});
|
|
742
|
+
return !(a != null && a.dryRun) && ((u = (c = l.effects) == null ? void 0 : c.status) == null ? void 0 : u.status) === "success" && (this.emit("volo:stake-success", {
|
|
743
|
+
suiAmount: e
|
|
744
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Unstake vSUI tokens to receive SUI tokens
|
|
748
|
+
*
|
|
749
|
+
* @param vSuiAmount - Amount of vSUI to unstake (in MIST units)
|
|
750
|
+
* @param options - Optional parameters including dryRun flag
|
|
751
|
+
* @returns Transaction response or dry run response
|
|
752
|
+
* @throws Error if wallet client not found or unstake amount is too low
|
|
753
|
+
*/
|
|
754
|
+
async unstake(e, a) {
|
|
755
|
+
var i, c, u;
|
|
756
|
+
if (!this.walletClient)
|
|
757
|
+
throw new Error("Wallet client not found");
|
|
758
|
+
if (e < 1e9)
|
|
759
|
+
throw new Error("Unstake amount should >= 1vSui");
|
|
760
|
+
await this.walletClient.module("balance").waitForUpdate();
|
|
761
|
+
const t = new d(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = w(t, s.coins, {
|
|
762
|
+
balance: e
|
|
763
|
+
}), r = await this.unstakePTB(t, n);
|
|
764
|
+
t.transferObjects([r], this.walletClient.address);
|
|
765
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
766
|
+
transaction: t,
|
|
767
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
768
|
+
});
|
|
769
|
+
return !(a != null && a.dryRun) && ((u = (c = l.effects) == null ? void 0 : c.status) == null ? void 0 : u.status) === "success" && (this.emit("volo:unstake-success", {
|
|
770
|
+
vSuiAmount: e
|
|
771
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
class ie extends T {
|
|
775
|
+
constructor() {
|
|
776
|
+
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
777
|
+
apiKey: "",
|
|
778
|
+
baseUrl: "https://open-aggregator-api.naviprotocol.io/find_routes",
|
|
779
|
+
dexList: [],
|
|
780
|
+
depth: 3,
|
|
781
|
+
serviceFee: void 0,
|
|
782
|
+
env: "prod"
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Gets the referral ID for this swap module
|
|
787
|
+
*
|
|
788
|
+
* @returns Referral ID if API key is configured, otherwise 0
|
|
789
|
+
*/
|
|
790
|
+
get referral() {
|
|
791
|
+
return this.config.apiKey ? Z(this.config.apiKey) : 0;
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Executes a swap between two coin types
|
|
795
|
+
*
|
|
796
|
+
* This method performs a complete swap operation including:
|
|
797
|
+
* - Balance validation
|
|
798
|
+
* - Quote retrieval from aggregator
|
|
799
|
+
* - Transaction building with slippage protection
|
|
800
|
+
* - Transaction execution
|
|
801
|
+
* - Event emission on success
|
|
802
|
+
*
|
|
803
|
+
* @param fromCoinType - Source coin type
|
|
804
|
+
* @param toCoinType - Target coin type
|
|
805
|
+
* @param fromAmount - Amount to swap
|
|
806
|
+
* @param slippage - Slippage tolerance (0-1)
|
|
807
|
+
* @param options - Optional parameters including dry run mode
|
|
808
|
+
* @returns Transaction response or dry run response
|
|
809
|
+
*/
|
|
810
|
+
async swap(e, a, t, s, n) {
|
|
811
|
+
var E, C, b, y;
|
|
812
|
+
if (!this.walletClient)
|
|
813
|
+
throw new Error("Wallet client not found");
|
|
814
|
+
await this.walletClient.module("balance").waitForUpdate();
|
|
815
|
+
const r = this.walletClient.module("balance").portfolio.getBalance(e), l = new d(), i = w(l, r.coins, {
|
|
816
|
+
balance: t,
|
|
817
|
+
useGasCoin: !0
|
|
818
|
+
}), c = {
|
|
819
|
+
baseUrl: this.config.baseUrl,
|
|
820
|
+
dexList: this.config.dexList,
|
|
821
|
+
depth: this.config.depth,
|
|
822
|
+
serviceFee: this.config.serviceFee
|
|
823
|
+
}, u = await ee(
|
|
824
|
+
e,
|
|
825
|
+
a,
|
|
826
|
+
t,
|
|
827
|
+
this.config.apiKey,
|
|
828
|
+
c
|
|
829
|
+
), h = new S(u.amount_out).multipliedBy(1 - s).toFixed(0), g = await te(
|
|
830
|
+
this.walletClient.address,
|
|
831
|
+
l,
|
|
832
|
+
Number(h),
|
|
833
|
+
i,
|
|
834
|
+
u,
|
|
835
|
+
this.referral,
|
|
836
|
+
!1,
|
|
837
|
+
this.config.apiKey,
|
|
838
|
+
c
|
|
839
|
+
);
|
|
840
|
+
l.transferObjects([g], this.walletClient.address);
|
|
841
|
+
const f = await this.walletClient.signExecuteTransaction({
|
|
842
|
+
transaction: l,
|
|
843
|
+
dryRun: (E = n == null ? void 0 : n.dryRun) != null ? E : !1
|
|
844
|
+
});
|
|
845
|
+
if (!(n != null && n.dryRun) && ((b = (C = f.effects) == null ? void 0 : C.status) == null ? void 0 : b.status) === "success") {
|
|
846
|
+
const v = (y = f.events) == null ? void 0 : y.find((I) => I.type.includes("::slippage::SwapEvent"));
|
|
847
|
+
v && this.emit("swap:swap-success", {
|
|
848
|
+
fromCoinType: e,
|
|
849
|
+
toCoinType: a,
|
|
850
|
+
fromAmount: t,
|
|
851
|
+
slippage: s,
|
|
852
|
+
toAmount: Number(v.parsedJson.amount_out)
|
|
853
|
+
}), this.walletClient.module("balance").updatePortfolio();
|
|
854
|
+
}
|
|
855
|
+
return f;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
class re extends T {
|
|
859
|
+
constructor() {
|
|
860
|
+
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
861
|
+
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
862
|
+
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
863
|
+
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
864
|
+
}, this.getApy = k(
|
|
865
|
+
j(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Builds a transaction block for staking SUI to haSUI
|
|
870
|
+
*
|
|
871
|
+
* @param tx - Transaction to add staking operation to
|
|
872
|
+
* @param suiCoin - Sui coin object to stake
|
|
873
|
+
* @returns haSUI coin object
|
|
874
|
+
*/
|
|
875
|
+
async stakePTB(e, a) {
|
|
876
|
+
const [t] = e.moveCall({
|
|
877
|
+
target: `${this.config.packageId}::staking::request_stake_coin`,
|
|
878
|
+
arguments: [
|
|
879
|
+
e.object("0x05"),
|
|
880
|
+
e.object(this.config.configId),
|
|
881
|
+
R(a, e.object),
|
|
882
|
+
e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
883
|
+
],
|
|
884
|
+
typeArguments: []
|
|
885
|
+
});
|
|
886
|
+
return t;
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Builds a transaction block for unstaking haSUI to SUI
|
|
890
|
+
*
|
|
891
|
+
* @param tx - Transaction to add unstaking operation to
|
|
892
|
+
* @param haSUICoin - haSUI coin object to unstake
|
|
893
|
+
* @returns SUI coin object
|
|
894
|
+
*/
|
|
895
|
+
async unstakePTB(e, a) {
|
|
896
|
+
const [t] = e.moveCall({
|
|
897
|
+
target: `${this.config.packageId}::staking::request_unstake_instant_coin`,
|
|
898
|
+
arguments: [
|
|
899
|
+
e.object("0x05"),
|
|
900
|
+
e.object(this.config.configId),
|
|
901
|
+
R(a, e.object)
|
|
902
|
+
],
|
|
903
|
+
typeArguments: []
|
|
904
|
+
});
|
|
905
|
+
return t;
|
|
906
|
+
}
|
|
907
|
+
/**
|
|
908
|
+
* Stake SUI for haSUI
|
|
909
|
+
*
|
|
910
|
+
* @param suiAmount - Amount of SUI to stake
|
|
911
|
+
* @param options Optional dry run
|
|
912
|
+
*/
|
|
913
|
+
async stake(e, a) {
|
|
914
|
+
var i, c, u;
|
|
915
|
+
if (!this.walletClient)
|
|
916
|
+
throw new Error("Wallet client not found");
|
|
917
|
+
const t = new d();
|
|
918
|
+
await this.walletClient.module("balance").waitForUpdate();
|
|
919
|
+
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = w(t, s.coins, {
|
|
920
|
+
balance: e,
|
|
921
|
+
useGasCoin: !0
|
|
922
|
+
}), r = await this.stakePTB(t, n);
|
|
923
|
+
t.transferObjects([r], this.walletClient.address);
|
|
924
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
925
|
+
transaction: t,
|
|
926
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
927
|
+
});
|
|
928
|
+
return !(a != null && a.dryRun) && ((u = (c = l.effects) == null ? void 0 : c.status) == null ? void 0 : u.status) === "success" && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
|
|
929
|
+
}
|
|
930
|
+
/**
|
|
931
|
+
* Unstake haSUI for SUI
|
|
932
|
+
*
|
|
933
|
+
* @param haSUIAmount - Amount of haSUI to unstake
|
|
934
|
+
* @param options Optional dry run
|
|
935
|
+
*/
|
|
936
|
+
async unstake(e, a) {
|
|
937
|
+
var i, c, u;
|
|
938
|
+
if (!this.walletClient)
|
|
939
|
+
throw new Error("Wallet client not found");
|
|
940
|
+
await this.walletClient.module("balance").waitForUpdate();
|
|
941
|
+
const t = new d(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = w(t, s.coins, {
|
|
942
|
+
balance: e
|
|
943
|
+
}), r = await this.unstakePTB(t, n);
|
|
944
|
+
t.transferObjects([r], this.walletClient.address);
|
|
945
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
946
|
+
transaction: t,
|
|
947
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
948
|
+
});
|
|
949
|
+
return !(a != null && a.dryRun) && ((u = (c = l.effects) == null ? void 0 : c.status) == null ? void 0 : u.status) === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
const ce = {
|
|
953
|
+
/** Balance management module */
|
|
954
|
+
balance: new ne(),
|
|
955
|
+
/** Lending protocol module */
|
|
956
|
+
lending: new se(),
|
|
957
|
+
/** Volo protocol module */
|
|
958
|
+
volo: new le(),
|
|
959
|
+
/** DEX swapping module */
|
|
960
|
+
swap: new ie(),
|
|
961
|
+
/** Haedal protocol module */
|
|
962
|
+
haedal: new re()
|
|
963
|
+
}, ue = {
|
|
964
|
+
url: F("mainnet")
|
|
965
|
+
};
|
|
966
|
+
class ye {
|
|
967
|
+
/**
|
|
968
|
+
* Creates a new wallet client instance
|
|
969
|
+
* @param options - Configuration options for the wallet client
|
|
970
|
+
*/
|
|
971
|
+
constructor(e) {
|
|
972
|
+
this.modules = ce, this.userConfigs = {}, this.events = _();
|
|
973
|
+
const a = {
|
|
974
|
+
...ue,
|
|
975
|
+
...e.client
|
|
976
|
+
};
|
|
977
|
+
a.transport = a.transport || new ae(a.url), this.client = new W(a), this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, s]) => {
|
|
978
|
+
if (t !== s.name)
|
|
979
|
+
throw new Error(`Module name ${t} does not match module name ${s.name}`);
|
|
980
|
+
s.install(this);
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
get lending() {
|
|
984
|
+
return this.modules.lending;
|
|
985
|
+
}
|
|
986
|
+
get balance() {
|
|
987
|
+
return this.modules.balance;
|
|
988
|
+
}
|
|
989
|
+
get volo() {
|
|
990
|
+
return this.modules.volo;
|
|
991
|
+
}
|
|
992
|
+
get swap() {
|
|
993
|
+
return this.modules.swap;
|
|
994
|
+
}
|
|
995
|
+
get haedal() {
|
|
996
|
+
return this.modules.haedal;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Signs and executes a transaction block
|
|
1000
|
+
* @param options - Transaction execution options including dry run support
|
|
1001
|
+
* @returns Promise with transaction execution result
|
|
1002
|
+
*/
|
|
1003
|
+
async signExecuteTransaction(e) {
|
|
1004
|
+
const { dryRun: a = !1, ...t } = e;
|
|
1005
|
+
if (a) {
|
|
1006
|
+
let s;
|
|
1007
|
+
return e.transaction instanceof d ? (e.transaction.setSenderIfNotSet(this.address), s = await e.transaction.build({
|
|
1008
|
+
client: this.client
|
|
1009
|
+
})) : s = e.transaction, this.client.dryRunTransactionBlock({
|
|
1010
|
+
transactionBlock: s
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
return this.client.signAndExecuteTransaction({
|
|
1014
|
+
...t,
|
|
1015
|
+
signer: this.signer
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Gets the wallet address from the signer's public key
|
|
1020
|
+
* @returns The wallet address as a string
|
|
1021
|
+
*/
|
|
1022
|
+
get address() {
|
|
1023
|
+
return this.signer.getPublicKey().toSuiAddress();
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Gets a specific module by name
|
|
1027
|
+
* @param name - The name of the module to retrieve
|
|
1028
|
+
* @returns The requested module instance
|
|
1029
|
+
*/
|
|
1030
|
+
module(e) {
|
|
1031
|
+
return this.modules[e];
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Gets the configuration for a specific module
|
|
1035
|
+
* @param name - The name of the module
|
|
1036
|
+
* @returns The merged configuration (default + user config)
|
|
1037
|
+
*/
|
|
1038
|
+
config(e) {
|
|
1039
|
+
return {
|
|
1040
|
+
...this.modules[e].defaultConfig,
|
|
1041
|
+
...this.userConfigs[e]
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Checks if a module is available
|
|
1046
|
+
* @param name - The name of the module to check
|
|
1047
|
+
* @returns True if the module exists, false otherwise
|
|
1048
|
+
*/
|
|
1049
|
+
hasModule(e) {
|
|
1050
|
+
return e in this.modules;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
class ve extends U {
|
|
1054
|
+
/**
|
|
1055
|
+
* Creates a new watch-only signer
|
|
1056
|
+
*
|
|
1057
|
+
* @param address - The wallet address to watch
|
|
1058
|
+
*/
|
|
1059
|
+
constructor(e) {
|
|
1060
|
+
super(), this.address = e;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Signs transaction bytes (not implemented for watch-only mode)
|
|
1064
|
+
*
|
|
1065
|
+
* This method is required by the Signer interface but cannot
|
|
1066
|
+
* actually sign transactions in watch-only mode.
|
|
1067
|
+
*
|
|
1068
|
+
* @param bytes - Transaction bytes to sign
|
|
1069
|
+
* @returns Promise<Uint8Array> - Empty signature (not valid)
|
|
1070
|
+
*/
|
|
1071
|
+
async sign(e) {
|
|
1072
|
+
return new Uint8Array([]);
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Gets the public key information for this signer
|
|
1076
|
+
*
|
|
1077
|
+
* Returns a mock public key object that provides the wallet address
|
|
1078
|
+
* but cannot be used for actual cryptographic operations.
|
|
1079
|
+
*
|
|
1080
|
+
* @returns Mock public key object
|
|
1081
|
+
*/
|
|
1082
|
+
getPublicKey() {
|
|
1083
|
+
return {
|
|
1084
|
+
/** Returns the wallet address */
|
|
1085
|
+
toSuiAddress: () => this.address,
|
|
1086
|
+
/** Returns empty bytes (not a real public key) */
|
|
1087
|
+
toBytes: () => new Uint8Array(32),
|
|
1088
|
+
/** Returns empty raw bytes (not a real public key) */
|
|
1089
|
+
toRawBytes: () => new Uint8Array(32),
|
|
1090
|
+
/** Public key flag (0 for mock) */
|
|
1091
|
+
flag: 0,
|
|
1092
|
+
/** Verification always returns false (not a real public key) */
|
|
1093
|
+
verify: async () => !1
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Gets the key scheme for this signer
|
|
1098
|
+
*
|
|
1099
|
+
* @returns Key scheme string (ed25519 for compatibility)
|
|
1100
|
+
*/
|
|
1101
|
+
getKeyScheme() {
|
|
1102
|
+
return "ed25519";
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Signs and executes a transaction (not implemented for watch-only mode)
|
|
1106
|
+
*
|
|
1107
|
+
* This method is required by the Signer interface but cannot
|
|
1108
|
+
* actually sign and execute transactions in watch-only mode.
|
|
1109
|
+
*
|
|
1110
|
+
* @param options - Sign and execute options
|
|
1111
|
+
* @returns Promise<any> - Empty result (not a real transaction result)
|
|
1112
|
+
*/
|
|
1113
|
+
async signAndExecuteTransaction({ transaction: e, client: a }) {
|
|
1114
|
+
return {};
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
class Pe extends U {
|
|
1118
|
+
/**
|
|
1119
|
+
* Creates a new watch-only signer
|
|
1120
|
+
*
|
|
1121
|
+
* @param address - The wallet address to watch
|
|
1122
|
+
*/
|
|
1123
|
+
constructor(e) {
|
|
1124
|
+
super(), this.address = e;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Signs transaction bytes (not implemented for watch-only mode)
|
|
1128
|
+
*
|
|
1129
|
+
* This method is required by the Signer interface but cannot
|
|
1130
|
+
* actually sign transactions in watch-only mode.
|
|
1131
|
+
*
|
|
1132
|
+
* @param bytes - Transaction bytes to sign
|
|
1133
|
+
* @returns Promise<Uint8Array> - Empty signature (not valid)
|
|
1134
|
+
*/
|
|
1135
|
+
async sign(e) {
|
|
1136
|
+
return new Uint8Array([]);
|
|
1137
|
+
}
|
|
1138
|
+
/**
|
|
1139
|
+
* Gets the public key information for this signer
|
|
1140
|
+
*
|
|
1141
|
+
* Returns a mock public key object that provides the wallet address
|
|
1142
|
+
* but cannot be used for actual cryptographic operations.
|
|
1143
|
+
*
|
|
1144
|
+
* @returns Mock public key object
|
|
1145
|
+
*/
|
|
1146
|
+
getPublicKey() {
|
|
1147
|
+
return {
|
|
1148
|
+
/** Returns the wallet address */
|
|
1149
|
+
toSuiAddress: () => this.address,
|
|
1150
|
+
/** Returns empty bytes (not a real public key) */
|
|
1151
|
+
toBytes: () => new Uint8Array(32),
|
|
1152
|
+
/** Returns empty raw bytes (not a real public key) */
|
|
1153
|
+
toRawBytes: () => new Uint8Array(32),
|
|
1154
|
+
/** Public key flag (0 for mock) */
|
|
1155
|
+
flag: 0,
|
|
1156
|
+
/** Verification always returns false (not a real public key) */
|
|
1157
|
+
verify: async () => !1
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Gets the key scheme for this signer
|
|
1162
|
+
*
|
|
1163
|
+
* @returns Key scheme string (ed25519 for compatibility)
|
|
1164
|
+
*/
|
|
1165
|
+
getKeyScheme() {
|
|
1166
|
+
return "ed25519";
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
export {
|
|
1170
|
+
ye as WalletClient,
|
|
1171
|
+
ve as WatchSigner,
|
|
1172
|
+
Pe as WebSigner
|
|
1173
|
+
};
|
|
1174
|
+
//# sourceMappingURL=index.esm.js.map
|