@naviprotocol/lending 1.4.0-emode.16 → 1.4.0-emode.17

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