@naviprotocol/lending 2.0.3 → 2.0.5-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts +10 -10
- package/dist/account.d.ts.map +1 -1
- package/dist/index.esm.js +448 -413
- package/dist/index.esm.js.map +1 -1
- package/dist/pyth.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Transaction as
|
|
1
|
+
import { Transaction as q } from "@mysten/sui/transactions";
|
|
2
2
|
import { bcs as l } from "@mysten/sui/bcs";
|
|
3
|
-
import { toHex as Me, fromHex as Ue, normalizeStructTag as
|
|
3
|
+
import { toHex as Me, fromHex as Ue, normalizeStructTag as Y, SUI_CLOCK_OBJECT_ID as x, fromBase64 as De } from "@mysten/sui/utils";
|
|
4
4
|
import Fe from "lodash.camelcase";
|
|
5
5
|
import p from "bignumber.js";
|
|
6
6
|
import { SuiJsonRpcClient as Ne } from "@mysten/sui/jsonRpc";
|
|
7
7
|
import { SuiGraphQLClient as Re } from "@mysten/sui/graphql";
|
|
8
|
-
import { SuiGrpcClient as
|
|
9
|
-
const
|
|
8
|
+
import { SuiGrpcClient as he, GrpcWebFetchTransport as we } from "@mysten/sui/grpc";
|
|
9
|
+
const ie = l.bytes(32).transform({
|
|
10
10
|
// To change the input type, you need to provide a type definition for the input
|
|
11
11
|
input: (e) => Ue(e),
|
|
12
12
|
output: (e) => Me(e)
|
|
@@ -19,9 +19,9 @@ const oe = l.bytes(32).transform({
|
|
|
19
19
|
coin_types: l.vector(l.string())
|
|
20
20
|
}), Le = l.struct("IncentivePoolInfo", {
|
|
21
21
|
/** Unique pool identifier */
|
|
22
|
-
pool_id:
|
|
22
|
+
pool_id: ie,
|
|
23
23
|
/** Address holding the incentive funds */
|
|
24
|
-
funds:
|
|
24
|
+
funds: ie,
|
|
25
25
|
/** Current phase of the incentive program */
|
|
26
26
|
phase: l.u64(),
|
|
27
27
|
/** Timestamp when the incentive started */
|
|
@@ -129,9 +129,9 @@ const oe = l.bytes(32).transform({
|
|
|
129
129
|
borrow_balance: l.u256(),
|
|
130
130
|
/** User's current supply balance */
|
|
131
131
|
supply_balance: l.u256()
|
|
132
|
-
}), Ge = "2.0.
|
|
132
|
+
}), Ge = "2.0.5-beta.0", V = {
|
|
133
133
|
version: Ge
|
|
134
|
-
}, We =
|
|
134
|
+
}, We = V.version, He = () => {
|
|
135
135
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
136
136
|
const e = process.version;
|
|
137
137
|
return `Node.js ${e.startsWith("v") ? e.substring(1) : e}`;
|
|
@@ -140,7 +140,7 @@ const oe = l.bytes(32).transform({
|
|
|
140
140
|
}, Je = () => {
|
|
141
141
|
let e = "";
|
|
142
142
|
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${We} (${He()})`), e;
|
|
143
|
-
},
|
|
143
|
+
}, ce = Je(), be = "0x2::sui::SUI";
|
|
144
144
|
class Ke extends Error {
|
|
145
145
|
constructor(t) {
|
|
146
146
|
super(
|
|
@@ -148,7 +148,7 @@ class Ke extends Error {
|
|
|
148
148
|
), this.name = "NaviMissingGraphQLClientError";
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function ee(e) {
|
|
152
152
|
return e == null ? void 0 : String(e);
|
|
153
153
|
}
|
|
154
154
|
function Qe(e, t) {
|
|
@@ -157,48 +157,48 @@ function Qe(e, t) {
|
|
|
157
157
|
function Ye(e, t) {
|
|
158
158
|
return (BigInt(e) - BigInt(t)).toString();
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function ve(e) {
|
|
161
161
|
const t = e.core;
|
|
162
162
|
if (typeof t?.getBalance != "function" || typeof t?.listBalances != "function")
|
|
163
163
|
throw new Error("NAVI Sui balance helpers require a v2 Core API client");
|
|
164
164
|
return t;
|
|
165
165
|
}
|
|
166
|
-
function
|
|
167
|
-
const r =
|
|
168
|
-
let o =
|
|
166
|
+
function Ce(e, t = be) {
|
|
167
|
+
const r = ee(e.addressBalance ?? e.fundsInAddressBalance) ?? "0";
|
|
168
|
+
let o = ee(e.balance ?? e.totalBalance), n = ee(e.coinBalance);
|
|
169
169
|
return !n && o && (n = Ye(o, r)), !o && n && (o = Qe(n, r)), {
|
|
170
|
-
coinType:
|
|
170
|
+
coinType: Y(e.coinType ?? t),
|
|
171
171
|
totalBalance: o ?? "0",
|
|
172
172
|
coinBalance: n ?? "0",
|
|
173
173
|
addressBalance: r,
|
|
174
174
|
...e.coinObjectCount === null || e.coinObjectCount === void 0 ? {} : { coinObjectCount: e.coinObjectCount }
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
function Ht(e, t =
|
|
178
|
-
const r =
|
|
179
|
-
return e.filter((o) =>
|
|
177
|
+
function Ht(e, t = be) {
|
|
178
|
+
const r = Y(t);
|
|
179
|
+
return e.filter((o) => Y(o.coinType) === r).reduce((o, n) => o + BigInt(n.balance), 0n).toString();
|
|
180
180
|
}
|
|
181
181
|
async function Jt(e, t) {
|
|
182
|
-
const r = await
|
|
183
|
-
return
|
|
182
|
+
const r = await ve(e).getBalance(t), o = r.balance;
|
|
183
|
+
return Ce((o && typeof o == "object" ? o : r) ?? {}, t.coinType);
|
|
184
184
|
}
|
|
185
185
|
async function Kt(e, t) {
|
|
186
|
-
const r = await
|
|
186
|
+
const r = await ve(e).listBalances(t), { balances: o = [] } = r;
|
|
187
187
|
return {
|
|
188
|
-
balances: o.map((n) =>
|
|
188
|
+
balances: o.map((n) => Ce(n)),
|
|
189
189
|
nextCursor: r.nextCursor ?? r.cursor ?? null
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
192
|
function Ze(e, t) {
|
|
193
193
|
if ("client" in t)
|
|
194
194
|
return t.client;
|
|
195
|
-
const r = new
|
|
195
|
+
const r = new we({
|
|
196
196
|
baseUrl: t.url,
|
|
197
197
|
meta: t.headers,
|
|
198
198
|
fetchInit: t.fetchInit,
|
|
199
199
|
fetch: t.fetch
|
|
200
200
|
});
|
|
201
|
-
return new
|
|
201
|
+
return new he({
|
|
202
202
|
network: e,
|
|
203
203
|
transport: r
|
|
204
204
|
});
|
|
@@ -211,7 +211,7 @@ function Xe(e, t) {
|
|
|
211
211
|
fetch: t.fetch
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
|
-
function
|
|
214
|
+
function je(e, t) {
|
|
215
215
|
return "client" in t ? t.client : new Ne({
|
|
216
216
|
network: e,
|
|
217
217
|
url: t.url
|
|
@@ -224,7 +224,7 @@ function xe(e) {
|
|
|
224
224
|
coreClient: t,
|
|
225
225
|
grpc: t,
|
|
226
226
|
graphql: e.graphql ? Xe(e.network, e.graphql) : void 0,
|
|
227
|
-
legacyJsonRpc: e.legacyJsonRpc ?
|
|
227
|
+
legacyJsonRpc: e.legacyJsonRpc ? je(e.network, e.legacyJsonRpc) : void 0,
|
|
228
228
|
services: e.services
|
|
229
229
|
};
|
|
230
230
|
}
|
|
@@ -234,22 +234,22 @@ function Qt(e, t) {
|
|
|
234
234
|
return e.graphql;
|
|
235
235
|
}
|
|
236
236
|
const et = "https://fullnode.mainnet.sui.io:443";
|
|
237
|
-
let
|
|
237
|
+
let te;
|
|
238
238
|
function tt() {
|
|
239
|
-
return
|
|
239
|
+
return te || (te = new he({
|
|
240
240
|
network: "mainnet",
|
|
241
|
-
transport: new
|
|
242
|
-
})),
|
|
241
|
+
transport: new we({ baseUrl: et })
|
|
242
|
+
})), te;
|
|
243
243
|
}
|
|
244
244
|
function rt(e, t = "mainnet") {
|
|
245
|
-
return e ? typeof e == "string" ?
|
|
245
|
+
return e ? typeof e == "string" ? je(t, { url: e }) : xe(e) : tt();
|
|
246
246
|
}
|
|
247
247
|
const nt = 16 * 1024;
|
|
248
|
-
function
|
|
248
|
+
function oe(e) {
|
|
249
249
|
return e.replace(/^0x/i, "");
|
|
250
250
|
}
|
|
251
|
-
function
|
|
252
|
-
const t =
|
|
251
|
+
function se(e) {
|
|
252
|
+
const t = oe(e), r = new Uint8Array(t.length / 2);
|
|
253
253
|
for (let o = 0; o < r.length; o += 1)
|
|
254
254
|
r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
|
|
255
255
|
return r;
|
|
@@ -257,12 +257,12 @@ function ie(e) {
|
|
|
257
257
|
function ot(e, t) {
|
|
258
258
|
return (e[t] << 8) + e[t + 1];
|
|
259
259
|
}
|
|
260
|
-
function
|
|
260
|
+
function ue(e) {
|
|
261
261
|
return l.vector(l.U8).serialize(Array.from(e), {
|
|
262
262
|
maxSize: nt
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function le(e, t) {
|
|
266
266
|
return {
|
|
267
267
|
type: e,
|
|
268
268
|
bcs: t
|
|
@@ -299,7 +299,7 @@ function st(e) {
|
|
|
299
299
|
function ut(e) {
|
|
300
300
|
return Uint8Array.from(atob(e), (t) => t.charCodeAt(0));
|
|
301
301
|
}
|
|
302
|
-
class
|
|
302
|
+
class Ie {
|
|
303
303
|
constructor(t, r) {
|
|
304
304
|
this.endpoint = t.replace(/\/$/, ""), this.timeout = r?.timeout ?? 1e4;
|
|
305
305
|
}
|
|
@@ -334,7 +334,7 @@ class Ce {
|
|
|
334
334
|
for (const [i, s] of Object.entries(o ?? {}))
|
|
335
335
|
c.searchParams.set(i, s);
|
|
336
336
|
for (const i of r)
|
|
337
|
-
c.searchParams.append("ids[]",
|
|
337
|
+
c.searchParams.append("ids[]", oe(i));
|
|
338
338
|
try {
|
|
339
339
|
const i = await fetch(c, {
|
|
340
340
|
signal: n.signal
|
|
@@ -353,7 +353,7 @@ class lt {
|
|
|
353
353
|
}
|
|
354
354
|
getCoreProvider() {
|
|
355
355
|
const t = this.provider.core;
|
|
356
|
-
return t && typeof t.getObject == "function" && typeof t.getDynamicObjectField == "function" ? t : null;
|
|
356
|
+
return t && typeof t.getObject == "function" && typeof t.getDynamicObjectField == "function" && typeof t.getDynamicField == "function" ? t : null;
|
|
357
357
|
}
|
|
358
358
|
async getMoveObjectJson(t) {
|
|
359
359
|
const r = this.getCoreProvider();
|
|
@@ -445,8 +445,8 @@ class lt {
|
|
|
445
445
|
target: `${o}::vaa::parse_and_verify`,
|
|
446
446
|
arguments: [
|
|
447
447
|
r.object(this.wormholeStateId),
|
|
448
|
-
r.pure(
|
|
449
|
-
r.object(
|
|
448
|
+
r.pure(ue(n)),
|
|
449
|
+
r.object(x)
|
|
450
450
|
]
|
|
451
451
|
});
|
|
452
452
|
return a;
|
|
@@ -461,9 +461,9 @@ class lt {
|
|
|
461
461
|
target: `${o}::pyth::create_authenticated_price_infos_using_accumulator`,
|
|
462
462
|
arguments: [
|
|
463
463
|
t.object(this.pythStateId),
|
|
464
|
-
t.pure(
|
|
464
|
+
t.pure(ue(r[0])),
|
|
465
465
|
a,
|
|
466
|
-
t.object(
|
|
466
|
+
t.object(x)
|
|
467
467
|
]
|
|
468
468
|
});
|
|
469
469
|
return c;
|
|
@@ -481,7 +481,7 @@ class lt {
|
|
|
481
481
|
n,
|
|
482
482
|
t.object(u),
|
|
483
483
|
a[i],
|
|
484
|
-
t.object(
|
|
484
|
+
t.object(x)
|
|
485
485
|
]
|
|
486
486
|
});
|
|
487
487
|
}
|
|
@@ -498,24 +498,33 @@ class lt {
|
|
|
498
498
|
return this.pythPackageId || (this.pythPackageId = await this.getPackageId(this.pythStateId)), this.pythPackageId;
|
|
499
499
|
}
|
|
500
500
|
async getPriceFeedObjectId(t) {
|
|
501
|
-
const r =
|
|
501
|
+
const r = oe(t);
|
|
502
502
|
if (!this.priceFeedObjectIdCache.has(r)) {
|
|
503
|
-
const { id: o, fieldType: n } = await this.getPriceTableInfo(), a = this.getCoreProvider()
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
value
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
503
|
+
const { id: o, fieldType: n } = await this.getPriceTableInfo(), a = `${n}::price_identifier::PriceIdentifier`, c = this.getCoreProvider();
|
|
504
|
+
if (c) {
|
|
505
|
+
const { dynamicField: i } = await c.getDynamicField({
|
|
506
|
+
parentId: o,
|
|
507
|
+
name: le(a, it(se(r)))
|
|
508
|
+
}), s = i?.value?.bcs;
|
|
509
|
+
this.priceFeedObjectIdCache.set(
|
|
510
|
+
r,
|
|
511
|
+
s && s.length === 32 ? l.Address.parse(Uint8Array.from(s)) : void 0
|
|
512
|
+
);
|
|
513
|
+
} else {
|
|
514
|
+
const i = await this.getDynamicMoveObjectJson(o, {
|
|
515
|
+
type: a,
|
|
516
|
+
value: {
|
|
517
|
+
bytes: Array.from(se(r))
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
i?.fields ? this.priceFeedObjectIdCache.set(r, i.fields.value) : this.priceFeedObjectIdCache.set(r, void 0);
|
|
521
|
+
}
|
|
513
522
|
}
|
|
514
523
|
return this.priceFeedObjectIdCache.get(r);
|
|
515
524
|
}
|
|
516
525
|
async getPriceTableInfo() {
|
|
517
526
|
if (!this.priceTableInfo) {
|
|
518
|
-
const t = this.getCoreProvider() ?
|
|
527
|
+
const t = this.getCoreProvider() ? le("vector<u8>", at("price_info")) : {
|
|
519
528
|
type: "vector<u8>",
|
|
520
529
|
value: "price_info"
|
|
521
530
|
}, r = await this.getDynamicMoveObjectJson(this.pythStateId, t);
|
|
@@ -534,32 +543,32 @@ class lt {
|
|
|
534
543
|
}
|
|
535
544
|
}
|
|
536
545
|
const dt = "https://open-api.naviprotocol.io/api";
|
|
537
|
-
let
|
|
546
|
+
let Q = {}, ke = 0;
|
|
538
547
|
function pt(e) {
|
|
539
548
|
return e.replace(/\/+$/, "");
|
|
540
549
|
}
|
|
541
550
|
function Yt(e) {
|
|
542
|
-
|
|
543
|
-
...
|
|
551
|
+
Q = {
|
|
552
|
+
...Q,
|
|
544
553
|
...e,
|
|
545
554
|
services: {
|
|
546
|
-
...
|
|
555
|
+
...Q.services,
|
|
547
556
|
...e.services
|
|
548
557
|
}
|
|
549
|
-
},
|
|
558
|
+
}, ke += 1;
|
|
550
559
|
}
|
|
551
|
-
function
|
|
552
|
-
return
|
|
560
|
+
function de() {
|
|
561
|
+
return ke;
|
|
553
562
|
}
|
|
554
|
-
function
|
|
555
|
-
const t = e?.services?.naviOpenApi ??
|
|
563
|
+
function M(e) {
|
|
564
|
+
const t = e?.services?.naviOpenApi ?? Q.services?.naviOpenApi;
|
|
556
565
|
return {
|
|
557
566
|
baseUrl: pt(t?.baseUrl ?? dt),
|
|
558
567
|
headers: t?.headers
|
|
559
568
|
};
|
|
560
569
|
}
|
|
561
|
-
function
|
|
562
|
-
const r =
|
|
570
|
+
function F(e, t) {
|
|
571
|
+
const r = M(t), o = e.startsWith("/") ? e : `/${e}`;
|
|
563
572
|
return `${r.baseUrl}${o}`;
|
|
564
573
|
}
|
|
565
574
|
function mt(e) {
|
|
@@ -571,14 +580,14 @@ function mt(e) {
|
|
|
571
580
|
}
|
|
572
581
|
return Array.isArray(e) ? Object.fromEntries(e) : e;
|
|
573
582
|
}
|
|
574
|
-
function
|
|
583
|
+
function N(e, t) {
|
|
575
584
|
return {
|
|
576
585
|
...mt(e),
|
|
577
586
|
...t?.headers ?? {}
|
|
578
587
|
};
|
|
579
588
|
}
|
|
580
|
-
const
|
|
581
|
-
function
|
|
589
|
+
const U = rt();
|
|
590
|
+
function pe(e) {
|
|
582
591
|
return e ? e instanceof Uint8Array ? Array.from(e) : Array.isArray(e) ? e : Array.from(De(e)) : [];
|
|
583
592
|
}
|
|
584
593
|
function ft(e) {
|
|
@@ -588,21 +597,21 @@ function ft(e) {
|
|
|
588
597
|
events: r.events,
|
|
589
598
|
error: o,
|
|
590
599
|
results: t.map((n) => ({
|
|
591
|
-
returnValues: (n.returnValues ?? []).map((a) => [
|
|
600
|
+
returnValues: (n.returnValues ?? []).map((a) => [pe(a.bcs), ""]),
|
|
592
601
|
mutableReferenceOutputs: (n.mutatedReferences ?? []).map((a) => [
|
|
593
602
|
"",
|
|
594
|
-
|
|
603
|
+
pe(a.bcs),
|
|
595
604
|
""
|
|
596
605
|
])
|
|
597
606
|
}))
|
|
598
607
|
};
|
|
599
608
|
}
|
|
600
|
-
async function
|
|
609
|
+
async function W(e, t) {
|
|
601
610
|
const r = e?.core;
|
|
602
611
|
if (typeof r?.simulateTransaction != "function")
|
|
603
612
|
throw new Error("devInspectTransaction requires a Sui v2 Core-capable client");
|
|
604
613
|
const o = t.transaction ?? t.transactionBlock;
|
|
605
|
-
o instanceof
|
|
614
|
+
o instanceof q && o.setSenderIfNotSet(t.sender);
|
|
606
615
|
const n = await r.simulateTransaction({
|
|
607
616
|
transaction: o,
|
|
608
617
|
checksEnabled: !1,
|
|
@@ -614,7 +623,7 @@ async function q(e, t) {
|
|
|
614
623
|
});
|
|
615
624
|
return ft(n);
|
|
616
625
|
}
|
|
617
|
-
function
|
|
626
|
+
function _e(e) {
|
|
618
627
|
return {
|
|
619
628
|
json: !!e?.showContent,
|
|
620
629
|
display: !!e?.showDisplay,
|
|
@@ -622,7 +631,7 @@ function ke(e) {
|
|
|
622
631
|
objectBcs: !!e?.showBcs
|
|
623
632
|
};
|
|
624
633
|
}
|
|
625
|
-
function
|
|
634
|
+
function Te(e) {
|
|
626
635
|
return !e || e instanceof Error ? {
|
|
627
636
|
error: e instanceof Error ? { code: "notFound", error: e.message } : void 0
|
|
628
637
|
} : {
|
|
@@ -648,9 +657,9 @@ async function yt(e, t) {
|
|
|
648
657
|
throw new Error("getSuiObject requires a Sui v2 Core-capable client");
|
|
649
658
|
const { object: o } = await r.getObject({
|
|
650
659
|
objectId: t.id,
|
|
651
|
-
include:
|
|
660
|
+
include: _e(t.options)
|
|
652
661
|
});
|
|
653
|
-
return
|
|
662
|
+
return Te(o);
|
|
654
663
|
}
|
|
655
664
|
async function gt(e, t) {
|
|
656
665
|
const r = e?.core;
|
|
@@ -658,48 +667,48 @@ async function gt(e, t) {
|
|
|
658
667
|
throw new Error("multiGetSuiObjects requires a Sui v2 Core-capable client");
|
|
659
668
|
const { objects: o } = await r.getObjects({
|
|
660
669
|
objectIds: t.ids,
|
|
661
|
-
include:
|
|
670
|
+
include: _e(t.options)
|
|
662
671
|
});
|
|
663
|
-
return o.map(
|
|
672
|
+
return o.map(Te);
|
|
664
673
|
}
|
|
665
|
-
function
|
|
674
|
+
function Be(e) {
|
|
666
675
|
const t = [];
|
|
667
676
|
let r = !1;
|
|
668
677
|
return e.forEach((o, n) => {
|
|
669
678
|
const a = n === e.length - 1;
|
|
670
679
|
if (typeof o == "object" && o !== null && a) {
|
|
671
680
|
const { client: c, disableCache: i, cacheTime: s, ...u } = o;
|
|
672
|
-
u.__naviSdkServiceConfigVersion =
|
|
681
|
+
u.__naviSdkServiceConfigVersion = de(), t.push(u), r = !0;
|
|
673
682
|
} else
|
|
674
683
|
t.push(o);
|
|
675
684
|
}), r || t.push({
|
|
676
|
-
__naviSdkServiceConfigVersion:
|
|
685
|
+
__naviSdkServiceConfigVersion: de()
|
|
677
686
|
}), JSON.stringify(t);
|
|
678
687
|
}
|
|
679
|
-
function
|
|
688
|
+
function S(e) {
|
|
680
689
|
const t = {};
|
|
681
690
|
return (...r) => {
|
|
682
|
-
const o =
|
|
691
|
+
const o = Be(r);
|
|
683
692
|
return t[o] || (t[o] = e(...r).finally(() => {
|
|
684
693
|
delete t[o];
|
|
685
694
|
})), t[o];
|
|
686
695
|
};
|
|
687
696
|
}
|
|
688
|
-
function
|
|
697
|
+
function O(e) {
|
|
689
698
|
let t = {};
|
|
690
699
|
return (...r) => {
|
|
691
|
-
const o = r[r.length - 1], n =
|
|
700
|
+
const o = r[r.length - 1], n = Be(r), a = t[n];
|
|
692
701
|
return !o?.disableCache && typeof a?.data < "u" && (typeof o?.cacheTime > "u" || o.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...r).then((c) => (t[n] = {
|
|
693
702
|
data: c,
|
|
694
703
|
cacheAt: Date.now()
|
|
695
704
|
}, c));
|
|
696
705
|
};
|
|
697
706
|
}
|
|
698
|
-
function
|
|
699
|
-
return Array.isArray(e) ? e.map((t) =>
|
|
707
|
+
function re(e) {
|
|
708
|
+
return Array.isArray(e) ? e.map((t) => re(t)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
|
|
700
709
|
(t, r) => ({
|
|
701
710
|
...t,
|
|
702
|
-
[Fe(r)]:
|
|
711
|
+
[Fe(r)]: re(e[r])
|
|
703
712
|
}),
|
|
704
713
|
{}
|
|
705
714
|
) : e;
|
|
@@ -712,7 +721,7 @@ function h(e, t) {
|
|
|
712
721
|
function ht(e, t) {
|
|
713
722
|
return typeof t == "string" ? e.object(t) : typeof t == "object" && t.$kind ? t : e.object(t.contract.pool);
|
|
714
723
|
}
|
|
715
|
-
function
|
|
724
|
+
function Z(e, t, r) {
|
|
716
725
|
if (e.results && e.results.length > 0) {
|
|
717
726
|
if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
|
|
718
727
|
return e.results[0].returnValues.map((o, n) => (t[n] || t[0]).parse(Uint8Array.from(o[0])));
|
|
@@ -721,35 +730,35 @@ function Q(e, t, r) {
|
|
|
721
730
|
return [];
|
|
722
731
|
}
|
|
723
732
|
function C(e) {
|
|
724
|
-
return
|
|
733
|
+
return Y(e);
|
|
725
734
|
}
|
|
726
|
-
function
|
|
735
|
+
function Pe(e) {
|
|
727
736
|
const t = (e || 0) / Math.pow(10, 27);
|
|
728
737
|
return t > Math.pow(10, 5) ? 1 / 0 : t;
|
|
729
738
|
}
|
|
730
|
-
new
|
|
739
|
+
new Ie("https://hermes.pyth.network", {
|
|
731
740
|
timeout: 2e4
|
|
732
741
|
});
|
|
733
|
-
const wt = 27,
|
|
742
|
+
const wt = 27, me = (e, t) => {
|
|
734
743
|
if (!Number(e) || !Number(t)) return new p(0);
|
|
735
744
|
const r = new p(1).shiftedBy(1 * wt), o = r.multipliedBy(new p(0.5));
|
|
736
745
|
return new p(e).multipliedBy(new p(t)).plus(o).dividedBy(r).integerValue(p.ROUND_DOWN);
|
|
737
|
-
},
|
|
738
|
-
"User-Agent":
|
|
746
|
+
}, R = ce ? {
|
|
747
|
+
"User-Agent": ce
|
|
739
748
|
} : {};
|
|
740
|
-
function
|
|
749
|
+
function ne(e, t = "uniqueId") {
|
|
741
750
|
return e.reduce(
|
|
742
751
|
(r, o) => (r[o[t]] = o, r),
|
|
743
752
|
{}
|
|
744
753
|
);
|
|
745
754
|
}
|
|
746
|
-
function
|
|
755
|
+
function fe(e, t = "uniqueId") {
|
|
747
756
|
return e.reduce(
|
|
748
757
|
(r, o) => (r[o[t]] = o, r),
|
|
749
758
|
{}
|
|
750
759
|
);
|
|
751
760
|
}
|
|
752
|
-
function
|
|
761
|
+
function K(e, t) {
|
|
753
762
|
const r = e.emodes.find((n) => n.emodeId === t.emodeId);
|
|
754
763
|
if (!r)
|
|
755
764
|
throw new Error("EMode not found in pool");
|
|
@@ -770,45 +779,45 @@ function bt(e) {
|
|
|
770
779
|
poolId: parseInt(r)
|
|
771
780
|
};
|
|
772
781
|
}
|
|
773
|
-
function
|
|
782
|
+
function A() {
|
|
774
783
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
775
784
|
}
|
|
776
|
-
var
|
|
777
|
-
const
|
|
778
|
-
|
|
785
|
+
var H = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(H || {});
|
|
786
|
+
const J = O(
|
|
787
|
+
S(
|
|
779
788
|
async (e) => {
|
|
780
|
-
const t = (e?.markets || [
|
|
781
|
-
`/navi/pools?env=${e?.env || "prod"}&sdk=${
|
|
789
|
+
const t = (e?.markets || [L.main]).map((a) => P(a)), r = M(e), o = F(
|
|
790
|
+
`/navi/pools?env=${e?.env || "prod"}&sdk=${V.version}&market=${t.map(
|
|
782
791
|
(a) => a.key
|
|
783
792
|
)}`,
|
|
784
793
|
e
|
|
785
|
-
), n = await fetch(o, { headers:
|
|
794
|
+
), n = await fetch(o, { headers: N(R, r) }).then(
|
|
786
795
|
(a) => a.json()
|
|
787
796
|
);
|
|
788
797
|
return n.data.forEach((a) => {
|
|
789
798
|
const i = n.meta.emodes.filter((b) => {
|
|
790
|
-
const
|
|
791
|
-
return a.market ===
|
|
792
|
-
}).filter((b) => !!b.assets.find((
|
|
799
|
+
const j = P(b.marketId);
|
|
800
|
+
return a.market === j.key && b.isActive;
|
|
801
|
+
}).filter((b) => !!b.assets.find((j) => j.assetId === a.id));
|
|
793
802
|
a.emodes = i;
|
|
794
|
-
const s = p(a.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), u = p(a.borrowedAmount).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), m = p(s).multipliedBy(a.oracle.price).toString(), w = p(u).multipliedBy(a.oracle.price).toString(),
|
|
803
|
+
const s = p(a.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), u = p(a.borrowedAmount).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), m = p(s).multipliedBy(a.oracle.price).toString(), w = p(u).multipliedBy(a.oracle.price).toString(), g = p(a.supplyCapCeiling).shiftedBy(-27).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), y = p.max(
|
|
795
804
|
p(a.borrowedAmount),
|
|
796
805
|
p(a.validBorrowAmount)
|
|
797
|
-
).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), d = p(
|
|
798
|
-
a.poolSupplyAmount = s, a.poolBorrowAmount = u, a.poolSupplyValue = m, a.poolBorrowValue = w, a.poolSupplyCapAmount =
|
|
806
|
+
).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), d = p(g).multipliedBy(a.oracle.price).toString(), f = p(y).multipliedBy(a.oracle.price).toString();
|
|
807
|
+
a.poolSupplyAmount = s, a.poolBorrowAmount = u, a.poolSupplyValue = m, a.poolBorrowValue = w, a.poolSupplyCapAmount = g, a.poolBorrowCapAmount = y, a.poolSupplyCapValue = d, a.poolBorrowCapValue = f;
|
|
799
808
|
}), n.data;
|
|
800
809
|
}
|
|
801
810
|
)
|
|
802
811
|
);
|
|
803
|
-
async function
|
|
812
|
+
async function E(e, t) {
|
|
804
813
|
let r = t?.market;
|
|
805
814
|
if (typeof e == "string") {
|
|
806
815
|
const a = bt(e);
|
|
807
816
|
a && (r = a.marketKey, e = a.poolId);
|
|
808
817
|
}
|
|
809
|
-
const o = await
|
|
818
|
+
const o = await J({
|
|
810
819
|
...t,
|
|
811
|
-
markets: [r ||
|
|
820
|
+
markets: [r || z],
|
|
812
821
|
cacheTime: v
|
|
813
822
|
});
|
|
814
823
|
if (typeof e == "object")
|
|
@@ -818,28 +827,28 @@ async function S(e, t) {
|
|
|
818
827
|
throw new Error("Pool not found");
|
|
819
828
|
return n.isDeprecated && console.log(`The lending pool for coinType ${n.suiCoinType} is going to be deprecated.`), n;
|
|
820
829
|
}
|
|
821
|
-
const Zt =
|
|
822
|
-
|
|
823
|
-
const t =
|
|
830
|
+
const Zt = O(
|
|
831
|
+
S(async (e) => {
|
|
832
|
+
const t = M(e), r = F(`/navi/stats?sdk=${V.version}`, e);
|
|
824
833
|
return (await fetch(r, {
|
|
825
|
-
headers:
|
|
834
|
+
headers: N(R, t)
|
|
826
835
|
}).then((n) => n.json())).data;
|
|
827
836
|
})
|
|
828
|
-
), Xt =
|
|
829
|
-
|
|
837
|
+
), Xt = O(
|
|
838
|
+
S(
|
|
830
839
|
async (e) => {
|
|
831
|
-
const t =
|
|
840
|
+
const t = M(e), r = F(`/navi/fee?sdk=${V.version}`, e);
|
|
832
841
|
return await fetch(r, {
|
|
833
|
-
headers:
|
|
842
|
+
headers: N(R, t)
|
|
834
843
|
}).then((n) => n.json());
|
|
835
844
|
}
|
|
836
845
|
)
|
|
837
846
|
);
|
|
838
847
|
async function vt(e, t, r, o) {
|
|
839
|
-
const n = await
|
|
848
|
+
const n = await I({
|
|
840
849
|
...o,
|
|
841
850
|
cacheTime: v
|
|
842
|
-
}), a = await
|
|
851
|
+
}), a = await E(t, o), c = o?.market || z, i = o?.env || "prod";
|
|
843
852
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
844
853
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
845
854
|
if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
@@ -884,10 +893,10 @@ async function vt(e, t, r, o) {
|
|
|
884
893
|
}), e;
|
|
885
894
|
}
|
|
886
895
|
async function xt(e, t, r, o) {
|
|
887
|
-
const n = await
|
|
896
|
+
const n = await I({
|
|
888
897
|
...o,
|
|
889
898
|
cacheTime: v
|
|
890
|
-
}), a = await
|
|
899
|
+
}), a = await E(t, o), c = h(r, e.pure.u64);
|
|
891
900
|
let i;
|
|
892
901
|
if (n.version === 1)
|
|
893
902
|
if (o?.accountCap) {
|
|
@@ -967,10 +976,10 @@ async function xt(e, t, r, o) {
|
|
|
967
976
|
});
|
|
968
977
|
}
|
|
969
978
|
async function er(e, t, r, o) {
|
|
970
|
-
const n = await
|
|
979
|
+
const n = await I({
|
|
971
980
|
...o,
|
|
972
981
|
cacheTime: v
|
|
973
|
-
}), a = await
|
|
982
|
+
}), a = await E(t, o);
|
|
974
983
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
975
984
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
976
985
|
const c = h(r, e.pure.u64);
|
|
@@ -1053,10 +1062,10 @@ async function er(e, t, r, o) {
|
|
|
1053
1062
|
});
|
|
1054
1063
|
}
|
|
1055
1064
|
async function tr(e, t, r, o) {
|
|
1056
|
-
const n = await
|
|
1065
|
+
const n = await I({
|
|
1057
1066
|
...o,
|
|
1058
1067
|
cacheTime: v
|
|
1059
|
-
}), a = await
|
|
1068
|
+
}), a = await E(t, o);
|
|
1060
1069
|
if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
1061
1070
|
if (!o?.amount)
|
|
1062
1071
|
throw new Error("Amount is required for sui coin");
|
|
@@ -1105,15 +1114,15 @@ async function tr(e, t, r, o) {
|
|
|
1105
1114
|
typeArguments: [a.suiCoinType]
|
|
1106
1115
|
}), e;
|
|
1107
1116
|
}
|
|
1108
|
-
const rr =
|
|
1109
|
-
|
|
1117
|
+
const rr = O(
|
|
1118
|
+
S(
|
|
1110
1119
|
async (e) => {
|
|
1111
|
-
const t = await
|
|
1120
|
+
const t = await I({
|
|
1112
1121
|
...e
|
|
1113
|
-
}), r = e?.client ??
|
|
1122
|
+
}), r = e?.client ?? U;
|
|
1114
1123
|
if (e?.address && typeof e?.asset < "u")
|
|
1115
1124
|
try {
|
|
1116
|
-
const a = await
|
|
1125
|
+
const a = await E(e.asset, e), c = new q();
|
|
1117
1126
|
c.moveCall({
|
|
1118
1127
|
target: `${t.package}::incentive_v3::get_borrow_fee_v2`,
|
|
1119
1128
|
arguments: [
|
|
@@ -1124,10 +1133,10 @@ const rr = $(
|
|
|
1124
1133
|
],
|
|
1125
1134
|
typeArguments: []
|
|
1126
1135
|
});
|
|
1127
|
-
const i = await
|
|
1136
|
+
const i = await W(r, {
|
|
1128
1137
|
transactionBlock: c,
|
|
1129
1138
|
sender: e.address
|
|
1130
|
-
}), s =
|
|
1139
|
+
}), s = Z(i, [l.u64()]);
|
|
1131
1140
|
return (Number(s[0]) || 0) / 100;
|
|
1132
1141
|
} catch (a) {
|
|
1133
1142
|
console.error(
|
|
@@ -1142,7 +1151,7 @@ const rr = $(
|
|
|
1142
1151
|
return Number(n) / 100;
|
|
1143
1152
|
}
|
|
1144
1153
|
)
|
|
1145
|
-
),
|
|
1154
|
+
), z = "main", L = {
|
|
1146
1155
|
main: {
|
|
1147
1156
|
id: 0,
|
|
1148
1157
|
key: "main",
|
|
@@ -1169,13 +1178,13 @@ class Ct {
|
|
|
1169
1178
|
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
1170
1179
|
marketTotalSupplyValue: "0",
|
|
1171
1180
|
marketTotalBorrowValue: "0"
|
|
1172
|
-
}, this.config =
|
|
1181
|
+
}, this.config = P(t), this.initPools(r);
|
|
1173
1182
|
}
|
|
1174
1183
|
get overview() {
|
|
1175
1184
|
return this._overview;
|
|
1176
1185
|
}
|
|
1177
1186
|
initPools(t) {
|
|
1178
|
-
const r =
|
|
1187
|
+
const r = ne(this.pools), o = fe(this.emodes), n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
1179
1188
|
let c = p(0), i = p(0);
|
|
1180
1189
|
t.forEach((s) => {
|
|
1181
1190
|
if (!this.checkMarket(s.market)) {
|
|
@@ -1185,11 +1194,11 @@ class Ct {
|
|
|
1185
1194
|
r[s.uniqueId] || this.pools.push(s), s?.emodes?.forEach((m) => {
|
|
1186
1195
|
o[m.uniqueId] || this.emodes.push(m), m.assets.forEach((w) => {
|
|
1187
1196
|
w.isDebt && m.assets.find(
|
|
1188
|
-
(
|
|
1189
|
-
) && n.add(s.uniqueId), w.isCollateral && m.assets.find((
|
|
1197
|
+
(y) => y.isCollateral && y.ltv > 0 && y.assetId !== s.id
|
|
1198
|
+
) && n.add(s.uniqueId), w.isCollateral && m.assets.find((y) => y.isDebt && y.assetId !== s.id) && a.add(s.uniqueId);
|
|
1190
1199
|
});
|
|
1191
1200
|
}), i = i.plus(s.poolBorrowValue), c = c.plus(s.poolSupplyValue);
|
|
1192
|
-
}), this.poolMap =
|
|
1201
|
+
}), this.poolMap = ne(this.pools, "id"), this.emodeMap = fe(this.emodes, "emodeId"), this.emodes.forEach((s) => {
|
|
1193
1202
|
const u = this.getEModePools(s.emodeId);
|
|
1194
1203
|
this.emodePools.push(...u);
|
|
1195
1204
|
}), this._overview = {
|
|
@@ -1227,44 +1236,44 @@ class Ct {
|
|
|
1227
1236
|
return typeof t == "number" && t === this.config.id && (r = !0), typeof t == "string" && t === this.config.key && (r = !0), typeof t == "object" && t.id === this.config.id && (r = !0), r;
|
|
1228
1237
|
}
|
|
1229
1238
|
}
|
|
1230
|
-
const
|
|
1231
|
-
const r = Object.values(
|
|
1239
|
+
const P = (e) => {
|
|
1240
|
+
const r = Object.values(L).find((o) => typeof e == "number" ? o.id === e : typeof e == "string" ? o.key === e : o.id === e.id);
|
|
1232
1241
|
if (!r)
|
|
1233
1242
|
throw new Error("Market not found");
|
|
1234
1243
|
return r;
|
|
1235
|
-
}, jt =
|
|
1236
|
-
|
|
1244
|
+
}, jt = O(
|
|
1245
|
+
S(
|
|
1237
1246
|
async (e, t) => {
|
|
1238
|
-
const r = await
|
|
1247
|
+
const r = await J({
|
|
1239
1248
|
cacheTime: 6e4,
|
|
1240
1249
|
...t,
|
|
1241
1250
|
markets: e
|
|
1242
1251
|
});
|
|
1243
1252
|
return e.map((o) => {
|
|
1244
|
-
const n =
|
|
1253
|
+
const n = P(o), a = r.filter((c) => c.market === n.key);
|
|
1245
1254
|
return new Ct(o, a);
|
|
1246
1255
|
});
|
|
1247
1256
|
}
|
|
1248
1257
|
)
|
|
1249
|
-
), nr =
|
|
1250
|
-
|
|
1258
|
+
), nr = O(
|
|
1259
|
+
S(
|
|
1251
1260
|
async (e, t) => (await jt([e], t))[0]
|
|
1252
1261
|
)
|
|
1253
|
-
),
|
|
1254
|
-
|
|
1262
|
+
), I = O(
|
|
1263
|
+
S(
|
|
1255
1264
|
async (e) => {
|
|
1256
|
-
const t =
|
|
1257
|
-
`/navi/config?env=${e?.env || "prod"}&sdk=${
|
|
1265
|
+
const t = P(e?.market || z), r = M(e), o = F(
|
|
1266
|
+
`/navi/config?env=${e?.env || "prod"}&sdk=${V.version}&market=${t.key}`,
|
|
1258
1267
|
e
|
|
1259
1268
|
);
|
|
1260
1269
|
return (await fetch(o, {
|
|
1261
|
-
headers:
|
|
1270
|
+
headers: N(R, r)
|
|
1262
1271
|
}).then((a) => a.json())).data;
|
|
1263
1272
|
}
|
|
1264
1273
|
)
|
|
1265
1274
|
), v = 1e3 * 60 * 5;
|
|
1266
|
-
async function
|
|
1267
|
-
const r = await
|
|
1275
|
+
async function It(e, t) {
|
|
1276
|
+
const r = await I({
|
|
1268
1277
|
cacheTime: v,
|
|
1269
1278
|
...t
|
|
1270
1279
|
});
|
|
@@ -1273,8 +1282,8 @@ async function kt(e, t) {
|
|
|
1273
1282
|
arguments: []
|
|
1274
1283
|
});
|
|
1275
1284
|
}
|
|
1276
|
-
async function
|
|
1277
|
-
const o = await
|
|
1285
|
+
async function kt(e, t, r) {
|
|
1286
|
+
const o = await I({
|
|
1278
1287
|
cacheTime: v,
|
|
1279
1288
|
...r
|
|
1280
1289
|
});
|
|
@@ -1284,7 +1293,7 @@ async function It(e, t, r) {
|
|
|
1284
1293
|
});
|
|
1285
1294
|
}
|
|
1286
1295
|
async function _t(e, t, r) {
|
|
1287
|
-
const o = await
|
|
1296
|
+
const o = await I({
|
|
1288
1297
|
...r,
|
|
1289
1298
|
cacheTime: v
|
|
1290
1299
|
});
|
|
@@ -1301,7 +1310,7 @@ async function _t(e, t, r) {
|
|
|
1301
1310
|
}), e;
|
|
1302
1311
|
}
|
|
1303
1312
|
async function or(e, t) {
|
|
1304
|
-
const r = await
|
|
1313
|
+
const r = await I({
|
|
1305
1314
|
...t,
|
|
1306
1315
|
cacheTime: v
|
|
1307
1316
|
});
|
|
@@ -1314,15 +1323,15 @@ async function or(e, t) {
|
|
|
1314
1323
|
}), e;
|
|
1315
1324
|
}
|
|
1316
1325
|
async function ar(e, t, r) {
|
|
1317
|
-
const o = await
|
|
1326
|
+
const o = await I({
|
|
1318
1327
|
cacheTime: v,
|
|
1319
1328
|
...r
|
|
1320
|
-
}), n = await
|
|
1329
|
+
}), n = await It(e, r);
|
|
1321
1330
|
await _t(e, t, {
|
|
1322
1331
|
...r,
|
|
1323
1332
|
accountCap: n
|
|
1324
1333
|
});
|
|
1325
|
-
const a = await
|
|
1334
|
+
const a = await P(r?.market || z), c = await kt(e, n, r);
|
|
1326
1335
|
return e.moveCall({
|
|
1327
1336
|
target: `${o.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
1328
1337
|
arguments: [
|
|
@@ -1333,18 +1342,18 @@ async function ar(e, t, r) {
|
|
|
1333
1342
|
]
|
|
1334
1343
|
}), n;
|
|
1335
1344
|
}
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1345
|
+
const Ae = O(
|
|
1346
|
+
S(
|
|
1338
1347
|
async (e, t) => {
|
|
1339
|
-
const r = await
|
|
1348
|
+
const r = await I({
|
|
1340
1349
|
cacheTime: v,
|
|
1341
1350
|
...t
|
|
1342
|
-
}), o = new
|
|
1351
|
+
}), o = new q(), n = t?.client ?? U;
|
|
1343
1352
|
o.moveCall({
|
|
1344
1353
|
target: `${r.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
1345
1354
|
arguments: [o.object(r.emode.contract.registryObject), o.pure.address(e)]
|
|
1346
1355
|
});
|
|
1347
|
-
const c = (await
|
|
1356
|
+
const c = (await W(n, {
|
|
1348
1357
|
transactionBlock: o,
|
|
1349
1358
|
sender: e
|
|
1350
1359
|
})).results[0].returnValues, i = l.vector(l.u64()).parse(Uint8Array.from(c[0][0])), s = l.vector(l.u64()).parse(Uint8Array.from(c[1][0])), u = l.vector(l.Address).parse(Uint8Array.from(c[2][0]));
|
|
@@ -1357,12 +1366,12 @@ const Be = $(
|
|
|
1357
1366
|
)
|
|
1358
1367
|
);
|
|
1359
1368
|
function ir(e) {
|
|
1360
|
-
return `${
|
|
1369
|
+
return `${P(e.marketId).key}-${e.emodeId}`;
|
|
1361
1370
|
}
|
|
1362
1371
|
function Tt(e, t) {
|
|
1363
1372
|
return e.coinType ? e.coinType : t || (typeof e.type == "string" ? e.type.match(/::coin::Coin<(.+)>$/) : null)?.[1];
|
|
1364
1373
|
}
|
|
1365
|
-
function
|
|
1374
|
+
function ye(e, t) {
|
|
1366
1375
|
const r = Tt(e, t), o = e.coinObjectId ?? e.objectId;
|
|
1367
1376
|
return !r || !o || e.balance === void 0 || e.balance === null ? null : {
|
|
1368
1377
|
...e,
|
|
@@ -1371,29 +1380,55 @@ function me(e, t) {
|
|
|
1371
1380
|
};
|
|
1372
1381
|
}
|
|
1373
1382
|
function cr(e, t, r) {
|
|
1374
|
-
const o = typeof r?.balance == "number", n = o ? r.balance : 0;
|
|
1375
|
-
let
|
|
1376
|
-
const
|
|
1377
|
-
let
|
|
1378
|
-
|
|
1379
|
-
if (!(o &&
|
|
1380
|
-
if (
|
|
1383
|
+
const o = typeof r?.balance == "number", n = o ? r.balance : 0, a = BigInt(r?.addressBalance ?? 0);
|
|
1384
|
+
let c = 0;
|
|
1385
|
+
const i = [];
|
|
1386
|
+
let s = "", u = 0n;
|
|
1387
|
+
t.sort((B, X) => Number(X.balance) - Number(B.balance)).forEach((B) => {
|
|
1388
|
+
if (u += BigInt(B.balance), !(o && c >= n) && Number(B.balance) !== 0) {
|
|
1389
|
+
if (s || (s = B.coinType), s !== B.coinType)
|
|
1381
1390
|
throw new Error("All coins must be of the same type");
|
|
1382
|
-
|
|
1391
|
+
c += Number(B.balance), i.push(B.coinObjectId);
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
const m = r?.coinType, y = ((B) => {
|
|
1395
|
+
if (!B)
|
|
1396
|
+
return !1;
|
|
1397
|
+
try {
|
|
1398
|
+
return C(B) === C("0x2::sui::SUI");
|
|
1399
|
+
} catch {
|
|
1400
|
+
return !1;
|
|
1383
1401
|
}
|
|
1384
|
-
}),
|
|
1402
|
+
})(s || m || "") && !!r?.useGasCoin, d = BigInt(n), f = !y && !!m, b = f ? a : 0n, j = u + b, _ = !o || u >= d ? 0n : d - u, k = f && _ > 0n && b >= _;
|
|
1403
|
+
if (o && j < d)
|
|
1404
|
+
throw new Error(`Balance is less than the specified balance: ${j} < ${d}`);
|
|
1405
|
+
if (i.length === 0 && !k)
|
|
1385
1406
|
throw new Error("No coins to merge");
|
|
1386
|
-
if (
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
);
|
|
1390
|
-
|
|
1407
|
+
if (y)
|
|
1408
|
+
return o ? e.splitCoins(e.gas, [e.pure.u64(n)]) : e.gas;
|
|
1409
|
+
if (!k)
|
|
1410
|
+
return i.length === 1 ? e.object(i[0]) : e.mergeCoins(i[0], i.slice(1)), o ? e.splitCoins(i[0], [e.pure.u64(n)]) : i[0];
|
|
1411
|
+
const T = e.moveCall({
|
|
1412
|
+
target: "0x2::coin::redeem_funds",
|
|
1413
|
+
typeArguments: [m],
|
|
1414
|
+
arguments: [e.withdrawal({ amount: _, type: m })]
|
|
1415
|
+
});
|
|
1416
|
+
let $;
|
|
1417
|
+
const D = [];
|
|
1418
|
+
if (i.length > 0) {
|
|
1419
|
+
$ = e.object(i[0]);
|
|
1420
|
+
for (const B of i.slice(1))
|
|
1421
|
+
D.push(e.object(B));
|
|
1422
|
+
D.push(T);
|
|
1423
|
+
} else
|
|
1424
|
+
$ = T;
|
|
1425
|
+
return D.length > 0 && e.mergeCoins($, D), i.length === 0 ? $ : o ? e.splitCoins($, [e.pure.u64(n)]) : $;
|
|
1391
1426
|
}
|
|
1392
|
-
async function
|
|
1393
|
-
const i = await
|
|
1427
|
+
async function Se(e, t, r, o, n, a, c) {
|
|
1428
|
+
const i = await I({
|
|
1394
1429
|
...c,
|
|
1395
1430
|
cacheTime: v
|
|
1396
|
-
}), s = await
|
|
1431
|
+
}), s = await E(r, c);
|
|
1397
1432
|
return e.moveCall({
|
|
1398
1433
|
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
1399
1434
|
arguments: [
|
|
@@ -1411,15 +1446,15 @@ async function Pe(e, t, r, o, n, a, c) {
|
|
|
1411
1446
|
});
|
|
1412
1447
|
}
|
|
1413
1448
|
async function Bt(e, t, r) {
|
|
1414
|
-
return
|
|
1449
|
+
return Se(e, t, 0, 0, 0, !1, r);
|
|
1415
1450
|
}
|
|
1416
|
-
async function
|
|
1417
|
-
const o = new
|
|
1451
|
+
async function $e(e, t, r) {
|
|
1452
|
+
const o = new q(), n = r?.client ?? U, a = await J({
|
|
1418
1453
|
...r,
|
|
1419
|
-
markets: Object.values(
|
|
1420
|
-
}), c =
|
|
1454
|
+
markets: Object.values(L)
|
|
1455
|
+
}), c = ne(a), s = Array.from(new Set(t.map((d) => d.market))).map((d) => P(d));
|
|
1421
1456
|
for (const d of s) {
|
|
1422
|
-
const f = await
|
|
1457
|
+
const f = await I({
|
|
1423
1458
|
...r,
|
|
1424
1459
|
cacheTime: v,
|
|
1425
1460
|
market: d.key
|
|
@@ -1430,7 +1465,7 @@ async function Ae(e, t, r) {
|
|
|
1430
1465
|
});
|
|
1431
1466
|
}
|
|
1432
1467
|
for (let d of t) {
|
|
1433
|
-
const f = await
|
|
1468
|
+
const f = await I({
|
|
1434
1469
|
...r,
|
|
1435
1470
|
cacheTime: v,
|
|
1436
1471
|
market: d.market
|
|
@@ -1440,19 +1475,19 @@ async function Ae(e, t, r) {
|
|
|
1440
1475
|
arguments: [o.object(f.storage), o.pure.address(d.address)]
|
|
1441
1476
|
});
|
|
1442
1477
|
}
|
|
1443
|
-
const m = (await
|
|
1478
|
+
const m = (await W(n, {
|
|
1444
1479
|
transactionBlock: o,
|
|
1445
1480
|
sender: e
|
|
1446
1481
|
})).results || [], w = {};
|
|
1447
1482
|
s.forEach((d, f) => {
|
|
1448
1483
|
try {
|
|
1449
|
-
const b = m[f]?.returnValues?.map((
|
|
1450
|
-
for (const
|
|
1451
|
-
|
|
1452
|
-
supplyIndex:
|
|
1453
|
-
borrowIndex:
|
|
1484
|
+
const b = m[f]?.returnValues?.map((_) => l.vector(qe).parse(Uint8Array.from(_[0])))[0] || [], j = {};
|
|
1485
|
+
for (const _ of b)
|
|
1486
|
+
j[_.id] = {
|
|
1487
|
+
supplyIndex: _.supply_index,
|
|
1488
|
+
borrowIndex: _.borrow_index
|
|
1454
1489
|
};
|
|
1455
|
-
w[d.key] =
|
|
1490
|
+
w[d.key] = j;
|
|
1456
1491
|
} catch (b) {
|
|
1457
1492
|
console.warn(
|
|
1458
1493
|
`[@naviprotocol/lending] Failed to decode reserve data for market "${d.key}", falling back to open-api pool indices`,
|
|
@@ -1460,55 +1495,55 @@ async function Ae(e, t, r) {
|
|
|
1460
1495
|
);
|
|
1461
1496
|
}
|
|
1462
1497
|
});
|
|
1463
|
-
const
|
|
1464
|
-
return
|
|
1465
|
-
const b = t[f],
|
|
1466
|
-
d.forEach((
|
|
1467
|
-
if (
|
|
1498
|
+
const g = m.slice(s.length).map((d) => d.returnValues?.map((f) => l.vector(ze).parse(Uint8Array.from(f[0])))[0] || []), y = [];
|
|
1499
|
+
return g.forEach((d, f) => {
|
|
1500
|
+
const b = t[f], j = P(b.market), _ = w[j.key] || {};
|
|
1501
|
+
d.forEach((k) => {
|
|
1502
|
+
if (k.supply_balance === "0" && k.borrow_balance === "0" && (b.emodeId === void 0 || !r?.includeZeroBalanceEmodePositions))
|
|
1468
1503
|
return;
|
|
1469
|
-
const
|
|
1470
|
-
if (!
|
|
1504
|
+
const T = c[`${j.key}-${k.asset_id}`];
|
|
1505
|
+
if (!T)
|
|
1471
1506
|
return;
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1474
|
-
supplyBalance:
|
|
1507
|
+
const $ = _[k.asset_id], D = $?.supplyIndex ?? T.currentSupplyIndex, B = $?.borrowIndex ?? T.currentBorrowIndex, X = me(k.supply_balance, D).toString(), Ve = me(k.borrow_balance, B).toString();
|
|
1508
|
+
y.push({
|
|
1509
|
+
supplyBalance: X,
|
|
1475
1510
|
borrowBalance: Ve,
|
|
1476
|
-
assetId:
|
|
1477
|
-
market:
|
|
1478
|
-
pool:
|
|
1511
|
+
assetId: k.asset_id,
|
|
1512
|
+
market: j.key,
|
|
1513
|
+
pool: T,
|
|
1479
1514
|
emodeId: b.emodeId
|
|
1480
1515
|
});
|
|
1481
1516
|
});
|
|
1482
|
-
}),
|
|
1517
|
+
}), y;
|
|
1483
1518
|
}
|
|
1484
|
-
const sr =
|
|
1519
|
+
const sr = O(
|
|
1485
1520
|
async (e, t) => {
|
|
1486
|
-
const o = (t?.markets || Object.keys(
|
|
1521
|
+
const o = (t?.markets || Object.keys(L)).map((n) => P(n)).map((n) => ({
|
|
1487
1522
|
address: e,
|
|
1488
1523
|
market: n.key
|
|
1489
1524
|
}));
|
|
1490
|
-
return await
|
|
1525
|
+
return await $e(e, o, t);
|
|
1491
1526
|
}
|
|
1492
1527
|
);
|
|
1493
1528
|
async function ur(e, t) {
|
|
1494
|
-
const r = t?.client ??
|
|
1529
|
+
const r = t?.client ?? U, o = new q();
|
|
1495
1530
|
await Bt(o, e, t);
|
|
1496
|
-
const n = await
|
|
1531
|
+
const n = await W(r, {
|
|
1497
1532
|
transactionBlock: o,
|
|
1498
1533
|
sender: e
|
|
1499
|
-
}), a =
|
|
1500
|
-
return
|
|
1534
|
+
}), a = Z(n, [l.u256()]);
|
|
1535
|
+
return Pe(Number(a[0]) || 0);
|
|
1501
1536
|
}
|
|
1502
1537
|
async function lr(e, t, r, o) {
|
|
1503
|
-
const n = o?.client ??
|
|
1538
|
+
const n = o?.client ?? U, a = new q();
|
|
1504
1539
|
let c = 0, i = 0;
|
|
1505
|
-
const s = await
|
|
1506
|
-
if (r.forEach((
|
|
1507
|
-
|
|
1540
|
+
const s = await E(t, o);
|
|
1541
|
+
if (r.forEach((g) => {
|
|
1542
|
+
g.type === H.Supply ? c += g.amount : g.type === H.Withdraw ? c -= g.amount : g.type === H.Borrow ? i += g.amount : g.type === H.Repay && (i -= g.amount);
|
|
1508
1543
|
}), c * i < 0)
|
|
1509
1544
|
throw new Error("Invalid operations");
|
|
1510
1545
|
const u = c > 0 || i > 0;
|
|
1511
|
-
await
|
|
1546
|
+
await Se(
|
|
1512
1547
|
a,
|
|
1513
1548
|
e,
|
|
1514
1549
|
s,
|
|
@@ -1517,28 +1552,28 @@ async function lr(e, t, r, o) {
|
|
|
1517
1552
|
u,
|
|
1518
1553
|
o
|
|
1519
1554
|
);
|
|
1520
|
-
const m = await
|
|
1555
|
+
const m = await W(n, {
|
|
1521
1556
|
transactionBlock: a,
|
|
1522
1557
|
sender: e
|
|
1523
|
-
}), w =
|
|
1524
|
-
return
|
|
1558
|
+
}), w = Z(m, [l.u256()]);
|
|
1559
|
+
return Pe(Number(w[0]) || 0);
|
|
1525
1560
|
}
|
|
1526
|
-
const dr =
|
|
1561
|
+
const dr = S(
|
|
1527
1562
|
async (e, t) => {
|
|
1528
1563
|
const r = new URLSearchParams();
|
|
1529
1564
|
t?.cursor && r.set("cursor", t.cursor), r.set("userAddress", e);
|
|
1530
|
-
const o =
|
|
1531
|
-
`/navi/user/transactions?${r.toString()}&sdk=${
|
|
1565
|
+
const o = M(t), n = F(
|
|
1566
|
+
`/navi/user/transactions?${r.toString()}&sdk=${V.version}`,
|
|
1532
1567
|
t
|
|
1533
1568
|
);
|
|
1534
1569
|
return (await fetch(n, {
|
|
1535
|
-
headers:
|
|
1570
|
+
headers: N(R, o)
|
|
1536
1571
|
}).then((c) => c.json())).data;
|
|
1537
1572
|
}
|
|
1538
1573
|
);
|
|
1539
1574
|
async function pr(e, t) {
|
|
1540
1575
|
let r = null;
|
|
1541
|
-
const o = [], n = t?.client ??
|
|
1576
|
+
const o = [], n = t?.client ?? U, a = n.core;
|
|
1542
1577
|
do {
|
|
1543
1578
|
let c;
|
|
1544
1579
|
if (t?.coinType)
|
|
@@ -1550,7 +1585,7 @@ async function pr(e, t) {
|
|
|
1550
1585
|
limit: 100
|
|
1551
1586
|
});
|
|
1552
1587
|
c = {
|
|
1553
|
-
data: (i.objects ?? i.data ?? []).map((s) =>
|
|
1588
|
+
data: (i.objects ?? i.data ?? []).map((s) => ye(s, t?.coinType)).filter(Boolean),
|
|
1554
1589
|
nextCursor: i.cursor ?? i.nextCursor ?? null,
|
|
1555
1590
|
hasNextPage: i.hasNextPage ?? !1
|
|
1556
1591
|
};
|
|
@@ -1587,7 +1622,7 @@ async function pr(e, t) {
|
|
|
1587
1622
|
limit: 100
|
|
1588
1623
|
});
|
|
1589
1624
|
o.push(
|
|
1590
|
-
...(w.objects ?? w.data ?? []).map((
|
|
1625
|
+
...(w.objects ?? w.data ?? []).map((g) => ye(g, u)).filter(Boolean)
|
|
1591
1626
|
), m = w.cursor ?? w.nextCursor ?? null;
|
|
1592
1627
|
} while (m);
|
|
1593
1628
|
}
|
|
@@ -1609,75 +1644,75 @@ async function pr(e, t) {
|
|
|
1609
1644
|
} while (r);
|
|
1610
1645
|
return o;
|
|
1611
1646
|
}
|
|
1612
|
-
const Pt =
|
|
1647
|
+
const Pt = O(
|
|
1613
1648
|
async (e, t) => {
|
|
1614
|
-
const r = [], o = (t?.markets || Object.keys(
|
|
1649
|
+
const r = [], o = (t?.markets || Object.keys(L)).map((i) => P(i)), n = await Ae(e, t), a = o.map((i) => ({
|
|
1615
1650
|
address: e,
|
|
1616
1651
|
market: i.key
|
|
1617
1652
|
})).concat(
|
|
1618
1653
|
n.filter((i) => !!o.find((s) => s.id === i.marketId)).map((i) => ({
|
|
1619
1654
|
address: i.accountCap,
|
|
1620
|
-
market:
|
|
1655
|
+
market: P(i.marketId).key,
|
|
1621
1656
|
emodeId: i.emodeId
|
|
1622
1657
|
}))
|
|
1623
1658
|
);
|
|
1624
|
-
return (await
|
|
1659
|
+
return (await $e(e, a, t)).forEach((i) => {
|
|
1625
1660
|
const s = typeof i.emodeId == "number" ? n.find((u) => {
|
|
1626
|
-
const m =
|
|
1661
|
+
const m = P(i.market);
|
|
1627
1662
|
return u.emodeId === i.emodeId && u.marketId === m.id;
|
|
1628
1663
|
}) : void 0;
|
|
1629
1664
|
if (s) {
|
|
1630
1665
|
if (!i.pool.emodes.find((m) => m.emodeId === s.emodeId))
|
|
1631
1666
|
return;
|
|
1632
1667
|
if (p(i.supplyBalance).gte(0)) {
|
|
1633
|
-
const m = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w =
|
|
1668
|
+
const m = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = K(i.pool, s);
|
|
1634
1669
|
if (m.gt(0) || w.emode.isCollateral)
|
|
1635
1670
|
try {
|
|
1636
1671
|
r.push({
|
|
1637
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${
|
|
1672
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${A()}`,
|
|
1638
1673
|
wallet: e,
|
|
1639
1674
|
protocol: "navi",
|
|
1640
1675
|
market: i.market,
|
|
1641
1676
|
type: "navi-lending-emode-supply",
|
|
1642
1677
|
"navi-lending-emode-supply": {
|
|
1643
1678
|
amount: m.toString(),
|
|
1644
|
-
pool:
|
|
1679
|
+
pool: K(i.pool, s),
|
|
1645
1680
|
token: i.pool.token,
|
|
1646
1681
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1647
1682
|
emodeCap: s
|
|
1648
1683
|
}
|
|
1649
1684
|
});
|
|
1650
|
-
} catch (
|
|
1651
|
-
console.error(
|
|
1685
|
+
} catch (g) {
|
|
1686
|
+
console.error(g);
|
|
1652
1687
|
}
|
|
1653
1688
|
}
|
|
1654
1689
|
if (p(i.borrowBalance).gte(0)) {
|
|
1655
|
-
const m = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w =
|
|
1690
|
+
const m = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = K(i.pool, s);
|
|
1656
1691
|
if (m.gt(0) || w.emode.isDebt)
|
|
1657
1692
|
try {
|
|
1658
1693
|
r.push({
|
|
1659
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${
|
|
1694
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${A()}`,
|
|
1660
1695
|
wallet: e,
|
|
1661
1696
|
protocol: "navi",
|
|
1662
1697
|
market: i.market,
|
|
1663
1698
|
type: "navi-lending-emode-borrow",
|
|
1664
1699
|
"navi-lending-emode-borrow": {
|
|
1665
1700
|
amount: m.toString(),
|
|
1666
|
-
pool:
|
|
1701
|
+
pool: K(i.pool, s),
|
|
1667
1702
|
token: i.pool.token,
|
|
1668
1703
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1669
1704
|
emodeCap: s
|
|
1670
1705
|
}
|
|
1671
1706
|
});
|
|
1672
|
-
} catch (
|
|
1673
|
-
console.error(
|
|
1707
|
+
} catch (g) {
|
|
1708
|
+
console.error(g);
|
|
1674
1709
|
}
|
|
1675
1710
|
}
|
|
1676
1711
|
} else {
|
|
1677
1712
|
if (p(i.supplyBalance).gt(0)) {
|
|
1678
1713
|
const u = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1679
1714
|
r.push({
|
|
1680
|
-
id: `${i.pool.uniqueId}_navi-lending-supply-${
|
|
1715
|
+
id: `${i.pool.uniqueId}_navi-lending-supply-${A()}`,
|
|
1681
1716
|
wallet: e,
|
|
1682
1717
|
protocol: "navi",
|
|
1683
1718
|
type: "navi-lending-supply",
|
|
@@ -1693,7 +1728,7 @@ const Pt = $(
|
|
|
1693
1728
|
if (p(i.borrowBalance).gt(0)) {
|
|
1694
1729
|
const u = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1695
1730
|
r.push({
|
|
1696
|
-
id: `${i.pool.uniqueId}_navi-lending-borrow-${
|
|
1731
|
+
id: `${i.pool.uniqueId}_navi-lending-borrow-${A()}`,
|
|
1697
1732
|
wallet: e,
|
|
1698
1733
|
protocol: "navi",
|
|
1699
1734
|
market: i.market,
|
|
@@ -1710,7 +1745,7 @@ const Pt = $(
|
|
|
1710
1745
|
}), r;
|
|
1711
1746
|
}
|
|
1712
1747
|
);
|
|
1713
|
-
class
|
|
1748
|
+
class G {
|
|
1714
1749
|
constructor(t, r) {
|
|
1715
1750
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1716
1751
|
hf: 1 / 0,
|
|
@@ -1750,7 +1785,7 @@ class L {
|
|
|
1750
1785
|
}
|
|
1751
1786
|
filterPositionsByPool(t) {
|
|
1752
1787
|
const o = !!t.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1753
|
-
return new
|
|
1788
|
+
return new G(
|
|
1754
1789
|
this.positions.filter((n) => {
|
|
1755
1790
|
const a = n[n.type];
|
|
1756
1791
|
return o.includes(n.type) && a.pool.uniqueId === t.uniqueId;
|
|
@@ -1762,7 +1797,7 @@ class L {
|
|
|
1762
1797
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1763
1798
|
let a;
|
|
1764
1799
|
return o ? a = {
|
|
1765
|
-
id:
|
|
1800
|
+
id: A(),
|
|
1766
1801
|
wallet: "",
|
|
1767
1802
|
protocol: "navi",
|
|
1768
1803
|
market: "",
|
|
@@ -1775,7 +1810,7 @@ class L {
|
|
|
1775
1810
|
emodeCap: {}
|
|
1776
1811
|
}
|
|
1777
1812
|
} : a = {
|
|
1778
|
-
id:
|
|
1813
|
+
id: A(),
|
|
1779
1814
|
wallet: "",
|
|
1780
1815
|
protocol: "navi",
|
|
1781
1816
|
market: "",
|
|
@@ -1786,13 +1821,13 @@ class L {
|
|
|
1786
1821
|
token: t.token,
|
|
1787
1822
|
pool: t
|
|
1788
1823
|
}
|
|
1789
|
-
}, new
|
|
1824
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1790
1825
|
}
|
|
1791
1826
|
withdraw(t, r) {
|
|
1792
1827
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1793
1828
|
let a;
|
|
1794
1829
|
return o ? a = {
|
|
1795
|
-
id:
|
|
1830
|
+
id: A(),
|
|
1796
1831
|
wallet: "",
|
|
1797
1832
|
protocol: "navi",
|
|
1798
1833
|
market: "",
|
|
@@ -1805,7 +1840,7 @@ class L {
|
|
|
1805
1840
|
emodeCap: {}
|
|
1806
1841
|
}
|
|
1807
1842
|
} : a = {
|
|
1808
|
-
id:
|
|
1843
|
+
id: A(),
|
|
1809
1844
|
wallet: "",
|
|
1810
1845
|
protocol: "navi",
|
|
1811
1846
|
market: "",
|
|
@@ -1816,13 +1851,13 @@ class L {
|
|
|
1816
1851
|
token: t.token,
|
|
1817
1852
|
pool: t
|
|
1818
1853
|
}
|
|
1819
|
-
}, new
|
|
1854
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1820
1855
|
}
|
|
1821
1856
|
borrow(t, r) {
|
|
1822
1857
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1823
1858
|
let a;
|
|
1824
1859
|
return o ? a = {
|
|
1825
|
-
id:
|
|
1860
|
+
id: A(),
|
|
1826
1861
|
wallet: "",
|
|
1827
1862
|
protocol: "navi",
|
|
1828
1863
|
market: "",
|
|
@@ -1835,7 +1870,7 @@ class L {
|
|
|
1835
1870
|
emodeCap: {}
|
|
1836
1871
|
}
|
|
1837
1872
|
} : a = {
|
|
1838
|
-
id:
|
|
1873
|
+
id: A(),
|
|
1839
1874
|
wallet: "",
|
|
1840
1875
|
protocol: "navi",
|
|
1841
1876
|
market: "",
|
|
@@ -1846,13 +1881,13 @@ class L {
|
|
|
1846
1881
|
token: t.token,
|
|
1847
1882
|
pool: t
|
|
1848
1883
|
}
|
|
1849
|
-
}, new
|
|
1884
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1850
1885
|
}
|
|
1851
1886
|
repay(t, r) {
|
|
1852
1887
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1853
1888
|
let a;
|
|
1854
1889
|
return o ? a = {
|
|
1855
|
-
id:
|
|
1890
|
+
id: A(),
|
|
1856
1891
|
wallet: "",
|
|
1857
1892
|
protocol: "navi",
|
|
1858
1893
|
market: "",
|
|
@@ -1865,7 +1900,7 @@ class L {
|
|
|
1865
1900
|
emodeCap: {}
|
|
1866
1901
|
}
|
|
1867
1902
|
} : a = {
|
|
1868
|
-
id:
|
|
1903
|
+
id: A(),
|
|
1869
1904
|
wallet: "",
|
|
1870
1905
|
protocol: "navi",
|
|
1871
1906
|
market: "",
|
|
@@ -1876,7 +1911,7 @@ class L {
|
|
|
1876
1911
|
token: t.token,
|
|
1877
1912
|
pool: t
|
|
1878
1913
|
}
|
|
1879
|
-
}, new
|
|
1914
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1880
1915
|
}
|
|
1881
1916
|
resolveValueUSD(t) {
|
|
1882
1917
|
return Object.keys(this._priceMap).length > 0 ? p(t.amount).multipliedBy(this.getPrice(t.pool)).toString() : t.valueUSD;
|
|
@@ -1884,19 +1919,19 @@ class L {
|
|
|
1884
1919
|
getPositionsOverview(t) {
|
|
1885
1920
|
const r = {}, o = {};
|
|
1886
1921
|
let n = new p(0), a = new p(0), c = new p(0), i = new p(0), s = new p(0), u = new p(0);
|
|
1887
|
-
t.forEach((
|
|
1888
|
-
if (
|
|
1889
|
-
const d =
|
|
1922
|
+
t.forEach((y) => {
|
|
1923
|
+
if (y.type === "navi-lending-supply") {
|
|
1924
|
+
const d = y["navi-lending-supply"], f = this.resolveValueUSD(d);
|
|
1890
1925
|
n = n.plus(f), s = s.plus(
|
|
1891
1926
|
new p(f).multipliedBy(d.pool.liquidationFactor.threshold)
|
|
1892
1927
|
), u = u.plus(
|
|
1893
1928
|
new p(f).multipliedBy(d.pool.ltvValue)
|
|
1894
1929
|
);
|
|
1895
|
-
} else if (
|
|
1896
|
-
const d =
|
|
1930
|
+
} else if (y.type === "navi-lending-borrow") {
|
|
1931
|
+
const d = y["navi-lending-borrow"];
|
|
1897
1932
|
a = a.plus(this.resolveValueUSD(d));
|
|
1898
|
-
} else if (
|
|
1899
|
-
const d =
|
|
1933
|
+
} else if (y.type === "navi-lending-emode-supply") {
|
|
1934
|
+
const d = y["navi-lending-emode-supply"], f = this.resolveValueUSD(d);
|
|
1900
1935
|
n = n.plus(f);
|
|
1901
1936
|
const b = d.pool.emode;
|
|
1902
1937
|
s = s.plus(
|
|
@@ -1904,28 +1939,28 @@ class L {
|
|
|
1904
1939
|
), u = u.plus(
|
|
1905
1940
|
new p(f).multipliedBy(b.ltv)
|
|
1906
1941
|
);
|
|
1907
|
-
} else if (
|
|
1908
|
-
const d =
|
|
1942
|
+
} else if (y.type === "navi-lending-emode-borrow") {
|
|
1943
|
+
const d = y["navi-lending-emode-borrow"];
|
|
1909
1944
|
a = a.plus(this.resolveValueUSD(d));
|
|
1910
1945
|
}
|
|
1911
|
-
}), a = p.max(a, 0), n = p.max(n, 0), s = p.max(s, 0), u = p.max(u, 0), t.forEach((
|
|
1912
|
-
if (
|
|
1913
|
-
const d =
|
|
1946
|
+
}), a = p.max(a, 0), n = p.max(n, 0), s = p.max(s, 0), u = p.max(u, 0), t.forEach((y) => {
|
|
1947
|
+
if (y.type === "navi-lending-supply") {
|
|
1948
|
+
const d = y["navi-lending-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
|
|
1914
1949
|
n.gt(0) && (c = c.plus(
|
|
1915
1950
|
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1916
1951
|
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1917
|
-
} else if (
|
|
1918
|
-
const d =
|
|
1952
|
+
} else if (y.type === "navi-lending-borrow") {
|
|
1953
|
+
const d = y["navi-lending-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
|
|
1919
1954
|
a.gt(0) && (i = i.plus(
|
|
1920
1955
|
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1921
1956
|
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1922
|
-
} else if (
|
|
1923
|
-
const d =
|
|
1957
|
+
} else if (y.type === "navi-lending-emode-supply") {
|
|
1958
|
+
const d = y["navi-lending-emode-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
|
|
1924
1959
|
n.gt(0) && (c = c.plus(
|
|
1925
1960
|
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1926
1961
|
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1927
|
-
} else if (
|
|
1928
|
-
const d =
|
|
1962
|
+
} else if (y.type === "navi-lending-emode-borrow") {
|
|
1963
|
+
const d = y["navi-lending-emode-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
|
|
1929
1964
|
a.gt(0) && (i = i.plus(
|
|
1930
1965
|
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1931
1966
|
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
@@ -1948,7 +1983,7 @@ class L {
|
|
|
1948
1983
|
}
|
|
1949
1984
|
}
|
|
1950
1985
|
async function mr(e, t, r, o) {
|
|
1951
|
-
const n = await
|
|
1986
|
+
const n = await I({
|
|
1952
1987
|
...o,
|
|
1953
1988
|
cacheTime: v
|
|
1954
1989
|
});
|
|
@@ -1963,12 +1998,12 @@ async function mr(e, t, r, o) {
|
|
|
1963
1998
|
]
|
|
1964
1999
|
});
|
|
1965
2000
|
}
|
|
1966
|
-
const
|
|
2001
|
+
const Ee = new Ie("https://hermes.pyth.network", {
|
|
1967
2002
|
timeout: 1e4
|
|
1968
2003
|
});
|
|
1969
2004
|
async function fr(e) {
|
|
1970
2005
|
try {
|
|
1971
|
-
const t = [], r = await
|
|
2006
|
+
const t = [], r = await Ee.getLatestPriceFeeds(e);
|
|
1972
2007
|
if (!r) return t;
|
|
1973
2008
|
const o = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1974
2009
|
for (const n of r) {
|
|
@@ -1989,7 +2024,7 @@ async function fr(e) {
|
|
|
1989
2024
|
}
|
|
1990
2025
|
}
|
|
1991
2026
|
async function At(e, t) {
|
|
1992
|
-
const r = [], o = t?.client ??
|
|
2027
|
+
const r = [], o = t?.client ?? U, n = e.map((c) => c.priceInfoObject), a = await gt(o, {
|
|
1993
2028
|
ids: Array.from(new Set(n)),
|
|
1994
2029
|
options: { showContent: !0 }
|
|
1995
2030
|
});
|
|
@@ -2009,12 +2044,12 @@ async function At(e, t) {
|
|
|
2009
2044
|
console.warn(`unexpected pyth price struct, priceInfoObject: ${i.objectId}`);
|
|
2010
2045
|
continue;
|
|
2011
2046
|
}
|
|
2012
|
-
const { magnitude: w, negative:
|
|
2047
|
+
const { magnitude: w, negative: g } = m, y = u.conf, d = u.timestamp;
|
|
2013
2048
|
r.push({
|
|
2014
2049
|
priceFeedId: s.priceFeedId,
|
|
2015
2050
|
priceInfoObject: s.priceInfoObject,
|
|
2016
|
-
price:
|
|
2017
|
-
conf:
|
|
2051
|
+
price: g ? "-" + w : w,
|
|
2052
|
+
conf: y,
|
|
2018
2053
|
publishTime: Number(d),
|
|
2019
2054
|
expiration: s.expiration
|
|
2020
2055
|
});
|
|
@@ -2044,12 +2079,12 @@ async function St(e, t) {
|
|
|
2044
2079
|
}
|
|
2045
2080
|
}
|
|
2046
2081
|
async function $t(e, t, r) {
|
|
2047
|
-
const o = r?.client ??
|
|
2082
|
+
const o = r?.client ?? U, n = await I({
|
|
2048
2083
|
...r,
|
|
2049
2084
|
cacheTime: v
|
|
2050
2085
|
});
|
|
2051
2086
|
try {
|
|
2052
|
-
const a = await
|
|
2087
|
+
const a = await Ee.getPriceFeedsUpdateData(t);
|
|
2053
2088
|
return await new lt(
|
|
2054
2089
|
o,
|
|
2055
2090
|
n.oracle.pythStateId,
|
|
@@ -2059,8 +2094,8 @@ async function $t(e, t, r) {
|
|
|
2059
2094
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
2060
2095
|
}
|
|
2061
2096
|
}
|
|
2062
|
-
async function
|
|
2063
|
-
const o = await
|
|
2097
|
+
async function ge(e, t, r) {
|
|
2098
|
+
const o = await I({
|
|
2064
2099
|
...r,
|
|
2065
2100
|
cacheTime: v
|
|
2066
2101
|
});
|
|
@@ -2093,8 +2128,8 @@ async function fe(e, t, r) {
|
|
|
2093
2128
|
});
|
|
2094
2129
|
return e;
|
|
2095
2130
|
}
|
|
2096
|
-
async function
|
|
2097
|
-
return (await
|
|
2131
|
+
async function Oe(e) {
|
|
2132
|
+
return (await I({
|
|
2098
2133
|
...e,
|
|
2099
2134
|
cacheTime: v
|
|
2100
2135
|
})).oracle.feeds;
|
|
@@ -2115,7 +2150,7 @@ function Et(e, t) {
|
|
|
2115
2150
|
async function yr(e, t, r, o) {
|
|
2116
2151
|
let n;
|
|
2117
2152
|
try {
|
|
2118
|
-
const a = await
|
|
2153
|
+
const a = await Oe({
|
|
2119
2154
|
...o
|
|
2120
2155
|
}), c = [];
|
|
2121
2156
|
r.forEach((u) => {
|
|
@@ -2128,7 +2163,7 @@ async function yr(e, t, r, o) {
|
|
|
2128
2163
|
return n = Et(a, {
|
|
2129
2164
|
lendingPositions: i,
|
|
2130
2165
|
pools: r
|
|
2131
|
-
}), await
|
|
2166
|
+
}), await ge(e, n, {
|
|
2132
2167
|
updatePythPriceFeeds: !0,
|
|
2133
2168
|
...o
|
|
2134
2169
|
});
|
|
@@ -2137,7 +2172,7 @@ async function yr(e, t, r, o) {
|
|
|
2137
2172
|
throw a;
|
|
2138
2173
|
if (console.error(a), n)
|
|
2139
2174
|
try {
|
|
2140
|
-
return await
|
|
2175
|
+
return await ge(e, n, {
|
|
2141
2176
|
...o,
|
|
2142
2177
|
updatePythPriceFeeds: !1
|
|
2143
2178
|
});
|
|
@@ -2147,14 +2182,14 @@ async function yr(e, t, r, o) {
|
|
|
2147
2182
|
return e;
|
|
2148
2183
|
}
|
|
2149
2184
|
}
|
|
2150
|
-
const
|
|
2151
|
-
|
|
2185
|
+
const ae = O(
|
|
2186
|
+
S(
|
|
2152
2187
|
async (e) => {
|
|
2153
|
-
const t =
|
|
2154
|
-
`/navi/flashloan?env=${e?.env || "prod"}&sdk=${
|
|
2188
|
+
const t = M(e), r = F(
|
|
2189
|
+
`/navi/flashloan?env=${e?.env || "prod"}&sdk=${V.version}&market=${e?.market || z}`,
|
|
2155
2190
|
e
|
|
2156
2191
|
), o = await fetch(r, {
|
|
2157
|
-
headers:
|
|
2192
|
+
headers: N(R, t)
|
|
2158
2193
|
}).then((n) => n.json());
|
|
2159
2194
|
return Object.keys(o.data).map((n) => ({
|
|
2160
2195
|
...o.data[n],
|
|
@@ -2164,14 +2199,14 @@ const ne = $(
|
|
|
2164
2199
|
)
|
|
2165
2200
|
);
|
|
2166
2201
|
async function gr(e, t) {
|
|
2167
|
-
return (await
|
|
2202
|
+
return (await ae(t)).find((o) => typeof e == "string" ? C(o.coinType) === C(e) : typeof e == "number" ? o.assetId === e : o.assetId === e.id) || null;
|
|
2168
2203
|
}
|
|
2169
2204
|
async function hr(e, t, r, o) {
|
|
2170
|
-
const n = await
|
|
2205
|
+
const n = await I({
|
|
2171
2206
|
...o,
|
|
2172
2207
|
cacheTime: v
|
|
2173
|
-
}), a = await
|
|
2174
|
-
if (!(await
|
|
2208
|
+
}), a = await E(t, o);
|
|
2209
|
+
if (!(await ae({
|
|
2175
2210
|
...o,
|
|
2176
2211
|
cacheTime: v
|
|
2177
2212
|
})).some(
|
|
@@ -2204,11 +2239,11 @@ async function hr(e, t, r, o) {
|
|
|
2204
2239
|
}
|
|
2205
2240
|
}
|
|
2206
2241
|
async function wr(e, t, r, o, n) {
|
|
2207
|
-
const a = await
|
|
2242
|
+
const a = await I({
|
|
2208
2243
|
...n,
|
|
2209
2244
|
cacheTime: v
|
|
2210
|
-
}), c = await
|
|
2211
|
-
if (!(await
|
|
2245
|
+
}), c = await E(t, n);
|
|
2246
|
+
if (!(await ae({
|
|
2212
2247
|
...n,
|
|
2213
2248
|
cacheTime: v
|
|
2214
2249
|
})).some(
|
|
@@ -2232,7 +2267,7 @@ async function br(e, t, r, o, n, a) {
|
|
|
2232
2267
|
const c = {
|
|
2233
2268
|
...a,
|
|
2234
2269
|
cacheTime: v
|
|
2235
|
-
}, i = await
|
|
2270
|
+
}, i = await I(c), s = await E(t, c), u = await E(o, c);
|
|
2236
2271
|
if (i.version === 1) {
|
|
2237
2272
|
const [m, w] = e.moveCall({
|
|
2238
2273
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
@@ -2298,19 +2333,19 @@ async function br(e, t, r, o, n, a) {
|
|
|
2298
2333
|
}
|
|
2299
2334
|
}
|
|
2300
2335
|
async function Ot(e, t, r) {
|
|
2301
|
-
const o = r?.client ??
|
|
2336
|
+
const o = r?.client ?? U, n = await J({
|
|
2302
2337
|
...r,
|
|
2303
|
-
markets: Object.values(
|
|
2338
|
+
markets: Object.values(L),
|
|
2304
2339
|
cacheTime: v
|
|
2305
|
-
}), a = await
|
|
2340
|
+
}), a = await Oe(r), c = [];
|
|
2306
2341
|
return await Promise.all(
|
|
2307
2342
|
t.map(async (i) => {
|
|
2308
2343
|
try {
|
|
2309
|
-
const s = await
|
|
2344
|
+
const s = await I({
|
|
2310
2345
|
...r,
|
|
2311
2346
|
cacheTime: v,
|
|
2312
2347
|
market: i.market
|
|
2313
|
-
}), u = new
|
|
2348
|
+
}), u = new q();
|
|
2314
2349
|
u.moveCall({
|
|
2315
2350
|
target: `${s.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
2316
2351
|
arguments: [
|
|
@@ -2324,13 +2359,13 @@ async function Ot(e, t, r) {
|
|
|
2324
2359
|
// User address
|
|
2325
2360
|
]
|
|
2326
2361
|
});
|
|
2327
|
-
const w = (await
|
|
2362
|
+
const w = (await W(o, {
|
|
2328
2363
|
transactionBlock: u,
|
|
2329
2364
|
sender: e
|
|
2330
2365
|
}))?.results?.[0];
|
|
2331
2366
|
if (!w)
|
|
2332
2367
|
return;
|
|
2333
|
-
const
|
|
2368
|
+
const g = Z({ results: [w] }, [
|
|
2334
2369
|
l.vector(l.string()),
|
|
2335
2370
|
// Asset coin types
|
|
2336
2371
|
l.vector(l.string()),
|
|
@@ -2342,21 +2377,21 @@ async function Ot(e, t, r) {
|
|
|
2342
2377
|
l.vector(l.u256())
|
|
2343
2378
|
// Claimable amounts
|
|
2344
2379
|
]);
|
|
2345
|
-
if (
|
|
2346
|
-
const
|
|
2347
|
-
for (let d = 0; d <
|
|
2380
|
+
if (g.length === 5 && Array.isArray(g[0])) {
|
|
2381
|
+
const y = g[0].length;
|
|
2382
|
+
for (let d = 0; d < y; d++) {
|
|
2348
2383
|
const f = a.find(
|
|
2349
|
-
(
|
|
2384
|
+
(j) => C(j.coinType) === C(g[1][d])
|
|
2350
2385
|
), b = n.find(
|
|
2351
|
-
(
|
|
2386
|
+
(j) => C(j.coinType) === C(g[0][d]) && j.market === i.market
|
|
2352
2387
|
);
|
|
2353
2388
|
!f || !b || c.push({
|
|
2354
2389
|
assetId: b.id,
|
|
2355
|
-
assetCoinType: C(
|
|
2356
|
-
rewardCoinType: C(
|
|
2357
|
-
option: Number(
|
|
2358
|
-
userClaimableReward: Number(
|
|
2359
|
-
ruleIds: Array.isArray(
|
|
2390
|
+
assetCoinType: C(g[0][d]),
|
|
2391
|
+
rewardCoinType: C(g[1][d]),
|
|
2392
|
+
option: Number(g[2][d]),
|
|
2393
|
+
userClaimableReward: Number(g[4][d]) / Math.pow(10, f.priceDecimal),
|
|
2394
|
+
ruleIds: Array.isArray(g[3][d]) ? g[3][d] : [g[3][d]],
|
|
2360
2395
|
market: i.market,
|
|
2361
2396
|
owner: i.owner,
|
|
2362
2397
|
address: i.address,
|
|
@@ -2374,13 +2409,13 @@ async function Ot(e, t, r) {
|
|
|
2374
2409
|
), c;
|
|
2375
2410
|
}
|
|
2376
2411
|
async function vr(e, t) {
|
|
2377
|
-
const r = (t?.markets || [
|
|
2412
|
+
const r = (t?.markets || [L.main]).map((a) => P(a)), o = await Ae(e, t), n = r.map((a) => ({
|
|
2378
2413
|
address: e,
|
|
2379
2414
|
owner: e,
|
|
2380
2415
|
market: a.key
|
|
2381
2416
|
})).concat(
|
|
2382
2417
|
o.filter((a) => !!r.find((c) => c.id === a.marketId)).map((a) => {
|
|
2383
|
-
const c =
|
|
2418
|
+
const c = P(a.marketId);
|
|
2384
2419
|
return {
|
|
2385
2420
|
address: a.accountCap,
|
|
2386
2421
|
owner: e,
|
|
@@ -2420,72 +2455,72 @@ function Cr(e) {
|
|
|
2420
2455
|
}))
|
|
2421
2456
|
}));
|
|
2422
2457
|
}
|
|
2423
|
-
const jr =
|
|
2458
|
+
const jr = S(
|
|
2424
2459
|
async (e, t) => {
|
|
2425
|
-
const r =
|
|
2426
|
-
`/navi/user/total_claimed_reward?userAddress=${e}&sdk=${
|
|
2460
|
+
const r = M(t), o = F(
|
|
2461
|
+
`/navi/user/total_claimed_reward?userAddress=${e}&sdk=${V.version}&market=${t?.market || z}`,
|
|
2427
2462
|
t
|
|
2428
2463
|
);
|
|
2429
2464
|
return (await fetch(o, {
|
|
2430
|
-
headers:
|
|
2465
|
+
headers: N(R, r)
|
|
2431
2466
|
}).then((a) => a.json())).data;
|
|
2432
2467
|
}
|
|
2433
|
-
),
|
|
2468
|
+
), Ir = S(
|
|
2434
2469
|
async (e, t) => {
|
|
2435
|
-
const r =
|
|
2436
|
-
`/navi/user/rewards?userAddress=${e}&page=${t?.page || 1}&pageSize=${t?.size || 400}&sdk=${
|
|
2470
|
+
const r = M(t), o = F(
|
|
2471
|
+
`/navi/user/rewards?userAddress=${e}&page=${t?.page || 1}&pageSize=${t?.size || 400}&sdk=${V.version}&market=${t?.market || z}`,
|
|
2437
2472
|
t
|
|
2438
2473
|
), n = await fetch(o, {
|
|
2439
|
-
headers:
|
|
2474
|
+
headers: N(R, r)
|
|
2440
2475
|
}).then((a) => a.json());
|
|
2441
|
-
return
|
|
2476
|
+
return re({
|
|
2442
2477
|
data: n.data.rewards
|
|
2443
2478
|
});
|
|
2444
2479
|
}
|
|
2445
2480
|
);
|
|
2446
|
-
async function
|
|
2447
|
-
const o = await
|
|
2481
|
+
async function kr(e, t, r) {
|
|
2482
|
+
const o = await J({
|
|
2448
2483
|
...r,
|
|
2449
|
-
markets: Object.values(
|
|
2484
|
+
markets: Object.values(L),
|
|
2450
2485
|
cacheTime: v
|
|
2451
2486
|
}), n = /* @__PURE__ */ new Map();
|
|
2452
2487
|
for (const c of t) {
|
|
2453
|
-
const { rewardCoinType: i, ruleIds: s, market: u, owner: m, address: w, emodeId:
|
|
2488
|
+
const { rewardCoinType: i, ruleIds: s, market: u, owner: m, address: w, emodeId: g } = c, y = `${i}___${w}__${u}`;
|
|
2454
2489
|
for (const d of s) {
|
|
2455
|
-
n.has(
|
|
2490
|
+
n.has(y) || n.set(y, {
|
|
2456
2491
|
assetIds: [],
|
|
2457
2492
|
ruleIds: [],
|
|
2458
2493
|
amount: 0,
|
|
2459
2494
|
market: u,
|
|
2460
2495
|
owner: m,
|
|
2461
2496
|
address: w,
|
|
2462
|
-
isEMode: typeof
|
|
2497
|
+
isEMode: typeof g < "u"
|
|
2463
2498
|
});
|
|
2464
|
-
const f = n.get(
|
|
2499
|
+
const f = n.get(y);
|
|
2465
2500
|
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(d), f.amount += c.userClaimableReward;
|
|
2466
2501
|
}
|
|
2467
2502
|
}
|
|
2468
2503
|
const a = [];
|
|
2469
2504
|
for (const [
|
|
2470
2505
|
c,
|
|
2471
|
-
{ assetIds: i, ruleIds: s, amount: u, market: m, owner: w, address:
|
|
2506
|
+
{ assetIds: i, ruleIds: s, amount: u, market: m, owner: w, address: g, isEMode: y }
|
|
2472
2507
|
] of n) {
|
|
2473
|
-
const d = await
|
|
2508
|
+
const d = await I({
|
|
2474
2509
|
...r,
|
|
2475
2510
|
cacheTime: v,
|
|
2476
2511
|
market: m
|
|
2477
2512
|
}), f = c.split("___")[0], b = o.filter(
|
|
2478
|
-
(
|
|
2513
|
+
(k) => C(k.suiCoinType) === C(f)
|
|
2479
2514
|
);
|
|
2480
|
-
b.sort((
|
|
2481
|
-
const
|
|
2482
|
-
if (!
|
|
2515
|
+
b.sort((k, T) => k.market === m ? -1 : 1);
|
|
2516
|
+
const j = b[0], _ = d.rewardFunds[C(f)];
|
|
2517
|
+
if (!_)
|
|
2483
2518
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${m}`);
|
|
2484
2519
|
if (r?.accountCap && !r.customCoinReceive)
|
|
2485
2520
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
2486
2521
|
if (r?.customCoinReceive) {
|
|
2487
|
-
let
|
|
2488
|
-
r.accountCap ?
|
|
2522
|
+
let k;
|
|
2523
|
+
r.accountCap ? k = e.moveCall({
|
|
2489
2524
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2490
2525
|
arguments: [
|
|
2491
2526
|
e.object("0x06"),
|
|
@@ -2494,7 +2529,7 @@ async function Ir(e, t, r) {
|
|
|
2494
2529
|
// Incentive V3 contract
|
|
2495
2530
|
e.object(d.storage),
|
|
2496
2531
|
// Protocol storage
|
|
2497
|
-
e.object(
|
|
2532
|
+
e.object(_),
|
|
2498
2533
|
// Reward fund
|
|
2499
2534
|
e.pure.vector("string", i),
|
|
2500
2535
|
// Asset IDs
|
|
@@ -2504,7 +2539,7 @@ async function Ir(e, t, r) {
|
|
|
2504
2539
|
// Account capability
|
|
2505
2540
|
],
|
|
2506
2541
|
typeArguments: [f]
|
|
2507
|
-
}) :
|
|
2542
|
+
}) : y ? k = e.moveCall({
|
|
2508
2543
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2509
2544
|
arguments: [
|
|
2510
2545
|
e.object("0x06"),
|
|
@@ -2513,17 +2548,17 @@ async function Ir(e, t, r) {
|
|
|
2513
2548
|
// Incentive V3 contract
|
|
2514
2549
|
e.object(d.storage),
|
|
2515
2550
|
// Protocol storage
|
|
2516
|
-
e.object(
|
|
2551
|
+
e.object(_),
|
|
2517
2552
|
// Reward fund
|
|
2518
2553
|
e.pure.vector("string", i),
|
|
2519
2554
|
// Asset IDs
|
|
2520
2555
|
e.pure.vector("address", s),
|
|
2521
2556
|
// Rule IDs
|
|
2522
|
-
h(
|
|
2557
|
+
h(g, e.object)
|
|
2523
2558
|
// Account capability
|
|
2524
2559
|
],
|
|
2525
2560
|
typeArguments: [f]
|
|
2526
|
-
}) :
|
|
2561
|
+
}) : k = e.moveCall({
|
|
2527
2562
|
target: `${d.package}::incentive_v3::claim_reward`,
|
|
2528
2563
|
arguments: [
|
|
2529
2564
|
e.object("0x06"),
|
|
@@ -2532,7 +2567,7 @@ async function Ir(e, t, r) {
|
|
|
2532
2567
|
// Incentive V3 contract
|
|
2533
2568
|
e.object(d.storage),
|
|
2534
2569
|
// Protocol storage
|
|
2535
|
-
e.object(
|
|
2570
|
+
e.object(_),
|
|
2536
2571
|
// Reward fund
|
|
2537
2572
|
e.pure.vector("string", i),
|
|
2538
2573
|
// Asset IDs
|
|
@@ -2541,37 +2576,37 @@ async function Ir(e, t, r) {
|
|
|
2541
2576
|
],
|
|
2542
2577
|
typeArguments: [f]
|
|
2543
2578
|
});
|
|
2544
|
-
const [
|
|
2579
|
+
const [T] = e.moveCall({
|
|
2545
2580
|
target: "0x2::coin::from_balance",
|
|
2546
|
-
arguments: [
|
|
2581
|
+
arguments: [k],
|
|
2547
2582
|
typeArguments: [f]
|
|
2548
2583
|
});
|
|
2549
2584
|
if (r?.customCoinReceive.type === "transfer") {
|
|
2550
2585
|
if (!r.customCoinReceive.transfer)
|
|
2551
2586
|
throw new Error("customCoinReceive.transfer is required");
|
|
2552
2587
|
e.transferObjects(
|
|
2553
|
-
[
|
|
2588
|
+
[T],
|
|
2554
2589
|
h(r.customCoinReceive.transfer, e.pure.address)
|
|
2555
2590
|
);
|
|
2556
2591
|
}
|
|
2557
2592
|
if (r?.customCoinReceive.type === "depositNAVI") {
|
|
2558
|
-
const
|
|
2559
|
-
|
|
2560
|
-
[
|
|
2593
|
+
const $ = p(j.totalSupplyAmount).shiftedBy(-9), D = p(j.supplyCapCeiling).shiftedBy(-27);
|
|
2594
|
+
$.plus(u).isGreaterThan(D) && r?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
2595
|
+
[T],
|
|
2561
2596
|
e.pure.address(r.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
2562
|
-
) : await vt(e,
|
|
2597
|
+
) : await vt(e, j, T, {
|
|
2563
2598
|
...r,
|
|
2564
|
-
market:
|
|
2599
|
+
market: j.market
|
|
2565
2600
|
});
|
|
2566
2601
|
} else
|
|
2567
2602
|
a.push({
|
|
2568
|
-
coin:
|
|
2569
|
-
identifier:
|
|
2603
|
+
coin: T,
|
|
2604
|
+
identifier: j,
|
|
2570
2605
|
owner: w,
|
|
2571
|
-
isEMode:
|
|
2606
|
+
isEMode: y
|
|
2572
2607
|
});
|
|
2573
|
-
} else if (r?.accountCap ||
|
|
2574
|
-
const
|
|
2608
|
+
} else if (r?.accountCap || y) {
|
|
2609
|
+
const k = e.moveCall({
|
|
2575
2610
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2576
2611
|
arguments: [
|
|
2577
2612
|
e.object("0x06"),
|
|
@@ -2580,23 +2615,23 @@ async function Ir(e, t, r) {
|
|
|
2580
2615
|
// Incentive V3 contract
|
|
2581
2616
|
e.object(d.storage),
|
|
2582
2617
|
// Protocol storage
|
|
2583
|
-
e.object(
|
|
2618
|
+
e.object(_),
|
|
2584
2619
|
// Reward fund
|
|
2585
2620
|
e.pure.vector("string", i),
|
|
2586
2621
|
// Asset IDs
|
|
2587
2622
|
e.pure.vector("address", s),
|
|
2588
2623
|
// Rule IDs
|
|
2589
|
-
h(r?.accountCap ||
|
|
2624
|
+
h(r?.accountCap || g, e.object)
|
|
2590
2625
|
// Account capability
|
|
2591
2626
|
],
|
|
2592
2627
|
typeArguments: [f]
|
|
2593
|
-
}), [
|
|
2628
|
+
}), [T] = e.moveCall({
|
|
2594
2629
|
target: "0x2::coin::from_balance",
|
|
2595
|
-
arguments: [
|
|
2630
|
+
arguments: [k],
|
|
2596
2631
|
typeArguments: [f]
|
|
2597
2632
|
});
|
|
2598
2633
|
e.transferObjects(
|
|
2599
|
-
[
|
|
2634
|
+
[T],
|
|
2600
2635
|
h(r?.accountCap || w, e.pure.address)
|
|
2601
2636
|
);
|
|
2602
2637
|
} else
|
|
@@ -2609,7 +2644,7 @@ async function Ir(e, t, r) {
|
|
|
2609
2644
|
// Incentive V3 contract
|
|
2610
2645
|
e.object(d.storage),
|
|
2611
2646
|
// Protocol storage
|
|
2612
|
-
e.object(
|
|
2647
|
+
e.object(_),
|
|
2613
2648
|
// Reward fund
|
|
2614
2649
|
e.pure.vector("string", i),
|
|
2615
2650
|
// Asset IDs
|
|
@@ -2622,31 +2657,31 @@ async function Ir(e, t, r) {
|
|
|
2622
2657
|
return a;
|
|
2623
2658
|
}
|
|
2624
2659
|
export {
|
|
2625
|
-
|
|
2660
|
+
ie as Address,
|
|
2626
2661
|
v as DEFAULT_CACHE_TIME,
|
|
2627
|
-
|
|
2662
|
+
z as DEFAULT_MARKET_IDENTITY,
|
|
2628
2663
|
Wt as FlashLoanAssetConfig,
|
|
2629
2664
|
qt as IncentiveAPYInfo,
|
|
2630
2665
|
Le as IncentivePoolInfo,
|
|
2631
2666
|
zt as IncentivePoolInfoByPhase,
|
|
2632
|
-
|
|
2667
|
+
L as MARKETS,
|
|
2633
2668
|
Ct as Market,
|
|
2634
2669
|
Ke as NaviMissingGraphQLClientError,
|
|
2635
2670
|
Gt as OracleInfo,
|
|
2636
2671
|
et as PUBLIC_MAINNET_GRPC_URL,
|
|
2637
|
-
|
|
2672
|
+
H as PoolOperator,
|
|
2638
2673
|
qe as ReserveDataInfo,
|
|
2639
|
-
|
|
2674
|
+
Ie as SuiPriceServiceConnection,
|
|
2640
2675
|
lt as SuiPythClient,
|
|
2641
|
-
|
|
2676
|
+
G as UserPositions,
|
|
2642
2677
|
ze as UserStateInfo,
|
|
2643
2678
|
er as borrowCoinPTB,
|
|
2644
|
-
|
|
2645
|
-
|
|
2679
|
+
F as buildNaviOpenApiUrl,
|
|
2680
|
+
kr as claimLendingRewardsPTB,
|
|
2646
2681
|
Yt as configureNaviSdk,
|
|
2647
|
-
|
|
2682
|
+
It as createAccountCapPTB,
|
|
2648
2683
|
ar as createEModeCapPTB,
|
|
2649
|
-
|
|
2684
|
+
je as createNaviLegacyJsonRpcClient,
|
|
2650
2685
|
rt as createNaviSuiClient,
|
|
2651
2686
|
xe as createNaviSuiClientBundle,
|
|
2652
2687
|
vt as depositCoinPTB,
|
|
@@ -2655,13 +2690,13 @@ export {
|
|
|
2655
2690
|
or as exitEModePTB,
|
|
2656
2691
|
Et as filterPriceFeeds,
|
|
2657
2692
|
hr as flashloanPTB,
|
|
2658
|
-
|
|
2693
|
+
kt as getAccountCapOwnerPTB,
|
|
2659
2694
|
Jt as getAddressBalance,
|
|
2660
|
-
|
|
2695
|
+
ae as getAllFlashLoanAssets,
|
|
2661
2696
|
rr as getBorrowFee,
|
|
2662
2697
|
Ht as getCoinObjectOnlyBalance,
|
|
2663
2698
|
pr as getCoins,
|
|
2664
|
-
|
|
2699
|
+
I as getConfig,
|
|
2665
2700
|
Xt as getFees,
|
|
2666
2701
|
gr as getFlashLoanAsset,
|
|
2667
2702
|
ur as getHealthFactor,
|
|
@@ -2669,40 +2704,40 @@ export {
|
|
|
2669
2704
|
Pt as getLendingPositions,
|
|
2670
2705
|
sr as getLendingState,
|
|
2671
2706
|
nr as getMarket,
|
|
2672
|
-
|
|
2707
|
+
P as getMarketConfig,
|
|
2673
2708
|
jt as getMarkets,
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2709
|
+
E as getPool,
|
|
2710
|
+
J as getPools,
|
|
2711
|
+
Oe as getPriceFeeds,
|
|
2677
2712
|
fr as getPythStalePriceFeedId,
|
|
2678
2713
|
St as getPythStalePriceFeedIdV2,
|
|
2679
2714
|
lr as getSimulatedHealthFactor,
|
|
2680
|
-
|
|
2715
|
+
Se as getSimulatedHealthFactorPTB,
|
|
2681
2716
|
Zt as getStats,
|
|
2682
2717
|
dr as getTransactions,
|
|
2683
2718
|
vr as getUserAvailableLendingRewards,
|
|
2684
|
-
|
|
2685
|
-
|
|
2719
|
+
Ir as getUserClaimedRewardHistory,
|
|
2720
|
+
Ae as getUserEModeCaps,
|
|
2686
2721
|
jr as getUserTotalClaimedReward,
|
|
2687
2722
|
br as liquidatePTB,
|
|
2688
2723
|
Kt as listAddressBalances,
|
|
2689
2724
|
cr as mergeCoinsPTB,
|
|
2690
|
-
|
|
2691
|
-
|
|
2725
|
+
N as mergeServiceHeaders,
|
|
2726
|
+
Ce as normalizeAddressBalance,
|
|
2692
2727
|
C as normalizeCoinType,
|
|
2693
2728
|
bt as parsePoolUID,
|
|
2694
2729
|
h as parseTxValue,
|
|
2695
2730
|
tr as repayCoinPTB,
|
|
2696
2731
|
wr as repayFlashLoanPTB,
|
|
2697
2732
|
Qt as requireNaviGraphQLClient,
|
|
2698
|
-
|
|
2733
|
+
M as resolveNaviOpenApiEndpoint,
|
|
2699
2734
|
Cr as summaryLendingRewards,
|
|
2700
2735
|
yr as updateOraclePriceBeforeUserOperationPTB,
|
|
2701
|
-
|
|
2736
|
+
ge as updateOraclePricesPTB,
|
|
2702
2737
|
$t as updatePythPriceFeeds,
|
|
2703
2738
|
mr as verifyHealthFactorPTB,
|
|
2704
|
-
|
|
2705
|
-
|
|
2739
|
+
O as withCache,
|
|
2740
|
+
S as withSingleton,
|
|
2706
2741
|
xt as withdrawCoinPTB
|
|
2707
2742
|
};
|
|
2708
2743
|
//# sourceMappingURL=index.esm.js.map
|