@naviprotocol/lending 2.0.4 → 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 +430 -404
- package/dist/index.esm.js.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
|
|
@@ -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,13 +498,13 @@ 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
503
|
const { id: o, fieldType: n } = await this.getPriceTableInfo(), a = `${n}::price_identifier::PriceIdentifier`, c = this.getCoreProvider();
|
|
504
504
|
if (c) {
|
|
505
505
|
const { dynamicField: i } = await c.getDynamicField({
|
|
506
506
|
parentId: o,
|
|
507
|
-
name:
|
|
507
|
+
name: le(a, it(se(r)))
|
|
508
508
|
}), s = i?.value?.bcs;
|
|
509
509
|
this.priceFeedObjectIdCache.set(
|
|
510
510
|
r,
|
|
@@ -514,7 +514,7 @@ class lt {
|
|
|
514
514
|
const i = await this.getDynamicMoveObjectJson(o, {
|
|
515
515
|
type: a,
|
|
516
516
|
value: {
|
|
517
|
-
bytes: Array.from(
|
|
517
|
+
bytes: Array.from(se(r))
|
|
518
518
|
}
|
|
519
519
|
});
|
|
520
520
|
i?.fields ? this.priceFeedObjectIdCache.set(r, i.fields.value) : this.priceFeedObjectIdCache.set(r, void 0);
|
|
@@ -524,7 +524,7 @@ class lt {
|
|
|
524
524
|
}
|
|
525
525
|
async getPriceTableInfo() {
|
|
526
526
|
if (!this.priceTableInfo) {
|
|
527
|
-
const t = this.getCoreProvider() ?
|
|
527
|
+
const t = this.getCoreProvider() ? le("vector<u8>", at("price_info")) : {
|
|
528
528
|
type: "vector<u8>",
|
|
529
529
|
value: "price_info"
|
|
530
530
|
}, r = await this.getDynamicMoveObjectJson(this.pythStateId, t);
|
|
@@ -543,32 +543,32 @@ class lt {
|
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
const dt = "https://open-api.naviprotocol.io/api";
|
|
546
|
-
let
|
|
546
|
+
let Q = {}, ke = 0;
|
|
547
547
|
function pt(e) {
|
|
548
548
|
return e.replace(/\/+$/, "");
|
|
549
549
|
}
|
|
550
550
|
function Yt(e) {
|
|
551
|
-
|
|
552
|
-
...
|
|
551
|
+
Q = {
|
|
552
|
+
...Q,
|
|
553
553
|
...e,
|
|
554
554
|
services: {
|
|
555
|
-
...
|
|
555
|
+
...Q.services,
|
|
556
556
|
...e.services
|
|
557
557
|
}
|
|
558
|
-
},
|
|
558
|
+
}, ke += 1;
|
|
559
559
|
}
|
|
560
|
-
function
|
|
561
|
-
return
|
|
560
|
+
function de() {
|
|
561
|
+
return ke;
|
|
562
562
|
}
|
|
563
|
-
function
|
|
564
|
-
const t = e?.services?.naviOpenApi ??
|
|
563
|
+
function M(e) {
|
|
564
|
+
const t = e?.services?.naviOpenApi ?? Q.services?.naviOpenApi;
|
|
565
565
|
return {
|
|
566
566
|
baseUrl: pt(t?.baseUrl ?? dt),
|
|
567
567
|
headers: t?.headers
|
|
568
568
|
};
|
|
569
569
|
}
|
|
570
|
-
function
|
|
571
|
-
const r =
|
|
570
|
+
function F(e, t) {
|
|
571
|
+
const r = M(t), o = e.startsWith("/") ? e : `/${e}`;
|
|
572
572
|
return `${r.baseUrl}${o}`;
|
|
573
573
|
}
|
|
574
574
|
function mt(e) {
|
|
@@ -580,14 +580,14 @@ function mt(e) {
|
|
|
580
580
|
}
|
|
581
581
|
return Array.isArray(e) ? Object.fromEntries(e) : e;
|
|
582
582
|
}
|
|
583
|
-
function
|
|
583
|
+
function N(e, t) {
|
|
584
584
|
return {
|
|
585
585
|
...mt(e),
|
|
586
586
|
...t?.headers ?? {}
|
|
587
587
|
};
|
|
588
588
|
}
|
|
589
|
-
const
|
|
590
|
-
function
|
|
589
|
+
const U = rt();
|
|
590
|
+
function pe(e) {
|
|
591
591
|
return e ? e instanceof Uint8Array ? Array.from(e) : Array.isArray(e) ? e : Array.from(De(e)) : [];
|
|
592
592
|
}
|
|
593
593
|
function ft(e) {
|
|
@@ -597,21 +597,21 @@ function ft(e) {
|
|
|
597
597
|
events: r.events,
|
|
598
598
|
error: o,
|
|
599
599
|
results: t.map((n) => ({
|
|
600
|
-
returnValues: (n.returnValues ?? []).map((a) => [
|
|
600
|
+
returnValues: (n.returnValues ?? []).map((a) => [pe(a.bcs), ""]),
|
|
601
601
|
mutableReferenceOutputs: (n.mutatedReferences ?? []).map((a) => [
|
|
602
602
|
"",
|
|
603
|
-
|
|
603
|
+
pe(a.bcs),
|
|
604
604
|
""
|
|
605
605
|
])
|
|
606
606
|
}))
|
|
607
607
|
};
|
|
608
608
|
}
|
|
609
|
-
async function
|
|
609
|
+
async function W(e, t) {
|
|
610
610
|
const r = e?.core;
|
|
611
611
|
if (typeof r?.simulateTransaction != "function")
|
|
612
612
|
throw new Error("devInspectTransaction requires a Sui v2 Core-capable client");
|
|
613
613
|
const o = t.transaction ?? t.transactionBlock;
|
|
614
|
-
o instanceof
|
|
614
|
+
o instanceof q && o.setSenderIfNotSet(t.sender);
|
|
615
615
|
const n = await r.simulateTransaction({
|
|
616
616
|
transaction: o,
|
|
617
617
|
checksEnabled: !1,
|
|
@@ -623,7 +623,7 @@ async function q(e, t) {
|
|
|
623
623
|
});
|
|
624
624
|
return ft(n);
|
|
625
625
|
}
|
|
626
|
-
function
|
|
626
|
+
function _e(e) {
|
|
627
627
|
return {
|
|
628
628
|
json: !!e?.showContent,
|
|
629
629
|
display: !!e?.showDisplay,
|
|
@@ -631,7 +631,7 @@ function ke(e) {
|
|
|
631
631
|
objectBcs: !!e?.showBcs
|
|
632
632
|
};
|
|
633
633
|
}
|
|
634
|
-
function
|
|
634
|
+
function Te(e) {
|
|
635
635
|
return !e || e instanceof Error ? {
|
|
636
636
|
error: e instanceof Error ? { code: "notFound", error: e.message } : void 0
|
|
637
637
|
} : {
|
|
@@ -657,9 +657,9 @@ async function yt(e, t) {
|
|
|
657
657
|
throw new Error("getSuiObject requires a Sui v2 Core-capable client");
|
|
658
658
|
const { object: o } = await r.getObject({
|
|
659
659
|
objectId: t.id,
|
|
660
|
-
include:
|
|
660
|
+
include: _e(t.options)
|
|
661
661
|
});
|
|
662
|
-
return
|
|
662
|
+
return Te(o);
|
|
663
663
|
}
|
|
664
664
|
async function gt(e, t) {
|
|
665
665
|
const r = e?.core;
|
|
@@ -667,48 +667,48 @@ async function gt(e, t) {
|
|
|
667
667
|
throw new Error("multiGetSuiObjects requires a Sui v2 Core-capable client");
|
|
668
668
|
const { objects: o } = await r.getObjects({
|
|
669
669
|
objectIds: t.ids,
|
|
670
|
-
include:
|
|
670
|
+
include: _e(t.options)
|
|
671
671
|
});
|
|
672
|
-
return o.map(
|
|
672
|
+
return o.map(Te);
|
|
673
673
|
}
|
|
674
|
-
function
|
|
674
|
+
function Be(e) {
|
|
675
675
|
const t = [];
|
|
676
676
|
let r = !1;
|
|
677
677
|
return e.forEach((o, n) => {
|
|
678
678
|
const a = n === e.length - 1;
|
|
679
679
|
if (typeof o == "object" && o !== null && a) {
|
|
680
680
|
const { client: c, disableCache: i, cacheTime: s, ...u } = o;
|
|
681
|
-
u.__naviSdkServiceConfigVersion =
|
|
681
|
+
u.__naviSdkServiceConfigVersion = de(), t.push(u), r = !0;
|
|
682
682
|
} else
|
|
683
683
|
t.push(o);
|
|
684
684
|
}), r || t.push({
|
|
685
|
-
__naviSdkServiceConfigVersion:
|
|
685
|
+
__naviSdkServiceConfigVersion: de()
|
|
686
686
|
}), JSON.stringify(t);
|
|
687
687
|
}
|
|
688
|
-
function
|
|
688
|
+
function S(e) {
|
|
689
689
|
const t = {};
|
|
690
690
|
return (...r) => {
|
|
691
|
-
const o =
|
|
691
|
+
const o = Be(r);
|
|
692
692
|
return t[o] || (t[o] = e(...r).finally(() => {
|
|
693
693
|
delete t[o];
|
|
694
694
|
})), t[o];
|
|
695
695
|
};
|
|
696
696
|
}
|
|
697
|
-
function
|
|
697
|
+
function O(e) {
|
|
698
698
|
let t = {};
|
|
699
699
|
return (...r) => {
|
|
700
|
-
const o = r[r.length - 1], n =
|
|
700
|
+
const o = r[r.length - 1], n = Be(r), a = t[n];
|
|
701
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] = {
|
|
702
702
|
data: c,
|
|
703
703
|
cacheAt: Date.now()
|
|
704
704
|
}, c));
|
|
705
705
|
};
|
|
706
706
|
}
|
|
707
|
-
function
|
|
708
|
-
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(
|
|
709
709
|
(t, r) => ({
|
|
710
710
|
...t,
|
|
711
|
-
[Fe(r)]:
|
|
711
|
+
[Fe(r)]: re(e[r])
|
|
712
712
|
}),
|
|
713
713
|
{}
|
|
714
714
|
) : e;
|
|
@@ -721,7 +721,7 @@ function h(e, t) {
|
|
|
721
721
|
function ht(e, t) {
|
|
722
722
|
return typeof t == "string" ? e.object(t) : typeof t == "object" && t.$kind ? t : e.object(t.contract.pool);
|
|
723
723
|
}
|
|
724
|
-
function
|
|
724
|
+
function Z(e, t, r) {
|
|
725
725
|
if (e.results && e.results.length > 0) {
|
|
726
726
|
if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
|
|
727
727
|
return e.results[0].returnValues.map((o, n) => (t[n] || t[0]).parse(Uint8Array.from(o[0])));
|
|
@@ -730,35 +730,35 @@ function Q(e, t, r) {
|
|
|
730
730
|
return [];
|
|
731
731
|
}
|
|
732
732
|
function C(e) {
|
|
733
|
-
return
|
|
733
|
+
return Y(e);
|
|
734
734
|
}
|
|
735
|
-
function
|
|
735
|
+
function Pe(e) {
|
|
736
736
|
const t = (e || 0) / Math.pow(10, 27);
|
|
737
737
|
return t > Math.pow(10, 5) ? 1 / 0 : t;
|
|
738
738
|
}
|
|
739
|
-
new
|
|
739
|
+
new Ie("https://hermes.pyth.network", {
|
|
740
740
|
timeout: 2e4
|
|
741
741
|
});
|
|
742
|
-
const wt = 27,
|
|
742
|
+
const wt = 27, me = (e, t) => {
|
|
743
743
|
if (!Number(e) || !Number(t)) return new p(0);
|
|
744
744
|
const r = new p(1).shiftedBy(1 * wt), o = r.multipliedBy(new p(0.5));
|
|
745
745
|
return new p(e).multipliedBy(new p(t)).plus(o).dividedBy(r).integerValue(p.ROUND_DOWN);
|
|
746
|
-
},
|
|
747
|
-
"User-Agent":
|
|
746
|
+
}, R = ce ? {
|
|
747
|
+
"User-Agent": ce
|
|
748
748
|
} : {};
|
|
749
|
-
function
|
|
749
|
+
function ne(e, t = "uniqueId") {
|
|
750
750
|
return e.reduce(
|
|
751
751
|
(r, o) => (r[o[t]] = o, r),
|
|
752
752
|
{}
|
|
753
753
|
);
|
|
754
754
|
}
|
|
755
|
-
function
|
|
755
|
+
function fe(e, t = "uniqueId") {
|
|
756
756
|
return e.reduce(
|
|
757
757
|
(r, o) => (r[o[t]] = o, r),
|
|
758
758
|
{}
|
|
759
759
|
);
|
|
760
760
|
}
|
|
761
|
-
function
|
|
761
|
+
function K(e, t) {
|
|
762
762
|
const r = e.emodes.find((n) => n.emodeId === t.emodeId);
|
|
763
763
|
if (!r)
|
|
764
764
|
throw new Error("EMode not found in pool");
|
|
@@ -779,45 +779,45 @@ function bt(e) {
|
|
|
779
779
|
poolId: parseInt(r)
|
|
780
780
|
};
|
|
781
781
|
}
|
|
782
|
-
function
|
|
782
|
+
function A() {
|
|
783
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);
|
|
784
784
|
}
|
|
785
|
-
var
|
|
786
|
-
const
|
|
787
|
-
|
|
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(
|
|
788
788
|
async (e) => {
|
|
789
|
-
const t = (e?.markets || [
|
|
790
|
-
`/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(
|
|
791
791
|
(a) => a.key
|
|
792
792
|
)}`,
|
|
793
793
|
e
|
|
794
|
-
), n = await fetch(o, { headers:
|
|
794
|
+
), n = await fetch(o, { headers: N(R, r) }).then(
|
|
795
795
|
(a) => a.json()
|
|
796
796
|
);
|
|
797
797
|
return n.data.forEach((a) => {
|
|
798
798
|
const i = n.meta.emodes.filter((b) => {
|
|
799
|
-
const
|
|
800
|
-
return a.market ===
|
|
801
|
-
}).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));
|
|
802
802
|
a.emodes = i;
|
|
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(),
|
|
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(
|
|
804
804
|
p(a.borrowedAmount),
|
|
805
805
|
p(a.validBorrowAmount)
|
|
806
|
-
).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), d = p(
|
|
807
|
-
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;
|
|
808
808
|
}), n.data;
|
|
809
809
|
}
|
|
810
810
|
)
|
|
811
811
|
);
|
|
812
|
-
async function
|
|
812
|
+
async function E(e, t) {
|
|
813
813
|
let r = t?.market;
|
|
814
814
|
if (typeof e == "string") {
|
|
815
815
|
const a = bt(e);
|
|
816
816
|
a && (r = a.marketKey, e = a.poolId);
|
|
817
817
|
}
|
|
818
|
-
const o = await
|
|
818
|
+
const o = await J({
|
|
819
819
|
...t,
|
|
820
|
-
markets: [r ||
|
|
820
|
+
markets: [r || z],
|
|
821
821
|
cacheTime: v
|
|
822
822
|
});
|
|
823
823
|
if (typeof e == "object")
|
|
@@ -827,28 +827,28 @@ async function S(e, t) {
|
|
|
827
827
|
throw new Error("Pool not found");
|
|
828
828
|
return n.isDeprecated && console.log(`The lending pool for coinType ${n.suiCoinType} is going to be deprecated.`), n;
|
|
829
829
|
}
|
|
830
|
-
const Zt =
|
|
831
|
-
|
|
832
|
-
const t =
|
|
830
|
+
const Zt = O(
|
|
831
|
+
S(async (e) => {
|
|
832
|
+
const t = M(e), r = F(`/navi/stats?sdk=${V.version}`, e);
|
|
833
833
|
return (await fetch(r, {
|
|
834
|
-
headers:
|
|
834
|
+
headers: N(R, t)
|
|
835
835
|
}).then((n) => n.json())).data;
|
|
836
836
|
})
|
|
837
|
-
), Xt =
|
|
838
|
-
|
|
837
|
+
), Xt = O(
|
|
838
|
+
S(
|
|
839
839
|
async (e) => {
|
|
840
|
-
const t =
|
|
840
|
+
const t = M(e), r = F(`/navi/fee?sdk=${V.version}`, e);
|
|
841
841
|
return await fetch(r, {
|
|
842
|
-
headers:
|
|
842
|
+
headers: N(R, t)
|
|
843
843
|
}).then((n) => n.json());
|
|
844
844
|
}
|
|
845
845
|
)
|
|
846
846
|
);
|
|
847
847
|
async function vt(e, t, r, o) {
|
|
848
|
-
const n = await
|
|
848
|
+
const n = await I({
|
|
849
849
|
...o,
|
|
850
850
|
cacheTime: v
|
|
851
|
-
}), a = await
|
|
851
|
+
}), a = await E(t, o), c = o?.market || z, i = o?.env || "prod";
|
|
852
852
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
853
853
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
854
854
|
if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
@@ -893,10 +893,10 @@ async function vt(e, t, r, o) {
|
|
|
893
893
|
}), e;
|
|
894
894
|
}
|
|
895
895
|
async function xt(e, t, r, o) {
|
|
896
|
-
const n = await
|
|
896
|
+
const n = await I({
|
|
897
897
|
...o,
|
|
898
898
|
cacheTime: v
|
|
899
|
-
}), a = await
|
|
899
|
+
}), a = await E(t, o), c = h(r, e.pure.u64);
|
|
900
900
|
let i;
|
|
901
901
|
if (n.version === 1)
|
|
902
902
|
if (o?.accountCap) {
|
|
@@ -976,10 +976,10 @@ async function xt(e, t, r, o) {
|
|
|
976
976
|
});
|
|
977
977
|
}
|
|
978
978
|
async function er(e, t, r, o) {
|
|
979
|
-
const n = await
|
|
979
|
+
const n = await I({
|
|
980
980
|
...o,
|
|
981
981
|
cacheTime: v
|
|
982
|
-
}), a = await
|
|
982
|
+
}), a = await E(t, o);
|
|
983
983
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
984
984
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
985
985
|
const c = h(r, e.pure.u64);
|
|
@@ -1062,10 +1062,10 @@ async function er(e, t, r, o) {
|
|
|
1062
1062
|
});
|
|
1063
1063
|
}
|
|
1064
1064
|
async function tr(e, t, r, o) {
|
|
1065
|
-
const n = await
|
|
1065
|
+
const n = await I({
|
|
1066
1066
|
...o,
|
|
1067
1067
|
cacheTime: v
|
|
1068
|
-
}), a = await
|
|
1068
|
+
}), a = await E(t, o);
|
|
1069
1069
|
if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
1070
1070
|
if (!o?.amount)
|
|
1071
1071
|
throw new Error("Amount is required for sui coin");
|
|
@@ -1114,15 +1114,15 @@ async function tr(e, t, r, o) {
|
|
|
1114
1114
|
typeArguments: [a.suiCoinType]
|
|
1115
1115
|
}), e;
|
|
1116
1116
|
}
|
|
1117
|
-
const rr =
|
|
1118
|
-
|
|
1117
|
+
const rr = O(
|
|
1118
|
+
S(
|
|
1119
1119
|
async (e) => {
|
|
1120
|
-
const t = await
|
|
1120
|
+
const t = await I({
|
|
1121
1121
|
...e
|
|
1122
|
-
}), r = e?.client ??
|
|
1122
|
+
}), r = e?.client ?? U;
|
|
1123
1123
|
if (e?.address && typeof e?.asset < "u")
|
|
1124
1124
|
try {
|
|
1125
|
-
const a = await
|
|
1125
|
+
const a = await E(e.asset, e), c = new q();
|
|
1126
1126
|
c.moveCall({
|
|
1127
1127
|
target: `${t.package}::incentive_v3::get_borrow_fee_v2`,
|
|
1128
1128
|
arguments: [
|
|
@@ -1133,10 +1133,10 @@ const rr = $(
|
|
|
1133
1133
|
],
|
|
1134
1134
|
typeArguments: []
|
|
1135
1135
|
});
|
|
1136
|
-
const i = await
|
|
1136
|
+
const i = await W(r, {
|
|
1137
1137
|
transactionBlock: c,
|
|
1138
1138
|
sender: e.address
|
|
1139
|
-
}), s =
|
|
1139
|
+
}), s = Z(i, [l.u64()]);
|
|
1140
1140
|
return (Number(s[0]) || 0) / 100;
|
|
1141
1141
|
} catch (a) {
|
|
1142
1142
|
console.error(
|
|
@@ -1151,7 +1151,7 @@ const rr = $(
|
|
|
1151
1151
|
return Number(n) / 100;
|
|
1152
1152
|
}
|
|
1153
1153
|
)
|
|
1154
|
-
),
|
|
1154
|
+
), z = "main", L = {
|
|
1155
1155
|
main: {
|
|
1156
1156
|
id: 0,
|
|
1157
1157
|
key: "main",
|
|
@@ -1178,13 +1178,13 @@ class Ct {
|
|
|
1178
1178
|
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
1179
1179
|
marketTotalSupplyValue: "0",
|
|
1180
1180
|
marketTotalBorrowValue: "0"
|
|
1181
|
-
}, this.config =
|
|
1181
|
+
}, this.config = P(t), this.initPools(r);
|
|
1182
1182
|
}
|
|
1183
1183
|
get overview() {
|
|
1184
1184
|
return this._overview;
|
|
1185
1185
|
}
|
|
1186
1186
|
initPools(t) {
|
|
1187
|
-
const r =
|
|
1187
|
+
const r = ne(this.pools), o = fe(this.emodes), n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
1188
1188
|
let c = p(0), i = p(0);
|
|
1189
1189
|
t.forEach((s) => {
|
|
1190
1190
|
if (!this.checkMarket(s.market)) {
|
|
@@ -1194,11 +1194,11 @@ class Ct {
|
|
|
1194
1194
|
r[s.uniqueId] || this.pools.push(s), s?.emodes?.forEach((m) => {
|
|
1195
1195
|
o[m.uniqueId] || this.emodes.push(m), m.assets.forEach((w) => {
|
|
1196
1196
|
w.isDebt && m.assets.find(
|
|
1197
|
-
(
|
|
1198
|
-
) && 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);
|
|
1199
1199
|
});
|
|
1200
1200
|
}), i = i.plus(s.poolBorrowValue), c = c.plus(s.poolSupplyValue);
|
|
1201
|
-
}), this.poolMap =
|
|
1201
|
+
}), this.poolMap = ne(this.pools, "id"), this.emodeMap = fe(this.emodes, "emodeId"), this.emodes.forEach((s) => {
|
|
1202
1202
|
const u = this.getEModePools(s.emodeId);
|
|
1203
1203
|
this.emodePools.push(...u);
|
|
1204
1204
|
}), this._overview = {
|
|
@@ -1236,44 +1236,44 @@ class Ct {
|
|
|
1236
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;
|
|
1237
1237
|
}
|
|
1238
1238
|
}
|
|
1239
|
-
const
|
|
1240
|
-
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);
|
|
1241
1241
|
if (!r)
|
|
1242
1242
|
throw new Error("Market not found");
|
|
1243
1243
|
return r;
|
|
1244
|
-
}, jt =
|
|
1245
|
-
|
|
1244
|
+
}, jt = O(
|
|
1245
|
+
S(
|
|
1246
1246
|
async (e, t) => {
|
|
1247
|
-
const r = await
|
|
1247
|
+
const r = await J({
|
|
1248
1248
|
cacheTime: 6e4,
|
|
1249
1249
|
...t,
|
|
1250
1250
|
markets: e
|
|
1251
1251
|
});
|
|
1252
1252
|
return e.map((o) => {
|
|
1253
|
-
const n =
|
|
1253
|
+
const n = P(o), a = r.filter((c) => c.market === n.key);
|
|
1254
1254
|
return new Ct(o, a);
|
|
1255
1255
|
});
|
|
1256
1256
|
}
|
|
1257
1257
|
)
|
|
1258
|
-
), nr =
|
|
1259
|
-
|
|
1258
|
+
), nr = O(
|
|
1259
|
+
S(
|
|
1260
1260
|
async (e, t) => (await jt([e], t))[0]
|
|
1261
1261
|
)
|
|
1262
|
-
),
|
|
1263
|
-
|
|
1262
|
+
), I = O(
|
|
1263
|
+
S(
|
|
1264
1264
|
async (e) => {
|
|
1265
|
-
const t =
|
|
1266
|
-
`/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}`,
|
|
1267
1267
|
e
|
|
1268
1268
|
);
|
|
1269
1269
|
return (await fetch(o, {
|
|
1270
|
-
headers:
|
|
1270
|
+
headers: N(R, r)
|
|
1271
1271
|
}).then((a) => a.json())).data;
|
|
1272
1272
|
}
|
|
1273
1273
|
)
|
|
1274
1274
|
), v = 1e3 * 60 * 5;
|
|
1275
|
-
async function
|
|
1276
|
-
const r = await
|
|
1275
|
+
async function It(e, t) {
|
|
1276
|
+
const r = await I({
|
|
1277
1277
|
cacheTime: v,
|
|
1278
1278
|
...t
|
|
1279
1279
|
});
|
|
@@ -1282,8 +1282,8 @@ async function kt(e, t) {
|
|
|
1282
1282
|
arguments: []
|
|
1283
1283
|
});
|
|
1284
1284
|
}
|
|
1285
|
-
async function
|
|
1286
|
-
const o = await
|
|
1285
|
+
async function kt(e, t, r) {
|
|
1286
|
+
const o = await I({
|
|
1287
1287
|
cacheTime: v,
|
|
1288
1288
|
...r
|
|
1289
1289
|
});
|
|
@@ -1293,7 +1293,7 @@ async function It(e, t, r) {
|
|
|
1293
1293
|
});
|
|
1294
1294
|
}
|
|
1295
1295
|
async function _t(e, t, r) {
|
|
1296
|
-
const o = await
|
|
1296
|
+
const o = await I({
|
|
1297
1297
|
...r,
|
|
1298
1298
|
cacheTime: v
|
|
1299
1299
|
});
|
|
@@ -1310,7 +1310,7 @@ async function _t(e, t, r) {
|
|
|
1310
1310
|
}), e;
|
|
1311
1311
|
}
|
|
1312
1312
|
async function or(e, t) {
|
|
1313
|
-
const r = await
|
|
1313
|
+
const r = await I({
|
|
1314
1314
|
...t,
|
|
1315
1315
|
cacheTime: v
|
|
1316
1316
|
});
|
|
@@ -1323,15 +1323,15 @@ async function or(e, t) {
|
|
|
1323
1323
|
}), e;
|
|
1324
1324
|
}
|
|
1325
1325
|
async function ar(e, t, r) {
|
|
1326
|
-
const o = await
|
|
1326
|
+
const o = await I({
|
|
1327
1327
|
cacheTime: v,
|
|
1328
1328
|
...r
|
|
1329
|
-
}), n = await
|
|
1329
|
+
}), n = await It(e, r);
|
|
1330
1330
|
await _t(e, t, {
|
|
1331
1331
|
...r,
|
|
1332
1332
|
accountCap: n
|
|
1333
1333
|
});
|
|
1334
|
-
const a = await
|
|
1334
|
+
const a = await P(r?.market || z), c = await kt(e, n, r);
|
|
1335
1335
|
return e.moveCall({
|
|
1336
1336
|
target: `${o.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
1337
1337
|
arguments: [
|
|
@@ -1342,18 +1342,18 @@ async function ar(e, t, r) {
|
|
|
1342
1342
|
]
|
|
1343
1343
|
}), n;
|
|
1344
1344
|
}
|
|
1345
|
-
const
|
|
1346
|
-
|
|
1345
|
+
const Ae = O(
|
|
1346
|
+
S(
|
|
1347
1347
|
async (e, t) => {
|
|
1348
|
-
const r = await
|
|
1348
|
+
const r = await I({
|
|
1349
1349
|
cacheTime: v,
|
|
1350
1350
|
...t
|
|
1351
|
-
}), o = new
|
|
1351
|
+
}), o = new q(), n = t?.client ?? U;
|
|
1352
1352
|
o.moveCall({
|
|
1353
1353
|
target: `${r.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
1354
1354
|
arguments: [o.object(r.emode.contract.registryObject), o.pure.address(e)]
|
|
1355
1355
|
});
|
|
1356
|
-
const c = (await
|
|
1356
|
+
const c = (await W(n, {
|
|
1357
1357
|
transactionBlock: o,
|
|
1358
1358
|
sender: e
|
|
1359
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]));
|
|
@@ -1366,12 +1366,12 @@ const Be = $(
|
|
|
1366
1366
|
)
|
|
1367
1367
|
);
|
|
1368
1368
|
function ir(e) {
|
|
1369
|
-
return `${
|
|
1369
|
+
return `${P(e.marketId).key}-${e.emodeId}`;
|
|
1370
1370
|
}
|
|
1371
1371
|
function Tt(e, t) {
|
|
1372
1372
|
return e.coinType ? e.coinType : t || (typeof e.type == "string" ? e.type.match(/::coin::Coin<(.+)>$/) : null)?.[1];
|
|
1373
1373
|
}
|
|
1374
|
-
function
|
|
1374
|
+
function ye(e, t) {
|
|
1375
1375
|
const r = Tt(e, t), o = e.coinObjectId ?? e.objectId;
|
|
1376
1376
|
return !r || !o || e.balance === void 0 || e.balance === null ? null : {
|
|
1377
1377
|
...e,
|
|
@@ -1380,29 +1380,55 @@ function me(e, t) {
|
|
|
1380
1380
|
};
|
|
1381
1381
|
}
|
|
1382
1382
|
function cr(e, t, r) {
|
|
1383
|
-
const o = typeof r?.balance == "number", n = o ? r.balance : 0;
|
|
1384
|
-
let
|
|
1385
|
-
const
|
|
1386
|
-
let
|
|
1387
|
-
|
|
1388
|
-
if (!(o &&
|
|
1389
|
-
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)
|
|
1390
1390
|
throw new Error("All coins must be of the same type");
|
|
1391
|
-
|
|
1391
|
+
c += Number(B.balance), i.push(B.coinObjectId);
|
|
1392
1392
|
}
|
|
1393
|
-
})
|
|
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;
|
|
1401
|
+
}
|
|
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)
|
|
1394
1406
|
throw new Error("No coins to merge");
|
|
1395
|
-
if (
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
);
|
|
1399
|
-
|
|
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)]) : $;
|
|
1400
1426
|
}
|
|
1401
|
-
async function
|
|
1402
|
-
const i = await
|
|
1427
|
+
async function Se(e, t, r, o, n, a, c) {
|
|
1428
|
+
const i = await I({
|
|
1403
1429
|
...c,
|
|
1404
1430
|
cacheTime: v
|
|
1405
|
-
}), s = await
|
|
1431
|
+
}), s = await E(r, c);
|
|
1406
1432
|
return e.moveCall({
|
|
1407
1433
|
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
1408
1434
|
arguments: [
|
|
@@ -1420,15 +1446,15 @@ async function Pe(e, t, r, o, n, a, c) {
|
|
|
1420
1446
|
});
|
|
1421
1447
|
}
|
|
1422
1448
|
async function Bt(e, t, r) {
|
|
1423
|
-
return
|
|
1449
|
+
return Se(e, t, 0, 0, 0, !1, r);
|
|
1424
1450
|
}
|
|
1425
|
-
async function
|
|
1426
|
-
const o = new
|
|
1451
|
+
async function $e(e, t, r) {
|
|
1452
|
+
const o = new q(), n = r?.client ?? U, a = await J({
|
|
1427
1453
|
...r,
|
|
1428
|
-
markets: Object.values(
|
|
1429
|
-
}), c =
|
|
1454
|
+
markets: Object.values(L)
|
|
1455
|
+
}), c = ne(a), s = Array.from(new Set(t.map((d) => d.market))).map((d) => P(d));
|
|
1430
1456
|
for (const d of s) {
|
|
1431
|
-
const f = await
|
|
1457
|
+
const f = await I({
|
|
1432
1458
|
...r,
|
|
1433
1459
|
cacheTime: v,
|
|
1434
1460
|
market: d.key
|
|
@@ -1439,7 +1465,7 @@ async function Ae(e, t, r) {
|
|
|
1439
1465
|
});
|
|
1440
1466
|
}
|
|
1441
1467
|
for (let d of t) {
|
|
1442
|
-
const f = await
|
|
1468
|
+
const f = await I({
|
|
1443
1469
|
...r,
|
|
1444
1470
|
cacheTime: v,
|
|
1445
1471
|
market: d.market
|
|
@@ -1449,19 +1475,19 @@ async function Ae(e, t, r) {
|
|
|
1449
1475
|
arguments: [o.object(f.storage), o.pure.address(d.address)]
|
|
1450
1476
|
});
|
|
1451
1477
|
}
|
|
1452
|
-
const m = (await
|
|
1478
|
+
const m = (await W(n, {
|
|
1453
1479
|
transactionBlock: o,
|
|
1454
1480
|
sender: e
|
|
1455
1481
|
})).results || [], w = {};
|
|
1456
1482
|
s.forEach((d, f) => {
|
|
1457
1483
|
try {
|
|
1458
|
-
const b = m[f]?.returnValues?.map((
|
|
1459
|
-
for (const
|
|
1460
|
-
|
|
1461
|
-
supplyIndex:
|
|
1462
|
-
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
|
|
1463
1489
|
};
|
|
1464
|
-
w[d.key] =
|
|
1490
|
+
w[d.key] = j;
|
|
1465
1491
|
} catch (b) {
|
|
1466
1492
|
console.warn(
|
|
1467
1493
|
`[@naviprotocol/lending] Failed to decode reserve data for market "${d.key}", falling back to open-api pool indices`,
|
|
@@ -1469,55 +1495,55 @@ async function Ae(e, t, r) {
|
|
|
1469
1495
|
);
|
|
1470
1496
|
}
|
|
1471
1497
|
});
|
|
1472
|
-
const
|
|
1473
|
-
return
|
|
1474
|
-
const b = t[f],
|
|
1475
|
-
d.forEach((
|
|
1476
|
-
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))
|
|
1477
1503
|
return;
|
|
1478
|
-
const
|
|
1479
|
-
if (!
|
|
1504
|
+
const T = c[`${j.key}-${k.asset_id}`];
|
|
1505
|
+
if (!T)
|
|
1480
1506
|
return;
|
|
1481
|
-
const
|
|
1482
|
-
|
|
1483
|
-
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,
|
|
1484
1510
|
borrowBalance: Ve,
|
|
1485
|
-
assetId:
|
|
1486
|
-
market:
|
|
1487
|
-
pool:
|
|
1511
|
+
assetId: k.asset_id,
|
|
1512
|
+
market: j.key,
|
|
1513
|
+
pool: T,
|
|
1488
1514
|
emodeId: b.emodeId
|
|
1489
1515
|
});
|
|
1490
1516
|
});
|
|
1491
|
-
}),
|
|
1517
|
+
}), y;
|
|
1492
1518
|
}
|
|
1493
|
-
const sr =
|
|
1519
|
+
const sr = O(
|
|
1494
1520
|
async (e, t) => {
|
|
1495
|
-
const o = (t?.markets || Object.keys(
|
|
1521
|
+
const o = (t?.markets || Object.keys(L)).map((n) => P(n)).map((n) => ({
|
|
1496
1522
|
address: e,
|
|
1497
1523
|
market: n.key
|
|
1498
1524
|
}));
|
|
1499
|
-
return await
|
|
1525
|
+
return await $e(e, o, t);
|
|
1500
1526
|
}
|
|
1501
1527
|
);
|
|
1502
1528
|
async function ur(e, t) {
|
|
1503
|
-
const r = t?.client ??
|
|
1529
|
+
const r = t?.client ?? U, o = new q();
|
|
1504
1530
|
await Bt(o, e, t);
|
|
1505
|
-
const n = await
|
|
1531
|
+
const n = await W(r, {
|
|
1506
1532
|
transactionBlock: o,
|
|
1507
1533
|
sender: e
|
|
1508
|
-
}), a =
|
|
1509
|
-
return
|
|
1534
|
+
}), a = Z(n, [l.u256()]);
|
|
1535
|
+
return Pe(Number(a[0]) || 0);
|
|
1510
1536
|
}
|
|
1511
1537
|
async function lr(e, t, r, o) {
|
|
1512
|
-
const n = o?.client ??
|
|
1538
|
+
const n = o?.client ?? U, a = new q();
|
|
1513
1539
|
let c = 0, i = 0;
|
|
1514
|
-
const s = await
|
|
1515
|
-
if (r.forEach((
|
|
1516
|
-
|
|
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);
|
|
1517
1543
|
}), c * i < 0)
|
|
1518
1544
|
throw new Error("Invalid operations");
|
|
1519
1545
|
const u = c > 0 || i > 0;
|
|
1520
|
-
await
|
|
1546
|
+
await Se(
|
|
1521
1547
|
a,
|
|
1522
1548
|
e,
|
|
1523
1549
|
s,
|
|
@@ -1526,28 +1552,28 @@ async function lr(e, t, r, o) {
|
|
|
1526
1552
|
u,
|
|
1527
1553
|
o
|
|
1528
1554
|
);
|
|
1529
|
-
const m = await
|
|
1555
|
+
const m = await W(n, {
|
|
1530
1556
|
transactionBlock: a,
|
|
1531
1557
|
sender: e
|
|
1532
|
-
}), w =
|
|
1533
|
-
return
|
|
1558
|
+
}), w = Z(m, [l.u256()]);
|
|
1559
|
+
return Pe(Number(w[0]) || 0);
|
|
1534
1560
|
}
|
|
1535
|
-
const dr =
|
|
1561
|
+
const dr = S(
|
|
1536
1562
|
async (e, t) => {
|
|
1537
1563
|
const r = new URLSearchParams();
|
|
1538
1564
|
t?.cursor && r.set("cursor", t.cursor), r.set("userAddress", e);
|
|
1539
|
-
const o =
|
|
1540
|
-
`/navi/user/transactions?${r.toString()}&sdk=${
|
|
1565
|
+
const o = M(t), n = F(
|
|
1566
|
+
`/navi/user/transactions?${r.toString()}&sdk=${V.version}`,
|
|
1541
1567
|
t
|
|
1542
1568
|
);
|
|
1543
1569
|
return (await fetch(n, {
|
|
1544
|
-
headers:
|
|
1570
|
+
headers: N(R, o)
|
|
1545
1571
|
}).then((c) => c.json())).data;
|
|
1546
1572
|
}
|
|
1547
1573
|
);
|
|
1548
1574
|
async function pr(e, t) {
|
|
1549
1575
|
let r = null;
|
|
1550
|
-
const o = [], n = t?.client ??
|
|
1576
|
+
const o = [], n = t?.client ?? U, a = n.core;
|
|
1551
1577
|
do {
|
|
1552
1578
|
let c;
|
|
1553
1579
|
if (t?.coinType)
|
|
@@ -1559,7 +1585,7 @@ async function pr(e, t) {
|
|
|
1559
1585
|
limit: 100
|
|
1560
1586
|
});
|
|
1561
1587
|
c = {
|
|
1562
|
-
data: (i.objects ?? i.data ?? []).map((s) =>
|
|
1588
|
+
data: (i.objects ?? i.data ?? []).map((s) => ye(s, t?.coinType)).filter(Boolean),
|
|
1563
1589
|
nextCursor: i.cursor ?? i.nextCursor ?? null,
|
|
1564
1590
|
hasNextPage: i.hasNextPage ?? !1
|
|
1565
1591
|
};
|
|
@@ -1596,7 +1622,7 @@ async function pr(e, t) {
|
|
|
1596
1622
|
limit: 100
|
|
1597
1623
|
});
|
|
1598
1624
|
o.push(
|
|
1599
|
-
...(w.objects ?? w.data ?? []).map((
|
|
1625
|
+
...(w.objects ?? w.data ?? []).map((g) => ye(g, u)).filter(Boolean)
|
|
1600
1626
|
), m = w.cursor ?? w.nextCursor ?? null;
|
|
1601
1627
|
} while (m);
|
|
1602
1628
|
}
|
|
@@ -1618,75 +1644,75 @@ async function pr(e, t) {
|
|
|
1618
1644
|
} while (r);
|
|
1619
1645
|
return o;
|
|
1620
1646
|
}
|
|
1621
|
-
const Pt =
|
|
1647
|
+
const Pt = O(
|
|
1622
1648
|
async (e, t) => {
|
|
1623
|
-
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) => ({
|
|
1624
1650
|
address: e,
|
|
1625
1651
|
market: i.key
|
|
1626
1652
|
})).concat(
|
|
1627
1653
|
n.filter((i) => !!o.find((s) => s.id === i.marketId)).map((i) => ({
|
|
1628
1654
|
address: i.accountCap,
|
|
1629
|
-
market:
|
|
1655
|
+
market: P(i.marketId).key,
|
|
1630
1656
|
emodeId: i.emodeId
|
|
1631
1657
|
}))
|
|
1632
1658
|
);
|
|
1633
|
-
return (await
|
|
1659
|
+
return (await $e(e, a, t)).forEach((i) => {
|
|
1634
1660
|
const s = typeof i.emodeId == "number" ? n.find((u) => {
|
|
1635
|
-
const m =
|
|
1661
|
+
const m = P(i.market);
|
|
1636
1662
|
return u.emodeId === i.emodeId && u.marketId === m.id;
|
|
1637
1663
|
}) : void 0;
|
|
1638
1664
|
if (s) {
|
|
1639
1665
|
if (!i.pool.emodes.find((m) => m.emodeId === s.emodeId))
|
|
1640
1666
|
return;
|
|
1641
1667
|
if (p(i.supplyBalance).gte(0)) {
|
|
1642
|
-
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);
|
|
1643
1669
|
if (m.gt(0) || w.emode.isCollateral)
|
|
1644
1670
|
try {
|
|
1645
1671
|
r.push({
|
|
1646
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${
|
|
1672
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${A()}`,
|
|
1647
1673
|
wallet: e,
|
|
1648
1674
|
protocol: "navi",
|
|
1649
1675
|
market: i.market,
|
|
1650
1676
|
type: "navi-lending-emode-supply",
|
|
1651
1677
|
"navi-lending-emode-supply": {
|
|
1652
1678
|
amount: m.toString(),
|
|
1653
|
-
pool:
|
|
1679
|
+
pool: K(i.pool, s),
|
|
1654
1680
|
token: i.pool.token,
|
|
1655
1681
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1656
1682
|
emodeCap: s
|
|
1657
1683
|
}
|
|
1658
1684
|
});
|
|
1659
|
-
} catch (
|
|
1660
|
-
console.error(
|
|
1685
|
+
} catch (g) {
|
|
1686
|
+
console.error(g);
|
|
1661
1687
|
}
|
|
1662
1688
|
}
|
|
1663
1689
|
if (p(i.borrowBalance).gte(0)) {
|
|
1664
|
-
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);
|
|
1665
1691
|
if (m.gt(0) || w.emode.isDebt)
|
|
1666
1692
|
try {
|
|
1667
1693
|
r.push({
|
|
1668
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${
|
|
1694
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${A()}`,
|
|
1669
1695
|
wallet: e,
|
|
1670
1696
|
protocol: "navi",
|
|
1671
1697
|
market: i.market,
|
|
1672
1698
|
type: "navi-lending-emode-borrow",
|
|
1673
1699
|
"navi-lending-emode-borrow": {
|
|
1674
1700
|
amount: m.toString(),
|
|
1675
|
-
pool:
|
|
1701
|
+
pool: K(i.pool, s),
|
|
1676
1702
|
token: i.pool.token,
|
|
1677
1703
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1678
1704
|
emodeCap: s
|
|
1679
1705
|
}
|
|
1680
1706
|
});
|
|
1681
|
-
} catch (
|
|
1682
|
-
console.error(
|
|
1707
|
+
} catch (g) {
|
|
1708
|
+
console.error(g);
|
|
1683
1709
|
}
|
|
1684
1710
|
}
|
|
1685
1711
|
} else {
|
|
1686
1712
|
if (p(i.supplyBalance).gt(0)) {
|
|
1687
1713
|
const u = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1688
1714
|
r.push({
|
|
1689
|
-
id: `${i.pool.uniqueId}_navi-lending-supply-${
|
|
1715
|
+
id: `${i.pool.uniqueId}_navi-lending-supply-${A()}`,
|
|
1690
1716
|
wallet: e,
|
|
1691
1717
|
protocol: "navi",
|
|
1692
1718
|
type: "navi-lending-supply",
|
|
@@ -1702,7 +1728,7 @@ const Pt = $(
|
|
|
1702
1728
|
if (p(i.borrowBalance).gt(0)) {
|
|
1703
1729
|
const u = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1704
1730
|
r.push({
|
|
1705
|
-
id: `${i.pool.uniqueId}_navi-lending-borrow-${
|
|
1731
|
+
id: `${i.pool.uniqueId}_navi-lending-borrow-${A()}`,
|
|
1706
1732
|
wallet: e,
|
|
1707
1733
|
protocol: "navi",
|
|
1708
1734
|
market: i.market,
|
|
@@ -1719,7 +1745,7 @@ const Pt = $(
|
|
|
1719
1745
|
}), r;
|
|
1720
1746
|
}
|
|
1721
1747
|
);
|
|
1722
|
-
class
|
|
1748
|
+
class G {
|
|
1723
1749
|
constructor(t, r) {
|
|
1724
1750
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1725
1751
|
hf: 1 / 0,
|
|
@@ -1759,7 +1785,7 @@ class L {
|
|
|
1759
1785
|
}
|
|
1760
1786
|
filterPositionsByPool(t) {
|
|
1761
1787
|
const o = !!t.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1762
|
-
return new
|
|
1788
|
+
return new G(
|
|
1763
1789
|
this.positions.filter((n) => {
|
|
1764
1790
|
const a = n[n.type];
|
|
1765
1791
|
return o.includes(n.type) && a.pool.uniqueId === t.uniqueId;
|
|
@@ -1771,7 +1797,7 @@ class L {
|
|
|
1771
1797
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1772
1798
|
let a;
|
|
1773
1799
|
return o ? a = {
|
|
1774
|
-
id:
|
|
1800
|
+
id: A(),
|
|
1775
1801
|
wallet: "",
|
|
1776
1802
|
protocol: "navi",
|
|
1777
1803
|
market: "",
|
|
@@ -1784,7 +1810,7 @@ class L {
|
|
|
1784
1810
|
emodeCap: {}
|
|
1785
1811
|
}
|
|
1786
1812
|
} : a = {
|
|
1787
|
-
id:
|
|
1813
|
+
id: A(),
|
|
1788
1814
|
wallet: "",
|
|
1789
1815
|
protocol: "navi",
|
|
1790
1816
|
market: "",
|
|
@@ -1795,13 +1821,13 @@ class L {
|
|
|
1795
1821
|
token: t.token,
|
|
1796
1822
|
pool: t
|
|
1797
1823
|
}
|
|
1798
|
-
}, new
|
|
1824
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1799
1825
|
}
|
|
1800
1826
|
withdraw(t, r) {
|
|
1801
1827
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1802
1828
|
let a;
|
|
1803
1829
|
return o ? a = {
|
|
1804
|
-
id:
|
|
1830
|
+
id: A(),
|
|
1805
1831
|
wallet: "",
|
|
1806
1832
|
protocol: "navi",
|
|
1807
1833
|
market: "",
|
|
@@ -1814,7 +1840,7 @@ class L {
|
|
|
1814
1840
|
emodeCap: {}
|
|
1815
1841
|
}
|
|
1816
1842
|
} : a = {
|
|
1817
|
-
id:
|
|
1843
|
+
id: A(),
|
|
1818
1844
|
wallet: "",
|
|
1819
1845
|
protocol: "navi",
|
|
1820
1846
|
market: "",
|
|
@@ -1825,13 +1851,13 @@ class L {
|
|
|
1825
1851
|
token: t.token,
|
|
1826
1852
|
pool: t
|
|
1827
1853
|
}
|
|
1828
|
-
}, new
|
|
1854
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1829
1855
|
}
|
|
1830
1856
|
borrow(t, r) {
|
|
1831
1857
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1832
1858
|
let a;
|
|
1833
1859
|
return o ? a = {
|
|
1834
|
-
id:
|
|
1860
|
+
id: A(),
|
|
1835
1861
|
wallet: "",
|
|
1836
1862
|
protocol: "navi",
|
|
1837
1863
|
market: "",
|
|
@@ -1844,7 +1870,7 @@ class L {
|
|
|
1844
1870
|
emodeCap: {}
|
|
1845
1871
|
}
|
|
1846
1872
|
} : a = {
|
|
1847
|
-
id:
|
|
1873
|
+
id: A(),
|
|
1848
1874
|
wallet: "",
|
|
1849
1875
|
protocol: "navi",
|
|
1850
1876
|
market: "",
|
|
@@ -1855,13 +1881,13 @@ class L {
|
|
|
1855
1881
|
token: t.token,
|
|
1856
1882
|
pool: t
|
|
1857
1883
|
}
|
|
1858
|
-
}, new
|
|
1884
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1859
1885
|
}
|
|
1860
1886
|
repay(t, r) {
|
|
1861
1887
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1862
1888
|
let a;
|
|
1863
1889
|
return o ? a = {
|
|
1864
|
-
id:
|
|
1890
|
+
id: A(),
|
|
1865
1891
|
wallet: "",
|
|
1866
1892
|
protocol: "navi",
|
|
1867
1893
|
market: "",
|
|
@@ -1874,7 +1900,7 @@ class L {
|
|
|
1874
1900
|
emodeCap: {}
|
|
1875
1901
|
}
|
|
1876
1902
|
} : a = {
|
|
1877
|
-
id:
|
|
1903
|
+
id: A(),
|
|
1878
1904
|
wallet: "",
|
|
1879
1905
|
protocol: "navi",
|
|
1880
1906
|
market: "",
|
|
@@ -1885,7 +1911,7 @@ class L {
|
|
|
1885
1911
|
token: t.token,
|
|
1886
1912
|
pool: t
|
|
1887
1913
|
}
|
|
1888
|
-
}, new
|
|
1914
|
+
}, new G([...this.positions, a], this._priceMap);
|
|
1889
1915
|
}
|
|
1890
1916
|
resolveValueUSD(t) {
|
|
1891
1917
|
return Object.keys(this._priceMap).length > 0 ? p(t.amount).multipliedBy(this.getPrice(t.pool)).toString() : t.valueUSD;
|
|
@@ -1893,19 +1919,19 @@ class L {
|
|
|
1893
1919
|
getPositionsOverview(t) {
|
|
1894
1920
|
const r = {}, o = {};
|
|
1895
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);
|
|
1896
|
-
t.forEach((
|
|
1897
|
-
if (
|
|
1898
|
-
const d =
|
|
1922
|
+
t.forEach((y) => {
|
|
1923
|
+
if (y.type === "navi-lending-supply") {
|
|
1924
|
+
const d = y["navi-lending-supply"], f = this.resolveValueUSD(d);
|
|
1899
1925
|
n = n.plus(f), s = s.plus(
|
|
1900
1926
|
new p(f).multipliedBy(d.pool.liquidationFactor.threshold)
|
|
1901
1927
|
), u = u.plus(
|
|
1902
1928
|
new p(f).multipliedBy(d.pool.ltvValue)
|
|
1903
1929
|
);
|
|
1904
|
-
} else if (
|
|
1905
|
-
const d =
|
|
1930
|
+
} else if (y.type === "navi-lending-borrow") {
|
|
1931
|
+
const d = y["navi-lending-borrow"];
|
|
1906
1932
|
a = a.plus(this.resolveValueUSD(d));
|
|
1907
|
-
} else if (
|
|
1908
|
-
const d =
|
|
1933
|
+
} else if (y.type === "navi-lending-emode-supply") {
|
|
1934
|
+
const d = y["navi-lending-emode-supply"], f = this.resolveValueUSD(d);
|
|
1909
1935
|
n = n.plus(f);
|
|
1910
1936
|
const b = d.pool.emode;
|
|
1911
1937
|
s = s.plus(
|
|
@@ -1913,28 +1939,28 @@ class L {
|
|
|
1913
1939
|
), u = u.plus(
|
|
1914
1940
|
new p(f).multipliedBy(b.ltv)
|
|
1915
1941
|
);
|
|
1916
|
-
} else if (
|
|
1917
|
-
const d =
|
|
1942
|
+
} else if (y.type === "navi-lending-emode-borrow") {
|
|
1943
|
+
const d = y["navi-lending-emode-borrow"];
|
|
1918
1944
|
a = a.plus(this.resolveValueUSD(d));
|
|
1919
1945
|
}
|
|
1920
|
-
}), a = p.max(a, 0), n = p.max(n, 0), s = p.max(s, 0), u = p.max(u, 0), t.forEach((
|
|
1921
|
-
if (
|
|
1922
|
-
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;
|
|
1923
1949
|
n.gt(0) && (c = c.plus(
|
|
1924
1950
|
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1925
1951
|
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1926
|
-
} else if (
|
|
1927
|
-
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;
|
|
1928
1954
|
a.gt(0) && (i = i.plus(
|
|
1929
1955
|
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1930
1956
|
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1931
|
-
} else if (
|
|
1932
|
-
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;
|
|
1933
1959
|
n.gt(0) && (c = c.plus(
|
|
1934
1960
|
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1935
1961
|
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1936
|
-
} else if (
|
|
1937
|
-
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;
|
|
1938
1964
|
a.gt(0) && (i = i.plus(
|
|
1939
1965
|
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1940
1966
|
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
@@ -1957,7 +1983,7 @@ class L {
|
|
|
1957
1983
|
}
|
|
1958
1984
|
}
|
|
1959
1985
|
async function mr(e, t, r, o) {
|
|
1960
|
-
const n = await
|
|
1986
|
+
const n = await I({
|
|
1961
1987
|
...o,
|
|
1962
1988
|
cacheTime: v
|
|
1963
1989
|
});
|
|
@@ -1972,12 +1998,12 @@ async function mr(e, t, r, o) {
|
|
|
1972
1998
|
]
|
|
1973
1999
|
});
|
|
1974
2000
|
}
|
|
1975
|
-
const
|
|
2001
|
+
const Ee = new Ie("https://hermes.pyth.network", {
|
|
1976
2002
|
timeout: 1e4
|
|
1977
2003
|
});
|
|
1978
2004
|
async function fr(e) {
|
|
1979
2005
|
try {
|
|
1980
|
-
const t = [], r = await
|
|
2006
|
+
const t = [], r = await Ee.getLatestPriceFeeds(e);
|
|
1981
2007
|
if (!r) return t;
|
|
1982
2008
|
const o = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1983
2009
|
for (const n of r) {
|
|
@@ -1998,7 +2024,7 @@ async function fr(e) {
|
|
|
1998
2024
|
}
|
|
1999
2025
|
}
|
|
2000
2026
|
async function At(e, t) {
|
|
2001
|
-
const r = [], o = t?.client ??
|
|
2027
|
+
const r = [], o = t?.client ?? U, n = e.map((c) => c.priceInfoObject), a = await gt(o, {
|
|
2002
2028
|
ids: Array.from(new Set(n)),
|
|
2003
2029
|
options: { showContent: !0 }
|
|
2004
2030
|
});
|
|
@@ -2018,12 +2044,12 @@ async function At(e, t) {
|
|
|
2018
2044
|
console.warn(`unexpected pyth price struct, priceInfoObject: ${i.objectId}`);
|
|
2019
2045
|
continue;
|
|
2020
2046
|
}
|
|
2021
|
-
const { magnitude: w, negative:
|
|
2047
|
+
const { magnitude: w, negative: g } = m, y = u.conf, d = u.timestamp;
|
|
2022
2048
|
r.push({
|
|
2023
2049
|
priceFeedId: s.priceFeedId,
|
|
2024
2050
|
priceInfoObject: s.priceInfoObject,
|
|
2025
|
-
price:
|
|
2026
|
-
conf:
|
|
2051
|
+
price: g ? "-" + w : w,
|
|
2052
|
+
conf: y,
|
|
2027
2053
|
publishTime: Number(d),
|
|
2028
2054
|
expiration: s.expiration
|
|
2029
2055
|
});
|
|
@@ -2053,12 +2079,12 @@ async function St(e, t) {
|
|
|
2053
2079
|
}
|
|
2054
2080
|
}
|
|
2055
2081
|
async function $t(e, t, r) {
|
|
2056
|
-
const o = r?.client ??
|
|
2082
|
+
const o = r?.client ?? U, n = await I({
|
|
2057
2083
|
...r,
|
|
2058
2084
|
cacheTime: v
|
|
2059
2085
|
});
|
|
2060
2086
|
try {
|
|
2061
|
-
const a = await
|
|
2087
|
+
const a = await Ee.getPriceFeedsUpdateData(t);
|
|
2062
2088
|
return await new lt(
|
|
2063
2089
|
o,
|
|
2064
2090
|
n.oracle.pythStateId,
|
|
@@ -2068,8 +2094,8 @@ async function $t(e, t, r) {
|
|
|
2068
2094
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
2069
2095
|
}
|
|
2070
2096
|
}
|
|
2071
|
-
async function
|
|
2072
|
-
const o = await
|
|
2097
|
+
async function ge(e, t, r) {
|
|
2098
|
+
const o = await I({
|
|
2073
2099
|
...r,
|
|
2074
2100
|
cacheTime: v
|
|
2075
2101
|
});
|
|
@@ -2102,8 +2128,8 @@ async function fe(e, t, r) {
|
|
|
2102
2128
|
});
|
|
2103
2129
|
return e;
|
|
2104
2130
|
}
|
|
2105
|
-
async function
|
|
2106
|
-
return (await
|
|
2131
|
+
async function Oe(e) {
|
|
2132
|
+
return (await I({
|
|
2107
2133
|
...e,
|
|
2108
2134
|
cacheTime: v
|
|
2109
2135
|
})).oracle.feeds;
|
|
@@ -2124,7 +2150,7 @@ function Et(e, t) {
|
|
|
2124
2150
|
async function yr(e, t, r, o) {
|
|
2125
2151
|
let n;
|
|
2126
2152
|
try {
|
|
2127
|
-
const a = await
|
|
2153
|
+
const a = await Oe({
|
|
2128
2154
|
...o
|
|
2129
2155
|
}), c = [];
|
|
2130
2156
|
r.forEach((u) => {
|
|
@@ -2137,7 +2163,7 @@ async function yr(e, t, r, o) {
|
|
|
2137
2163
|
return n = Et(a, {
|
|
2138
2164
|
lendingPositions: i,
|
|
2139
2165
|
pools: r
|
|
2140
|
-
}), await
|
|
2166
|
+
}), await ge(e, n, {
|
|
2141
2167
|
updatePythPriceFeeds: !0,
|
|
2142
2168
|
...o
|
|
2143
2169
|
});
|
|
@@ -2146,7 +2172,7 @@ async function yr(e, t, r, o) {
|
|
|
2146
2172
|
throw a;
|
|
2147
2173
|
if (console.error(a), n)
|
|
2148
2174
|
try {
|
|
2149
|
-
return await
|
|
2175
|
+
return await ge(e, n, {
|
|
2150
2176
|
...o,
|
|
2151
2177
|
updatePythPriceFeeds: !1
|
|
2152
2178
|
});
|
|
@@ -2156,14 +2182,14 @@ async function yr(e, t, r, o) {
|
|
|
2156
2182
|
return e;
|
|
2157
2183
|
}
|
|
2158
2184
|
}
|
|
2159
|
-
const
|
|
2160
|
-
|
|
2185
|
+
const ae = O(
|
|
2186
|
+
S(
|
|
2161
2187
|
async (e) => {
|
|
2162
|
-
const t =
|
|
2163
|
-
`/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}`,
|
|
2164
2190
|
e
|
|
2165
2191
|
), o = await fetch(r, {
|
|
2166
|
-
headers:
|
|
2192
|
+
headers: N(R, t)
|
|
2167
2193
|
}).then((n) => n.json());
|
|
2168
2194
|
return Object.keys(o.data).map((n) => ({
|
|
2169
2195
|
...o.data[n],
|
|
@@ -2173,14 +2199,14 @@ const ne = $(
|
|
|
2173
2199
|
)
|
|
2174
2200
|
);
|
|
2175
2201
|
async function gr(e, t) {
|
|
2176
|
-
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;
|
|
2177
2203
|
}
|
|
2178
2204
|
async function hr(e, t, r, o) {
|
|
2179
|
-
const n = await
|
|
2205
|
+
const n = await I({
|
|
2180
2206
|
...o,
|
|
2181
2207
|
cacheTime: v
|
|
2182
|
-
}), a = await
|
|
2183
|
-
if (!(await
|
|
2208
|
+
}), a = await E(t, o);
|
|
2209
|
+
if (!(await ae({
|
|
2184
2210
|
...o,
|
|
2185
2211
|
cacheTime: v
|
|
2186
2212
|
})).some(
|
|
@@ -2213,11 +2239,11 @@ async function hr(e, t, r, o) {
|
|
|
2213
2239
|
}
|
|
2214
2240
|
}
|
|
2215
2241
|
async function wr(e, t, r, o, n) {
|
|
2216
|
-
const a = await
|
|
2242
|
+
const a = await I({
|
|
2217
2243
|
...n,
|
|
2218
2244
|
cacheTime: v
|
|
2219
|
-
}), c = await
|
|
2220
|
-
if (!(await
|
|
2245
|
+
}), c = await E(t, n);
|
|
2246
|
+
if (!(await ae({
|
|
2221
2247
|
...n,
|
|
2222
2248
|
cacheTime: v
|
|
2223
2249
|
})).some(
|
|
@@ -2241,7 +2267,7 @@ async function br(e, t, r, o, n, a) {
|
|
|
2241
2267
|
const c = {
|
|
2242
2268
|
...a,
|
|
2243
2269
|
cacheTime: v
|
|
2244
|
-
}, i = await
|
|
2270
|
+
}, i = await I(c), s = await E(t, c), u = await E(o, c);
|
|
2245
2271
|
if (i.version === 1) {
|
|
2246
2272
|
const [m, w] = e.moveCall({
|
|
2247
2273
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
@@ -2307,19 +2333,19 @@ async function br(e, t, r, o, n, a) {
|
|
|
2307
2333
|
}
|
|
2308
2334
|
}
|
|
2309
2335
|
async function Ot(e, t, r) {
|
|
2310
|
-
const o = r?.client ??
|
|
2336
|
+
const o = r?.client ?? U, n = await J({
|
|
2311
2337
|
...r,
|
|
2312
|
-
markets: Object.values(
|
|
2338
|
+
markets: Object.values(L),
|
|
2313
2339
|
cacheTime: v
|
|
2314
|
-
}), a = await
|
|
2340
|
+
}), a = await Oe(r), c = [];
|
|
2315
2341
|
return await Promise.all(
|
|
2316
2342
|
t.map(async (i) => {
|
|
2317
2343
|
try {
|
|
2318
|
-
const s = await
|
|
2344
|
+
const s = await I({
|
|
2319
2345
|
...r,
|
|
2320
2346
|
cacheTime: v,
|
|
2321
2347
|
market: i.market
|
|
2322
|
-
}), u = new
|
|
2348
|
+
}), u = new q();
|
|
2323
2349
|
u.moveCall({
|
|
2324
2350
|
target: `${s.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
2325
2351
|
arguments: [
|
|
@@ -2333,13 +2359,13 @@ async function Ot(e, t, r) {
|
|
|
2333
2359
|
// User address
|
|
2334
2360
|
]
|
|
2335
2361
|
});
|
|
2336
|
-
const w = (await
|
|
2362
|
+
const w = (await W(o, {
|
|
2337
2363
|
transactionBlock: u,
|
|
2338
2364
|
sender: e
|
|
2339
2365
|
}))?.results?.[0];
|
|
2340
2366
|
if (!w)
|
|
2341
2367
|
return;
|
|
2342
|
-
const
|
|
2368
|
+
const g = Z({ results: [w] }, [
|
|
2343
2369
|
l.vector(l.string()),
|
|
2344
2370
|
// Asset coin types
|
|
2345
2371
|
l.vector(l.string()),
|
|
@@ -2351,21 +2377,21 @@ async function Ot(e, t, r) {
|
|
|
2351
2377
|
l.vector(l.u256())
|
|
2352
2378
|
// Claimable amounts
|
|
2353
2379
|
]);
|
|
2354
|
-
if (
|
|
2355
|
-
const
|
|
2356
|
-
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++) {
|
|
2357
2383
|
const f = a.find(
|
|
2358
|
-
(
|
|
2384
|
+
(j) => C(j.coinType) === C(g[1][d])
|
|
2359
2385
|
), b = n.find(
|
|
2360
|
-
(
|
|
2386
|
+
(j) => C(j.coinType) === C(g[0][d]) && j.market === i.market
|
|
2361
2387
|
);
|
|
2362
2388
|
!f || !b || c.push({
|
|
2363
2389
|
assetId: b.id,
|
|
2364
|
-
assetCoinType: C(
|
|
2365
|
-
rewardCoinType: C(
|
|
2366
|
-
option: Number(
|
|
2367
|
-
userClaimableReward: Number(
|
|
2368
|
-
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]],
|
|
2369
2395
|
market: i.market,
|
|
2370
2396
|
owner: i.owner,
|
|
2371
2397
|
address: i.address,
|
|
@@ -2383,13 +2409,13 @@ async function Ot(e, t, r) {
|
|
|
2383
2409
|
), c;
|
|
2384
2410
|
}
|
|
2385
2411
|
async function vr(e, t) {
|
|
2386
|
-
const r = (t?.markets || [
|
|
2412
|
+
const r = (t?.markets || [L.main]).map((a) => P(a)), o = await Ae(e, t), n = r.map((a) => ({
|
|
2387
2413
|
address: e,
|
|
2388
2414
|
owner: e,
|
|
2389
2415
|
market: a.key
|
|
2390
2416
|
})).concat(
|
|
2391
2417
|
o.filter((a) => !!r.find((c) => c.id === a.marketId)).map((a) => {
|
|
2392
|
-
const c =
|
|
2418
|
+
const c = P(a.marketId);
|
|
2393
2419
|
return {
|
|
2394
2420
|
address: a.accountCap,
|
|
2395
2421
|
owner: e,
|
|
@@ -2429,72 +2455,72 @@ function Cr(e) {
|
|
|
2429
2455
|
}))
|
|
2430
2456
|
}));
|
|
2431
2457
|
}
|
|
2432
|
-
const jr =
|
|
2458
|
+
const jr = S(
|
|
2433
2459
|
async (e, t) => {
|
|
2434
|
-
const r =
|
|
2435
|
-
`/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}`,
|
|
2436
2462
|
t
|
|
2437
2463
|
);
|
|
2438
2464
|
return (await fetch(o, {
|
|
2439
|
-
headers:
|
|
2465
|
+
headers: N(R, r)
|
|
2440
2466
|
}).then((a) => a.json())).data;
|
|
2441
2467
|
}
|
|
2442
|
-
),
|
|
2468
|
+
), Ir = S(
|
|
2443
2469
|
async (e, t) => {
|
|
2444
|
-
const r =
|
|
2445
|
-
`/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}`,
|
|
2446
2472
|
t
|
|
2447
2473
|
), n = await fetch(o, {
|
|
2448
|
-
headers:
|
|
2474
|
+
headers: N(R, r)
|
|
2449
2475
|
}).then((a) => a.json());
|
|
2450
|
-
return
|
|
2476
|
+
return re({
|
|
2451
2477
|
data: n.data.rewards
|
|
2452
2478
|
});
|
|
2453
2479
|
}
|
|
2454
2480
|
);
|
|
2455
|
-
async function
|
|
2456
|
-
const o = await
|
|
2481
|
+
async function kr(e, t, r) {
|
|
2482
|
+
const o = await J({
|
|
2457
2483
|
...r,
|
|
2458
|
-
markets: Object.values(
|
|
2484
|
+
markets: Object.values(L),
|
|
2459
2485
|
cacheTime: v
|
|
2460
2486
|
}), n = /* @__PURE__ */ new Map();
|
|
2461
2487
|
for (const c of t) {
|
|
2462
|
-
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}`;
|
|
2463
2489
|
for (const d of s) {
|
|
2464
|
-
n.has(
|
|
2490
|
+
n.has(y) || n.set(y, {
|
|
2465
2491
|
assetIds: [],
|
|
2466
2492
|
ruleIds: [],
|
|
2467
2493
|
amount: 0,
|
|
2468
2494
|
market: u,
|
|
2469
2495
|
owner: m,
|
|
2470
2496
|
address: w,
|
|
2471
|
-
isEMode: typeof
|
|
2497
|
+
isEMode: typeof g < "u"
|
|
2472
2498
|
});
|
|
2473
|
-
const f = n.get(
|
|
2499
|
+
const f = n.get(y);
|
|
2474
2500
|
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(d), f.amount += c.userClaimableReward;
|
|
2475
2501
|
}
|
|
2476
2502
|
}
|
|
2477
2503
|
const a = [];
|
|
2478
2504
|
for (const [
|
|
2479
2505
|
c,
|
|
2480
|
-
{ 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 }
|
|
2481
2507
|
] of n) {
|
|
2482
|
-
const d = await
|
|
2508
|
+
const d = await I({
|
|
2483
2509
|
...r,
|
|
2484
2510
|
cacheTime: v,
|
|
2485
2511
|
market: m
|
|
2486
2512
|
}), f = c.split("___")[0], b = o.filter(
|
|
2487
|
-
(
|
|
2513
|
+
(k) => C(k.suiCoinType) === C(f)
|
|
2488
2514
|
);
|
|
2489
|
-
b.sort((
|
|
2490
|
-
const
|
|
2491
|
-
if (!
|
|
2515
|
+
b.sort((k, T) => k.market === m ? -1 : 1);
|
|
2516
|
+
const j = b[0], _ = d.rewardFunds[C(f)];
|
|
2517
|
+
if (!_)
|
|
2492
2518
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${m}`);
|
|
2493
2519
|
if (r?.accountCap && !r.customCoinReceive)
|
|
2494
2520
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
2495
2521
|
if (r?.customCoinReceive) {
|
|
2496
|
-
let
|
|
2497
|
-
r.accountCap ?
|
|
2522
|
+
let k;
|
|
2523
|
+
r.accountCap ? k = e.moveCall({
|
|
2498
2524
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2499
2525
|
arguments: [
|
|
2500
2526
|
e.object("0x06"),
|
|
@@ -2503,7 +2529,7 @@ async function Ir(e, t, r) {
|
|
|
2503
2529
|
// Incentive V3 contract
|
|
2504
2530
|
e.object(d.storage),
|
|
2505
2531
|
// Protocol storage
|
|
2506
|
-
e.object(
|
|
2532
|
+
e.object(_),
|
|
2507
2533
|
// Reward fund
|
|
2508
2534
|
e.pure.vector("string", i),
|
|
2509
2535
|
// Asset IDs
|
|
@@ -2513,7 +2539,7 @@ async function Ir(e, t, r) {
|
|
|
2513
2539
|
// Account capability
|
|
2514
2540
|
],
|
|
2515
2541
|
typeArguments: [f]
|
|
2516
|
-
}) :
|
|
2542
|
+
}) : y ? k = e.moveCall({
|
|
2517
2543
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2518
2544
|
arguments: [
|
|
2519
2545
|
e.object("0x06"),
|
|
@@ -2522,17 +2548,17 @@ async function Ir(e, t, r) {
|
|
|
2522
2548
|
// Incentive V3 contract
|
|
2523
2549
|
e.object(d.storage),
|
|
2524
2550
|
// Protocol storage
|
|
2525
|
-
e.object(
|
|
2551
|
+
e.object(_),
|
|
2526
2552
|
// Reward fund
|
|
2527
2553
|
e.pure.vector("string", i),
|
|
2528
2554
|
// Asset IDs
|
|
2529
2555
|
e.pure.vector("address", s),
|
|
2530
2556
|
// Rule IDs
|
|
2531
|
-
h(
|
|
2557
|
+
h(g, e.object)
|
|
2532
2558
|
// Account capability
|
|
2533
2559
|
],
|
|
2534
2560
|
typeArguments: [f]
|
|
2535
|
-
}) :
|
|
2561
|
+
}) : k = e.moveCall({
|
|
2536
2562
|
target: `${d.package}::incentive_v3::claim_reward`,
|
|
2537
2563
|
arguments: [
|
|
2538
2564
|
e.object("0x06"),
|
|
@@ -2541,7 +2567,7 @@ async function Ir(e, t, r) {
|
|
|
2541
2567
|
// Incentive V3 contract
|
|
2542
2568
|
e.object(d.storage),
|
|
2543
2569
|
// Protocol storage
|
|
2544
|
-
e.object(
|
|
2570
|
+
e.object(_),
|
|
2545
2571
|
// Reward fund
|
|
2546
2572
|
e.pure.vector("string", i),
|
|
2547
2573
|
// Asset IDs
|
|
@@ -2550,37 +2576,37 @@ async function Ir(e, t, r) {
|
|
|
2550
2576
|
],
|
|
2551
2577
|
typeArguments: [f]
|
|
2552
2578
|
});
|
|
2553
|
-
const [
|
|
2579
|
+
const [T] = e.moveCall({
|
|
2554
2580
|
target: "0x2::coin::from_balance",
|
|
2555
|
-
arguments: [
|
|
2581
|
+
arguments: [k],
|
|
2556
2582
|
typeArguments: [f]
|
|
2557
2583
|
});
|
|
2558
2584
|
if (r?.customCoinReceive.type === "transfer") {
|
|
2559
2585
|
if (!r.customCoinReceive.transfer)
|
|
2560
2586
|
throw new Error("customCoinReceive.transfer is required");
|
|
2561
2587
|
e.transferObjects(
|
|
2562
|
-
[
|
|
2588
|
+
[T],
|
|
2563
2589
|
h(r.customCoinReceive.transfer, e.pure.address)
|
|
2564
2590
|
);
|
|
2565
2591
|
}
|
|
2566
2592
|
if (r?.customCoinReceive.type === "depositNAVI") {
|
|
2567
|
-
const
|
|
2568
|
-
|
|
2569
|
-
[
|
|
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],
|
|
2570
2596
|
e.pure.address(r.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
2571
|
-
) : await vt(e,
|
|
2597
|
+
) : await vt(e, j, T, {
|
|
2572
2598
|
...r,
|
|
2573
|
-
market:
|
|
2599
|
+
market: j.market
|
|
2574
2600
|
});
|
|
2575
2601
|
} else
|
|
2576
2602
|
a.push({
|
|
2577
|
-
coin:
|
|
2578
|
-
identifier:
|
|
2603
|
+
coin: T,
|
|
2604
|
+
identifier: j,
|
|
2579
2605
|
owner: w,
|
|
2580
|
-
isEMode:
|
|
2606
|
+
isEMode: y
|
|
2581
2607
|
});
|
|
2582
|
-
} else if (r?.accountCap ||
|
|
2583
|
-
const
|
|
2608
|
+
} else if (r?.accountCap || y) {
|
|
2609
|
+
const k = e.moveCall({
|
|
2584
2610
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2585
2611
|
arguments: [
|
|
2586
2612
|
e.object("0x06"),
|
|
@@ -2589,23 +2615,23 @@ async function Ir(e, t, r) {
|
|
|
2589
2615
|
// Incentive V3 contract
|
|
2590
2616
|
e.object(d.storage),
|
|
2591
2617
|
// Protocol storage
|
|
2592
|
-
e.object(
|
|
2618
|
+
e.object(_),
|
|
2593
2619
|
// Reward fund
|
|
2594
2620
|
e.pure.vector("string", i),
|
|
2595
2621
|
// Asset IDs
|
|
2596
2622
|
e.pure.vector("address", s),
|
|
2597
2623
|
// Rule IDs
|
|
2598
|
-
h(r?.accountCap ||
|
|
2624
|
+
h(r?.accountCap || g, e.object)
|
|
2599
2625
|
// Account capability
|
|
2600
2626
|
],
|
|
2601
2627
|
typeArguments: [f]
|
|
2602
|
-
}), [
|
|
2628
|
+
}), [T] = e.moveCall({
|
|
2603
2629
|
target: "0x2::coin::from_balance",
|
|
2604
|
-
arguments: [
|
|
2630
|
+
arguments: [k],
|
|
2605
2631
|
typeArguments: [f]
|
|
2606
2632
|
});
|
|
2607
2633
|
e.transferObjects(
|
|
2608
|
-
[
|
|
2634
|
+
[T],
|
|
2609
2635
|
h(r?.accountCap || w, e.pure.address)
|
|
2610
2636
|
);
|
|
2611
2637
|
} else
|
|
@@ -2618,7 +2644,7 @@ async function Ir(e, t, r) {
|
|
|
2618
2644
|
// Incentive V3 contract
|
|
2619
2645
|
e.object(d.storage),
|
|
2620
2646
|
// Protocol storage
|
|
2621
|
-
e.object(
|
|
2647
|
+
e.object(_),
|
|
2622
2648
|
// Reward fund
|
|
2623
2649
|
e.pure.vector("string", i),
|
|
2624
2650
|
// Asset IDs
|
|
@@ -2631,31 +2657,31 @@ async function Ir(e, t, r) {
|
|
|
2631
2657
|
return a;
|
|
2632
2658
|
}
|
|
2633
2659
|
export {
|
|
2634
|
-
|
|
2660
|
+
ie as Address,
|
|
2635
2661
|
v as DEFAULT_CACHE_TIME,
|
|
2636
|
-
|
|
2662
|
+
z as DEFAULT_MARKET_IDENTITY,
|
|
2637
2663
|
Wt as FlashLoanAssetConfig,
|
|
2638
2664
|
qt as IncentiveAPYInfo,
|
|
2639
2665
|
Le as IncentivePoolInfo,
|
|
2640
2666
|
zt as IncentivePoolInfoByPhase,
|
|
2641
|
-
|
|
2667
|
+
L as MARKETS,
|
|
2642
2668
|
Ct as Market,
|
|
2643
2669
|
Ke as NaviMissingGraphQLClientError,
|
|
2644
2670
|
Gt as OracleInfo,
|
|
2645
2671
|
et as PUBLIC_MAINNET_GRPC_URL,
|
|
2646
|
-
|
|
2672
|
+
H as PoolOperator,
|
|
2647
2673
|
qe as ReserveDataInfo,
|
|
2648
|
-
|
|
2674
|
+
Ie as SuiPriceServiceConnection,
|
|
2649
2675
|
lt as SuiPythClient,
|
|
2650
|
-
|
|
2676
|
+
G as UserPositions,
|
|
2651
2677
|
ze as UserStateInfo,
|
|
2652
2678
|
er as borrowCoinPTB,
|
|
2653
|
-
|
|
2654
|
-
|
|
2679
|
+
F as buildNaviOpenApiUrl,
|
|
2680
|
+
kr as claimLendingRewardsPTB,
|
|
2655
2681
|
Yt as configureNaviSdk,
|
|
2656
|
-
|
|
2682
|
+
It as createAccountCapPTB,
|
|
2657
2683
|
ar as createEModeCapPTB,
|
|
2658
|
-
|
|
2684
|
+
je as createNaviLegacyJsonRpcClient,
|
|
2659
2685
|
rt as createNaviSuiClient,
|
|
2660
2686
|
xe as createNaviSuiClientBundle,
|
|
2661
2687
|
vt as depositCoinPTB,
|
|
@@ -2664,13 +2690,13 @@ export {
|
|
|
2664
2690
|
or as exitEModePTB,
|
|
2665
2691
|
Et as filterPriceFeeds,
|
|
2666
2692
|
hr as flashloanPTB,
|
|
2667
|
-
|
|
2693
|
+
kt as getAccountCapOwnerPTB,
|
|
2668
2694
|
Jt as getAddressBalance,
|
|
2669
|
-
|
|
2695
|
+
ae as getAllFlashLoanAssets,
|
|
2670
2696
|
rr as getBorrowFee,
|
|
2671
2697
|
Ht as getCoinObjectOnlyBalance,
|
|
2672
2698
|
pr as getCoins,
|
|
2673
|
-
|
|
2699
|
+
I as getConfig,
|
|
2674
2700
|
Xt as getFees,
|
|
2675
2701
|
gr as getFlashLoanAsset,
|
|
2676
2702
|
ur as getHealthFactor,
|
|
@@ -2678,40 +2704,40 @@ export {
|
|
|
2678
2704
|
Pt as getLendingPositions,
|
|
2679
2705
|
sr as getLendingState,
|
|
2680
2706
|
nr as getMarket,
|
|
2681
|
-
|
|
2707
|
+
P as getMarketConfig,
|
|
2682
2708
|
jt as getMarkets,
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2709
|
+
E as getPool,
|
|
2710
|
+
J as getPools,
|
|
2711
|
+
Oe as getPriceFeeds,
|
|
2686
2712
|
fr as getPythStalePriceFeedId,
|
|
2687
2713
|
St as getPythStalePriceFeedIdV2,
|
|
2688
2714
|
lr as getSimulatedHealthFactor,
|
|
2689
|
-
|
|
2715
|
+
Se as getSimulatedHealthFactorPTB,
|
|
2690
2716
|
Zt as getStats,
|
|
2691
2717
|
dr as getTransactions,
|
|
2692
2718
|
vr as getUserAvailableLendingRewards,
|
|
2693
|
-
|
|
2694
|
-
|
|
2719
|
+
Ir as getUserClaimedRewardHistory,
|
|
2720
|
+
Ae as getUserEModeCaps,
|
|
2695
2721
|
jr as getUserTotalClaimedReward,
|
|
2696
2722
|
br as liquidatePTB,
|
|
2697
2723
|
Kt as listAddressBalances,
|
|
2698
2724
|
cr as mergeCoinsPTB,
|
|
2699
|
-
|
|
2700
|
-
|
|
2725
|
+
N as mergeServiceHeaders,
|
|
2726
|
+
Ce as normalizeAddressBalance,
|
|
2701
2727
|
C as normalizeCoinType,
|
|
2702
2728
|
bt as parsePoolUID,
|
|
2703
2729
|
h as parseTxValue,
|
|
2704
2730
|
tr as repayCoinPTB,
|
|
2705
2731
|
wr as repayFlashLoanPTB,
|
|
2706
2732
|
Qt as requireNaviGraphQLClient,
|
|
2707
|
-
|
|
2733
|
+
M as resolveNaviOpenApiEndpoint,
|
|
2708
2734
|
Cr as summaryLendingRewards,
|
|
2709
2735
|
yr as updateOraclePriceBeforeUserOperationPTB,
|
|
2710
|
-
|
|
2736
|
+
ge as updateOraclePricesPTB,
|
|
2711
2737
|
$t as updatePythPriceFeeds,
|
|
2712
2738
|
mr as verifyHealthFactorPTB,
|
|
2713
|
-
|
|
2714
|
-
|
|
2739
|
+
O as withCache,
|
|
2740
|
+
S as withSingleton,
|
|
2715
2741
|
xt as withdrawCoinPTB
|
|
2716
2742
|
};
|
|
2717
2743
|
//# sourceMappingURL=index.esm.js.map
|