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