@naviprotocol/lending 1.3.0-dev.5 → 1.3.0-dev.7

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,660 +1,732 @@
1
- import { Transaction as B } 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 N, 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
8
  import { bcs as h } from "@mysten/sui/bcs";
9
- const V = s.bytes(32).transform({
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
- }), fe = 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: V,
22
+ pool_id: F,
23
23
  /** Address holding the incentive funds */
24
- funds: V,
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
- }), me = 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
- }), pe = 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
135
  function E(e) {
136
- const r = [];
137
- return e.forEach((a, t) => {
138
- const c = t === e.length - 1;
139
- if (typeof a == "object" && c) {
140
- const { client: n, disableCache: o, cacheTime: i, ...u } = a;
141
- r.push(u);
136
+ const a = [];
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
+ a.push(u);
142
142
  } else
143
- r.push(a);
144
- }), JSON.stringify(r);
143
+ a.push(c);
144
+ }), JSON.stringify(a);
145
145
  }
146
- function _(e) {
147
- const r = {};
148
- return (...a) => {
149
- const t = E(a);
150
- return r[t] || (r[t] = e(...a).finally(() => {
151
- r[t] = null;
152
- })), r[t];
146
+ function C(e) {
147
+ const a = {};
148
+ return (...c) => {
149
+ const t = E(c);
150
+ return a[t] || (a[t] = e(...c).finally(() => {
151
+ a[t] = null;
152
+ })), a[t];
153
153
  };
154
154
  }
155
- function A(e) {
156
- let r = {};
157
- return (...a) => {
158
- const t = a[a.length - 1], c = E(a), n = r[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(...a).then((o) => (r[c] = {
155
+ function I(e) {
156
+ let a = {};
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 k(e) {
166
- return Array.isArray(e) ? e.map((r) => k(r)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
167
- (r, a) => ({
168
- ...r,
169
- [W(a)]: k(e[a])
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
+ ...a,
169
+ [W(c)]: P(e[c])
170
170
  }),
171
171
  {}
172
172
  ) : e;
173
173
  }
174
- function m(e, r) {
175
- return typeof e == "object" ? e : r(e);
174
+ function d(e, a) {
175
+ return typeof e == "object" ? e : a(e);
176
176
  }
177
- function X(e, r) {
178
- return typeof r == "string" ? e.object(r) : typeof r == "object" && r.$kind ? r : e.object(r.contract.pool);
177
+ function X(e, a) {
178
+ return typeof a == "string" ? e.object(a) : typeof a == "object" && a.$kind ? a : e.object(a.contract.pool);
179
179
  }
180
- function $(e, r, a) {
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) => (r[c] || r[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 p(e) {
189
- return K(e);
188
+ function f(e) {
189
+ return J(e);
190
190
  }
191
- function L(e) {
192
- const r = (e || 0) / Math.pow(10, 27);
193
- return r > Math.pow(10, 5) ? 1 / 0 : r;
191
+ function D(e) {
192
+ const a = (e || 0) / Math.pow(10, 27);
193
+ return a > Math.pow(10, 5) ? 1 / 0 : a;
194
194
  }
195
195
  new N("https://hermes.pyth.network", {
196
196
  timeout: 2e4
197
197
  });
198
- const Z = 27, R = (e, r) => {
199
- if (!Number(e) || !Number(r)) return new T(0);
200
- const a = new T(1).shiftedBy(1 * Z), t = a.multipliedBy(new T(0.5));
201
- return new T(e).multipliedBy(new T(r)).plus(t).dividedBy(a).integerValue(T.ROUND_DOWN);
202
- }, w = A(
203
- _(async (e) => {
204
- const r = `https://open-api.naviprotocol.io/api/navi/config?env=${(e == null ? void 0 : e.env) || "prod"}&v=2`;
205
- return (await fetch(r).then((t) => t.json())).data;
198
+ const Z = 27, R = (e, a) => {
199
+ if (!Number(e) || !Number(a)) return new T(0);
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-dev.7", 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}`;
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) => {
211
- const r = `https://open-api.naviprotocol.io/api/navi/pools?env=${(e == null ? void 0 : e.env) || "prod"}`;
212
- return (await fetch(r).then((t) => t.json())).data;
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) => {
213
+ const a = `https://open-api.naviprotocol.io/api/navi/pools?env=${(e == null ? void 0 : e.env) || "prod"}`;
214
+ return (await fetch(a).then((t) => t.json())).data;
213
215
  })
214
216
  );
215
- async function v(e, r) {
216
- const a = await S({
217
- ...r,
217
+ async function v(e, a) {
218
+ const c = await V({
219
+ ...a,
218
220
  cacheTime: g
219
221
  });
220
222
  if (typeof e == "object")
221
223
  return e;
222
- const t = a.find((c) => typeof e == "string" ? p(c.suiCoinType) === p(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, r, a, 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 v(r, t), o = typeof a == "object" && a.$kind === "GasCoin";
239
- if (p(n.suiCoinType) === p("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
- a = e.splitCoins(a, [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 = m(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: [m(a, 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
- m(a, e.object),
257
- e.object(c.incentiveV2),
258
- e.object(c.incentiveV3),
259
- m(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
- m(a, 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]
275
- }), n.id === 0 && e.moveCall({
276
- target: `${c.package}::pool::refresh_stake`,
277
+ }), r.version === 2 && n.id === 0 && e.moveCall({
278
+ target: `${r.package}::pool::refresh_stake`,
277
279
  arguments: [e.object(n.contract.pool), e.object("0x05")]
278
280
  }), e;
279
281
  }
280
- async function be(e, r, a, t) {
281
- const c = await w({
282
+ async function je(e, a, c, t) {
283
+ const r = await b({
282
284
  ...t,
283
285
  cacheTime: g
284
- }), n = await v(r, t), o = m(a, e.pure.u64);
285
- let i;
286
- 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) {
287
324
  const [l] = e.moveCall({
288
- target: `${c.package}::incentive_v3::withdraw_with_account_cap_v2`,
325
+ target: `${r.package}::incentive_v3::withdraw_with_account_cap_v2`,
289
326
  arguments: [
290
327
  e.object("0x06"),
291
- e.object(c.priceOracle),
292
- e.object(c.storage),
328
+ e.object(r.priceOracle),
329
+ e.object(r.storage),
293
330
  e.object(n.contract.pool),
294
331
  e.pure.u8(n.id),
295
332
  o,
296
- e.object(c.incentiveV2),
297
- e.object(c.incentiveV3),
298
- m(t.accountCap, e.object),
333
+ e.object(r.incentiveV2),
334
+ e.object(r.incentiveV3),
335
+ d(t.accountCap, e.object),
299
336
  e.object("0x05")
300
337
  ],
301
338
  typeArguments: [n.suiCoinType]
302
339
  });
303
- i = l;
340
+ s = l;
304
341
  } else {
305
342
  const [l] = e.moveCall({
306
- target: `${c.package}::incentive_v3::withdraw_v2`,
343
+ target: `${r.package}::incentive_v3::withdraw_v2`,
307
344
  arguments: [
308
345
  e.object("0x06"),
309
- e.object(c.priceOracle),
310
- e.object(c.storage),
346
+ e.object(r.priceOracle),
347
+ e.object(r.storage),
311
348
  e.object(n.contract.pool),
312
349
  e.pure.u8(n.id),
313
350
  o,
314
- e.object(c.incentiveV2),
315
- e.object(c.incentiveV3),
351
+ e.object(r.incentiveV2),
352
+ e.object(r.incentiveV3),
316
353
  e.object("0x05")
317
354
  ],
318
355
  typeArguments: [n.suiCoinType]
319
356
  });
320
- i = l;
357
+ s = l;
321
358
  }
322
359
  return e.moveCall({
323
360
  target: "0x2::coin::from_balance",
324
- arguments: [i],
361
+ arguments: [s],
325
362
  typeArguments: [n.suiCoinType]
326
363
  });
327
364
  }
328
- async function ve(e, r, a, t) {
329
- const c = await w({
365
+ async function Ce(e, a, c, t) {
366
+ const r = await b({
330
367
  ...t,
331
368
  cacheTime: g
332
- }), n = await v(r, t), o = m(a, e.pure.u64);
333
- let i;
334
- 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) {
335
407
  const [l] = e.moveCall({
336
- target: `${c.package}::incentive_v3::borrow_with_account_cap_v2`,
408
+ target: `${r.package}::incentive_v3::borrow_with_account_cap_v2`,
337
409
  arguments: [
338
410
  e.object("0x06"),
339
- e.object(c.priceOracle),
340
- e.object(c.storage),
411
+ e.object(r.priceOracle),
412
+ e.object(r.storage),
341
413
  e.object(n.contract.pool),
342
414
  e.pure.u8(n.id),
343
415
  o,
344
- e.object(c.incentiveV2),
345
- e.object(c.incentiveV3),
346
- m(t.accountCap, e.object),
416
+ e.object(r.incentiveV2),
417
+ e.object(r.incentiveV3),
418
+ d(t.accountCap, e.object),
347
419
  e.object("0x05")
348
420
  ],
349
421
  typeArguments: [n.suiCoinType]
350
422
  });
351
- i = l;
423
+ s = l;
352
424
  } else {
353
425
  const [l] = e.moveCall({
354
- target: `${c.package}::incentive_v3::borrow_v2`,
426
+ target: `${r.package}::incentive_v3::borrow_v2`,
355
427
  arguments: [
356
428
  e.object("0x06"),
357
- e.object(c.priceOracle),
358
- e.object(c.storage),
429
+ e.object(r.priceOracle),
430
+ e.object(r.storage),
359
431
  e.object(n.contract.pool),
360
432
  e.pure.u8(n.id),
361
433
  o,
362
- e.object(c.incentiveV2),
363
- e.object(c.incentiveV3),
434
+ e.object(r.incentiveV2),
435
+ e.object(r.incentiveV3),
364
436
  e.object("0x05")
365
437
  ],
366
438
  typeArguments: [n.suiCoinType]
367
439
  });
368
- i = l;
440
+ s = l;
369
441
  }
370
442
  return e.moveCall({
371
443
  target: "0x2::coin::from_balance",
372
- arguments: [e.object(i)],
444
+ arguments: [e.object(s)],
373
445
  typeArguments: [n.suiCoinType]
374
446
  });
375
447
  }
376
- async function Ce(e, r, a, t) {
377
- const c = await w({
448
+ async function _e(e, a, c, t) {
449
+ const r = await b({
378
450
  ...t,
379
451
  cacheTime: g
380
- }), n = await v(r, t), o = typeof a == "object" && a.$kind === "GasCoin";
381
- if (p(n.suiCoinType) === p("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) {
382
454
  if (!(t != null && t.amount))
383
455
  throw new Error("Amount is required for sui coin");
384
- a = e.splitCoins(a, [t.amount]);
456
+ c = e.splitCoins(c, [t.amount]);
385
457
  }
386
- let i;
387
- return typeof (t == null ? void 0 : t.amount) != "undefined" ? i = m(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({
388
460
  target: "0x2::coin::value",
389
- arguments: [m(a, e.object)],
461
+ arguments: [d(c, e.object)],
390
462
  typeArguments: [n.suiCoinType]
391
463
  }), t != null && t.accountCap ? e.moveCall({
392
- target: `${c.package}::incentive_v3::repay_with_account_cap`,
464
+ target: `${r.package}::incentive_v3::repay_with_account_cap`,
393
465
  arguments: [
394
466
  e.object("0x06"),
395
- e.object(c.priceOracle),
396
- e.object(c.storage),
467
+ e.object(r.priceOracle),
468
+ e.object(r.storage),
397
469
  e.object(n.contract.pool),
398
470
  e.pure.u8(n.id),
399
- m(a, e.object),
400
- i,
401
- e.object(c.incentiveV2),
402
- e.object(c.incentiveV3),
403
- m(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)
404
476
  ],
405
477
  typeArguments: [n.suiCoinType]
406
478
  }) : e.moveCall({
407
- target: `${c.package}::incentive_v3::entry_repay`,
479
+ target: `${r.package}::incentive_v3::entry_repay`,
408
480
  arguments: [
409
481
  e.object("0x06"),
410
- e.object(c.priceOracle),
411
- e.object(c.storage),
482
+ e.object(r.priceOracle),
483
+ e.object(r.storage),
412
484
  e.object(n.contract.pool),
413
485
  e.pure.u8(n.id),
414
- m(a, e.object),
415
- i,
416
- e.object(c.incentiveV2),
417
- e.object(c.incentiveV3)
486
+ d(c, e.object),
487
+ s,
488
+ e.object(r.incentiveV2),
489
+ e.object(r.incentiveV3)
418
490
  ],
419
491
  typeArguments: [n.suiCoinType]
420
492
  }), e;
421
493
  }
422
- const _e = A(
423
- _(
494
+ const Te = I(
495
+ C(
424
496
  async (e) => {
425
- var c;
426
- const r = await w({
497
+ var r;
498
+ const a = await b({
427
499
  ...e
428
500
  });
429
501
  if (e != null && e.address && typeof (e == null ? void 0 : e.asset) != "undefined")
430
502
  try {
431
- const n = await v(e.asset, e), o = (c = e == null ? void 0 : e.client) != null ? c : I, i = new B();
432
- i.moveCall({
433
- target: `${r.package}::incentive_v3::get_borrow_fee_v2`,
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`,
434
506
  arguments: [
435
- i.object(r.incentiveV3),
436
- i.pure.address(e.address),
437
- i.pure.u8(n.id),
438
- i.pure.u64(1e4)
507
+ s.object(a.incentiveV3),
508
+ s.pure.address(e.address),
509
+ s.pure.u8(n.id),
510
+ s.pure.u64(1e4)
439
511
  ],
440
512
  typeArguments: []
441
513
  });
442
514
  const u = await o.devInspectTransactionBlock({
443
- transactionBlock: i,
515
+ transactionBlock: s,
444
516
  sender: e.address
445
- }), l = $(u, [h.u64()]);
517
+ }), l = B(u, [h.u64()]);
446
518
  return (Number(l[0]) || 0) / 100;
447
519
  } catch (n) {
448
520
  console.error(n);
449
521
  }
450
- const t = (await I.getObject({
451
- id: r.incentiveV3,
522
+ const t = (await A.getObject({
523
+ id: a.incentiveV3,
452
524
  options: { showType: !0, showOwner: !0, showContent: !0 }
453
525
  })).data.content.fields.borrow_fee_rate;
454
526
  return Number(t) / 100;
455
527
  }
456
528
  )
457
529
  );
458
- function je(e, r, a) {
459
- const t = typeof (a == null ? void 0 : a.balance) == "number", c = t ? a.balance : 0;
530
+ function Ae(e, a, c) {
531
+ const t = typeof (c == null ? void 0 : c.balance) == "number", r = t ? c.balance : 0;
460
532
  let n = 0;
461
533
  const o = [];
462
- let i = "";
463
- if (r.sort((l, d) => Number(d.balance) - Number(l.balance)).forEach((l) => {
464
- if (!(t && n >= c) && Number(l.balance) !== 0) {
465
- 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)
466
538
  throw new Error("All coins must be of the same type");
467
539
  n += Number(l.balance), o.push(l.coinObjectId);
468
540
  }
469
541
  }), o.length === 0)
470
542
  throw new Error("No coins to merge");
471
- if (t && n < c)
543
+ if (t && n < r)
472
544
  throw new Error(
473
- `Balance is less than the specified balance: ${n} < ${c}`
545
+ `Balance is less than the specified balance: ${n} < ${r}`
474
546
  );
475
- if (p(i) === p("0x2::sui::SUI") && (a != null && a.useGasCoin))
476
- 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;
477
549
  const u = o.length === 1 ? e.object(o[0]) : e.mergeCoins(o[0], o.slice(1));
478
- return t ? e.splitCoins(u, [e.pure.u64(c)]) : u;
550
+ return t ? e.splitCoins(u, [e.pure.u64(r)]) : u;
479
551
  }
480
- async function D(e, r, a, t, c, n, o) {
481
- const i = await w({
552
+ async function L(e, a, c, t, r, n, o) {
553
+ const s = await b({
482
554
  ...o,
483
555
  cacheTime: g
484
- }), u = await v(a, o);
556
+ }), u = await v(c, o);
485
557
  return e.moveCall({
486
- target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
558
+ target: `${s.uiGetter}::calculator_unchecked::dynamic_health_factor`,
487
559
  arguments: [
488
560
  e.object("0x06"),
489
- e.object(i.storage),
490
- e.object(i.oracle.priceOracle),
561
+ e.object(s.storage),
562
+ e.object(s.oracle.priceOracle),
491
563
  X(e, u),
492
- m(r, e.pure.address),
493
- m(u.id, e.pure.u8),
494
- m(t, e.pure.u64),
495
- m(c, e.pure.u64),
496
- m(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)
497
569
  ],
498
570
  typeArguments: [u.suiCoinType]
499
571
  });
500
572
  }
501
- async function ee(e, r, a) {
502
- return D(e, r, 0, 0, 0, !1, a);
573
+ async function ae(e, a, c) {
574
+ return L(e, a, 0, 0, 0, !1, c);
503
575
  }
504
- const Te = A(
505
- async (e, r) => {
576
+ const Ie = I(
577
+ async (e, a) => {
506
578
  var l;
507
- const a = await w({
508
- ...r,
579
+ const c = await b({
580
+ ...a,
509
581
  cacheTime: g
510
- }), t = new B(), c = (l = r == null ? void 0 : r.client) != null ? l : I, n = await S(r);
582
+ }), t = new k(), r = (l = a == null ? void 0 : a.client) != null ? l : A, n = await V(a);
511
583
  t.moveCall({
512
- target: `${a.uiGetter}::getter_unchecked::get_user_state`,
513
- arguments: [t.object(a.storage), t.pure.address(e)]
584
+ target: `${c.uiGetter}::getter_unchecked::get_user_state`,
585
+ arguments: [t.object(c.storage), t.pure.address(e)]
514
586
  });
515
- const o = await c.devInspectTransactionBlock({
587
+ const o = await r.devInspectTransactionBlock({
516
588
  transactionBlock: t,
517
589
  sender: e
518
- }), i = $(o, [h.vector(Q)]);
519
- return k(
520
- i[0].filter((d) => d.supply_balance !== "0" || d.borrow_balance !== "0")
521
- ).map((d) => {
522
- const b = n.find((C) => C.id === d.assetId), f = R(
523
- d.supplyBalance,
524
- b.currentSupplyIndex
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
525
597
  ).toString(), y = R(
526
- d.borrowBalance,
527
- b.currentBorrowIndex
598
+ p.borrowBalance,
599
+ w.currentBorrowIndex
528
600
  ).toString();
529
601
  return {
530
- ...d,
531
- supplyBalance: f,
602
+ ...p,
603
+ supplyBalance: m,
532
604
  borrowBalance: y,
533
- pool: b
605
+ pool: w
534
606
  };
535
- }).filter((d) => !!d.pool);
607
+ }).filter((p) => !!p.pool);
536
608
  }
537
609
  );
538
- async function Ie(e, r) {
610
+ async function $e(e, a) {
539
611
  var o;
540
- const a = (o = r == null ? void 0 : r.client) != null ? o : I, t = new B();
541
- await ee(t, e, r);
542
- const c = await a.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({
543
615
  transactionBlock: t,
544
616
  sender: e
545
- }), n = $(c, [h.u256()]);
546
- return L(Number(n[0]) || 0);
617
+ }), n = B(r, [h.u256()]);
618
+ return D(Number(n[0]) || 0);
547
619
  }
548
- async function Ae(e, r, a, t) {
549
- var f;
550
- const c = (f = t == null ? void 0 : t.client) != null ? f : I, n = new B();
551
- let o = 0, i = 0;
552
- const u = await v(r, t);
553
- if (a.forEach((y) => {
554
- 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);
555
- }), 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)
556
628
  throw new Error("Invalid operations");
557
- const l = o > 0 || i > 0;
558
- await D(
629
+ const l = o > 0 || s > 0;
630
+ await L(
559
631
  n,
560
632
  e,
561
633
  u,
562
634
  Math.abs(o),
563
- Math.abs(i),
635
+ Math.abs(s),
564
636
  l,
565
637
  t
566
638
  );
567
- const d = await c.devInspectTransactionBlock({
639
+ const p = await r.devInspectTransactionBlock({
568
640
  transactionBlock: n,
569
641
  sender: e
570
- }), b = $(d, [h.u256()]);
571
- return L(Number(b[0]) || 0);
642
+ }), w = B(p, [h.u256()]);
643
+ return D(Number(w[0]) || 0);
572
644
  }
573
- const Pe = _(
574
- async (e, r) => {
575
- const a = new URLSearchParams();
576
- r != null && r.cursor && a.set("cursor", r.cursor), a.set("userAddress", e);
577
- const t = `https://open-api.naviprotocol.io/api/navi/user/transactions?${a.toString()}`;
645
+ const Be = C(
646
+ async (e, a) => {
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()}`;
578
650
  return (await fetch(t).then((n) => n.json())).data;
579
651
  }
580
652
  );
581
- async function Be(e, r) {
653
+ async function Pe(e, a) {
582
654
  var n;
583
- let a = null;
584
- const t = [], c = (n = r == null ? void 0 : r.client) != null ? n : I;
655
+ let c = null;
656
+ const t = [], r = (n = a == null ? void 0 : a.client) != null ? n : A;
585
657
  do {
586
658
  let o;
587
- if (r != null && r.coinType ? o = await c.getCoins({
659
+ if (a != null && a.coinType ? o = await r.getCoins({
588
660
  owner: e,
589
- coinType: r == null ? void 0 : r.coinType,
590
- cursor: a,
661
+ coinType: a == null ? void 0 : a.coinType,
662
+ cursor: c,
591
663
  limit: 100
592
- }) : o = await c.getAllCoins({
664
+ }) : o = await r.getAllCoins({
593
665
  owner: e,
594
- cursor: a,
666
+ cursor: c,
595
667
  limit: 100
596
668
  }), !o.data || !o.data.length)
597
669
  break;
598
- t.push(...o.data), a = o.nextCursor;
599
- } while (a);
670
+ t.push(...o.data), c = o.nextCursor;
671
+ } while (c);
600
672
  return t;
601
673
  }
602
674
  const M = new N("https://hermes.pyth.network", {
603
675
  timeout: 1e4
604
676
  });
605
- async function te(e) {
677
+ async function re(e) {
606
678
  try {
607
- const r = [], a = await M.getLatestPriceFeeds(e);
608
- if (!a) return r;
679
+ const a = [], c = await M.getLatestPriceFeeds(e);
680
+ if (!c) return a;
609
681
  const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
610
- for (const c of a) {
611
- const n = c.getPriceUnchecked();
682
+ for (const r of c) {
683
+ const n = r.getPriceUnchecked();
612
684
  if (n.publishTime > t) {
613
685
  console.warn(
614
- `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}`
615
687
  );
616
688
  continue;
617
689
  }
618
- t - c.getPriceUnchecked().publishTime > 30 && (console.info(
619
- `stale price feed, id: ${c.id}, publish time: ${n.publishTime}, current timestamp: ${t}`
620
- ), r.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));
621
693
  }
622
- return r;
623
- } catch (r) {
624
- throw new Error(`failed to get pyth stale price feed id, msg: ${r.message}`);
694
+ return a;
695
+ } catch (a) {
696
+ throw new Error(`failed to get pyth stale price feed id, msg: ${a.message}`);
625
697
  }
626
698
  }
627
- async function re(e, r, a) {
699
+ async function ce(e, a, c) {
628
700
  var n;
629
- const t = (n = a == null ? void 0 : a.client) != null ? n : I, c = await w({
630
- ...a,
701
+ const t = (n = c == null ? void 0 : c.client) != null ? n : A, r = await b({
702
+ ...c,
631
703
  cacheTime: g
632
704
  });
633
705
  try {
634
- const o = await M.getPriceFeedsUpdateData(r);
635
- return await new Y(
706
+ const o = await M.getPriceFeedsUpdateData(a);
707
+ return await new K(
636
708
  t,
637
- c.oracle.pythStateId,
638
- c.oracle.wormholeStateId
639
- ).updatePriceFeeds(e, o, r);
709
+ r.oracle.pythStateId,
710
+ r.oracle.wormholeStateId
711
+ ).updatePriceFeeds(e, o, a);
640
712
  } catch (o) {
641
713
  throw new Error(`failed to update pyth price feeds, msg: ${o.message}`);
642
714
  }
643
715
  }
644
- async function $e(e, r, a) {
645
- const t = await w({
646
- ...a,
716
+ async function Ve(e, a, c) {
717
+ const t = await b({
718
+ ...c,
647
719
  cacheTime: g
648
720
  });
649
- if (a != null && a.updatePythPriceFeeds) {
650
- const c = r.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);
651
723
  try {
652
- const n = await te(c);
653
- n.length > 0 && await re(e, n, a);
724
+ const n = await re(r);
725
+ n.length > 0 && await ce(e, n, c);
654
726
  } catch {
655
727
  }
656
728
  }
657
- for (const c of r)
729
+ for (const r of a)
658
730
  e.moveCall({
659
731
  target: `${t.oracle.packageId}::oracle_pro::update_single_price`,
660
732
  arguments: [
@@ -666,69 +738,82 @@ async function $e(e, r, a) {
666
738
  // Price oracle contract
667
739
  e.object(t.oracle.supraOracleHolder),
668
740
  // Supra oracle holder
669
- e.object(c.pythPriceInfoObject),
741
+ e.object(r.pythPriceInfoObject),
670
742
  // Pyth price info object
671
- e.pure.address(c.feedId)
743
+ e.pure.address(r.feedId)
672
744
  // Price feed ID
673
745
  ]
674
746
  });
675
747
  return e;
676
748
  }
677
- async function ae(e) {
678
- return (await w({
749
+ async function ne(e) {
750
+ return (await b({
679
751
  ...e,
680
752
  cacheTime: g
681
753
  })).oracle.feeds;
682
754
  }
683
- function ke(e, r) {
684
- return e.filter((a) => !!(r != null && r.lendingState && r.lendingState.find((c) => c.assetId === a.assetId) || r != null && r.pools && r.pools.find((c) => c.id === a.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)));
685
757
  }
686
- const F = A(
687
- _(async (e) => {
688
- const r = `https://open-api.naviprotocol.io/api/navi/flashloan?env=${(e == null ? void 0 : e.env) || "prod"}`, a = await fetch(r).then((t) => t.json());
689
- return Object.keys(a.data).map((t) => ({
690
- ...a.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],
691
763
  coinType: t
692
764
  }));
693
765
  })
694
766
  );
695
- async function Se(e, r) {
696
- return (await F(r)).find((t) => typeof e == "string" ? p(t.coinType) === p(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;
697
769
  }
698
- async function Fe(e, r, a, t) {
699
- const c = await w({
770
+ async function Re(e, a, c, t) {
771
+ const r = await b({
700
772
  ...t,
701
773
  cacheTime: g
702
- }), n = await v(r, t);
703
- if (!(await F({
774
+ }), n = await v(a, t);
775
+ if (!(await S({
704
776
  ...t,
705
777
  cacheTime: g
706
778
  })).some(
707
- (d) => p(d.coinType) === p(n.suiCoinType)
779
+ (u) => f(u.coinType) === f(n.suiCoinType)
708
780
  ))
709
781
  throw new Error("Pool does not support flashloan");
710
- const [u, l] = e.moveCall({
711
- target: `${c.package}::lending::flash_loan_with_ctx_v2`,
712
- arguments: [
713
- e.object(c.flashloanConfig),
714
- e.object(n.contract.pool),
715
- m(a, e.pure.u64),
716
- e.object("0x05")
717
- ],
718
- typeArguments: [n.suiCoinType]
719
- });
720
- 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
+ }
721
806
  }
722
- async function Ve(e, r, a, t, c) {
723
- const n = await w({
724
- ...c,
807
+ async function Ne(e, a, c, t, r) {
808
+ const n = await b({
809
+ ...r,
725
810
  cacheTime: g
726
- }), o = await v(r, c);
727
- if (!(await F({
728
- ...c,
811
+ }), o = await v(a, r);
812
+ if (!(await S({
813
+ ...r,
729
814
  cacheTime: g
730
815
  })).some(
731
- (d) => p(d.coinType) === p(o.suiCoinType)
816
+ (p) => f(p.coinType) === f(o.suiCoinType)
732
817
  ))
733
818
  throw new Error("Pool does not support flashloan");
734
819
  const [l] = e.moveCall({
@@ -737,58 +822,91 @@ async function Ve(e, r, a, t, c) {
737
822
  e.object("0x06"),
738
823
  e.object(n.storage),
739
824
  e.object(o.contract.pool),
740
- m(a, e.object),
741
- m(t, e.object)
825
+ d(c, e.object),
826
+ d(t, e.object)
742
827
  ],
743
828
  typeArguments: [o.suiCoinType]
744
829
  });
745
830
  return [l];
746
831
  }
747
- async function Re(e, r, a, t, c, n) {
832
+ async function Ee(e, a, c, t, r, n) {
748
833
  const o = {
749
834
  ...n,
750
835
  cacheTime: g
751
- }, i = await w(o), u = await v(r, o), l = await v(t, o), [d, b] = e.moveCall({
752
- target: `${i.package}::incentive_v3::liquidation_v2`,
753
- arguments: [
754
- e.object("0x06"),
755
- // Clock object
756
- e.object(i.priceOracle),
757
- // Price oracle for asset pricing
758
- e.object(i.storage),
759
- // Protocol storage
760
- e.pure.u8(u.id),
761
- // Pay asset ID
762
- e.object(u.contract.pool),
763
- // Pay asset pool contract
764
- m(a, e.object),
765
- // Debt repayment amount
766
- e.pure.u8(l.id),
767
- // Collateral asset ID
768
- e.object(l.contract.pool),
769
- // Collateral asset pool contract
770
- m(c, e.pure.address),
771
- // Borrower address
772
- e.object(i.incentiveV2),
773
- // Incentive V2 contract
774
- e.object(i.incentiveV3),
775
- // Incentive V3 contract
776
- e.object("0x05")
777
- // SuiSystemState object
778
- ],
779
- typeArguments: [u.suiCoinType, l.suiCoinType]
780
- });
781
- return [d, b];
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
+ }
782
900
  }
783
- async function Ne(e, r) {
784
- var d;
785
- const a = await ae(r), t = await S({
786
- ...r,
901
+ async function De(e, a) {
902
+ var p;
903
+ const c = await ne(a), t = await V({
904
+ ...a,
787
905
  cacheTime: g
788
- }), c = (d = r == null ? void 0 : r.client) != null ? d : I, n = await w({
789
- ...r,
906
+ }), r = (p = a == null ? void 0 : a.client) != null ? p : A, n = await b({
907
+ ...a,
790
908
  cacheTime: g
791
- }), o = new B();
909
+ }), o = new k();
792
910
  o.moveCall({
793
911
  target: `${n.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
794
912
  arguments: [
@@ -802,11 +920,11 @@ async function Ne(e, r) {
802
920
  // User address
803
921
  ]
804
922
  });
805
- const i = await c.devInspectTransactionBlock({
923
+ const s = await r.devInspectTransactionBlock({
806
924
  transactionBlock: o,
807
925
  sender: e
808
- }), u = $(
809
- i,
926
+ }), u = B(
927
+ s,
810
928
  [
811
929
  h.vector(h.string()),
812
930
  // Asset coin types
@@ -821,95 +939,95 @@ async function Ne(e, r) {
821
939
  ]
822
940
  ), l = [];
823
941
  if (u.length === 5 && Array.isArray(u[0])) {
824
- const b = u[0].length;
825
- for (let f = 0; f < b; f++) {
826
- const y = a.find(
827
- (j) => p(j.coinType) === p(u[1][f])
828
- ), C = t.find(
829
- (j) => p(j.coinType) === p(u[0][f])
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])
830
948
  );
831
- !y || !C || l.push({
832
- assetId: C.id,
833
- assetCoinType: p(u[0][f]),
834
- rewardCoinType: p(u[1][f]),
835
- option: Number(u[2][f]),
836
- userClaimableReward: Number(u[4][f]) / Math.pow(10, y.priceDecimal),
837
- ruleIds: Array.isArray(u[3][f]) ? u[3][f] : [u[3][f]]
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]]
838
956
  });
839
957
  }
840
958
  }
841
959
  return l;
842
960
  }
843
- function Ee(e) {
844
- const r = /* @__PURE__ */ new Map();
961
+ function Le(e) {
962
+ const a = /* @__PURE__ */ new Map();
845
963
  e.forEach((t) => {
846
- const c = t.assetId, n = t.option, o = `${c}-${n}-${t.rewardCoinType}`;
847
- r.has(o) ? r.get(o).total += t.userClaimableReward : r.set(o, {
848
- assetId: c,
964
+ const r = t.assetId, n = t.option, o = `${r}-${n}-${t.rewardCoinType}`;
965
+ a.has(o) ? a.get(o).total += t.userClaimableReward : a.set(o, {
966
+ assetId: r,
849
967
  rewardType: n,
850
968
  coinType: t.rewardCoinType,
851
969
  total: Number(t.userClaimableReward)
852
970
  });
853
971
  });
854
- const a = /* @__PURE__ */ new Map();
855
- for (const { assetId: t, rewardType: c, coinType: n, total: o } of r.values()) {
856
- const i = `${t}-${c}`;
857
- a.has(i) || a.set(i, { assetId: t, rewardType: c, rewards: /* @__PURE__ */ new Map() });
858
- const u = a.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);
859
977
  u.rewards.set(n, (u.rewards.get(n) || 0) + o);
860
978
  }
861
- return Array.from(a.values()).map((t) => ({
979
+ return Array.from(c.values()).map((t) => ({
862
980
  assetId: t.assetId,
863
981
  rewardType: t.rewardType,
864
- rewards: Array.from(t.rewards.entries()).map(([c, n]) => ({
865
- coinType: c,
982
+ rewards: Array.from(t.rewards.entries()).map(([r, n]) => ({
983
+ coinType: r,
866
984
  available: n.toFixed(6)
867
985
  }))
868
986
  }));
869
987
  }
870
- const Le = _(
988
+ const Me = C(
871
989
  async (e) => {
872
- const r = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}`;
873
- return (await fetch(r).then((t) => t.json())).data;
990
+ const a = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}`;
991
+ return (await fetch(a).then((t) => t.json())).data;
874
992
  }
875
- ), De = _(
876
- async (e, r) => {
877
- const a = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${(r == null ? void 0 : r.page) || 1}&pageSize=${(r == null ? void 0 : r.size) || 400}`, t = await fetch(a).then((c) => c.json());
878
- return k({
993
+ ), Ue = C(
994
+ async (e, a) => {
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({
879
997
  data: t.data.rewards
880
998
  });
881
999
  }
882
1000
  );
883
- async function Me(e, r, a) {
884
- var i;
885
- const t = await w({
886
- ...a,
1001
+ async function Oe(e, a, c) {
1002
+ var s;
1003
+ const t = await b({
1004
+ ...c,
887
1005
  cacheTime: g
888
- }), c = await S({
889
- ...a,
1006
+ }), r = await V({
1007
+ ...c,
890
1008
  cacheTime: g
891
1009
  }), n = /* @__PURE__ */ new Map();
892
- for (const u of r) {
893
- const { rewardCoinType: l, ruleIds: d } = u;
894
- for (const b of d) {
1010
+ for (const u of a) {
1011
+ const { rewardCoinType: l, ruleIds: p } = u;
1012
+ for (const w of p) {
895
1013
  n.has(l) || n.set(l, { assetIds: [], ruleIds: [], amount: 0 });
896
- const f = n.get(l);
897
- f.assetIds.push(u.assetCoinType.replace("0x", "")), f.ruleIds.push(b), f.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;
898
1016
  }
899
1017
  }
900
1018
  const o = [];
901
- for (const [u, { assetIds: l, ruleIds: d, amount: b }] of n) {
902
- const f = c.find(
903
- (C) => p(C.suiCoinType) === p(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)
904
1022
  );
905
- if (!f || !f.contract.rewardFundId)
1023
+ if (!m || !m.contract.rewardFundId)
906
1024
  throw new Error(`No matching rewardFund found for reward coin: ${u}`);
907
- const y = f.contract.rewardFundId;
908
- if (a != null && a.accountCap && !a.customCoinReceive)
1025
+ const y = m.contract.rewardFundId;
1026
+ if (c != null && c.accountCap && !c.customCoinReceive)
909
1027
  throw new Error("customCoinReceive is required when accountCap is provided");
910
- if (a != null && a.customCoinReceive) {
911
- let C;
912
- a.accountCap ? C = e.moveCall({
1028
+ if (c != null && c.customCoinReceive) {
1029
+ let j;
1030
+ c.accountCap ? j = e.moveCall({
913
1031
  target: `${t.package}::incentive_v3::claim_reward_with_account_cap`,
914
1032
  arguments: [
915
1033
  e.object("0x06"),
@@ -922,13 +1040,13 @@ async function Me(e, r, a) {
922
1040
  // Reward fund
923
1041
  e.pure.vector("string", l),
924
1042
  // Asset IDs
925
- e.pure.vector("address", d),
1043
+ e.pure.vector("address", p),
926
1044
  // Rule IDs
927
- m(a.accountCap, e.object)
1045
+ d(c.accountCap, e.object)
928
1046
  // Account capability
929
1047
  ],
930
1048
  typeArguments: [u]
931
- }) : C = e.moveCall({
1049
+ }) : j = e.moveCall({
932
1050
  target: `${t.package}::incentive_v3::claim_reward`,
933
1051
  arguments: [
934
1052
  e.object("0x06"),
@@ -941,34 +1059,34 @@ async function Me(e, r, a) {
941
1059
  // Reward fund
942
1060
  e.pure.vector("string", l),
943
1061
  // Asset IDs
944
- e.pure.vector("address", d)
1062
+ e.pure.vector("address", p)
945
1063
  // Rule IDs
946
1064
  ],
947
1065
  typeArguments: [u]
948
1066
  });
949
- const [j] = e.moveCall({
1067
+ const [_] = e.moveCall({
950
1068
  target: "0x2::coin::from_balance",
951
- arguments: [C],
1069
+ arguments: [j],
952
1070
  typeArguments: [u]
953
1071
  });
954
- if ((a == null ? void 0 : a.customCoinReceive.type) === "transfer") {
955
- if (!a.customCoinReceive.transfer)
1072
+ if ((c == null ? void 0 : c.customCoinReceive.type) === "transfer") {
1073
+ if (!c.customCoinReceive.transfer)
956
1074
  throw new Error("customCoinReceive.transfer is required");
957
1075
  e.transferObjects(
958
- [j],
959
- m(a.customCoinReceive.transfer, e.pure.address)
1076
+ [_],
1077
+ d(c.customCoinReceive.transfer, e.pure.address)
960
1078
  );
961
1079
  }
962
- if ((a == null ? void 0 : a.customCoinReceive.type) === "depositNAVI") {
963
- const U = T(f.totalSupplyAmount).shiftedBy(-9), G = T(f.supplyCapCeiling).shiftedBy(-27);
964
- U.plus(b).isGreaterThan(G) && ((i = a == null ? void 0 : a.customCoinReceive.depositNAVI) != null && i.fallbackReceiveAddress) ? e.transferObjects(
965
- [j],
966
- e.pure.address(a.customCoinReceive.depositNAVI.fallbackReceiveAddress)
967
- ) : await x(e, f, j, a);
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);
968
1086
  } else
969
1087
  o.push({
970
- coin: j,
971
- identifier: f
1088
+ coin: _,
1089
+ identifier: m
972
1090
  });
973
1091
  } else
974
1092
  e.moveCall({
@@ -984,7 +1102,7 @@ async function Me(e, r, a) {
984
1102
  // Reward fund
985
1103
  e.pure.vector("string", l),
986
1104
  // Asset IDs
987
- e.pure.vector("address", d)
1105
+ e.pure.vector("address", p)
988
1106
  // Rule IDs
989
1107
  ],
990
1108
  typeArguments: [u]
@@ -992,63 +1110,63 @@ async function Me(e, r, a) {
992
1110
  }
993
1111
  return o;
994
1112
  }
995
- async function Ue(e, r) {
996
- const a = await w({
997
- ...r
1113
+ async function Ge(e, a) {
1114
+ const c = await b({
1115
+ ...a
998
1116
  });
999
1117
  return e.moveCall({
1000
- target: `${a.package}::lending::create_account`,
1118
+ target: `${c.package}::lending::create_account`,
1001
1119
  arguments: []
1002
1120
  });
1003
1121
  }
1004
1122
  export {
1005
- V as Address,
1123
+ F as Address,
1006
1124
  g as DEFAULT_CACHE_TIME,
1007
- ge as FlashLoanAssetConfig,
1125
+ be as FlashLoanAssetConfig,
1008
1126
  fe as IncentiveAPYInfo,
1009
- J as IncentivePoolInfo,
1010
- me as IncentivePoolInfoByPhase,
1011
- pe as OracleInfo,
1012
- P as PoolOperator,
1013
- ye as ReserveDataInfo,
1127
+ Y as IncentivePoolInfo,
1128
+ ge as IncentivePoolInfoByPhase,
1129
+ ye as OracleInfo,
1130
+ $ as PoolOperator,
1131
+ we as ReserveDataInfo,
1014
1132
  Q as UserStateInfo,
1015
- ve as borrowCoinPTB,
1016
- Me as claimLendingRewardsPTB,
1017
- Ue as createAccountCapPTB,
1018
- x as depositCoinPTB,
1019
- ke as filterPriceFeeds,
1020
- Fe as flashloanPTB,
1021
- F as getAllFlashLoanAssets,
1022
- _e as getBorrowFee,
1023
- Be as getCoins,
1024
- w as getConfig,
1025
- he as getFees,
1026
- Se as getFlashLoanAsset,
1027
- Ie as getHealthFactor,
1028
- ee as getHealthFactorPTB,
1029
- Te as getLendingState,
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,
1030
1148
  v as getPool,
1031
- S as getPools,
1032
- ae as getPriceFeeds,
1033
- te as getPythStalePriceFeedId,
1034
- Ae as getSimulatedHealthFactor,
1035
- D as getSimulatedHealthFactorPTB,
1036
- we as getStats,
1037
- Pe as getTransactions,
1038
- Ne as getUserAvailableLendingRewards,
1039
- De as getUserClaimedRewardHistory,
1040
- Le as getUserTotalClaimedReward,
1041
- Re as liquidatePTB,
1042
- je as mergeCoinsPTB,
1043
- p as normalizeCoinType,
1044
- m as parseTxValue,
1045
- Ce as repayCoinPTB,
1046
- Ve as repayFlashLoanPTB,
1047
- Ee as summaryLendingRewards,
1048
- $e as updateOraclePricesPTB,
1049
- re as updatePythPriceFeeds,
1050
- A as withCache,
1051
- _ as withSingleton,
1052
- be as withdrawCoinPTB
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
1053
1171
  };
1054
1172
  //# sourceMappingURL=index.esm.js.map