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