@naviprotocol/wallet-client 1.3.2-dev.3 → 1.3.2-dev.7
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 +287 -293
- package/dist/index.esm.js.map +1 -1
- package/dist/modules/lendingModule/index.d.ts +0 -1
- package/dist/modules/lendingModule/index.d.ts.map +1 -1
- package/dist/modules/lendingModule/migrate.d.ts +1 -1
- package/dist/modules/lendingModule/migrate.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { getFullnodeUrl as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { withSingleton as
|
|
5
|
-
import
|
|
6
|
-
import { normalizeStructTag as
|
|
1
|
+
import { getFullnodeUrl as we, SuiClient as he } from "@mysten/sui/client";
|
|
2
|
+
import fe from "mitt";
|
|
3
|
+
import ge from "axios";
|
|
4
|
+
import { withSingleton as L, getCoins as te, mergeCoinsPTB as P, getPriceFeeds as Q, updateOraclePricesPTB as K, filterPriceFeeds as $, getFlashLoanAsset as ae, flashloanPTB as ne, depositCoinPTB as N, repayFlashLoanPTB as se, borrowCoinPTB as ie, withdrawCoinPTB as le, repayCoinPTB as re, getPools as me, getPool as T, getHealthFactor as Ce, liquidatePTB as be, getUserAvailableLendingRewards as J, getUserClaimedRewardHistory as ye, claimLendingRewardsPTB as pe, getLendingState as Pe, createAccountCapPTB as Be, withCache as oe, parseTxValue as _ } from "@naviprotocol/lending";
|
|
5
|
+
import R, { BigNumber as W } from "bignumber.js";
|
|
6
|
+
import { normalizeStructTag as p } from "@mysten/sui/utils";
|
|
7
7
|
import { Transaction as m } from "@mysten/sui/transactions";
|
|
8
|
-
import { buildSwapPTBFromQuote as
|
|
9
|
-
import { SuilendClient as
|
|
10
|
-
import { getCoinMetadataMap as
|
|
11
|
-
import { executeAuction as
|
|
12
|
-
import { Signer as
|
|
13
|
-
const
|
|
8
|
+
import { buildSwapPTBFromQuote as q, generateRefId as Te, getQuote as ve } from "@naviprotocol/astros-aggregator-sdk";
|
|
9
|
+
import { SuilendClient as V, LENDING_MARKET_ID as Ee, LENDING_MARKET_TYPE as X, parseReserve as Re, parseObligation as Se } from "@suilend/sdk";
|
|
10
|
+
import { getCoinMetadataMap as Oe, MAX_U64 as Ae } from "@suilend/sui-fe";
|
|
11
|
+
import { executeAuction as xe } from "shio-sdk";
|
|
12
|
+
import { Signer as ce } from "@mysten/sui/cryptography";
|
|
13
|
+
const ue = ge.create({
|
|
14
14
|
timeout: 2e4
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
ue.interceptors.response.use(
|
|
17
17
|
function(o) {
|
|
18
18
|
if (o.data.err)
|
|
19
19
|
throw new Error(o.data.err);
|
|
@@ -25,7 +25,7 @@ ge.interceptors.response.use(
|
|
|
25
25
|
return Promise.reject(o);
|
|
26
26
|
}
|
|
27
27
|
);
|
|
28
|
-
class
|
|
28
|
+
class ke {
|
|
29
29
|
/**
|
|
30
30
|
* Creates a new custom transport instance
|
|
31
31
|
*
|
|
@@ -44,7 +44,7 @@ class Me {
|
|
|
44
44
|
* @returns Promise<T> - The response data from the RPC call
|
|
45
45
|
*/
|
|
46
46
|
async request(e) {
|
|
47
|
-
return this.requestId += 1, (await
|
|
47
|
+
return this.requestId += 1, (await ue.post(this.rpcUrl, {
|
|
48
48
|
jsonrpc: "2.0",
|
|
49
49
|
id: this.requestId,
|
|
50
50
|
method: e.method,
|
|
@@ -107,25 +107,25 @@ class O {
|
|
|
107
107
|
this.walletClient = void 0;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
class
|
|
110
|
+
class S {
|
|
111
111
|
/**
|
|
112
112
|
* Creates a new user portfolio
|
|
113
113
|
*
|
|
114
114
|
* @param coins - Array of coin objects or existing portfolio to copy from
|
|
115
115
|
*/
|
|
116
116
|
constructor(e) {
|
|
117
|
-
if (e instanceof
|
|
117
|
+
if (e instanceof S)
|
|
118
118
|
this.balances = JSON.parse(JSON.stringify(e.balances));
|
|
119
119
|
else {
|
|
120
120
|
const a = {};
|
|
121
121
|
e == null || e.forEach((t) => {
|
|
122
|
-
const
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
coinType:
|
|
126
|
-
amount:
|
|
122
|
+
const n = p(t.coinType);
|
|
123
|
+
let s = a[n];
|
|
124
|
+
s || (s = {
|
|
125
|
+
coinType: n,
|
|
126
|
+
amount: W(0),
|
|
127
127
|
coins: []
|
|
128
|
-
}, a[
|
|
128
|
+
}, a[n] = s), s.coins.push(t), s.amount = s.amount.plus(t.balance);
|
|
129
129
|
}), this.balances = a;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
@@ -136,7 +136,7 @@ class E {
|
|
|
136
136
|
* @returns UserCoinBalance object with coin type, total amount, and coin objects
|
|
137
137
|
*/
|
|
138
138
|
getBalance(e) {
|
|
139
|
-
return e =
|
|
139
|
+
return e = p(e), this.balances[e] || { coinType: e, amount: W(0), coins: [] };
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Gets all coin types in the portfolio
|
|
@@ -153,9 +153,9 @@ class E {
|
|
|
153
153
|
* @returns BigNumber representing the total balance
|
|
154
154
|
*/
|
|
155
155
|
balanceOf(e) {
|
|
156
|
-
e =
|
|
156
|
+
e = p(e);
|
|
157
157
|
const a = this.getBalance(e);
|
|
158
|
-
return (a == null ? void 0 : a.amount) ||
|
|
158
|
+
return (a == null ? void 0 : a.amount) || W(0);
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Creates a deep copy of the portfolio
|
|
@@ -166,22 +166,22 @@ class E {
|
|
|
166
166
|
* @returns New UserPortfolio instance with copied data
|
|
167
167
|
*/
|
|
168
168
|
clone() {
|
|
169
|
-
const e = JSON.parse(JSON.stringify(this.balances)), a = new
|
|
169
|
+
const e = JSON.parse(JSON.stringify(this.balances)), a = new S();
|
|
170
170
|
return a.balances = e, a;
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
-
class
|
|
173
|
+
class Ne extends O {
|
|
174
174
|
constructor() {
|
|
175
175
|
super(...arguments), this.name = "balance", this.defaultConfig = {
|
|
176
176
|
coinPollingInterval: 6e3,
|
|
177
177
|
disableCoinPolling: !1
|
|
178
|
-
}, this.updatePortfolio =
|
|
178
|
+
}, this.updatePortfolio = L(async () => {
|
|
179
179
|
if (!this.walletClient)
|
|
180
180
|
throw new Error("Wallet client not found");
|
|
181
|
-
this._coins = await
|
|
181
|
+
this._coins = await te(this.walletClient.address, {
|
|
182
182
|
client: this.walletClient.client
|
|
183
|
-
}), this._portfolio = new
|
|
184
|
-
}), this._coins = [], this._portfolio = new
|
|
183
|
+
}), this._portfolio = new S(this._coins), this.emit("balance:portfolio-updated", {});
|
|
184
|
+
}), this._coins = [], this._portfolio = new S(), this.pollingTimer = null, this._updatePromise = null;
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* Gets the current coin objects from the wallet
|
|
@@ -219,8 +219,8 @@ class Le extends O {
|
|
|
219
219
|
* @param options - Optional parameters including dry run mode
|
|
220
220
|
* @returns Transaction response or dry run response
|
|
221
221
|
*/
|
|
222
|
-
async sendCoin(e, a, t,
|
|
223
|
-
return this.sendCoinBatch(e, [a], [t],
|
|
222
|
+
async sendCoin(e, a, t, n) {
|
|
223
|
+
return this.sendCoinBatch(e, [a], [t], n);
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
226
226
|
* Sends coins to multiple recipients in a single transaction
|
|
@@ -231,27 +231,27 @@ class Le extends O {
|
|
|
231
231
|
* @param options - Optional parameters including dry run mode
|
|
232
232
|
* @returns Transaction response or dry run response
|
|
233
233
|
*/
|
|
234
|
-
async sendCoinBatch(e, a, t,
|
|
234
|
+
async sendCoinBatch(e, a, t, n) {
|
|
235
235
|
var w;
|
|
236
236
|
if (!this.walletClient)
|
|
237
237
|
throw new Error("Wallet client not found");
|
|
238
238
|
if (a.length !== t.length)
|
|
239
239
|
throw new Error("Recipients and amounts must have the same length");
|
|
240
240
|
await this.waitForUpdate();
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
241
|
+
const s = this.portfolio.getBalance(e), c = t.reduce((g, h) => g.plus(h), R(0));
|
|
242
|
+
if (s.amount.lt(c))
|
|
243
243
|
throw new Error("Insufficient balance");
|
|
244
244
|
const i = new m();
|
|
245
245
|
let l = i.gas;
|
|
246
|
-
|
|
246
|
+
p(e) !== p("0x2::sui::SUI") && (l = P(i, s.coins, {
|
|
247
247
|
balance: c.toNumber()
|
|
248
248
|
}));
|
|
249
249
|
const u = i.splitCoins(l, t);
|
|
250
|
-
return a.forEach((
|
|
251
|
-
i.transferObjects([u[h]],
|
|
250
|
+
return a.forEach((g, h) => {
|
|
251
|
+
i.transferObjects([u[h]], g);
|
|
252
252
|
}), await this.walletClient.signExecuteTransaction({
|
|
253
253
|
transaction: i,
|
|
254
|
-
dryRun: (w =
|
|
254
|
+
dryRun: (w = n == null ? void 0 : n.dryRun) != null ? w : !1
|
|
255
255
|
});
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
@@ -283,11 +283,11 @@ class Le extends O {
|
|
|
283
283
|
if (e.length !== a.length)
|
|
284
284
|
throw new Error("Objects and recipients must have the same length");
|
|
285
285
|
await this.waitForUpdate();
|
|
286
|
-
const
|
|
286
|
+
const n = new m();
|
|
287
287
|
return e.forEach((i, l) => {
|
|
288
|
-
|
|
288
|
+
n.transferObjects([n.object(i)], a[l]);
|
|
289
289
|
}), await this.walletClient.signExecuteTransaction({
|
|
290
|
-
transaction:
|
|
290
|
+
transaction: n,
|
|
291
291
|
dryRun: (c = t == null ? void 0 : t.dryRun) != null ? c : !1
|
|
292
292
|
});
|
|
293
293
|
}
|
|
@@ -329,168 +329,163 @@ class Le extends O {
|
|
|
329
329
|
super.uninstall(), this.pollingTimer && (clearTimeout(this.pollingTimer), this.pollingTimer = null);
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
|
-
async function
|
|
333
|
-
var
|
|
332
|
+
async function Y(o, e, a, t) {
|
|
333
|
+
var A, x, k;
|
|
334
334
|
if (!this.walletClient)
|
|
335
335
|
throw new Error("Wallet client not found");
|
|
336
|
-
const
|
|
336
|
+
const n = await this.getPool(a), s = await this.getLendingState(), c = this.walletClient.address, i = (A = t == null ? void 0 : t.protocol) != null ? A : "navi";
|
|
337
|
+
let l;
|
|
338
|
+
i === "navi" && (l = await this.getPool(e));
|
|
339
|
+
const u = await this.getProtocol(i);
|
|
337
340
|
if (!u)
|
|
338
|
-
throw new Error(`Protocol ${
|
|
339
|
-
const r = await u.getPool(
|
|
341
|
+
throw new Error(`Protocol ${i} not found`);
|
|
342
|
+
const r = await u.getPool(e.toString());
|
|
340
343
|
if (console.log("migrateBetweenSupplyPTB", {
|
|
341
344
|
fromPoolLending: r
|
|
342
|
-
}),
|
|
345
|
+
}), i === "navi" && r.supplyBalance === 0)
|
|
343
346
|
throw new Error("No supply balance");
|
|
344
347
|
if (t != null && t.amount && t.amount > r.supplyBalance)
|
|
345
348
|
throw new Error("Amount is less than supply balance");
|
|
346
|
-
const w = await
|
|
347
|
-
await
|
|
349
|
+
const w = await Q();
|
|
350
|
+
await K(
|
|
348
351
|
o,
|
|
349
|
-
|
|
350
|
-
lendingState:
|
|
351
|
-
pools:
|
|
352
|
+
$(w, {
|
|
353
|
+
lendingState: s,
|
|
354
|
+
pools: l ? [l, n] : [n]
|
|
352
355
|
})
|
|
353
356
|
);
|
|
354
|
-
const
|
|
357
|
+
const g = await ae(n, {
|
|
355
358
|
env: this.config.env
|
|
356
359
|
});
|
|
357
|
-
if (!
|
|
360
|
+
if (!g)
|
|
358
361
|
throw new Error(`${n.token.symbol} pool not support flashloan`);
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
n.suiCoinType,
|
|
362
|
-
b
|
|
363
|
-
), g = Number(d.amount_out);
|
|
364
|
-
if (g <= 0)
|
|
362
|
+
const h = (x = t == null ? void 0 : t.slippage) != null ? x : 5e-3, b = (k = t == null ? void 0 : t.amount) != null ? k : Number(r.supplyBalance), y = await this.walletClient.swap.getQuote(e, n.suiCoinType, b), d = Number(y.amount_out);
|
|
363
|
+
if (d <= 0)
|
|
365
364
|
throw new Error("The amount of swapAmountOut must be greater than 0.");
|
|
366
|
-
const
|
|
367
|
-
if (
|
|
365
|
+
const f = Math.floor(d * (1 - h)), C = Math.floor(f / (1 + g.flashloanFee));
|
|
366
|
+
if (C <= 0)
|
|
368
367
|
throw new Error("The calculated borrow amount must be positive.");
|
|
369
|
-
const [
|
|
368
|
+
const [B, v] = await ne(o, n, C), [E] = o.moveCall({
|
|
370
369
|
target: "0x2::coin::from_balance",
|
|
371
|
-
arguments: [
|
|
370
|
+
arguments: [B],
|
|
372
371
|
typeArguments: [n.suiCoinType]
|
|
373
372
|
});
|
|
374
|
-
await
|
|
375
|
-
amount:
|
|
373
|
+
await N(o, n, E, {
|
|
374
|
+
amount: C
|
|
376
375
|
});
|
|
377
|
-
const
|
|
378
|
-
|
|
376
|
+
const F = await u.withdrawCoinPTB(o, e, b), j = await q(
|
|
377
|
+
c,
|
|
379
378
|
o,
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
),
|
|
379
|
+
f,
|
|
380
|
+
F,
|
|
381
|
+
y
|
|
382
|
+
), I = o.moveCall({
|
|
384
383
|
target: "0x2::coin::into_balance",
|
|
385
|
-
arguments: [
|
|
384
|
+
arguments: [j],
|
|
386
385
|
typeArguments: [n.suiCoinType]
|
|
387
|
-
}), [
|
|
386
|
+
}), [U] = await se(o, n, v, I), [M] = o.moveCall({
|
|
388
387
|
target: "0x2::coin::from_balance",
|
|
389
|
-
arguments: [
|
|
388
|
+
arguments: [U],
|
|
390
389
|
typeArguments: [n.suiCoinType]
|
|
391
390
|
});
|
|
392
|
-
return await
|
|
391
|
+
return await N(o, n, M), o;
|
|
393
392
|
}
|
|
394
|
-
async function
|
|
395
|
-
var
|
|
393
|
+
async function Z(o, e, a, t) {
|
|
394
|
+
var z, H, D;
|
|
396
395
|
if (!this.walletClient)
|
|
397
396
|
throw new Error("Wallet client not found");
|
|
398
|
-
const
|
|
397
|
+
const n = this.walletClient.address, s = await this.getPool(e), c = await this.getPool(a), i = await this.getLendingState(), l = (z = t == null ? void 0 : t.protocol) != null ? z : "navi", u = await this.getProtocol(l);
|
|
399
398
|
if (!u)
|
|
400
399
|
throw new Error(`Protocol ${l} not found`);
|
|
401
|
-
const r = await u.getPool(
|
|
400
|
+
const r = await u.getPool(s.coinType);
|
|
402
401
|
if (console.log("migrateBetweenBorrowPTB", {
|
|
403
402
|
fromPoolLending: r
|
|
404
403
|
}), r.borrowBalance === 0)
|
|
405
404
|
throw new Error("No borrow balance");
|
|
406
405
|
if (t != null && t.amount && t.amount > r.borrowBalance)
|
|
407
406
|
throw new Error("Amount is more than borrow balance");
|
|
408
|
-
const w = await
|
|
409
|
-
await
|
|
407
|
+
const w = await Q(), g = await Promise.all([s, c]);
|
|
408
|
+
await K(
|
|
410
409
|
o,
|
|
411
|
-
|
|
410
|
+
$(w, {
|
|
412
411
|
lendingState: i,
|
|
413
|
-
pools:
|
|
412
|
+
pools: g
|
|
414
413
|
})
|
|
415
414
|
);
|
|
416
|
-
let h = (
|
|
415
|
+
let h = (H = t == null ? void 0 : t.amount) != null ? H : Number(r.borrowBalance);
|
|
417
416
|
if (Number(r.borrowBalance) === h) {
|
|
418
|
-
const
|
|
417
|
+
const de = r.borrowAPR / 100;
|
|
419
418
|
h = Math.ceil(
|
|
420
|
-
new
|
|
419
|
+
new R(h).multipliedBy(de * (60 * 3) / (365 * 24 * 3600)).plus(new R(1).shiftedBy(-s.token.decimals)).plus(h).toNumber()
|
|
421
420
|
);
|
|
422
421
|
}
|
|
423
|
-
const
|
|
422
|
+
const b = await ae(s, {
|
|
424
423
|
env: this.config.env
|
|
425
424
|
});
|
|
426
|
-
if (!
|
|
427
|
-
throw new Error(`${
|
|
425
|
+
if (!b)
|
|
426
|
+
throw new Error(`${s.token.symbol} pool not support flashloan`);
|
|
428
427
|
if (!this.walletClient)
|
|
429
428
|
throw new Error("Wallet client not found");
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
429
|
+
const y = (D = t == null ? void 0 : t.slippage) != null ? D : 5e-3, d = Math.ceil(h * (1 + b.flashloanFee)), f = d, C = await this.walletClient.swap.getQuote(
|
|
430
|
+
s.suiCoinType,
|
|
431
|
+
c.suiCoinType,
|
|
432
|
+
f
|
|
433
|
+
);
|
|
434
|
+
let B = 1 + y, v = Math.ceil(Number(C.amount_out) * B), E = await this.walletClient.swap.getQuote(
|
|
435
|
+
c.suiCoinType,
|
|
436
|
+
s.suiCoinType,
|
|
437
|
+
v
|
|
438
|
+
);
|
|
439
|
+
for (; Number(E.amount_out) < f; )
|
|
440
|
+
B = B * Math.max(f / Number(E.amount_out), 1.001), v = Math.ceil(Number(C.amount_out) * B), E = await this.walletClient.swap.getQuote(
|
|
441
|
+
c.suiCoinType,
|
|
442
|
+
s.suiCoinType,
|
|
443
|
+
v
|
|
444
|
+
);
|
|
445
|
+
const [F, j] = await ne(o, s, h), [I] = o.moveCall({
|
|
447
446
|
target: "0x2::coin::from_balance",
|
|
448
|
-
arguments: [
|
|
449
|
-
typeArguments: [
|
|
447
|
+
arguments: [F],
|
|
448
|
+
typeArguments: [s.suiCoinType]
|
|
450
449
|
});
|
|
451
|
-
await u.repayCoinPTB(o,
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
n.suiCoinType,
|
|
455
|
-
k
|
|
456
|
-
), me = await z(
|
|
457
|
-
s,
|
|
450
|
+
await u.repayCoinPTB(o, s.suiCoinType, I, h);
|
|
451
|
+
const U = await ie(o, c, v), M = await q(
|
|
452
|
+
n,
|
|
458
453
|
o,
|
|
459
454
|
d,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
),
|
|
455
|
+
U,
|
|
456
|
+
E
|
|
457
|
+
), A = o.moveCall({
|
|
463
458
|
target: "0x2::coin::into_balance",
|
|
464
|
-
arguments: [
|
|
465
|
-
typeArguments: [
|
|
466
|
-
}), [
|
|
459
|
+
arguments: [M],
|
|
460
|
+
typeArguments: [s.suiCoinType]
|
|
461
|
+
}), [x] = await se(o, s, j, A), [k] = o.moveCall({
|
|
467
462
|
target: "0x2::coin::from_balance",
|
|
468
|
-
arguments: [
|
|
469
|
-
typeArguments: [
|
|
463
|
+
arguments: [x],
|
|
464
|
+
typeArguments: [s.suiCoinType]
|
|
470
465
|
});
|
|
471
|
-
return o.transferObjects([
|
|
466
|
+
return o.transferObjects([k], n), o;
|
|
472
467
|
}
|
|
473
|
-
async function
|
|
474
|
-
var w,
|
|
468
|
+
async function ee(o, e, a, t) {
|
|
469
|
+
var w, g;
|
|
475
470
|
if (!this.walletClient)
|
|
476
471
|
throw new Error("Wallet client not found");
|
|
477
|
-
const
|
|
472
|
+
const n = await te(this.walletClient.address, {
|
|
478
473
|
client: this.walletClient.client,
|
|
479
474
|
coinType: e
|
|
480
|
-
}),
|
|
475
|
+
}), s = await this.getPool(a), i = new S(n).getBalance(e);
|
|
481
476
|
if (i.amount.eq(0))
|
|
482
477
|
throw new Error(`No balance of ${e}`);
|
|
483
478
|
if (console.log("migrateBalanceToSupplyPTB", {
|
|
484
479
|
balance: i.amount.toNumber()
|
|
485
480
|
}), t != null && t.amount && i.amount.lt(t.amount))
|
|
486
481
|
throw new Error("Amount is greater than balance");
|
|
487
|
-
const l = (w = t == null ? void 0 : t.amount) != null ? w : i.amount.toNumber(), u = (
|
|
482
|
+
const l = (w = t == null ? void 0 : t.amount) != null ? w : i.amount.toNumber(), u = (g = t == null ? void 0 : t.slippage) != null ? g : 5e-3;
|
|
488
483
|
let r = await P(o, i.coins, {
|
|
489
484
|
balance: l,
|
|
490
485
|
useGasCoin: !0
|
|
491
486
|
});
|
|
492
|
-
if (
|
|
493
|
-
const h = await this.walletClient.swap.getQuote(e,
|
|
487
|
+
if (p(e) !== p(s.suiCoinType)) {
|
|
488
|
+
const h = await this.walletClient.swap.getQuote(e, s.suiCoinType, l);
|
|
494
489
|
r = await this.walletClient.swap.buildSwapPTBFromQuote(
|
|
495
490
|
o,
|
|
496
491
|
h,
|
|
@@ -498,102 +493,101 @@ async function ie(o, e, a, t) {
|
|
|
498
493
|
u
|
|
499
494
|
);
|
|
500
495
|
}
|
|
501
|
-
return await
|
|
496
|
+
return await N(o, s, r), o;
|
|
502
497
|
}
|
|
503
|
-
class
|
|
498
|
+
class _e {
|
|
504
499
|
constructor(e) {
|
|
505
500
|
this.name = "navi", this.walletClient = e;
|
|
506
501
|
}
|
|
507
502
|
async getPool(e) {
|
|
508
|
-
const a = await this.walletClient.lending.getPool(e),
|
|
509
|
-
(i) => i.pool.suiCoinType ===
|
|
510
|
-
),
|
|
503
|
+
const a = await this.walletClient.lending.getPool(e), n = (await this.walletClient.lending.getLendingState()).find(
|
|
504
|
+
(i) => i.pool.suiCoinType === p(e)
|
|
505
|
+
), s = n ? new R(n.supplyBalance).toNumber() : 0, c = n ? new R(n.borrowBalance).toNumber() : 0;
|
|
511
506
|
return {
|
|
512
|
-
supplyBalance:
|
|
507
|
+
supplyBalance: s,
|
|
513
508
|
borrowBalance: c,
|
|
514
509
|
borrowAPR: parseFloat(a.borrowIncentiveApyInfo.apy)
|
|
515
510
|
};
|
|
516
511
|
}
|
|
517
|
-
async depositCoinPTB(e, a, t,
|
|
512
|
+
async depositCoinPTB(e, a, t, n) {
|
|
518
513
|
throw new Error("Not implemented");
|
|
519
514
|
}
|
|
520
515
|
async withdrawCoinPTB(e, a, t) {
|
|
521
|
-
return
|
|
516
|
+
return le(e, a, t);
|
|
522
517
|
}
|
|
523
518
|
async borrowCoinPTB(e, a, t) {
|
|
524
519
|
throw new Error("Not implemented");
|
|
525
520
|
}
|
|
526
|
-
async repayCoinPTB(e, a, t,
|
|
527
|
-
|
|
521
|
+
async repayCoinPTB(e, a, t, n) {
|
|
522
|
+
re(e, a, t, { amount: n });
|
|
528
523
|
}
|
|
529
524
|
}
|
|
530
|
-
class
|
|
525
|
+
class G {
|
|
531
526
|
constructor(e, a, t) {
|
|
532
527
|
this.name = "suilend", this.walletClient = e, this.obligationOwnerCap = a, this.suilendClient = t;
|
|
533
528
|
}
|
|
534
529
|
static async create(e) {
|
|
535
530
|
const [a, t] = await Promise.all([
|
|
536
|
-
|
|
537
|
-
|
|
531
|
+
V.initialize(Ee, X, e.client),
|
|
532
|
+
V.getObligationOwnerCaps(
|
|
538
533
|
e.address,
|
|
539
|
-
[
|
|
534
|
+
[X],
|
|
540
535
|
e.client
|
|
541
536
|
)
|
|
542
537
|
]);
|
|
543
538
|
if (t.length === 0)
|
|
544
539
|
throw new Error("No existing obligations found for wallet address: " + e.address);
|
|
545
|
-
return new
|
|
540
|
+
return new G(e, t[0], a);
|
|
546
541
|
}
|
|
547
542
|
async getPool(e) {
|
|
548
|
-
var
|
|
549
|
-
const a =
|
|
543
|
+
var b, y;
|
|
544
|
+
const a = p(e), t = this.suilendClient.lendingMarket.reserves, n = /* @__PURE__ */ new Set();
|
|
550
545
|
t.forEach((d) => {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
}), d.borrowsPoolRewardManager.poolRewards.forEach((
|
|
554
|
-
|
|
546
|
+
n.add(p(d.coinType.name)), d.depositsPoolRewardManager.poolRewards.forEach((f) => {
|
|
547
|
+
f && n.add(p(f.coinType.name));
|
|
548
|
+
}), d.borrowsPoolRewardManager.poolRewards.forEach((f) => {
|
|
549
|
+
f && n.add(p(f.coinType.name));
|
|
555
550
|
});
|
|
556
551
|
});
|
|
557
|
-
const
|
|
558
|
-
(d,
|
|
552
|
+
const s = await Oe(Array.from(n)), i = t.map((d) => Re(d, s)).reduce(
|
|
553
|
+
(d, f) => (d[f.coinType] = f, d),
|
|
559
554
|
{}
|
|
560
555
|
), l = await this.suilendClient.getObligation(
|
|
561
556
|
this.obligationOwnerCap.obligationId
|
|
562
|
-
), u =
|
|
557
|
+
), u = Se(l, i), r = u.deposits.find((d) => d.coinType === a), w = u.borrows.find((d) => d.coinType === a), g = s[a].decimals;
|
|
563
558
|
return {
|
|
564
559
|
cTokenExchangeRate: i[a].cTokenExchangeRate.toNumber(),
|
|
565
|
-
supplyBalance: (
|
|
566
|
-
borrowBalance: (
|
|
560
|
+
supplyBalance: (b = r == null ? void 0 : r.depositedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? b : 0,
|
|
561
|
+
borrowBalance: (y = w == null ? void 0 : w.borrowedAmount.shiftedBy(g).decimalPlaces(0).toNumber()) != null ? y : 0,
|
|
567
562
|
borrowAPR: i[a].borrowAprPercent.toNumber()
|
|
568
563
|
};
|
|
569
564
|
}
|
|
570
|
-
async depositCoinPTB(e, a, t,
|
|
565
|
+
async depositCoinPTB(e, a, t, n) {
|
|
571
566
|
throw new Error("Not implemented");
|
|
572
567
|
}
|
|
573
568
|
async withdrawCoinPTB(e, a, t) {
|
|
574
|
-
const
|
|
569
|
+
const n = await this.getPool(a), s = t === n.supplyBalance;
|
|
575
570
|
return await this.suilendClient.withdraw(
|
|
576
571
|
this.obligationOwnerCap.id,
|
|
577
572
|
this.obligationOwnerCap.obligationId,
|
|
578
573
|
a,
|
|
579
|
-
|
|
574
|
+
s ? Ae.toString() : Math.ceil(t / n.cTokenExchangeRate).toString(),
|
|
580
575
|
e
|
|
581
576
|
);
|
|
582
577
|
}
|
|
583
578
|
async borrowCoinPTB(e, a, t) {
|
|
584
579
|
throw new Error("Not implemented");
|
|
585
580
|
}
|
|
586
|
-
async repayCoinPTB(e, a, t,
|
|
581
|
+
async repayCoinPTB(e, a, t, n) {
|
|
587
582
|
this.suilendClient.repay(this.obligationOwnerCap.obligationId, a, t, e), e.transferObjects([t], e.pure.address(this.walletClient.address));
|
|
588
583
|
}
|
|
589
584
|
}
|
|
590
|
-
class
|
|
585
|
+
class Fe extends O {
|
|
591
586
|
constructor() {
|
|
592
587
|
super(), this.name = "lending", this.defaultConfig = {
|
|
593
588
|
env: "prod",
|
|
594
|
-
protocols: []
|
|
595
|
-
|
|
596
|
-
}, this._protocols = [], this.migrateBetweenSupplyPTB = ne, this.migrateBetweenBorrowPTB = se, this.migrateBalanceToSupplyPTB = ie, this.migrateBetweenSupplyPTB = ne.bind(this), this.migrateBetweenBorrowPTB = se.bind(this), this.migrateBalanceToSupplyPTB = ie.bind(this);
|
|
589
|
+
protocols: []
|
|
590
|
+
}, this._protocols = [], this.migrateBetweenSupplyPTB = Y, this.migrateBetweenBorrowPTB = Z, this.migrateBalanceToSupplyPTB = ee, this.migrateBetweenSupplyPTB = Y.bind(this), this.migrateBetweenBorrowPTB = Z.bind(this), this.migrateBalanceToSupplyPTB = ee.bind(this);
|
|
597
591
|
}
|
|
598
592
|
/** Get protocols (either from internal storage or config) */
|
|
599
593
|
get protocols() {
|
|
@@ -609,7 +603,7 @@ class qe extends O {
|
|
|
609
603
|
* @returns Array of pool information
|
|
610
604
|
*/
|
|
611
605
|
async getPools(e) {
|
|
612
|
-
return await
|
|
606
|
+
return await me({
|
|
613
607
|
env: this.config.env,
|
|
614
608
|
...e
|
|
615
609
|
});
|
|
@@ -622,7 +616,7 @@ class qe extends O {
|
|
|
622
616
|
* @returns Pool information
|
|
623
617
|
*/
|
|
624
618
|
async getPool(e, a) {
|
|
625
|
-
return await
|
|
619
|
+
return await T(e, {
|
|
626
620
|
env: this.config.env,
|
|
627
621
|
...a
|
|
628
622
|
});
|
|
@@ -639,21 +633,21 @@ class qe extends O {
|
|
|
639
633
|
var u, r, w;
|
|
640
634
|
if (!this.walletClient)
|
|
641
635
|
throw new Error("Wallet client not found");
|
|
642
|
-
const
|
|
636
|
+
const n = await T(e, {
|
|
643
637
|
env: this.config.env
|
|
644
638
|
});
|
|
645
639
|
await this.walletClient.module("balance").waitForUpdate();
|
|
646
|
-
const
|
|
640
|
+
const s = new m(), c = this.walletClient.module("balance").portfolio.getBalance(n.suiCoinType), i = P(s, c.coins, {
|
|
647
641
|
balance: a,
|
|
648
642
|
useGasCoin: !0
|
|
649
643
|
});
|
|
650
|
-
await
|
|
644
|
+
await N(s, n, i, {
|
|
651
645
|
env: this.config.env,
|
|
652
646
|
amount: a,
|
|
653
647
|
accountCap: t == null ? void 0 : t.accountCap
|
|
654
648
|
});
|
|
655
649
|
const l = await this.walletClient.signExecuteTransaction({
|
|
656
|
-
transaction:
|
|
650
|
+
transaction: s,
|
|
657
651
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
658
652
|
});
|
|
659
653
|
return !(t != null && t.dryRun) && ((w = (r = l.effects) == null ? void 0 : r.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:deposit-success", {
|
|
@@ -673,17 +667,17 @@ class qe extends O {
|
|
|
673
667
|
var l, u, r;
|
|
674
668
|
if (!this.walletClient)
|
|
675
669
|
throw new Error("Wallet client not found");
|
|
676
|
-
const
|
|
670
|
+
const n = await T(e, {
|
|
677
671
|
env: this.config.env
|
|
678
|
-
}),
|
|
679
|
-
t != null && t.disableUpdateOracle || await this.updateOraclePTB(
|
|
680
|
-
const c = await
|
|
672
|
+
}), s = new m();
|
|
673
|
+
t != null && t.disableUpdateOracle || await this.updateOraclePTB(s, [n]);
|
|
674
|
+
const c = await le(s, n, a, {
|
|
681
675
|
env: this.config.env,
|
|
682
676
|
accountCap: t == null ? void 0 : t.accountCap
|
|
683
677
|
});
|
|
684
|
-
|
|
678
|
+
s.transferObjects([c], this.walletClient.address);
|
|
685
679
|
const i = await this.walletClient.signExecuteTransaction({
|
|
686
|
-
transaction:
|
|
680
|
+
transaction: s,
|
|
687
681
|
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
688
682
|
});
|
|
689
683
|
return !(t != null && t.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("lending:withdraw-success", {
|
|
@@ -703,17 +697,17 @@ class qe extends O {
|
|
|
703
697
|
var l, u, r;
|
|
704
698
|
if (!this.walletClient)
|
|
705
699
|
throw new Error("Wallet client not found");
|
|
706
|
-
const
|
|
700
|
+
const n = await T(e, {
|
|
707
701
|
env: this.config.env
|
|
708
|
-
}),
|
|
709
|
-
t != null && t.disableUpdateOracle || await this.updateOraclePTB(
|
|
710
|
-
const c = await
|
|
702
|
+
}), s = new m();
|
|
703
|
+
t != null && t.disableUpdateOracle || await this.updateOraclePTB(s, [n]);
|
|
704
|
+
const c = await ie(s, n, a, {
|
|
711
705
|
env: this.config.env,
|
|
712
706
|
accountCap: t == null ? void 0 : t.accountCap
|
|
713
707
|
});
|
|
714
|
-
|
|
708
|
+
s.transferObjects([c], this.walletClient.address);
|
|
715
709
|
const i = await this.walletClient.signExecuteTransaction({
|
|
716
|
-
transaction:
|
|
710
|
+
transaction: s,
|
|
717
711
|
dryRun: (l = t == null ? void 0 : t.dryRun) != null ? l : !1
|
|
718
712
|
});
|
|
719
713
|
return !(t != null && t.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("lending:borrow-success", {
|
|
@@ -734,19 +728,19 @@ class qe extends O {
|
|
|
734
728
|
if (!this.walletClient)
|
|
735
729
|
throw new Error("Wallet client not found");
|
|
736
730
|
await this.walletClient.module("balance").waitForUpdate();
|
|
737
|
-
const
|
|
731
|
+
const n = await T(e, {
|
|
738
732
|
env: this.config.env
|
|
739
|
-
}),
|
|
733
|
+
}), s = new m(), c = this.walletClient.module("balance").portfolio.getBalance(n.suiCoinType), i = P(s, c.coins, {
|
|
740
734
|
balance: a,
|
|
741
735
|
useGasCoin: !0
|
|
742
736
|
});
|
|
743
|
-
await
|
|
737
|
+
await re(s, n, i, {
|
|
744
738
|
env: this.config.env,
|
|
745
739
|
amount: a,
|
|
746
740
|
accountCap: t == null ? void 0 : t.accountCap
|
|
747
741
|
});
|
|
748
742
|
const l = await this.walletClient.signExecuteTransaction({
|
|
749
|
-
transaction:
|
|
743
|
+
transaction: s,
|
|
750
744
|
dryRun: (u = t == null ? void 0 : t.dryRun) != null ? u : !1
|
|
751
745
|
});
|
|
752
746
|
return !(t != null && t.dryRun) && ((w = (r = l.effects) == null ? void 0 : r.status) == null ? void 0 : w.status) === "success" && (this.emit("lending:repay-success", {
|
|
@@ -763,7 +757,7 @@ class qe extends O {
|
|
|
763
757
|
if (!this.walletClient)
|
|
764
758
|
throw new Error("Wallet client not found");
|
|
765
759
|
const e = this.walletClient.address;
|
|
766
|
-
return await
|
|
760
|
+
return await Ce(e, {
|
|
767
761
|
env: this.config.env,
|
|
768
762
|
client: this.walletClient.client
|
|
769
763
|
});
|
|
@@ -778,23 +772,23 @@ class qe extends O {
|
|
|
778
772
|
* @param options - Optional parameters including dry run mode
|
|
779
773
|
* @returns Transaction response or dry run response
|
|
780
774
|
*/
|
|
781
|
-
async liquidate(e, a, t,
|
|
782
|
-
var d,
|
|
775
|
+
async liquidate(e, a, t, n, s) {
|
|
776
|
+
var d, f, C;
|
|
783
777
|
if (!this.walletClient)
|
|
784
778
|
throw new Error("Wallet client not found");
|
|
785
|
-
const c = await
|
|
779
|
+
const c = await T(e, {
|
|
786
780
|
env: this.config.env
|
|
787
|
-
}), i = await
|
|
781
|
+
}), i = await T(t, {
|
|
788
782
|
env: this.config.env
|
|
789
783
|
}), l = new m(), u = this.walletClient.module("balance").portfolio.getBalance(c.suiCoinType), r = P(l, u.coins, {
|
|
790
784
|
balance: a,
|
|
791
785
|
useGasCoin: !0
|
|
792
|
-
}), [w,
|
|
786
|
+
}), [w, g] = await be(
|
|
793
787
|
l,
|
|
794
788
|
c,
|
|
795
789
|
r,
|
|
796
790
|
i,
|
|
797
|
-
|
|
791
|
+
n,
|
|
798
792
|
{
|
|
799
793
|
env: this.config.env
|
|
800
794
|
}
|
|
@@ -802,22 +796,22 @@ class qe extends O {
|
|
|
802
796
|
target: "0x2::coin::from_balance",
|
|
803
797
|
arguments: [w],
|
|
804
798
|
typeArguments: [i.suiCoinType]
|
|
805
|
-
}), [
|
|
799
|
+
}), [b] = l.moveCall({
|
|
806
800
|
target: "0x2::coin::from_balance",
|
|
807
|
-
arguments: [
|
|
801
|
+
arguments: [g],
|
|
808
802
|
typeArguments: [c.suiCoinType]
|
|
809
803
|
});
|
|
810
|
-
l.transferObjects([h,
|
|
811
|
-
const
|
|
804
|
+
l.transferObjects([h, b], this.walletClient.address);
|
|
805
|
+
const y = await this.walletClient.signExecuteTransaction({
|
|
812
806
|
transaction: l,
|
|
813
|
-
dryRun: (d =
|
|
807
|
+
dryRun: (d = s == null ? void 0 : s.dryRun) != null ? d : !1
|
|
814
808
|
});
|
|
815
|
-
return !(
|
|
809
|
+
return !(s != null && s.dryRun) && ((C = (f = y.effects) == null ? void 0 : f.status) == null ? void 0 : C.status) === "success" && (this.emit("lending:liquidate-success", {
|
|
816
810
|
payIdentifier: e,
|
|
817
811
|
payAmount: a,
|
|
818
812
|
collateralIdentifier: t,
|
|
819
|
-
liquidationAddress:
|
|
820
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
813
|
+
liquidationAddress: n
|
|
814
|
+
}), this.walletClient.module("balance").updatePortfolio()), y;
|
|
821
815
|
}
|
|
822
816
|
/**
|
|
823
817
|
* Gets the available lending rewards for the current user.
|
|
@@ -829,7 +823,7 @@ class qe extends O {
|
|
|
829
823
|
async getAvailableRewards(e) {
|
|
830
824
|
if (!this.walletClient)
|
|
831
825
|
throw new Error("Wallet client not found");
|
|
832
|
-
return
|
|
826
|
+
return J(this.walletClient.address, {
|
|
833
827
|
...e,
|
|
834
828
|
env: this.config.env
|
|
835
829
|
});
|
|
@@ -844,7 +838,7 @@ class qe extends O {
|
|
|
844
838
|
async getClaimedRewardHistory(e) {
|
|
845
839
|
if (!this.walletClient)
|
|
846
840
|
throw new Error("Wallet client not found");
|
|
847
|
-
return
|
|
841
|
+
return ye(this.walletClient.address, {
|
|
848
842
|
...e
|
|
849
843
|
});
|
|
850
844
|
}
|
|
@@ -855,34 +849,34 @@ class qe extends O {
|
|
|
855
849
|
* @returns Transaction response or dry run response
|
|
856
850
|
*/
|
|
857
851
|
async claimAllRewards(e) {
|
|
858
|
-
var
|
|
852
|
+
var s, c, i;
|
|
859
853
|
if (!this.walletClient)
|
|
860
854
|
throw new Error("Wallet client not found");
|
|
861
|
-
const a = new m(), t = await
|
|
855
|
+
const a = new m(), t = await J(this.walletClient.address, {
|
|
862
856
|
env: this.config.env
|
|
863
857
|
});
|
|
864
|
-
await
|
|
858
|
+
await pe(a, t, {
|
|
865
859
|
env: this.config.env,
|
|
866
860
|
accountCap: e == null ? void 0 : e.accountCap
|
|
867
861
|
});
|
|
868
|
-
const
|
|
862
|
+
const n = await this.walletClient.signExecuteTransaction({
|
|
869
863
|
transaction: a,
|
|
870
|
-
dryRun: (
|
|
864
|
+
dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
|
|
871
865
|
});
|
|
872
|
-
return !(e != null && e.dryRun) && ((i = (c =
|
|
866
|
+
return !(e != null && e.dryRun) && ((i = (c = n.effects) == null ? void 0 : c.status) == null ? void 0 : i.status) === "success" && (this.emit("lending:claim-rewards-success", {
|
|
873
867
|
rewards: t
|
|
874
|
-
}), this.walletClient.module("balance").updatePortfolio()),
|
|
868
|
+
}), this.walletClient.module("balance").updatePortfolio()), n;
|
|
875
869
|
}
|
|
876
870
|
async updateOraclePTB(e, a) {
|
|
877
|
-
const t = await
|
|
871
|
+
const t = await Q({
|
|
878
872
|
env: this.config.env
|
|
879
|
-
}),
|
|
873
|
+
}), n = await this.getLendingState({
|
|
880
874
|
cacheTime: 60 * 1e3
|
|
881
|
-
}),
|
|
882
|
-
lendingState:
|
|
875
|
+
}), s = $(t, {
|
|
876
|
+
lendingState: n,
|
|
883
877
|
pools: a
|
|
884
878
|
});
|
|
885
|
-
await
|
|
879
|
+
await K(e, s, {
|
|
886
880
|
env: this.config.env,
|
|
887
881
|
updatePythPriceFeeds: !0
|
|
888
882
|
});
|
|
@@ -895,13 +889,13 @@ class qe extends O {
|
|
|
895
889
|
* @returns Transaction response or dry run response
|
|
896
890
|
*/
|
|
897
891
|
async updateOracle(e) {
|
|
898
|
-
var
|
|
892
|
+
var n;
|
|
899
893
|
if (!this.walletClient)
|
|
900
894
|
throw new Error("Wallet client not found");
|
|
901
895
|
const a = new m();
|
|
902
896
|
return await this.updateOraclePTB(a, e == null ? void 0 : e.pools), await this.walletClient.signExecuteTransaction({
|
|
903
897
|
transaction: a,
|
|
904
|
-
dryRun: (
|
|
898
|
+
dryRun: (n = e == null ? void 0 : e.dryRun) != null ? n : !1
|
|
905
899
|
});
|
|
906
900
|
}
|
|
907
901
|
/**
|
|
@@ -913,7 +907,7 @@ class qe extends O {
|
|
|
913
907
|
async getLendingState(e) {
|
|
914
908
|
if (!this.walletClient)
|
|
915
909
|
throw new Error("Wallet client not found");
|
|
916
|
-
return await
|
|
910
|
+
return await Pe(this.walletClient.address, {
|
|
917
911
|
env: this.config.env,
|
|
918
912
|
...e,
|
|
919
913
|
client: this.walletClient.client
|
|
@@ -926,13 +920,13 @@ class qe extends O {
|
|
|
926
920
|
* @returns Transaction response or dry run response
|
|
927
921
|
*/
|
|
928
922
|
async createAccountCap(e) {
|
|
929
|
-
var
|
|
923
|
+
var s;
|
|
930
924
|
if (!this.walletClient)
|
|
931
925
|
throw new Error("Wallet client not found");
|
|
932
|
-
const a = new m(), t = await
|
|
926
|
+
const a = new m(), t = await Be(a);
|
|
933
927
|
return a.transferObjects([t], this.walletClient.address), await this.walletClient.signExecuteTransaction({
|
|
934
928
|
transaction: a,
|
|
935
|
-
dryRun: (
|
|
929
|
+
dryRun: (s = e == null ? void 0 : e.dryRun) != null ? s : !1
|
|
936
930
|
});
|
|
937
931
|
}
|
|
938
932
|
async initializeProtocols() {
|
|
@@ -941,24 +935,24 @@ class qe extends O {
|
|
|
941
935
|
return;
|
|
942
936
|
}
|
|
943
937
|
const e = [];
|
|
944
|
-
e.push(new
|
|
938
|
+
e.push(new _e(this.walletClient));
|
|
945
939
|
try {
|
|
946
|
-
e.push(await
|
|
940
|
+
e.push(await G.create(this.walletClient));
|
|
947
941
|
} catch (a) {
|
|
948
942
|
console.warn("Failed to initialize SuilendProtocol:", a);
|
|
949
943
|
}
|
|
950
944
|
this._protocols = e;
|
|
951
945
|
}
|
|
952
946
|
}
|
|
953
|
-
class
|
|
947
|
+
class je extends O {
|
|
954
948
|
constructor() {
|
|
955
949
|
super(...arguments), this.name = "volo", this.defaultConfig = {
|
|
956
950
|
packageId: "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20",
|
|
957
951
|
poolId: "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5",
|
|
958
952
|
metadataId: "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",
|
|
959
953
|
coinType: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"
|
|
960
|
-
}, this.getStats =
|
|
961
|
-
|
|
954
|
+
}, this.getStats = oe(
|
|
955
|
+
L(async () => (await fetch("https://open-api.naviprotocol.io/api/volo/stats").then((a) => a.json())).data)
|
|
962
956
|
);
|
|
963
957
|
}
|
|
964
958
|
/**
|
|
@@ -975,7 +969,7 @@ class Ke extends O {
|
|
|
975
969
|
e.object(this.config.poolId),
|
|
976
970
|
e.object(this.config.metadataId),
|
|
977
971
|
e.object("0x05"),
|
|
978
|
-
|
|
972
|
+
_(a, e.object)
|
|
979
973
|
],
|
|
980
974
|
typeArguments: []
|
|
981
975
|
});
|
|
@@ -995,7 +989,7 @@ class Ke extends O {
|
|
|
995
989
|
e.object(this.config.poolId),
|
|
996
990
|
e.object(this.config.metadataId),
|
|
997
991
|
e.object("0x05"),
|
|
998
|
-
|
|
992
|
+
_(a, e.object)
|
|
999
993
|
],
|
|
1000
994
|
typeArguments: []
|
|
1001
995
|
});
|
|
@@ -1017,10 +1011,10 @@ class Ke extends O {
|
|
|
1017
1011
|
throw new Error("Stake amount should be greater than 1Sui");
|
|
1018
1012
|
const t = new m();
|
|
1019
1013
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1020
|
-
const
|
|
1014
|
+
const n = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), s = P(t, n.coins, {
|
|
1021
1015
|
balance: e,
|
|
1022
1016
|
useGasCoin: !0
|
|
1023
|
-
}), c = await this.stakePTB(t,
|
|
1017
|
+
}), c = await this.stakePTB(t, s);
|
|
1024
1018
|
t.transferObjects([c], this.walletClient.address);
|
|
1025
1019
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1026
1020
|
transaction: t,
|
|
@@ -1045,9 +1039,9 @@ class Ke extends O {
|
|
|
1045
1039
|
if (e < 1e9)
|
|
1046
1040
|
throw new Error("Unstake amount should >= 1vSui");
|
|
1047
1041
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1048
|
-
const t = new m(),
|
|
1042
|
+
const t = new m(), n = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), s = P(t, n.coins, {
|
|
1049
1043
|
balance: e
|
|
1050
|
-
}), c = await this.unstakePTB(t,
|
|
1044
|
+
}), c = await this.unstakePTB(t, s);
|
|
1051
1045
|
t.transferObjects([c], this.walletClient.address);
|
|
1052
1046
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1053
1047
|
transaction: t,
|
|
@@ -1058,7 +1052,7 @@ class Ke extends O {
|
|
|
1058
1052
|
}), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1059
1053
|
}
|
|
1060
1054
|
}
|
|
1061
|
-
class
|
|
1055
|
+
class Ie extends O {
|
|
1062
1056
|
constructor() {
|
|
1063
1057
|
super(...arguments), this.name = "swap", this.defaultConfig = {
|
|
1064
1058
|
apiKey: "",
|
|
@@ -1075,7 +1069,7 @@ class Qe extends O {
|
|
|
1075
1069
|
* @returns Referral ID if API key is configured, otherwise 0
|
|
1076
1070
|
*/
|
|
1077
1071
|
get referral() {
|
|
1078
|
-
return this.config.apiKey ?
|
|
1072
|
+
return this.config.apiKey ? Te(this.config.apiKey) : 0;
|
|
1079
1073
|
}
|
|
1080
1074
|
/**
|
|
1081
1075
|
* Get the swap options
|
|
@@ -1097,7 +1091,7 @@ class Qe extends O {
|
|
|
1097
1091
|
* @returns A promise that resolves with the quote
|
|
1098
1092
|
*/
|
|
1099
1093
|
async getQuote(e, a, t) {
|
|
1100
|
-
return
|
|
1094
|
+
return ve(e, a, t, this.config.apiKey, this.swapOptions);
|
|
1101
1095
|
}
|
|
1102
1096
|
/**
|
|
1103
1097
|
* Builds a swap transaction from a quote
|
|
@@ -1107,14 +1101,14 @@ class Qe extends O {
|
|
|
1107
1101
|
* @param slippage - The slippage tolerance
|
|
1108
1102
|
* @returns The swap transaction
|
|
1109
1103
|
*/
|
|
1110
|
-
async buildSwapPTBFromQuote(e, a, t,
|
|
1104
|
+
async buildSwapPTBFromQuote(e, a, t, n) {
|
|
1111
1105
|
if (!this.walletClient)
|
|
1112
1106
|
throw new Error("Wallet client not found");
|
|
1113
|
-
const
|
|
1114
|
-
return await
|
|
1107
|
+
const s = new R(a.amount_out).multipliedBy(1 - n).toFixed(0);
|
|
1108
|
+
return await q(
|
|
1115
1109
|
this.walletClient.address,
|
|
1116
1110
|
e,
|
|
1117
|
-
Number(
|
|
1111
|
+
Number(s),
|
|
1118
1112
|
t,
|
|
1119
1113
|
a,
|
|
1120
1114
|
this.referral,
|
|
@@ -1140,30 +1134,30 @@ class Qe extends O {
|
|
|
1140
1134
|
* @param options - Optional parameters including dry run mode
|
|
1141
1135
|
* @returns Transaction response or dry run response
|
|
1142
1136
|
*/
|
|
1143
|
-
async swap(e, a, t,
|
|
1144
|
-
var
|
|
1137
|
+
async swap(e, a, t, n, s) {
|
|
1138
|
+
var y, d, f;
|
|
1145
1139
|
if (!this.walletClient)
|
|
1146
1140
|
throw new Error("Wallet client not found");
|
|
1147
1141
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1148
1142
|
const c = this.walletClient.module("balance").portfolio.getBalance(e), i = new m(), l = P(i, c.coins, {
|
|
1149
1143
|
balance: t,
|
|
1150
1144
|
useGasCoin: !0
|
|
1151
|
-
}), u = await this.getQuote(e, a, t), r = await this.buildSwapPTBFromQuote(i, u, l,
|
|
1152
|
-
if (i.transferObjects([r], this.walletClient.address), i.setSender(this.walletClient.address),
|
|
1145
|
+
}), u = await this.getQuote(e, a, t), r = await this.buildSwapPTBFromQuote(i, u, l, n);
|
|
1146
|
+
if (i.transferObjects([r], this.walletClient.address), i.setSender(this.walletClient.address), s != null && s.dryRun)
|
|
1153
1147
|
return await this.walletClient.signExecuteTransaction({
|
|
1154
1148
|
transaction: i,
|
|
1155
1149
|
dryRun: !0
|
|
1156
1150
|
});
|
|
1157
1151
|
const w = await i.build({
|
|
1158
1152
|
client: this.walletClient.client
|
|
1159
|
-
}),
|
|
1153
|
+
}), g = await this.walletClient.signer.signTransaction(w), h = [g.signature];
|
|
1160
1154
|
try {
|
|
1161
|
-
await
|
|
1162
|
-
} catch (
|
|
1163
|
-
console.error(
|
|
1155
|
+
await xe(g.bytes, h);
|
|
1156
|
+
} catch (C) {
|
|
1157
|
+
console.error(C);
|
|
1164
1158
|
}
|
|
1165
|
-
const
|
|
1166
|
-
transactionBlock:
|
|
1159
|
+
const b = await this.walletClient.client.executeTransactionBlock({
|
|
1160
|
+
transactionBlock: g.bytes,
|
|
1167
1161
|
signature: h,
|
|
1168
1162
|
options: {
|
|
1169
1163
|
showEffects: !0,
|
|
@@ -1171,27 +1165,27 @@ class Qe extends O {
|
|
|
1171
1165
|
showBalanceChanges: !0
|
|
1172
1166
|
}
|
|
1173
1167
|
});
|
|
1174
|
-
if (((d = (
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1168
|
+
if (((d = (y = b.effects) == null ? void 0 : y.status) == null ? void 0 : d.status) === "success") {
|
|
1169
|
+
const C = (f = b.events) == null ? void 0 : f.find((B) => B.type.includes("::slippage::SwapEvent"));
|
|
1170
|
+
C && this.emit("swap:swap-success", {
|
|
1177
1171
|
fromCoinType: e,
|
|
1178
1172
|
toCoinType: a,
|
|
1179
1173
|
fromAmount: t,
|
|
1180
|
-
slippage:
|
|
1181
|
-
toAmount: Number(
|
|
1174
|
+
slippage: n,
|
|
1175
|
+
toAmount: Number(C.parsedJson.amount_out)
|
|
1182
1176
|
}), this.walletClient.module("balance").updatePortfolio();
|
|
1183
1177
|
}
|
|
1184
|
-
return
|
|
1178
|
+
return b;
|
|
1185
1179
|
}
|
|
1186
1180
|
}
|
|
1187
|
-
class
|
|
1181
|
+
class Ue extends O {
|
|
1188
1182
|
constructor() {
|
|
1189
1183
|
super(...arguments), this.name = "haedal", this.defaultConfig = {
|
|
1190
1184
|
packageId: "0x3f45767c1aa95b25422f675800f02d8a813ec793a00b60667d071a77ba7178a2",
|
|
1191
1185
|
configId: "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",
|
|
1192
1186
|
coinType: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
|
|
1193
|
-
}, this.getApy =
|
|
1194
|
-
|
|
1187
|
+
}, this.getApy = oe(
|
|
1188
|
+
L(async () => (await fetch("https://open-api.naviprotocol.io/api/haedal/stats").then((a) => a.json())).data.apy)
|
|
1195
1189
|
);
|
|
1196
1190
|
}
|
|
1197
1191
|
/**
|
|
@@ -1207,7 +1201,7 @@ class Ge extends O {
|
|
|
1207
1201
|
arguments: [
|
|
1208
1202
|
e.object("0x05"),
|
|
1209
1203
|
e.object(this.config.configId),
|
|
1210
|
-
|
|
1204
|
+
_(a, e.object),
|
|
1211
1205
|
e.pure.address("0x0000000000000000000000000000000000000000000000000000000000000000")
|
|
1212
1206
|
],
|
|
1213
1207
|
typeArguments: []
|
|
@@ -1227,7 +1221,7 @@ class Ge extends O {
|
|
|
1227
1221
|
arguments: [
|
|
1228
1222
|
e.object("0x05"),
|
|
1229
1223
|
e.object(this.config.configId),
|
|
1230
|
-
|
|
1224
|
+
_(a, e.object)
|
|
1231
1225
|
],
|
|
1232
1226
|
typeArguments: []
|
|
1233
1227
|
});
|
|
@@ -1245,10 +1239,10 @@ class Ge extends O {
|
|
|
1245
1239
|
throw new Error("Wallet client not found");
|
|
1246
1240
|
const t = new m();
|
|
1247
1241
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1248
|
-
const
|
|
1242
|
+
const n = this.walletClient.module("balance").portfolio.getBalance("0x2::sui::SUI"), s = P(t, n.coins, {
|
|
1249
1243
|
balance: e,
|
|
1250
1244
|
useGasCoin: !0
|
|
1251
|
-
}), c = await this.stakePTB(t,
|
|
1245
|
+
}), c = await this.stakePTB(t, s);
|
|
1252
1246
|
t.transferObjects([c], this.walletClient.address);
|
|
1253
1247
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1254
1248
|
transaction: t,
|
|
@@ -1267,9 +1261,9 @@ class Ge extends O {
|
|
|
1267
1261
|
if (!this.walletClient)
|
|
1268
1262
|
throw new Error("Wallet client not found");
|
|
1269
1263
|
await this.walletClient.module("balance").waitForUpdate();
|
|
1270
|
-
const t = new m(),
|
|
1264
|
+
const t = new m(), n = this.walletClient.module("balance").portfolio.getBalance(this.config.coinType), s = P(t, n.coins, {
|
|
1271
1265
|
balance: e
|
|
1272
|
-
}), c = await this.unstakePTB(t,
|
|
1266
|
+
}), c = await this.unstakePTB(t, s);
|
|
1273
1267
|
t.transferObjects([c], this.walletClient.address);
|
|
1274
1268
|
const i = await this.walletClient.signExecuteTransaction({
|
|
1275
1269
|
transaction: t,
|
|
@@ -1278,35 +1272,35 @@ class Ge extends O {
|
|
|
1278
1272
|
return !(a != null && a.dryRun) && ((r = (u = i.effects) == null ? void 0 : u.status) == null ? void 0 : r.status) === "success" && (this.emit("haedal:unstake-success", { haSUIAmount: e }), this.walletClient.module("balance").updatePortfolio()), i;
|
|
1279
1273
|
}
|
|
1280
1274
|
}
|
|
1281
|
-
const
|
|
1275
|
+
const Me = {
|
|
1282
1276
|
/** Balance management module */
|
|
1283
|
-
balance: new
|
|
1277
|
+
balance: new Ne(),
|
|
1284
1278
|
/** Lending protocol module */
|
|
1285
|
-
lending: new
|
|
1279
|
+
lending: new Fe(),
|
|
1286
1280
|
/** Volo protocol module */
|
|
1287
|
-
volo: new
|
|
1281
|
+
volo: new je(),
|
|
1288
1282
|
/** DEX swapping module */
|
|
1289
|
-
swap: new
|
|
1283
|
+
swap: new Ie(),
|
|
1290
1284
|
/** Haedal protocol module */
|
|
1291
|
-
haedal: new
|
|
1292
|
-
},
|
|
1293
|
-
url:
|
|
1285
|
+
haedal: new Ue()
|
|
1286
|
+
}, We = {
|
|
1287
|
+
url: we("mainnet")
|
|
1294
1288
|
};
|
|
1295
|
-
class
|
|
1289
|
+
class Ye {
|
|
1296
1290
|
/**
|
|
1297
1291
|
* Creates a new wallet client instance
|
|
1298
1292
|
* @param options - Configuration options for the wallet client
|
|
1299
1293
|
*/
|
|
1300
1294
|
constructor(e) {
|
|
1301
|
-
this.modules =
|
|
1295
|
+
this.modules = Me, this.userConfigs = {}, this.events = fe();
|
|
1302
1296
|
const a = {
|
|
1303
|
-
...
|
|
1297
|
+
...We,
|
|
1304
1298
|
...e.client
|
|
1305
1299
|
};
|
|
1306
|
-
a.transport = a.transport || new
|
|
1307
|
-
if (t !==
|
|
1308
|
-
throw new Error(`Module name ${t} does not match module name ${
|
|
1309
|
-
|
|
1300
|
+
a.transport = a.transport || new ke(a.url), this.client = new he(a), this.signer = e.signer, this.userConfigs = e.configs || {}, Object.entries(this.modules).forEach(([t, n]) => {
|
|
1301
|
+
if (t !== n.name)
|
|
1302
|
+
throw new Error(`Module name ${t} does not match module name ${n.name}`);
|
|
1303
|
+
n.install(this);
|
|
1310
1304
|
});
|
|
1311
1305
|
}
|
|
1312
1306
|
get lending() {
|
|
@@ -1332,11 +1326,11 @@ class lt {
|
|
|
1332
1326
|
async signExecuteTransaction(e) {
|
|
1333
1327
|
const { dryRun: a = !1, ...t } = e;
|
|
1334
1328
|
if (a) {
|
|
1335
|
-
let
|
|
1336
|
-
return e.transaction instanceof m ? (e.transaction.setSenderIfNotSet(this.address),
|
|
1329
|
+
let n;
|
|
1330
|
+
return e.transaction instanceof m ? (e.transaction.setSenderIfNotSet(this.address), n = await e.transaction.build({
|
|
1337
1331
|
client: this.client
|
|
1338
|
-
})) :
|
|
1339
|
-
transactionBlock:
|
|
1332
|
+
})) : n = e.transaction, this.client.dryRunTransactionBlock({
|
|
1333
|
+
transactionBlock: n
|
|
1340
1334
|
});
|
|
1341
1335
|
}
|
|
1342
1336
|
return this.client.signAndExecuteTransaction({
|
|
@@ -1379,7 +1373,7 @@ class lt {
|
|
|
1379
1373
|
return e in this.modules;
|
|
1380
1374
|
}
|
|
1381
1375
|
}
|
|
1382
|
-
class
|
|
1376
|
+
class Ze extends ce {
|
|
1383
1377
|
/**
|
|
1384
1378
|
* Creates a new watch-only signer
|
|
1385
1379
|
*
|
|
@@ -1443,7 +1437,7 @@ class rt extends fe {
|
|
|
1443
1437
|
return {};
|
|
1444
1438
|
}
|
|
1445
1439
|
}
|
|
1446
|
-
class
|
|
1440
|
+
class et extends ce {
|
|
1447
1441
|
/**
|
|
1448
1442
|
* Creates a new watch-only signer
|
|
1449
1443
|
*
|
|
@@ -1496,8 +1490,8 @@ class ot extends fe {
|
|
|
1496
1490
|
}
|
|
1497
1491
|
}
|
|
1498
1492
|
export {
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1493
|
+
Ye as WalletClient,
|
|
1494
|
+
Ze as WatchSigner,
|
|
1495
|
+
et as WebSigner
|
|
1502
1496
|
};
|
|
1503
1497
|
//# sourceMappingURL=index.esm.js.map
|