@naviprotocol/wallet-client 1.0.1-dev.2 → 1.0.2-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +278 -255
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/lendingModule/index.d.ts +2 -2
- package/dist/modules/lendingModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/migrate.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { getFullnodeUrl as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as
|
|
5
|
-
import
|
|
1
|
+
import { getFullnodeUrl as le, SuiClient as ie } from "@mysten/sui/client";
|
|
2
|
+
import re from "mitt";
|
|
3
|
+
import ce from "axios";
|
|
4
|
+
import { withSingleton as M, getCoins as oe, mergeCoinsPTB as y, getPriceFeeds as Q, updateOraclePricesPTB as q, filterPriceFeeds as K, getFlashLoanAsset as V, flashloanPTB as X, depositCoinPTB as x, withdrawCoinPTB as Y, repayFlashLoanPTB as Z, repayCoinPTB as ee, borrowCoinPTB as te, getPools as ue, getPool as P, getHealthFactor as de, liquidatePTB as we, getUserAvailableLendingRewards as H, getUserClaimedRewardHistory as he, claimLendingRewardsPTB as fe, getLendingState as ge, createAccountCapPTB as me, withCache as ae, parseTxValue as k } from "@naviprotocol/lending";
|
|
5
|
+
import p, { BigNumber as L } from "bignumber.js";
|
|
6
6
|
import { normalizeStructTag as T } from "@mysten/sui/utils";
|
|
7
|
-
import { Transaction as
|
|
8
|
-
import { buildSwapPTBFromQuote as
|
|
9
|
-
import { Signer as
|
|
10
|
-
const
|
|
7
|
+
import { Transaction as w } from "@mysten/sui/transactions";
|
|
8
|
+
import { buildSwapPTBFromQuote as $, generateRefId as Ce, getQuote as be } from "@naviprotocol/astros-aggregator-sdk";
|
|
9
|
+
import { Signer as ne } from "@mysten/sui/cryptography";
|
|
10
|
+
const se = ce.create({
|
|
11
11
|
timeout: 2e4
|
|
12
12
|
});
|
|
13
|
-
|
|
13
|
+
se.interceptors.response.use(
|
|
14
14
|
function(r) {
|
|
15
15
|
if (r.data.err)
|
|
16
16
|
throw new Error(r.data.err);
|
|
@@ -22,7 +22,7 @@ Z.interceptors.response.use(
|
|
|
22
22
|
return Promise.reject(r);
|
|
23
23
|
}
|
|
24
24
|
);
|
|
25
|
-
class
|
|
25
|
+
class ye {
|
|
26
26
|
/**
|
|
27
27
|
* Creates a new custom transport instance
|
|
28
28
|
*
|
|
@@ -41,7 +41,7 @@ class Ce {
|
|
|
41
41
|
* @returns Promise<T> - The response data from the RPC call
|
|
42
42
|
*/
|
|
43
43
|
async request(e) {
|
|
44
|
-
return this.requestId += 1, (await
|
|
44
|
+
return this.requestId += 1, (await se.post(this.rpcUrl, {
|
|
45
45
|
jsonrpc: "2.0",
|
|
46
46
|
id: this.requestId,
|
|
47
47
|
method: e.method,
|
|
@@ -61,7 +61,7 @@ class Ce {
|
|
|
61
61
|
throw new Error("subscribe not implemented.");
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
class
|
|
64
|
+
class R {
|
|
65
65
|
/**
|
|
66
66
|
* Gets the current configuration for this module
|
|
67
67
|
*
|
|
@@ -104,14 +104,14 @@ class E {
|
|
|
104
104
|
this.walletClient = void 0;
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
class
|
|
107
|
+
class E {
|
|
108
108
|
/**
|
|
109
109
|
* Creates a new user portfolio
|
|
110
110
|
*
|
|
111
111
|
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
112
112
|
*/
|
|
113
113
|
constructor(e) {
|
|
114
|
-
if (e instanceof
|
|
114
|
+
if (e instanceof E)
|
|
115
115
|
this.balances = JSON.parse(JSON.stringify(e.balances));
|
|
116
116
|
else {
|
|
117
117
|
const a = {};
|
|
@@ -120,7 +120,7 @@ class p {
|
|
|
120
120
|
let n = a[s];
|
|
121
121
|
n || (n = {
|
|
122
122
|
coinType: s,
|
|
123
|
-
amount:
|
|
123
|
+
amount: L(0),
|
|
124
124
|
coins: []
|
|
125
125
|
}, a[s] = n), n.coins.push(t), n.amount = n.amount.plus(t.balance);
|
|
126
126
|
}), this.balances = a;
|
|
@@ -133,7 +133,7 @@ class p {
|
|
|
133
133
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
134
134
|
*/
|
|
135
135
|
getBalance(e) {
|
|
136
|
-
return e = T(e), this.balances[e] || { coinType: e, amount:
|
|
136
|
+
return e = T(e), this.balances[e] || { coinType: e, amount: L(0), coins: [] };
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* Gets all coin types in the portfolio
|
|
@@ -152,7 +152,7 @@ class p {
|
|
|
152
152
|
balanceOf(e) {
|
|
153
153
|
e = T(e);
|
|
154
154
|
const a = this.getBalance(e);
|
|
155
|
-
return (a == null ? void 0 : a.amount) ||
|
|
155
|
+
return (a == null ? void 0 : a.amount) || L(0);
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Creates a deep copy of the portfolio
|
|
@@ -163,21 +163,21 @@ class p {
|
|
|
163
163
|
* @returns New UserPortfolio instance with copied data
|
|
164
164
|
*/
|
|
165
165
|
clone() {
|
|
166
|
-
const e = JSON.parse(JSON.stringify(this.balances)), a = new
|
|
166
|
+
const e = JSON.parse(JSON.stringify(this.balances)), a = new E();
|
|
167
167
|
return a.balances = e, a;
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
-
class
|
|
170
|
+
class Be extends R {
|
|
171
171
|
constructor() {
|
|
172
172
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
173
173
|
coinPollingInterval: 6e3
|
|
174
|
-
}, this.updatePortfolio =
|
|
174
|
+
}, this.updatePortfolio = M(async () => {
|
|
175
175
|
if (!this.walletClient)
|
|
176
176
|
throw new Error("Wallet client not found");
|
|
177
|
-
this._coins = await
|
|
177
|
+
this._coins = await oe(this.walletClient.address, {
|
|
178
178
|
client: this.walletClient.client
|
|
179
|
-
}), this._portfolio = new
|
|
180
|
-
}), this._coins = [], this._portfolio = new
|
|
179
|
+
}), this._portfolio = new E(this._coins), this.emit("balance:portfolio-updated", {});
|
|
180
|
+
}), this._coins = [], this._portfolio = new E(), this.pollingTimer = null, this._updatePromise = null;
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
183
|
* Gets the current coin objects from the wallet
|
|
@@ -234,19 +234,19 @@ class be extends E {
|
|
|
234
234
|
if (a.length !== t.length)
|
|
235
235
|
throw new Error("Recipients and amounts must have the same length");
|
|
236
236
|
await this.waitForUpdate();
|
|
237
|
-
const n = this.portfolio.getBalance(e),
|
|
238
|
-
if (n.amount.lt(
|
|
237
|
+
const n = this.portfolio.getBalance(e), c = t.reduce((h, f) => h.plus(f), p(0));
|
|
238
|
+
if (n.amount.lt(c))
|
|
239
239
|
throw new Error("Insufficient balance");
|
|
240
|
-
const
|
|
241
|
-
let
|
|
242
|
-
T(e) !== T("0x2::sui::SUI") && (
|
|
243
|
-
balance:
|
|
240
|
+
const l = new w();
|
|
241
|
+
let i = l.gas;
|
|
242
|
+
T(e) !== T("0x2::sui::SUI") && (i = y(l, n.coins, {
|
|
243
|
+
balance: c.toNumber()
|
|
244
244
|
}));
|
|
245
|
-
const
|
|
246
|
-
return a.forEach((
|
|
247
|
-
|
|
245
|
+
const o = l.splitCoins(i, t);
|
|
246
|
+
return a.forEach((h, f) => {
|
|
247
|
+
l.transferObjects([o[f]], h);
|
|
248
248
|
}), await this.walletClient.signExecuteTransaction({
|
|
249
|
-
transaction:
|
|
249
|
+
transaction: l,
|
|
250
250
|
dryRun: (d = s == null ? void 0 : s.dryRun) != null ? d : !1
|
|
251
251
|
});
|
|
252
252
|
}
|
|
@@ -273,18 +273,18 @@ class be extends E {
|
|
|
273
273
|
* @returns Transaction response or dry run response
|
|
274
274
|
*/
|
|
275
275
|
async transferObjectBatch(e, a, t) {
|
|
276
|
-
var
|
|
276
|
+
var c;
|
|
277
277
|
if (!this.walletClient)
|
|
278
278
|
throw new Error("Wallet client not found");
|
|
279
279
|
if (e.length !== a.length)
|
|
280
280
|
throw new Error("Objects and recipients must have the same length");
|
|
281
281
|
await this.waitForUpdate();
|
|
282
|
-
const s = new
|
|
283
|
-
return e.forEach((
|
|
284
|
-
s.transferObjects([s.object(
|
|
282
|
+
const s = new w();
|
|
283
|
+
return e.forEach((l, i) => {
|
|
284
|
+
s.transferObjects([s.object(l)], a[i]);
|
|
285
285
|
}), await this.walletClient.signExecuteTransaction({
|
|
286
286
|
transaction: s,
|
|
287
|
-
dryRun: (
|
|
287
|
+
dryRun: (c = t == null ? void 0 : t.dryRun) != null ? c : !1
|
|
288
288
|
});
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
@@ -323,127 +323,150 @@ class be extends E {
|
|
|
323
323
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
|
-
const
|
|
327
|
-
function
|
|
328
|
-
return r ? new
|
|
326
|
+
const Pe = 27;
|
|
327
|
+
function Te(r, e = 2) {
|
|
328
|
+
return r ? new p(r.toString()).shiftedBy(-1 * Pe).multipliedBy(100).decimalPlaces(e, p.ROUND_DOWN).toFixed(e) : "0.00";
|
|
329
329
|
}
|
|
330
|
-
async function
|
|
331
|
-
var
|
|
330
|
+
async function D(r, e, a, t) {
|
|
331
|
+
var S, O;
|
|
332
332
|
if (!this.walletClient)
|
|
333
333
|
throw new Error("Wallet client not found");
|
|
334
334
|
await this.walletClient.balance.waitForUpdate();
|
|
335
|
-
const s = await this.getPool(e), n = await this.getPool(a),
|
|
336
|
-
if (
|
|
335
|
+
const s = await this.getPool(e), n = await this.getPool(a), c = await this.getLendingState(), l = c.find((F) => F.pool.id === s.id), i = this.walletClient.address;
|
|
336
|
+
if (console.log("fromPoolLending", {
|
|
337
|
+
fromPoolLending: l,
|
|
338
|
+
lendingState: c,
|
|
339
|
+
address: i,
|
|
340
|
+
options: t,
|
|
341
|
+
from: e,
|
|
342
|
+
to: a
|
|
343
|
+
}), !l || l.supplyBalance === "0")
|
|
337
344
|
throw new Error("No supply balance");
|
|
338
|
-
if (t != null && t.amount && t.amount
|
|
345
|
+
if (t != null && t.amount && t.amount > Number(l.supplyBalance))
|
|
339
346
|
throw new Error("Amount is less than supply balance");
|
|
340
|
-
const
|
|
347
|
+
const o = await Q(), u = await Promise.all([s, n]);
|
|
348
|
+
await q(
|
|
349
|
+
r,
|
|
350
|
+
K(o, {
|
|
351
|
+
lendingState: c,
|
|
352
|
+
pools: u
|
|
353
|
+
})
|
|
354
|
+
);
|
|
355
|
+
const d = await V(n, {
|
|
341
356
|
env: this.config.env
|
|
342
357
|
});
|
|
343
|
-
if (!(
|
|
358
|
+
if (!(d != null && d.flashloanFee))
|
|
344
359
|
throw new Error(`${s.token.symbol} pool not support flashloan`);
|
|
345
|
-
const
|
|
360
|
+
const h = (S = t == null ? void 0 : t.slippage) != null ? S : 5e-3, f = (O = t == null ? void 0 : t.amount) != null ? O : Number(l.supplyBalance), b = await this.walletClient.swap.getQuote(
|
|
346
361
|
s.suiCoinType,
|
|
347
362
|
n.suiCoinType,
|
|
348
|
-
|
|
349
|
-
),
|
|
350
|
-
if (
|
|
363
|
+
f
|
|
364
|
+
), m = Number(b.amount_out);
|
|
365
|
+
if (m <= 0)
|
|
351
366
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
352
|
-
const
|
|
367
|
+
const C = Math.floor(m * (1 - h)), g = Math.floor(C / (1 + d.flashloanFee));
|
|
353
368
|
if (g <= 0)
|
|
354
369
|
throw new Error("The calculated borrow amount must be positive.");
|
|
355
|
-
const [
|
|
370
|
+
const [B, v] = await X(r, n, g), [A] = r.moveCall({
|
|
356
371
|
target: "0x2::coin::from_balance",
|
|
357
|
-
arguments: [
|
|
372
|
+
arguments: [B],
|
|
358
373
|
typeArguments: [n.suiCoinType]
|
|
359
374
|
});
|
|
360
|
-
await x(r, n,
|
|
375
|
+
await x(r, n, A, {
|
|
361
376
|
amount: g
|
|
362
377
|
});
|
|
363
|
-
const
|
|
364
|
-
|
|
378
|
+
const j = await Y(r, s, f), U = await $(
|
|
379
|
+
i,
|
|
365
380
|
r,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
),
|
|
381
|
+
C,
|
|
382
|
+
j,
|
|
383
|
+
b
|
|
384
|
+
), _ = r.moveCall({
|
|
370
385
|
target: "0x2::coin::into_balance",
|
|
371
|
-
arguments: [
|
|
386
|
+
arguments: [U],
|
|
372
387
|
typeArguments: [n.suiCoinType]
|
|
373
|
-
}), [
|
|
388
|
+
}), [W] = await Z(r, n, v, _), [N] = r.moveCall({
|
|
374
389
|
target: "0x2::coin::from_balance",
|
|
375
|
-
arguments: [
|
|
390
|
+
arguments: [W],
|
|
376
391
|
typeArguments: [n.suiCoinType]
|
|
377
392
|
});
|
|
378
|
-
return await x(r, n,
|
|
393
|
+
return await x(r, n, N), r;
|
|
379
394
|
}
|
|
380
|
-
async function
|
|
381
|
-
var
|
|
395
|
+
async function J(r, e, a, t) {
|
|
396
|
+
var F, G;
|
|
382
397
|
if (!this.walletClient)
|
|
383
398
|
throw new Error("Wallet client not found");
|
|
384
399
|
await this.walletClient.balance.waitForUpdate();
|
|
385
|
-
const s = this.walletClient.address, n = await this.getPool(e),
|
|
386
|
-
if (!
|
|
400
|
+
const s = this.walletClient.address, n = await this.getPool(e), c = await this.getPool(a), l = await this.getLendingState(), i = l.find((I) => I.pool.id === n.id);
|
|
401
|
+
if (!i || i.borrowBalance === "0")
|
|
387
402
|
throw new Error("No borrow balance");
|
|
388
|
-
if (t != null && t.amount && t.amount
|
|
403
|
+
if (t != null && t.amount && t.amount > Number(i.borrowBalance))
|
|
389
404
|
throw new Error("Amount is less than borrow balance");
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
405
|
+
const o = await Q(), u = await Promise.all([n, c]);
|
|
406
|
+
await q(
|
|
407
|
+
r,
|
|
408
|
+
K(o, {
|
|
409
|
+
lendingState: l,
|
|
410
|
+
pools: u
|
|
411
|
+
})
|
|
412
|
+
);
|
|
413
|
+
let d = (F = t == null ? void 0 : t.amount) != null ? F : Number(i.borrowBalance);
|
|
414
|
+
if (Number(i.borrowBalance) === d) {
|
|
415
|
+
const I = parseFloat(Te(n.currentBorrowRate, 8)) / 100;
|
|
416
|
+
d = Math.ceil(
|
|
417
|
+
new p(d).multipliedBy(I * (60 * 3) / (365 * 24 * 3600)).plus(new p(1).shiftedBy(-n.token.decimals)).plus(d).toNumber()
|
|
395
418
|
);
|
|
396
419
|
}
|
|
397
|
-
const
|
|
420
|
+
const h = await V(n, {
|
|
398
421
|
env: this.config.env
|
|
399
422
|
});
|
|
400
|
-
if (!
|
|
423
|
+
if (!h)
|
|
401
424
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
402
425
|
if (!this.walletClient)
|
|
403
426
|
throw new Error("Wallet client not found");
|
|
404
|
-
const
|
|
427
|
+
const f = (G = t == null ? void 0 : t.slippage) != null ? G : 5e-3, b = Math.ceil(d * (1 + h.flashloanFee)), m = b, C = await this.walletClient.swap.getQuote(
|
|
405
428
|
n.suiCoinType,
|
|
406
|
-
|
|
407
|
-
|
|
429
|
+
c.suiCoinType,
|
|
430
|
+
m
|
|
408
431
|
);
|
|
409
|
-
let g = 1 +
|
|
410
|
-
|
|
432
|
+
let g = 1 + f, B = Math.ceil(Number(C.amount_out) * g), v = await this.walletClient.swap.getQuote(
|
|
433
|
+
c.suiCoinType,
|
|
411
434
|
n.suiCoinType,
|
|
412
|
-
|
|
435
|
+
B
|
|
413
436
|
);
|
|
414
|
-
for (; Number(
|
|
415
|
-
g = g * Math.max(
|
|
416
|
-
|
|
437
|
+
for (; Number(v.amount_out) < m; )
|
|
438
|
+
g = g * Math.max(m / Number(v.amount_out), 1.001), B = Math.ceil(Number(C.amount_out) * g), v = await this.walletClient.swap.getQuote(
|
|
439
|
+
c.suiCoinType,
|
|
417
440
|
n.suiCoinType,
|
|
418
|
-
|
|
441
|
+
B
|
|
419
442
|
);
|
|
420
|
-
const [
|
|
443
|
+
const [A, j] = await X(r, n, d), [U] = r.moveCall({
|
|
421
444
|
target: "0x2::coin::from_balance",
|
|
422
|
-
arguments: [
|
|
445
|
+
arguments: [A],
|
|
423
446
|
typeArguments: [n.suiCoinType]
|
|
424
447
|
});
|
|
425
|
-
await
|
|
426
|
-
amount:
|
|
448
|
+
await ee(r, n, U, {
|
|
449
|
+
amount: d
|
|
427
450
|
});
|
|
428
|
-
const
|
|
451
|
+
const _ = await te(r, c, B), W = await $(
|
|
429
452
|
s,
|
|
430
453
|
r,
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
),
|
|
454
|
+
b,
|
|
455
|
+
_,
|
|
456
|
+
v
|
|
457
|
+
), N = r.moveCall({
|
|
435
458
|
target: "0x2::coin::into_balance",
|
|
436
|
-
arguments: [
|
|
459
|
+
arguments: [W],
|
|
437
460
|
typeArguments: [n.suiCoinType]
|
|
438
|
-
}), [
|
|
461
|
+
}), [S] = await Z(r, n, j, N), [O] = r.moveCall({
|
|
439
462
|
target: "0x2::coin::from_balance",
|
|
440
|
-
arguments: [
|
|
463
|
+
arguments: [S],
|
|
441
464
|
typeArguments: [n.suiCoinType]
|
|
442
465
|
});
|
|
443
|
-
return r.transferObjects([
|
|
466
|
+
return r.transferObjects([O], s), r;
|
|
444
467
|
}
|
|
445
|
-
async function
|
|
446
|
-
var
|
|
468
|
+
async function z(r, e, a, t) {
|
|
469
|
+
var o, u;
|
|
447
470
|
if (!this.walletClient)
|
|
448
471
|
throw new Error("Wallet client not found");
|
|
449
472
|
await this.walletClient.balance.waitForUpdate(), this.walletClient.address;
|
|
@@ -452,27 +475,27 @@ async function $(r, e, a, t) {
|
|
|
452
475
|
throw new Error(`No balance of ${e}`);
|
|
453
476
|
if (t != null && t.amount && n.amount.lt(t.amount))
|
|
454
477
|
throw new Error("Amount is less than balance");
|
|
455
|
-
const
|
|
456
|
-
let
|
|
457
|
-
balance:
|
|
478
|
+
const c = (o = t == null ? void 0 : t.amount) != null ? o : n.amount.toNumber(), l = (u = t == null ? void 0 : t.slippage) != null ? u : 5e-3;
|
|
479
|
+
let i = await y(r, n.coins, {
|
|
480
|
+
balance: c,
|
|
458
481
|
useGasCoin: !0
|
|
459
482
|
});
|
|
460
483
|
if (T(e) !== T(s.suiCoinType)) {
|
|
461
|
-
const d = await this.walletClient.swap.getQuote(e, s.suiCoinType,
|
|
462
|
-
|
|
484
|
+
const d = await this.walletClient.swap.getQuote(e, s.suiCoinType, c);
|
|
485
|
+
i = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
463
486
|
r,
|
|
464
487
|
d,
|
|
465
|
-
|
|
466
|
-
|
|
488
|
+
i,
|
|
489
|
+
l
|
|
467
490
|
);
|
|
468
491
|
}
|
|
469
|
-
return await x(r, s,
|
|
492
|
+
return await x(r, s, i), r;
|
|
470
493
|
}
|
|
471
|
-
class
|
|
494
|
+
class ve extends R {
|
|
472
495
|
constructor() {
|
|
473
496
|
super(), this.name = "lending", this.defaultConfig = {
|
|
474
497
|
env: "prod"
|
|
475
|
-
}, this.
|
|
498
|
+
}, this.migrateBetweenSupplyPTB = D, this.migrateBetweenBorrowPTB = J, this.migrateBalanceToSupplyPTB = z, this.migrateBetweenSupplyPTB = D.bind(this), this.migrateBetweenSupplyPTB = J.bind(this), this.migrateBalanceToSupplyPTB = z.bind(this);
|
|
476
499
|
}
|
|
477
500
|
/**
|
|
478
501
|
* Gets all available lending pools
|
|
@@ -481,7 +504,7 @@ class Te extends E {
|
|
|
481
504
|
* @returns Array of pool information
|
|
482
505
|
*/
|
|
483
506
|
async getPools(e) {
|
|
484
|
-
return await
|
|
507
|
+
return await ue({
|
|
485
508
|
env: this.config.env,
|
|
486
509
|
...e
|
|
487
510
|
});
|
|
@@ -494,7 +517,7 @@ class Te extends E {
|
|
|
494
517
|
* @returns Pool information
|
|
495
518
|
*/
|
|
496
519
|
async getPool(e, a) {
|
|
497
|
-
return await
|
|
520
|
+
return await P(e, {
|
|
498
521
|
env: this.config.env,
|
|
499
522
|
...a
|
|
500
523
|
});
|
|
@@ -508,30 +531,30 @@ class Te extends E {
|
|
|
508
531
|
* @returns Transaction response or dry run response
|
|
509
532
|
*/
|
|
510
533
|
async deposit(e, a, t) {
|
|
511
|
-
var
|
|
534
|
+
var o, u, d;
|
|
512
535
|
if (!this.walletClient)
|
|
513
536
|
throw new Error("Wallet client not found");
|
|
514
|
-
const s = await
|
|
537
|
+
const s = await P(e, {
|
|
515
538
|
env: this.config.env
|
|
516
539
|
});
|
|
517
540
|
await this.walletClient.module("balance").waitForUpdate();
|
|
518
|
-
const n = new
|
|
541
|
+
const n = new w(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), l = y(n, c.coins, {
|
|
519
542
|
balance: a,
|
|
520
543
|
useGasCoin: !0
|
|
521
544
|
});
|
|
522
|
-
await x(n, s,
|
|
545
|
+
await x(n, s, l, {
|
|
523
546
|
env: this.config.env,
|
|
524
547
|
amount: a,
|
|
525
548
|
accountCap: t == null ? void 0 : t.accountCap
|
|
526
549
|
});
|
|
527
|
-
const
|
|
550
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
528
551
|
transaction: n,
|
|
529
|
-
dryRun: (
|
|
552
|
+
dryRun: (o = t == null ? void 0 : t.dryRun) != null ? o : !1
|
|
530
553
|
});
|
|
531
|
-
return !(t != null && t.dryRun) && ((d = (u =
|
|
554
|
+
return !(t != null && t.dryRun) && ((d = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : d.status) === "success" && (this.emit("lending:deposit-success", {
|
|
532
555
|
identifier: e,
|
|
533
556
|
amount: a
|
|
534
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
557
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
535
558
|
}
|
|
536
559
|
/**
|
|
537
560
|
* Withdraws coins from a lending pool
|
|
@@ -542,26 +565,26 @@ class Te extends E {
|
|
|
542
565
|
* @returns Transaction response or dry run response
|
|
543
566
|
*/
|
|
544
567
|
async withdraw(e, a, t) {
|
|
545
|
-
var
|
|
568
|
+
var i, o, u;
|
|
546
569
|
if (!this.walletClient)
|
|
547
570
|
throw new Error("Wallet client not found");
|
|
548
|
-
const s = await
|
|
571
|
+
const s = await P(e, {
|
|
549
572
|
env: this.config.env
|
|
550
|
-
}), n = new
|
|
573
|
+
}), n = new w();
|
|
551
574
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
552
|
-
const
|
|
575
|
+
const c = await Y(n, s, a, {
|
|
553
576
|
env: this.config.env,
|
|
554
577
|
accountCap: t == null ? void 0 : t.accountCap
|
|
555
578
|
});
|
|
556
|
-
n.transferObjects([
|
|
557
|
-
const
|
|
579
|
+
n.transferObjects([c], this.walletClient.address);
|
|
580
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
558
581
|
transaction: n,
|
|
559
|
-
dryRun: (
|
|
582
|
+
dryRun: (i = t == null ? void 0 : t.dryRun) != null ? i : !1
|
|
560
583
|
});
|
|
561
|
-
return !(t != null && t.dryRun) && ((u = (
|
|
584
|
+
return !(t != null && t.dryRun) && ((u = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : u.status) === "success" && (this.emit("lending:withdraw-success", {
|
|
562
585
|
identifier: e,
|
|
563
586
|
amount: a
|
|
564
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
587
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
565
588
|
}
|
|
566
589
|
/**
|
|
567
590
|
* Borrows coins from a lending pool
|
|
@@ -572,26 +595,26 @@ class Te extends E {
|
|
|
572
595
|
* @returns Transaction response or dry run response
|
|
573
596
|
*/
|
|
574
597
|
async borrow(e, a, t) {
|
|
575
|
-
var
|
|
598
|
+
var i, o, u;
|
|
576
599
|
if (!this.walletClient)
|
|
577
600
|
throw new Error("Wallet client not found");
|
|
578
|
-
const s = await
|
|
601
|
+
const s = await P(e, {
|
|
579
602
|
env: this.config.env
|
|
580
|
-
}), n = new
|
|
603
|
+
}), n = new w();
|
|
581
604
|
t != null && t.disableUpdateOracle || await this.updateOraclePTB(n, [s]);
|
|
582
|
-
const
|
|
605
|
+
const c = await te(n, s, a, {
|
|
583
606
|
env: this.config.env,
|
|
584
607
|
accountCap: t == null ? void 0 : t.accountCap
|
|
585
608
|
});
|
|
586
|
-
n.transferObjects([
|
|
587
|
-
const
|
|
609
|
+
n.transferObjects([c], this.walletClient.address);
|
|
610
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
588
611
|
transaction: n,
|
|
589
|
-
dryRun: (
|
|
612
|
+
dryRun: (i = t == null ? void 0 : t.dryRun) != null ? i : !1
|
|
590
613
|
});
|
|
591
|
-
return !(t != null && t.dryRun) && ((u = (
|
|
614
|
+
return !(t != null && t.dryRun) && ((u = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : u.status) === "success" && (this.emit("lending:borrow-success", {
|
|
592
615
|
identifier: e,
|
|
593
616
|
amount: a
|
|
594
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
617
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
595
618
|
}
|
|
596
619
|
/**
|
|
597
620
|
* Repays borrowed coins to a lending pool
|
|
@@ -602,29 +625,29 @@ class Te extends E {
|
|
|
602
625
|
* @returns Transaction response or dry run response
|
|
603
626
|
*/
|
|
604
627
|
async repay(e, a, t) {
|
|
605
|
-
var
|
|
628
|
+
var o, u, d;
|
|
606
629
|
if (!this.walletClient)
|
|
607
630
|
throw new Error("Wallet client not found");
|
|
608
631
|
await this.walletClient.module("balance").waitForUpdate();
|
|
609
|
-
const s = await
|
|
632
|
+
const s = await P(e, {
|
|
610
633
|
env: this.config.env
|
|
611
|
-
}), n = new
|
|
634
|
+
}), n = new w(), c = this.walletClient.module("balance").portfolio.getBalance(s.suiCoinType), l = y(n, c.coins, {
|
|
612
635
|
balance: a,
|
|
613
636
|
useGasCoin: !0
|
|
614
637
|
});
|
|
615
|
-
await
|
|
638
|
+
await ee(n, s, l, {
|
|
616
639
|
env: this.config.env,
|
|
617
640
|
amount: a,
|
|
618
641
|
accountCap: t == null ? void 0 : t.accountCap
|
|
619
642
|
});
|
|
620
|
-
const
|
|
643
|
+
const i = await this.walletClient.signExecuteTransaction({
|
|
621
644
|
transaction: n,
|
|
622
|
-
dryRun: (
|
|
645
|
+
dryRun: (o = t == null ? void 0 : t.dryRun) != null ? o : !1
|
|
623
646
|
});
|
|
624
|
-
return !(t != null && t.dryRun) && ((d = (u =
|
|
647
|
+
return !(t != null && t.dryRun) && ((d = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : d.status) === "success" && (this.emit("lending:repay-success", {
|
|
625
648
|
identifier: e,
|
|
626
649
|
amount: a
|
|
627
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
650
|
+
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
628
651
|
}
|
|
629
652
|
/**
|
|
630
653
|
* Gets the current health factor for the user
|
|
@@ -635,7 +658,7 @@ class Te extends E {
|
|
|
635
658
|
if (!this.walletClient)
|
|
636
659
|
throw new Error("Wallet client not found");
|
|
637
660
|
const e = this.walletClient.address;
|
|
638
|
-
return await
|
|
661
|
+
return await de(e, {
|
|
639
662
|
env: this.config.env,
|
|
640
663
|
client: this.walletClient.client
|
|
641
664
|
});
|
|
@@ -651,45 +674,45 @@ class Te extends E {
|
|
|
651
674
|
* @returns Transaction response or dry run response
|
|
652
675
|
*/
|
|
653
676
|
async liquidate(e, a, t, s, n) {
|
|
654
|
-
var
|
|
677
|
+
var C, g, B;
|
|
655
678
|
if (!this.walletClient)
|
|
656
679
|
throw new Error("Wallet client not found");
|
|
657
|
-
const
|
|
680
|
+
const c = await P(e, {
|
|
658
681
|
env: this.config.env
|
|
659
|
-
}),
|
|
682
|
+
}), l = await P(t, {
|
|
660
683
|
env: this.config.env
|
|
661
|
-
}),
|
|
684
|
+
}), i = new w(), o = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), u = y(i, o.coins, {
|
|
662
685
|
balance: a,
|
|
663
686
|
useGasCoin: !0
|
|
664
|
-
}), [d,
|
|
665
|
-
l,
|
|
666
|
-
o,
|
|
667
|
-
u,
|
|
687
|
+
}), [d, h] = await we(
|
|
668
688
|
i,
|
|
689
|
+
c,
|
|
690
|
+
u,
|
|
691
|
+
l,
|
|
669
692
|
s,
|
|
670
693
|
{
|
|
671
694
|
env: this.config.env
|
|
672
695
|
}
|
|
673
|
-
), [
|
|
696
|
+
), [f] = i.moveCall({
|
|
674
697
|
target: "0x2::coin::from_balance",
|
|
675
698
|
arguments: [d],
|
|
676
|
-
typeArguments: [
|
|
677
|
-
}), [b] =
|
|
699
|
+
typeArguments: [l.suiCoinType]
|
|
700
|
+
}), [b] = i.moveCall({
|
|
678
701
|
target: "0x2::coin::from_balance",
|
|
679
|
-
arguments: [
|
|
680
|
-
typeArguments: [
|
|
702
|
+
arguments: [h],
|
|
703
|
+
typeArguments: [c.suiCoinType]
|
|
681
704
|
});
|
|
682
|
-
|
|
683
|
-
const
|
|
684
|
-
transaction:
|
|
685
|
-
dryRun: (
|
|
705
|
+
i.transferObjects([f, b], this.walletClient.address);
|
|
706
|
+
const m = await this.walletClient.signExecuteTransaction({
|
|
707
|
+
transaction: i,
|
|
708
|
+
dryRun: (C = n == null ? void 0 : n.dryRun) != null ? C : !1
|
|
686
709
|
});
|
|
687
|
-
return !(n != null && n.dryRun) && ((
|
|
710
|
+
return !(n != null && n.dryRun) && ((B = (g = m.effects) == null ? void 0 : g.status) == null ? void 0 : B.status) === "success" && (this.emit("lending:liquidate-success", {
|
|
688
711
|
payIdentifier: e,
|
|
689
712
|
payAmount: a,
|
|
690
713
|
collateralIdentifier: t,
|
|
691
714
|
liquidationAddress: s
|
|
692
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
715
|
+
}), this.walletClient.module("balance").updatePortfolio()), m;
|
|
693
716
|
}
|
|
694
717
|
/**
|
|
695
718
|
* Gets the available lending rewards for the current user.
|
|
@@ -701,7 +724,7 @@ class Te extends E {
|
|
|
701
724
|
async getAvailableRewards(e) {
|
|
702
725
|
if (!this.walletClient)
|
|
703
726
|
throw new Error("Wallet client not found");
|
|
704
|
-
return
|
|
727
|
+
return H(this.walletClient.address, {
|
|
705
728
|
...e,
|
|
706
729
|
env: this.config.env
|
|
707
730
|
});
|
|
@@ -716,7 +739,7 @@ class Te extends E {
|
|
|
716
739
|
async getClaimedRewardHistory(e) {
|
|
717
740
|
if (!this.walletClient)
|
|
718
741
|
throw new Error("Wallet client not found");
|
|
719
|
-
return
|
|
742
|
+
return he(this.walletClient.address, {
|
|
720
743
|
...e
|
|
721
744
|
});
|
|
722
745
|
}
|
|
@@ -727,13 +750,13 @@ class Te extends E {
|
|
|
727
750
|
* @returns Transaction response or dry run response
|
|
728
751
|
*/
|
|
729
752
|
async claimAllRewards(e) {
|
|
730
|
-
var n,
|
|
753
|
+
var n, c, l;
|
|
731
754
|
if (!this.walletClient)
|
|
732
755
|
throw new Error("Wallet client not found");
|
|
733
|
-
const a = new
|
|
756
|
+
const a = new w(), t = await H(this.walletClient.address, {
|
|
734
757
|
env: this.config.env
|
|
735
758
|
});
|
|
736
|
-
await
|
|
759
|
+
await fe(a, t, {
|
|
737
760
|
env: this.config.env,
|
|
738
761
|
accountCap: e == null ? void 0 : e.accountCap
|
|
739
762
|
});
|
|
@@ -741,20 +764,20 @@ class Te extends E {
|
|
|
741
764
|
transaction: a,
|
|
742
765
|
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
743
766
|
});
|
|
744
|
-
return !(e != null && e.dryRun) && ((
|
|
767
|
+
return !(e != null && e.dryRun) && ((l = (c = s.effects) == null ? void 0 : c.status) == null ? void 0 : l.status) === "success" && (this.emit("lending:claim-rewards-success", {
|
|
745
768
|
rewards: t
|
|
746
769
|
}), this.walletClient.module("balance").updatePortfolio()), s;
|
|
747
770
|
}
|
|
748
771
|
async updateOraclePTB(e, a) {
|
|
749
|
-
const t = await
|
|
772
|
+
const t = await Q({
|
|
750
773
|
env: this.config.env
|
|
751
774
|
}), s = await this.getLendingState({
|
|
752
775
|
cacheTime: 60 * 1e3
|
|
753
|
-
}), n =
|
|
776
|
+
}), n = K(t, {
|
|
754
777
|
lendingState: s,
|
|
755
778
|
pools: a
|
|
756
779
|
});
|
|
757
|
-
await
|
|
780
|
+
await q(e, n, {
|
|
758
781
|
env: this.config.env,
|
|
759
782
|
updatePythPriceFeeds: !0
|
|
760
783
|
});
|
|
@@ -770,7 +793,7 @@ class Te extends E {
|
|
|
770
793
|
var s;
|
|
771
794
|
if (!this.walletClient)
|
|
772
795
|
throw new Error("Wallet client not found");
|
|
773
|
-
const a = new
|
|
796
|
+
const a = new w();
|
|
774
797
|
return await this.updateOraclePTB(a, e == null ? void 0 : e.pools), await this.walletClient.signExecuteTransaction({
|
|
775
798
|
transaction: a,
|
|
776
799
|
dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
|
|
@@ -785,7 +808,7 @@ class Te extends E {
|
|
|
785
808
|
async getLendingState(e) {
|
|
786
809
|
if (!this.walletClient)
|
|
787
810
|
throw new Error("Wallet client not found");
|
|
788
|
-
return await
|
|
811
|
+
return await ge(this.walletClient.address, {
|
|
789
812
|
env: this.config.env,
|
|
790
813
|
...e,
|
|
791
814
|
client: this.walletClient.client
|
|
@@ -801,22 +824,22 @@ class Te extends E {
|
|
|
801
824
|
var n;
|
|
802
825
|
if (!this.walletClient)
|
|
803
826
|
throw new Error("Wallet client not found");
|
|
804
|
-
const a = new
|
|
827
|
+
const a = new w(), t = await me(a);
|
|
805
828
|
return a.transferObjects([t], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
806
829
|
transaction: a,
|
|
807
830
|
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
808
831
|
});
|
|
809
832
|
}
|
|
810
833
|
}
|
|
811
|
-
class
|
|
834
|
+
class pe extends R {
|
|
812
835
|
constructor() {
|
|
813
836
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
814
837
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
815
838
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
816
839
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
817
840
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
818
|
-
}, this.getStats =
|
|
819
|
-
|
|
841
|
+
}, this.getStats = ae(
|
|
842
|
+
M(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
820
843
|
);
|
|
821
844
|
}
|
|
822
845
|
/**
|
|
@@ -833,7 +856,7 @@ class ve extends E {
|
|
|
833
856
|
e.object(this.config.poolId),
|
|
834
857
|
e.object(this.config.metadataId),
|
|
835
858
|
e.object("0x05"),
|
|
836
|
-
|
|
859
|
+
k(a, e.object)
|
|
837
860
|
],
|
|
838
861
|
typeArguments: []
|
|
839
862
|
});
|
|
@@ -853,7 +876,7 @@ class ve extends E {
|
|
|
853
876
|
e.object(this.config.poolId),
|
|
854
877
|
e.object(this.config.metadataId),
|
|
855
878
|
e.object("0x05"),
|
|
856
|
-
|
|
879
|
+
k(a, e.object)
|
|
857
880
|
],
|
|
858
881
|
typeArguments: []
|
|
859
882
|
});
|
|
@@ -868,25 +891,25 @@ class ve extends E {
|
|
|
868
891
|
* @throws Error if wallet client not found or stake amount is too low
|
|
869
892
|
*/
|
|
870
893
|
async stake(e, a) {
|
|
871
|
-
var
|
|
894
|
+
var i, o, u;
|
|
872
895
|
if (!this.walletClient)
|
|
873
896
|
throw new Error("Wallet client not found");
|
|
874
897
|
if (e < 1e9)
|
|
875
898
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
876
|
-
const t = new
|
|
899
|
+
const t = new w();
|
|
877
900
|
await this.walletClient.module("balance").waitForUpdate();
|
|
878
901
|
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = y(t, s.coins, {
|
|
879
902
|
balance: e,
|
|
880
903
|
useGasCoin: !0
|
|
881
|
-
}),
|
|
882
|
-
t.transferObjects([
|
|
883
|
-
const
|
|
904
|
+
}), c = await this.stakePTB(t, n);
|
|
905
|
+
t.transferObjects([c], this.walletClient.address);
|
|
906
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
884
907
|
transaction: t,
|
|
885
|
-
dryRun: (
|
|
908
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
886
909
|
});
|
|
887
|
-
return !(a != null && a.dryRun) && ((u = (
|
|
910
|
+
return !(a != null && a.dryRun) && ((u = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : u.status) === "success" && (this.emit("volo:stake-success", {
|
|
888
911
|
suiAmount: e
|
|
889
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
912
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
890
913
|
}
|
|
891
914
|
/**
|
|
892
915
|
* Unstake vSUI tokens to receive SUI tokens
|
|
@@ -897,26 +920,26 @@ class ve extends E {
|
|
|
897
920
|
* @throws Error if wallet client not found or unstake amount is too low
|
|
898
921
|
*/
|
|
899
922
|
async unstake(e, a) {
|
|
900
|
-
var
|
|
923
|
+
var i, o, u;
|
|
901
924
|
if (!this.walletClient)
|
|
902
925
|
throw new Error("Wallet client not found");
|
|
903
926
|
if (e < 1e9)
|
|
904
927
|
throw new Error("Unstake amount should >= 1vSui");
|
|
905
928
|
await this.walletClient.module("balance").waitForUpdate();
|
|
906
|
-
const t = new
|
|
929
|
+
const t = new w(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = y(t, s.coins, {
|
|
907
930
|
balance: e
|
|
908
|
-
}),
|
|
909
|
-
t.transferObjects([
|
|
910
|
-
const
|
|
931
|
+
}), c = await this.unstakePTB(t, n);
|
|
932
|
+
t.transferObjects([c], this.walletClient.address);
|
|
933
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
911
934
|
transaction: t,
|
|
912
|
-
dryRun: (
|
|
935
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
913
936
|
});
|
|
914
|
-
return !(a != null && a.dryRun) && ((u = (
|
|
937
|
+
return !(a != null && a.dryRun) && ((u = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : u.status) === "success" && (this.emit("volo:unstake-success", {
|
|
915
938
|
vSuiAmount: e
|
|
916
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
939
|
+
}), this.walletClient.module("balance").updatePortfolio()), l;
|
|
917
940
|
}
|
|
918
941
|
}
|
|
919
|
-
class
|
|
942
|
+
class Ee extends R {
|
|
920
943
|
constructor() {
|
|
921
944
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
922
945
|
apiKey: "",
|
|
@@ -933,7 +956,7 @@ class Pe extends E {
|
|
|
933
956
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
934
957
|
*/
|
|
935
958
|
get referral() {
|
|
936
|
-
return this.config.apiKey ?
|
|
959
|
+
return this.config.apiKey ? Ce(this.config.apiKey) : 0;
|
|
937
960
|
}
|
|
938
961
|
/**
|
|
939
962
|
* Get the swap options
|
|
@@ -955,7 +978,7 @@ class Pe extends E {
|
|
|
955
978
|
* @returns A promise that resolves with the quote
|
|
956
979
|
*/
|
|
957
980
|
async getQuote(e, a, t) {
|
|
958
|
-
return
|
|
981
|
+
return be(e, a, t, this.config.apiKey, this.swapOptions);
|
|
959
982
|
}
|
|
960
983
|
/**
|
|
961
984
|
* Builds a swap transaction from a quote
|
|
@@ -968,8 +991,8 @@ class Pe extends E {
|
|
|
968
991
|
async buildSwapPTBFromQuote(e, a, t, s) {
|
|
969
992
|
if (!this.walletClient)
|
|
970
993
|
throw new Error("Wallet client not found");
|
|
971
|
-
const n = new
|
|
972
|
-
return await
|
|
994
|
+
const n = new p(a.amount_out).multipliedBy(1 - s).toFixed(0);
|
|
995
|
+
return await $(
|
|
973
996
|
this.walletClient.address,
|
|
974
997
|
e,
|
|
975
998
|
Number(n),
|
|
@@ -999,40 +1022,40 @@ class Pe extends E {
|
|
|
999
1022
|
* @returns Transaction response or dry run response
|
|
1000
1023
|
*/
|
|
1001
1024
|
async swap(e, a, t, s, n) {
|
|
1002
|
-
var
|
|
1025
|
+
var h, f, b, m;
|
|
1003
1026
|
if (!this.walletClient)
|
|
1004
1027
|
throw new Error("Wallet client not found");
|
|
1005
1028
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1006
|
-
const
|
|
1029
|
+
const c = this.walletClient.module("balance").portfolio.getBalance(e), l = new w(), i = y(l, c.coins, {
|
|
1007
1030
|
balance: t,
|
|
1008
1031
|
useGasCoin: !0
|
|
1009
|
-
}),
|
|
1010
|
-
|
|
1032
|
+
}), o = await this.getQuote(e, a, t), u = await this.buildSwapPTBFromQuote(l, o, i, s);
|
|
1033
|
+
l.transferObjects([u], this.walletClient.address);
|
|
1011
1034
|
const d = await this.walletClient.signExecuteTransaction({
|
|
1012
|
-
transaction:
|
|
1013
|
-
dryRun: (
|
|
1035
|
+
transaction: l,
|
|
1036
|
+
dryRun: (h = n == null ? void 0 : n.dryRun) != null ? h : !1
|
|
1014
1037
|
});
|
|
1015
|
-
if (!(n != null && n.dryRun) && ((b = (
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1038
|
+
if (!(n != null && n.dryRun) && ((b = (f = d.effects) == null ? void 0 : f.status) == null ? void 0 : b.status) === "success") {
|
|
1039
|
+
const C = (m = d.events) == null ? void 0 : m.find((g) => g.type.includes("::slippage::SwapEvent"));
|
|
1040
|
+
C && this.emit("swap:swap-success", {
|
|
1018
1041
|
fromCoinType: e,
|
|
1019
1042
|
toCoinType: a,
|
|
1020
1043
|
fromAmount: t,
|
|
1021
1044
|
slippage: s,
|
|
1022
|
-
toAmount: Number(
|
|
1045
|
+
toAmount: Number(C.parsedJson.amount_out)
|
|
1023
1046
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1024
1047
|
}
|
|
1025
1048
|
return d;
|
|
1026
1049
|
}
|
|
1027
1050
|
}
|
|
1028
|
-
class
|
|
1051
|
+
class Re extends R {
|
|
1029
1052
|
constructor() {
|
|
1030
1053
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1031
1054
|
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
1032
1055
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1033
1056
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1034
|
-
}, this.getApy =
|
|
1035
|
-
|
|
1057
|
+
}, this.getApy = ae(
|
|
1058
|
+
M(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
1036
1059
|
);
|
|
1037
1060
|
}
|
|
1038
1061
|
/**
|
|
@@ -1048,7 +1071,7 @@ class pe extends E {
|
|
|
1048
1071
|
arguments: [
|
|
1049
1072
|
e.object("0x05"),
|
|
1050
1073
|
e.object(this.config.configId),
|
|
1051
|
-
|
|
1074
|
+
k(a, e.object),
|
|
1052
1075
|
e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1053
1076
|
],
|
|
1054
1077
|
typeArguments: []
|
|
@@ -1068,7 +1091,7 @@ class pe extends E {
|
|
|
1068
1091
|
arguments: [
|
|
1069
1092
|
e.object("0x05"),
|
|
1070
1093
|
e.object(this.config.configId),
|
|
1071
|
-
|
|
1094
|
+
k(a, e.object)
|
|
1072
1095
|
],
|
|
1073
1096
|
typeArguments: []
|
|
1074
1097
|
});
|
|
@@ -1081,21 +1104,21 @@ class pe extends E {
|
|
|
1081
1104
|
* @param options Optional dry run
|
|
1082
1105
|
*/
|
|
1083
1106
|
async stake(e, a) {
|
|
1084
|
-
var
|
|
1107
|
+
var i, o, u;
|
|
1085
1108
|
if (!this.walletClient)
|
|
1086
1109
|
throw new Error("Wallet client not found");
|
|
1087
|
-
const t = new
|
|
1110
|
+
const t = new w();
|
|
1088
1111
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1089
1112
|
const s = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), n = y(t, s.coins, {
|
|
1090
1113
|
balance: e,
|
|
1091
1114
|
useGasCoin: !0
|
|
1092
|
-
}),
|
|
1093
|
-
t.transferObjects([
|
|
1094
|
-
const
|
|
1115
|
+
}), c = await this.stakePTB(t, n);
|
|
1116
|
+
t.transferObjects([c], this.walletClient.address);
|
|
1117
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
1095
1118
|
transaction: t,
|
|
1096
|
-
dryRun: (
|
|
1119
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
1097
1120
|
});
|
|
1098
|
-
return !(a != null && a.dryRun) && ((u = (
|
|
1121
|
+
return !(a != null && a.dryRun) && ((u = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : u.status) === "success" && (this.emit("haedal:stake-success", { suiAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
|
|
1099
1122
|
}
|
|
1100
1123
|
/**
|
|
1101
1124
|
* Unstake haSUI for SUI
|
|
@@ -1104,47 +1127,47 @@ class pe extends E {
|
|
|
1104
1127
|
* @param options Optional dry run
|
|
1105
1128
|
*/
|
|
1106
1129
|
async unstake(e, a) {
|
|
1107
|
-
var
|
|
1130
|
+
var i, o, u;
|
|
1108
1131
|
if (!this.walletClient)
|
|
1109
1132
|
throw new Error("Wallet client not found");
|
|
1110
1133
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1111
|
-
const t = new
|
|
1134
|
+
const t = new w(), s = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), n = y(t, s.coins, {
|
|
1112
1135
|
balance: e
|
|
1113
|
-
}),
|
|
1114
|
-
t.transferObjects([
|
|
1115
|
-
const
|
|
1136
|
+
}), c = await this.unstakePTB(t, n);
|
|
1137
|
+
t.transferObjects([c], this.walletClient.address);
|
|
1138
|
+
const l = await this.walletClient.signExecuteTransaction({
|
|
1116
1139
|
transaction: t,
|
|
1117
|
-
dryRun: (
|
|
1140
|
+
dryRun: (i = a == null ? void 0 : a.dryRun) != null ? i : !1
|
|
1118
1141
|
});
|
|
1119
|
-
return !(a != null && a.dryRun) && ((u = (
|
|
1142
|
+
return !(a != null && a.dryRun) && ((u = (o = l.effects) == null ? void 0 : o.status) == null ? void 0 : u.status) === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), l;
|
|
1120
1143
|
}
|
|
1121
1144
|
}
|
|
1122
|
-
const
|
|
1145
|
+
const Se = {
|
|
1123
1146
|
/** Balance management module */
|
|
1124
|
-
balance: new
|
|
1147
|
+
balance: new Be(),
|
|
1125
1148
|
/** Lending protocol module */
|
|
1126
|
-
lending: new
|
|
1149
|
+
lending: new ve(),
|
|
1127
1150
|
/** Volo protocol module */
|
|
1128
|
-
volo: new
|
|
1151
|
+
volo: new pe(),
|
|
1129
1152
|
/** DEX swapping module */
|
|
1130
|
-
swap: new
|
|
1153
|
+
swap: new Ee(),
|
|
1131
1154
|
/** Haedal protocol module */
|
|
1132
|
-
haedal: new
|
|
1133
|
-
},
|
|
1134
|
-
url:
|
|
1155
|
+
haedal: new Re()
|
|
1156
|
+
}, Oe = {
|
|
1157
|
+
url: le("mainnet")
|
|
1135
1158
|
};
|
|
1136
|
-
class
|
|
1159
|
+
class Ie {
|
|
1137
1160
|
/**
|
|
1138
1161
|
* Creates a new wallet client instance
|
|
1139
1162
|
* @param options - Configuration options for the wallet client
|
|
1140
1163
|
*/
|
|
1141
1164
|
constructor(e) {
|
|
1142
|
-
this.modules =
|
|
1165
|
+
this.modules = Se, this.userConfigs = {}, this.events = re();
|
|
1143
1166
|
const a = {
|
|
1144
|
-
...
|
|
1167
|
+
...Oe,
|
|
1145
1168
|
...e.client
|
|
1146
1169
|
};
|
|
1147
|
-
a.transport = a.transport || new
|
|
1170
|
+
a.transport = a.transport || new ye(a.url), this.client = new ie(a), this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, s]) => {
|
|
1148
1171
|
if (t !== s.name)
|
|
1149
1172
|
throw new Error(`Module name ${t} does not match module name ${s.name}`);
|
|
1150
1173
|
s.install(this);
|
|
@@ -1174,7 +1197,7 @@ class We {
|
|
|
1174
1197
|
const { dryRun: a = !1, ...t } = e;
|
|
1175
1198
|
if (a) {
|
|
1176
1199
|
let s;
|
|
1177
|
-
return e.transaction instanceof
|
|
1200
|
+
return e.transaction instanceof w ? (e.transaction.setSenderIfNotSet(this.address), s = await e.transaction.build({
|
|
1178
1201
|
client: this.client
|
|
1179
1202
|
})) : s = e.transaction, this.client.dryRunTransactionBlock({
|
|
1180
1203
|
transactionBlock: s
|
|
@@ -1220,7 +1243,7 @@ class We {
|
|
|
1220
1243
|
return e in this.modules;
|
|
1221
1244
|
}
|
|
1222
1245
|
}
|
|
1223
|
-
class
|
|
1246
|
+
class Le extends ne {
|
|
1224
1247
|
/**
|
|
1225
1248
|
* Creates a new watch-only signer
|
|
1226
1249
|
*
|
|
@@ -1284,7 +1307,7 @@ class Ne extends Y {
|
|
|
1284
1307
|
return {};
|
|
1285
1308
|
}
|
|
1286
1309
|
}
|
|
1287
|
-
class
|
|
1310
|
+
class Me extends ne {
|
|
1288
1311
|
/**
|
|
1289
1312
|
* Creates a new watch-only signer
|
|
1290
1313
|
*
|
|
@@ -1337,8 +1360,8 @@ class Ie extends Y {
|
|
|
1337
1360
|
}
|
|
1338
1361
|
}
|
|
1339
1362
|
export {
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1363
|
+
Ie as WalletClient,
|
|
1364
|
+
Le as WatchSigner,
|
|
1365
|
+
Me as WebSigner
|
|
1343
1366
|
};
|
|
1344
1367
|
//# sourceMappingURL=index.esm.js.map
|