@naviprotocol/lending 1.4.0-emode.9 → 1.4.0

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