@naviprotocol/lending 1.4.0-emode.11 → 1.4.0-emode.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,16 +1,16 @@
1
- import { Transaction as U } from "@mysten/sui/transactions";
1
+ import { Transaction as M } from "@mysten/sui/transactions";
2
2
  import { bcs as p, toHex as ne, fromHex as re } from "@mysten/bcs";
3
- import { SuiClient as ae, getFullnodeUrl as ce } from "@mysten/sui/client";
4
- import ie from "lodash.camelcase";
3
+ import { SuiClient as ae, getFullnodeUrl as ie } from "@mysten/sui/client";
4
+ import ce from "lodash.camelcase";
5
5
  import { normalizeStructTag as se } from "@mysten/sui/utils";
6
- import { SuiPriceServiceConnection as z, SuiPythClient as ue } from "@pythnetwork/pyth-sui-js";
6
+ import { SuiPriceServiceConnection as K, SuiPythClient as ue } from "@pythnetwork/pyth-sui-js";
7
7
  import l from "bignumber.js";
8
8
  import { bcs as _ } from "@mysten/sui/bcs";
9
- const L = p.bytes(32).transform({
9
+ const q = p.bytes(32).transform({
10
10
  // To change the input type, you need to provide a type definition for the input
11
11
  input: (e) => re(e),
12
12
  output: (e) => ne(e)
13
- }), Le = p.struct("IncentiveAPYInfo", {
13
+ }), Fe = p.struct("IncentiveAPYInfo", {
14
14
  /** Asset identifier */
15
15
  asset_id: p.u8(),
16
16
  /** Annual Percentage Yield as a 256-bit integer */
@@ -19,9 +19,9 @@ const L = p.bytes(32).transform({
19
19
  coin_types: p.vector(p.string())
20
20
  }), le = p.struct("IncentivePoolInfo", {
21
21
  /** Unique pool identifier */
22
- pool_id: L,
22
+ pool_id: q,
23
23
  /** Address holding the incentive funds */
24
- funds: L,
24
+ funds: q,
25
25
  /** Current phase of the incentive program */
26
26
  phase: p.u64(),
27
27
  /** Timestamp when the incentive started */
@@ -44,12 +44,12 @@ const L = p.bytes(32).transform({
44
44
  available: p.u256(),
45
45
  /** Total amount of incentives */
46
46
  total: p.u256()
47
- }), qe = p.struct("IncentivePoolInfoByPhase", {
47
+ }), Le = p.struct("IncentivePoolInfoByPhase", {
48
48
  /** Phase number */
49
49
  phase: p.u64(),
50
50
  /** List of incentive pools in this phase */
51
51
  pools: p.vector(le)
52
- }), We = p.struct("OracleInfo", {
52
+ }), qe = p.struct("OracleInfo", {
53
53
  /** Oracle identifier */
54
54
  oracle_id: p.u8(),
55
55
  /** Current price as a 256-bit integer */
@@ -58,7 +58,7 @@ const L = p.bytes(32).transform({
58
58
  decimals: p.u8(),
59
59
  /** Whether the oracle data is valid */
60
60
  valid: p.bool()
61
- }), He = p.struct("FlashLoanAssetConfig", {
61
+ }), We = p.struct("FlashLoanAssetConfig", {
62
62
  /** Unique identifier for the flash loan asset */
63
63
  id: p.string(),
64
64
  /** Asset identifier */
@@ -75,7 +75,7 @@ const L = p.bytes(32).transform({
75
75
  max: p.u64(),
76
76
  /** Minimum flash loan amount */
77
77
  min: p.u64()
78
- }), Ge = p.struct("ReserveDataInfo", {
78
+ }), He = p.struct("ReserveDataInfo", {
79
79
  /** Reserve identifier */
80
80
  id: p.u8(),
81
81
  /** Oracle identifier for price feeds */
@@ -129,13 +129,13 @@ const L = p.bytes(32).transform({
129
129
  borrow_balance: p.u256(),
130
130
  /** User's current supply balance */
131
131
  supply_balance: p.u256()
132
- }), de = "1.4.0-emode.11", S = {
132
+ }), de = "1.4.0-emode.12", P = {
133
133
  version: de
134
- }, me = S.version, ge = () => {
134
+ }, me = P.version, ge = () => {
135
135
  if (typeof process < "u" && process.versions && process.versions.node)
136
136
  try {
137
- const e = require("os"), o = process.version, n = e.type(), r = e.arch();
138
- return `Node.js ${o.startsWith("v") ? o.substring(1) : o}; ${n}/${r}`;
137
+ const e = require("os"), n = process.version, o = e.type(), r = e.arch();
138
+ return `Node.js ${n.startsWith("v") ? n.substring(1) : n}; ${o}/${r}`;
139
139
  } catch {
140
140
  return `Node.js ${process.version}; OS/Unknown (Error)`;
141
141
  }
@@ -143,58 +143,58 @@ const L = p.bytes(32).transform({
143
143
  }, fe = () => {
144
144
  let e = "";
145
145
  return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${me} (${ge()})`), e;
146
- }, q = fe(), $ = new ae({
147
- url: ce("mainnet")
146
+ }, W = fe(), $ = new ae({
147
+ url: ie("mainnet")
148
148
  });
149
- function K(e) {
150
- const o = [];
151
- return e.forEach((n, r) => {
149
+ function Y(e) {
150
+ const n = [];
151
+ return e.forEach((o, r) => {
152
152
  const t = r === e.length - 1;
153
- if (typeof n == "object" && n !== null && t) {
154
- const { client: a, disableCache: i, cacheTime: c, ...u } = n;
155
- o.push(u);
153
+ if (typeof o == "object" && o !== null && t) {
154
+ const { client: a, disableCache: c, cacheTime: i, ...s } = o;
155
+ n.push(s);
156
156
  } else
157
- o.push(n);
158
- }), JSON.stringify(o);
157
+ n.push(o);
158
+ }), JSON.stringify(n);
159
159
  }
160
- function B(e) {
161
- const o = {};
162
- return (...n) => {
163
- const r = K(n);
164
- return o[r] || (o[r] = e(...n).finally(() => {
165
- delete o[r];
166
- })), o[r];
160
+ function I(e) {
161
+ const n = {};
162
+ return (...o) => {
163
+ const r = Y(o);
164
+ return n[r] || (n[r] = e(...o).finally(() => {
165
+ delete n[r];
166
+ })), n[r];
167
167
  };
168
168
  }
169
- function I(e) {
170
- let o = {};
171
- return (...n) => {
172
- const r = n[n.length - 1], t = K(n), a = o[t];
173
- return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? a.data : e(...n).then((i) => (o[t] = {
174
- data: i,
169
+ function A(e) {
170
+ let n = {};
171
+ return (...o) => {
172
+ const r = o[o.length - 1], t = Y(o), a = n[t];
173
+ return !r?.disableCache && typeof a?.data < "u" && (typeof r?.cacheTime > "u" || r.cacheTime > Date.now() - a.cacheAt) ? a.data : e(...o).then((c) => (n[t] = {
174
+ data: c,
175
175
  cacheAt: Date.now()
176
- }, i));
176
+ }, c));
177
177
  };
178
178
  }
179
- function R(e) {
180
- return Array.isArray(e) ? e.map((o) => R(o)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
181
- (o, n) => ({
182
- ...o,
183
- [ie(n)]: R(e[n])
179
+ function O(e) {
180
+ return Array.isArray(e) ? e.map((n) => O(n)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
181
+ (n, o) => ({
182
+ ...n,
183
+ [ce(o)]: O(e[o])
184
184
  }),
185
185
  {}
186
186
  ) : e;
187
187
  }
188
- function f(e, o) {
189
- return typeof e == "object" ? e : o(e);
188
+ function f(e, n) {
189
+ return typeof e == "object" ? e : n(e);
190
190
  }
191
- function ye(e, o) {
192
- return typeof o == "string" ? e.object(o) : typeof o == "object" && o.$kind ? o : e.object(o.contract.pool);
191
+ function ye(e, n) {
192
+ return typeof n == "string" ? e.object(n) : typeof n == "object" && n.$kind ? n : e.object(n.contract.pool);
193
193
  }
194
- function O(e, o, n) {
194
+ function R(e, n, o) {
195
195
  if (e.results && e.results.length > 0) {
196
196
  if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
197
- return e.results[0].returnValues.map((r, t) => (o[t] || o[0]).parse(Uint8Array.from(r[0])));
197
+ return e.results[0].returnValues.map((r, t) => (n[t] || n[0]).parse(Uint8Array.from(r[0])));
198
198
  } else if (e.error)
199
199
  return console.log(`Get an error, msg: ${e.error}`), [];
200
200
  return [];
@@ -202,83 +202,87 @@ function O(e, o, n) {
202
202
  function b(e) {
203
203
  return se(e);
204
204
  }
205
- function Y(e) {
206
- const o = (e || 0) / Math.pow(10, 27);
207
- return o > Math.pow(10, 5) ? 1 / 0 : o;
205
+ function J(e) {
206
+ const n = (e || 0) / Math.pow(10, 27);
207
+ return n > Math.pow(10, 5) ? 1 / 0 : n;
208
208
  }
209
- new z("https://hermes.pyth.network", {
209
+ new K("https://hermes.pyth.network", {
210
210
  timeout: 2e4
211
211
  });
212
- const ve = 27, W = (e, o) => {
213
- if (!Number(e) || !Number(o)) return new l(0);
214
- const n = new l(1).shiftedBy(1 * ve), r = n.multipliedBy(new l(0.5));
215
- return new l(e).multipliedBy(new l(o)).plus(r).dividedBy(n).integerValue(l.ROUND_DOWN);
216
- }, V = q ? {
217
- "User-Agent": q
212
+ const ve = 27, H = (e, n) => {
213
+ if (!Number(e) || !Number(n)) return new l(0);
214
+ const o = new l(1).shiftedBy(1 * ve), r = o.multipliedBy(new l(0.5));
215
+ return new l(e).multipliedBy(new l(n)).plus(r).dividedBy(o).integerValue(l.ROUND_DOWN);
216
+ }, V = W ? {
217
+ "User-Agent": W
218
218
  } : {};
219
- function J(e) {
219
+ function F(e, n = "uniqueId") {
220
220
  return e.reduce(
221
- (o, n) => (o[n.uniqueId] = n, o),
221
+ (o, r) => (o[n] = r, o),
222
222
  {}
223
223
  );
224
224
  }
225
- function H(e) {
225
+ function G(e, n = "uniqueId") {
226
226
  return e.reduce(
227
- (o, n) => (o[n.uniqueId] = n, o),
227
+ (o, r) => (o[n] = r, o),
228
228
  {}
229
229
  );
230
230
  }
231
- function G(e, o) {
232
- const n = e.emodes.find((r) => r.emodeId === o.emodeId);
233
- if (!n)
231
+ function z(e, n) {
232
+ const o = e.emodes.find((t) => t.emodeId === n.emodeId);
233
+ if (!o)
234
234
  throw new Error("EMode not found in pool");
235
+ const r = o.assets.find((t) => t.assetId === e.id);
235
236
  return {
236
237
  ...e,
237
- emode: n,
238
+ emode: {
239
+ ...r,
240
+ emodeId: o.emodeId
241
+ },
238
242
  isEMode: !0
239
243
  };
240
244
  }
241
245
  function we(e) {
242
- const [o, n] = e.split("-");
243
- return !o || !n ? null : {
244
- marketKey: o,
245
- poolId: parseInt(n)
246
+ const [n, o] = e.split("-");
247
+ return !n || !o ? null : {
248
+ marketKey: n,
249
+ poolId: parseInt(o)
246
250
  };
247
251
  }
248
- function P() {
252
+ function S() {
249
253
  return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
250
254
  }
251
255
  var D = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(D || {});
252
- const N = I(
253
- B(
256
+ const N = A(
257
+ I(
254
258
  async (e) => {
255
- const o = (e?.markets || [E.main]).map((t) => j(t)), n = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${S.version}&market=${o.map(
259
+ const n = (e?.markets || [E.main]).map((t) => j(t)), o = `https://open-api.naviprotocol.io/api/navi/pools?env=${e?.env || "prod"}&sdk=${P.version}&market=${n.map(
256
260
  (t) => t.key
257
- )}`, r = await fetch(n, { headers: V }).then((t) => t.json());
261
+ )}`, r = await fetch(o, { headers: V }).then((t) => t.json());
258
262
  return r.data.forEach((t) => {
259
- const i = r.meta.emodes.filter((h) => {
263
+ const c = r.meta.emodes.filter((h) => {
260
264
  const C = j(h.marketId);
261
265
  return t.market === C.key && h.isActive;
262
266
  }).filter((h) => !!h.assets.find((C) => C.assetId === t.id));
263
- t.emodes = i;
264
- const c = l(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), u = l(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), s = l(c).multipliedBy(t.oracle.price).toString(), g = l(u).multipliedBy(t.oracle.price).toString(), m = l(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), d = l.max(
267
+ t.emodes = c;
268
+ const i = l(t.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), s = l(t.borrowedAmount).shiftedBy(-9).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), u = l(i).multipliedBy(t.oracle.price).toString(), m = l(s).multipliedBy(t.oracle.price).toString(), d = l(t.supplyCapCeiling).shiftedBy(-27).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), g = l.max(
265
269
  l(t.borrowedAmount),
266
270
  l(t.validBorrowAmount)
267
- ).shiftedBy(-9).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), v = l(m).multipliedBy(t.oracle.price).toString(), y = l(d).multipliedBy(t.oracle.price).toString();
268
- t.poolSupplyAmount = c, t.poolBorrowAmount = u, t.poolSupplyValue = s, t.poolBorrowValue = g, t.poolSupplyCapAmount = m, t.poolBorrowCapAmount = d, t.poolSupplyCapValue = v, t.poolBorrowCapValue = y;
271
+ ).shiftedBy(-9).decimalPlaces(t.token.decimals, l.ROUND_DOWN).toString(), v = l(d).multipliedBy(t.oracle.price).toString(), y = l(g).multipliedBy(t.oracle.price).toString();
272
+ t.poolSupplyAmount = i, t.poolBorrowAmount = s, t.poolSupplyValue = u, t.poolBorrowValue = m, t.poolSupplyCapAmount = d, t.poolBorrowCapAmount = g, t.poolSupplyCapValue = v, t.poolBorrowCapValue = y;
269
273
  }), r.data;
270
274
  }
271
275
  )
272
276
  );
273
- async function A(e, o) {
274
- let n = o?.market;
277
+ async function B(e, n) {
278
+ let o = n?.market;
275
279
  if (typeof e == "string") {
276
280
  const a = we(e);
277
- a && (n = a.marketKey, e = a.poolId);
281
+ a && (o = a.marketKey, e = a.poolId);
278
282
  }
279
283
  const r = await N({
280
- ...o,
281
- markets: [n || M],
284
+ ...n,
285
+ markets: [o || U],
282
286
  cacheTime: w
283
287
  });
284
288
  if (typeof e == "object")
@@ -288,36 +292,36 @@ async function A(e, o) {
288
292
  throw new Error("Pool not found");
289
293
  return t.isDeprecated && console.log(`The lending pool for coinType ${t.suiCoinType} is going to be deprecated.`), t;
290
294
  }
291
- const ze = I(
292
- B(async (e) => {
293
- const o = `https://open-api.naviprotocol.io/api/navi/stats?sdk=${S.version}`;
294
- return (await fetch(o, { headers: V }).then((r) => r.json())).data;
295
+ const Ge = A(
296
+ I(async (e) => {
297
+ const n = `https://open-api.naviprotocol.io/api/navi/stats?sdk=${P.version}`;
298
+ return (await fetch(n, { headers: V }).then((r) => r.json())).data;
295
299
  })
296
- ), Ke = I(
297
- B(
300
+ ), ze = A(
301
+ I(
298
302
  async (e) => {
299
- const o = `https://open-api.naviprotocol.io/api/navi/fee?sdk=${S.version}`;
300
- return await fetch(o, { headers: V }).then((r) => r.json());
303
+ const n = `https://open-api.naviprotocol.io/api/navi/fee?sdk=${P.version}`;
304
+ return await fetch(n, { headers: V }).then((r) => r.json());
301
305
  }
302
306
  )
303
307
  );
304
- async function he(e, o, n, r) {
308
+ async function he(e, n, o, r) {
305
309
  const t = await k({
306
310
  ...r,
307
311
  cacheTime: w
308
- }), a = await A(o, r);
312
+ }), a = await B(n, r);
309
313
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
310
314
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
311
- const i = typeof n == "object" && n.$kind === "GasCoin";
312
- if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
315
+ const c = typeof o == "object" && o.$kind === "GasCoin";
316
+ if (b(a.suiCoinType) === b("0x2::sui::SUI") && c) {
313
317
  if (!r?.amount)
314
318
  throw new Error("Amount is required for sui coin");
315
- n = e.splitCoins(n, [r.amount]);
319
+ o = e.splitCoins(o, [r.amount]);
316
320
  }
317
- let c;
318
- return typeof r?.amount < "u" ? c = f(r.amount, e.pure.u64) : c = e.moveCall({
321
+ let i;
322
+ return typeof r?.amount < "u" ? i = f(r.amount, e.pure.u64) : i = e.moveCall({
319
323
  target: "0x2::coin::value",
320
- arguments: [f(n, e.object)],
324
+ arguments: [f(o, e.object)],
321
325
  typeArguments: [a.suiCoinType]
322
326
  }), r?.accountCap ? e.moveCall({
323
327
  target: `${t.package}::incentive_v3::deposit_with_account_cap`,
@@ -326,7 +330,7 @@ async function he(e, o, n, r) {
326
330
  e.object(t.storage),
327
331
  e.object(a.contract.pool),
328
332
  e.pure.u8(a.id),
329
- f(n, e.object),
333
+ f(o, e.object),
330
334
  e.object(t.incentiveV2),
331
335
  e.object(t.incentiveV3),
332
336
  f(r.accountCap, e.object)
@@ -339,8 +343,8 @@ async function he(e, o, n, r) {
339
343
  e.object(t.storage),
340
344
  e.object(a.contract.pool),
341
345
  e.pure.u8(a.id),
342
- f(n, e.object),
343
- c,
346
+ f(o, e.object),
347
+ i,
344
348
  e.object(t.incentiveV2),
345
349
  e.object(t.incentiveV3)
346
350
  ],
@@ -350,15 +354,15 @@ async function he(e, o, n, r) {
350
354
  arguments: [e.object(a.contract.pool), e.object("0x05")]
351
355
  }), e;
352
356
  }
353
- async function Ye(e, o, n, r) {
357
+ async function Ke(e, n, o, r) {
354
358
  const t = await k({
355
359
  ...r,
356
360
  cacheTime: w
357
- }), a = await A(o, r), i = f(n, e.pure.u64);
358
- let c;
361
+ }), a = await B(n, r), c = f(o, e.pure.u64);
362
+ let i;
359
363
  if (t.version === 1)
360
364
  if (r?.accountCap) {
361
- const [s] = e.moveCall({
365
+ const [u] = e.moveCall({
362
366
  target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
363
367
  arguments: [
364
368
  e.object("0x06"),
@@ -366,16 +370,16 @@ async function Ye(e, o, n, r) {
366
370
  e.object(t.storage),
367
371
  e.object(a.contract.pool),
368
372
  e.pure.u8(a.id),
369
- i,
373
+ c,
370
374
  e.object(t.incentiveV2),
371
375
  e.object(t.incentiveV3),
372
376
  f(r.accountCap, e.object)
373
377
  ],
374
378
  typeArguments: [a.suiCoinType]
375
379
  });
376
- c = s;
380
+ i = u;
377
381
  } else {
378
- const [s] = e.moveCall({
382
+ const [u] = e.moveCall({
379
383
  target: `${t.package}::incentive_v3::withdraw`,
380
384
  arguments: [
381
385
  e.object("0x06"),
@@ -383,16 +387,16 @@ async function Ye(e, o, n, r) {
383
387
  e.object(t.storage),
384
388
  e.object(a.contract.pool),
385
389
  e.pure.u8(a.id),
386
- i,
390
+ c,
387
391
  e.object(t.incentiveV2),
388
392
  e.object(t.incentiveV3)
389
393
  ],
390
394
  typeArguments: [a.suiCoinType]
391
395
  });
392
- c = s;
396
+ i = u;
393
397
  }
394
398
  else if (r?.accountCap) {
395
- const [s] = e.moveCall({
399
+ const [u] = e.moveCall({
396
400
  target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
397
401
  arguments: [
398
402
  e.object("0x06"),
@@ -400,7 +404,7 @@ async function Ye(e, o, n, r) {
400
404
  e.object(t.storage),
401
405
  e.object(a.contract.pool),
402
406
  e.pure.u8(a.id),
403
- i,
407
+ c,
404
408
  e.object(t.incentiveV2),
405
409
  e.object(t.incentiveV3),
406
410
  f(r.accountCap, e.object),
@@ -408,9 +412,9 @@ async function Ye(e, o, n, r) {
408
412
  ],
409
413
  typeArguments: [a.suiCoinType]
410
414
  });
411
- c = s;
415
+ i = u;
412
416
  } else {
413
- const [s] = e.moveCall({
417
+ const [u] = e.moveCall({
414
418
  target: `${t.package}::incentive_v3::withdraw_v2`,
415
419
  arguments: [
416
420
  e.object("0x06"),
@@ -418,33 +422,33 @@ async function Ye(e, o, n, r) {
418
422
  e.object(t.storage),
419
423
  e.object(a.contract.pool),
420
424
  e.pure.u8(a.id),
421
- i,
425
+ c,
422
426
  e.object(t.incentiveV2),
423
427
  e.object(t.incentiveV3),
424
428
  e.object("0x05")
425
429
  ],
426
430
  typeArguments: [a.suiCoinType]
427
431
  });
428
- c = s;
432
+ i = u;
429
433
  }
430
434
  return e.moveCall({
431
435
  target: "0x2::coin::from_balance",
432
- arguments: [c],
436
+ arguments: [i],
433
437
  typeArguments: [a.suiCoinType]
434
438
  });
435
439
  }
436
- async function Je(e, o, n, r) {
440
+ async function Ye(e, n, o, r) {
437
441
  const t = await k({
438
442
  ...r,
439
443
  cacheTime: w
440
- }), a = await A(o, r);
444
+ }), a = await B(n, r);
441
445
  if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
442
446
  throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
443
- const i = f(n, e.pure.u64);
444
- let c;
447
+ const c = f(o, e.pure.u64);
448
+ let i;
445
449
  if (t.version === 1)
446
450
  if (r?.accountCap) {
447
- const [s] = e.moveCall({
451
+ const [u] = e.moveCall({
448
452
  target: `${t.package}::incentive_v3::borrow_with_account_cap`,
449
453
  arguments: [
450
454
  e.object("0x06"),
@@ -452,16 +456,16 @@ async function Je(e, o, n, r) {
452
456
  e.object(t.storage),
453
457
  e.object(a.contract.pool),
454
458
  e.pure.u8(a.id),
455
- i,
459
+ c,
456
460
  e.object(t.incentiveV2),
457
461
  e.object(t.incentiveV3),
458
462
  f(r.accountCap, e.object)
459
463
  ],
460
464
  typeArguments: [a.suiCoinType]
461
465
  });
462
- c = s;
466
+ i = u;
463
467
  } else {
464
- const [s] = e.moveCall({
468
+ const [u] = e.moveCall({
465
469
  target: `${t.package}::incentive_v3::borrow`,
466
470
  arguments: [
467
471
  e.object("0x06"),
@@ -469,16 +473,16 @@ async function Je(e, o, n, r) {
469
473
  e.object(t.storage),
470
474
  e.object(a.contract.pool),
471
475
  e.pure.u8(a.id),
472
- i,
476
+ c,
473
477
  e.object(t.incentiveV2),
474
478
  e.object(t.incentiveV3)
475
479
  ],
476
480
  typeArguments: [a.suiCoinType]
477
481
  });
478
- c = s;
482
+ i = u;
479
483
  }
480
484
  else if (r?.accountCap) {
481
- const [s] = e.moveCall({
485
+ const [u] = e.moveCall({
482
486
  target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
483
487
  arguments: [
484
488
  e.object("0x06"),
@@ -486,7 +490,7 @@ async function Je(e, o, n, r) {
486
490
  e.object(t.storage),
487
491
  e.object(a.contract.pool),
488
492
  e.pure.u8(a.id),
489
- i,
493
+ c,
490
494
  e.object(t.incentiveV2),
491
495
  e.object(t.incentiveV3),
492
496
  f(r.accountCap, e.object),
@@ -494,9 +498,9 @@ async function Je(e, o, n, r) {
494
498
  ],
495
499
  typeArguments: [a.suiCoinType]
496
500
  });
497
- c = s;
501
+ i = u;
498
502
  } else {
499
- const [s] = e.moveCall({
503
+ const [u] = e.moveCall({
500
504
  target: `${t.package}::incentive_v3::borrow_v2`,
501
505
  arguments: [
502
506
  e.object("0x06"),
@@ -504,38 +508,38 @@ async function Je(e, o, n, r) {
504
508
  e.object(t.storage),
505
509
  e.object(a.contract.pool),
506
510
  e.pure.u8(a.id),
507
- i,
511
+ c,
508
512
  e.object(t.incentiveV2),
509
513
  e.object(t.incentiveV3),
510
514
  e.object("0x05")
511
515
  ],
512
516
  typeArguments: [a.suiCoinType]
513
517
  });
514
- c = s;
518
+ i = u;
515
519
  }
516
520
  return e.moveCall({
517
521
  target: "0x2::coin::from_balance",
518
- arguments: [e.object(c)],
522
+ arguments: [e.object(i)],
519
523
  typeArguments: [a.suiCoinType]
520
524
  });
521
525
  }
522
- async function Qe(e, o, n, r) {
526
+ async function Je(e, n, o, r) {
523
527
  const t = await k({
524
528
  ...r,
525
529
  cacheTime: w
526
- }), a = await A(o, r), i = typeof n == "object" && n.$kind === "GasCoin";
527
- if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
530
+ }), a = await B(n, r), c = typeof o == "object" && o.$kind === "GasCoin";
531
+ if (b(a.suiCoinType) === b("0x2::sui::SUI") && c) {
528
532
  if (!r?.amount)
529
533
  throw new Error("Amount is required for sui coin");
530
- n = e.splitCoins(n, [r.amount]);
534
+ o = e.splitCoins(o, [r.amount]);
531
535
  }
532
- let c;
533
- if (typeof r?.amount < "u" ? c = f(r.amount, e.pure.u64) : c = e.moveCall({
536
+ let i;
537
+ if (typeof r?.amount < "u" ? i = f(r.amount, e.pure.u64) : i = e.moveCall({
534
538
  target: "0x2::coin::value",
535
- arguments: [f(n, e.object)],
539
+ arguments: [f(o, e.object)],
536
540
  typeArguments: [a.suiCoinType]
537
541
  }), r?.accountCap) {
538
- const [u] = e.moveCall({
542
+ const [s] = e.moveCall({
539
543
  target: `${t.package}::incentive_v3::repay_with_account_cap`,
540
544
  arguments: [
541
545
  e.object("0x06"),
@@ -543,7 +547,7 @@ async function Qe(e, o, n, r) {
543
547
  e.object(t.storage),
544
548
  e.object(a.contract.pool),
545
549
  e.pure.u8(a.id),
546
- f(n, e.object),
550
+ f(o, e.object),
547
551
  e.object(t.incentiveV2),
548
552
  e.object(t.incentiveV3),
549
553
  f(r.accountCap, e.object)
@@ -552,7 +556,7 @@ async function Qe(e, o, n, r) {
552
556
  });
553
557
  return e.moveCall({
554
558
  target: "0x2::coin::from_balance",
555
- arguments: [u],
559
+ arguments: [s],
556
560
  typeArguments: [a.suiCoinType]
557
561
  });
558
562
  } else
@@ -564,485 +568,491 @@ async function Qe(e, o, n, r) {
564
568
  e.object(t.storage),
565
569
  e.object(a.contract.pool),
566
570
  e.pure.u8(a.id),
567
- f(n, e.object),
568
- c,
571
+ f(o, e.object),
572
+ i,
569
573
  e.object(t.incentiveV2),
570
574
  e.object(t.incentiveV3)
571
575
  ],
572
576
  typeArguments: [a.suiCoinType]
573
577
  }), e;
574
578
  }
575
- const Xe = I(
576
- B(
579
+ const Qe = A(
580
+ I(
577
581
  async (e) => {
578
- const o = await k({
582
+ const n = await k({
579
583
  ...e
580
584
  });
581
585
  if (e?.address && typeof e?.asset < "u")
582
586
  try {
583
- const t = await A(e.asset, e), a = e?.client ?? $, i = new U();
584
- i.moveCall({
585
- target: `${o.package}::incentive_v3::get_borrow_fee_v2`,
587
+ const t = await B(e.asset, e), a = e?.client ?? $, c = new M();
588
+ c.moveCall({
589
+ target: `${n.package}::incentive_v3::get_borrow_fee_v2`,
586
590
  arguments: [
587
- i.object(o.incentiveV3),
588
- i.pure.address(e.address),
589
- i.pure.u8(t.id),
590
- i.pure.u64(1e4)
591
+ c.object(n.incentiveV3),
592
+ c.pure.address(e.address),
593
+ c.pure.u8(t.id),
594
+ c.pure.u64(1e4)
591
595
  ],
592
596
  typeArguments: []
593
597
  });
594
- const c = await a.devInspectTransactionBlock({
595
- transactionBlock: i,
598
+ const i = await a.devInspectTransactionBlock({
599
+ transactionBlock: c,
596
600
  sender: e.address
597
- }), u = O(c, [_.u64()]);
598
- return (Number(u[0]) || 0) / 100;
601
+ }), s = R(i, [_.u64()]);
602
+ return (Number(s[0]) || 0) / 100;
599
603
  } catch (t) {
600
604
  console.error(t);
601
605
  }
602
606
  const r = (await $.getObject({
603
- id: o.incentiveV3,
607
+ id: n.incentiveV3,
604
608
  options: { showType: !0, showOwner: !0, showContent: !0 }
605
609
  })).data.content.fields.borrow_fee_rate;
606
610
  return Number(r) / 100;
607
611
  }
608
612
  )
609
- );
610
- async function be(e, o) {
611
- const n = await k({
613
+ ), U = "main", E = {
614
+ main: {
615
+ id: 0,
616
+ key: "main",
617
+ name: "Main Market"
618
+ }
619
+ };
620
+ class be {
621
+ constructor(n, o) {
622
+ this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
623
+ marketTotalSupplyValue: "0",
624
+ marketTotalBorrowValue: "0"
625
+ }, this.config = j(n), this.addPools(o);
626
+ }
627
+ get overview() {
628
+ return this._overview;
629
+ }
630
+ addPools(n) {
631
+ const o = F(this.pools), r = G(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
632
+ let c = l(0), i = l(0);
633
+ n.forEach((s) => {
634
+ if (!this.checkMarket(s.market)) {
635
+ console.warn(`Pool is not in market ${this.config.name}`, s);
636
+ return;
637
+ }
638
+ o[s.uniqueId] || this.pools.push(s), s.emodes.forEach((m) => {
639
+ r[m.uniqueId] || this.emodes.push(m), m.assets.forEach((d) => {
640
+ d.isDebt && t.add(s.uniqueId), d.isCollateral && a.add(s.uniqueId);
641
+ });
642
+ }), i = i.plus(s.poolBorrowValue), c = c.plus(s.poolSupplyValue);
643
+ }), this.poolMap = F(this.pools, "id"), this.emodeMap = G(this.emodes, "emodeId"), this.emodes.forEach((s) => {
644
+ const u = this.getEModePools(s.emodeId);
645
+ this.emodePools.push(...u);
646
+ }), this._overview = {
647
+ marketTotalSupplyValue: c.toString(),
648
+ marketTotalBorrowValue: i.toString()
649
+ }, this.emodeBorrowablePools = this.pools.filter((s) => t.has(s.uniqueId)), this.emodeSupplyablePools = this.pools.filter((s) => a.has(s.uniqueId));
650
+ }
651
+ getEMode(n) {
652
+ return this.emodeMap[n] || null;
653
+ }
654
+ getEModeRelatePools(n, o) {
655
+ const { collateral: r, debt: t, emodeId: a } = o || {}, c = [];
656
+ return n.emodes.forEach((i) => {
657
+ typeof a == "number" && a !== i.emodeId || i.assets.forEach((s) => {
658
+ typeof r == "boolean" && r && s.isCollateral && s.assetId === n.id && c.push(this.poolMap[s.assetId]), typeof t == "boolean" && t && s.isDebt && s.assetId === n.id && c.push(this.poolMap[s.assetId]);
659
+ });
660
+ }), c;
661
+ }
662
+ getEModePools(n) {
663
+ const o = this.getEMode(n);
664
+ return o ? o.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
665
+ const a = o.assets.find((c) => c.assetId === t.id);
666
+ return {
667
+ ...t,
668
+ emode: {
669
+ ...a,
670
+ emodeId: o.emodeId
671
+ },
672
+ isEMode: !0
673
+ };
674
+ }) : [];
675
+ }
676
+ checkMarket(n) {
677
+ let o = !1;
678
+ return typeof n == "number" && n === this.config.id && (o = !0), typeof n == "string" && n === this.config.key && (o = !0), typeof n == "object" && n.id === this.config.id && (o = !0), o;
679
+ }
680
+ }
681
+ const j = (e) => {
682
+ const o = Object.values(E).find((r) => typeof e == "number" ? r.id === e : typeof e == "string" ? r.key === e : r.id === e.id);
683
+ if (!o)
684
+ throw new Error("Market not found");
685
+ return o;
686
+ }, ke = A(
687
+ I(
688
+ async (e, n) => {
689
+ const o = await N({
690
+ cacheTime: 6e4,
691
+ ...n,
692
+ markets: e
693
+ });
694
+ return e.map((r) => {
695
+ const t = j(r), a = o.filter((c) => c.market === t.key);
696
+ return new be(r, a);
697
+ });
698
+ }
699
+ )
700
+ ), Xe = A(
701
+ I(
702
+ async (e, n) => (await ke([e], n))[0]
703
+ )
704
+ ), k = A(
705
+ I(
706
+ async (e) => {
707
+ const n = j(e?.market || U), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${P.version}&market=${n.key}`;
708
+ return (await fetch(o, { headers: V }).then((t) => t.json())).data;
709
+ }
710
+ )
711
+ ), w = 1e3 * 60 * 5;
712
+ async function _e(e, n) {
713
+ const o = await k({
612
714
  cacheTime: w,
613
- ...o
715
+ ...n
614
716
  });
615
717
  return e.moveCall({
616
- target: `${n.package}::lending::create_account`,
718
+ target: `${o.package}::lending::create_account`,
617
719
  arguments: []
618
720
  });
619
721
  }
620
- async function ke(e, o, n) {
722
+ async function Ce(e, n, o) {
621
723
  const r = await k({
622
724
  cacheTime: w,
623
- ...n
725
+ ...o
624
726
  });
625
727
  return e.moveCall({
626
728
  target: `${r.package}::lending_core::account_owner`,
627
- arguments: [o]
729
+ arguments: [n]
628
730
  });
629
731
  }
630
- async function _e(e, o, n) {
732
+ async function je(e, n, o) {
631
733
  const r = await k({
632
- ...n,
734
+ ...o,
633
735
  cacheTime: w
634
736
  });
635
- return n?.accountCap ? e.moveCall({
737
+ return o?.accountCap ? e.moveCall({
636
738
  target: `${r.package}::lending::enter_emode_with_account_cap`,
637
739
  arguments: [
638
740
  e.object(r.storage),
639
- f(o, e.pure.u64),
640
- f(n.accountCap, e.object)
741
+ f(n, e.pure.u64),
742
+ f(o.accountCap, e.object)
641
743
  ]
642
744
  }) : e.moveCall({
643
745
  target: `${r.package}::lending::enter_emode`,
644
- arguments: [e.object(r.storage), f(o, e.pure.u64)]
746
+ arguments: [e.object(r.storage), f(n, e.pure.u64)]
645
747
  }), e;
646
748
  }
647
- async function Ze(e, o) {
648
- const n = await k({
649
- ...o,
749
+ async function Ze(e, n) {
750
+ const o = await k({
751
+ ...n,
650
752
  cacheTime: w
651
753
  });
652
- return o?.accountCap ? e.moveCall({
653
- target: `${n.package}::lending::exit_emode_with_account_cap`,
654
- arguments: [e.object(n.storage), f(o.accountCap, e.object)]
754
+ return n?.accountCap ? e.moveCall({
755
+ target: `${o.package}::lending::exit_emode_with_account_cap`,
756
+ arguments: [e.object(o.storage), f(n.accountCap, e.object)]
655
757
  }) : e.moveCall({
656
- target: `${n.package}::lending::exit_emode`,
657
- arguments: [e.object(n.storage)]
758
+ target: `${o.package}::lending::exit_emode`,
759
+ arguments: [e.object(o.storage)]
658
760
  }), e;
659
761
  }
660
- async function xe(e, o, n) {
762
+ async function xe(e, n, o) {
661
763
  const r = await k({
662
764
  cacheTime: w,
663
- ...n
664
- }), t = await be(e, n);
665
- await _e(e, o, {
666
- ...n,
765
+ ...o
766
+ }), t = await _e(e, o);
767
+ await je(e, n, {
768
+ ...o,
667
769
  accountCap: t
668
770
  });
669
- const a = await j(n?.market || M), i = await ke(e, t, n);
771
+ const a = await j(o?.market || U), c = await Ce(e, t, o);
670
772
  return e.moveCall({
671
773
  target: `${r.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
672
774
  arguments: [
673
775
  e.object(r.emode.contract.registryObject),
674
- i,
776
+ c,
675
777
  f(a.id, e.pure.u64),
676
- f(o, e.pure.u64)
778
+ f(n, e.pure.u64)
677
779
  ]
678
780
  }), t;
679
781
  }
680
- const Q = I(
681
- B(
682
- async (e, o) => {
683
- const n = await k({
782
+ const Q = A(
783
+ I(
784
+ async (e, n) => {
785
+ const o = await k({
684
786
  cacheTime: w,
685
- ...o
686
- }), r = new U(), t = o?.client ?? $;
787
+ ...n
788
+ }), r = new M(), t = n?.client ?? $;
687
789
  r.moveCall({
688
- target: `${n.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
689
- arguments: [r.object(n.emode.contract.registryObject), r.pure.address(e)]
790
+ target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
791
+ arguments: [r.object(o.emode.contract.registryObject), r.pure.address(e)]
690
792
  });
691
- const i = (await t.devInspectTransactionBlock({
793
+ const c = (await t.devInspectTransactionBlock({
692
794
  transactionBlock: r,
693
795
  sender: e
694
- })).results[0].returnValues, c = _.vector(_.u64()).parse(Uint8Array.from(i[0][0])), u = _.vector(_.u64()).parse(Uint8Array.from(i[1][0])), s = _.vector(_.Address).parse(Uint8Array.from(i[2][0]));
695
- return c.map((g, m) => ({
696
- marketId: Number(g),
697
- emodeId: Number(u[m]),
698
- accountCap: s[m].toString()
796
+ })).results[0].returnValues, i = _.vector(_.u64()).parse(Uint8Array.from(c[0][0])), s = _.vector(_.u64()).parse(Uint8Array.from(c[1][0])), u = _.vector(_.Address).parse(Uint8Array.from(c[2][0]));
797
+ return i.map((m, d) => ({
798
+ marketId: Number(m),
799
+ emodeId: Number(s[d]),
800
+ accountCap: u[d].toString()
699
801
  }));
700
802
  }
701
803
  )
702
804
  );
703
- function Ce(e) {
805
+ function et(e) {
704
806
  return `${j(e.marketId).key}-${e.emodeId}`;
705
807
  }
706
- const M = "main", E = {
707
- main: {
708
- id: 0,
709
- key: "main",
710
- name: "Main Market"
711
- }
712
- };
713
- class je {
714
- constructor(o, n) {
715
- this.pools = [], this.emodes = [], this._overview = {
716
- marketTotalSupplyValue: "0",
717
- marketTotalBorrowValue: "0"
718
- }, this.config = j(o), this.addPools(n);
719
- }
720
- get overview() {
721
- return this._overview;
722
- }
723
- addPools(o) {
724
- const n = J(this.pools), r = H(this.emodes);
725
- let t = l(0), a = l(0);
726
- o.forEach((i) => {
727
- if (!this.checkMarket(i.market)) {
728
- console.warn(`Pool is not in market ${this.config.name}`, i);
729
- return;
730
- }
731
- n[i.uniqueId] || this.pools.push(i), i.emodes.forEach((u) => {
732
- r[u.uniqueId] || this.emodes.push(u);
733
- }), a = a.plus(i.poolBorrowValue), t = t.plus(i.poolSupplyValue);
734
- }), this._overview = {
735
- marketTotalSupplyValue: t.toString(),
736
- marketTotalBorrowValue: a.toString()
737
- };
738
- }
739
- getEMode(o) {
740
- if (!this.checkMarket(o.marketId))
741
- return console.warn(
742
- `EMode market mismatch ${this.config.id} !== ${o.marketId}`,
743
- o
744
- ), null;
745
- const t = H(this.emodes)[Ce(o)];
746
- return t || (console.warn(
747
- `EMode not found ${o.emodeId} in market ${this.config.name}`,
748
- o
749
- ), null);
750
- }
751
- getEModePools(o) {
752
- const n = this.getEMode(o);
753
- if (!n)
754
- return [];
755
- const r = n.assets.map((a) => a.assetId);
756
- return this.pools.filter((a) => r.includes(a.id)).map((a) => ({
757
- ...a,
758
- emode: n,
759
- isEMode: !0
760
- }));
761
- }
762
- checkMarket(o) {
763
- let n = !1;
764
- return typeof o == "number" && o === this.config.id && (n = !0), typeof o == "string" && o === this.config.key && (n = !0), typeof o == "object" && o.id === this.config.id && (n = !0), n;
765
- }
766
- }
767
- const j = (e) => {
768
- const n = Object.values(E).find((r) => typeof e == "number" ? r.id === e : typeof e == "string" ? r.key === e : r.id === e.id);
769
- if (!n)
770
- throw new Error("Market not found");
771
- return n;
772
- }, Te = I(
773
- B(
774
- async (e, o) => {
775
- const n = await N({
776
- cacheTime: 6e4,
777
- ...o,
778
- markets: e
779
- });
780
- return e.map((r) => {
781
- const t = j(r), a = n.filter((i) => i.market === t.key);
782
- return new je(r, a);
783
- });
784
- }
785
- )
786
- ), et = I(
787
- B(
788
- async (e, o) => (await Te([e], o))[0]
789
- )
790
- ), k = I(
791
- B(
792
- async (e) => {
793
- const o = j(e?.market || M), n = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${S.version}&market=${o.key}`;
794
- return (await fetch(n, { headers: V }).then((t) => t.json())).data;
795
- }
796
- )
797
- ), w = 1e3 * 60 * 5;
798
- function tt(e, o, n) {
799
- const r = typeof n?.balance == "number", t = r ? n.balance : 0;
808
+ function tt(e, n, o) {
809
+ const r = typeof o?.balance == "number", t = r ? o.balance : 0;
800
810
  let a = 0;
801
- const i = [];
802
- let c = "";
803
- if (o.sort((u, s) => Number(s.balance) - Number(u.balance)).forEach((u) => {
804
- if (!(r && a >= t) && Number(u.balance) !== 0) {
805
- if (c || (c = u.coinType), c !== u.coinType)
811
+ const c = [];
812
+ let i = "";
813
+ if (n.sort((s, u) => Number(u.balance) - Number(s.balance)).forEach((s) => {
814
+ if (!(r && a >= t) && Number(s.balance) !== 0) {
815
+ if (i || (i = s.coinType), i !== s.coinType)
806
816
  throw new Error("All coins must be of the same type");
807
- a += Number(u.balance), i.push(u.coinObjectId);
817
+ a += Number(s.balance), c.push(s.coinObjectId);
808
818
  }
809
- }), i.length === 0)
819
+ }), c.length === 0)
810
820
  throw new Error("No coins to merge");
811
821
  if (r && a < t)
812
822
  throw new Error(
813
823
  `Balance is less than the specified balance: ${a} < ${t}`
814
824
  );
815
- return b(c) === b("0x2::sui::SUI") && n?.useGasCoin ? r ? e.splitCoins(e.gas, [e.pure.u64(t)]) : e.gas : (i.length === 1 ? e.object(i[0]) : e.mergeCoins(i[0], i.slice(1)), r ? e.splitCoins(i[0], [e.pure.u64(t)]) : i[0]);
825
+ return b(i) === b("0x2::sui::SUI") && o?.useGasCoin ? r ? e.splitCoins(e.gas, [e.pure.u64(t)]) : e.gas : (c.length === 1 ? e.object(c[0]) : e.mergeCoins(c[0], c.slice(1)), r ? e.splitCoins(c[0], [e.pure.u64(t)]) : c[0]);
816
826
  }
817
- async function X(e, o, n, r, t, a, i) {
818
- const c = await k({
819
- ...i,
827
+ async function X(e, n, o, r, t, a, c) {
828
+ const i = await k({
829
+ ...c,
820
830
  cacheTime: w
821
- }), u = await A(n, i);
831
+ }), s = await B(o, c);
822
832
  return e.moveCall({
823
- target: `${c.uiGetter}::calculator_unchecked::dynamic_health_factor`,
833
+ target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
824
834
  arguments: [
825
835
  e.object("0x06"),
826
- e.object(c.storage),
827
- e.object(c.oracle.priceOracle),
828
- ye(e, u),
829
- f(o, e.pure.address),
830
- f(u.id, e.pure.u8),
836
+ e.object(i.storage),
837
+ e.object(i.oracle.priceOracle),
838
+ ye(e, s),
839
+ f(n, e.pure.address),
840
+ f(s.id, e.pure.u8),
831
841
  f(r, e.pure.u64),
832
842
  f(t, e.pure.u64),
833
843
  f(a, e.pure.bool)
834
844
  ],
835
- typeArguments: [u.suiCoinType]
845
+ typeArguments: [s.suiCoinType]
836
846
  });
837
847
  }
838
- async function Be(e, o, n) {
839
- return X(e, o, 0, 0, 0, !1, n);
848
+ async function Te(e, n, o) {
849
+ return X(e, n, 0, 0, 0, !1, o);
840
850
  }
841
- async function Z(e, o, n) {
842
- const r = new U(), t = n?.client ?? $, a = await N({
843
- ...n,
851
+ async function Z(e, n, o) {
852
+ const r = new M(), t = o?.client ?? $, a = await N({
853
+ ...o,
844
854
  markets: Object.values(E)
845
- }), i = J(a);
846
- for (let g of o) {
847
- const m = await k({
848
- ...n,
855
+ }), c = F(a);
856
+ for (let m of n) {
857
+ const d = await k({
858
+ ...o,
849
859
  cacheTime: w,
850
- market: g.market
860
+ market: m.market
851
861
  });
852
862
  r.moveCall({
853
- target: `${m.uiGetter}::getter_unchecked::get_user_state`,
854
- arguments: [r.object(m.storage), r.pure.address(g.address)]
863
+ target: `${d.uiGetter}::getter_unchecked::get_user_state`,
864
+ arguments: [r.object(d.storage), r.pure.address(m.address)]
855
865
  });
856
866
  }
857
- const u = ((await t.devInspectTransactionBlock({
867
+ const s = ((await t.devInspectTransactionBlock({
858
868
  transactionBlock: r,
859
869
  sender: e
860
- })).results || []).map((g) => g.returnValues?.map((m) => _.vector(pe).parse(Uint8Array.from(m[0])))[0] || []), s = [];
861
- return u.forEach((g, m) => {
862
- const d = o[m], v = j(d.market);
863
- g.forEach((y) => {
870
+ })).results || []).map((m) => m.returnValues?.map((d) => _.vector(pe).parse(Uint8Array.from(d[0])))[0] || []), u = [];
871
+ return s.forEach((m, d) => {
872
+ const g = n[d], v = j(g.market);
873
+ m.forEach((y) => {
864
874
  if (y.supply_balance === "0" && y.borrow_balance === "0")
865
875
  return;
866
- const h = i[`${v.key}-${y.asset_id}`];
876
+ const h = c[`${v.key}-${y.asset_id}`];
867
877
  if (!h)
868
878
  return;
869
- const C = W(
879
+ const C = H(
870
880
  y.supply_balance,
871
881
  h.currentSupplyIndex
872
- ).toString(), T = W(
882
+ ).toString(), T = H(
873
883
  y.borrow_balance,
874
884
  h.currentBorrowIndex
875
885
  ).toString();
876
- s.push({
886
+ u.push({
877
887
  supplyBalance: C,
878
888
  borrowBalance: T,
879
889
  assetId: y.asset_id,
880
890
  market: v.key,
881
891
  pool: h,
882
- emodeId: d.emodeId
892
+ emodeId: g.emodeId
883
893
  });
884
894
  });
885
- }), s;
895
+ }), u;
886
896
  }
887
- const ot = I(
888
- async (e, o) => {
889
- const r = (o?.markets || Object.keys(E)).map((t) => j(t)).map((t) => ({
897
+ const ot = A(
898
+ async (e, n) => {
899
+ const r = (n?.markets || Object.keys(E)).map((t) => j(t)).map((t) => ({
890
900
  address: e,
891
901
  market: t.key
892
902
  }));
893
- return await Z(e, r, o);
903
+ return await Z(e, r, n);
894
904
  }
895
905
  );
896
- async function nt(e, o) {
897
- const n = o?.client ?? $, r = new U();
898
- await Be(r, e, o);
899
- const t = await n.devInspectTransactionBlock({
906
+ async function nt(e, n) {
907
+ const o = n?.client ?? $, r = new M();
908
+ await Te(r, e, n);
909
+ const t = await o.devInspectTransactionBlock({
900
910
  transactionBlock: r,
901
911
  sender: e
902
- }), a = O(t, [_.u256()]);
903
- return Y(Number(a[0]) || 0);
912
+ }), a = R(t, [_.u256()]);
913
+ return J(Number(a[0]) || 0);
904
914
  }
905
- async function rt(e, o, n, r) {
906
- const t = r?.client ?? $, a = new U();
907
- let i = 0, c = 0;
908
- const u = await A(o, r);
909
- if (n.forEach((d) => {
910
- d.type === D.Supply ? i += d.amount : d.type === D.Withdraw ? i -= d.amount : d.type === D.Borrow ? c += d.amount : d.type === D.Repay && (c -= d.amount);
911
- }), i * c < 0)
915
+ async function rt(e, n, o, r) {
916
+ const t = r?.client ?? $, a = new M();
917
+ let c = 0, i = 0;
918
+ const s = await B(n, r);
919
+ if (o.forEach((g) => {
920
+ g.type === D.Supply ? c += g.amount : g.type === D.Withdraw ? c -= g.amount : g.type === D.Borrow ? i += g.amount : g.type === D.Repay && (i -= g.amount);
921
+ }), c * i < 0)
912
922
  throw new Error("Invalid operations");
913
- const s = i > 0 || c > 0;
923
+ const u = c > 0 || i > 0;
914
924
  await X(
915
925
  a,
916
926
  e,
917
- u,
918
- Math.abs(i),
919
- Math.abs(c),
920
927
  s,
928
+ Math.abs(c),
929
+ Math.abs(i),
930
+ u,
921
931
  r
922
932
  );
923
- const g = await t.devInspectTransactionBlock({
933
+ const m = await t.devInspectTransactionBlock({
924
934
  transactionBlock: a,
925
935
  sender: e
926
- }), m = O(g, [_.u256()]);
927
- return Y(Number(m[0]) || 0);
936
+ }), d = R(m, [_.u256()]);
937
+ return J(Number(d[0]) || 0);
928
938
  }
929
- const at = B(
930
- async (e, o) => {
931
- const n = new URLSearchParams();
932
- o?.cursor && n.set("cursor", o.cursor), n.set("userAddress", e);
933
- const r = `https://open-api.naviprotocol.io/api/navi/user/transactions?${n.toString()}&sdk=${S.version}`;
939
+ const at = I(
940
+ async (e, n) => {
941
+ const o = new URLSearchParams();
942
+ n?.cursor && o.set("cursor", n.cursor), o.set("userAddress", e);
943
+ const r = `https://open-api.naviprotocol.io/api/navi/user/transactions?${o.toString()}&sdk=${P.version}`;
934
944
  return (await fetch(r, { headers: V }).then((a) => a.json())).data;
935
945
  }
936
946
  );
937
- async function ct(e, o) {
938
- let n = null;
939
- const r = [], t = o?.client ?? $;
947
+ async function it(e, n) {
948
+ let o = null;
949
+ const r = [], t = n?.client ?? $;
940
950
  do {
941
951
  let a;
942
- if (o?.coinType ? a = await t.getCoins({
952
+ if (n?.coinType ? a = await t.getCoins({
943
953
  owner: e,
944
- coinType: o?.coinType,
945
- cursor: n,
954
+ coinType: n?.coinType,
955
+ cursor: o,
946
956
  limit: 100
947
957
  }) : a = await t.getAllCoins({
948
958
  owner: e,
949
- cursor: n,
959
+ cursor: o,
950
960
  limit: 100
951
961
  }), !a.data || !a.data.length)
952
962
  break;
953
- r.push(...a.data), n = a.nextCursor;
954
- } while (n);
963
+ r.push(...a.data), o = a.nextCursor;
964
+ } while (o);
955
965
  return r;
956
966
  }
957
- const Ae = I(
958
- async (e, o) => {
959
- const n = [], r = (o?.markets || Object.keys(E)).map((c) => j(c)), t = await Q(e, o), a = r.map((c) => ({
967
+ const Ie = A(
968
+ async (e, n) => {
969
+ const o = [], r = (n?.markets || Object.keys(E)).map((i) => j(i)), t = await Q(e, n), a = r.map((i) => ({
960
970
  address: e,
961
- market: c.key
971
+ market: i.key
962
972
  })).concat(
963
- t.filter((c) => !!r.find((u) => u.id === c.marketId)).map((c) => ({
973
+ t.filter((i) => !!r.find((s) => s.id === i.marketId)).map((i) => ({
964
974
  address: e,
965
- market: j(c.marketId).key,
966
- emodeId: c.emodeId
975
+ market: j(i.marketId).key,
976
+ emodeId: i.emodeId
967
977
  }))
968
978
  );
969
- return (await Z(e, a, o)).forEach((c) => {
970
- const u = c.emodeId ? t.find((s) => {
971
- const g = j(c.market);
972
- return s.emodeId === c.emodeId && s.marketId === g.id;
979
+ return (await Z(e, a, n)).forEach((i) => {
980
+ const s = i.emodeId ? t.find((u) => {
981
+ const m = j(i.market);
982
+ return u.emodeId === i.emodeId && u.marketId === m.id;
973
983
  }) : void 0;
974
- if (u) {
975
- if (l(c.supplyBalance).gt(0)) {
976
- const s = l(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
977
- n.push({
978
- id: `${c.pool.uniqueId}_${u.emodeId}_navi-lending-emode-supply`,
984
+ if (s) {
985
+ if (l(i.supplyBalance).gt(0)) {
986
+ const u = l(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, l.ROUND_DOWN);
987
+ o.push({
988
+ id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply`,
979
989
  wallet: e,
980
990
  protocol: "navi",
981
- market: c.market,
991
+ market: i.market,
982
992
  type: "navi-lending-emode-supply",
983
993
  "navi-lending-emode-supply": {
984
- amount: s.toString(),
985
- pool: G(c.pool, u),
986
- token: c.pool.token,
987
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
994
+ amount: u.toString(),
995
+ pool: z(i.pool, s),
996
+ token: i.pool.token,
997
+ valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
988
998
  }
989
999
  });
990
1000
  }
991
- if (l(c.borrowBalance).gt(0)) {
992
- const s = l(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
993
- n.push({
994
- id: `${c.pool.uniqueId}_${u.emodeId}_navi-lending-emode-borrow`,
1001
+ if (l(i.borrowBalance).gt(0)) {
1002
+ const u = l(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, l.ROUND_DOWN);
1003
+ o.push({
1004
+ id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow`,
995
1005
  wallet: e,
996
1006
  protocol: "navi",
997
- market: c.market,
1007
+ market: i.market,
998
1008
  type: "navi-lending-emode-borrow",
999
1009
  "navi-lending-emode-borrow": {
1000
- amount: s.toString(),
1001
- pool: G(c.pool, u),
1002
- token: c.pool.token,
1003
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
1010
+ amount: u.toString(),
1011
+ pool: z(i.pool, s),
1012
+ token: i.pool.token,
1013
+ valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
1004
1014
  }
1005
1015
  });
1006
1016
  }
1007
1017
  } else {
1008
- if (l(c.supplyBalance).gt(0)) {
1009
- const s = l(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
1010
- n.push({
1011
- id: `${c.pool.uniqueId}_navi-lending-supply`,
1018
+ if (l(i.supplyBalance).gt(0)) {
1019
+ const u = l(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, l.ROUND_DOWN);
1020
+ o.push({
1021
+ id: `${i.pool.uniqueId}_navi-lending-supply`,
1012
1022
  wallet: e,
1013
1023
  protocol: "navi",
1014
1024
  type: "navi-lending-supply",
1015
- market: c.market,
1025
+ market: i.market,
1016
1026
  "navi-lending-supply": {
1017
- amount: s.toString(),
1018
- pool: c.pool,
1019
- token: c.pool.token,
1020
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
1027
+ amount: u.toString(),
1028
+ pool: i.pool,
1029
+ token: i.pool.token,
1030
+ valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
1021
1031
  }
1022
1032
  });
1023
1033
  }
1024
- if (l(c.borrowBalance).gt(0)) {
1025
- const s = l(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
1026
- n.push({
1027
- id: `${c.pool.uniqueId}_navi-lending-borrow`,
1034
+ if (l(i.borrowBalance).gt(0)) {
1035
+ const u = l(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, l.ROUND_DOWN);
1036
+ o.push({
1037
+ id: `${i.pool.uniqueId}_navi-lending-borrow`,
1028
1038
  wallet: e,
1029
1039
  protocol: "navi",
1030
- market: c.market,
1040
+ market: i.market,
1031
1041
  type: "navi-lending-borrow",
1032
1042
  "navi-lending-borrow": {
1033
- amount: s.toString(),
1034
- pool: c.pool,
1035
- token: c.pool.token,
1036
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
1043
+ amount: u.toString(),
1044
+ pool: i.pool,
1045
+ token: i.pool.token,
1046
+ valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
1037
1047
  }
1038
1048
  });
1039
1049
  }
1040
1050
  }
1041
- }), n;
1051
+ }), o;
1042
1052
  }
1043
1053
  );
1044
- class it {
1045
- constructor(o) {
1054
+ class ct {
1055
+ constructor(n) {
1046
1056
  this._positions = [], this._overview = {
1047
1057
  hf: 1 / 0,
1048
1058
  netVaule: "0",
@@ -1053,7 +1063,7 @@ class it {
1053
1063
  totalBorrowApy: "0",
1054
1064
  maxLiquidationValue: "0",
1055
1065
  maxLoanToVaule: "0"
1056
- }, this.positions = o;
1066
+ }, this.positions = n;
1057
1067
  }
1058
1068
  get positions() {
1059
1069
  return this._positions;
@@ -1061,199 +1071,197 @@ class it {
1061
1071
  get overview() {
1062
1072
  return this._overview;
1063
1073
  }
1064
- set positions(o) {
1065
- this._positions = o, this._overview = this.getPositionsOverview(o);
1074
+ set positions(n) {
1075
+ this._positions = n, this._overview = this.getPositionsOverview(n);
1066
1076
  }
1067
- deposit(o, n) {
1068
- const r = !!o.isEMode;
1077
+ deposit(n, o) {
1078
+ const r = !!n.isEMode;
1069
1079
  let t;
1070
1080
  r ? t = {
1071
- id: P(),
1081
+ id: S(),
1072
1082
  wallet: "",
1073
1083
  protocol: "navi",
1074
1084
  market: "",
1075
1085
  type: "navi-lending-emode-supply",
1076
1086
  "navi-lending-emode-supply": {
1077
- amount: n.toString(),
1078
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1079
- token: o.token,
1080
- pool: o
1087
+ amount: o.toString(),
1088
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1089
+ token: n.token,
1090
+ pool: n
1081
1091
  }
1082
1092
  } : t = {
1083
- id: P(),
1093
+ id: S(),
1084
1094
  wallet: "",
1085
1095
  protocol: "navi",
1086
1096
  market: "",
1087
1097
  type: "navi-lending-supply",
1088
1098
  "navi-lending-supply": {
1089
- amount: n.toString(),
1090
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1091
- token: o.token,
1092
- pool: o
1099
+ amount: o.toString(),
1100
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1101
+ token: n.token,
1102
+ pool: n
1093
1103
  }
1094
1104
  }, this.positions = [...this.positions, t];
1095
1105
  }
1096
- withdraw(o, n) {
1097
- const r = !!o.isEMode;
1106
+ withdraw(n, o) {
1107
+ const r = !!n.isEMode;
1098
1108
  let t;
1099
1109
  r ? t = {
1100
- id: P(),
1110
+ id: S(),
1101
1111
  wallet: "",
1102
1112
  protocol: "navi",
1103
1113
  market: "",
1104
1114
  type: "navi-lending-emode-supply",
1105
1115
  "navi-lending-emode-supply": {
1106
- amount: (-n).toString(),
1107
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1108
- token: o.token,
1109
- pool: o
1116
+ amount: (-o).toString(),
1117
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1118
+ token: n.token,
1119
+ pool: n
1110
1120
  }
1111
1121
  } : t = {
1112
- id: P(),
1122
+ id: S(),
1113
1123
  wallet: "",
1114
1124
  protocol: "navi",
1115
1125
  market: "",
1116
1126
  type: "navi-lending-supply",
1117
1127
  "navi-lending-supply": {
1118
- amount: (-n).toString(),
1119
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1120
- token: o.token,
1121
- pool: o
1128
+ amount: (-o).toString(),
1129
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1130
+ token: n.token,
1131
+ pool: n
1122
1132
  }
1123
1133
  }, this.positions = [...this.positions, t];
1124
1134
  }
1125
- borrow(o, n) {
1126
- const r = !!o.isEMode;
1135
+ borrow(n, o) {
1136
+ const r = !!n.isEMode;
1127
1137
  let t;
1128
1138
  r ? t = {
1129
- id: P(),
1139
+ id: S(),
1130
1140
  wallet: "",
1131
1141
  protocol: "navi",
1132
1142
  market: "",
1133
1143
  type: "navi-lending-emode-borrow",
1134
1144
  "navi-lending-emode-borrow": {
1135
- amount: n.toString(),
1136
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1137
- token: o.token,
1138
- pool: o
1145
+ amount: o.toString(),
1146
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1147
+ token: n.token,
1148
+ pool: n
1139
1149
  }
1140
1150
  } : t = {
1141
- id: P(),
1151
+ id: S(),
1142
1152
  wallet: "",
1143
1153
  protocol: "navi",
1144
1154
  market: "",
1145
1155
  type: "navi-lending-borrow",
1146
1156
  "navi-lending-borrow": {
1147
- amount: n.toString(),
1148
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1149
- token: o.token,
1150
- pool: o
1157
+ amount: o.toString(),
1158
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1159
+ token: n.token,
1160
+ pool: n
1151
1161
  }
1152
1162
  }, this.positions = [...this.positions, t];
1153
1163
  }
1154
- repay(o, n) {
1155
- const r = !!o.isEMode;
1164
+ repay(n, o) {
1165
+ const r = !!n.isEMode;
1156
1166
  let t;
1157
1167
  r ? t = {
1158
- id: P(),
1168
+ id: S(),
1159
1169
  wallet: "",
1160
1170
  protocol: "navi",
1161
1171
  market: "",
1162
1172
  type: "navi-lending-emode-borrow",
1163
1173
  "navi-lending-emode-borrow": {
1164
- amount: (-n).toString(),
1165
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1166
- token: o.token,
1167
- pool: o
1174
+ amount: (-o).toString(),
1175
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1176
+ token: n.token,
1177
+ pool: n
1168
1178
  }
1169
1179
  } : t = {
1170
- id: P(),
1180
+ id: S(),
1171
1181
  wallet: "",
1172
1182
  protocol: "navi",
1173
1183
  market: "",
1174
1184
  type: "navi-lending-borrow",
1175
1185
  "navi-lending-borrow": {
1176
- amount: (-n).toString(),
1177
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1178
- token: o.token,
1179
- pool: o
1186
+ amount: (-o).toString(),
1187
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1188
+ token: n.token,
1189
+ pool: n
1180
1190
  }
1181
1191
  }, this.positions = [...this.positions, t];
1182
1192
  }
1183
- findPositionsByPool(o, n) {
1184
- const r = !!o.isEMode;
1185
- return this.positions.filter((t) => r ? t.type === (n ? "navi-lending-emode-supply" : "navi-lending-emode-borrow") : t.type === (n ? "navi-lending-supply" : "navi-lending-borrow"));
1193
+ findPositionsByPool(n, o) {
1194
+ const r = !!n.isEMode;
1195
+ return this.positions.filter((t) => r ? t.type === (o ? "navi-lending-emode-supply" : "navi-lending-emode-borrow") : t.type === (o ? "navi-lending-supply" : "navi-lending-borrow"));
1186
1196
  }
1187
- getPositionsOverview(o) {
1188
- let n = new l(0), r = new l(0), t = new l(0), a = new l(0), i = new l(0), c = new l(0);
1189
- o.forEach((m) => {
1190
- if (m.type === "navi-lending-supply") {
1191
- const d = m["navi-lending-supply"];
1192
- n = n.plus(d.valueUSD), i = i.plus(
1193
- new l(d.valueUSD).multipliedBy(d.pool.liquidationFactor.threshold)
1194
- ), c = c.plus(
1195
- new l(d.valueUSD).multipliedBy(d.pool.ltvValue)
1196
- );
1197
- } else if (m.type === "navi-lending-borrow")
1198
- r = r.plus(m["navi-lending-borrow"].valueUSD);
1199
- else if (m.type === "navi-lending-emode-supply") {
1200
- const d = m["navi-lending-emode-supply"];
1201
- n = n.plus(d.valueUSD);
1202
- const v = d.pool.emode.assets.find(
1203
- (y) => y.assetId === d.pool.id
1197
+ getPositionsOverview(n) {
1198
+ let o = new l(0), r = new l(0), t = new l(0), a = new l(0), c = new l(0), i = new l(0);
1199
+ n.forEach((d) => {
1200
+ if (d.type === "navi-lending-supply") {
1201
+ const g = d["navi-lending-supply"];
1202
+ o = o.plus(g.valueUSD), c = c.plus(
1203
+ new l(g.valueUSD).multipliedBy(g.pool.liquidationFactor.threshold)
1204
+ ), i = i.plus(
1205
+ new l(g.valueUSD).multipliedBy(g.pool.ltvValue)
1204
1206
  );
1205
- i = i.plus(
1206
- new l(d.valueUSD).multipliedBy(v.lt)
1207
- ), c = c.plus(
1208
- new l(d.valueUSD).multipliedBy(v.ltv)
1207
+ } else if (d.type === "navi-lending-borrow")
1208
+ r = r.plus(d["navi-lending-borrow"].valueUSD);
1209
+ else if (d.type === "navi-lending-emode-supply") {
1210
+ const g = d["navi-lending-emode-supply"];
1211
+ o = o.plus(g.valueUSD);
1212
+ const v = g.pool.emode;
1213
+ c = c.plus(
1214
+ new l(g.valueUSD).multipliedBy(v.lt)
1215
+ ), i = i.plus(
1216
+ new l(g.valueUSD).multipliedBy(v.ltv)
1209
1217
  );
1210
- } else m.type === "navi-lending-emode-borrow" && (r = r.plus(m["navi-lending-emode-borrow"].valueUSD));
1211
- }), o.forEach((m) => {
1212
- if (m.type === "navi-lending-supply") {
1213
- const d = m["navi-lending-supply"], v = d.pool.supplyIncentiveApyInfo.apy;
1218
+ } else d.type === "navi-lending-emode-borrow" && (r = r.plus(d["navi-lending-emode-borrow"].valueUSD));
1219
+ }), n.forEach((d) => {
1220
+ if (d.type === "navi-lending-supply") {
1221
+ const g = d["navi-lending-supply"], v = g.pool.supplyIncentiveApyInfo.apy;
1214
1222
  t = t.plus(
1215
- new l(d.valueUSD).dividedBy(n).multipliedBy(new l(v).dividedBy(100))
1223
+ new l(g.valueUSD).dividedBy(o).multipliedBy(new l(v).dividedBy(100))
1216
1224
  );
1217
- } else if (m.type === "navi-lending-borrow") {
1218
- const d = m["navi-lending-borrow"], v = d.pool.borrowIncentiveApyInfo.apy;
1225
+ } else if (d.type === "navi-lending-borrow") {
1226
+ const g = d["navi-lending-borrow"], v = g.pool.borrowIncentiveApyInfo.apy;
1219
1227
  r.gt(0) && (a = a.plus(
1220
- new l(d.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1228
+ new l(g.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1221
1229
  ));
1222
- } else if (m.type === "navi-lending-emode-supply") {
1223
- const d = m["navi-lending-emode-supply"], v = d.pool.supplyIncentiveApyInfo.apy;
1224
- n.gt(0) && (t = t.plus(
1225
- new l(d.valueUSD).dividedBy(n).multipliedBy(new l(v).dividedBy(100))
1230
+ } else if (d.type === "navi-lending-emode-supply") {
1231
+ const g = d["navi-lending-emode-supply"], v = g.pool.supplyIncentiveApyInfo.apy;
1232
+ o.gt(0) && (t = t.plus(
1233
+ new l(g.valueUSD).dividedBy(o).multipliedBy(new l(v).dividedBy(100))
1226
1234
  ));
1227
- } else if (m.type === "navi-lending-emode-borrow") {
1228
- const d = m["navi-lending-emode-borrow"], v = d.pool.borrowIncentiveApyInfo.apy;
1235
+ } else if (d.type === "navi-lending-emode-borrow") {
1236
+ const g = d["navi-lending-emode-borrow"], v = g.pool.borrowIncentiveApyInfo.apy;
1229
1237
  r.gt(0) && (a = a.plus(
1230
- new l(d.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1238
+ new l(g.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1231
1239
  ));
1232
1240
  }
1233
1241
  });
1234
- const u = n.minus(r), s = n.minus(r).eq(0) ? new l(0) : n.multipliedBy(t).minus(r.multipliedBy(a)).div(n.minus(r));
1242
+ const s = o.minus(r), u = o.minus(r).eq(0) ? new l(0) : o.multipliedBy(t).minus(r.multipliedBy(a)).div(o.minus(r));
1235
1243
  return {
1236
- hf: r.toNumber() !== 0 ? i.dividedBy(r).toNumber() : 1 / 0,
1237
- netVaule: u.toString(),
1238
- netWorthApr: s.toString(),
1239
- totalSupplyValue: n.toString(),
1244
+ hf: r.toNumber() !== 0 ? c.dividedBy(r).toNumber() : 1 / 0,
1245
+ netVaule: s.toString(),
1246
+ netWorthApr: u.toString(),
1247
+ totalSupplyValue: o.toString(),
1240
1248
  totalBorrowValue: r.toString(),
1241
1249
  totalsupplyApy: t.toString(),
1242
1250
  totalBorrowApy: a.toString(),
1243
- maxLiquidationValue: i.toString(),
1244
- maxLoanToVaule: c.toString()
1251
+ maxLiquidationValue: c.toString(),
1252
+ maxLoanToVaule: i.toString()
1245
1253
  };
1246
1254
  }
1247
1255
  }
1248
- const x = new z("https://hermes.pyth.network", {
1256
+ const x = new K("https://hermes.pyth.network", {
1249
1257
  timeout: 1e4
1250
1258
  });
1251
- async function Ie(e) {
1259
+ async function Be(e) {
1252
1260
  try {
1253
- const o = [], n = await x.getLatestPriceFeeds(e);
1254
- if (!n) return o;
1261
+ const n = [], o = await x.getLatestPriceFeeds(e);
1262
+ if (!o) return n;
1255
1263
  const r = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1256
- for (const t of n) {
1264
+ for (const t of o) {
1257
1265
  const a = t.getPriceUnchecked();
1258
1266
  if (a.publishTime > r) {
1259
1267
  console.warn(
@@ -1263,43 +1271,43 @@ async function Ie(e) {
1263
1271
  }
1264
1272
  r - t.getPriceUnchecked().publishTime > 30 && (console.info(
1265
1273
  `stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`
1266
- ), o.push(t.id));
1274
+ ), n.push(t.id));
1267
1275
  }
1268
- return o;
1269
- } catch (o) {
1270
- throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`);
1276
+ return n;
1277
+ } catch (n) {
1278
+ throw new Error(`failed to get pyth stale price feed id, msg: ${n.message}`);
1271
1279
  }
1272
1280
  }
1273
- async function $e(e, o, n) {
1274
- const r = n?.client ?? $, t = await k({
1275
- ...n,
1281
+ async function Ae(e, n, o) {
1282
+ const r = o?.client ?? $, t = await k({
1283
+ ...o,
1276
1284
  cacheTime: w
1277
1285
  });
1278
1286
  try {
1279
- const a = await x.getPriceFeedsUpdateData(o);
1287
+ const a = await x.getPriceFeedsUpdateData(n);
1280
1288
  return await new ue(
1281
1289
  r,
1282
1290
  t.oracle.pythStateId,
1283
1291
  t.oracle.wormholeStateId
1284
- ).updatePriceFeeds(e, a, o);
1292
+ ).updatePriceFeeds(e, a, n);
1285
1293
  } catch (a) {
1286
1294
  throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
1287
1295
  }
1288
1296
  }
1289
- async function Se(e, o, n) {
1297
+ async function $e(e, n, o) {
1290
1298
  const r = await k({
1291
- ...n,
1299
+ ...o,
1292
1300
  cacheTime: w
1293
1301
  });
1294
- if (n?.updatePythPriceFeeds) {
1295
- const t = o.filter((a) => !!a.pythPriceFeedId).map((a) => a.pythPriceFeedId);
1302
+ if (o?.updatePythPriceFeeds) {
1303
+ const t = n.filter((a) => !!a.pythPriceFeedId).map((a) => a.pythPriceFeedId);
1296
1304
  try {
1297
- const a = await Ie(t);
1298
- a.length > 0 && await $e(e, a, n);
1305
+ const a = await Be(t);
1306
+ a.length > 0 && await Ae(e, a, o);
1299
1307
  } catch {
1300
1308
  }
1301
1309
  }
1302
- for (const t of o)
1310
+ for (const t of n)
1303
1311
  e.moveCall({
1304
1312
  target: `${r.oracle.packageId}::oracle_pro::update_single_price`,
1305
1313
  arguments: [
@@ -1325,30 +1333,30 @@ async function ee(e) {
1325
1333
  cacheTime: w
1326
1334
  })).oracle.feeds;
1327
1335
  }
1328
- function Pe(e, o) {
1329
- return e.filter((n) => !!(o?.lendingState && o.lendingState.find((t) => t.assetId === n.assetId) || o?.lendingPositions && o.lendingPositions.find((t) => [
1336
+ function Pe(e, n) {
1337
+ return e.filter((o) => !!(n?.lendingState && n.lendingState.find((t) => t.assetId === o.assetId) || n?.lendingPositions && n.lendingPositions.find((t) => [
1330
1338
  "navi-lending-supply",
1331
1339
  "navi-lending-borrow",
1332
1340
  "navi-lending-emode-supply",
1333
1341
  "navi-lending-emode-borrow"
1334
- ].includes(t.type) ? t[t.type]?.pool?.id === n.assetId : !1) || o?.pools && o.pools.find((t) => t.id === n.assetId)));
1342
+ ].includes(t.type) ? t[t.type]?.pool?.id === o.assetId : !1) || n?.pools && n.pools.find((t) => t.id === o.assetId)));
1335
1343
  }
1336
- async function st(e, o, n, r) {
1344
+ async function st(e, n, o, r) {
1337
1345
  try {
1338
1346
  const t = await ee({
1339
1347
  ...r
1340
1348
  }), a = [];
1341
- n.forEach((s) => {
1342
- a.includes(s.market) || a.push(s.market);
1349
+ o.forEach((u) => {
1350
+ a.includes(u.market) || a.push(u.market);
1343
1351
  });
1344
- const i = await Ae(o, {
1352
+ const c = await Ie(n, {
1345
1353
  ...r,
1346
1354
  markets: a
1347
- }), c = Pe(t, {
1348
- lendingPositions: i,
1349
- pools: n
1355
+ }), i = Pe(t, {
1356
+ lendingPositions: c,
1357
+ pools: o
1350
1358
  });
1351
- return await Se(e, c, {
1359
+ return await $e(e, i, {
1352
1360
  updatePythPriceFeeds: !0,
1353
1361
  ...r
1354
1362
  });
@@ -1358,186 +1366,186 @@ async function st(e, o, n, r) {
1358
1366
  return console.error(t), e;
1359
1367
  }
1360
1368
  }
1361
- const F = I(
1362
- B(
1369
+ const L = A(
1370
+ I(
1363
1371
  async (e) => {
1364
- const o = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${S.version}&market=${e?.market || M}`, n = await fetch(o, { headers: V }).then((r) => r.json());
1365
- return Object.keys(n.data).map((r) => ({
1366
- ...n.data[r],
1372
+ const n = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${P.version}&market=${e?.market || U}`, o = await fetch(n, { headers: V }).then((r) => r.json());
1373
+ return Object.keys(o.data).map((r) => ({
1374
+ ...o.data[r],
1367
1375
  coinType: r
1368
1376
  }));
1369
1377
  }
1370
1378
  )
1371
1379
  );
1372
- async function ut(e, o) {
1373
- return (await F(o)).find((r) => typeof e == "string" ? b(r.coinType) === b(e) : typeof e == "number" ? r.assetId === e : r.assetId === e.id) || null;
1380
+ async function ut(e, n) {
1381
+ return (await L(n)).find((r) => typeof e == "string" ? b(r.coinType) === b(e) : typeof e == "number" ? r.assetId === e : r.assetId === e.id) || null;
1374
1382
  }
1375
- async function lt(e, o, n, r) {
1383
+ async function lt(e, n, o, r) {
1376
1384
  const t = await k({
1377
1385
  ...r,
1378
1386
  cacheTime: w
1379
- }), a = await A(o, r);
1380
- if (!(await F({
1387
+ }), a = await B(n, r);
1388
+ if (!(await L({
1381
1389
  ...r,
1382
1390
  cacheTime: w
1383
1391
  })).some(
1384
- (u) => b(u.coinType) === b(a.suiCoinType)
1392
+ (s) => b(s.coinType) === b(a.suiCoinType)
1385
1393
  ))
1386
1394
  throw new Error("Pool does not support flashloan");
1387
1395
  if (t.version === 1) {
1388
- const [u, s] = e.moveCall({
1396
+ const [s, u] = e.moveCall({
1389
1397
  target: `${t.package}::lending::flash_loan_with_ctx`,
1390
1398
  arguments: [
1391
1399
  e.object(t.flashloanConfig),
1392
1400
  e.object(a.contract.pool),
1393
- f(n, e.pure.u64)
1401
+ f(o, e.pure.u64)
1394
1402
  ],
1395
1403
  typeArguments: [a.suiCoinType]
1396
1404
  });
1397
- return [u, s];
1405
+ return [s, u];
1398
1406
  } else {
1399
- const [u, s] = e.moveCall({
1407
+ const [s, u] = e.moveCall({
1400
1408
  target: `${t.package}::lending::flash_loan_with_ctx_v2`,
1401
1409
  arguments: [
1402
1410
  e.object(t.flashloanConfig),
1403
1411
  e.object(a.contract.pool),
1404
- f(n, e.pure.u64),
1412
+ f(o, e.pure.u64),
1405
1413
  e.object("0x05")
1406
1414
  ],
1407
1415
  typeArguments: [a.suiCoinType]
1408
1416
  });
1409
- return [u, s];
1417
+ return [s, u];
1410
1418
  }
1411
1419
  }
1412
- async function pt(e, o, n, r, t) {
1420
+ async function pt(e, n, o, r, t) {
1413
1421
  const a = await k({
1414
1422
  ...t,
1415
1423
  cacheTime: w
1416
- }), i = await A(o, t);
1417
- if (!(await F({
1424
+ }), c = await B(n, t);
1425
+ if (!(await L({
1418
1426
  ...t,
1419
1427
  cacheTime: w
1420
1428
  })).some(
1421
- (g) => b(g.coinType) === b(i.suiCoinType)
1429
+ (m) => b(m.coinType) === b(c.suiCoinType)
1422
1430
  ))
1423
1431
  throw new Error("Pool does not support flashloan");
1424
- const [s] = e.moveCall({
1432
+ const [u] = e.moveCall({
1425
1433
  target: `${a.package}::lending::flash_repay_with_ctx`,
1426
1434
  arguments: [
1427
1435
  e.object("0x06"),
1428
1436
  e.object(a.storage),
1429
- e.object(i.contract.pool),
1430
- f(n, e.object),
1437
+ e.object(c.contract.pool),
1438
+ f(o, e.object),
1431
1439
  f(r, e.object)
1432
1440
  ],
1433
- typeArguments: [i.suiCoinType]
1441
+ typeArguments: [c.suiCoinType]
1434
1442
  });
1435
- return [s];
1443
+ return [u];
1436
1444
  }
1437
- async function dt(e, o, n, r, t, a) {
1438
- const i = {
1445
+ async function dt(e, n, o, r, t, a) {
1446
+ const c = {
1439
1447
  ...a,
1440
1448
  cacheTime: w
1441
- }, c = await k(i), u = await A(o, i), s = await A(r, i);
1442
- if (c.version === 1) {
1443
- const [g, m] = e.moveCall({
1444
- target: `${c.package}::incentive_v3::liquidation`,
1449
+ }, i = await k(c), s = await B(n, c), u = await B(r, c);
1450
+ if (i.version === 1) {
1451
+ const [m, d] = e.moveCall({
1452
+ target: `${i.package}::incentive_v3::liquidation`,
1445
1453
  arguments: [
1446
1454
  e.object("0x06"),
1447
1455
  // Clock object
1448
- e.object(c.priceOracle),
1456
+ e.object(i.priceOracle),
1449
1457
  // Price oracle for asset pricing
1450
- e.object(c.storage),
1458
+ e.object(i.storage),
1451
1459
  // Protocol storage
1452
- e.pure.u8(u.id),
1460
+ e.pure.u8(s.id),
1453
1461
  // Pay asset ID
1454
- e.object(u.contract.pool),
1462
+ e.object(s.contract.pool),
1455
1463
  // Pay asset pool contract
1456
- f(n, e.object),
1464
+ f(o, e.object),
1457
1465
  // Debt repayment amount
1458
- e.pure.u8(s.id),
1466
+ e.pure.u8(u.id),
1459
1467
  // Collateral asset ID
1460
- e.object(s.contract.pool),
1468
+ e.object(u.contract.pool),
1461
1469
  // Collateral asset pool contract
1462
1470
  f(t, e.pure.address),
1463
1471
  // Borrower address
1464
- e.object(c.incentiveV2),
1472
+ e.object(i.incentiveV2),
1465
1473
  // Incentive V2 contract
1466
- e.object(c.incentiveV3)
1474
+ e.object(i.incentiveV3)
1467
1475
  // Incentive V3 contract
1468
1476
  ],
1469
- typeArguments: [u.suiCoinType, s.suiCoinType]
1477
+ typeArguments: [s.suiCoinType, u.suiCoinType]
1470
1478
  });
1471
- return [g, m];
1479
+ return [m, d];
1472
1480
  } else {
1473
- const [g, m] = e.moveCall({
1474
- target: `${c.package}::incentive_v3::liquidation_v2`,
1481
+ const [m, d] = e.moveCall({
1482
+ target: `${i.package}::incentive_v3::liquidation_v2`,
1475
1483
  arguments: [
1476
1484
  e.object("0x06"),
1477
1485
  // Clock object
1478
- e.object(c.priceOracle),
1486
+ e.object(i.priceOracle),
1479
1487
  // Price oracle for asset pricing
1480
- e.object(c.storage),
1488
+ e.object(i.storage),
1481
1489
  // Protocol storage
1482
- e.pure.u8(u.id),
1490
+ e.pure.u8(s.id),
1483
1491
  // Pay asset ID
1484
- e.object(u.contract.pool),
1492
+ e.object(s.contract.pool),
1485
1493
  // Pay asset pool contract
1486
- f(n, e.object),
1494
+ f(o, e.object),
1487
1495
  // Debt repayment amount
1488
- e.pure.u8(s.id),
1496
+ e.pure.u8(u.id),
1489
1497
  // Collateral asset ID
1490
- e.object(s.contract.pool),
1498
+ e.object(u.contract.pool),
1491
1499
  // Collateral asset pool contract
1492
1500
  f(t, e.pure.address),
1493
1501
  // Borrower address
1494
- e.object(c.incentiveV2),
1502
+ e.object(i.incentiveV2),
1495
1503
  // Incentive V2 contract
1496
- e.object(c.incentiveV3),
1504
+ e.object(i.incentiveV3),
1497
1505
  // Incentive V3 contract
1498
1506
  e.object("0x05")
1499
1507
  // SuiSystemState object
1500
1508
  ],
1501
- typeArguments: [u.suiCoinType, s.suiCoinType]
1509
+ typeArguments: [s.suiCoinType, u.suiCoinType]
1502
1510
  });
1503
- return [g, m];
1511
+ return [m, d];
1504
1512
  }
1505
1513
  }
1506
- async function Ve(e, o, n) {
1507
- const r = n?.client ?? $, t = new U(), a = await N({
1508
- ...n,
1514
+ async function Se(e, n, o) {
1515
+ const r = o?.client ?? $, t = new M(), a = await N({
1516
+ ...o,
1509
1517
  markets: Object.values(E),
1510
1518
  cacheTime: w
1511
- }), i = await ee(n);
1512
- for (let g of o) {
1513
- const m = await k({
1514
- ...n,
1519
+ }), c = await ee(o);
1520
+ for (let m of n) {
1521
+ const d = await k({
1522
+ ...o,
1515
1523
  cacheTime: w,
1516
- market: g.market
1524
+ market: m.market
1517
1525
  });
1518
1526
  t.moveCall({
1519
- target: `${m.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
1527
+ target: `${d.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
1520
1528
  arguments: [
1521
1529
  t.object("0x06"),
1522
1530
  // Clock object
1523
- t.object(m.storage),
1531
+ t.object(d.storage),
1524
1532
  // Protocol storage
1525
- t.object(m.incentiveV3),
1533
+ t.object(d.incentiveV3),
1526
1534
  // Incentive V3 contract
1527
- t.pure.address(g.address)
1535
+ t.pure.address(m.address)
1528
1536
  // User address
1529
1537
  ]
1530
1538
  });
1531
1539
  }
1532
- const c = await r.devInspectTransactionBlock({
1540
+ const i = await r.devInspectTransactionBlock({
1533
1541
  transactionBlock: t,
1534
1542
  sender: e
1535
- }), u = [];
1536
- c?.results?.forEach((g) => {
1537
- u.push(
1538
- O(
1543
+ }), s = [];
1544
+ i?.results?.forEach((m) => {
1545
+ s.push(
1546
+ R(
1539
1547
  {
1540
- results: [g]
1548
+ results: [m]
1541
1549
  },
1542
1550
  [
1543
1551
  _.vector(_.string()),
@@ -1554,53 +1562,53 @@ async function Ve(e, o, n) {
1554
1562
  )
1555
1563
  );
1556
1564
  });
1557
- const s = [];
1558
- return u.forEach((g, m) => {
1559
- const d = o[m];
1560
- if (g.length === 5 && Array.isArray(g[0])) {
1561
- const v = g[0].length;
1565
+ const u = [];
1566
+ return s.forEach((m, d) => {
1567
+ const g = n[d];
1568
+ if (m.length === 5 && Array.isArray(m[0])) {
1569
+ const v = m[0].length;
1562
1570
  for (let y = 0; y < v; y++) {
1563
- const h = i.find(
1564
- (T) => b(T.coinType) === b(g[1][y])
1571
+ const h = c.find(
1572
+ (T) => b(T.coinType) === b(m[1][y])
1565
1573
  ), C = a.find(
1566
- (T) => b(T.coinType) === b(g[0][y])
1574
+ (T) => b(T.coinType) === b(m[0][y])
1567
1575
  );
1568
- !h || !C || s.push({
1576
+ !h || !C || u.push({
1569
1577
  assetId: C.id,
1570
- assetCoinType: b(g[0][y]),
1571
- rewardCoinType: b(g[1][y]),
1572
- option: Number(g[2][y]),
1573
- userClaimableReward: Number(g[4][y]) / Math.pow(10, h.priceDecimal),
1574
- ruleIds: Array.isArray(g[3][y]) ? g[3][y] : [g[3][y]],
1575
- market: d.market,
1576
- owner: d.address,
1577
- emodeId: d.emodeId
1578
+ assetCoinType: b(m[0][y]),
1579
+ rewardCoinType: b(m[1][y]),
1580
+ option: Number(m[2][y]),
1581
+ userClaimableReward: Number(m[4][y]) / Math.pow(10, h.priceDecimal),
1582
+ ruleIds: Array.isArray(m[3][y]) ? m[3][y] : [m[3][y]],
1583
+ market: g.market,
1584
+ owner: g.address,
1585
+ emodeId: g.emodeId
1578
1586
  });
1579
1587
  }
1580
1588
  }
1581
- }), s;
1589
+ }), u;
1582
1590
  }
1583
- async function mt(e, o) {
1584
- const n = (o?.markets || [E.main]).map((a) => j(a)), r = await Q(e, o), t = n.map((a) => ({
1591
+ async function mt(e, n) {
1592
+ const o = (n?.markets || [E.main]).map((a) => j(a)), r = await Q(e, n), t = o.map((a) => ({
1585
1593
  address: e,
1586
1594
  market: a.key
1587
1595
  })).concat(
1588
- r.filter((a) => !!n.find((i) => i.id === a.marketId)).map((a) => {
1589
- const i = j(a.marketId);
1596
+ r.filter((a) => !!o.find((c) => c.id === a.marketId)).map((a) => {
1597
+ const c = j(a.marketId);
1590
1598
  return {
1591
1599
  address: e,
1592
- market: i.key,
1600
+ market: c.key,
1593
1601
  emodeId: a.emodeId
1594
1602
  };
1595
1603
  })
1596
1604
  );
1597
- return await Ve(e, t, o);
1605
+ return await Se(e, t, n);
1598
1606
  }
1599
1607
  function gt(e) {
1600
- const o = /* @__PURE__ */ new Map();
1608
+ const n = /* @__PURE__ */ new Map();
1601
1609
  e.forEach((r) => {
1602
- const t = r.assetId, a = r.option, i = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
1603
- o.has(i) ? o.get(i).total += r.userClaimableReward : o.set(i, {
1610
+ const t = r.assetId, a = r.option, c = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
1611
+ n.has(c) ? n.get(c).total += r.userClaimableReward : n.set(c, {
1604
1612
  assetId: t,
1605
1613
  rewardType: a,
1606
1614
  coinType: r.rewardCoinType,
@@ -1608,14 +1616,14 @@ function gt(e) {
1608
1616
  market: r.market
1609
1617
  });
1610
1618
  });
1611
- const n = /* @__PURE__ */ new Map();
1612
- for (const { assetId: r, rewardType: t, coinType: a, total: i, market: c } of o.values()) {
1613
- const u = `${r}-${t}-${c}`;
1614
- n.has(u) || n.set(u, { assetId: r, rewardType: t, market: c, rewards: /* @__PURE__ */ new Map() });
1615
- const s = n.get(u);
1616
- s.rewards.set(a, (s.rewards.get(a) || 0) + i);
1619
+ const o = /* @__PURE__ */ new Map();
1620
+ for (const { assetId: r, rewardType: t, coinType: a, total: c, market: i } of n.values()) {
1621
+ const s = `${r}-${t}-${i}`;
1622
+ o.has(s) || o.set(s, { assetId: r, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
1623
+ const u = o.get(s);
1624
+ u.rewards.set(a, (u.rewards.get(a) || 0) + c);
1617
1625
  }
1618
- return Array.from(n.values()).map((r) => ({
1626
+ return Array.from(o.values()).map((r) => ({
1619
1627
  assetId: r.assetId,
1620
1628
  rewardType: r.rewardType,
1621
1629
  market: r.market,
@@ -1625,56 +1633,56 @@ function gt(e) {
1625
1633
  }))
1626
1634
  }));
1627
1635
  }
1628
- const ft = B(
1629
- async (e, o) => {
1630
- const n = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${S.version}&market=${o?.market || M}`;
1631
- return (await fetch(n, { headers: V }).then((t) => t.json())).data;
1636
+ const ft = I(
1637
+ async (e, n) => {
1638
+ const o = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${P.version}&market=${n?.market || U}`;
1639
+ return (await fetch(o, { headers: V }).then((t) => t.json())).data;
1632
1640
  }
1633
- ), yt = B(
1634
- async (e, o) => {
1635
- const n = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${o?.page || 1}&pageSize=${o?.size || 400}&sdk=${S.version}&market=${o?.market || M}`, r = await fetch(n, { headers: V }).then((t) => t.json());
1636
- return R({
1641
+ ), yt = I(
1642
+ async (e, n) => {
1643
+ const o = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${n?.page || 1}&pageSize=${n?.size || 400}&sdk=${P.version}&market=${n?.market || U}`, r = await fetch(o, { headers: V }).then((t) => t.json());
1644
+ return O({
1637
1645
  data: r.data.rewards
1638
1646
  });
1639
1647
  }
1640
1648
  );
1641
- async function vt(e, o, n) {
1649
+ async function vt(e, n, o) {
1642
1650
  const r = await k({
1643
- ...n,
1651
+ ...o,
1644
1652
  cacheTime: w
1645
1653
  }), t = await N({
1646
- ...n,
1654
+ ...o,
1647
1655
  markets: Object.values(E),
1648
1656
  cacheTime: w
1649
1657
  }), a = /* @__PURE__ */ new Map();
1650
- for (const c of o) {
1651
- const { rewardCoinType: u, ruleIds: s, market: g, owner: m, emodeId: d } = c, v = `${u}-${g}-${m}`;
1652
- for (const y of s) {
1658
+ for (const i of n) {
1659
+ const { rewardCoinType: s, ruleIds: u, market: m, owner: d, emodeId: g } = i, v = `${s}-${m}-${d}`;
1660
+ for (const y of u) {
1653
1661
  a.has(v) || a.set(v, {
1654
1662
  assetIds: [],
1655
1663
  ruleIds: [],
1656
1664
  amount: 0,
1657
- market: g,
1658
- owner: m,
1659
- isEMode: typeof d < "u"
1665
+ market: m,
1666
+ owner: d,
1667
+ isEMode: typeof g < "u"
1660
1668
  });
1661
1669
  const h = a.get(v);
1662
- h.assetIds.push(c.assetCoinType.replace("0x", "")), h.ruleIds.push(y), h.amount += c.userClaimableReward;
1670
+ h.assetIds.push(i.assetCoinType.replace("0x", "")), h.ruleIds.push(y), h.amount += i.userClaimableReward;
1663
1671
  }
1664
1672
  }
1665
- const i = [];
1666
- for (const [c, { assetIds: u, ruleIds: s, amount: g, market: m, owner: d, isEMode: v }] of a) {
1673
+ const c = [];
1674
+ for (const [i, { assetIds: s, ruleIds: u, amount: m, market: d, owner: g, isEMode: v }] of a) {
1667
1675
  const y = t.find(
1668
- (C) => b(C.suiCoinType) === b(c) && C.market === m
1676
+ (C) => b(C.suiCoinType) === b(i) && C.market === d
1669
1677
  );
1670
1678
  if (!y || !y.contract.rewardFundId)
1671
- throw new Error(`No matching rewardFund found for reward coin: ${c} ${m}`);
1679
+ throw new Error(`No matching rewardFund found for reward coin: ${i} ${d}`);
1672
1680
  const h = y.contract.rewardFundId;
1673
- if (n?.accountCap && !n.customCoinReceive)
1681
+ if (o?.accountCap && !o.customCoinReceive)
1674
1682
  throw new Error("customCoinReceive is required when accountCap is provided");
1675
- if (n?.customCoinReceive) {
1683
+ if (o?.customCoinReceive) {
1676
1684
  let C;
1677
- n.accountCap ? C = e.moveCall({
1685
+ o.accountCap ? C = e.moveCall({
1678
1686
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1679
1687
  arguments: [
1680
1688
  e.object("0x06"),
@@ -1685,14 +1693,14 @@ async function vt(e, o, n) {
1685
1693
  // Protocol storage
1686
1694
  e.object(h),
1687
1695
  // Reward fund
1688
- e.pure.vector("string", u),
1696
+ e.pure.vector("string", s),
1689
1697
  // Asset IDs
1690
- e.pure.vector("address", s),
1698
+ e.pure.vector("address", u),
1691
1699
  // Rule IDs
1692
- f(n.accountCap, e.object)
1700
+ f(o.accountCap, e.object)
1693
1701
  // Account capability
1694
1702
  ],
1695
- typeArguments: [c]
1703
+ typeArguments: [i]
1696
1704
  }) : v ? C = e.moveCall({
1697
1705
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1698
1706
  arguments: [
@@ -1704,14 +1712,14 @@ async function vt(e, o, n) {
1704
1712
  // Protocol storage
1705
1713
  e.object(h),
1706
1714
  // Reward fund
1707
- e.pure.vector("string", u),
1715
+ e.pure.vector("string", s),
1708
1716
  // Asset IDs
1709
- e.pure.vector("address", s),
1717
+ e.pure.vector("address", u),
1710
1718
  // Rule IDs
1711
- f(d, e.object)
1719
+ f(g, e.object)
1712
1720
  // Account capability
1713
1721
  ],
1714
- typeArguments: [c]
1722
+ typeArguments: [i]
1715
1723
  }) : C = e.moveCall({
1716
1724
  target: `${r.package}::incentive_v3::claim_reward`,
1717
1725
  arguments: [
@@ -1723,40 +1731,40 @@ async function vt(e, o, n) {
1723
1731
  // Protocol storage
1724
1732
  e.object(h),
1725
1733
  // Reward fund
1726
- e.pure.vector("string", u),
1734
+ e.pure.vector("string", s),
1727
1735
  // Asset IDs
1728
- e.pure.vector("address", s)
1736
+ e.pure.vector("address", u)
1729
1737
  // Rule IDs
1730
1738
  ],
1731
- typeArguments: [c]
1739
+ typeArguments: [i]
1732
1740
  });
1733
1741
  const [T] = e.moveCall({
1734
1742
  target: "0x2::coin::from_balance",
1735
1743
  arguments: [C],
1736
- typeArguments: [c]
1744
+ typeArguments: [i]
1737
1745
  });
1738
- if (n?.customCoinReceive.type === "transfer") {
1739
- if (!n.customCoinReceive.transfer)
1746
+ if (o?.customCoinReceive.type === "transfer") {
1747
+ if (!o.customCoinReceive.transfer)
1740
1748
  throw new Error("customCoinReceive.transfer is required");
1741
1749
  e.transferObjects(
1742
1750
  [T],
1743
- f(n.customCoinReceive.transfer, e.pure.address)
1751
+ f(o.customCoinReceive.transfer, e.pure.address)
1744
1752
  );
1745
1753
  }
1746
- if (n?.customCoinReceive.type === "depositNAVI") {
1754
+ if (o?.customCoinReceive.type === "depositNAVI") {
1747
1755
  const te = l(y.totalSupplyAmount).shiftedBy(-9), oe = l(y.supplyCapCeiling).shiftedBy(-27);
1748
- te.plus(g).isGreaterThan(oe) && n?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1756
+ te.plus(m).isGreaterThan(oe) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1749
1757
  [T],
1750
- e.pure.address(n.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1751
- ) : await he(e, y, T, n);
1758
+ e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1759
+ ) : await he(e, y, T, o);
1752
1760
  } else
1753
- i.push({
1761
+ c.push({
1754
1762
  coin: T,
1755
1763
  identifier: y,
1756
- owner: d,
1764
+ owner: g,
1757
1765
  isEMode: v
1758
1766
  });
1759
- } else if (n?.accountCap || v) {
1767
+ } else if (o?.accountCap || v) {
1760
1768
  const C = e.moveCall({
1761
1769
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1762
1770
  arguments: [
@@ -1768,22 +1776,22 @@ async function vt(e, o, n) {
1768
1776
  // Protocol storage
1769
1777
  e.object(h),
1770
1778
  // Reward fund
1771
- e.pure.vector("string", u),
1779
+ e.pure.vector("string", s),
1772
1780
  // Asset IDs
1773
- e.pure.vector("address", s),
1781
+ e.pure.vector("address", u),
1774
1782
  // Rule IDs
1775
- f(n?.accountCap || d, e.object)
1783
+ f(o?.accountCap || g, e.object)
1776
1784
  // Account capability
1777
1785
  ],
1778
- typeArguments: [c]
1786
+ typeArguments: [i]
1779
1787
  }), [T] = e.moveCall({
1780
1788
  target: "0x2::coin::from_balance",
1781
1789
  arguments: [C],
1782
- typeArguments: [c]
1790
+ typeArguments: [i]
1783
1791
  });
1784
1792
  e.transferObjects(
1785
1793
  [T],
1786
- f(n?.accountCap || d, e.pure.address)
1794
+ f(o?.accountCap || g, e.pure.address)
1787
1795
  );
1788
1796
  } else
1789
1797
  e.moveCall({
@@ -1797,62 +1805,62 @@ async function vt(e, o, n) {
1797
1805
  // Protocol storage
1798
1806
  e.object(h),
1799
1807
  // Reward fund
1800
- e.pure.vector("string", u),
1808
+ e.pure.vector("string", s),
1801
1809
  // Asset IDs
1802
- e.pure.vector("address", s)
1810
+ e.pure.vector("address", u)
1803
1811
  // Rule IDs
1804
1812
  ],
1805
- typeArguments: [c]
1813
+ typeArguments: [i]
1806
1814
  });
1807
1815
  }
1808
- return i;
1816
+ return c;
1809
1817
  }
1810
1818
  export {
1811
- L as Address,
1819
+ q as Address,
1812
1820
  w as DEFAULT_CACHE_TIME,
1813
- M as DEFAULT_MARKET_IDENTITY,
1814
- He as FlashLoanAssetConfig,
1815
- Le as IncentiveAPYInfo,
1821
+ U as DEFAULT_MARKET_IDENTITY,
1822
+ We as FlashLoanAssetConfig,
1823
+ Fe as IncentiveAPYInfo,
1816
1824
  le as IncentivePoolInfo,
1817
- qe as IncentivePoolInfoByPhase,
1825
+ Le as IncentivePoolInfoByPhase,
1818
1826
  E as MARKETS,
1819
- je as Market,
1820
- We as OracleInfo,
1827
+ be as Market,
1828
+ qe as OracleInfo,
1821
1829
  D as PoolOperator,
1822
- Ge as ReserveDataInfo,
1823
- it as UserPositions,
1830
+ He as ReserveDataInfo,
1831
+ ct as UserPositions,
1824
1832
  pe as UserStateInfo,
1825
- Je as borrowCoinPTB,
1833
+ Ye as borrowCoinPTB,
1826
1834
  vt as claimLendingRewardsPTB,
1827
- be as createAccountCapPTB,
1835
+ _e as createAccountCapPTB,
1828
1836
  xe as createEModeCapPTB,
1829
1837
  he as depositCoinPTB,
1830
- Ce as emodeIdentityId,
1831
- _e as enterEModePTB,
1838
+ et as emodeIdentityId,
1839
+ je as enterEModePTB,
1832
1840
  Ze as exitEModePTB,
1833
1841
  Pe as filterPriceFeeds,
1834
1842
  lt as flashloanPTB,
1835
- ke as getAccountCapOwnerPTB,
1836
- F as getAllFlashLoanAssets,
1837
- Xe as getBorrowFee,
1838
- ct as getCoins,
1843
+ Ce as getAccountCapOwnerPTB,
1844
+ L as getAllFlashLoanAssets,
1845
+ Qe as getBorrowFee,
1846
+ it as getCoins,
1839
1847
  k as getConfig,
1840
- Ke as getFees,
1848
+ ze as getFees,
1841
1849
  ut as getFlashLoanAsset,
1842
1850
  nt as getHealthFactor,
1843
- Be as getHealthFactorPTB,
1844
- Ae as getLendingPositions,
1851
+ Te as getHealthFactorPTB,
1852
+ Ie as getLendingPositions,
1845
1853
  ot as getLendingState,
1846
- et as getMarket,
1854
+ Xe as getMarket,
1847
1855
  j as getMarketConfig,
1848
- Te as getMarkets,
1849
- A as getPool,
1856
+ ke as getMarkets,
1857
+ B as getPool,
1850
1858
  N as getPools,
1851
1859
  ee as getPriceFeeds,
1852
- Ie as getPythStalePriceFeedId,
1860
+ Be as getPythStalePriceFeedId,
1853
1861
  rt as getSimulatedHealthFactor,
1854
1862
  X as getSimulatedHealthFactorPTB,
1855
- ze as getStats,
1863
+ Ge as getStats,
1856
1864
  at as getTransactions,
1857
1865
  mt as getUserAvailableLendingRewards,
1858
1866
  yt as getUserClaimedRewardHistory,
@@ -1863,14 +1871,14 @@ export {
1863
1871
  b as normalizeCoinType,
1864
1872
  we as parsePoolUID,
1865
1873
  f as parseTxValue,
1866
- Qe as repayCoinPTB,
1874
+ Je as repayCoinPTB,
1867
1875
  pt as repayFlashLoanPTB,
1868
1876
  gt as summaryLendingRewards,
1869
1877
  st as updateOraclePriceBeforeUserOperationPTB,
1870
- Se as updateOraclePricesPTB,
1871
- $e as updatePythPriceFeeds,
1872
- I as withCache,
1873
- B as withSingleton,
1874
- Ye as withdrawCoinPTB
1878
+ $e as updateOraclePricesPTB,
1879
+ Ae as updatePythPriceFeeds,
1880
+ A as withCache,
1881
+ I as withSingleton,
1882
+ Ke as withdrawCoinPTB
1875
1883
  };
1876
1884
  //# sourceMappingURL=index.esm.js.map