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