@naviprotocol/lending 1.2.2-dev.1 → 1.3.0-beta.1

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,628 +1,732 @@
1
- import { Transaction as $ } from "@mysten/sui/transactions";
2
- import { bcs as s, toHex as H, fromHex as q } from "@mysten/bcs";
3
- import { SuiClient as z, getFullnodeUrl as O } from "@mysten/sui/client";
1
+ import { Transaction as k } from "@mysten/sui/transactions";
2
+ import { bcs as i, toHex as G, fromHex as H } from "@mysten/bcs";
3
+ import { SuiClient as q, getFullnodeUrl as z } from "@mysten/sui/client";
4
4
  import W from "lodash.camelcase";
5
- import { normalizeStructTag as K } from "@mysten/sui/utils";
6
- import { SuiPriceServiceConnection as E, SuiPythClient as Y } from "@pythnetwork/pyth-sui-js";
5
+ import { normalizeStructTag as J } from "@mysten/sui/utils";
6
+ import { SuiPriceServiceConnection as N, SuiPythClient as K } from "@pythnetwork/pyth-sui-js";
7
7
  import T from "bignumber.js";
8
- import { bcs as b } from "@mysten/sui/bcs";
9
- const R = s.bytes(32).transform({
8
+ import { bcs as h } from "@mysten/sui/bcs";
9
+ const F = i.bytes(32).transform({
10
10
  // To change the input type, you need to provide a type definition for the input
11
- input: (e) => q(e),
12
- output: (e) => H(e)
13
- }), pe = s.struct("IncentiveAPYInfo", {
11
+ input: (e) => H(e),
12
+ output: (e) => G(e)
13
+ }), fe = i.struct("IncentiveAPYInfo", {
14
14
  /** Asset identifier */
15
- asset_id: s.u8(),
15
+ asset_id: i.u8(),
16
16
  /** Annual Percentage Yield as a 256-bit integer */
17
- apy: s.u256(),
17
+ apy: i.u256(),
18
18
  /** List of supported coin types for this incentive */
19
- coin_types: s.vector(s.string())
20
- }), J = s.struct("IncentivePoolInfo", {
19
+ coin_types: i.vector(i.string())
20
+ }), Y = i.struct("IncentivePoolInfo", {
21
21
  /** Unique pool identifier */
22
- pool_id: R,
22
+ pool_id: F,
23
23
  /** Address holding the incentive funds */
24
- funds: R,
24
+ funds: F,
25
25
  /** Current phase of the incentive program */
26
- phase: s.u64(),
26
+ phase: i.u64(),
27
27
  /** Timestamp when the incentive started */
28
- start_at: s.u64(),
28
+ start_at: i.u64(),
29
29
  /** Timestamp when the incentive ends */
30
- end_at: s.u64(),
30
+ end_at: i.u64(),
31
31
  /** Timestamp when the incentive was closed */
32
- closed_at: s.u64(),
32
+ closed_at: i.u64(),
33
33
  /** Total supply of incentive tokens */
34
- total_supply: s.u64(),
34
+ total_supply: i.u64(),
35
35
  /** Asset identifier for the incentive */
36
- asset_id: s.u8(),
36
+ asset_id: i.u8(),
37
37
  /** Option type for the incentive */
38
- option: s.u8(),
38
+ option: i.u8(),
39
39
  /** Factor used in incentive calculations */
40
- factor: s.u256(),
40
+ factor: i.u256(),
41
41
  /** Amount of incentives already distributed */
42
- distributed: s.u64(),
42
+ distributed: i.u64(),
43
43
  /** Amount of incentives currently available */
44
- available: s.u256(),
44
+ available: i.u256(),
45
45
  /** Total amount of incentives */
46
- total: s.u256()
47
- }), fe = s.struct("IncentivePoolInfoByPhase", {
46
+ total: i.u256()
47
+ }), ge = i.struct("IncentivePoolInfoByPhase", {
48
48
  /** Phase number */
49
- phase: s.u64(),
49
+ phase: i.u64(),
50
50
  /** List of incentive pools in this phase */
51
- pools: s.vector(J)
52
- }), me = s.struct("OracleInfo", {
51
+ pools: i.vector(Y)
52
+ }), ye = i.struct("OracleInfo", {
53
53
  /** Oracle identifier */
54
- oracle_id: s.u8(),
54
+ oracle_id: i.u8(),
55
55
  /** Current price as a 256-bit integer */
56
- price: s.u256(),
56
+ price: i.u256(),
57
57
  /** Number of decimal places for the price */
58
- decimals: s.u8(),
58
+ decimals: i.u8(),
59
59
  /** Whether the oracle data is valid */
60
- valid: s.bool()
61
- }), ge = s.struct("FlashLoanAssetConfig", {
60
+ valid: i.bool()
61
+ }), be = i.struct("FlashLoanAssetConfig", {
62
62
  /** Unique identifier for the flash loan asset */
63
- id: s.string(),
63
+ id: i.string(),
64
64
  /** Asset identifier */
65
- asset_id: s.u8(),
65
+ asset_id: i.u8(),
66
66
  /** Coin type for the asset */
67
- coin_type: s.string(),
67
+ coin_type: i.string(),
68
68
  /** Pool identifier for the flash loan */
69
- pool_id: s.string(),
69
+ pool_id: i.string(),
70
70
  /** Rate paid to suppliers for flash loans */
71
- rate_to_supplier: s.u64(),
71
+ rate_to_supplier: i.u64(),
72
72
  /** Rate paid to treasury for flash loans */
73
- rate_to_treasury: s.u64(),
73
+ rate_to_treasury: i.u64(),
74
74
  /** Maximum flash loan amount */
75
- max: s.u64(),
75
+ max: i.u64(),
76
76
  /** Minimum flash loan amount */
77
- min: s.u64()
78
- }), ye = s.struct("ReserveDataInfo", {
77
+ min: i.u64()
78
+ }), we = i.struct("ReserveDataInfo", {
79
79
  /** Reserve identifier */
80
- id: s.u8(),
80
+ id: i.u8(),
81
81
  /** Oracle identifier for price feeds */
82
- oracle_id: s.u8(),
82
+ oracle_id: i.u8(),
83
83
  /** Coin type for the reserve */
84
- coin_type: s.string(),
84
+ coin_type: i.string(),
85
85
  /** Maximum supply capacity */
86
- supply_cap: s.u256(),
86
+ supply_cap: i.u256(),
87
87
  /** Maximum borrow capacity */
88
- borrow_cap: s.u256(),
88
+ borrow_cap: i.u256(),
89
89
  /** Current supply interest rate */
90
- supply_rate: s.u256(),
90
+ supply_rate: i.u256(),
91
91
  /** Current borrow interest rate */
92
- borrow_rate: s.u256(),
92
+ borrow_rate: i.u256(),
93
93
  /** Current supply index for interest calculation */
94
- supply_index: s.u256(),
94
+ supply_index: i.u256(),
95
95
  /** Current borrow index for interest calculation */
96
- borrow_index: s.u256(),
96
+ borrow_index: i.u256(),
97
97
  /** Total amount supplied to the reserve */
98
- total_supply: s.u256(),
98
+ total_supply: i.u256(),
99
99
  /** Total amount borrowed from the reserve */
100
- total_borrow: s.u256(),
100
+ total_borrow: i.u256(),
101
101
  /** Timestamp of last update */
102
- last_update_at: s.u64(),
102
+ last_update_at: i.u64(),
103
103
  /** Loan-to-Value ratio for collateral */
104
- ltv: s.u256(),
104
+ ltv: i.u256(),
105
105
  /** Treasury factor for fee calculations */
106
- treasury_factor: s.u256(),
106
+ treasury_factor: i.u256(),
107
107
  /** Current treasury balance */
108
- treasury_balance: s.u256(),
108
+ treasury_balance: i.u256(),
109
109
  /** Base interest rate */
110
- base_rate: s.u256(),
110
+ base_rate: i.u256(),
111
111
  /** Interest rate multiplier */
112
- multiplier: s.u256(),
112
+ multiplier: i.u256(),
113
113
  /** Jump rate multiplier for high utilization */
114
- jump_rate_multiplier: s.u256(),
114
+ jump_rate_multiplier: i.u256(),
115
115
  /** Reserve factor for protocol fees */
116
- reserve_factor: s.u256(),
116
+ reserve_factor: i.u256(),
117
117
  /** Optimal utilization rate */
118
- optimal_utilization: s.u256(),
118
+ optimal_utilization: i.u256(),
119
119
  /** Liquidation ratio threshold */
120
- liquidation_ratio: s.u256(),
120
+ liquidation_ratio: i.u256(),
121
121
  /** Liquidation bonus for liquidators */
122
- liquidation_bonus: s.u256(),
122
+ liquidation_bonus: i.u256(),
123
123
  /** Liquidation threshold */
124
- liquidation_threshold: s.u256()
125
- }), Q = s.struct("UserStateInfo", {
124
+ liquidation_threshold: i.u256()
125
+ }), Q = i.struct("UserStateInfo", {
126
126
  /** Asset identifier */
127
- asset_id: s.u8(),
127
+ asset_id: i.u8(),
128
128
  /** User's current borrow balance */
129
- borrow_balance: s.u256(),
129
+ borrow_balance: i.u256(),
130
130
  /** User's current supply balance */
131
- supply_balance: s.u256()
132
- }), I = new z({
133
- url: O("mainnet")
131
+ supply_balance: i.u256()
132
+ }), A = new q({
133
+ url: z("mainnet")
134
134
  });
135
- function N(e) {
135
+ function E(e) {
136
136
  const a = [];
137
- return e.forEach((r, t) => {
138
- const c = t === e.length - 1;
139
- if (typeof r == "object" && c) {
140
- const { client: n, disableCache: o, cacheTime: i, ...u } = r;
137
+ return e.forEach((c, t) => {
138
+ const r = t === e.length - 1;
139
+ if (typeof c == "object" && r) {
140
+ const { client: n, disableCache: o, cacheTime: s, ...u } = c;
141
141
  a.push(u);
142
142
  } else
143
- a.push(r);
143
+ a.push(c);
144
144
  }), JSON.stringify(a);
145
145
  }
146
- function _(e) {
146
+ function C(e) {
147
147
  const a = {};
148
- return (...r) => {
149
- const t = N(r);
150
- return a[t] || (a[t] = e(...r).finally(() => {
148
+ return (...c) => {
149
+ const t = E(c);
150
+ return a[t] || (a[t] = e(...c).finally(() => {
151
151
  a[t] = null;
152
152
  })), a[t];
153
153
  };
154
154
  }
155
- function A(e) {
155
+ function I(e) {
156
156
  let a = {};
157
- return (...r) => {
158
- const t = r[r.length - 1], c = N(r), n = a[c];
159
- return !(t != null && t.disableCache) && typeof (n == null ? void 0 : n.data) != "undefined" && (typeof (t == null ? void 0 : t.cacheTime) == "undefined" || t.cacheTime > Date.now() - n.cacheAt) ? n.data : e(...r).then((o) => (a[c] = {
157
+ return (...c) => {
158
+ const t = c[c.length - 1], r = E(c), n = a[r];
159
+ return !(t != null && t.disableCache) && typeof (n == null ? void 0 : n.data) != "undefined" && (typeof (t == null ? void 0 : t.cacheTime) == "undefined" || t.cacheTime > Date.now() - n.cacheAt) ? n.data : e(...c).then((o) => (a[r] = {
160
160
  data: o,
161
161
  cacheAt: Date.now()
162
162
  }, o));
163
163
  };
164
164
  }
165
- function B(e) {
166
- return Array.isArray(e) ? e.map((a) => B(a)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
167
- (a, r) => ({
165
+ function P(e) {
166
+ return Array.isArray(e) ? e.map((a) => P(a)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
167
+ (a, c) => ({
168
168
  ...a,
169
- [W(r)]: B(e[r])
169
+ [W(c)]: P(e[c])
170
170
  }),
171
171
  {}
172
172
  ) : e;
173
173
  }
174
- function f(e, a) {
174
+ function d(e, a) {
175
175
  return typeof e == "object" ? e : a(e);
176
176
  }
177
177
  function X(e, a) {
178
178
  return typeof a == "string" ? e.object(a) : typeof a == "object" && a.$kind ? a : e.object(a.contract.pool);
179
179
  }
180
- function k(e, a, r) {
180
+ function B(e, a, c) {
181
181
  if (e.results && e.results.length > 0) {
182
182
  if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
183
- return e.results[0].returnValues.map((t, c) => (a[c] || a[0]).parse(Uint8Array.from(t[0])));
183
+ return e.results[0].returnValues.map((t, r) => (a[r] || a[0]).parse(Uint8Array.from(t[0])));
184
184
  } else if (e.error)
185
185
  return console.log(`Get an error, msg: ${e.error}`), [];
186
186
  return [];
187
187
  }
188
- function m(e) {
189
- return K(e);
188
+ function f(e) {
189
+ return J(e);
190
190
  }
191
- function L(e) {
191
+ function D(e) {
192
192
  const a = (e || 0) / Math.pow(10, 27);
193
193
  return a > Math.pow(10, 5) ? 1 / 0 : a;
194
194
  }
195
- new E("https://hermes.pyth.network", {
195
+ new N("https://hermes.pyth.network", {
196
196
  timeout: 2e4
197
197
  });
198
- const Z = 27, V = (e, a) => {
198
+ const Z = 27, R = (e, a) => {
199
199
  if (!Number(e) || !Number(a)) return new T(0);
200
- const r = new T(1).shiftedBy(1 * Z), t = r.multipliedBy(new T(0.5));
201
- return new T(e).multipliedBy(new T(a)).plus(t).dividedBy(r).integerValue(T.ROUND_DOWN);
202
- }, w = A(
203
- _(async (e) => {
204
- const a = `https://open-api.naviprotocol.io/api/navi/config?env=${(e == null ? void 0 : e.env) || "prod"}`;
200
+ const c = new T(1).shiftedBy(1 * Z), t = c.multipliedBy(new T(0.5));
201
+ return new T(e).multipliedBy(new T(a)).plus(t).dividedBy(c).integerValue(T.ROUND_DOWN);
202
+ }, x = "1.3.0-beta.1", ee = {
203
+ version: x
204
+ }, b = I(
205
+ C(async (e) => {
206
+ const a = `https://open-api.naviprotocol.io/api/navi/config?env=${(e == null ? void 0 : e.env) || "prod"}&sdk=${ee.version}`;
205
207
  return (await fetch(a).then((t) => t.json())).data;
206
208
  })
207
209
  ), g = 1e3 * 60 * 5;
208
- var P = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(P || {});
209
- const S = A(
210
- _(async (e) => {
210
+ var $ = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))($ || {});
211
+ const V = I(
212
+ C(async (e) => {
211
213
  const a = `https://open-api.naviprotocol.io/api/navi/pools?env=${(e == null ? void 0 : e.env) || "prod"}`;
212
214
  return (await fetch(a).then((t) => t.json())).data;
213
215
  })
214
216
  );
215
- async function C(e, a) {
216
- const r = await S({
217
+ async function v(e, a) {
218
+ const c = await V({
217
219
  ...a,
218
220
  cacheTime: g
219
221
  });
220
222
  if (typeof e == "object")
221
223
  return e;
222
- const t = r.find((c) => typeof e == "string" ? m(c.suiCoinType) === m(e) : typeof e == "number" ? c.id === e : !1);
224
+ const t = c.find((r) => typeof e == "string" ? f(r.suiCoinType) === f(e) : typeof e == "number" ? r.id === e : !1);
223
225
  if (!t)
224
226
  throw new Error("Pool not found");
225
227
  return t;
226
228
  }
227
- const we = A(
228
- _(async (e) => (await fetch("https://open-api.naviprotocol.io/api/navi/stats").then((t) => t.json())).data)
229
- ), he = A(
230
- _(
229
+ const he = I(
230
+ C(async (e) => (await fetch("https://open-api.naviprotocol.io/api/navi/stats").then((t) => t.json())).data)
231
+ ), ve = I(
232
+ C(
231
233
  async (e) => await fetch("https://open-api.naviprotocol.io/api/navi/fee").then((t) => t.json())
232
234
  )
233
235
  );
234
- async function x(e, a, r, t) {
235
- const c = await w({
236
+ async function te(e, a, c, t) {
237
+ const r = await b({
236
238
  ...t,
237
239
  cacheTime: g
238
- }), n = await C(a, t), o = typeof r == "object" && r.$kind === "GasCoin";
239
- if (m(n.suiCoinType) === m("0x2::sui::SUI") && o) {
240
+ }), n = await v(a, t), o = typeof c == "object" && c.$kind === "GasCoin";
241
+ if (f(n.suiCoinType) === f("0x2::sui::SUI") && o) {
240
242
  if (!(t != null && t.amount))
241
243
  throw new Error("Amount is required for sui coin");
242
- r = e.splitCoins(r, [t.amount]);
244
+ c = e.splitCoins(c, [t.amount]);
243
245
  }
244
- let i;
245
- return typeof (t == null ? void 0 : t.amount) != "undefined" ? i = f(t.amount, e.pure.u64) : i = e.moveCall({
246
+ let s;
247
+ return typeof (t == null ? void 0 : t.amount) != "undefined" ? s = d(t.amount, e.pure.u64) : s = e.moveCall({
246
248
  target: "0x2::coin::value",
247
- arguments: [f(r, e.object)],
249
+ arguments: [d(c, e.object)],
248
250
  typeArguments: [n.suiCoinType]
249
251
  }), t != null && t.accountCap ? e.moveCall({
250
- target: `${c.package}::incentive_v3::deposit_with_account_cap`,
252
+ target: `${r.package}::incentive_v3::deposit_with_account_cap`,
251
253
  arguments: [
252
254
  e.object("0x06"),
253
- e.object(c.storage),
255
+ e.object(r.storage),
254
256
  e.object(n.contract.pool),
255
257
  e.pure.u8(n.id),
256
- f(r, e.object),
257
- e.object(c.incentiveV2),
258
- e.object(c.incentiveV3),
259
- f(t.accountCap, e.object)
258
+ d(c, e.object),
259
+ e.object(r.incentiveV2),
260
+ e.object(r.incentiveV3),
261
+ d(t.accountCap, e.object)
260
262
  ],
261
263
  typeArguments: [n.suiCoinType]
262
264
  }) : e.moveCall({
263
- target: `${c.package}::incentive_v3::entry_deposit`,
265
+ target: `${r.package}::incentive_v3::entry_deposit`,
264
266
  arguments: [
265
267
  e.object("0x06"),
266
- e.object(c.storage),
268
+ e.object(r.storage),
267
269
  e.object(n.contract.pool),
268
270
  e.pure.u8(n.id),
269
- f(r, e.object),
270
- i,
271
- e.object(c.incentiveV2),
272
- e.object(c.incentiveV3)
271
+ d(c, e.object),
272
+ s,
273
+ e.object(r.incentiveV2),
274
+ e.object(r.incentiveV3)
273
275
  ],
274
276
  typeArguments: [n.suiCoinType]
277
+ }), r.version === 2 && n.id === 0 && e.moveCall({
278
+ target: `${r.package}::pool::refresh_stake`,
279
+ arguments: [e.object(n.contract.pool), e.object("0x05")]
275
280
  }), e;
276
281
  }
277
- async function be(e, a, r, t) {
278
- const c = await w({
282
+ async function je(e, a, c, t) {
283
+ const r = await b({
279
284
  ...t,
280
285
  cacheTime: g
281
- }), n = await C(a, t), o = f(r, e.pure.u64);
282
- let i;
283
- if (t != null && t.accountCap) {
286
+ }), n = await v(a, t), o = d(c, e.pure.u64);
287
+ let s;
288
+ if (r.version === 1)
289
+ if (t != null && t.accountCap) {
290
+ const [l] = e.moveCall({
291
+ target: `${r.package}::incentive_v3::withdraw_with_account_cap`,
292
+ arguments: [
293
+ e.object("0x06"),
294
+ e.object(r.priceOracle),
295
+ e.object(r.storage),
296
+ e.object(n.contract.pool),
297
+ e.pure.u8(n.id),
298
+ o,
299
+ e.object(r.incentiveV2),
300
+ e.object(r.incentiveV3),
301
+ d(t.accountCap, e.object)
302
+ ],
303
+ typeArguments: [n.suiCoinType]
304
+ });
305
+ s = l;
306
+ } else {
307
+ const [l] = e.moveCall({
308
+ target: `${r.package}::incentive_v3::withdraw`,
309
+ arguments: [
310
+ e.object("0x06"),
311
+ e.object(r.priceOracle),
312
+ e.object(r.storage),
313
+ e.object(n.contract.pool),
314
+ e.pure.u8(n.id),
315
+ o,
316
+ e.object(r.incentiveV2),
317
+ e.object(r.incentiveV3)
318
+ ],
319
+ typeArguments: [n.suiCoinType]
320
+ });
321
+ s = l;
322
+ }
323
+ else if (t != null && t.accountCap) {
284
324
  const [l] = e.moveCall({
285
- target: `${c.package}::incentive_v3::withdraw_with_account_cap`,
325
+ target: `${r.package}::incentive_v3::withdraw_with_account_cap_v2`,
286
326
  arguments: [
287
327
  e.object("0x06"),
288
- e.object(c.priceOracle),
289
- e.object(c.storage),
328
+ e.object(r.priceOracle),
329
+ e.object(r.storage),
290
330
  e.object(n.contract.pool),
291
331
  e.pure.u8(n.id),
292
332
  o,
293
- e.object(c.incentiveV2),
294
- e.object(c.incentiveV3),
295
- f(t.accountCap, e.object)
333
+ e.object(r.incentiveV2),
334
+ e.object(r.incentiveV3),
335
+ d(t.accountCap, e.object),
336
+ e.object("0x05")
296
337
  ],
297
338
  typeArguments: [n.suiCoinType]
298
339
  });
299
- i = l;
340
+ s = l;
300
341
  } else {
301
342
  const [l] = e.moveCall({
302
- target: `${c.package}::incentive_v3::withdraw`,
343
+ target: `${r.package}::incentive_v3::withdraw_v2`,
303
344
  arguments: [
304
345
  e.object("0x06"),
305
- e.object(c.priceOracle),
306
- e.object(c.storage),
346
+ e.object(r.priceOracle),
347
+ e.object(r.storage),
307
348
  e.object(n.contract.pool),
308
349
  e.pure.u8(n.id),
309
350
  o,
310
- e.object(c.incentiveV2),
311
- e.object(c.incentiveV3)
351
+ e.object(r.incentiveV2),
352
+ e.object(r.incentiveV3),
353
+ e.object("0x05")
312
354
  ],
313
355
  typeArguments: [n.suiCoinType]
314
356
  });
315
- i = l;
357
+ s = l;
316
358
  }
317
359
  return e.moveCall({
318
360
  target: "0x2::coin::from_balance",
319
- arguments: [i],
361
+ arguments: [s],
320
362
  typeArguments: [n.suiCoinType]
321
363
  });
322
364
  }
323
- async function ve(e, a, r, t) {
324
- const c = await w({
365
+ async function Ce(e, a, c, t) {
366
+ const r = await b({
325
367
  ...t,
326
368
  cacheTime: g
327
- }), n = await C(a, t), o = f(r, e.pure.u64);
328
- let i;
329
- if (t != null && t.accountCap) {
369
+ }), n = await v(a, t), o = d(c, e.pure.u64);
370
+ let s;
371
+ if (r.version === 1)
372
+ if (t != null && t.accountCap) {
373
+ const [l] = e.moveCall({
374
+ target: `${r.package}::incentive_v3::borrow_with_account_cap`,
375
+ arguments: [
376
+ e.object("0x06"),
377
+ e.object(r.priceOracle),
378
+ e.object(r.storage),
379
+ e.object(n.contract.pool),
380
+ e.pure.u8(n.id),
381
+ o,
382
+ e.object(r.incentiveV2),
383
+ e.object(r.incentiveV3),
384
+ d(t.accountCap, e.object)
385
+ ],
386
+ typeArguments: [n.suiCoinType]
387
+ });
388
+ s = l;
389
+ } else {
390
+ const [l] = e.moveCall({
391
+ target: `${r.package}::incentive_v3::borrow`,
392
+ arguments: [
393
+ e.object("0x06"),
394
+ e.object(r.priceOracle),
395
+ e.object(r.storage),
396
+ e.object(n.contract.pool),
397
+ e.pure.u8(n.id),
398
+ o,
399
+ e.object(r.incentiveV2),
400
+ e.object(r.incentiveV3)
401
+ ],
402
+ typeArguments: [n.suiCoinType]
403
+ });
404
+ s = l;
405
+ }
406
+ else if (t != null && t.accountCap) {
330
407
  const [l] = e.moveCall({
331
- target: `${c.package}::incentive_v3::borrow_with_account_cap`,
408
+ target: `${r.package}::incentive_v3::borrow_with_account_cap_v2`,
332
409
  arguments: [
333
410
  e.object("0x06"),
334
- e.object(c.priceOracle),
335
- e.object(c.storage),
411
+ e.object(r.priceOracle),
412
+ e.object(r.storage),
336
413
  e.object(n.contract.pool),
337
414
  e.pure.u8(n.id),
338
415
  o,
339
- e.object(c.incentiveV2),
340
- e.object(c.incentiveV3),
341
- f(t.accountCap, e.object)
416
+ e.object(r.incentiveV2),
417
+ e.object(r.incentiveV3),
418
+ d(t.accountCap, e.object),
419
+ e.object("0x05")
342
420
  ],
343
421
  typeArguments: [n.suiCoinType]
344
422
  });
345
- i = l;
423
+ s = l;
346
424
  } else {
347
425
  const [l] = e.moveCall({
348
- target: `${c.package}::incentive_v3::borrow`,
426
+ target: `${r.package}::incentive_v3::borrow_v2`,
349
427
  arguments: [
350
428
  e.object("0x06"),
351
- e.object(c.priceOracle),
352
- e.object(c.storage),
429
+ e.object(r.priceOracle),
430
+ e.object(r.storage),
353
431
  e.object(n.contract.pool),
354
432
  e.pure.u8(n.id),
355
433
  o,
356
- e.object(c.incentiveV2),
357
- e.object(c.incentiveV3)
434
+ e.object(r.incentiveV2),
435
+ e.object(r.incentiveV3),
436
+ e.object("0x05")
358
437
  ],
359
438
  typeArguments: [n.suiCoinType]
360
439
  });
361
- i = l;
440
+ s = l;
362
441
  }
363
442
  return e.moveCall({
364
443
  target: "0x2::coin::from_balance",
365
- arguments: [e.object(i)],
444
+ arguments: [e.object(s)],
366
445
  typeArguments: [n.suiCoinType]
367
446
  });
368
447
  }
369
- async function Ce(e, a, r, t) {
370
- const c = await w({
448
+ async function _e(e, a, c, t) {
449
+ const r = await b({
371
450
  ...t,
372
451
  cacheTime: g
373
- }), n = await C(a, t), o = typeof r == "object" && r.$kind === "GasCoin";
374
- if (m(n.suiCoinType) === m("0x2::sui::SUI") && o) {
452
+ }), n = await v(a, t), o = typeof c == "object" && c.$kind === "GasCoin";
453
+ if (f(n.suiCoinType) === f("0x2::sui::SUI") && o) {
375
454
  if (!(t != null && t.amount))
376
455
  throw new Error("Amount is required for sui coin");
377
- r = e.splitCoins(r, [t.amount]);
456
+ c = e.splitCoins(c, [t.amount]);
378
457
  }
379
- let i;
380
- return typeof (t == null ? void 0 : t.amount) != "undefined" ? i = f(t.amount, e.pure.u64) : i = e.moveCall({
458
+ let s;
459
+ return typeof (t == null ? void 0 : t.amount) != "undefined" ? s = d(t.amount, e.pure.u64) : s = e.moveCall({
381
460
  target: "0x2::coin::value",
382
- arguments: [f(r, e.object)],
461
+ arguments: [d(c, e.object)],
383
462
  typeArguments: [n.suiCoinType]
384
463
  }), t != null && t.accountCap ? e.moveCall({
385
- target: `${c.package}::incentive_v3::repay_with_account_cap`,
464
+ target: `${r.package}::incentive_v3::repay_with_account_cap`,
386
465
  arguments: [
387
466
  e.object("0x06"),
388
- e.object(c.priceOracle),
389
- e.object(c.storage),
467
+ e.object(r.priceOracle),
468
+ e.object(r.storage),
390
469
  e.object(n.contract.pool),
391
470
  e.pure.u8(n.id),
392
- f(r, e.object),
393
- i,
394
- e.object(c.incentiveV2),
395
- e.object(c.incentiveV3),
396
- f(t.accountCap, e.object)
471
+ d(c, e.object),
472
+ s,
473
+ e.object(r.incentiveV2),
474
+ e.object(r.incentiveV3),
475
+ d(t.accountCap, e.object)
397
476
  ],
398
477
  typeArguments: [n.suiCoinType]
399
478
  }) : e.moveCall({
400
- target: `${c.package}::incentive_v3::entry_repay`,
479
+ target: `${r.package}::incentive_v3::entry_repay`,
401
480
  arguments: [
402
481
  e.object("0x06"),
403
- e.object(c.priceOracle),
404
- e.object(c.storage),
482
+ e.object(r.priceOracle),
483
+ e.object(r.storage),
405
484
  e.object(n.contract.pool),
406
485
  e.pure.u8(n.id),
407
- f(r, e.object),
408
- i,
409
- e.object(c.incentiveV2),
410
- e.object(c.incentiveV3)
486
+ d(c, e.object),
487
+ s,
488
+ e.object(r.incentiveV2),
489
+ e.object(r.incentiveV3)
411
490
  ],
412
491
  typeArguments: [n.suiCoinType]
413
492
  }), e;
414
493
  }
415
- const _e = A(
416
- _(async (e) => {
417
- const a = await w({
418
- ...e
419
- }), t = (await I.getObject({
420
- id: a.incentiveV3,
421
- options: { showType: !0, showOwner: !0, showContent: !0 }
422
- })).data.content.fields.borrow_fee_rate;
423
- return Number(t) / 100;
424
- })
494
+ const Te = I(
495
+ C(
496
+ async (e) => {
497
+ var r;
498
+ const a = await b({
499
+ ...e
500
+ });
501
+ if (e != null && e.address && typeof (e == null ? void 0 : e.asset) != "undefined")
502
+ try {
503
+ const n = await v(e.asset, e), o = (r = e == null ? void 0 : e.client) != null ? r : A, s = new k();
504
+ s.moveCall({
505
+ target: `${a.package}::incentive_v3::get_borrow_fee_v2`,
506
+ arguments: [
507
+ s.object(a.incentiveV3),
508
+ s.pure.address(e.address),
509
+ s.pure.u8(n.id),
510
+ s.pure.u64(1e4)
511
+ ],
512
+ typeArguments: []
513
+ });
514
+ const u = await o.devInspectTransactionBlock({
515
+ transactionBlock: s,
516
+ sender: e.address
517
+ }), l = B(u, [h.u64()]);
518
+ return (Number(l[0]) || 0) / 100;
519
+ } catch (n) {
520
+ console.error(n);
521
+ }
522
+ const t = (await A.getObject({
523
+ id: a.incentiveV3,
524
+ options: { showType: !0, showOwner: !0, showContent: !0 }
525
+ })).data.content.fields.borrow_fee_rate;
526
+ return Number(t) / 100;
527
+ }
528
+ )
425
529
  );
426
- function je(e, a, r) {
427
- const t = typeof (r == null ? void 0 : r.balance) == "number", c = t ? r.balance : 0;
530
+ function Ae(e, a, c) {
531
+ const t = typeof (c == null ? void 0 : c.balance) == "number", r = t ? c.balance : 0;
428
532
  let n = 0;
429
533
  const o = [];
430
- let i = "";
431
- if (a.sort((l, d) => Number(d.balance) - Number(l.balance)).forEach((l) => {
432
- if (!(t && n >= c) && Number(l.balance) !== 0) {
433
- if (i || (i = l.coinType), i !== l.coinType)
534
+ let s = "";
535
+ if (a.sort((l, p) => Number(p.balance) - Number(l.balance)).forEach((l) => {
536
+ if (!(t && n >= r) && Number(l.balance) !== 0) {
537
+ if (s || (s = l.coinType), s !== l.coinType)
434
538
  throw new Error("All coins must be of the same type");
435
539
  n += Number(l.balance), o.push(l.coinObjectId);
436
540
  }
437
541
  }), o.length === 0)
438
542
  throw new Error("No coins to merge");
439
- if (t && n < c)
543
+ if (t && n < r)
440
544
  throw new Error(
441
- `Balance is less than the specified balance: ${n} < ${c}`
545
+ `Balance is less than the specified balance: ${n} < ${r}`
442
546
  );
443
- if (m(i) === m("0x2::sui::SUI") && (r != null && r.useGasCoin))
444
- return t ? e.splitCoins(e.gas, [e.pure.u64(c)]) : e.gas;
547
+ if (f(s) === f("0x2::sui::SUI") && (c != null && c.useGasCoin))
548
+ return t ? e.splitCoins(e.gas, [e.pure.u64(r)]) : e.gas;
445
549
  const u = o.length === 1 ? e.object(o[0]) : e.mergeCoins(o[0], o.slice(1));
446
- return t ? e.splitCoins(u, [e.pure.u64(c)]) : u;
550
+ return t ? e.splitCoins(u, [e.pure.u64(r)]) : u;
447
551
  }
448
- async function D(e, a, r, t, c, n, o) {
449
- const i = await w({
552
+ async function L(e, a, c, t, r, n, o) {
553
+ const s = await b({
450
554
  ...o,
451
555
  cacheTime: g
452
- }), u = await C(r, o);
556
+ }), u = await v(c, o);
453
557
  return e.moveCall({
454
- target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
558
+ target: `${s.uiGetter}::calculator_unchecked::dynamic_health_factor`,
455
559
  arguments: [
456
560
  e.object("0x06"),
457
- e.object(i.storage),
458
- e.object(i.oracle.priceOracle),
561
+ e.object(s.storage),
562
+ e.object(s.oracle.priceOracle),
459
563
  X(e, u),
460
- f(a, e.pure.address),
461
- f(u.id, e.pure.u8),
462
- f(t, e.pure.u64),
463
- f(c, e.pure.u64),
464
- f(n, e.pure.bool)
564
+ d(a, e.pure.address),
565
+ d(u.id, e.pure.u8),
566
+ d(t, e.pure.u64),
567
+ d(r, e.pure.u64),
568
+ d(n, e.pure.bool)
465
569
  ],
466
570
  typeArguments: [u.suiCoinType]
467
571
  });
468
572
  }
469
- async function ee(e, a, r) {
470
- return D(e, a, 0, 0, 0, !1, r);
573
+ async function ae(e, a, c) {
574
+ return L(e, a, 0, 0, 0, !1, c);
471
575
  }
472
- const Te = A(
576
+ const Ie = I(
473
577
  async (e, a) => {
474
578
  var l;
475
- const r = await w({
579
+ const c = await b({
476
580
  ...a,
477
581
  cacheTime: g
478
- }), t = new $(), c = (l = a == null ? void 0 : a.client) != null ? l : I, n = await S(a);
582
+ }), t = new k(), r = (l = a == null ? void 0 : a.client) != null ? l : A, n = await V(a);
479
583
  t.moveCall({
480
- target: `${r.uiGetter}::getter_unchecked::get_user_state`,
481
- arguments: [t.object(r.storage), t.pure.address(e)]
584
+ target: `${c.uiGetter}::getter_unchecked::get_user_state`,
585
+ arguments: [t.object(c.storage), t.pure.address(e)]
482
586
  });
483
- const o = await c.devInspectTransactionBlock({
587
+ const o = await r.devInspectTransactionBlock({
484
588
  transactionBlock: t,
485
589
  sender: e
486
- }), i = k(o, [b.vector(Q)]);
487
- return B(
488
- i[0].filter((d) => d.supply_balance !== "0" || d.borrow_balance !== "0")
489
- ).map((d) => {
490
- const h = n.find((v) => v.id === d.assetId), p = V(
491
- d.supplyBalance,
492
- h.currentSupplyIndex
493
- ).toString(), y = V(
494
- d.borrowBalance,
495
- h.currentBorrowIndex
590
+ }), s = B(o, [h.vector(Q)]);
591
+ return P(
592
+ s[0].filter((p) => p.supply_balance !== "0" || p.borrow_balance !== "0")
593
+ ).map((p) => {
594
+ const w = n.find((j) => j.id === p.assetId), m = R(
595
+ p.supplyBalance,
596
+ w.currentSupplyIndex
597
+ ).toString(), y = R(
598
+ p.borrowBalance,
599
+ w.currentBorrowIndex
496
600
  ).toString();
497
601
  return {
498
- ...d,
499
- supplyBalance: p,
602
+ ...p,
603
+ supplyBalance: m,
500
604
  borrowBalance: y,
501
- pool: h
605
+ pool: w
502
606
  };
503
- }).filter((d) => !!d.pool);
607
+ }).filter((p) => !!p.pool);
504
608
  }
505
609
  );
506
- async function Ie(e, a) {
610
+ async function $e(e, a) {
507
611
  var o;
508
- const r = (o = a == null ? void 0 : a.client) != null ? o : I, t = new $();
509
- await ee(t, e, a);
510
- const c = await r.devInspectTransactionBlock({
612
+ const c = (o = a == null ? void 0 : a.client) != null ? o : A, t = new k();
613
+ await ae(t, e, a);
614
+ const r = await c.devInspectTransactionBlock({
511
615
  transactionBlock: t,
512
616
  sender: e
513
- }), n = k(c, [b.u256()]);
514
- return L(Number(n[0]) || 0);
617
+ }), n = B(r, [h.u256()]);
618
+ return D(Number(n[0]) || 0);
515
619
  }
516
- async function Ae(e, a, r, t) {
517
- var p;
518
- const c = (p = t == null ? void 0 : t.client) != null ? p : I, n = new $();
519
- let o = 0, i = 0;
520
- const u = await C(a, t);
521
- if (r.forEach((y) => {
522
- y.type === P.Supply ? o += y.amount : y.type === P.Withdraw ? o -= y.amount : y.type === P.Borrow ? i += y.amount : y.type === P.Repay && (i -= y.amount);
523
- }), o * i < 0)
620
+ async function ke(e, a, c, t) {
621
+ var m;
622
+ const r = (m = t == null ? void 0 : t.client) != null ? m : A, n = new k();
623
+ let o = 0, s = 0;
624
+ const u = await v(a, t);
625
+ if (c.forEach((y) => {
626
+ y.type === $.Supply ? o += y.amount : y.type === $.Withdraw ? o -= y.amount : y.type === $.Borrow ? s += y.amount : y.type === $.Repay && (s -= y.amount);
627
+ }), o * s < 0)
524
628
  throw new Error("Invalid operations");
525
- const l = o > 0 || i > 0;
526
- await D(
629
+ const l = o > 0 || s > 0;
630
+ await L(
527
631
  n,
528
632
  e,
529
633
  u,
530
634
  Math.abs(o),
531
- Math.abs(i),
635
+ Math.abs(s),
532
636
  l,
533
637
  t
534
638
  );
535
- const d = await c.devInspectTransactionBlock({
639
+ const p = await r.devInspectTransactionBlock({
536
640
  transactionBlock: n,
537
641
  sender: e
538
- }), h = k(d, [b.u256()]);
539
- return L(Number(h[0]) || 0);
642
+ }), w = B(p, [h.u256()]);
643
+ return D(Number(w[0]) || 0);
540
644
  }
541
- const Pe = _(
645
+ const Be = C(
542
646
  async (e, a) => {
543
- const r = new URLSearchParams();
544
- a != null && a.cursor && r.set("cursor", a.cursor), r.set("userAddress", e);
545
- const t = `https://open-api.naviprotocol.io/api/navi/user/transactions?${r.toString()}`;
647
+ const c = new URLSearchParams();
648
+ a != null && a.cursor && c.set("cursor", a.cursor), c.set("userAddress", e);
649
+ const t = `https://open-api.naviprotocol.io/api/navi/user/transactions?${c.toString()}`;
546
650
  return (await fetch(t).then((n) => n.json())).data;
547
651
  }
548
652
  );
549
- async function Be(e, a) {
653
+ async function Pe(e, a) {
550
654
  var n;
551
- let r = null;
552
- const t = [], c = (n = a == null ? void 0 : a.client) != null ? n : I;
655
+ let c = null;
656
+ const t = [], r = (n = a == null ? void 0 : a.client) != null ? n : A;
553
657
  do {
554
658
  let o;
555
- if (a != null && a.coinType ? o = await c.getCoins({
659
+ if (a != null && a.coinType ? o = await r.getCoins({
556
660
  owner: e,
557
661
  coinType: a == null ? void 0 : a.coinType,
558
- cursor: r,
662
+ cursor: c,
559
663
  limit: 100
560
- }) : o = await c.getAllCoins({
664
+ }) : o = await r.getAllCoins({
561
665
  owner: e,
562
- cursor: r,
666
+ cursor: c,
563
667
  limit: 100
564
668
  }), !o.data || !o.data.length)
565
669
  break;
566
- t.push(...o.data), r = o.nextCursor;
567
- } while (r);
670
+ t.push(...o.data), c = o.nextCursor;
671
+ } while (c);
568
672
  return t;
569
673
  }
570
- const M = new E("https://hermes.pyth.network", {
674
+ const M = new N("https://hermes.pyth.network", {
571
675
  timeout: 1e4
572
676
  });
573
- async function te(e) {
677
+ async function re(e) {
574
678
  try {
575
- const a = [], r = await M.getLatestPriceFeeds(e);
576
- if (!r) return a;
679
+ const a = [], c = await M.getLatestPriceFeeds(e);
680
+ if (!c) return a;
577
681
  const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
578
- for (const c of r) {
579
- const n = c.getPriceUnchecked();
682
+ for (const r of c) {
683
+ const n = r.getPriceUnchecked();
580
684
  if (n.publishTime > t) {
581
685
  console.warn(
582
- `pyth price feed is invalid, id: ${c.id}, publish time: ${n.publishTime}, current timestamp: ${t}`
686
+ `pyth price feed is invalid, id: ${r.id}, publish time: ${n.publishTime}, current timestamp: ${t}`
583
687
  );
584
688
  continue;
585
689
  }
586
- t - c.getPriceUnchecked().publishTime > 30 && (console.info(
587
- `stale price feed, id: ${c.id}, publish time: ${n.publishTime}, current timestamp: ${t}`
588
- ), a.push(c.id));
690
+ t - r.getPriceUnchecked().publishTime > 30 && (console.info(
691
+ `stale price feed, id: ${r.id}, publish time: ${n.publishTime}, current timestamp: ${t}`
692
+ ), a.push(r.id));
589
693
  }
590
694
  return a;
591
695
  } catch (a) {
592
696
  throw new Error(`failed to get pyth stale price feed id, msg: ${a.message}`);
593
697
  }
594
698
  }
595
- async function ae(e, a, r) {
699
+ async function ce(e, a, c) {
596
700
  var n;
597
- const t = (n = r == null ? void 0 : r.client) != null ? n : I, c = await w({
598
- ...r,
701
+ const t = (n = c == null ? void 0 : c.client) != null ? n : A, r = await b({
702
+ ...c,
599
703
  cacheTime: g
600
704
  });
601
705
  try {
602
706
  const o = await M.getPriceFeedsUpdateData(a);
603
- return await new Y(
707
+ return await new K(
604
708
  t,
605
- c.oracle.pythStateId,
606
- c.oracle.wormholeStateId
709
+ r.oracle.pythStateId,
710
+ r.oracle.wormholeStateId
607
711
  ).updatePriceFeeds(e, o, a);
608
712
  } catch (o) {
609
713
  throw new Error(`failed to update pyth price feeds, msg: ${o.message}`);
610
714
  }
611
715
  }
612
- async function $e(e, a, r) {
613
- const t = await w({
614
- ...r,
716
+ async function Ve(e, a, c) {
717
+ const t = await b({
718
+ ...c,
615
719
  cacheTime: g
616
720
  });
617
- if (r != null && r.updatePythPriceFeeds) {
618
- const c = a.filter((n) => !!n.pythPriceFeedId).map((n) => n.pythPriceFeedId);
721
+ if (c != null && c.updatePythPriceFeeds) {
722
+ const r = a.filter((n) => !!n.pythPriceFeedId).map((n) => n.pythPriceFeedId);
619
723
  try {
620
- const n = await te(c);
621
- n.length > 0 && await ae(e, n, r);
724
+ const n = await re(r);
725
+ n.length > 0 && await ce(e, n, c);
622
726
  } catch {
623
727
  }
624
728
  }
625
- for (const c of a)
729
+ for (const r of a)
626
730
  e.moveCall({
627
731
  target: `${t.oracle.packageId}::oracle_pro::update_single_price`,
628
732
  arguments: [
@@ -634,68 +738,82 @@ async function $e(e, a, r) {
634
738
  // Price oracle contract
635
739
  e.object(t.oracle.supraOracleHolder),
636
740
  // Supra oracle holder
637
- e.object(c.pythPriceInfoObject),
741
+ e.object(r.pythPriceInfoObject),
638
742
  // Pyth price info object
639
- e.pure.address(c.feedId)
743
+ e.pure.address(r.feedId)
640
744
  // Price feed ID
641
745
  ]
642
746
  });
643
747
  return e;
644
748
  }
645
- async function re(e) {
646
- return (await w({
749
+ async function ne(e) {
750
+ return (await b({
647
751
  ...e,
648
752
  cacheTime: g
649
753
  })).oracle.feeds;
650
754
  }
651
- function ke(e, a) {
652
- return e.filter((r) => !!(a != null && a.lendingState && a.lendingState.find((c) => c.assetId === r.assetId) || a != null && a.pools && a.pools.find((c) => c.id === r.assetId)));
755
+ function Se(e, a) {
756
+ return e.filter((c) => !!(a != null && a.lendingState && a.lendingState.find((r) => r.assetId === c.assetId) || a != null && a.pools && a.pools.find((r) => r.id === c.assetId)));
653
757
  }
654
- const F = A(
655
- _(async (e) => {
656
- const a = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${(e == null ? void 0 : e.env) || "prod"}`, r = await fetch(a).then((t) => t.json());
657
- return Object.keys(r.data).map((t) => ({
658
- ...r.data[t],
758
+ const S = I(
759
+ C(async (e) => {
760
+ const a = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${(e == null ? void 0 : e.env) || "prod"}`, c = await fetch(a).then((t) => t.json());
761
+ return Object.keys(c.data).map((t) => ({
762
+ ...c.data[t],
659
763
  coinType: t
660
764
  }));
661
765
  })
662
766
  );
663
- async function Se(e, a) {
664
- return (await F(a)).find((t) => typeof e == "string" ? m(t.coinType) === m(e) : typeof e == "number" ? t.assetId === e : t.assetId === e.id) || null;
767
+ async function Fe(e, a) {
768
+ return (await S(a)).find((t) => typeof e == "string" ? f(t.coinType) === f(e) : typeof e == "number" ? t.assetId === e : t.assetId === e.id) || null;
665
769
  }
666
- async function Fe(e, a, r, t) {
667
- const c = await w({
770
+ async function Re(e, a, c, t) {
771
+ const r = await b({
668
772
  ...t,
669
773
  cacheTime: g
670
- }), n = await C(a, t);
671
- if (!(await F({
774
+ }), n = await v(a, t);
775
+ if (!(await S({
672
776
  ...t,
673
777
  cacheTime: g
674
778
  })).some(
675
- (d) => m(d.coinType) === m(n.suiCoinType)
779
+ (u) => f(u.coinType) === f(n.suiCoinType)
676
780
  ))
677
781
  throw new Error("Pool does not support flashloan");
678
- const [u, l] = e.moveCall({
679
- target: `${c.package}::lending::flash_loan_with_ctx`,
680
- arguments: [
681
- e.object(c.flashloanConfig),
682
- e.object(n.contract.pool),
683
- f(r, e.pure.u64)
684
- ],
685
- typeArguments: [n.suiCoinType]
686
- });
687
- return [u, l];
782
+ if (r.version === 1) {
783
+ const [u, l] = e.moveCall({
784
+ target: `${r.package}::lending::flash_loan_with_ctx`,
785
+ arguments: [
786
+ e.object(r.flashloanConfig),
787
+ e.object(n.contract.pool),
788
+ d(c, e.pure.u64)
789
+ ],
790
+ typeArguments: [n.suiCoinType]
791
+ });
792
+ return [u, l];
793
+ } else {
794
+ const [u, l] = e.moveCall({
795
+ target: `${r.package}::lending::flash_loan_with_ctx_v2`,
796
+ arguments: [
797
+ e.object(r.flashloanConfig),
798
+ e.object(n.contract.pool),
799
+ d(c, e.pure.u64),
800
+ e.object("0x05")
801
+ ],
802
+ typeArguments: [n.suiCoinType]
803
+ });
804
+ return [u, l];
805
+ }
688
806
  }
689
- async function Re(e, a, r, t, c) {
690
- const n = await w({
691
- ...c,
807
+ async function Ne(e, a, c, t, r) {
808
+ const n = await b({
809
+ ...r,
692
810
  cacheTime: g
693
- }), o = await C(a, c);
694
- if (!(await F({
695
- ...c,
811
+ }), o = await v(a, r);
812
+ if (!(await S({
813
+ ...r,
696
814
  cacheTime: g
697
815
  })).some(
698
- (d) => m(d.coinType) === m(o.suiCoinType)
816
+ (p) => f(p.coinType) === f(o.suiCoinType)
699
817
  ))
700
818
  throw new Error("Pool does not support flashloan");
701
819
  const [l] = e.moveCall({
@@ -704,56 +822,91 @@ async function Re(e, a, r, t, c) {
704
822
  e.object("0x06"),
705
823
  e.object(n.storage),
706
824
  e.object(o.contract.pool),
707
- f(r, e.object),
708
- f(t, e.object)
825
+ d(c, e.object),
826
+ d(t, e.object)
709
827
  ],
710
828
  typeArguments: [o.suiCoinType]
711
829
  });
712
830
  return [l];
713
831
  }
714
- async function Ve(e, a, r, t, c, n) {
832
+ async function Ee(e, a, c, t, r, n) {
715
833
  const o = {
716
834
  ...n,
717
835
  cacheTime: g
718
- }, i = await w(o), u = await C(a, o), l = await C(t, o), [d, h] = e.moveCall({
719
- target: `${i.package}::incentive_v3::liquidation`,
720
- arguments: [
721
- e.object("0x06"),
722
- // Clock object
723
- e.object(i.priceOracle),
724
- // Price oracle for asset pricing
725
- e.object(i.storage),
726
- // Protocol storage
727
- e.pure.u8(u.id),
728
- // Pay asset ID
729
- e.object(u.contract.pool),
730
- // Pay asset pool contract
731
- f(r, e.object),
732
- // Debt repayment amount
733
- e.pure.u8(l.id),
734
- // Collateral asset ID
735
- e.object(l.contract.pool),
736
- // Collateral asset pool contract
737
- f(c, e.pure.address),
738
- // Borrower address
739
- e.object(i.incentiveV2),
740
- // Incentive V2 contract
741
- e.object(i.incentiveV3)
742
- // Incentive V3 contract
743
- ],
744
- typeArguments: [u.suiCoinType, l.suiCoinType]
745
- });
746
- return [d, h];
836
+ }, s = await b(o), u = await v(a, o), l = await v(t, o);
837
+ if (s.version === 1) {
838
+ const [p, w] = e.moveCall({
839
+ target: `${s.package}::incentive_v3::liquidation`,
840
+ arguments: [
841
+ e.object("0x06"),
842
+ // Clock object
843
+ e.object(s.priceOracle),
844
+ // Price oracle for asset pricing
845
+ e.object(s.storage),
846
+ // Protocol storage
847
+ e.pure.u8(u.id),
848
+ // Pay asset ID
849
+ e.object(u.contract.pool),
850
+ // Pay asset pool contract
851
+ d(c, e.object),
852
+ // Debt repayment amount
853
+ e.pure.u8(l.id),
854
+ // Collateral asset ID
855
+ e.object(l.contract.pool),
856
+ // Collateral asset pool contract
857
+ d(r, e.pure.address),
858
+ // Borrower address
859
+ e.object(s.incentiveV2),
860
+ // Incentive V2 contract
861
+ e.object(s.incentiveV3)
862
+ // Incentive V3 contract
863
+ ],
864
+ typeArguments: [u.suiCoinType, l.suiCoinType]
865
+ });
866
+ return [p, w];
867
+ } else {
868
+ const [p, w] = e.moveCall({
869
+ target: `${s.package}::incentive_v3::liquidation_v2`,
870
+ arguments: [
871
+ e.object("0x06"),
872
+ // Clock object
873
+ e.object(s.priceOracle),
874
+ // Price oracle for asset pricing
875
+ e.object(s.storage),
876
+ // Protocol storage
877
+ e.pure.u8(u.id),
878
+ // Pay asset ID
879
+ e.object(u.contract.pool),
880
+ // Pay asset pool contract
881
+ d(c, e.object),
882
+ // Debt repayment amount
883
+ e.pure.u8(l.id),
884
+ // Collateral asset ID
885
+ e.object(l.contract.pool),
886
+ // Collateral asset pool contract
887
+ d(r, e.pure.address),
888
+ // Borrower address
889
+ e.object(s.incentiveV2),
890
+ // Incentive V2 contract
891
+ e.object(s.incentiveV3),
892
+ // Incentive V3 contract
893
+ e.object("0x05")
894
+ // SuiSystemState object
895
+ ],
896
+ typeArguments: [u.suiCoinType, l.suiCoinType]
897
+ });
898
+ return [p, w];
899
+ }
747
900
  }
748
- async function Ee(e, a) {
749
- var d;
750
- const r = await re(a), t = await S({
901
+ async function De(e, a) {
902
+ var p;
903
+ const c = await ne(a), t = await V({
751
904
  ...a,
752
905
  cacheTime: g
753
- }), c = (d = a == null ? void 0 : a.client) != null ? d : I, n = await w({
906
+ }), r = (p = a == null ? void 0 : a.client) != null ? p : A, n = await b({
754
907
  ...a,
755
908
  cacheTime: g
756
- }), o = new $();
909
+ }), o = new k();
757
910
  o.moveCall({
758
911
  target: `${n.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
759
912
  arguments: [
@@ -767,114 +920,114 @@ async function Ee(e, a) {
767
920
  // User address
768
921
  ]
769
922
  });
770
- const i = await c.devInspectTransactionBlock({
923
+ const s = await r.devInspectTransactionBlock({
771
924
  transactionBlock: o,
772
925
  sender: e
773
- }), u = k(
774
- i,
926
+ }), u = B(
927
+ s,
775
928
  [
776
- b.vector(b.string()),
929
+ h.vector(h.string()),
777
930
  // Asset coin types
778
- b.vector(b.string()),
931
+ h.vector(h.string()),
779
932
  // Reward coin types
780
- b.vector(b.u8()),
933
+ h.vector(h.u8()),
781
934
  // Reward options
782
- b.vector(b.Address),
935
+ h.vector(h.Address),
783
936
  // Rule IDs
784
- b.vector(b.u256())
937
+ h.vector(h.u256())
785
938
  // Claimable amounts
786
939
  ]
787
940
  ), l = [];
788
941
  if (u.length === 5 && Array.isArray(u[0])) {
789
- const h = u[0].length;
790
- for (let p = 0; p < h; p++) {
791
- const y = r.find(
792
- (j) => m(j.coinType) === m(u[1][p])
793
- ), v = t.find(
794
- (j) => m(j.coinType) === m(u[0][p])
942
+ const w = u[0].length;
943
+ for (let m = 0; m < w; m++) {
944
+ const y = c.find(
945
+ (_) => f(_.coinType) === f(u[1][m])
946
+ ), j = t.find(
947
+ (_) => f(_.coinType) === f(u[0][m])
795
948
  );
796
- !y || !v || l.push({
797
- assetId: v.id,
798
- assetCoinType: m(u[0][p]),
799
- rewardCoinType: m(u[1][p]),
800
- option: Number(u[2][p]),
801
- userClaimableReward: Number(u[4][p]) / Math.pow(10, y.priceDecimal),
802
- ruleIds: Array.isArray(u[3][p]) ? u[3][p] : [u[3][p]]
949
+ !y || !j || l.push({
950
+ assetId: j.id,
951
+ assetCoinType: f(u[0][m]),
952
+ rewardCoinType: f(u[1][m]),
953
+ option: Number(u[2][m]),
954
+ userClaimableReward: Number(u[4][m]) / Math.pow(10, y.priceDecimal),
955
+ ruleIds: Array.isArray(u[3][m]) ? u[3][m] : [u[3][m]]
803
956
  });
804
957
  }
805
958
  }
806
959
  return l;
807
960
  }
808
- function Ne(e) {
961
+ function Le(e) {
809
962
  const a = /* @__PURE__ */ new Map();
810
963
  e.forEach((t) => {
811
- const c = t.assetId, n = t.option, o = `${c}-${n}-${t.rewardCoinType}`;
964
+ const r = t.assetId, n = t.option, o = `${r}-${n}-${t.rewardCoinType}`;
812
965
  a.has(o) ? a.get(o).total += t.userClaimableReward : a.set(o, {
813
- assetId: c,
966
+ assetId: r,
814
967
  rewardType: n,
815
968
  coinType: t.rewardCoinType,
816
969
  total: Number(t.userClaimableReward)
817
970
  });
818
971
  });
819
- const r = /* @__PURE__ */ new Map();
820
- for (const { assetId: t, rewardType: c, coinType: n, total: o } of a.values()) {
821
- const i = `${t}-${c}`;
822
- r.has(i) || r.set(i, { assetId: t, rewardType: c, rewards: /* @__PURE__ */ new Map() });
823
- const u = r.get(i);
972
+ const c = /* @__PURE__ */ new Map();
973
+ for (const { assetId: t, rewardType: r, coinType: n, total: o } of a.values()) {
974
+ const s = `${t}-${r}`;
975
+ c.has(s) || c.set(s, { assetId: t, rewardType: r, rewards: /* @__PURE__ */ new Map() });
976
+ const u = c.get(s);
824
977
  u.rewards.set(n, (u.rewards.get(n) || 0) + o);
825
978
  }
826
- return Array.from(r.values()).map((t) => ({
979
+ return Array.from(c.values()).map((t) => ({
827
980
  assetId: t.assetId,
828
981
  rewardType: t.rewardType,
829
- rewards: Array.from(t.rewards.entries()).map(([c, n]) => ({
830
- coinType: c,
982
+ rewards: Array.from(t.rewards.entries()).map(([r, n]) => ({
983
+ coinType: r,
831
984
  available: n.toFixed(6)
832
985
  }))
833
986
  }));
834
987
  }
835
- const Le = _(
988
+ const Me = C(
836
989
  async (e) => {
837
990
  const a = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}`;
838
991
  return (await fetch(a).then((t) => t.json())).data;
839
992
  }
840
- ), De = _(
993
+ ), Ue = C(
841
994
  async (e, a) => {
842
- const r = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${(a == null ? void 0 : a.page) || 1}&pageSize=${(a == null ? void 0 : a.size) || 400}`, t = await fetch(r).then((c) => c.json());
843
- return B({
995
+ const c = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${(a == null ? void 0 : a.page) || 1}&pageSize=${(a == null ? void 0 : a.size) || 400}`, t = await fetch(c).then((r) => r.json());
996
+ return P({
844
997
  data: t.data.rewards
845
998
  });
846
999
  }
847
1000
  );
848
- async function Me(e, a, r) {
849
- var i;
850
- const t = await w({
851
- ...r,
1001
+ async function Oe(e, a, c) {
1002
+ var s;
1003
+ const t = await b({
1004
+ ...c,
852
1005
  cacheTime: g
853
- }), c = await S({
854
- ...r,
1006
+ }), r = await V({
1007
+ ...c,
855
1008
  cacheTime: g
856
1009
  }), n = /* @__PURE__ */ new Map();
857
1010
  for (const u of a) {
858
- const { rewardCoinType: l, ruleIds: d } = u;
859
- for (const h of d) {
1011
+ const { rewardCoinType: l, ruleIds: p } = u;
1012
+ for (const w of p) {
860
1013
  n.has(l) || n.set(l, { assetIds: [], ruleIds: [], amount: 0 });
861
- const p = n.get(l);
862
- p.assetIds.push(u.assetCoinType.replace("0x", "")), p.ruleIds.push(h), p.amount += u.userClaimableReward;
1014
+ const m = n.get(l);
1015
+ m.assetIds.push(u.assetCoinType.replace("0x", "")), m.ruleIds.push(w), m.amount += u.userClaimableReward;
863
1016
  }
864
1017
  }
865
1018
  const o = [];
866
- for (const [u, { assetIds: l, ruleIds: d, amount: h }] of n) {
867
- const p = c.find(
868
- (v) => m(v.suiCoinType) === m(u)
1019
+ for (const [u, { assetIds: l, ruleIds: p, amount: w }] of n) {
1020
+ const m = r.find(
1021
+ (j) => f(j.suiCoinType) === f(u)
869
1022
  );
870
- if (!p || !p.contract.rewardFundId)
1023
+ if (!m || !m.contract.rewardFundId)
871
1024
  throw new Error(`No matching rewardFund found for reward coin: ${u}`);
872
- const y = p.contract.rewardFundId;
873
- if (r != null && r.accountCap && !r.customCoinReceive)
1025
+ const y = m.contract.rewardFundId;
1026
+ if (c != null && c.accountCap && !c.customCoinReceive)
874
1027
  throw new Error("customCoinReceive is required when accountCap is provided");
875
- if (r != null && r.customCoinReceive) {
876
- let v;
877
- r.accountCap ? v = e.moveCall({
1028
+ if (c != null && c.customCoinReceive) {
1029
+ let j;
1030
+ c.accountCap ? j = e.moveCall({
878
1031
  target: `${t.package}::incentive_v3::claim_reward_with_account_cap`,
879
1032
  arguments: [
880
1033
  e.object("0x06"),
@@ -887,13 +1040,13 @@ async function Me(e, a, r) {
887
1040
  // Reward fund
888
1041
  e.pure.vector("string", l),
889
1042
  // Asset IDs
890
- e.pure.vector("address", d),
1043
+ e.pure.vector("address", p),
891
1044
  // Rule IDs
892
- f(r.accountCap, e.object)
1045
+ d(c.accountCap, e.object)
893
1046
  // Account capability
894
1047
  ],
895
1048
  typeArguments: [u]
896
- }) : v = e.moveCall({
1049
+ }) : j = e.moveCall({
897
1050
  target: `${t.package}::incentive_v3::claim_reward`,
898
1051
  arguments: [
899
1052
  e.object("0x06"),
@@ -906,34 +1059,34 @@ async function Me(e, a, r) {
906
1059
  // Reward fund
907
1060
  e.pure.vector("string", l),
908
1061
  // Asset IDs
909
- e.pure.vector("address", d)
1062
+ e.pure.vector("address", p)
910
1063
  // Rule IDs
911
1064
  ],
912
1065
  typeArguments: [u]
913
1066
  });
914
- const [j] = e.moveCall({
1067
+ const [_] = e.moveCall({
915
1068
  target: "0x2::coin::from_balance",
916
- arguments: [v],
1069
+ arguments: [j],
917
1070
  typeArguments: [u]
918
1071
  });
919
- if ((r == null ? void 0 : r.customCoinReceive.type) === "transfer") {
920
- if (!r.customCoinReceive.transfer)
1072
+ if ((c == null ? void 0 : c.customCoinReceive.type) === "transfer") {
1073
+ if (!c.customCoinReceive.transfer)
921
1074
  throw new Error("customCoinReceive.transfer is required");
922
1075
  e.transferObjects(
923
- [j],
924
- f(r.customCoinReceive.transfer, e.pure.address)
1076
+ [_],
1077
+ d(c.customCoinReceive.transfer, e.pure.address)
925
1078
  );
926
1079
  }
927
- if ((r == null ? void 0 : r.customCoinReceive.type) === "depositNAVI") {
928
- const U = T(p.totalSupplyAmount).shiftedBy(-9), G = T(p.supplyCapCeiling).shiftedBy(-27);
929
- U.plus(h).isGreaterThan(G) && ((i = r == null ? void 0 : r.customCoinReceive.depositNAVI) != null && i.fallbackReceiveAddress) ? e.transferObjects(
930
- [j],
931
- e.pure.address(r.customCoinReceive.depositNAVI.fallbackReceiveAddress)
932
- ) : await x(e, p, j, r);
1080
+ if ((c == null ? void 0 : c.customCoinReceive.type) === "depositNAVI") {
1081
+ const U = T(m.totalSupplyAmount).shiftedBy(-9), O = T(m.supplyCapCeiling).shiftedBy(-27);
1082
+ U.plus(w).isGreaterThan(O) && ((s = c == null ? void 0 : c.customCoinReceive.depositNAVI) != null && s.fallbackReceiveAddress) ? e.transferObjects(
1083
+ [_],
1084
+ e.pure.address(c.customCoinReceive.depositNAVI.fallbackReceiveAddress)
1085
+ ) : await te(e, m, _, c);
933
1086
  } else
934
1087
  o.push({
935
- coin: j,
936
- identifier: p
1088
+ coin: _,
1089
+ identifier: m
937
1090
  });
938
1091
  } else
939
1092
  e.moveCall({
@@ -949,7 +1102,7 @@ async function Me(e, a, r) {
949
1102
  // Reward fund
950
1103
  e.pure.vector("string", l),
951
1104
  // Asset IDs
952
- e.pure.vector("address", d)
1105
+ e.pure.vector("address", p)
953
1106
  // Rule IDs
954
1107
  ],
955
1108
  typeArguments: [u]
@@ -957,63 +1110,63 @@ async function Me(e, a, r) {
957
1110
  }
958
1111
  return o;
959
1112
  }
960
- async function Ue(e, a) {
961
- const r = await w({
1113
+ async function Ge(e, a) {
1114
+ const c = await b({
962
1115
  ...a
963
1116
  });
964
1117
  return e.moveCall({
965
- target: `${r.package}::lending::create_account`,
1118
+ target: `${c.package}::lending::create_account`,
966
1119
  arguments: []
967
1120
  });
968
1121
  }
969
1122
  export {
970
- R as Address,
1123
+ F as Address,
971
1124
  g as DEFAULT_CACHE_TIME,
972
- ge as FlashLoanAssetConfig,
973
- pe as IncentiveAPYInfo,
974
- J as IncentivePoolInfo,
975
- fe as IncentivePoolInfoByPhase,
976
- me as OracleInfo,
977
- P as PoolOperator,
978
- ye as ReserveDataInfo,
1125
+ be as FlashLoanAssetConfig,
1126
+ fe as IncentiveAPYInfo,
1127
+ Y as IncentivePoolInfo,
1128
+ ge as IncentivePoolInfoByPhase,
1129
+ ye as OracleInfo,
1130
+ $ as PoolOperator,
1131
+ we as ReserveDataInfo,
979
1132
  Q as UserStateInfo,
980
- ve as borrowCoinPTB,
981
- Me as claimLendingRewardsPTB,
982
- Ue as createAccountCapPTB,
983
- x as depositCoinPTB,
984
- ke as filterPriceFeeds,
985
- Fe as flashloanPTB,
986
- F as getAllFlashLoanAssets,
987
- _e as getBorrowFee,
988
- Be as getCoins,
989
- w as getConfig,
990
- he as getFees,
991
- Se as getFlashLoanAsset,
992
- Ie as getHealthFactor,
993
- ee as getHealthFactorPTB,
994
- Te as getLendingState,
995
- C as getPool,
996
- S as getPools,
997
- re as getPriceFeeds,
998
- te as getPythStalePriceFeedId,
999
- Ae as getSimulatedHealthFactor,
1000
- D as getSimulatedHealthFactorPTB,
1001
- we as getStats,
1002
- Pe as getTransactions,
1003
- Ee as getUserAvailableLendingRewards,
1004
- De as getUserClaimedRewardHistory,
1005
- Le as getUserTotalClaimedReward,
1006
- Ve as liquidatePTB,
1007
- je as mergeCoinsPTB,
1008
- m as normalizeCoinType,
1009
- f as parseTxValue,
1010
- Ce as repayCoinPTB,
1011
- Re as repayFlashLoanPTB,
1012
- Ne as summaryLendingRewards,
1013
- $e as updateOraclePricesPTB,
1014
- ae as updatePythPriceFeeds,
1015
- A as withCache,
1016
- _ as withSingleton,
1017
- be as withdrawCoinPTB
1133
+ Ce as borrowCoinPTB,
1134
+ Oe as claimLendingRewardsPTB,
1135
+ Ge as createAccountCapPTB,
1136
+ te as depositCoinPTB,
1137
+ Se as filterPriceFeeds,
1138
+ Re as flashloanPTB,
1139
+ S as getAllFlashLoanAssets,
1140
+ Te as getBorrowFee,
1141
+ Pe as getCoins,
1142
+ b as getConfig,
1143
+ ve as getFees,
1144
+ Fe as getFlashLoanAsset,
1145
+ $e as getHealthFactor,
1146
+ ae as getHealthFactorPTB,
1147
+ Ie as getLendingState,
1148
+ v as getPool,
1149
+ V as getPools,
1150
+ ne as getPriceFeeds,
1151
+ re as getPythStalePriceFeedId,
1152
+ ke as getSimulatedHealthFactor,
1153
+ L as getSimulatedHealthFactorPTB,
1154
+ he as getStats,
1155
+ Be as getTransactions,
1156
+ De as getUserAvailableLendingRewards,
1157
+ Ue as getUserClaimedRewardHistory,
1158
+ Me as getUserTotalClaimedReward,
1159
+ Ee as liquidatePTB,
1160
+ Ae as mergeCoinsPTB,
1161
+ f as normalizeCoinType,
1162
+ d as parseTxValue,
1163
+ _e as repayCoinPTB,
1164
+ Ne as repayFlashLoanPTB,
1165
+ Le as summaryLendingRewards,
1166
+ Ve as updateOraclePricesPTB,
1167
+ ce as updatePythPriceFeeds,
1168
+ I as withCache,
1169
+ C as withSingleton,
1170
+ je as withdrawCoinPTB
1018
1171
  };
1019
1172
  //# sourceMappingURL=index.esm.js.map