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

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,27 +1,27 @@
1
1
  import { Transaction as U } from "@mysten/sui/transactions";
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";
5
- import { normalizeStructTag as se } from "@mysten/sui/utils";
6
- import { SuiPriceServiceConnection as z, SuiPythClient as ue } from "@pythnetwork/pyth-sui-js";
2
+ import { bcs as p, toHex as re, fromHex as ae } from "@mysten/bcs";
3
+ import { SuiClient as ce, getFullnodeUrl as ie } from "@mysten/sui/client";
4
+ import se from "lodash.camelcase";
5
+ import { normalizeStructTag as ue } from "@mysten/sui/utils";
6
+ import { SuiPriceServiceConnection as Y, SuiPythClient as le } from "@pythnetwork/pyth-sui-js";
7
7
  import l from "bignumber.js";
8
- import { bcs as _ } from "@mysten/sui/bcs";
9
- const L = p.bytes(32).transform({
8
+ import { bcs as C } from "@mysten/sui/bcs";
9
+ const W = p.bytes(32).transform({
10
10
  // To change the input type, you need to provide a type definition for the input
11
- input: (e) => re(e),
12
- output: (e) => ne(e)
13
- }), Le = p.struct("IncentiveAPYInfo", {
11
+ input: (e) => ae(e),
12
+ output: (e) => re(e)
13
+ }), qe = p.struct("IncentiveAPYInfo", {
14
14
  /** Asset identifier */
15
15
  asset_id: p.u8(),
16
16
  /** Annual Percentage Yield as a 256-bit integer */
17
17
  apy: p.u256(),
18
18
  /** List of supported coin types for this incentive */
19
19
  coin_types: p.vector(p.string())
20
- }), le = p.struct("IncentivePoolInfo", {
20
+ }), pe = p.struct("IncentivePoolInfo", {
21
21
  /** Unique pool identifier */
22
- pool_id: L,
22
+ pool_id: W,
23
23
  /** Address holding the incentive funds */
24
- funds: L,
24
+ funds: W,
25
25
  /** Current phase of the incentive program */
26
26
  phase: p.u64(),
27
27
  /** Timestamp when the incentive started */
@@ -44,11 +44,11 @@ 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
- pools: p.vector(le)
51
+ pools: p.vector(pe)
52
52
  }), We = p.struct("OracleInfo", {
53
53
  /** Oracle identifier */
54
54
  oracle_id: p.u8(),
@@ -122,163 +122,167 @@ const L = p.bytes(32).transform({
122
122
  liquidation_bonus: p.u256(),
123
123
  /** Liquidation threshold */
124
124
  liquidation_threshold: p.u256()
125
- }), pe = p.struct("UserStateInfo", {
125
+ }), de = p.struct("UserStateInfo", {
126
126
  /** Asset identifier */
127
127
  asset_id: p.u8(),
128
128
  /** User's current borrow balance */
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 = {
133
- version: de
134
- }, me = S.version, ge = () => {
132
+ }), me = "1.4.0-emode.13", S = {
133
+ version: me
134
+ }, ge = S.version, ye = () => {
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
  }
142
142
  return "Node/Unknown";
143
143
  }, fe = () => {
144
144
  let e = "";
145
- return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${me} (${ge()})`), e;
146
- }, q = fe(), $ = new ae({
147
- url: ce("mainnet")
145
+ return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${ge} (${ye()})`), e;
146
+ }, H = fe(), $ = new ce({
147
+ url: ie("mainnet")
148
148
  });
149
- function K(e) {
150
- const o = [];
151
- return e.forEach((n, r) => {
149
+ function J(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: i, cacheTime: c, ...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 = J(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] = {
169
+ function A(e) {
170
+ let n = {};
171
+ return (...o) => {
172
+ const r = o[o.length - 1], t = J(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((i) => (n[t] = {
174
174
  data: i,
175
175
  cacheAt: Date.now()
176
176
  }, i));
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 F(e) {
180
+ return Array.isArray(e) ? e.map((n) => F(n)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
181
+ (n, o) => ({
182
+ ...n,
183
+ [se(o)]: F(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 y(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 ve(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 O(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 [];
201
201
  }
202
202
  function b(e) {
203
- return se(e);
203
+ return ue(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 Q(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 Y("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 we = 27, G = (e, n) => {
213
+ if (!Number(e) || !Number(n)) return new l(0);
214
+ const o = new l(1).shiftedBy(1 * we), 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 = H ? {
217
+ "User-Agent": H
218
218
  } : {};
219
- function J(e) {
219
+ function q(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 z(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 K(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
- function we(e) {
242
- const [o, n] = e.split("-");
243
- return !o || !n ? null : {
244
- marketKey: o,
245
- poolId: parseInt(n)
245
+ function he(e) {
246
+ const [n, o] = e.split("-");
247
+ return !n || !o ? null : {
248
+ marketKey: n,
249
+ poolId: parseInt(o)
246
250
  };
247
251
  }
248
252
  function P() {
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
- 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(
255
+ var N = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(N || {});
256
+ const R = 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=${S.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
263
  const i = r.meta.emodes.filter((h) => {
260
- const C = j(h.marketId);
261
- return t.market === C.key && h.isActive;
262
- }).filter((h) => !!h.assets.find((C) => C.assetId === t.id));
264
+ const _ = j(h.marketId);
265
+ return t.market === _.key && h.isActive;
266
+ }).filter((h) => !!h.assets.find((_) => _.assetId === t.id));
263
267
  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(
268
+ const c = 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(c).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(), f = l(g).multipliedBy(t.oracle.price).toString();
272
+ t.poolSupplyAmount = c, t.poolBorrowAmount = s, t.poolSupplyValue = u, t.poolBorrowValue = m, t.poolSupplyCapAmount = d, t.poolBorrowCapAmount = g, t.poolSupplyCapValue = v, t.poolBorrowCapValue = f;
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
- const a = we(e);
277
- a && (n = a.marketKey, e = a.poolId);
280
+ const a = he(e);
281
+ a && (o = a.marketKey, e = a.poolId);
278
282
  }
279
- const r = await N({
280
- ...o,
281
- markets: [n || M],
283
+ const r = await R({
284
+ ...n,
285
+ markets: [o || D],
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 ze = A(
296
+ I(async (e) => {
297
+ const n = `https://open-api.naviprotocol.io/api/navi/stats?sdk=${S.version}`;
298
+ return (await fetch(n, { headers: V }).then((r) => r.json())).data;
295
299
  })
296
- ), Ke = I(
297
- B(
300
+ ), Ke = 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=${S.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 be(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";
315
+ const i = typeof o == "object" && o.$kind === "GasCoin";
312
316
  if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
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
321
  let c;
318
- return typeof r?.amount < "u" ? c = f(r.amount, e.pure.u64) : c = e.moveCall({
322
+ return typeof r?.amount < "u" ? c = y(r.amount, e.pure.u64) : c = e.moveCall({
319
323
  target: "0x2::coin::value",
320
- arguments: [f(n, e.object)],
324
+ arguments: [y(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,10 +330,10 @@ 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
+ y(o, e.object),
330
334
  e.object(t.incentiveV2),
331
335
  e.object(t.incentiveV3),
332
- f(r.accountCap, e.object)
336
+ y(r.accountCap, e.object)
333
337
  ],
334
338
  typeArguments: [a.suiCoinType]
335
339
  }) : e.moveCall({
@@ -339,7 +343,7 @@ 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),
346
+ y(o, e.object),
343
347
  c,
344
348
  e.object(t.incentiveV2),
345
349
  e.object(t.incentiveV3)
@@ -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 Ye(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);
361
+ }), a = await B(n, r), i = y(o, e.pure.u64);
358
362
  let c;
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"),
@@ -369,13 +373,13 @@ async function Ye(e, o, n, r) {
369
373
  i,
370
374
  e.object(t.incentiveV2),
371
375
  e.object(t.incentiveV3),
372
- f(r.accountCap, e.object)
376
+ y(r.accountCap, e.object)
373
377
  ],
374
378
  typeArguments: [a.suiCoinType]
375
379
  });
376
- c = s;
380
+ c = 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"),
@@ -389,10 +393,10 @@ async function Ye(e, o, n, r) {
389
393
  ],
390
394
  typeArguments: [a.suiCoinType]
391
395
  });
392
- c = s;
396
+ c = 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"),
@@ -403,14 +407,14 @@ async function Ye(e, o, n, r) {
403
407
  i,
404
408
  e.object(t.incentiveV2),
405
409
  e.object(t.incentiveV3),
406
- f(r.accountCap, e.object),
410
+ y(r.accountCap, e.object),
407
411
  e.object("0x05")
408
412
  ],
409
413
  typeArguments: [a.suiCoinType]
410
414
  });
411
- c = s;
415
+ c = 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"),
@@ -425,7 +429,7 @@ async function Ye(e, o, n, r) {
425
429
  ],
426
430
  typeArguments: [a.suiCoinType]
427
431
  });
428
- c = s;
432
+ c = u;
429
433
  }
430
434
  return e.moveCall({
431
435
  target: "0x2::coin::from_balance",
@@ -433,18 +437,18 @@ async function Ye(e, o, n, r) {
433
437
  typeArguments: [a.suiCoinType]
434
438
  });
435
439
  }
436
- async function Je(e, o, n, r) {
440
+ async function Je(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);
447
+ const i = y(o, e.pure.u64);
444
448
  let c;
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"),
@@ -455,13 +459,13 @@ async function Je(e, o, n, r) {
455
459
  i,
456
460
  e.object(t.incentiveV2),
457
461
  e.object(t.incentiveV3),
458
- f(r.accountCap, e.object)
462
+ y(r.accountCap, e.object)
459
463
  ],
460
464
  typeArguments: [a.suiCoinType]
461
465
  });
462
- c = s;
466
+ c = 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"),
@@ -475,10 +479,10 @@ async function Je(e, o, n, r) {
475
479
  ],
476
480
  typeArguments: [a.suiCoinType]
477
481
  });
478
- c = s;
482
+ c = 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"),
@@ -489,14 +493,14 @@ async function Je(e, o, n, r) {
489
493
  i,
490
494
  e.object(t.incentiveV2),
491
495
  e.object(t.incentiveV3),
492
- f(r.accountCap, e.object),
496
+ y(r.accountCap, e.object),
493
497
  e.object("0x05")
494
498
  ],
495
499
  typeArguments: [a.suiCoinType]
496
500
  });
497
- c = s;
501
+ c = 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"),
@@ -511,7 +515,7 @@ async function Je(e, o, n, r) {
511
515
  ],
512
516
  typeArguments: [a.suiCoinType]
513
517
  });
514
- c = s;
518
+ c = u;
515
519
  }
516
520
  return e.moveCall({
517
521
  target: "0x2::coin::from_balance",
@@ -519,23 +523,23 @@ async function Je(e, o, n, r) {
519
523
  typeArguments: [a.suiCoinType]
520
524
  });
521
525
  }
522
- async function Qe(e, o, n, r) {
526
+ async function Qe(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";
530
+ }), a = await B(n, r), i = typeof o == "object" && o.$kind === "GasCoin";
527
531
  if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
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
536
  let c;
533
- if (typeof r?.amount < "u" ? c = f(r.amount, e.pure.u64) : c = e.moveCall({
537
+ if (typeof r?.amount < "u" ? c = y(r.amount, e.pure.u64) : c = e.moveCall({
534
538
  target: "0x2::coin::value",
535
- arguments: [f(n, e.object)],
539
+ arguments: [y(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,16 +547,16 @@ 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
+ y(o, e.object),
547
551
  e.object(t.incentiveV2),
548
552
  e.object(t.incentiveV3),
549
- f(r.accountCap, e.object)
553
+ y(r.accountCap, e.object)
550
554
  ],
551
555
  typeArguments: [a.suiCoinType]
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,7 +568,7 @@ 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),
571
+ y(o, e.object),
568
572
  c,
569
573
  e.object(t.incentiveV2),
570
574
  e.object(t.incentiveV3)
@@ -572,19 +576,19 @@ async function Qe(e, o, n, r) {
572
576
  typeArguments: [a.suiCoinType]
573
577
  }), e;
574
578
  }
575
- const Xe = I(
576
- B(
579
+ const Xe = 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();
587
+ const t = await B(e.asset, e), a = e?.client ?? $, i = new U();
584
588
  i.moveCall({
585
- target: `${o.package}::incentive_v3::get_borrow_fee_v2`,
589
+ target: `${n.package}::incentive_v3::get_borrow_fee_v2`,
586
590
  arguments: [
587
- i.object(o.incentiveV3),
591
+ i.object(n.incentiveV3),
588
592
  i.pure.address(e.address),
589
593
  i.pure.u8(t.id),
590
594
  i.pure.u64(1e4)
@@ -594,217 +598,223 @@ const Xe = I(
594
598
  const c = await a.devInspectTransactionBlock({
595
599
  transactionBlock: i,
596
600
  sender: e.address
597
- }), u = O(c, [_.u64()]);
598
- return (Number(u[0]) || 0) / 100;
601
+ }), s = O(c, [C.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
+ ), D = "main", E = {
614
+ main: {
615
+ id: 0,
616
+ key: "main",
617
+ name: "Main Market"
618
+ }
619
+ };
620
+ class ke {
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 = q(this.pools), r = z(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
632
+ let i = l(0), c = 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
+ }), c = c.plus(s.poolBorrowValue), i = i.plus(s.poolSupplyValue);
643
+ }), this.poolMap = q(this.pools, "id"), this.emodeMap = z(this.emodes, "emodeId"), this.emodes.forEach((s) => {
644
+ const u = this.getEModePools(s.emodeId);
645
+ this.emodePools.push(...u);
646
+ }), this._overview = {
647
+ marketTotalSupplyValue: i.toString(),
648
+ marketTotalBorrowValue: c.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 || {}, i = [];
656
+ return n.emodes.forEach((c) => {
657
+ typeof a == "number" && a !== c.emodeId || c.assets.forEach((s) => {
658
+ typeof r == "boolean" && r && s.isCollateral && s.assetId === n.id && i.push(this.poolMap[s.assetId]), typeof t == "boolean" && t && s.isDebt && s.assetId === n.id && i.push(this.poolMap[s.assetId]);
659
+ });
660
+ }), i;
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((i) => i.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
+ }, Ce = A(
687
+ I(
688
+ async (e, n) => {
689
+ const o = await R({
690
+ cacheTime: 6e4,
691
+ ...n,
692
+ markets: e
693
+ });
694
+ return e.map((r) => {
695
+ const t = j(r), a = o.filter((i) => i.market === t.key);
696
+ return new ke(r, a);
697
+ });
698
+ }
699
+ )
700
+ ), Ze = A(
701
+ I(
702
+ async (e, n) => (await Ce([e], n))[0]
703
+ )
704
+ ), k = A(
705
+ I(
706
+ async (e) => {
707
+ const n = j(e?.market || D), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${S.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 je(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 Te(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
+ y(n, e.pure.u64),
742
+ y(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), y(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 xe(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), y(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 et(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 Te(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 || D), i = await je(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
776
  i,
675
- f(a.id, e.pure.u64),
676
- f(o, e.pure.u64)
777
+ y(a.id, e.pure.u64),
778
+ y(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 X = 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 U(), 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
793
  const i = (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, c = C.vector(C.u64()).parse(Uint8Array.from(i[0][0])), s = C.vector(C.u64()).parse(Uint8Array.from(i[1][0])), u = C.vector(C.Address).parse(Uint8Array.from(i[2][0]));
797
+ return c.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 tt(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 ot(e, n, o) {
809
+ const r = typeof o?.balance == "number", t = r ? o.balance : 0;
800
810
  let a = 0;
801
811
  const i = [];
802
812
  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)
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 (c || (c = s.coinType), c !== 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), i.push(s.coinObjectId);
808
818
  }
809
819
  }), i.length === 0)
810
820
  throw new Error("No coins to merge");
@@ -812,237 +822,239 @@ function tt(e, o, n) {
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(c) === b("0x2::sui::SUI") && o?.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]);
816
826
  }
817
- async function X(e, o, n, r, t, a, i) {
827
+ async function Z(e, n, o, r, t, a, i) {
818
828
  const c = await k({
819
829
  ...i,
820
830
  cacheTime: w
821
- }), u = await A(n, i);
831
+ }), s = await B(o, i);
822
832
  return e.moveCall({
823
833
  target: `${c.uiGetter}::calculator_unchecked::dynamic_health_factor`,
824
834
  arguments: [
825
835
  e.object("0x06"),
826
836
  e.object(c.storage),
827
837
  e.object(c.oracle.priceOracle),
828
- ye(e, u),
829
- f(o, e.pure.address),
830
- f(u.id, e.pure.u8),
831
- f(r, e.pure.u64),
832
- f(t, e.pure.u64),
833
- f(a, e.pure.bool)
838
+ ve(e, s),
839
+ y(n, e.pure.address),
840
+ y(s.id, e.pure.u8),
841
+ y(r, e.pure.u64),
842
+ y(t, e.pure.u64),
843
+ y(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 Ie(e, n, o) {
849
+ return Z(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 x(e, n, o) {
852
+ const r = new U(), t = o?.client ?? $, a = await R({
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
+ }), i = q(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) => {
864
- if (y.supply_balance === "0" && y.borrow_balance === "0")
870
+ })).results || []).map((m) => m.returnValues?.map((d) => C.vector(de).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((f) => {
874
+ if (f.supply_balance === "0" && f.borrow_balance === "0")
865
875
  return;
866
- const h = i[`${v.key}-${y.asset_id}`];
876
+ const h = i[`${v.key}-${f.asset_id}`];
867
877
  if (!h)
868
878
  return;
869
- const C = W(
870
- y.supply_balance,
879
+ const _ = G(
880
+ f.supply_balance,
871
881
  h.currentSupplyIndex
872
- ).toString(), T = W(
873
- y.borrow_balance,
882
+ ).toString(), T = G(
883
+ f.borrow_balance,
874
884
  h.currentBorrowIndex
875
885
  ).toString();
876
- s.push({
877
- supplyBalance: C,
886
+ u.push({
887
+ supplyBalance: _,
878
888
  borrowBalance: T,
879
- assetId: y.asset_id,
889
+ assetId: f.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 nt = 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 x(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 rt(e, n) {
907
+ const o = n?.client ?? $, r = new U();
908
+ await Ie(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 = O(t, [C.u256()]);
913
+ return Q(Number(a[0]) || 0);
904
914
  }
905
- async function rt(e, o, n, r) {
915
+ async function at(e, n, o, r) {
906
916
  const t = r?.client ?? $, a = new U();
907
917
  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);
918
+ const s = await B(n, r);
919
+ if (o.forEach((g) => {
920
+ g.type === N.Supply ? i += g.amount : g.type === N.Withdraw ? i -= g.amount : g.type === N.Borrow ? c += g.amount : g.type === N.Repay && (c -= g.amount);
911
921
  }), i * c < 0)
912
922
  throw new Error("Invalid operations");
913
- const s = i > 0 || c > 0;
914
- await X(
923
+ const u = i > 0 || c > 0;
924
+ await Z(
915
925
  a,
916
926
  e,
917
- u,
927
+ s,
918
928
  Math.abs(i),
919
929
  Math.abs(c),
920
- s,
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 = O(m, [C.u256()]);
937
+ return Q(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 ct = 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=${S.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 Be = A(
968
+ async (e, n) => {
969
+ const o = [], r = (n?.markets || Object.keys(E)).map((c) => j(c)), t = await X(e, n), a = r.map((c) => ({
960
970
  address: e,
961
971
  market: c.key
962
972
  })).concat(
963
- t.filter((c) => !!r.find((u) => u.id === c.marketId)).map((c) => ({
973
+ t.filter((c) => !!r.find((s) => s.id === c.marketId)).map((c) => ({
964
974
  address: e,
965
975
  market: j(c.marketId).key,
966
976
  emodeId: c.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 x(e, a, n)).forEach((c) => {
980
+ const s = c.emodeId ? t.find((u) => {
981
+ const m = j(c.market);
982
+ return u.emodeId === c.emodeId && u.marketId === m.id;
973
983
  }) : void 0;
974
- if (u) {
984
+ if (s) {
975
985
  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`,
986
+ const u = l(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
987
+ o.push({
988
+ id: `${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply`,
979
989
  wallet: e,
980
990
  protocol: "navi",
981
991
  market: c.market,
982
992
  type: "navi-lending-emode-supply",
983
993
  "navi-lending-emode-supply": {
984
- amount: s.toString(),
985
- pool: G(c.pool, u),
994
+ amount: u.toString(),
995
+ pool: K(c.pool, s),
986
996
  token: c.pool.token,
987
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
997
+ valueUSD: u.multipliedBy(c.pool.oracle.price).toString(),
998
+ emodeCap: s
988
999
  }
989
1000
  });
990
1001
  }
991
1002
  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`,
1003
+ const u = l(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
1004
+ o.push({
1005
+ id: `${c.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow`,
995
1006
  wallet: e,
996
1007
  protocol: "navi",
997
1008
  market: c.market,
998
1009
  type: "navi-lending-emode-borrow",
999
1010
  "navi-lending-emode-borrow": {
1000
- amount: s.toString(),
1001
- pool: G(c.pool, u),
1011
+ amount: u.toString(),
1012
+ pool: K(c.pool, s),
1002
1013
  token: c.pool.token,
1003
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
1014
+ valueUSD: u.multipliedBy(c.pool.oracle.price).toString(),
1015
+ emodeCap: s
1004
1016
  }
1005
1017
  });
1006
1018
  }
1007
1019
  } else {
1008
1020
  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({
1021
+ const u = l(c.supplyBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
1022
+ o.push({
1011
1023
  id: `${c.pool.uniqueId}_navi-lending-supply`,
1012
1024
  wallet: e,
1013
1025
  protocol: "navi",
1014
1026
  type: "navi-lending-supply",
1015
1027
  market: c.market,
1016
1028
  "navi-lending-supply": {
1017
- amount: s.toString(),
1029
+ amount: u.toString(),
1018
1030
  pool: c.pool,
1019
1031
  token: c.pool.token,
1020
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
1032
+ valueUSD: u.multipliedBy(c.pool.oracle.price).toString()
1021
1033
  }
1022
1034
  });
1023
1035
  }
1024
1036
  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({
1037
+ const u = l(c.borrowBalance).shiftedBy(-9).decimalPlaces(c.pool.token.decimals, l.ROUND_DOWN);
1038
+ o.push({
1027
1039
  id: `${c.pool.uniqueId}_navi-lending-borrow`,
1028
1040
  wallet: e,
1029
1041
  protocol: "navi",
1030
1042
  market: c.market,
1031
1043
  type: "navi-lending-borrow",
1032
1044
  "navi-lending-borrow": {
1033
- amount: s.toString(),
1045
+ amount: u.toString(),
1034
1046
  pool: c.pool,
1035
1047
  token: c.pool.token,
1036
- valueUSD: s.multipliedBy(c.pool.oracle.price).toString()
1048
+ valueUSD: u.multipliedBy(c.pool.oracle.price).toString()
1037
1049
  }
1038
1050
  });
1039
1051
  }
1040
1052
  }
1041
- }), n;
1053
+ }), o;
1042
1054
  }
1043
1055
  );
1044
- class it {
1045
- constructor(o) {
1056
+ class M {
1057
+ constructor(n) {
1046
1058
  this._positions = [], this._overview = {
1047
1059
  hf: 1 / 0,
1048
1060
  netVaule: "0",
@@ -1053,7 +1065,7 @@ class it {
1053
1065
  totalBorrowApy: "0",
1054
1066
  maxLiquidationValue: "0",
1055
1067
  maxLoanToVaule: "0"
1056
- }, this.positions = o;
1068
+ }, this.positions = n;
1057
1069
  }
1058
1070
  get positions() {
1059
1071
  return this._positions;
@@ -1061,23 +1073,31 @@ class it {
1061
1073
  get overview() {
1062
1074
  return this._overview;
1063
1075
  }
1064
- set positions(o) {
1065
- this._positions = o, this._overview = this.getPositionsOverview(o);
1076
+ set positions(n) {
1077
+ this._positions = n, this._overview = this.getPositionsOverview(n);
1078
+ }
1079
+ filterPositionsByPool(n) {
1080
+ const r = !!n.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
1081
+ return new M(this.positions.filter((t) => {
1082
+ const a = t[t.type];
1083
+ return r.includes(t.type) && a.pool.uniqueId === n.uniqueId;
1084
+ }));
1066
1085
  }
1067
- deposit(o, n) {
1068
- const r = !!o.isEMode;
1086
+ deposit(n, o) {
1087
+ const r = !!n.isEMode;
1069
1088
  let t;
1070
- r ? t = {
1089
+ return r ? t = {
1071
1090
  id: P(),
1072
1091
  wallet: "",
1073
1092
  protocol: "navi",
1074
1093
  market: "",
1075
1094
  type: "navi-lending-emode-supply",
1076
1095
  "navi-lending-emode-supply": {
1077
- amount: n.toString(),
1078
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1079
- token: o.token,
1080
- pool: o
1096
+ amount: o.toString(),
1097
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1098
+ token: n.token,
1099
+ pool: n,
1100
+ emodeCap: {}
1081
1101
  }
1082
1102
  } : t = {
1083
1103
  id: P(),
@@ -1086,27 +1106,28 @@ class it {
1086
1106
  market: "",
1087
1107
  type: "navi-lending-supply",
1088
1108
  "navi-lending-supply": {
1089
- amount: n.toString(),
1090
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1091
- token: o.token,
1092
- pool: o
1109
+ amount: o.toString(),
1110
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1111
+ token: n.token,
1112
+ pool: n
1093
1113
  }
1094
- }, this.positions = [...this.positions, t];
1114
+ }, new M([...this.positions, t]);
1095
1115
  }
1096
- withdraw(o, n) {
1097
- const r = !!o.isEMode;
1116
+ withdraw(n, o) {
1117
+ const r = !!n.isEMode;
1098
1118
  let t;
1099
- r ? t = {
1119
+ return r ? t = {
1100
1120
  id: P(),
1101
1121
  wallet: "",
1102
1122
  protocol: "navi",
1103
1123
  market: "",
1104
1124
  type: "navi-lending-emode-supply",
1105
1125
  "navi-lending-emode-supply": {
1106
- amount: (-n).toString(),
1107
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1108
- token: o.token,
1109
- pool: o
1126
+ amount: (-o).toString(),
1127
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1128
+ token: n.token,
1129
+ pool: n,
1130
+ emodeCap: {}
1110
1131
  }
1111
1132
  } : t = {
1112
1133
  id: P(),
@@ -1115,27 +1136,28 @@ class it {
1115
1136
  market: "",
1116
1137
  type: "navi-lending-supply",
1117
1138
  "navi-lending-supply": {
1118
- amount: (-n).toString(),
1119
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1120
- token: o.token,
1121
- pool: o
1139
+ amount: (-o).toString(),
1140
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1141
+ token: n.token,
1142
+ pool: n
1122
1143
  }
1123
- }, this.positions = [...this.positions, t];
1144
+ }, new M([...this.positions, t]);
1124
1145
  }
1125
- borrow(o, n) {
1126
- const r = !!o.isEMode;
1146
+ borrow(n, o) {
1147
+ const r = !!n.isEMode;
1127
1148
  let t;
1128
- r ? t = {
1149
+ return r ? t = {
1129
1150
  id: P(),
1130
1151
  wallet: "",
1131
1152
  protocol: "navi",
1132
1153
  market: "",
1133
1154
  type: "navi-lending-emode-borrow",
1134
1155
  "navi-lending-emode-borrow": {
1135
- amount: n.toString(),
1136
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1137
- token: o.token,
1138
- pool: o
1156
+ amount: o.toString(),
1157
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1158
+ token: n.token,
1159
+ pool: n,
1160
+ emodeCap: {}
1139
1161
  }
1140
1162
  } : t = {
1141
1163
  id: P(),
@@ -1144,27 +1166,28 @@ class it {
1144
1166
  market: "",
1145
1167
  type: "navi-lending-borrow",
1146
1168
  "navi-lending-borrow": {
1147
- amount: n.toString(),
1148
- valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1149
- token: o.token,
1150
- pool: o
1169
+ amount: o.toString(),
1170
+ valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1171
+ token: n.token,
1172
+ pool: n
1151
1173
  }
1152
- }, this.positions = [...this.positions, t];
1174
+ }, new M([...this.positions, t]);
1153
1175
  }
1154
- repay(o, n) {
1155
- const r = !!o.isEMode;
1176
+ repay(n, o) {
1177
+ const r = !!n.isEMode;
1156
1178
  let t;
1157
- r ? t = {
1179
+ return r ? t = {
1158
1180
  id: P(),
1159
1181
  wallet: "",
1160
1182
  protocol: "navi",
1161
1183
  market: "",
1162
1184
  type: "navi-lending-emode-borrow",
1163
1185
  "navi-lending-emode-borrow": {
1164
- amount: (-n).toString(),
1165
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1166
- token: o.token,
1167
- pool: o
1186
+ amount: (-o).toString(),
1187
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1188
+ token: n.token,
1189
+ pool: n,
1190
+ emodeCap: {}
1168
1191
  }
1169
1192
  } : t = {
1170
1193
  id: P(),
@@ -1173,70 +1196,64 @@ class it {
1173
1196
  market: "",
1174
1197
  type: "navi-lending-borrow",
1175
1198
  "navi-lending-borrow": {
1176
- amount: (-n).toString(),
1177
- valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1178
- token: o.token,
1179
- pool: o
1199
+ amount: (-o).toString(),
1200
+ valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1201
+ token: n.token,
1202
+ pool: n
1180
1203
  }
1181
- }, this.positions = [...this.positions, t];
1204
+ }, new M([...this.positions, t]);
1182
1205
  }
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"));
1186
- }
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)
1206
+ getPositionsOverview(n) {
1207
+ let o = new l(0), r = new l(0), t = new l(0), a = new l(0), i = new l(0), c = new l(0);
1208
+ n.forEach((d) => {
1209
+ if (d.type === "navi-lending-supply") {
1210
+ const g = d["navi-lending-supply"];
1211
+ o = o.plus(g.valueUSD), i = i.plus(
1212
+ new l(g.valueUSD).multipliedBy(g.pool.liquidationFactor.threshold)
1194
1213
  ), 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
1214
+ new l(g.valueUSD).multipliedBy(g.pool.ltvValue)
1204
1215
  );
1216
+ } else if (d.type === "navi-lending-borrow")
1217
+ r = r.plus(d["navi-lending-borrow"].valueUSD);
1218
+ else if (d.type === "navi-lending-emode-supply") {
1219
+ const g = d["navi-lending-emode-supply"];
1220
+ o = o.plus(g.valueUSD);
1221
+ const v = g.pool.emode;
1205
1222
  i = i.plus(
1206
- new l(d.valueUSD).multipliedBy(v.lt)
1223
+ new l(g.valueUSD).multipliedBy(v.lt)
1207
1224
  ), c = c.plus(
1208
- new l(d.valueUSD).multipliedBy(v.ltv)
1225
+ new l(g.valueUSD).multipliedBy(v.ltv)
1209
1226
  );
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;
1227
+ } else d.type === "navi-lending-emode-borrow" && (r = r.plus(d["navi-lending-emode-borrow"].valueUSD));
1228
+ }), n.forEach((d) => {
1229
+ if (d.type === "navi-lending-supply") {
1230
+ const g = d["navi-lending-supply"], v = g.pool.supplyIncentiveApyInfo.apy;
1214
1231
  t = t.plus(
1215
- new l(d.valueUSD).dividedBy(n).multipliedBy(new l(v).dividedBy(100))
1232
+ new l(g.valueUSD).dividedBy(o).multipliedBy(new l(v).dividedBy(100))
1216
1233
  );
1217
- } else if (m.type === "navi-lending-borrow") {
1218
- const d = m["navi-lending-borrow"], v = d.pool.borrowIncentiveApyInfo.apy;
1234
+ } else if (d.type === "navi-lending-borrow") {
1235
+ const g = d["navi-lending-borrow"], v = g.pool.borrowIncentiveApyInfo.apy;
1219
1236
  r.gt(0) && (a = a.plus(
1220
- new l(d.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1237
+ new l(g.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1221
1238
  ));
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))
1239
+ } else if (d.type === "navi-lending-emode-supply") {
1240
+ const g = d["navi-lending-emode-supply"], v = g.pool.supplyIncentiveApyInfo.apy;
1241
+ o.gt(0) && (t = t.plus(
1242
+ new l(g.valueUSD).dividedBy(o).multipliedBy(new l(v).dividedBy(100))
1226
1243
  ));
1227
- } else if (m.type === "navi-lending-emode-borrow") {
1228
- const d = m["navi-lending-emode-borrow"], v = d.pool.borrowIncentiveApyInfo.apy;
1244
+ } else if (d.type === "navi-lending-emode-borrow") {
1245
+ const g = d["navi-lending-emode-borrow"], v = g.pool.borrowIncentiveApyInfo.apy;
1229
1246
  r.gt(0) && (a = a.plus(
1230
- new l(d.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1247
+ new l(g.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1231
1248
  ));
1232
1249
  }
1233
1250
  });
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));
1251
+ 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
1252
  return {
1236
1253
  hf: r.toNumber() !== 0 ? i.dividedBy(r).toNumber() : 1 / 0,
1237
- netVaule: u.toString(),
1238
- netWorthApr: s.toString(),
1239
- totalSupplyValue: n.toString(),
1254
+ netVaule: s.toString(),
1255
+ netWorthApr: u.toString(),
1256
+ totalSupplyValue: o.toString(),
1240
1257
  totalBorrowValue: r.toString(),
1241
1258
  totalsupplyApy: t.toString(),
1242
1259
  totalBorrowApy: a.toString(),
@@ -1245,15 +1262,15 @@ class it {
1245
1262
  };
1246
1263
  }
1247
1264
  }
1248
- const x = new z("https://hermes.pyth.network", {
1265
+ const ee = new Y("https://hermes.pyth.network", {
1249
1266
  timeout: 1e4
1250
1267
  });
1251
- async function Ie(e) {
1268
+ async function Ae(e) {
1252
1269
  try {
1253
- const o = [], n = await x.getLatestPriceFeeds(e);
1254
- if (!n) return o;
1270
+ const n = [], o = await ee.getLatestPriceFeeds(e);
1271
+ if (!o) return n;
1255
1272
  const r = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1256
- for (const t of n) {
1273
+ for (const t of o) {
1257
1274
  const a = t.getPriceUnchecked();
1258
1275
  if (a.publishTime > r) {
1259
1276
  console.warn(
@@ -1263,43 +1280,43 @@ async function Ie(e) {
1263
1280
  }
1264
1281
  r - t.getPriceUnchecked().publishTime > 30 && (console.info(
1265
1282
  `stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`
1266
- ), o.push(t.id));
1283
+ ), n.push(t.id));
1267
1284
  }
1268
- return o;
1269
- } catch (o) {
1270
- throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`);
1285
+ return n;
1286
+ } catch (n) {
1287
+ throw new Error(`failed to get pyth stale price feed id, msg: ${n.message}`);
1271
1288
  }
1272
1289
  }
1273
- async function $e(e, o, n) {
1274
- const r = n?.client ?? $, t = await k({
1275
- ...n,
1290
+ async function $e(e, n, o) {
1291
+ const r = o?.client ?? $, t = await k({
1292
+ ...o,
1276
1293
  cacheTime: w
1277
1294
  });
1278
1295
  try {
1279
- const a = await x.getPriceFeedsUpdateData(o);
1280
- return await new ue(
1296
+ const a = await ee.getPriceFeedsUpdateData(n);
1297
+ return await new le(
1281
1298
  r,
1282
1299
  t.oracle.pythStateId,
1283
1300
  t.oracle.wormholeStateId
1284
- ).updatePriceFeeds(e, a, o);
1301
+ ).updatePriceFeeds(e, a, n);
1285
1302
  } catch (a) {
1286
1303
  throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
1287
1304
  }
1288
1305
  }
1289
- async function Se(e, o, n) {
1306
+ async function Se(e, n, o) {
1290
1307
  const r = await k({
1291
- ...n,
1308
+ ...o,
1292
1309
  cacheTime: w
1293
1310
  });
1294
- if (n?.updatePythPriceFeeds) {
1295
- const t = o.filter((a) => !!a.pythPriceFeedId).map((a) => a.pythPriceFeedId);
1311
+ if (o?.updatePythPriceFeeds) {
1312
+ const t = n.filter((a) => !!a.pythPriceFeedId).map((a) => a.pythPriceFeedId);
1296
1313
  try {
1297
- const a = await Ie(t);
1298
- a.length > 0 && await $e(e, a, n);
1314
+ const a = await Ae(t);
1315
+ a.length > 0 && await $e(e, a, o);
1299
1316
  } catch {
1300
1317
  }
1301
1318
  }
1302
- for (const t of o)
1319
+ for (const t of n)
1303
1320
  e.moveCall({
1304
1321
  target: `${r.oracle.packageId}::oracle_pro::update_single_price`,
1305
1322
  arguments: [
@@ -1319,34 +1336,34 @@ async function Se(e, o, n) {
1319
1336
  });
1320
1337
  return e;
1321
1338
  }
1322
- async function ee(e) {
1339
+ async function te(e) {
1323
1340
  return (await k({
1324
1341
  ...e,
1325
1342
  cacheTime: w
1326
1343
  })).oracle.feeds;
1327
1344
  }
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) => [
1345
+ function Pe(e, n) {
1346
+ return e.filter((o) => !!(n?.lendingState && n.lendingState.find((t) => t.assetId === o.assetId) || n?.lendingPositions && n.lendingPositions.find((t) => [
1330
1347
  "navi-lending-supply",
1331
1348
  "navi-lending-borrow",
1332
1349
  "navi-lending-emode-supply",
1333
1350
  "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)));
1351
+ ].includes(t.type) ? t[t.type]?.pool?.id === o.assetId : !1) || n?.pools && n.pools.find((t) => t.id === o.assetId)));
1335
1352
  }
1336
- async function st(e, o, n, r) {
1353
+ async function st(e, n, o, r) {
1337
1354
  try {
1338
- const t = await ee({
1355
+ const t = await te({
1339
1356
  ...r
1340
1357
  }), a = [];
1341
- n.forEach((s) => {
1342
- a.includes(s.market) || a.push(s.market);
1358
+ o.forEach((u) => {
1359
+ a.includes(u.market) || a.push(u.market);
1343
1360
  });
1344
- const i = await Ae(o, {
1361
+ const i = await Be(n, {
1345
1362
  ...r,
1346
1363
  markets: a
1347
1364
  }), c = Pe(t, {
1348
1365
  lendingPositions: i,
1349
- pools: n
1366
+ pools: o
1350
1367
  });
1351
1368
  return await Se(e, c, {
1352
1369
  updatePythPriceFeeds: !0,
@@ -1358,89 +1375,89 @@ async function st(e, o, n, r) {
1358
1375
  return console.error(t), e;
1359
1376
  }
1360
1377
  }
1361
- const F = I(
1362
- B(
1378
+ const L = A(
1379
+ I(
1363
1380
  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],
1381
+ const n = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${e?.env || "prod"}&sdk=${S.version}&market=${e?.market || D}`, o = await fetch(n, { headers: V }).then((r) => r.json());
1382
+ return Object.keys(o.data).map((r) => ({
1383
+ ...o.data[r],
1367
1384
  coinType: r
1368
1385
  }));
1369
1386
  }
1370
1387
  )
1371
1388
  );
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;
1389
+ async function ut(e, n) {
1390
+ 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
1391
  }
1375
- async function lt(e, o, n, r) {
1392
+ async function lt(e, n, o, r) {
1376
1393
  const t = await k({
1377
1394
  ...r,
1378
1395
  cacheTime: w
1379
- }), a = await A(o, r);
1380
- if (!(await F({
1396
+ }), a = await B(n, r);
1397
+ if (!(await L({
1381
1398
  ...r,
1382
1399
  cacheTime: w
1383
1400
  })).some(
1384
- (u) => b(u.coinType) === b(a.suiCoinType)
1401
+ (s) => b(s.coinType) === b(a.suiCoinType)
1385
1402
  ))
1386
1403
  throw new Error("Pool does not support flashloan");
1387
1404
  if (t.version === 1) {
1388
- const [u, s] = e.moveCall({
1405
+ const [s, u] = e.moveCall({
1389
1406
  target: `${t.package}::lending::flash_loan_with_ctx`,
1390
1407
  arguments: [
1391
1408
  e.object(t.flashloanConfig),
1392
1409
  e.object(a.contract.pool),
1393
- f(n, e.pure.u64)
1410
+ y(o, e.pure.u64)
1394
1411
  ],
1395
1412
  typeArguments: [a.suiCoinType]
1396
1413
  });
1397
- return [u, s];
1414
+ return [s, u];
1398
1415
  } else {
1399
- const [u, s] = e.moveCall({
1416
+ const [s, u] = e.moveCall({
1400
1417
  target: `${t.package}::lending::flash_loan_with_ctx_v2`,
1401
1418
  arguments: [
1402
1419
  e.object(t.flashloanConfig),
1403
1420
  e.object(a.contract.pool),
1404
- f(n, e.pure.u64),
1421
+ y(o, e.pure.u64),
1405
1422
  e.object("0x05")
1406
1423
  ],
1407
1424
  typeArguments: [a.suiCoinType]
1408
1425
  });
1409
- return [u, s];
1426
+ return [s, u];
1410
1427
  }
1411
1428
  }
1412
- async function pt(e, o, n, r, t) {
1429
+ async function pt(e, n, o, r, t) {
1413
1430
  const a = await k({
1414
1431
  ...t,
1415
1432
  cacheTime: w
1416
- }), i = await A(o, t);
1417
- if (!(await F({
1433
+ }), i = await B(n, t);
1434
+ if (!(await L({
1418
1435
  ...t,
1419
1436
  cacheTime: w
1420
1437
  })).some(
1421
- (g) => b(g.coinType) === b(i.suiCoinType)
1438
+ (m) => b(m.coinType) === b(i.suiCoinType)
1422
1439
  ))
1423
1440
  throw new Error("Pool does not support flashloan");
1424
- const [s] = e.moveCall({
1441
+ const [u] = e.moveCall({
1425
1442
  target: `${a.package}::lending::flash_repay_with_ctx`,
1426
1443
  arguments: [
1427
1444
  e.object("0x06"),
1428
1445
  e.object(a.storage),
1429
1446
  e.object(i.contract.pool),
1430
- f(n, e.object),
1431
- f(r, e.object)
1447
+ y(o, e.object),
1448
+ y(r, e.object)
1432
1449
  ],
1433
1450
  typeArguments: [i.suiCoinType]
1434
1451
  });
1435
- return [s];
1452
+ return [u];
1436
1453
  }
1437
- async function dt(e, o, n, r, t, a) {
1454
+ async function dt(e, n, o, r, t, a) {
1438
1455
  const i = {
1439
1456
  ...a,
1440
1457
  cacheTime: w
1441
- }, c = await k(i), u = await A(o, i), s = await A(r, i);
1458
+ }, c = await k(i), s = await B(n, i), u = await B(r, i);
1442
1459
  if (c.version === 1) {
1443
- const [g, m] = e.moveCall({
1460
+ const [m, d] = e.moveCall({
1444
1461
  target: `${c.package}::incentive_v3::liquidation`,
1445
1462
  arguments: [
1446
1463
  e.object("0x06"),
@@ -1449,28 +1466,28 @@ async function dt(e, o, n, r, t, a) {
1449
1466
  // Price oracle for asset pricing
1450
1467
  e.object(c.storage),
1451
1468
  // Protocol storage
1452
- e.pure.u8(u.id),
1469
+ e.pure.u8(s.id),
1453
1470
  // Pay asset ID
1454
- e.object(u.contract.pool),
1471
+ e.object(s.contract.pool),
1455
1472
  // Pay asset pool contract
1456
- f(n, e.object),
1473
+ y(o, e.object),
1457
1474
  // Debt repayment amount
1458
- e.pure.u8(s.id),
1475
+ e.pure.u8(u.id),
1459
1476
  // Collateral asset ID
1460
- e.object(s.contract.pool),
1477
+ e.object(u.contract.pool),
1461
1478
  // Collateral asset pool contract
1462
- f(t, e.pure.address),
1479
+ y(t, e.pure.address),
1463
1480
  // Borrower address
1464
1481
  e.object(c.incentiveV2),
1465
1482
  // Incentive V2 contract
1466
1483
  e.object(c.incentiveV3)
1467
1484
  // Incentive V3 contract
1468
1485
  ],
1469
- typeArguments: [u.suiCoinType, s.suiCoinType]
1486
+ typeArguments: [s.suiCoinType, u.suiCoinType]
1470
1487
  });
1471
- return [g, m];
1488
+ return [m, d];
1472
1489
  } else {
1473
- const [g, m] = e.moveCall({
1490
+ const [m, d] = e.moveCall({
1474
1491
  target: `${c.package}::incentive_v3::liquidation_v2`,
1475
1492
  arguments: [
1476
1493
  e.object("0x06"),
@@ -1479,17 +1496,17 @@ async function dt(e, o, n, r, t, a) {
1479
1496
  // Price oracle for asset pricing
1480
1497
  e.object(c.storage),
1481
1498
  // Protocol storage
1482
- e.pure.u8(u.id),
1499
+ e.pure.u8(s.id),
1483
1500
  // Pay asset ID
1484
- e.object(u.contract.pool),
1501
+ e.object(s.contract.pool),
1485
1502
  // Pay asset pool contract
1486
- f(n, e.object),
1503
+ y(o, e.object),
1487
1504
  // Debt repayment amount
1488
- e.pure.u8(s.id),
1505
+ e.pure.u8(u.id),
1489
1506
  // Collateral asset ID
1490
- e.object(s.contract.pool),
1507
+ e.object(u.contract.pool),
1491
1508
  // Collateral asset pool contract
1492
- f(t, e.pure.address),
1509
+ y(t, e.pure.address),
1493
1510
  // Borrower address
1494
1511
  e.object(c.incentiveV2),
1495
1512
  // Incentive V2 contract
@@ -1498,33 +1515,33 @@ async function dt(e, o, n, r, t, a) {
1498
1515
  e.object("0x05")
1499
1516
  // SuiSystemState object
1500
1517
  ],
1501
- typeArguments: [u.suiCoinType, s.suiCoinType]
1518
+ typeArguments: [s.suiCoinType, u.suiCoinType]
1502
1519
  });
1503
- return [g, m];
1520
+ return [m, d];
1504
1521
  }
1505
1522
  }
1506
- async function Ve(e, o, n) {
1507
- const r = n?.client ?? $, t = new U(), a = await N({
1508
- ...n,
1523
+ async function Ve(e, n, o) {
1524
+ const r = o?.client ?? $, t = new U(), a = await R({
1525
+ ...o,
1509
1526
  markets: Object.values(E),
1510
1527
  cacheTime: w
1511
- }), i = await ee(n);
1512
- for (let g of o) {
1513
- const m = await k({
1514
- ...n,
1528
+ }), i = await te(o);
1529
+ for (let m of n) {
1530
+ const d = await k({
1531
+ ...o,
1515
1532
  cacheTime: w,
1516
- market: g.market
1533
+ market: m.market
1517
1534
  });
1518
1535
  t.moveCall({
1519
- target: `${m.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
1536
+ target: `${d.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
1520
1537
  arguments: [
1521
1538
  t.object("0x06"),
1522
1539
  // Clock object
1523
- t.object(m.storage),
1540
+ t.object(d.storage),
1524
1541
  // Protocol storage
1525
- t.object(m.incentiveV3),
1542
+ t.object(d.incentiveV3),
1526
1543
  // Incentive V3 contract
1527
- t.pure.address(g.address)
1544
+ t.pure.address(m.address)
1528
1545
  // User address
1529
1546
  ]
1530
1547
  });
@@ -1532,60 +1549,60 @@ async function Ve(e, o, n) {
1532
1549
  const c = await r.devInspectTransactionBlock({
1533
1550
  transactionBlock: t,
1534
1551
  sender: e
1535
- }), u = [];
1536
- c?.results?.forEach((g) => {
1537
- u.push(
1552
+ }), s = [];
1553
+ c?.results?.forEach((m) => {
1554
+ s.push(
1538
1555
  O(
1539
1556
  {
1540
- results: [g]
1557
+ results: [m]
1541
1558
  },
1542
1559
  [
1543
- _.vector(_.string()),
1560
+ C.vector(C.string()),
1544
1561
  // Asset coin types
1545
- _.vector(_.string()),
1562
+ C.vector(C.string()),
1546
1563
  // Reward coin types
1547
- _.vector(_.u8()),
1564
+ C.vector(C.u8()),
1548
1565
  // Reward options
1549
- _.vector(_.Address),
1566
+ C.vector(C.Address),
1550
1567
  // Rule IDs
1551
- _.vector(_.u256())
1568
+ C.vector(C.u256())
1552
1569
  // Claimable amounts
1553
1570
  ]
1554
1571
  )
1555
1572
  );
1556
1573
  });
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;
1562
- for (let y = 0; y < v; y++) {
1574
+ const u = [];
1575
+ return s.forEach((m, d) => {
1576
+ const g = n[d];
1577
+ if (m.length === 5 && Array.isArray(m[0])) {
1578
+ const v = m[0].length;
1579
+ for (let f = 0; f < v; f++) {
1563
1580
  const h = i.find(
1564
- (T) => b(T.coinType) === b(g[1][y])
1565
- ), C = a.find(
1566
- (T) => b(T.coinType) === b(g[0][y])
1581
+ (T) => b(T.coinType) === b(m[1][f])
1582
+ ), _ = a.find(
1583
+ (T) => b(T.coinType) === b(m[0][f])
1567
1584
  );
1568
- !h || !C || s.push({
1569
- 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
1585
+ !h || !_ || u.push({
1586
+ assetId: _.id,
1587
+ assetCoinType: b(m[0][f]),
1588
+ rewardCoinType: b(m[1][f]),
1589
+ option: Number(m[2][f]),
1590
+ userClaimableReward: Number(m[4][f]) / Math.pow(10, h.priceDecimal),
1591
+ ruleIds: Array.isArray(m[3][f]) ? m[3][f] : [m[3][f]],
1592
+ market: g.market,
1593
+ owner: g.address,
1594
+ emodeId: g.emodeId
1578
1595
  });
1579
1596
  }
1580
1597
  }
1581
- }), s;
1598
+ }), u;
1582
1599
  }
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) => ({
1600
+ async function mt(e, n) {
1601
+ const o = (n?.markets || [E.main]).map((a) => j(a)), r = await X(e, n), t = o.map((a) => ({
1585
1602
  address: e,
1586
1603
  market: a.key
1587
1604
  })).concat(
1588
- r.filter((a) => !!n.find((i) => i.id === a.marketId)).map((a) => {
1605
+ r.filter((a) => !!o.find((i) => i.id === a.marketId)).map((a) => {
1589
1606
  const i = j(a.marketId);
1590
1607
  return {
1591
1608
  address: e,
@@ -1594,13 +1611,13 @@ async function mt(e, o) {
1594
1611
  };
1595
1612
  })
1596
1613
  );
1597
- return await Ve(e, t, o);
1614
+ return await Ve(e, t, n);
1598
1615
  }
1599
1616
  function gt(e) {
1600
- const o = /* @__PURE__ */ new Map();
1617
+ const n = /* @__PURE__ */ new Map();
1601
1618
  e.forEach((r) => {
1602
1619
  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, {
1620
+ n.has(i) ? n.get(i).total += r.userClaimableReward : n.set(i, {
1604
1621
  assetId: t,
1605
1622
  rewardType: a,
1606
1623
  coinType: r.rewardCoinType,
@@ -1608,14 +1625,14 @@ function gt(e) {
1608
1625
  market: r.market
1609
1626
  });
1610
1627
  });
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);
1628
+ const o = /* @__PURE__ */ new Map();
1629
+ for (const { assetId: r, rewardType: t, coinType: a, total: i, market: c } of n.values()) {
1630
+ const s = `${r}-${t}-${c}`;
1631
+ o.has(s) || o.set(s, { assetId: r, rewardType: t, market: c, rewards: /* @__PURE__ */ new Map() });
1632
+ const u = o.get(s);
1633
+ u.rewards.set(a, (u.rewards.get(a) || 0) + i);
1617
1634
  }
1618
- return Array.from(n.values()).map((r) => ({
1635
+ return Array.from(o.values()).map((r) => ({
1619
1636
  assetId: r.assetId,
1620
1637
  rewardType: r.rewardType,
1621
1638
  market: r.market,
@@ -1625,56 +1642,56 @@ function gt(e) {
1625
1642
  }))
1626
1643
  }));
1627
1644
  }
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;
1645
+ const yt = I(
1646
+ async (e, n) => {
1647
+ const o = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${S.version}&market=${n?.market || D}`;
1648
+ return (await fetch(o, { headers: V }).then((t) => t.json())).data;
1632
1649
  }
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({
1650
+ ), ft = I(
1651
+ async (e, n) => {
1652
+ const o = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${n?.page || 1}&pageSize=${n?.size || 400}&sdk=${S.version}&market=${n?.market || D}`, r = await fetch(o, { headers: V }).then((t) => t.json());
1653
+ return F({
1637
1654
  data: r.data.rewards
1638
1655
  });
1639
1656
  }
1640
1657
  );
1641
- async function vt(e, o, n) {
1658
+ async function vt(e, n, o) {
1642
1659
  const r = await k({
1643
- ...n,
1660
+ ...o,
1644
1661
  cacheTime: w
1645
- }), t = await N({
1646
- ...n,
1662
+ }), t = await R({
1663
+ ...o,
1647
1664
  markets: Object.values(E),
1648
1665
  cacheTime: w
1649
1666
  }), 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) {
1667
+ for (const c of n) {
1668
+ const { rewardCoinType: s, ruleIds: u, market: m, owner: d, emodeId: g } = c, v = `${s}-${m}-${d}`;
1669
+ for (const f of u) {
1653
1670
  a.has(v) || a.set(v, {
1654
1671
  assetIds: [],
1655
1672
  ruleIds: [],
1656
1673
  amount: 0,
1657
- market: g,
1658
- owner: m,
1659
- isEMode: typeof d < "u"
1674
+ market: m,
1675
+ owner: d,
1676
+ isEMode: typeof g < "u"
1660
1677
  });
1661
1678
  const h = a.get(v);
1662
- h.assetIds.push(c.assetCoinType.replace("0x", "")), h.ruleIds.push(y), h.amount += c.userClaimableReward;
1679
+ h.assetIds.push(c.assetCoinType.replace("0x", "")), h.ruleIds.push(f), h.amount += c.userClaimableReward;
1663
1680
  }
1664
1681
  }
1665
1682
  const i = [];
1666
- for (const [c, { assetIds: u, ruleIds: s, amount: g, market: m, owner: d, isEMode: v }] of a) {
1667
- const y = t.find(
1668
- (C) => b(C.suiCoinType) === b(c) && C.market === m
1683
+ for (const [c, { assetIds: s, ruleIds: u, amount: m, market: d, owner: g, isEMode: v }] of a) {
1684
+ const f = t.find(
1685
+ (_) => b(_.suiCoinType) === b(c) && _.market === d
1669
1686
  );
1670
- if (!y || !y.contract.rewardFundId)
1671
- throw new Error(`No matching rewardFund found for reward coin: ${c} ${m}`);
1672
- const h = y.contract.rewardFundId;
1673
- if (n?.accountCap && !n.customCoinReceive)
1687
+ if (!f || !f.contract.rewardFundId)
1688
+ throw new Error(`No matching rewardFund found for reward coin: ${c} ${d}`);
1689
+ const h = f.contract.rewardFundId;
1690
+ if (o?.accountCap && !o.customCoinReceive)
1674
1691
  throw new Error("customCoinReceive is required when accountCap is provided");
1675
- if (n?.customCoinReceive) {
1676
- let C;
1677
- n.accountCap ? C = e.moveCall({
1692
+ if (o?.customCoinReceive) {
1693
+ let _;
1694
+ o.accountCap ? _ = e.moveCall({
1678
1695
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1679
1696
  arguments: [
1680
1697
  e.object("0x06"),
@@ -1685,15 +1702,15 @@ async function vt(e, o, n) {
1685
1702
  // Protocol storage
1686
1703
  e.object(h),
1687
1704
  // Reward fund
1688
- e.pure.vector("string", u),
1705
+ e.pure.vector("string", s),
1689
1706
  // Asset IDs
1690
- e.pure.vector("address", s),
1707
+ e.pure.vector("address", u),
1691
1708
  // Rule IDs
1692
- f(n.accountCap, e.object)
1709
+ y(o.accountCap, e.object)
1693
1710
  // Account capability
1694
1711
  ],
1695
1712
  typeArguments: [c]
1696
- }) : v ? C = e.moveCall({
1713
+ }) : v ? _ = e.moveCall({
1697
1714
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1698
1715
  arguments: [
1699
1716
  e.object("0x06"),
@@ -1704,15 +1721,15 @@ async function vt(e, o, n) {
1704
1721
  // Protocol storage
1705
1722
  e.object(h),
1706
1723
  // Reward fund
1707
- e.pure.vector("string", u),
1724
+ e.pure.vector("string", s),
1708
1725
  // Asset IDs
1709
- e.pure.vector("address", s),
1726
+ e.pure.vector("address", u),
1710
1727
  // Rule IDs
1711
- f(d, e.object)
1728
+ y(g, e.object)
1712
1729
  // Account capability
1713
1730
  ],
1714
1731
  typeArguments: [c]
1715
- }) : C = e.moveCall({
1732
+ }) : _ = e.moveCall({
1716
1733
  target: `${r.package}::incentive_v3::claim_reward`,
1717
1734
  arguments: [
1718
1735
  e.object("0x06"),
@@ -1723,41 +1740,41 @@ async function vt(e, o, n) {
1723
1740
  // Protocol storage
1724
1741
  e.object(h),
1725
1742
  // Reward fund
1726
- e.pure.vector("string", u),
1743
+ e.pure.vector("string", s),
1727
1744
  // Asset IDs
1728
- e.pure.vector("address", s)
1745
+ e.pure.vector("address", u)
1729
1746
  // Rule IDs
1730
1747
  ],
1731
1748
  typeArguments: [c]
1732
1749
  });
1733
1750
  const [T] = e.moveCall({
1734
1751
  target: "0x2::coin::from_balance",
1735
- arguments: [C],
1752
+ arguments: [_],
1736
1753
  typeArguments: [c]
1737
1754
  });
1738
- if (n?.customCoinReceive.type === "transfer") {
1739
- if (!n.customCoinReceive.transfer)
1755
+ if (o?.customCoinReceive.type === "transfer") {
1756
+ if (!o.customCoinReceive.transfer)
1740
1757
  throw new Error("customCoinReceive.transfer is required");
1741
1758
  e.transferObjects(
1742
1759
  [T],
1743
- f(n.customCoinReceive.transfer, e.pure.address)
1760
+ y(o.customCoinReceive.transfer, e.pure.address)
1744
1761
  );
1745
1762
  }
1746
- if (n?.customCoinReceive.type === "depositNAVI") {
1747
- 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(
1763
+ if (o?.customCoinReceive.type === "depositNAVI") {
1764
+ const oe = l(f.totalSupplyAmount).shiftedBy(-9), ne = l(f.supplyCapCeiling).shiftedBy(-27);
1765
+ oe.plus(m).isGreaterThan(ne) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
1749
1766
  [T],
1750
- e.pure.address(n.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1751
- ) : await he(e, y, T, n);
1767
+ e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1768
+ ) : await be(e, f, T, o);
1752
1769
  } else
1753
1770
  i.push({
1754
1771
  coin: T,
1755
- identifier: y,
1756
- owner: d,
1772
+ identifier: f,
1773
+ owner: g,
1757
1774
  isEMode: v
1758
1775
  });
1759
- } else if (n?.accountCap || v) {
1760
- const C = e.moveCall({
1776
+ } else if (o?.accountCap || v) {
1777
+ const _ = e.moveCall({
1761
1778
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1762
1779
  arguments: [
1763
1780
  e.object("0x06"),
@@ -1768,22 +1785,22 @@ async function vt(e, o, n) {
1768
1785
  // Protocol storage
1769
1786
  e.object(h),
1770
1787
  // Reward fund
1771
- e.pure.vector("string", u),
1788
+ e.pure.vector("string", s),
1772
1789
  // Asset IDs
1773
- e.pure.vector("address", s),
1790
+ e.pure.vector("address", u),
1774
1791
  // Rule IDs
1775
- f(n?.accountCap || d, e.object)
1792
+ y(o?.accountCap || g, e.object)
1776
1793
  // Account capability
1777
1794
  ],
1778
1795
  typeArguments: [c]
1779
1796
  }), [T] = e.moveCall({
1780
1797
  target: "0x2::coin::from_balance",
1781
- arguments: [C],
1798
+ arguments: [_],
1782
1799
  typeArguments: [c]
1783
1800
  });
1784
1801
  e.transferObjects(
1785
1802
  [T],
1786
- f(n?.accountCap || d, e.pure.address)
1803
+ y(o?.accountCap || g, e.pure.address)
1787
1804
  );
1788
1805
  } else
1789
1806
  e.moveCall({
@@ -1797,9 +1814,9 @@ async function vt(e, o, n) {
1797
1814
  // Protocol storage
1798
1815
  e.object(h),
1799
1816
  // Reward fund
1800
- e.pure.vector("string", u),
1817
+ e.pure.vector("string", s),
1801
1818
  // Asset IDs
1802
- e.pure.vector("address", s)
1819
+ e.pure.vector("address", u)
1803
1820
  // Rule IDs
1804
1821
  ],
1805
1822
  typeArguments: [c]
@@ -1808,69 +1825,69 @@ async function vt(e, o, n) {
1808
1825
  return i;
1809
1826
  }
1810
1827
  export {
1811
- L as Address,
1828
+ W as Address,
1812
1829
  w as DEFAULT_CACHE_TIME,
1813
- M as DEFAULT_MARKET_IDENTITY,
1830
+ D as DEFAULT_MARKET_IDENTITY,
1814
1831
  He as FlashLoanAssetConfig,
1815
- Le as IncentiveAPYInfo,
1816
- le as IncentivePoolInfo,
1817
- qe as IncentivePoolInfoByPhase,
1832
+ qe as IncentiveAPYInfo,
1833
+ pe as IncentivePoolInfo,
1834
+ Le as IncentivePoolInfoByPhase,
1818
1835
  E as MARKETS,
1819
- je as Market,
1836
+ ke as Market,
1820
1837
  We as OracleInfo,
1821
- D as PoolOperator,
1838
+ N as PoolOperator,
1822
1839
  Ge as ReserveDataInfo,
1823
- it as UserPositions,
1824
- pe as UserStateInfo,
1840
+ M as UserPositions,
1841
+ de as UserStateInfo,
1825
1842
  Je as borrowCoinPTB,
1826
1843
  vt as claimLendingRewardsPTB,
1827
- be as createAccountCapPTB,
1828
- xe as createEModeCapPTB,
1829
- he as depositCoinPTB,
1830
- Ce as emodeIdentityId,
1831
- _e as enterEModePTB,
1832
- Ze as exitEModePTB,
1844
+ _e as createAccountCapPTB,
1845
+ et as createEModeCapPTB,
1846
+ be as depositCoinPTB,
1847
+ tt as emodeIdentityId,
1848
+ Te as enterEModePTB,
1849
+ xe as exitEModePTB,
1833
1850
  Pe as filterPriceFeeds,
1834
1851
  lt as flashloanPTB,
1835
- ke as getAccountCapOwnerPTB,
1836
- F as getAllFlashLoanAssets,
1852
+ je as getAccountCapOwnerPTB,
1853
+ L as getAllFlashLoanAssets,
1837
1854
  Xe as getBorrowFee,
1838
- ct as getCoins,
1855
+ it as getCoins,
1839
1856
  k as getConfig,
1840
1857
  Ke as getFees,
1841
1858
  ut as getFlashLoanAsset,
1842
- nt as getHealthFactor,
1843
- Be as getHealthFactorPTB,
1844
- Ae as getLendingPositions,
1845
- ot as getLendingState,
1846
- et as getMarket,
1859
+ rt as getHealthFactor,
1860
+ Ie as getHealthFactorPTB,
1861
+ Be as getLendingPositions,
1862
+ nt as getLendingState,
1863
+ Ze as getMarket,
1847
1864
  j as getMarketConfig,
1848
- Te as getMarkets,
1849
- A as getPool,
1850
- N as getPools,
1851
- ee as getPriceFeeds,
1852
- Ie as getPythStalePriceFeedId,
1853
- rt as getSimulatedHealthFactor,
1854
- X as getSimulatedHealthFactorPTB,
1865
+ Ce as getMarkets,
1866
+ B as getPool,
1867
+ R as getPools,
1868
+ te as getPriceFeeds,
1869
+ Ae as getPythStalePriceFeedId,
1870
+ at as getSimulatedHealthFactor,
1871
+ Z as getSimulatedHealthFactorPTB,
1855
1872
  ze as getStats,
1856
- at as getTransactions,
1873
+ ct as getTransactions,
1857
1874
  mt as getUserAvailableLendingRewards,
1858
- yt as getUserClaimedRewardHistory,
1859
- Q as getUserEModeCaps,
1860
- ft as getUserTotalClaimedReward,
1875
+ ft as getUserClaimedRewardHistory,
1876
+ X as getUserEModeCaps,
1877
+ yt as getUserTotalClaimedReward,
1861
1878
  dt as liquidatePTB,
1862
- tt as mergeCoinsPTB,
1879
+ ot as mergeCoinsPTB,
1863
1880
  b as normalizeCoinType,
1864
- we as parsePoolUID,
1865
- f as parseTxValue,
1881
+ he as parsePoolUID,
1882
+ y as parseTxValue,
1866
1883
  Qe as repayCoinPTB,
1867
1884
  pt as repayFlashLoanPTB,
1868
1885
  gt as summaryLendingRewards,
1869
1886
  st as updateOraclePriceBeforeUserOperationPTB,
1870
1887
  Se as updateOraclePricesPTB,
1871
1888
  $e as updatePythPriceFeeds,
1872
- I as withCache,
1873
- B as withSingleton,
1889
+ A as withCache,
1890
+ I as withSingleton,
1874
1891
  Ye as withdrawCoinPTB
1875
1892
  };
1876
1893
  //# sourceMappingURL=index.esm.js.map