@naviprotocol/lending 1.4.0-emode.15 → 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.15", 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,18 +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
- 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
- }));
1081
+ filterPositionsByPool(o) {
1082
+ const r = !!o.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
1083
+ return new M(
1084
+ this.positions.filter((t) => {
1085
+ const a = t[t.type];
1086
+ return r.includes(t.type) && a.pool.uniqueId === o.uniqueId;
1087
+ })
1088
+ );
1085
1089
  }
1086
- deposit(n, o) {
1087
- const r = !!n.isEMode;
1090
+ deposit(o, n) {
1091
+ const r = !!o.isEMode;
1088
1092
  let t;
1089
1093
  return r ? t = {
1090
1094
  id: P(),
@@ -1093,10 +1097,10 @@ class M {
1093
1097
  market: "",
1094
1098
  type: "navi-lending-emode-supply",
1095
1099
  "navi-lending-emode-supply": {
1096
- amount: o.toString(),
1097
- valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1098
- token: n.token,
1099
- pool: n,
1100
+ amount: n.toString(),
1101
+ valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1102
+ token: o.token,
1103
+ pool: o,
1100
1104
  emodeCap: {}
1101
1105
  }
1102
1106
  } : t = {
@@ -1106,15 +1110,15 @@ class M {
1106
1110
  market: "",
1107
1111
  type: "navi-lending-supply",
1108
1112
  "navi-lending-supply": {
1109
- amount: o.toString(),
1110
- valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1111
- token: n.token,
1112
- pool: n
1113
+ amount: n.toString(),
1114
+ valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1115
+ token: o.token,
1116
+ pool: o
1113
1117
  }
1114
1118
  }, new M([...this.positions, t]);
1115
1119
  }
1116
- withdraw(n, o) {
1117
- const r = !!n.isEMode;
1120
+ withdraw(o, n) {
1121
+ const r = !!o.isEMode;
1118
1122
  let t;
1119
1123
  return r ? t = {
1120
1124
  id: P(),
@@ -1123,10 +1127,10 @@ class M {
1123
1127
  market: "",
1124
1128
  type: "navi-lending-emode-supply",
1125
1129
  "navi-lending-emode-supply": {
1126
- amount: (-o).toString(),
1127
- valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1128
- token: n.token,
1129
- pool: n,
1130
+ amount: (-n).toString(),
1131
+ valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1132
+ token: o.token,
1133
+ pool: o,
1130
1134
  emodeCap: {}
1131
1135
  }
1132
1136
  } : t = {
@@ -1136,15 +1140,15 @@ class M {
1136
1140
  market: "",
1137
1141
  type: "navi-lending-supply",
1138
1142
  "navi-lending-supply": {
1139
- amount: (-o).toString(),
1140
- valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1141
- token: n.token,
1142
- pool: n
1143
+ amount: (-n).toString(),
1144
+ valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1145
+ token: o.token,
1146
+ pool: o
1143
1147
  }
1144
1148
  }, new M([...this.positions, t]);
1145
1149
  }
1146
- borrow(n, o) {
1147
- const r = !!n.isEMode;
1150
+ borrow(o, n) {
1151
+ const r = !!o.isEMode;
1148
1152
  let t;
1149
1153
  return r ? t = {
1150
1154
  id: P(),
@@ -1153,10 +1157,10 @@ class M {
1153
1157
  market: "",
1154
1158
  type: "navi-lending-emode-borrow",
1155
1159
  "navi-lending-emode-borrow": {
1156
- amount: o.toString(),
1157
- valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1158
- token: n.token,
1159
- pool: n,
1160
+ amount: n.toString(),
1161
+ valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1162
+ token: o.token,
1163
+ pool: o,
1160
1164
  emodeCap: {}
1161
1165
  }
1162
1166
  } : t = {
@@ -1166,15 +1170,15 @@ class M {
1166
1170
  market: "",
1167
1171
  type: "navi-lending-borrow",
1168
1172
  "navi-lending-borrow": {
1169
- amount: o.toString(),
1170
- valueUSD: l(o).multipliedBy(n.oracle.price).toString(),
1171
- token: n.token,
1172
- pool: n
1173
+ amount: n.toString(),
1174
+ valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
1175
+ token: o.token,
1176
+ pool: o
1173
1177
  }
1174
1178
  }, new M([...this.positions, t]);
1175
1179
  }
1176
- repay(n, o) {
1177
- const r = !!n.isEMode;
1180
+ repay(o, n) {
1181
+ const r = !!o.isEMode;
1178
1182
  let t;
1179
1183
  return r ? t = {
1180
1184
  id: P(),
@@ -1183,10 +1187,10 @@ class M {
1183
1187
  market: "",
1184
1188
  type: "navi-lending-emode-borrow",
1185
1189
  "navi-lending-emode-borrow": {
1186
- amount: (-o).toString(),
1187
- valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1188
- token: n.token,
1189
- pool: n,
1190
+ amount: (-n).toString(),
1191
+ valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1192
+ token: o.token,
1193
+ pool: o,
1190
1194
  emodeCap: {}
1191
1195
  }
1192
1196
  } : t = {
@@ -1196,69 +1200,72 @@ class M {
1196
1200
  market: "",
1197
1201
  type: "navi-lending-borrow",
1198
1202
  "navi-lending-borrow": {
1199
- amount: (-o).toString(),
1200
- valueUSD: l(-o).multipliedBy(n.oracle.price).toString(),
1201
- token: n.token,
1202
- pool: n
1203
+ amount: (-n).toString(),
1204
+ valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
1205
+ token: o.token,
1206
+ pool: o
1203
1207
  }
1204
1208
  }, new M([...this.positions, t]);
1205
1209
  }
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)
1213
- ), c = c.plus(
1214
- new l(g.valueUSD).multipliedBy(g.pool.ltvValue)
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)
1215
1220
  );
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;
1222
- i = i.plus(
1223
- new l(g.valueUSD).multipliedBy(v.lt)
1224
- ), c = c.plus(
1225
- new l(g.valueUSD).multipliedBy(v.ltv)
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)
1226
1231
  );
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;
1231
- t = t.plus(
1232
- new l(g.valueUSD).dividedBy(o).multipliedBy(new l(v).dividedBy(100))
1233
- );
1234
- } else if (d.type === "navi-lending-borrow") {
1235
- const g = d["navi-lending-borrow"], v = g.pool.borrowIncentiveApyInfo.apy;
1236
- r.gt(0) && (a = a.plus(
1237
- new l(g.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1238
- ));
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))
1243
- ));
1244
- } else if (d.type === "navi-lending-emode-borrow") {
1245
- const g = d["navi-lending-emode-borrow"], v = g.pool.borrowIncentiveApyInfo.apy;
1246
- r.gt(0) && (a = a.plus(
1247
- new l(g.valueUSD).dividedBy(r).multipliedBy(new l(v).dividedBy(100))
1248
- ));
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();
1249
1254
  }
1250
1255
  });
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));
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));
1252
1257
  return {
1253
- hf: r.toNumber() !== 0 ? i.dividedBy(r).toNumber() : 1 / 0,
1254
- netVaule: s.toString(),
1255
- netWorthApr: u.toString(),
1256
- totalSupplyValue: o.toString(),
1257
- totalBorrowValue: r.toString(),
1258
- totalsupplyApy: t.toString(),
1259
- totalBorrowApy: a.toString(),
1260
- maxLiquidationValue: i.toString(),
1261
- 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
1262
1269
  };
1263
1270
  }
1264
1271
  }
@@ -1267,10 +1274,10 @@ const ee = new Y("https://hermes.pyth.network", {
1267
1274
  });
1268
1275
  async function Ae(e) {
1269
1276
  try {
1270
- const n = [], o = await ee.getLatestPriceFeeds(e);
1271
- if (!o) return n;
1277
+ const o = [], n = await ee.getLatestPriceFeeds(e);
1278
+ if (!n) return o;
1272
1279
  const r = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
1273
- for (const t of o) {
1280
+ for (const t of n) {
1274
1281
  const a = t.getPriceUnchecked();
1275
1282
  if (a.publishTime > r) {
1276
1283
  console.warn(
@@ -1280,43 +1287,43 @@ async function Ae(e) {
1280
1287
  }
1281
1288
  r - t.getPriceUnchecked().publishTime > 30 && (console.info(
1282
1289
  `stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`
1283
- ), n.push(t.id));
1290
+ ), o.push(t.id));
1284
1291
  }
1285
- return n;
1286
- } catch (n) {
1287
- 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}`);
1288
1295
  }
1289
1296
  }
1290
- async function $e(e, n, o) {
1291
- const r = o?.client ?? $, t = await k({
1292
- ...o,
1293
- cacheTime: w
1297
+ async function Se(e, o, n) {
1298
+ const r = n?.client ?? S, t = await k({
1299
+ ...n,
1300
+ cacheTime: h
1294
1301
  });
1295
1302
  try {
1296
- const a = await ee.getPriceFeedsUpdateData(n);
1303
+ const a = await ee.getPriceFeedsUpdateData(o);
1297
1304
  return await new le(
1298
1305
  r,
1299
1306
  t.oracle.pythStateId,
1300
1307
  t.oracle.wormholeStateId
1301
- ).updatePriceFeeds(e, a, n);
1308
+ ).updatePriceFeeds(e, a, o);
1302
1309
  } catch (a) {
1303
1310
  throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
1304
1311
  }
1305
1312
  }
1306
- async function Se(e, n, o) {
1313
+ async function $e(e, o, n) {
1307
1314
  const r = await k({
1308
- ...o,
1309
- cacheTime: w
1315
+ ...n,
1316
+ cacheTime: h
1310
1317
  });
1311
- if (o?.updatePythPriceFeeds) {
1312
- 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);
1313
1320
  try {
1314
1321
  const a = await Ae(t);
1315
- a.length > 0 && await $e(e, a, o);
1322
+ a.length > 0 && await Se(e, a, n);
1316
1323
  } catch {
1317
1324
  }
1318
1325
  }
1319
- for (const t of n)
1326
+ for (const t of o)
1320
1327
  e.moveCall({
1321
1328
  target: `${r.oracle.packageId}::oracle_pro::update_single_price`,
1322
1329
  arguments: [
@@ -1339,33 +1346,33 @@ async function Se(e, n, o) {
1339
1346
  async function te(e) {
1340
1347
  return (await k({
1341
1348
  ...e,
1342
- cacheTime: w
1349
+ cacheTime: h
1343
1350
  })).oracle.feeds;
1344
1351
  }
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) => [
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) => [
1347
1354
  "navi-lending-supply",
1348
1355
  "navi-lending-borrow",
1349
1356
  "navi-lending-emode-supply",
1350
1357
  "navi-lending-emode-borrow"
1351
- ].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)));
1352
1359
  }
1353
- async function st(e, n, o, r) {
1360
+ async function st(e, o, n, r) {
1354
1361
  try {
1355
1362
  const t = await te({
1356
1363
  ...r
1357
1364
  }), a = [];
1358
- o.forEach((u) => {
1365
+ n.forEach((u) => {
1359
1366
  a.includes(u.market) || a.push(u.market);
1360
1367
  });
1361
- const i = await Be(n, {
1368
+ const c = await Be(o, {
1362
1369
  ...r,
1363
1370
  markets: a
1364
- }), c = Pe(t, {
1365
- lendingPositions: i,
1366
- pools: o
1371
+ }), i = Pe(t, {
1372
+ lendingPositions: c,
1373
+ pools: n
1367
1374
  });
1368
- return await Se(e, c, {
1375
+ return await $e(e, i, {
1369
1376
  updatePythPriceFeeds: !0,
1370
1377
  ...r
1371
1378
  });
@@ -1378,25 +1385,25 @@ async function st(e, n, o, r) {
1378
1385
  const L = A(
1379
1386
  I(
1380
1387
  async (e) => {
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],
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],
1384
1391
  coinType: r
1385
1392
  }));
1386
1393
  }
1387
1394
  )
1388
1395
  );
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;
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;
1391
1398
  }
1392
- async function lt(e, n, o, r) {
1399
+ async function lt(e, o, n, r) {
1393
1400
  const t = await k({
1394
1401
  ...r,
1395
- cacheTime: w
1396
- }), a = await B(n, r);
1402
+ cacheTime: h
1403
+ }), a = await B(o, r);
1397
1404
  if (!(await L({
1398
1405
  ...r,
1399
- cacheTime: w
1406
+ cacheTime: h
1400
1407
  })).some(
1401
1408
  (s) => b(s.coinType) === b(a.suiCoinType)
1402
1409
  ))
@@ -1407,7 +1414,7 @@ async function lt(e, n, o, r) {
1407
1414
  arguments: [
1408
1415
  e.object(t.flashloanConfig),
1409
1416
  e.object(a.contract.pool),
1410
- y(o, e.pure.u64)
1417
+ y(n, e.pure.u64)
1411
1418
  ],
1412
1419
  typeArguments: [a.suiCoinType]
1413
1420
  });
@@ -1418,7 +1425,7 @@ async function lt(e, n, o, r) {
1418
1425
  arguments: [
1419
1426
  e.object(t.flashloanConfig),
1420
1427
  e.object(a.contract.pool),
1421
- y(o, e.pure.u64),
1428
+ y(n, e.pure.u64),
1422
1429
  e.object("0x05")
1423
1430
  ],
1424
1431
  typeArguments: [a.suiCoinType]
@@ -1426,16 +1433,16 @@ async function lt(e, n, o, r) {
1426
1433
  return [s, u];
1427
1434
  }
1428
1435
  }
1429
- async function pt(e, n, o, r, t) {
1436
+ async function pt(e, o, n, r, t) {
1430
1437
  const a = await k({
1431
1438
  ...t,
1432
- cacheTime: w
1433
- }), i = await B(n, t);
1439
+ cacheTime: h
1440
+ }), c = await B(o, t);
1434
1441
  if (!(await L({
1435
1442
  ...t,
1436
- cacheTime: w
1443
+ cacheTime: h
1437
1444
  })).some(
1438
- (m) => b(m.coinType) === b(i.suiCoinType)
1445
+ (m) => b(m.coinType) === b(c.suiCoinType)
1439
1446
  ))
1440
1447
  throw new Error("Pool does not support flashloan");
1441
1448
  const [u] = e.moveCall({
@@ -1443,34 +1450,34 @@ async function pt(e, n, o, r, t) {
1443
1450
  arguments: [
1444
1451
  e.object("0x06"),
1445
1452
  e.object(a.storage),
1446
- e.object(i.contract.pool),
1447
- y(o, e.object),
1453
+ e.object(c.contract.pool),
1454
+ y(n, e.object),
1448
1455
  y(r, e.object)
1449
1456
  ],
1450
- typeArguments: [i.suiCoinType]
1457
+ typeArguments: [c.suiCoinType]
1451
1458
  });
1452
1459
  return [u];
1453
1460
  }
1454
- async function dt(e, n, o, r, t, a) {
1455
- const i = {
1461
+ async function dt(e, o, n, r, t, a) {
1462
+ const c = {
1456
1463
  ...a,
1457
- cacheTime: w
1458
- }, c = await k(i), s = await B(n, i), u = await B(r, i);
1459
- if (c.version === 1) {
1460
- const [m, d] = e.moveCall({
1461
- 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`,
1462
1469
  arguments: [
1463
1470
  e.object("0x06"),
1464
1471
  // Clock object
1465
- e.object(c.priceOracle),
1472
+ e.object(i.priceOracle),
1466
1473
  // Price oracle for asset pricing
1467
- e.object(c.storage),
1474
+ e.object(i.storage),
1468
1475
  // Protocol storage
1469
1476
  e.pure.u8(s.id),
1470
1477
  // Pay asset ID
1471
1478
  e.object(s.contract.pool),
1472
1479
  // Pay asset pool contract
1473
- y(o, e.object),
1480
+ y(n, e.object),
1474
1481
  // Debt repayment amount
1475
1482
  e.pure.u8(u.id),
1476
1483
  // Collateral asset ID
@@ -1478,29 +1485,29 @@ async function dt(e, n, o, r, t, a) {
1478
1485
  // Collateral asset pool contract
1479
1486
  y(t, e.pure.address),
1480
1487
  // Borrower address
1481
- e.object(c.incentiveV2),
1488
+ e.object(i.incentiveV2),
1482
1489
  // Incentive V2 contract
1483
- e.object(c.incentiveV3)
1490
+ e.object(i.incentiveV3)
1484
1491
  // Incentive V3 contract
1485
1492
  ],
1486
1493
  typeArguments: [s.suiCoinType, u.suiCoinType]
1487
1494
  });
1488
- return [m, d];
1495
+ return [m, g];
1489
1496
  } else {
1490
- const [m, d] = e.moveCall({
1491
- target: `${c.package}::incentive_v3::liquidation_v2`,
1497
+ const [m, g] = e.moveCall({
1498
+ target: `${i.package}::incentive_v3::liquidation_v2`,
1492
1499
  arguments: [
1493
1500
  e.object("0x06"),
1494
1501
  // Clock object
1495
- e.object(c.priceOracle),
1502
+ e.object(i.priceOracle),
1496
1503
  // Price oracle for asset pricing
1497
- e.object(c.storage),
1504
+ e.object(i.storage),
1498
1505
  // Protocol storage
1499
1506
  e.pure.u8(s.id),
1500
1507
  // Pay asset ID
1501
1508
  e.object(s.contract.pool),
1502
1509
  // Pay asset pool contract
1503
- y(o, e.object),
1510
+ y(n, e.object),
1504
1511
  // Debt repayment amount
1505
1512
  e.pure.u8(u.id),
1506
1513
  // Collateral asset ID
@@ -1508,49 +1515,49 @@ async function dt(e, n, o, r, t, a) {
1508
1515
  // Collateral asset pool contract
1509
1516
  y(t, e.pure.address),
1510
1517
  // Borrower address
1511
- e.object(c.incentiveV2),
1518
+ e.object(i.incentiveV2),
1512
1519
  // Incentive V2 contract
1513
- e.object(c.incentiveV3),
1520
+ e.object(i.incentiveV3),
1514
1521
  // Incentive V3 contract
1515
1522
  e.object("0x05")
1516
1523
  // SuiSystemState object
1517
1524
  ],
1518
1525
  typeArguments: [s.suiCoinType, u.suiCoinType]
1519
1526
  });
1520
- return [m, d];
1527
+ return [m, g];
1521
1528
  }
1522
1529
  }
1523
- async function Ve(e, n, o) {
1524
- const r = o?.client ?? $, t = new U(), a = await R({
1525
- ...o,
1530
+ async function Ve(e, o, n) {
1531
+ const r = n?.client ?? S, t = new U(), a = await R({
1532
+ ...n,
1526
1533
  markets: Object.values(E),
1527
- cacheTime: w
1528
- }), i = await te(o);
1529
- for (let m of n) {
1530
- const d = await k({
1531
- ...o,
1532
- 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,
1533
1540
  market: m.market
1534
1541
  });
1535
1542
  t.moveCall({
1536
- target: `${d.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
1543
+ target: `${g.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
1537
1544
  arguments: [
1538
1545
  t.object("0x06"),
1539
1546
  // Clock object
1540
- t.object(d.storage),
1547
+ t.object(g.storage),
1541
1548
  // Protocol storage
1542
- t.object(d.incentiveV3),
1549
+ t.object(g.incentiveV3),
1543
1550
  // Incentive V3 contract
1544
1551
  t.pure.address(m.address)
1545
1552
  // User address
1546
1553
  ]
1547
1554
  });
1548
1555
  }
1549
- const c = await r.devInspectTransactionBlock({
1556
+ const i = await r.devInspectTransactionBlock({
1550
1557
  transactionBlock: t,
1551
1558
  sender: e
1552
1559
  }), s = [];
1553
- c?.results?.forEach((m) => {
1560
+ i?.results?.forEach((m) => {
1554
1561
  s.push(
1555
1562
  O(
1556
1563
  {
@@ -1572,52 +1579,52 @@ async function Ve(e, n, o) {
1572
1579
  );
1573
1580
  });
1574
1581
  const u = [];
1575
- return s.forEach((m, d) => {
1576
- const g = n[d];
1582
+ return s.forEach((m, g) => {
1583
+ const v = o[g];
1577
1584
  if (m.length === 5 && Array.isArray(m[0])) {
1578
- const v = m[0].length;
1579
- for (let f = 0; f < v; f++) {
1580
- const h = i.find(
1581
- (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])
1582
1589
  ), _ = a.find(
1583
- (T) => b(T.coinType) === b(m[0][f])
1590
+ (T) => b(T.coinType) === b(m[0][p])
1584
1591
  );
1585
- !h || !_ || u.push({
1592
+ !f || !_ || u.push({
1586
1593
  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
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
1595
1602
  });
1596
1603
  }
1597
1604
  }
1598
1605
  }), u;
1599
1606
  }
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) => ({
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) => ({
1602
1609
  address: e,
1603
1610
  market: a.key
1604
1611
  })).concat(
1605
- r.filter((a) => !!o.find((i) => i.id === a.marketId)).map((a) => {
1606
- const i = j(a.marketId);
1612
+ r.filter((a) => !!n.find((c) => c.id === a.marketId)).map((a) => {
1613
+ const c = j(a.marketId);
1607
1614
  return {
1608
1615
  address: e,
1609
- market: i.key,
1616
+ market: c.key,
1610
1617
  emodeId: a.emodeId
1611
1618
  };
1612
1619
  })
1613
1620
  );
1614
- return await Ve(e, t, n);
1621
+ return await Ve(e, t, o);
1615
1622
  }
1616
- function gt(e) {
1617
- const n = /* @__PURE__ */ new Map();
1623
+ function yt(e) {
1624
+ const o = /* @__PURE__ */ new Map();
1618
1625
  e.forEach((r) => {
1619
- const t = r.assetId, a = r.option, i = `${t}-${a}-${r.rewardCoinType}-${r.market}`;
1620
- 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, {
1621
1628
  assetId: t,
1622
1629
  rewardType: a,
1623
1630
  coinType: r.rewardCoinType,
@@ -1625,14 +1632,14 @@ function gt(e) {
1625
1632
  market: r.market
1626
1633
  });
1627
1634
  });
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);
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);
1634
1641
  }
1635
- return Array.from(o.values()).map((r) => ({
1642
+ return Array.from(n.values()).map((r) => ({
1636
1643
  assetId: r.assetId,
1637
1644
  rewardType: r.rewardType,
1638
1645
  market: r.market,
@@ -1642,56 +1649,56 @@ function gt(e) {
1642
1649
  }))
1643
1650
  }));
1644
1651
  }
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;
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;
1649
1656
  }
1650
1657
  ), 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());
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());
1653
1660
  return F({
1654
1661
  data: r.data.rewards
1655
1662
  });
1656
1663
  }
1657
1664
  );
1658
- async function vt(e, n, o) {
1665
+ async function wt(e, o, n) {
1659
1666
  const r = await k({
1660
- ...o,
1661
- cacheTime: w
1667
+ ...n,
1668
+ cacheTime: h
1662
1669
  }), t = await R({
1663
- ...o,
1670
+ ...n,
1664
1671
  markets: Object.values(E),
1665
- cacheTime: w
1672
+ cacheTime: h
1666
1673
  }), a = /* @__PURE__ */ new Map();
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) {
1670
- 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, {
1671
1678
  assetIds: [],
1672
1679
  ruleIds: [],
1673
1680
  amount: 0,
1674
1681
  market: m,
1675
- owner: d,
1676
- isEMode: typeof g < "u"
1682
+ owner: g,
1683
+ isEMode: typeof v < "u"
1677
1684
  });
1678
- const h = a.get(v);
1679
- 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;
1680
1687
  }
1681
1688
  }
1682
- const i = [];
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
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
1686
1693
  );
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)
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)
1691
1698
  throw new Error("customCoinReceive is required when accountCap is provided");
1692
- if (o?.customCoinReceive) {
1699
+ if (n?.customCoinReceive) {
1693
1700
  let _;
1694
- o.accountCap ? _ = e.moveCall({
1701
+ n.accountCap ? _ = e.moveCall({
1695
1702
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1696
1703
  arguments: [
1697
1704
  e.object("0x06"),
@@ -1700,17 +1707,17 @@ async function vt(e, n, o) {
1700
1707
  // Incentive V3 contract
1701
1708
  e.object(r.storage),
1702
1709
  // Protocol storage
1703
- e.object(h),
1710
+ e.object(f),
1704
1711
  // Reward fund
1705
1712
  e.pure.vector("string", s),
1706
1713
  // Asset IDs
1707
1714
  e.pure.vector("address", u),
1708
1715
  // Rule IDs
1709
- y(o.accountCap, e.object)
1716
+ y(n.accountCap, e.object)
1710
1717
  // Account capability
1711
1718
  ],
1712
- typeArguments: [c]
1713
- }) : v ? _ = e.moveCall({
1719
+ typeArguments: [i]
1720
+ }) : w ? _ = e.moveCall({
1714
1721
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1715
1722
  arguments: [
1716
1723
  e.object("0x06"),
@@ -1719,16 +1726,16 @@ async function vt(e, n, o) {
1719
1726
  // Incentive V3 contract
1720
1727
  e.object(r.storage),
1721
1728
  // Protocol storage
1722
- e.object(h),
1729
+ e.object(f),
1723
1730
  // Reward fund
1724
1731
  e.pure.vector("string", s),
1725
1732
  // Asset IDs
1726
1733
  e.pure.vector("address", u),
1727
1734
  // Rule IDs
1728
- y(g, e.object)
1735
+ y(v, e.object)
1729
1736
  // Account capability
1730
1737
  ],
1731
- typeArguments: [c]
1738
+ typeArguments: [i]
1732
1739
  }) : _ = e.moveCall({
1733
1740
  target: `${r.package}::incentive_v3::claim_reward`,
1734
1741
  arguments: [
@@ -1738,42 +1745,42 @@ async function vt(e, n, o) {
1738
1745
  // Incentive V3 contract
1739
1746
  e.object(r.storage),
1740
1747
  // Protocol storage
1741
- e.object(h),
1748
+ e.object(f),
1742
1749
  // Reward fund
1743
1750
  e.pure.vector("string", s),
1744
1751
  // Asset IDs
1745
1752
  e.pure.vector("address", u)
1746
1753
  // Rule IDs
1747
1754
  ],
1748
- typeArguments: [c]
1755
+ typeArguments: [i]
1749
1756
  });
1750
1757
  const [T] = e.moveCall({
1751
1758
  target: "0x2::coin::from_balance",
1752
1759
  arguments: [_],
1753
- typeArguments: [c]
1760
+ typeArguments: [i]
1754
1761
  });
1755
- if (o?.customCoinReceive.type === "transfer") {
1756
- if (!o.customCoinReceive.transfer)
1762
+ if (n?.customCoinReceive.type === "transfer") {
1763
+ if (!n.customCoinReceive.transfer)
1757
1764
  throw new Error("customCoinReceive.transfer is required");
1758
1765
  e.transferObjects(
1759
1766
  [T],
1760
- y(o.customCoinReceive.transfer, e.pure.address)
1767
+ y(n.customCoinReceive.transfer, e.pure.address)
1761
1768
  );
1762
1769
  }
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(
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(
1766
1773
  [T],
1767
- e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1768
- ) : await be(e, f, T, o);
1774
+ e.pure.address(n.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1775
+ ) : await be(e, p, T, n);
1769
1776
  } else
1770
- i.push({
1777
+ c.push({
1771
1778
  coin: T,
1772
- identifier: f,
1773
- owner: g,
1774
- isEMode: v
1779
+ identifier: p,
1780
+ owner: v,
1781
+ isEMode: w
1775
1782
  });
1776
- } else if (o?.accountCap || v) {
1783
+ } else if (n?.accountCap || w) {
1777
1784
  const _ = e.moveCall({
1778
1785
  target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
1779
1786
  arguments: [
@@ -1783,24 +1790,24 @@ async function vt(e, n, o) {
1783
1790
  // Incentive V3 contract
1784
1791
  e.object(r.storage),
1785
1792
  // Protocol storage
1786
- e.object(h),
1793
+ e.object(f),
1787
1794
  // Reward fund
1788
1795
  e.pure.vector("string", s),
1789
1796
  // Asset IDs
1790
1797
  e.pure.vector("address", u),
1791
1798
  // Rule IDs
1792
- y(o?.accountCap || g, e.object)
1799
+ y(n?.accountCap || v, e.object)
1793
1800
  // Account capability
1794
1801
  ],
1795
- typeArguments: [c]
1802
+ typeArguments: [i]
1796
1803
  }), [T] = e.moveCall({
1797
1804
  target: "0x2::coin::from_balance",
1798
1805
  arguments: [_],
1799
- typeArguments: [c]
1806
+ typeArguments: [i]
1800
1807
  });
1801
1808
  e.transferObjects(
1802
1809
  [T],
1803
- y(o?.accountCap || g, e.pure.address)
1810
+ y(n?.accountCap || v, e.pure.address)
1804
1811
  );
1805
1812
  } else
1806
1813
  e.moveCall({
@@ -1812,21 +1819,21 @@ async function vt(e, n, o) {
1812
1819
  // Incentive V3 contract
1813
1820
  e.object(r.storage),
1814
1821
  // Protocol storage
1815
- e.object(h),
1822
+ e.object(f),
1816
1823
  // Reward fund
1817
1824
  e.pure.vector("string", s),
1818
1825
  // Asset IDs
1819
1826
  e.pure.vector("address", u)
1820
1827
  // Rule IDs
1821
1828
  ],
1822
- typeArguments: [c]
1829
+ typeArguments: [i]
1823
1830
  });
1824
1831
  }
1825
- return i;
1832
+ return c;
1826
1833
  }
1827
1834
  export {
1828
1835
  W as Address,
1829
- w as DEFAULT_CACHE_TIME,
1836
+ h as DEFAULT_CACHE_TIME,
1830
1837
  D as DEFAULT_MARKET_IDENTITY,
1831
1838
  He as FlashLoanAssetConfig,
1832
1839
  qe as IncentiveAPYInfo,
@@ -1840,7 +1847,7 @@ export {
1840
1847
  M as UserPositions,
1841
1848
  de as UserStateInfo,
1842
1849
  Je as borrowCoinPTB,
1843
- vt as claimLendingRewardsPTB,
1850
+ wt as claimLendingRewardsPTB,
1844
1851
  _e as createAccountCapPTB,
1845
1852
  et as createEModeCapPTB,
1846
1853
  be as depositCoinPTB,
@@ -1852,7 +1859,7 @@ export {
1852
1859
  je as getAccountCapOwnerPTB,
1853
1860
  L as getAllFlashLoanAssets,
1854
1861
  Xe as getBorrowFee,
1855
- it as getCoins,
1862
+ ct as getCoins,
1856
1863
  k as getConfig,
1857
1864
  Ke as getFees,
1858
1865
  ut as getFlashLoanAsset,
@@ -1870,11 +1877,11 @@ export {
1870
1877
  at as getSimulatedHealthFactor,
1871
1878
  Z as getSimulatedHealthFactorPTB,
1872
1879
  ze as getStats,
1873
- ct as getTransactions,
1880
+ it as getTransactions,
1874
1881
  mt as getUserAvailableLendingRewards,
1875
1882
  ft as getUserClaimedRewardHistory,
1876
1883
  X as getUserEModeCaps,
1877
- yt as getUserTotalClaimedReward,
1884
+ gt as getUserTotalClaimedReward,
1878
1885
  dt as liquidatePTB,
1879
1886
  ot as mergeCoinsPTB,
1880
1887
  b as normalizeCoinType,
@@ -1882,10 +1889,10 @@ export {
1882
1889
  y as parseTxValue,
1883
1890
  Qe as repayCoinPTB,
1884
1891
  pt as repayFlashLoanPTB,
1885
- gt as summaryLendingRewards,
1892
+ yt as summaryLendingRewards,
1886
1893
  st as updateOraclePriceBeforeUserOperationPTB,
1887
- Se as updateOraclePricesPTB,
1888
- $e as updatePythPriceFeeds,
1894
+ $e as updateOraclePricesPTB,
1895
+ Se as updatePythPriceFeeds,
1889
1896
  A as withCache,
1890
1897
  I as withSingleton,
1891
1898
  Ye as withdrawCoinPTB