@naviprotocol/lending 1.4.3 → 1.4.4-beta.10
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 +704 -686
- package/dist/index.esm.js.map +1 -1
- package/dist/market.d.ts +9 -0
- package/dist/market.d.ts.map +1 -1
- package/dist/pool.d.ts.map +1 -1
- package/dist/reward.d.ts.map +1 -1
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Transaction as
|
|
2
|
-
import { bcs as m, toHex as
|
|
3
|
-
import { SuiClient as
|
|
4
|
-
import
|
|
5
|
-
import { normalizeStructTag as
|
|
6
|
-
import { SuiPriceServiceConnection as
|
|
1
|
+
import { Transaction as F } from "@mysten/sui/transactions";
|
|
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.10", 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
|
-
},
|
|
147
|
-
url:
|
|
145
|
+
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${he} (${ve()})`), e;
|
|
146
|
+
}, Y = we(), S = new le({
|
|
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) => j(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 = j(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
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 =
|
|
273
|
-
}),
|
|
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,24 +346,24 @@ 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 (
|
|
366
|
+
if (n?.accountCap) {
|
|
365
367
|
const [l] = e.moveCall({
|
|
366
368
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
|
|
367
369
|
arguments: [
|
|
@@ -370,10 +372,10 @@ 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
|
});
|
|
@@ -387,7 +389,7 @@ 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
|
],
|
|
@@ -395,7 +397,7 @@ async function Qe(e, n, o, r) {
|
|
|
395
397
|
});
|
|
396
398
|
i = l;
|
|
397
399
|
}
|
|
398
|
-
else if (
|
|
400
|
+
else if (n?.accountCap) {
|
|
399
401
|
const [l] = e.moveCall({
|
|
400
402
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
401
403
|
arguments: [
|
|
@@ -404,10 +406,10 @@ 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]
|
|
@@ -422,7 +424,7 @@ 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")
|
|
@@ -437,17 +439,17 @@ 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 (
|
|
452
|
+
if (n?.accountCap) {
|
|
451
453
|
const [l] = e.moveCall({
|
|
452
454
|
target: `${t.package}::incentive_v3::borrow_with_account_cap`,
|
|
453
455
|
arguments: [
|
|
@@ -456,10 +458,10 @@ 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
|
});
|
|
@@ -473,7 +475,7 @@ 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
|
],
|
|
@@ -481,7 +483,7 @@ async function Xe(e, n, o, r) {
|
|
|
481
483
|
});
|
|
482
484
|
i = l;
|
|
483
485
|
}
|
|
484
|
-
else if (
|
|
486
|
+
else if (n?.accountCap) {
|
|
485
487
|
const [l] = e.moveCall({
|
|
486
488
|
target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
487
489
|
arguments: [
|
|
@@ -490,10 +492,10 @@ 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]
|
|
@@ -508,7 +510,7 @@ 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")
|
|
@@ -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 F();
|
|
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",
|
|
@@ -620,56 +622,66 @@ const et = P(
|
|
|
620
622
|
id: 1,
|
|
621
623
|
key: "ember",
|
|
622
624
|
name: "Ember Market"
|
|
625
|
+
},
|
|
626
|
+
// 'sui-eco': {
|
|
627
|
+
// id: 2,
|
|
628
|
+
// key: 'sui-eco',
|
|
629
|
+
// name: 'Sui Eco Market'
|
|
630
|
+
// },
|
|
631
|
+
rwa: {
|
|
632
|
+
id: 2,
|
|
633
|
+
key: "rwa",
|
|
634
|
+
name: "Matrixdock Market"
|
|
623
635
|
}
|
|
624
636
|
};
|
|
625
|
-
class
|
|
626
|
-
constructor(
|
|
637
|
+
class je {
|
|
638
|
+
constructor(r, o) {
|
|
627
639
|
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
628
640
|
marketTotalSupplyValue: "0",
|
|
629
641
|
marketTotalBorrowValue: "0"
|
|
630
|
-
}, this.config = j(
|
|
642
|
+
}, this.config = j(r), this.initPools(o);
|
|
631
643
|
}
|
|
632
644
|
get overview() {
|
|
633
645
|
return this._overview;
|
|
634
646
|
}
|
|
635
|
-
initPools(
|
|
636
|
-
const o =
|
|
637
|
-
let
|
|
638
|
-
|
|
639
|
-
if (!this.checkMarket(
|
|
640
|
-
console.warn(`Pool is not in market ${this.config.name}`,
|
|
647
|
+
initPools(r) {
|
|
648
|
+
const o = G(this.pools), n = Z(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
649
|
+
let s = p(0), i = p(0);
|
|
650
|
+
r.forEach((c) => {
|
|
651
|
+
if (!this.checkMarket(c.market)) {
|
|
652
|
+
console.warn(`Pool is not in market ${this.config.name}`, c);
|
|
641
653
|
return;
|
|
642
654
|
}
|
|
643
|
-
o[
|
|
644
|
-
|
|
655
|
+
o[c.uniqueId] || this.pools.push(c), c?.emodes?.forEach((d) => {
|
|
656
|
+
n[d.uniqueId] || this.emodes.push(d), d.assets.forEach((y) => {
|
|
645
657
|
y.isDebt && d.assets.find(
|
|
646
|
-
(g) => g.isCollateral && g.ltv > 0 && g.assetId !==
|
|
647
|
-
) && t.add(
|
|
658
|
+
(g) => g.isCollateral && g.ltv > 0 && g.assetId !== c.id
|
|
659
|
+
) && t.add(c.uniqueId), y.isCollateral && d.assets.find((g) => g.isDebt && g.assetId !== c.id) && a.add(c.uniqueId);
|
|
648
660
|
});
|
|
649
|
-
}), i = i.plus(
|
|
650
|
-
}), this.poolMap =
|
|
651
|
-
const l = this.getEModePools(
|
|
661
|
+
}), i = i.plus(c.poolBorrowValue), s = s.plus(c.poolSupplyValue);
|
|
662
|
+
}), this.poolMap = G(this.pools, "id"), this.emodeMap = Z(this.emodes, "emodeId"), this.emodes.forEach((c) => {
|
|
663
|
+
const l = this.getEModePools(c.emodeId);
|
|
652
664
|
this.emodePools.push(...l);
|
|
653
665
|
}), this._overview = {
|
|
654
|
-
marketTotalSupplyValue:
|
|
666
|
+
marketTotalSupplyValue: s.toString(),
|
|
655
667
|
marketTotalBorrowValue: i.toString()
|
|
656
|
-
}, this.emodeBorrowablePools = this.pools.filter((
|
|
668
|
+
}, this.emodeBorrowablePools = this.pools.filter((c) => t.has(c.uniqueId)), this.emodeSupplyablePools = this.pools.filter((c) => a.has(c.uniqueId));
|
|
657
669
|
}
|
|
658
|
-
getEMode(
|
|
659
|
-
return this.emodeMap[
|
|
670
|
+
getEMode(r) {
|
|
671
|
+
return this.emodeMap[r] || null;
|
|
660
672
|
}
|
|
661
|
-
getEModeRelatePools(
|
|
662
|
-
const { collateral:
|
|
663
|
-
return
|
|
664
|
-
typeof a == "number" && a !== i.emodeId || i.assets.forEach((
|
|
665
|
-
typeof
|
|
673
|
+
getEModeRelatePools(r, o) {
|
|
674
|
+
const { collateral: n, debt: t, emodeId: a } = o || {}, s = [];
|
|
675
|
+
return r.emodes.forEach((i) => {
|
|
676
|
+
typeof a == "number" && a !== i.emodeId || i.assets.forEach((c) => {
|
|
677
|
+
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]);
|
|
666
678
|
});
|
|
667
|
-
}),
|
|
679
|
+
}), s;
|
|
668
680
|
}
|
|
669
|
-
getEModePools(
|
|
670
|
-
const o = this.getEMode(
|
|
681
|
+
getEModePools(r) {
|
|
682
|
+
const o = this.getEMode(r);
|
|
671
683
|
return o ? o.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
|
|
672
|
-
const a = o.assets.find((
|
|
684
|
+
const a = o.assets.find((s) => s.assetId === t.id);
|
|
673
685
|
return {
|
|
674
686
|
...t,
|
|
675
687
|
emode: {
|
|
@@ -680,218 +692,218 @@ class Ce {
|
|
|
680
692
|
};
|
|
681
693
|
}) : [];
|
|
682
694
|
}
|
|
683
|
-
checkMarket(
|
|
695
|
+
checkMarket(r) {
|
|
684
696
|
let o = !1;
|
|
685
|
-
return typeof
|
|
697
|
+
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;
|
|
686
698
|
}
|
|
687
699
|
}
|
|
688
700
|
const j = (e) => {
|
|
689
|
-
const o = Object.values(E).find((
|
|
701
|
+
const o = Object.values(E).find((n) => typeof e == "number" ? n.id === e : typeof e == "string" ? n.key === e : n.id === e.id);
|
|
690
702
|
if (!o)
|
|
691
703
|
throw new Error("Market not found");
|
|
692
704
|
return o;
|
|
693
|
-
},
|
|
705
|
+
}, Ie = P(
|
|
694
706
|
B(
|
|
695
|
-
async (e,
|
|
696
|
-
const o = await
|
|
707
|
+
async (e, r) => {
|
|
708
|
+
const o = await q({
|
|
697
709
|
cacheTime: 6e4,
|
|
698
|
-
...
|
|
710
|
+
...r,
|
|
699
711
|
markets: e
|
|
700
712
|
});
|
|
701
|
-
return e.map((
|
|
702
|
-
const t = j(
|
|
703
|
-
return new
|
|
713
|
+
return e.map((n) => {
|
|
714
|
+
const t = j(n), a = o.filter((s) => s.market === t.key);
|
|
715
|
+
return new je(n, a);
|
|
704
716
|
});
|
|
705
717
|
}
|
|
706
718
|
)
|
|
707
|
-
),
|
|
719
|
+
), ot = P(
|
|
708
720
|
B(
|
|
709
|
-
async (e,
|
|
721
|
+
async (e, r) => (await Ie([e], r))[0]
|
|
710
722
|
)
|
|
711
723
|
), _ = P(
|
|
712
724
|
B(
|
|
713
725
|
async (e) => {
|
|
714
|
-
const
|
|
726
|
+
const r = j(e?.market || U), o = `https://open-api.naviprotocol.io/api/navi/config?env=${e?.env || "prod"}&sdk=${V.version}&market=${r.key}`;
|
|
715
727
|
return (await fetch(o, { headers: M }).then((t) => t.json())).data;
|
|
716
728
|
}
|
|
717
729
|
)
|
|
718
|
-
),
|
|
719
|
-
async function
|
|
730
|
+
), w = 1e3 * 60 * 5;
|
|
731
|
+
async function Te(e, r) {
|
|
720
732
|
const o = await _({
|
|
721
|
-
cacheTime:
|
|
722
|
-
...
|
|
733
|
+
cacheTime: w,
|
|
734
|
+
...r
|
|
723
735
|
});
|
|
724
736
|
return e.moveCall({
|
|
725
737
|
target: `${o.package}::lending::create_account`,
|
|
726
738
|
arguments: []
|
|
727
739
|
});
|
|
728
740
|
}
|
|
729
|
-
async function
|
|
730
|
-
const
|
|
731
|
-
cacheTime:
|
|
741
|
+
async function Be(e, r, o) {
|
|
742
|
+
const n = await _({
|
|
743
|
+
cacheTime: w,
|
|
732
744
|
...o
|
|
733
745
|
});
|
|
734
746
|
return e.moveCall({
|
|
735
|
-
target: `${
|
|
736
|
-
arguments: [
|
|
747
|
+
target: `${n.package}::account::account_owner`,
|
|
748
|
+
arguments: [r]
|
|
737
749
|
});
|
|
738
750
|
}
|
|
739
|
-
async function
|
|
740
|
-
const
|
|
751
|
+
async function Ae(e, r, o) {
|
|
752
|
+
const n = await _({
|
|
741
753
|
...o,
|
|
742
|
-
cacheTime:
|
|
754
|
+
cacheTime: w
|
|
743
755
|
});
|
|
744
756
|
return o?.accountCap ? e.moveCall({
|
|
745
|
-
target: `${
|
|
757
|
+
target: `${n.package}::lending::enter_emode_with_account_cap`,
|
|
746
758
|
arguments: [
|
|
747
|
-
e.object(
|
|
748
|
-
h(
|
|
759
|
+
e.object(n.storage),
|
|
760
|
+
h(r, e.pure.u64),
|
|
749
761
|
h(o.accountCap, e.object)
|
|
750
762
|
]
|
|
751
763
|
}) : e.moveCall({
|
|
752
|
-
target: `${
|
|
753
|
-
arguments: [e.object(
|
|
764
|
+
target: `${n.package}::lending::enter_emode`,
|
|
765
|
+
arguments: [e.object(n.storage), h(r, e.pure.u64)]
|
|
754
766
|
}), e;
|
|
755
767
|
}
|
|
756
|
-
async function
|
|
768
|
+
async function rt(e, r) {
|
|
757
769
|
const o = await _({
|
|
758
|
-
...
|
|
759
|
-
cacheTime:
|
|
770
|
+
...r,
|
|
771
|
+
cacheTime: w
|
|
760
772
|
});
|
|
761
|
-
return
|
|
773
|
+
return r?.accountCap ? e.moveCall({
|
|
762
774
|
target: `${o.package}::lending::exit_emode_with_account_cap`,
|
|
763
|
-
arguments: [e.object(o.storage), h(
|
|
775
|
+
arguments: [e.object(o.storage), h(r.accountCap, e.object)]
|
|
764
776
|
}) : e.moveCall({
|
|
765
777
|
target: `${o.package}::lending::exit_emode`,
|
|
766
778
|
arguments: [e.object(o.storage)]
|
|
767
779
|
}), e;
|
|
768
780
|
}
|
|
769
|
-
async function nt(e,
|
|
770
|
-
const
|
|
771
|
-
cacheTime:
|
|
781
|
+
async function nt(e, r, o) {
|
|
782
|
+
const n = await _({
|
|
783
|
+
cacheTime: w,
|
|
772
784
|
...o
|
|
773
|
-
}), t = await
|
|
774
|
-
await
|
|
785
|
+
}), t = await Te(e, o);
|
|
786
|
+
await Ae(e, r, {
|
|
775
787
|
...o,
|
|
776
788
|
accountCap: t
|
|
777
789
|
});
|
|
778
|
-
const a = await j(o?.market ||
|
|
790
|
+
const a = await j(o?.market || U), s = await Be(e, t, o);
|
|
779
791
|
return e.moveCall({
|
|
780
|
-
target: `${
|
|
792
|
+
target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
781
793
|
arguments: [
|
|
782
|
-
e.object(
|
|
783
|
-
|
|
794
|
+
e.object(n.emode.contract.registryObject),
|
|
795
|
+
s,
|
|
784
796
|
h(a.id, e.pure.u64),
|
|
785
|
-
h(
|
|
797
|
+
h(r, e.pure.u64)
|
|
786
798
|
]
|
|
787
799
|
}), t;
|
|
788
800
|
}
|
|
789
|
-
const
|
|
801
|
+
const ee = P(
|
|
790
802
|
B(
|
|
791
|
-
async (e,
|
|
803
|
+
async (e, r) => {
|
|
792
804
|
const o = await _({
|
|
793
|
-
cacheTime:
|
|
794
|
-
...
|
|
795
|
-
}),
|
|
796
|
-
|
|
805
|
+
cacheTime: w,
|
|
806
|
+
...r
|
|
807
|
+
}), n = new F(), t = r?.client ?? S;
|
|
808
|
+
n.moveCall({
|
|
797
809
|
target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
798
|
-
arguments: [
|
|
810
|
+
arguments: [n.object(o.emode.contract.registryObject), n.pure.address(e)]
|
|
799
811
|
});
|
|
800
|
-
const
|
|
801
|
-
transactionBlock:
|
|
812
|
+
const s = (await t.devInspectTransactionBlock({
|
|
813
|
+
transactionBlock: n,
|
|
802
814
|
sender: e
|
|
803
|
-
})).results[0].returnValues, i = C.vector(C.u64()).parse(Uint8Array.from(
|
|
815
|
+
})).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]));
|
|
804
816
|
return i.map((d, y) => ({
|
|
805
817
|
marketId: Number(d),
|
|
806
|
-
emodeId: Number(
|
|
818
|
+
emodeId: Number(c[y]),
|
|
807
819
|
accountCap: l[y].toString()
|
|
808
820
|
}));
|
|
809
821
|
}
|
|
810
822
|
)
|
|
811
823
|
);
|
|
812
|
-
function
|
|
824
|
+
function at(e) {
|
|
813
825
|
return `${j(e.marketId).key}-${e.emodeId}`;
|
|
814
826
|
}
|
|
815
|
-
function
|
|
816
|
-
const
|
|
827
|
+
function it(e, r, o) {
|
|
828
|
+
const n = typeof o?.balance == "number", t = n ? o.balance : 0;
|
|
817
829
|
let a = 0;
|
|
818
|
-
const
|
|
830
|
+
const s = [];
|
|
819
831
|
let i = "";
|
|
820
|
-
if (
|
|
821
|
-
if (!(
|
|
822
|
-
if (i || (i =
|
|
832
|
+
if (r.sort((c, l) => Number(l.balance) - Number(c.balance)).forEach((c) => {
|
|
833
|
+
if (!(n && a >= t) && Number(c.balance) !== 0) {
|
|
834
|
+
if (i || (i = c.coinType), i !== c.coinType)
|
|
823
835
|
throw new Error("All coins must be of the same type");
|
|
824
|
-
a += Number(
|
|
836
|
+
a += Number(c.balance), s.push(c.coinObjectId);
|
|
825
837
|
}
|
|
826
|
-
}),
|
|
838
|
+
}), s.length === 0)
|
|
827
839
|
throw new Error("No coins to merge");
|
|
828
|
-
if (
|
|
840
|
+
if (n && a < t)
|
|
829
841
|
throw new Error(
|
|
830
842
|
`Balance is less than the specified balance: ${a} < ${t}`
|
|
831
843
|
);
|
|
832
|
-
return
|
|
844
|
+
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]);
|
|
833
845
|
}
|
|
834
|
-
async function
|
|
846
|
+
async function te(e, r, o, n, t, a, s) {
|
|
835
847
|
const i = await _({
|
|
836
|
-
...
|
|
837
|
-
cacheTime:
|
|
838
|
-
}),
|
|
848
|
+
...s,
|
|
849
|
+
cacheTime: w
|
|
850
|
+
}), c = await A(o, s);
|
|
839
851
|
return e.moveCall({
|
|
840
852
|
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
841
853
|
arguments: [
|
|
842
854
|
e.object("0x06"),
|
|
843
855
|
e.object(i.storage),
|
|
844
856
|
e.object(i.oracle.priceOracle),
|
|
845
|
-
|
|
846
|
-
h(
|
|
847
|
-
h(
|
|
848
|
-
h(
|
|
857
|
+
be(e, c),
|
|
858
|
+
h(r, e.pure.address),
|
|
859
|
+
h(c.id, e.pure.u8),
|
|
860
|
+
h(n, e.pure.u64),
|
|
849
861
|
h(t, e.pure.u64),
|
|
850
862
|
h(a, e.pure.bool)
|
|
851
863
|
],
|
|
852
|
-
typeArguments: [
|
|
864
|
+
typeArguments: [c.suiCoinType]
|
|
853
865
|
});
|
|
854
866
|
}
|
|
855
|
-
async function
|
|
856
|
-
return
|
|
867
|
+
async function Pe(e, r, o) {
|
|
868
|
+
return te(e, r, 0, 0, 0, !1, o);
|
|
857
869
|
}
|
|
858
|
-
async function
|
|
859
|
-
const
|
|
870
|
+
async function oe(e, r, o) {
|
|
871
|
+
const n = new F(), t = o?.client ?? S, a = await q({
|
|
860
872
|
...o,
|
|
861
873
|
markets: Object.values(E)
|
|
862
|
-
}),
|
|
863
|
-
for (let d of
|
|
874
|
+
}), s = G(a);
|
|
875
|
+
for (let d of r) {
|
|
864
876
|
const y = await _({
|
|
865
877
|
...o,
|
|
866
|
-
cacheTime:
|
|
878
|
+
cacheTime: w,
|
|
867
879
|
market: d.market
|
|
868
880
|
});
|
|
869
|
-
|
|
881
|
+
n.moveCall({
|
|
870
882
|
target: `${y.uiGetter}::getter_unchecked::get_user_state`,
|
|
871
|
-
arguments: [
|
|
883
|
+
arguments: [n.object(y.storage), n.pure.address(d.address)]
|
|
872
884
|
});
|
|
873
885
|
}
|
|
874
|
-
const
|
|
875
|
-
transactionBlock:
|
|
886
|
+
const c = ((await t.devInspectTransactionBlock({
|
|
887
|
+
transactionBlock: n,
|
|
876
888
|
sender: e
|
|
877
|
-
})).results || []).map((d) => d.returnValues?.map((y) => C.vector(
|
|
878
|
-
return
|
|
879
|
-
const v =
|
|
889
|
+
})).results || []).map((d) => d.returnValues?.map((y) => C.vector(ye).parse(Uint8Array.from(y[0])))[0] || []), l = [];
|
|
890
|
+
return c.forEach((d, y) => {
|
|
891
|
+
const v = r[y], g = j(v.market);
|
|
880
892
|
d.forEach((u) => {
|
|
881
893
|
if (u.supply_balance === "0" && u.borrow_balance === "0" && (v.emodeId === void 0 || !o?.includeZeroBalanceEmodePositions))
|
|
882
894
|
return;
|
|
883
|
-
const f =
|
|
895
|
+
const f = s[`${g.key}-${u.asset_id}`];
|
|
884
896
|
if (!f)
|
|
885
897
|
return;
|
|
886
|
-
const
|
|
898
|
+
const k = J(
|
|
887
899
|
u.supply_balance,
|
|
888
900
|
f.currentSupplyIndex
|
|
889
|
-
).toString(), I =
|
|
901
|
+
).toString(), I = J(
|
|
890
902
|
u.borrow_balance,
|
|
891
903
|
f.currentBorrowIndex
|
|
892
904
|
).toString();
|
|
893
905
|
l.push({
|
|
894
|
-
supplyBalance:
|
|
906
|
+
supplyBalance: k,
|
|
895
907
|
borrowBalance: I,
|
|
896
908
|
assetId: u.asset_id,
|
|
897
909
|
market: g.key,
|
|
@@ -901,64 +913,64 @@ async function te(e, n, o) {
|
|
|
901
913
|
});
|
|
902
914
|
}), l;
|
|
903
915
|
}
|
|
904
|
-
const
|
|
905
|
-
async (e,
|
|
906
|
-
const
|
|
916
|
+
const ct = P(
|
|
917
|
+
async (e, r) => {
|
|
918
|
+
const n = (r?.markets || Object.keys(E)).map((t) => j(t)).map((t) => ({
|
|
907
919
|
address: e,
|
|
908
920
|
market: t.key
|
|
909
921
|
}));
|
|
910
|
-
return await
|
|
922
|
+
return await oe(e, n, r);
|
|
911
923
|
}
|
|
912
924
|
);
|
|
913
|
-
async function
|
|
914
|
-
const o =
|
|
915
|
-
await
|
|
925
|
+
async function st(e, r) {
|
|
926
|
+
const o = r?.client ?? S, n = new F();
|
|
927
|
+
await Pe(n, e, r);
|
|
916
928
|
const t = await o.devInspectTransactionBlock({
|
|
917
|
-
transactionBlock:
|
|
929
|
+
transactionBlock: n,
|
|
918
930
|
sender: e
|
|
919
|
-
}), a =
|
|
920
|
-
return
|
|
931
|
+
}), a = W(t, [C.u256()]);
|
|
932
|
+
return x(Number(a[0]) || 0);
|
|
921
933
|
}
|
|
922
|
-
async function
|
|
923
|
-
const t =
|
|
924
|
-
let
|
|
925
|
-
const
|
|
934
|
+
async function lt(e, r, o, n) {
|
|
935
|
+
const t = n?.client ?? S, a = new F();
|
|
936
|
+
let s = 0, i = 0;
|
|
937
|
+
const c = await A(r, n);
|
|
926
938
|
if (o.forEach((v) => {
|
|
927
|
-
v.type ===
|
|
928
|
-
}),
|
|
939
|
+
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);
|
|
940
|
+
}), s * i < 0)
|
|
929
941
|
throw new Error("Invalid operations");
|
|
930
|
-
const l =
|
|
931
|
-
await
|
|
942
|
+
const l = s > 0 || i > 0;
|
|
943
|
+
await te(
|
|
932
944
|
a,
|
|
933
945
|
e,
|
|
934
|
-
|
|
935
|
-
Math.abs(
|
|
946
|
+
c,
|
|
947
|
+
Math.abs(s),
|
|
936
948
|
Math.abs(i),
|
|
937
949
|
l,
|
|
938
|
-
|
|
950
|
+
n
|
|
939
951
|
);
|
|
940
952
|
const d = await t.devInspectTransactionBlock({
|
|
941
953
|
transactionBlock: a,
|
|
942
954
|
sender: e
|
|
943
|
-
}), y =
|
|
944
|
-
return
|
|
955
|
+
}), y = W(d, [C.u256()]);
|
|
956
|
+
return x(Number(y[0]) || 0);
|
|
945
957
|
}
|
|
946
|
-
const
|
|
947
|
-
async (e,
|
|
958
|
+
const ut = B(
|
|
959
|
+
async (e, r) => {
|
|
948
960
|
const o = new URLSearchParams();
|
|
949
|
-
|
|
950
|
-
const
|
|
951
|
-
return (await fetch(
|
|
961
|
+
r?.cursor && o.set("cursor", r.cursor), o.set("userAddress", e);
|
|
962
|
+
const n = `https://open-api.naviprotocol.io/api/navi/user/transactions?${o.toString()}&sdk=${V.version}`;
|
|
963
|
+
return (await fetch(n, { headers: M }).then((a) => a.json())).data;
|
|
952
964
|
}
|
|
953
965
|
);
|
|
954
|
-
async function
|
|
966
|
+
async function pt(e, r) {
|
|
955
967
|
let o = null;
|
|
956
|
-
const
|
|
968
|
+
const n = [], t = r?.client ?? S;
|
|
957
969
|
do {
|
|
958
970
|
let a;
|
|
959
|
-
if (
|
|
971
|
+
if (r?.coinType ? a = await t.getCoins({
|
|
960
972
|
owner: e,
|
|
961
|
-
coinType:
|
|
973
|
+
coinType: r?.coinType,
|
|
962
974
|
cursor: o,
|
|
963
975
|
limit: 100
|
|
964
976
|
}) : a = await t.getAllCoins({
|
|
@@ -967,53 +979,53 @@ async function ut(e, n) {
|
|
|
967
979
|
limit: 100
|
|
968
980
|
}), !a.data || !a.data.length)
|
|
969
981
|
break;
|
|
970
|
-
|
|
982
|
+
n.push(...a.data), o = a.nextCursor;
|
|
971
983
|
} while (o);
|
|
972
|
-
return
|
|
984
|
+
return n;
|
|
973
985
|
}
|
|
974
|
-
const
|
|
975
|
-
async (e,
|
|
976
|
-
const o = [],
|
|
986
|
+
const $e = P(
|
|
987
|
+
async (e, r) => {
|
|
988
|
+
const o = [], n = (r?.markets || Object.keys(E)).map((i) => j(i));
|
|
977
989
|
let t = [];
|
|
978
990
|
try {
|
|
979
|
-
t = await
|
|
991
|
+
t = await ee(e, r);
|
|
980
992
|
} catch (i) {
|
|
981
993
|
console.error(i);
|
|
982
994
|
}
|
|
983
|
-
const a =
|
|
995
|
+
const a = n.map((i) => ({
|
|
984
996
|
address: e,
|
|
985
997
|
market: i.key
|
|
986
998
|
})).concat(
|
|
987
|
-
t.filter((i) => !!
|
|
999
|
+
t.filter((i) => !!n.find((c) => c.id === i.marketId)).map((i) => ({
|
|
988
1000
|
address: i.accountCap,
|
|
989
1001
|
market: j(i.marketId).key,
|
|
990
1002
|
emodeId: i.emodeId
|
|
991
1003
|
}))
|
|
992
1004
|
);
|
|
993
|
-
return (await
|
|
994
|
-
const
|
|
1005
|
+
return (await oe(e, a, r)).forEach((i) => {
|
|
1006
|
+
const c = typeof i.emodeId == "number" ? t.find((l) => {
|
|
995
1007
|
const d = j(i.market);
|
|
996
1008
|
return l.emodeId === i.emodeId && l.marketId === d.id;
|
|
997
1009
|
}) : void 0;
|
|
998
|
-
if (
|
|
999
|
-
if (!i.pool.emodes.find((d) => d.emodeId ===
|
|
1010
|
+
if (c) {
|
|
1011
|
+
if (!i.pool.emodes.find((d) => d.emodeId === c.emodeId))
|
|
1000
1012
|
return;
|
|
1001
1013
|
if (p(i.supplyBalance).gte(0)) {
|
|
1002
|
-
const d = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y =
|
|
1014
|
+
const d = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = L(i.pool, c);
|
|
1003
1015
|
if (d.gt(0) || y.emode.isCollateral)
|
|
1004
1016
|
try {
|
|
1005
1017
|
o.push({
|
|
1006
|
-
id: `${i.pool.uniqueId}_${
|
|
1018
|
+
id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-supply-${T()}`,
|
|
1007
1019
|
wallet: e,
|
|
1008
1020
|
protocol: "navi",
|
|
1009
1021
|
market: i.market,
|
|
1010
1022
|
type: "navi-lending-emode-supply",
|
|
1011
1023
|
"navi-lending-emode-supply": {
|
|
1012
1024
|
amount: d.toString(),
|
|
1013
|
-
pool:
|
|
1025
|
+
pool: L(i.pool, c),
|
|
1014
1026
|
token: i.pool.token,
|
|
1015
1027
|
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
1016
|
-
emodeCap:
|
|
1028
|
+
emodeCap: c
|
|
1017
1029
|
}
|
|
1018
1030
|
});
|
|
1019
1031
|
} catch (v) {
|
|
@@ -1021,21 +1033,21 @@ const Pe = P(
|
|
|
1021
1033
|
}
|
|
1022
1034
|
}
|
|
1023
1035
|
if (p(i.borrowBalance).gte(0)) {
|
|
1024
|
-
const d = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y =
|
|
1036
|
+
const d = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), y = L(i.pool, c);
|
|
1025
1037
|
if (d.gt(0) || y.emode.isDebt)
|
|
1026
1038
|
try {
|
|
1027
1039
|
o.push({
|
|
1028
|
-
id: `${i.pool.uniqueId}_${
|
|
1040
|
+
id: `${i.pool.uniqueId}_${c.emodeId}_navi-lending-emode-borrow-${T()}`,
|
|
1029
1041
|
wallet: e,
|
|
1030
1042
|
protocol: "navi",
|
|
1031
1043
|
market: i.market,
|
|
1032
1044
|
type: "navi-lending-emode-borrow",
|
|
1033
1045
|
"navi-lending-emode-borrow": {
|
|
1034
1046
|
amount: d.toString(),
|
|
1035
|
-
pool:
|
|
1047
|
+
pool: L(i.pool, c),
|
|
1036
1048
|
token: i.pool.token,
|
|
1037
1049
|
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
1038
|
-
emodeCap:
|
|
1050
|
+
emodeCap: c
|
|
1039
1051
|
}
|
|
1040
1052
|
});
|
|
1041
1053
|
} catch (v) {
|
|
@@ -1079,8 +1091,8 @@ const Pe = P(
|
|
|
1079
1091
|
}), o;
|
|
1080
1092
|
}
|
|
1081
1093
|
);
|
|
1082
|
-
class
|
|
1083
|
-
constructor(
|
|
1094
|
+
class N {
|
|
1095
|
+
constructor(r, o) {
|
|
1084
1096
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1085
1097
|
hf: 1 / 0,
|
|
1086
1098
|
netVaule: "0",
|
|
@@ -1093,7 +1105,7 @@ class O {
|
|
|
1093
1105
|
maxLoanToVaule: "0",
|
|
1094
1106
|
supply: {},
|
|
1095
1107
|
borrow: {}
|
|
1096
|
-
}, this._priceMap = o || {}, this.positions =
|
|
1108
|
+
}, this._priceMap = o || {}, this.positions = r;
|
|
1097
1109
|
}
|
|
1098
1110
|
get positions() {
|
|
1099
1111
|
return this._positions;
|
|
@@ -1104,33 +1116,33 @@ class O {
|
|
|
1104
1116
|
get priceMap() {
|
|
1105
1117
|
return this._priceMap;
|
|
1106
1118
|
}
|
|
1107
|
-
set positions(
|
|
1108
|
-
this._positions =
|
|
1119
|
+
set positions(r) {
|
|
1120
|
+
this._positions = r, this._overview = this.getPositionsOverview(r);
|
|
1109
1121
|
}
|
|
1110
|
-
updatePriceMap(
|
|
1111
|
-
return this._priceMap =
|
|
1122
|
+
updatePriceMap(r) {
|
|
1123
|
+
return this._priceMap = r, this._overview = this.getPositionsOverview(this._positions), this;
|
|
1112
1124
|
}
|
|
1113
|
-
getPrice(
|
|
1114
|
-
const o =
|
|
1125
|
+
getPrice(r) {
|
|
1126
|
+
const o = b(r.suiCoinType);
|
|
1115
1127
|
if (this._priceMap[o] !== void 0)
|
|
1116
1128
|
return this._priceMap[o].toString();
|
|
1117
|
-
const
|
|
1118
|
-
return this._priceMap[
|
|
1129
|
+
const n = r.suiCoinType;
|
|
1130
|
+
return this._priceMap[n] !== void 0 ? this._priceMap[n].toString() : r.oracle.price;
|
|
1119
1131
|
}
|
|
1120
|
-
filterPositionsByPool(
|
|
1121
|
-
const
|
|
1122
|
-
return new
|
|
1132
|
+
filterPositionsByPool(r) {
|
|
1133
|
+
const n = !!r.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1134
|
+
return new N(
|
|
1123
1135
|
this.positions.filter((t) => {
|
|
1124
1136
|
const a = t[t.type];
|
|
1125
|
-
return
|
|
1137
|
+
return n.includes(t.type) && a.pool.uniqueId === r.uniqueId;
|
|
1126
1138
|
}),
|
|
1127
1139
|
this._priceMap
|
|
1128
1140
|
);
|
|
1129
1141
|
}
|
|
1130
|
-
deposit(
|
|
1131
|
-
const
|
|
1142
|
+
deposit(r, o) {
|
|
1143
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1132
1144
|
let a;
|
|
1133
|
-
return
|
|
1145
|
+
return n ? a = {
|
|
1134
1146
|
id: T(),
|
|
1135
1147
|
wallet: "",
|
|
1136
1148
|
protocol: "navi",
|
|
@@ -1139,8 +1151,8 @@ class O {
|
|
|
1139
1151
|
"navi-lending-emode-supply": {
|
|
1140
1152
|
amount: o.toString(),
|
|
1141
1153
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1142
|
-
token:
|
|
1143
|
-
pool:
|
|
1154
|
+
token: r.token,
|
|
1155
|
+
pool: r,
|
|
1144
1156
|
emodeCap: {}
|
|
1145
1157
|
}
|
|
1146
1158
|
} : a = {
|
|
@@ -1152,15 +1164,15 @@ class O {
|
|
|
1152
1164
|
"navi-lending-supply": {
|
|
1153
1165
|
amount: o.toString(),
|
|
1154
1166
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1155
|
-
token:
|
|
1156
|
-
pool:
|
|
1167
|
+
token: r.token,
|
|
1168
|
+
pool: r
|
|
1157
1169
|
}
|
|
1158
|
-
}, new
|
|
1170
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1159
1171
|
}
|
|
1160
|
-
withdraw(
|
|
1161
|
-
const
|
|
1172
|
+
withdraw(r, o) {
|
|
1173
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1162
1174
|
let a;
|
|
1163
|
-
return
|
|
1175
|
+
return n ? a = {
|
|
1164
1176
|
id: T(),
|
|
1165
1177
|
wallet: "",
|
|
1166
1178
|
protocol: "navi",
|
|
@@ -1169,8 +1181,8 @@ class O {
|
|
|
1169
1181
|
"navi-lending-emode-supply": {
|
|
1170
1182
|
amount: (-o).toString(),
|
|
1171
1183
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1172
|
-
token:
|
|
1173
|
-
pool:
|
|
1184
|
+
token: r.token,
|
|
1185
|
+
pool: r,
|
|
1174
1186
|
emodeCap: {}
|
|
1175
1187
|
}
|
|
1176
1188
|
} : a = {
|
|
@@ -1182,15 +1194,15 @@ class O {
|
|
|
1182
1194
|
"navi-lending-supply": {
|
|
1183
1195
|
amount: (-o).toString(),
|
|
1184
1196
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1185
|
-
token:
|
|
1186
|
-
pool:
|
|
1197
|
+
token: r.token,
|
|
1198
|
+
pool: r
|
|
1187
1199
|
}
|
|
1188
|
-
}, new
|
|
1200
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1189
1201
|
}
|
|
1190
|
-
borrow(
|
|
1191
|
-
const
|
|
1202
|
+
borrow(r, o) {
|
|
1203
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1192
1204
|
let a;
|
|
1193
|
-
return
|
|
1205
|
+
return n ? a = {
|
|
1194
1206
|
id: T(),
|
|
1195
1207
|
wallet: "",
|
|
1196
1208
|
protocol: "navi",
|
|
@@ -1199,8 +1211,8 @@ class O {
|
|
|
1199
1211
|
"navi-lending-emode-borrow": {
|
|
1200
1212
|
amount: o.toString(),
|
|
1201
1213
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1202
|
-
token:
|
|
1203
|
-
pool:
|
|
1214
|
+
token: r.token,
|
|
1215
|
+
pool: r,
|
|
1204
1216
|
emodeCap: {}
|
|
1205
1217
|
}
|
|
1206
1218
|
} : a = {
|
|
@@ -1212,15 +1224,15 @@ class O {
|
|
|
1212
1224
|
"navi-lending-borrow": {
|
|
1213
1225
|
amount: o.toString(),
|
|
1214
1226
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1215
|
-
token:
|
|
1216
|
-
pool:
|
|
1227
|
+
token: r.token,
|
|
1228
|
+
pool: r
|
|
1217
1229
|
}
|
|
1218
|
-
}, new
|
|
1230
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1219
1231
|
}
|
|
1220
|
-
repay(
|
|
1221
|
-
const
|
|
1232
|
+
repay(r, o) {
|
|
1233
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1222
1234
|
let a;
|
|
1223
|
-
return
|
|
1235
|
+
return n ? a = {
|
|
1224
1236
|
id: T(),
|
|
1225
1237
|
wallet: "",
|
|
1226
1238
|
protocol: "navi",
|
|
@@ -1229,8 +1241,8 @@ class O {
|
|
|
1229
1241
|
"navi-lending-emode-borrow": {
|
|
1230
1242
|
amount: (-o).toString(),
|
|
1231
1243
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1232
|
-
token:
|
|
1233
|
-
pool:
|
|
1244
|
+
token: r.token,
|
|
1245
|
+
pool: r,
|
|
1234
1246
|
emodeCap: {}
|
|
1235
1247
|
}
|
|
1236
1248
|
} : a = {
|
|
@@ -1242,21 +1254,21 @@ class O {
|
|
|
1242
1254
|
"navi-lending-borrow": {
|
|
1243
1255
|
amount: (-o).toString(),
|
|
1244
1256
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1245
|
-
token:
|
|
1246
|
-
pool:
|
|
1257
|
+
token: r.token,
|
|
1258
|
+
pool: r
|
|
1247
1259
|
}
|
|
1248
|
-
}, new
|
|
1260
|
+
}, new N([...this.positions, a], this._priceMap);
|
|
1249
1261
|
}
|
|
1250
|
-
resolveValueUSD(
|
|
1251
|
-
return Object.keys(this._priceMap).length > 0 ? p(
|
|
1262
|
+
resolveValueUSD(r) {
|
|
1263
|
+
return Object.keys(this._priceMap).length > 0 ? p(r.amount).multipliedBy(this.getPrice(r.pool)).toString() : r.valueUSD;
|
|
1252
1264
|
}
|
|
1253
|
-
getPositionsOverview(
|
|
1254
|
-
const o = {},
|
|
1255
|
-
let t = new p(0), a = new p(0),
|
|
1256
|
-
|
|
1265
|
+
getPositionsOverview(r) {
|
|
1266
|
+
const o = {}, n = {};
|
|
1267
|
+
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);
|
|
1268
|
+
r.forEach((g) => {
|
|
1257
1269
|
if (g.type === "navi-lending-supply") {
|
|
1258
1270
|
const u = g["navi-lending-supply"], f = this.resolveValueUSD(u);
|
|
1259
|
-
t = t.plus(f),
|
|
1271
|
+
t = t.plus(f), c = c.plus(
|
|
1260
1272
|
new p(f).multipliedBy(u.pool.liquidationFactor.threshold)
|
|
1261
1273
|
), l = l.plus(
|
|
1262
1274
|
new p(f).multipliedBy(u.pool.ltvValue)
|
|
@@ -1267,59 +1279,59 @@ class O {
|
|
|
1267
1279
|
} else if (g.type === "navi-lending-emode-supply") {
|
|
1268
1280
|
const u = g["navi-lending-emode-supply"], f = this.resolveValueUSD(u);
|
|
1269
1281
|
t = t.plus(f);
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1272
|
-
new p(f).multipliedBy(
|
|
1282
|
+
const k = u.pool.emode;
|
|
1283
|
+
c = c.plus(
|
|
1284
|
+
new p(f).multipliedBy(k.lt)
|
|
1273
1285
|
), l = l.plus(
|
|
1274
|
-
new p(f).multipliedBy(
|
|
1286
|
+
new p(f).multipliedBy(k.ltv)
|
|
1275
1287
|
);
|
|
1276
1288
|
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1277
1289
|
const u = g["navi-lending-emode-borrow"];
|
|
1278
1290
|
a = a.plus(this.resolveValueUSD(u));
|
|
1279
1291
|
}
|
|
1280
|
-
}), a = p.max(a, 0), t = p.max(t, 0),
|
|
1292
|
+
}), a = p.max(a, 0), t = p.max(t, 0), c = p.max(c, 0), l = p.max(l, 0), r.forEach((g) => {
|
|
1281
1293
|
if (g.type === "navi-lending-supply") {
|
|
1282
|
-
const u = g["navi-lending-supply"], f = this.resolveValueUSD(u),
|
|
1283
|
-
t.gt(0) && (
|
|
1284
|
-
new p(f).dividedBy(t).multipliedBy(new p(
|
|
1294
|
+
const u = g["navi-lending-supply"], f = this.resolveValueUSD(u), k = u.pool.supplyIncentiveApyInfo.apy;
|
|
1295
|
+
t.gt(0) && (s = s.plus(
|
|
1296
|
+
new p(f).dividedBy(t).multipliedBy(new p(k).dividedBy(100))
|
|
1285
1297
|
)), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1286
1298
|
} else if (g.type === "navi-lending-borrow") {
|
|
1287
|
-
const u = g["navi-lending-borrow"], f = this.resolveValueUSD(u),
|
|
1299
|
+
const u = g["navi-lending-borrow"], f = this.resolveValueUSD(u), k = u.pool.borrowIncentiveApyInfo.apy;
|
|
1288
1300
|
a.gt(0) && (i = i.plus(
|
|
1289
|
-
new p(f).dividedBy(a).multipliedBy(new p(
|
|
1290
|
-
)),
|
|
1301
|
+
new p(f).dividedBy(a).multipliedBy(new p(k).dividedBy(100))
|
|
1302
|
+
)), n[u.pool.suiCoinType] = p(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1291
1303
|
} else if (g.type === "navi-lending-emode-supply") {
|
|
1292
|
-
const u = g["navi-lending-emode-supply"], f = this.resolveValueUSD(u),
|
|
1293
|
-
t.gt(0) && (
|
|
1294
|
-
new p(f).dividedBy(t).multipliedBy(new p(
|
|
1304
|
+
const u = g["navi-lending-emode-supply"], f = this.resolveValueUSD(u), k = u.pool.supplyIncentiveApyInfo.apy;
|
|
1305
|
+
t.gt(0) && (s = s.plus(
|
|
1306
|
+
new p(f).dividedBy(t).multipliedBy(new p(k).dividedBy(100))
|
|
1295
1307
|
)), o[u.pool.suiCoinType] = p(o[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1296
1308
|
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1297
|
-
const u = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(u),
|
|
1309
|
+
const u = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(u), k = u.pool.borrowIncentiveApyInfo.apy;
|
|
1298
1310
|
a.gt(0) && (i = i.plus(
|
|
1299
|
-
new p(f).dividedBy(a).multipliedBy(new p(
|
|
1300
|
-
)),
|
|
1311
|
+
new p(f).dividedBy(a).multipliedBy(new p(k).dividedBy(100))
|
|
1312
|
+
)), n[u.pool.suiCoinType] = p(n[u.pool.suiCoinType] || 0).plus(u.amount).toString();
|
|
1301
1313
|
}
|
|
1302
1314
|
});
|
|
1303
|
-
const d = t.minus(a), y = t.minus(a).eq(0) ? new p(0) : t.multipliedBy(
|
|
1315
|
+
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));
|
|
1304
1316
|
return {
|
|
1305
|
-
hf: a.toNumber() !== 0 ?
|
|
1317
|
+
hf: a.toNumber() !== 0 ? c.dividedBy(a).toNumber() : 1 / 0,
|
|
1306
1318
|
netVaule: d.toString(),
|
|
1307
1319
|
netWorthApr: y.toString(),
|
|
1308
1320
|
totalSupplyValue: t.toString(),
|
|
1309
1321
|
totalBorrowValue: a.toString(),
|
|
1310
|
-
totalsupplyApy:
|
|
1322
|
+
totalsupplyApy: s.toString(),
|
|
1311
1323
|
totalBorrowApy: i.toString(),
|
|
1312
|
-
maxLiquidationValue:
|
|
1324
|
+
maxLiquidationValue: c.toString(),
|
|
1313
1325
|
maxLoanToVaule: l.toString(),
|
|
1314
1326
|
supply: o,
|
|
1315
|
-
borrow:
|
|
1327
|
+
borrow: n
|
|
1316
1328
|
};
|
|
1317
1329
|
}
|
|
1318
1330
|
}
|
|
1319
|
-
async function
|
|
1331
|
+
async function dt(e, r, o, n) {
|
|
1320
1332
|
const t = await _({
|
|
1321
|
-
...
|
|
1322
|
-
cacheTime:
|
|
1333
|
+
...n,
|
|
1334
|
+
cacheTime: w
|
|
1323
1335
|
});
|
|
1324
1336
|
t.limter && e.moveCall({
|
|
1325
1337
|
target: `${t.limter}::navi_adaptor::verify_navi_position_healthy`,
|
|
@@ -1327,61 +1339,61 @@ async function pt(e, n, o, r) {
|
|
|
1327
1339
|
e.object("0x06"),
|
|
1328
1340
|
e.object(t.storage),
|
|
1329
1341
|
e.object(t.priceOracle),
|
|
1330
|
-
h(
|
|
1342
|
+
h(r, e.pure.address),
|
|
1331
1343
|
e.pure.u256(new p(o).shiftedBy(27).toNumber())
|
|
1332
1344
|
]
|
|
1333
1345
|
});
|
|
1334
1346
|
}
|
|
1335
|
-
const
|
|
1347
|
+
const re = new Q("https://hermes.pyth.network", {
|
|
1336
1348
|
timeout: 1e4
|
|
1337
1349
|
});
|
|
1338
|
-
async function
|
|
1350
|
+
async function mt(e) {
|
|
1339
1351
|
try {
|
|
1340
|
-
const
|
|
1341
|
-
if (!o) return
|
|
1342
|
-
const
|
|
1352
|
+
const r = [], o = await re.getLatestPriceFeeds(e);
|
|
1353
|
+
if (!o) return r;
|
|
1354
|
+
const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1343
1355
|
for (const t of o) {
|
|
1344
1356
|
const a = t.getPriceUnchecked();
|
|
1345
|
-
if (a.publishTime >
|
|
1357
|
+
if (a.publishTime > n) {
|
|
1346
1358
|
console.warn(
|
|
1347
|
-
`pyth price feed is invalid, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${
|
|
1359
|
+
`pyth price feed is invalid, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
|
|
1348
1360
|
);
|
|
1349
1361
|
continue;
|
|
1350
1362
|
}
|
|
1351
|
-
|
|
1352
|
-
`stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${
|
|
1353
|
-
),
|
|
1363
|
+
n - t.getPriceUnchecked().publishTime > 30 && (console.info(
|
|
1364
|
+
`stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
|
|
1365
|
+
), r.push(t.id));
|
|
1354
1366
|
}
|
|
1355
|
-
return
|
|
1356
|
-
} catch (
|
|
1357
|
-
throw new Error(`failed to get pyth stale price feed id, msg: ${
|
|
1367
|
+
return r;
|
|
1368
|
+
} catch (r) {
|
|
1369
|
+
throw new Error(`failed to get pyth stale price feed id, msg: ${r.message}`);
|
|
1358
1370
|
}
|
|
1359
1371
|
}
|
|
1360
|
-
async function
|
|
1372
|
+
async function Se(e, r) {
|
|
1361
1373
|
try {
|
|
1362
|
-
const o = [],
|
|
1374
|
+
const o = [], n = r?.client ?? S, t = e.map((s) => s.priceInfoObject), a = await n.multiGetObjects({
|
|
1363
1375
|
ids: Array.from(new Set(t)),
|
|
1364
1376
|
options: { showContent: !0 }
|
|
1365
1377
|
});
|
|
1366
|
-
for (const
|
|
1367
|
-
const i =
|
|
1378
|
+
for (const s of a) {
|
|
1379
|
+
const i = s.data;
|
|
1368
1380
|
if (!i || !i.content || i.content.dataType !== "moveObject") {
|
|
1369
1381
|
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
1370
1382
|
continue;
|
|
1371
1383
|
}
|
|
1372
|
-
const
|
|
1373
|
-
if (!
|
|
1384
|
+
const c = e.find((u) => u.priceInfoObject == i.objectId);
|
|
1385
|
+
if (!c) {
|
|
1374
1386
|
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
1375
1387
|
continue;
|
|
1376
1388
|
}
|
|
1377
1389
|
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;
|
|
1378
1390
|
o.push({
|
|
1379
|
-
priceFeedId:
|
|
1380
|
-
priceInfoObject:
|
|
1391
|
+
priceFeedId: c.priceFeedId,
|
|
1392
|
+
priceInfoObject: c.priceInfoObject,
|
|
1381
1393
|
price: y ? "-" + d : d,
|
|
1382
1394
|
conf: v,
|
|
1383
1395
|
publishTime: Number(g),
|
|
1384
|
-
expiration:
|
|
1396
|
+
expiration: c.expiration
|
|
1385
1397
|
});
|
|
1386
1398
|
}
|
|
1387
1399
|
return o;
|
|
@@ -1390,20 +1402,20 @@ async function $e(e, n) {
|
|
|
1390
1402
|
return;
|
|
1391
1403
|
}
|
|
1392
1404
|
}
|
|
1393
|
-
async function
|
|
1405
|
+
async function Ve(e, r) {
|
|
1394
1406
|
try {
|
|
1395
|
-
const o = [],
|
|
1396
|
-
if (!
|
|
1407
|
+
const o = [], n = await Se(e, r);
|
|
1408
|
+
if (!n) return o;
|
|
1397
1409
|
const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1398
|
-
for (const a of
|
|
1410
|
+
for (const a of n) {
|
|
1399
1411
|
if (a.publishTime > t) {
|
|
1400
1412
|
console.warn(
|
|
1401
1413
|
`pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
|
|
1402
1414
|
);
|
|
1403
1415
|
continue;
|
|
1404
1416
|
}
|
|
1405
|
-
const
|
|
1406
|
-
t - a.publishTime >
|
|
1417
|
+
const s = a.expiration || 60;
|
|
1418
|
+
t - a.publishTime > s && (console.info(
|
|
1407
1419
|
`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
|
|
1408
1420
|
), o.push(a.priceFeedId));
|
|
1409
1421
|
}
|
|
@@ -1412,51 +1424,51 @@ async function Se(e, n) {
|
|
|
1412
1424
|
throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`);
|
|
1413
1425
|
}
|
|
1414
1426
|
}
|
|
1415
|
-
async function
|
|
1416
|
-
const
|
|
1427
|
+
async function Me(e, r, o) {
|
|
1428
|
+
const n = o?.client ?? S, t = await _({
|
|
1417
1429
|
...o,
|
|
1418
|
-
cacheTime:
|
|
1430
|
+
cacheTime: w
|
|
1419
1431
|
});
|
|
1420
1432
|
try {
|
|
1421
|
-
const a = await
|
|
1422
|
-
return await new
|
|
1423
|
-
|
|
1433
|
+
const a = await re.getPriceFeedsUpdateData(r);
|
|
1434
|
+
return await new me(
|
|
1435
|
+
n,
|
|
1424
1436
|
t.oracle.pythStateId,
|
|
1425
1437
|
t.oracle.wormholeStateId
|
|
1426
|
-
).updatePriceFeeds(e, a,
|
|
1438
|
+
).updatePriceFeeds(e, a, r);
|
|
1427
1439
|
} catch (a) {
|
|
1428
1440
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
1429
1441
|
}
|
|
1430
1442
|
}
|
|
1431
|
-
async function
|
|
1432
|
-
const
|
|
1443
|
+
async function Ee(e, r, o) {
|
|
1444
|
+
const n = await _({
|
|
1433
1445
|
...o,
|
|
1434
|
-
cacheTime:
|
|
1446
|
+
cacheTime: w
|
|
1435
1447
|
});
|
|
1436
1448
|
if (o?.updatePythPriceFeeds) {
|
|
1437
|
-
const t =
|
|
1449
|
+
const t = r.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
|
|
1438
1450
|
priceFeedId: a.pythPriceFeedId,
|
|
1439
1451
|
priceInfoObject: a.pythPriceInfoObject,
|
|
1440
1452
|
expiration: 30
|
|
1441
1453
|
}));
|
|
1442
1454
|
try {
|
|
1443
|
-
const a = await
|
|
1444
|
-
a.length > 0 && await
|
|
1455
|
+
const a = await Ve(t, o);
|
|
1456
|
+
a.length > 0 && await Me(e, a, o);
|
|
1445
1457
|
} catch {
|
|
1446
1458
|
console.error("Failed to update Pyth price feeds");
|
|
1447
1459
|
}
|
|
1448
1460
|
}
|
|
1449
|
-
for (const t of
|
|
1461
|
+
for (const t of r)
|
|
1450
1462
|
o?.env === "dev" ? e.moveCall({
|
|
1451
|
-
target: `${
|
|
1463
|
+
target: `${n.oracle.packageId}::oracle_pro::update_single_price`,
|
|
1452
1464
|
arguments: [
|
|
1453
1465
|
e.object("0x6"),
|
|
1454
1466
|
// Clock object
|
|
1455
|
-
e.object(
|
|
1467
|
+
e.object(n.oracle.oracleConfig),
|
|
1456
1468
|
// Oracle configuration
|
|
1457
|
-
e.object(
|
|
1469
|
+
e.object(n.oracle.priceOracle),
|
|
1458
1470
|
// Price oracle contract
|
|
1459
|
-
e.object(
|
|
1471
|
+
e.object(n.oracle.supraOracleHolder),
|
|
1460
1472
|
// Supra oracle holder
|
|
1461
1473
|
e.object(t.pythPriceInfoObject),
|
|
1462
1474
|
// Pyth price info object
|
|
@@ -1464,19 +1476,19 @@ async function Me(e, n, o) {
|
|
|
1464
1476
|
// Price feed ID
|
|
1465
1477
|
]
|
|
1466
1478
|
}) : e.moveCall({
|
|
1467
|
-
target: `${
|
|
1479
|
+
target: `${n.oracle.packageId}::oracle_pro::update_single_price_v2`,
|
|
1468
1480
|
arguments: [
|
|
1469
1481
|
e.object("0x6"),
|
|
1470
1482
|
// Clock object
|
|
1471
|
-
e.object(
|
|
1483
|
+
e.object(n.oracle.oracleConfig),
|
|
1472
1484
|
// Oracle configuration
|
|
1473
|
-
e.object(
|
|
1485
|
+
e.object(n.oracle.priceOracle),
|
|
1474
1486
|
// Price oracle contract
|
|
1475
|
-
e.object(
|
|
1487
|
+
e.object(n.oracle.supraOracleHolder),
|
|
1476
1488
|
// Supra oracle holder
|
|
1477
1489
|
e.object(t.pythPriceInfoObject),
|
|
1478
1490
|
// Pyth price info object
|
|
1479
|
-
e.object(
|
|
1491
|
+
e.object(n.oracle.switchboardAggregator),
|
|
1480
1492
|
e.pure.address(t.feedId)
|
|
1481
1493
|
// Price feed ID
|
|
1482
1494
|
]
|
|
@@ -1486,11 +1498,11 @@ async function Me(e, n, o) {
|
|
|
1486
1498
|
async function ne(e) {
|
|
1487
1499
|
return (await _({
|
|
1488
1500
|
...e,
|
|
1489
|
-
cacheTime:
|
|
1501
|
+
cacheTime: w
|
|
1490
1502
|
})).oracle.feeds;
|
|
1491
1503
|
}
|
|
1492
|
-
function
|
|
1493
|
-
return e.filter((o) => !!(
|
|
1504
|
+
function De(e, r) {
|
|
1505
|
+
return e.filter((o) => !!(r?.lendingState && r.lendingState.find((t) => o.oracleId === t.pool.oracleId) || r?.lendingPositions && r.lendingPositions.find((t) => {
|
|
1494
1506
|
if (![
|
|
1495
1507
|
"navi-lending-supply",
|
|
1496
1508
|
"navi-lending-borrow",
|
|
@@ -1498,63 +1510,63 @@ function Ee(e, n) {
|
|
|
1498
1510
|
"navi-lending-emode-borrow"
|
|
1499
1511
|
].includes(t.type))
|
|
1500
1512
|
return !1;
|
|
1501
|
-
const
|
|
1502
|
-
return o.oracleId ===
|
|
1503
|
-
}) ||
|
|
1513
|
+
const s = t[t.type]?.pool;
|
|
1514
|
+
return o.oracleId === s?.oracleId;
|
|
1515
|
+
}) || r?.pools && r.pools.find((t) => o.oracleId === t.oracleId)));
|
|
1504
1516
|
}
|
|
1505
|
-
async function
|
|
1517
|
+
async function ft(e, r, o, n) {
|
|
1506
1518
|
try {
|
|
1507
1519
|
const t = await ne({
|
|
1508
|
-
...
|
|
1520
|
+
...n
|
|
1509
1521
|
}), a = [];
|
|
1510
1522
|
o.forEach((l) => {
|
|
1511
1523
|
a.includes(l.market) || a.push(l.market);
|
|
1512
1524
|
});
|
|
1513
|
-
const
|
|
1514
|
-
...
|
|
1525
|
+
const s = await $e(r, {
|
|
1526
|
+
...n,
|
|
1515
1527
|
markets: a
|
|
1516
|
-
}), i =
|
|
1517
|
-
lendingPositions:
|
|
1528
|
+
}), i = De(t, {
|
|
1529
|
+
lendingPositions: s,
|
|
1518
1530
|
pools: o
|
|
1519
1531
|
});
|
|
1520
|
-
return await
|
|
1532
|
+
return await Ee(e, i, {
|
|
1521
1533
|
updatePythPriceFeeds: !0,
|
|
1522
|
-
...
|
|
1534
|
+
...n
|
|
1523
1535
|
});
|
|
1524
1536
|
} catch (t) {
|
|
1525
|
-
if (
|
|
1537
|
+
if (n?.throws)
|
|
1526
1538
|
throw t;
|
|
1527
1539
|
return console.error(t), e;
|
|
1528
1540
|
}
|
|
1529
1541
|
}
|
|
1530
|
-
const
|
|
1542
|
+
const z = P(
|
|
1531
1543
|
B(
|
|
1532
1544
|
async (e) => {
|
|
1533
|
-
const
|
|
1534
|
-
return Object.keys(o.data).map((
|
|
1535
|
-
...o.data[
|
|
1536
|
-
coinType:
|
|
1545
|
+
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());
|
|
1546
|
+
return Object.keys(o.data).map((n) => ({
|
|
1547
|
+
...o.data[n],
|
|
1548
|
+
coinType: n
|
|
1537
1549
|
}));
|
|
1538
1550
|
}
|
|
1539
1551
|
)
|
|
1540
1552
|
);
|
|
1541
|
-
async function
|
|
1542
|
-
return (await
|
|
1553
|
+
async function yt(e, r) {
|
|
1554
|
+
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;
|
|
1543
1555
|
}
|
|
1544
|
-
async function
|
|
1556
|
+
async function gt(e, r, o, n) {
|
|
1545
1557
|
const t = await _({
|
|
1546
|
-
...
|
|
1547
|
-
cacheTime:
|
|
1548
|
-
}), a = await A(
|
|
1549
|
-
if (!(await
|
|
1550
|
-
...
|
|
1551
|
-
cacheTime:
|
|
1558
|
+
...n,
|
|
1559
|
+
cacheTime: w
|
|
1560
|
+
}), a = await A(r, n);
|
|
1561
|
+
if (!(await z({
|
|
1562
|
+
...n,
|
|
1563
|
+
cacheTime: w
|
|
1552
1564
|
})).some(
|
|
1553
|
-
(
|
|
1565
|
+
(c) => b(c.coinType) === b(a.suiCoinType)
|
|
1554
1566
|
))
|
|
1555
1567
|
throw new Error("Pool does not support flashloan");
|
|
1556
1568
|
if (t.version === 1) {
|
|
1557
|
-
const [
|
|
1569
|
+
const [c, l] = e.moveCall({
|
|
1558
1570
|
target: `${t.package}::lending::flash_loan_with_ctx`,
|
|
1559
1571
|
arguments: [
|
|
1560
1572
|
e.object(t.flashloanConfig),
|
|
@@ -1563,9 +1575,9 @@ async function yt(e, n, o, r) {
|
|
|
1563
1575
|
],
|
|
1564
1576
|
typeArguments: [a.suiCoinType]
|
|
1565
1577
|
});
|
|
1566
|
-
return [
|
|
1578
|
+
return [c, l];
|
|
1567
1579
|
} else {
|
|
1568
|
-
const [
|
|
1580
|
+
const [c, l] = e.moveCall({
|
|
1569
1581
|
target: `${t.package}::lending::flash_loan_with_ctx_v2`,
|
|
1570
1582
|
arguments: [
|
|
1571
1583
|
e.object(t.flashloanConfig),
|
|
@@ -1575,19 +1587,19 @@ async function yt(e, n, o, r) {
|
|
|
1575
1587
|
],
|
|
1576
1588
|
typeArguments: [a.suiCoinType]
|
|
1577
1589
|
});
|
|
1578
|
-
return [
|
|
1590
|
+
return [c, l];
|
|
1579
1591
|
}
|
|
1580
1592
|
}
|
|
1581
|
-
async function
|
|
1593
|
+
async function ht(e, r, o, n, t) {
|
|
1582
1594
|
const a = await _({
|
|
1583
1595
|
...t,
|
|
1584
|
-
cacheTime:
|
|
1585
|
-
}),
|
|
1586
|
-
if (!(await
|
|
1596
|
+
cacheTime: w
|
|
1597
|
+
}), s = await A(r, t);
|
|
1598
|
+
if (!(await z({
|
|
1587
1599
|
...t,
|
|
1588
|
-
cacheTime:
|
|
1600
|
+
cacheTime: w
|
|
1589
1601
|
})).some(
|
|
1590
|
-
(d) =>
|
|
1602
|
+
(d) => b(d.coinType) === b(s.suiCoinType)
|
|
1591
1603
|
))
|
|
1592
1604
|
throw new Error("Pool does not support flashloan");
|
|
1593
1605
|
const [l] = e.moveCall({
|
|
@@ -1595,19 +1607,19 @@ async function gt(e, n, o, r, t) {
|
|
|
1595
1607
|
arguments: [
|
|
1596
1608
|
e.object("0x06"),
|
|
1597
1609
|
e.object(a.storage),
|
|
1598
|
-
e.object(
|
|
1610
|
+
e.object(s.contract.pool),
|
|
1599
1611
|
h(o, e.object),
|
|
1600
|
-
h(
|
|
1612
|
+
h(n, e.object)
|
|
1601
1613
|
],
|
|
1602
|
-
typeArguments: [
|
|
1614
|
+
typeArguments: [s.suiCoinType]
|
|
1603
1615
|
});
|
|
1604
1616
|
return [l];
|
|
1605
1617
|
}
|
|
1606
|
-
async function
|
|
1607
|
-
const
|
|
1618
|
+
async function vt(e, r, o, n, t, a) {
|
|
1619
|
+
const s = {
|
|
1608
1620
|
...a,
|
|
1609
|
-
cacheTime:
|
|
1610
|
-
}, i = await _(
|
|
1621
|
+
cacheTime: w
|
|
1622
|
+
}, i = await _(s), c = await A(r, s), l = await A(n, s);
|
|
1611
1623
|
if (i.version === 1) {
|
|
1612
1624
|
const [d, y] = e.moveCall({
|
|
1613
1625
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
@@ -1618,9 +1630,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1618
1630
|
// Price oracle for asset pricing
|
|
1619
1631
|
e.object(i.storage),
|
|
1620
1632
|
// Protocol storage
|
|
1621
|
-
e.pure.u8(
|
|
1633
|
+
e.pure.u8(c.id),
|
|
1622
1634
|
// Pay asset ID
|
|
1623
|
-
e.object(
|
|
1635
|
+
e.object(c.contract.pool),
|
|
1624
1636
|
// Pay asset pool contract
|
|
1625
1637
|
h(o, e.object),
|
|
1626
1638
|
// Debt repayment amount
|
|
@@ -1635,7 +1647,7 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1635
1647
|
e.object(i.incentiveV3)
|
|
1636
1648
|
// Incentive V3 contract
|
|
1637
1649
|
],
|
|
1638
|
-
typeArguments: [
|
|
1650
|
+
typeArguments: [c.suiCoinType, l.suiCoinType]
|
|
1639
1651
|
});
|
|
1640
1652
|
return [d, y];
|
|
1641
1653
|
} else {
|
|
@@ -1648,9 +1660,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1648
1660
|
// Price oracle for asset pricing
|
|
1649
1661
|
e.object(i.storage),
|
|
1650
1662
|
// Protocol storage
|
|
1651
|
-
e.pure.u8(
|
|
1663
|
+
e.pure.u8(c.id),
|
|
1652
1664
|
// Pay asset ID
|
|
1653
|
-
e.object(
|
|
1665
|
+
e.object(c.contract.pool),
|
|
1654
1666
|
// Pay asset pool contract
|
|
1655
1667
|
h(o, e.object),
|
|
1656
1668
|
// Debt repayment amount
|
|
@@ -1667,21 +1679,21 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1667
1679
|
e.object("0x05")
|
|
1668
1680
|
// SuiSystemState object
|
|
1669
1681
|
],
|
|
1670
|
-
typeArguments: [
|
|
1682
|
+
typeArguments: [c.suiCoinType, l.suiCoinType]
|
|
1671
1683
|
});
|
|
1672
1684
|
return [d, y];
|
|
1673
1685
|
}
|
|
1674
1686
|
}
|
|
1675
|
-
async function
|
|
1676
|
-
const
|
|
1687
|
+
async function Ue(e, r, o) {
|
|
1688
|
+
const n = o?.client ?? S, t = new F(), a = await q({
|
|
1677
1689
|
...o,
|
|
1678
1690
|
markets: Object.values(E),
|
|
1679
|
-
cacheTime:
|
|
1680
|
-
}),
|
|
1681
|
-
for (let d of
|
|
1691
|
+
cacheTime: w
|
|
1692
|
+
}), s = await ne(o);
|
|
1693
|
+
for (let d of r) {
|
|
1682
1694
|
const y = await _({
|
|
1683
1695
|
...o,
|
|
1684
|
-
cacheTime:
|
|
1696
|
+
cacheTime: w,
|
|
1685
1697
|
market: d.market
|
|
1686
1698
|
});
|
|
1687
1699
|
t.moveCall({
|
|
@@ -1698,13 +1710,13 @@ async function De(e, n, o) {
|
|
|
1698
1710
|
]
|
|
1699
1711
|
});
|
|
1700
1712
|
}
|
|
1701
|
-
const i = await
|
|
1713
|
+
const i = await n.devInspectTransactionBlock({
|
|
1702
1714
|
transactionBlock: t,
|
|
1703
1715
|
sender: e
|
|
1704
|
-
}),
|
|
1716
|
+
}), c = [];
|
|
1705
1717
|
i?.results?.forEach((d) => {
|
|
1706
|
-
|
|
1707
|
-
|
|
1718
|
+
c.push(
|
|
1719
|
+
W(
|
|
1708
1720
|
{
|
|
1709
1721
|
results: [d]
|
|
1710
1722
|
},
|
|
@@ -1724,20 +1736,20 @@ async function De(e, n, o) {
|
|
|
1724
1736
|
);
|
|
1725
1737
|
});
|
|
1726
1738
|
const l = [];
|
|
1727
|
-
return
|
|
1728
|
-
const v =
|
|
1739
|
+
return c.forEach((d, y) => {
|
|
1740
|
+
const v = r[y];
|
|
1729
1741
|
if (d.length === 5 && Array.isArray(d[0])) {
|
|
1730
1742
|
const g = d[0].length;
|
|
1731
1743
|
for (let u = 0; u < g; u++) {
|
|
1732
|
-
const f =
|
|
1733
|
-
(I) =>
|
|
1734
|
-
),
|
|
1735
|
-
(I) =>
|
|
1744
|
+
const f = s.find(
|
|
1745
|
+
(I) => b(I.coinType) === b(d[1][u])
|
|
1746
|
+
), k = a.find(
|
|
1747
|
+
(I) => b(I.coinType) === b(d[0][u]) && I.market === v.market
|
|
1736
1748
|
);
|
|
1737
|
-
!f || !
|
|
1738
|
-
assetId:
|
|
1739
|
-
assetCoinType:
|
|
1740
|
-
rewardCoinType:
|
|
1749
|
+
!f || !k || l.push({
|
|
1750
|
+
assetId: k.id,
|
|
1751
|
+
assetCoinType: b(d[0][u]),
|
|
1752
|
+
rewardCoinType: b(d[1][u]),
|
|
1741
1753
|
option: Number(d[2][u]),
|
|
1742
1754
|
userClaimableReward: Number(d[4][u]) / Math.pow(10, f.priceDecimal),
|
|
1743
1755
|
ruleIds: Array.isArray(d[3][u]) ? d[3][u] : [d[3][u]],
|
|
@@ -1750,11 +1762,11 @@ async function De(e, n, o) {
|
|
|
1750
1762
|
}
|
|
1751
1763
|
}), l;
|
|
1752
1764
|
}
|
|
1753
|
-
async function
|
|
1754
|
-
const o = (
|
|
1755
|
-
let
|
|
1765
|
+
async function wt(e, r) {
|
|
1766
|
+
const o = (r?.markets || [E.main]).map((a) => j(a));
|
|
1767
|
+
let n = [];
|
|
1756
1768
|
try {
|
|
1757
|
-
|
|
1769
|
+
n = await ee(e, r);
|
|
1758
1770
|
} catch (a) {
|
|
1759
1771
|
console.error(a);
|
|
1760
1772
|
}
|
|
@@ -1763,69 +1775,69 @@ async function vt(e, n) {
|
|
|
1763
1775
|
owner: e,
|
|
1764
1776
|
market: a.key
|
|
1765
1777
|
})).concat(
|
|
1766
|
-
|
|
1767
|
-
const
|
|
1778
|
+
n.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
|
|
1779
|
+
const s = j(a.marketId);
|
|
1768
1780
|
return {
|
|
1769
1781
|
address: a.accountCap,
|
|
1770
1782
|
owner: e,
|
|
1771
|
-
market:
|
|
1783
|
+
market: s.key,
|
|
1772
1784
|
emodeId: a.emodeId
|
|
1773
1785
|
};
|
|
1774
1786
|
})
|
|
1775
1787
|
);
|
|
1776
|
-
return await
|
|
1788
|
+
return await Ue(e, t, r);
|
|
1777
1789
|
}
|
|
1778
|
-
function
|
|
1779
|
-
const
|
|
1780
|
-
e.forEach((
|
|
1781
|
-
const t =
|
|
1782
|
-
|
|
1790
|
+
function bt(e) {
|
|
1791
|
+
const r = /* @__PURE__ */ new Map();
|
|
1792
|
+
e.forEach((n) => {
|
|
1793
|
+
const t = n.assetId, a = n.option, s = `${t}-${a}-${n.rewardCoinType}-${n.market}`;
|
|
1794
|
+
r.has(s) ? r.get(s).total += n.userClaimableReward : r.set(s, {
|
|
1783
1795
|
assetId: t,
|
|
1784
1796
|
rewardType: a,
|
|
1785
|
-
coinType:
|
|
1786
|
-
total: Number(
|
|
1787
|
-
market:
|
|
1797
|
+
coinType: n.rewardCoinType,
|
|
1798
|
+
total: Number(n.userClaimableReward),
|
|
1799
|
+
market: n.market
|
|
1788
1800
|
});
|
|
1789
1801
|
});
|
|
1790
1802
|
const o = /* @__PURE__ */ new Map();
|
|
1791
|
-
for (const { assetId:
|
|
1792
|
-
const
|
|
1793
|
-
o.has(
|
|
1794
|
-
const l = o.get(
|
|
1795
|
-
l.rewards.set(a, (l.rewards.get(a) || 0) +
|
|
1803
|
+
for (const { assetId: n, rewardType: t, coinType: a, total: s, market: i } of r.values()) {
|
|
1804
|
+
const c = `${n}-${t}-${i}`;
|
|
1805
|
+
o.has(c) || o.set(c, { assetId: n, rewardType: t, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
1806
|
+
const l = o.get(c);
|
|
1807
|
+
l.rewards.set(a, (l.rewards.get(a) || 0) + s);
|
|
1796
1808
|
}
|
|
1797
|
-
return Array.from(o.values()).map((
|
|
1798
|
-
assetId:
|
|
1799
|
-
rewardType:
|
|
1800
|
-
market:
|
|
1801
|
-
rewards: Array.from(
|
|
1809
|
+
return Array.from(o.values()).map((n) => ({
|
|
1810
|
+
assetId: n.assetId,
|
|
1811
|
+
rewardType: n.rewardType,
|
|
1812
|
+
market: n.market,
|
|
1813
|
+
rewards: Array.from(n.rewards.entries()).map(([t, a]) => ({
|
|
1802
1814
|
coinType: t,
|
|
1803
1815
|
available: a.toFixed(6)
|
|
1804
1816
|
}))
|
|
1805
1817
|
}));
|
|
1806
1818
|
}
|
|
1807
|
-
const
|
|
1808
|
-
async (e,
|
|
1809
|
-
const o = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${
|
|
1819
|
+
const kt = B(
|
|
1820
|
+
async (e, r) => {
|
|
1821
|
+
const o = `https://open-api.naviprotocol.io/api/navi/user/total_claimed_reward?userAddress=${e}&sdk=${V.version}&market=${r?.market || U}`;
|
|
1810
1822
|
return (await fetch(o, { headers: M }).then((t) => t.json())).data;
|
|
1811
1823
|
}
|
|
1812
|
-
),
|
|
1813
|
-
async (e,
|
|
1814
|
-
const o = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${
|
|
1815
|
-
return
|
|
1816
|
-
data:
|
|
1824
|
+
), _t = B(
|
|
1825
|
+
async (e, r) => {
|
|
1826
|
+
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());
|
|
1827
|
+
return H({
|
|
1828
|
+
data: n.data.rewards
|
|
1817
1829
|
});
|
|
1818
1830
|
}
|
|
1819
1831
|
);
|
|
1820
|
-
async function
|
|
1821
|
-
const
|
|
1832
|
+
async function Ct(e, r, o) {
|
|
1833
|
+
const n = await q({
|
|
1822
1834
|
...o,
|
|
1823
1835
|
markets: Object.values(E),
|
|
1824
|
-
cacheTime:
|
|
1836
|
+
cacheTime: w
|
|
1825
1837
|
}), t = /* @__PURE__ */ new Map();
|
|
1826
|
-
for (const
|
|
1827
|
-
const { rewardCoinType: i, ruleIds:
|
|
1828
|
-
for (const u of
|
|
1838
|
+
for (const s of r) {
|
|
1839
|
+
const { rewardCoinType: i, ruleIds: c, market: l, owner: d, address: y, emodeId: v } = s, g = `${i}___${y}__${l}`;
|
|
1840
|
+
for (const u of c) {
|
|
1829
1841
|
t.has(g) || t.set(g, {
|
|
1830
1842
|
assetIds: [],
|
|
1831
1843
|
ruleIds: [],
|
|
@@ -1836,27 +1848,30 @@ async function _t(e, n, o) {
|
|
|
1836
1848
|
isEMode: typeof v < "u"
|
|
1837
1849
|
});
|
|
1838
1850
|
const f = t.get(g);
|
|
1839
|
-
f.assetIds.push(
|
|
1851
|
+
f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(u), f.amount += s.userClaimableReward;
|
|
1840
1852
|
}
|
|
1841
1853
|
}
|
|
1842
1854
|
const a = [];
|
|
1843
1855
|
for (const [
|
|
1844
|
-
|
|
1845
|
-
{ assetIds: i, ruleIds:
|
|
1856
|
+
s,
|
|
1857
|
+
{ assetIds: i, ruleIds: c, amount: l, market: d, owner: y, address: v, isEMode: g }
|
|
1846
1858
|
] of t) {
|
|
1847
1859
|
const u = await _({
|
|
1848
1860
|
...o,
|
|
1849
|
-
cacheTime:
|
|
1861
|
+
cacheTime: w,
|
|
1850
1862
|
market: d
|
|
1851
|
-
}), f =
|
|
1852
|
-
|
|
1863
|
+
}), f = s.split("___")[0], k = n.filter(
|
|
1864
|
+
($) => b($.suiCoinType) === b(f)
|
|
1865
|
+
);
|
|
1866
|
+
k.sort(($, D) => $.market === d ? -1 : 1);
|
|
1867
|
+
const I = k[0], O = u.rewardFunds[b(f)];
|
|
1868
|
+
if (!O)
|
|
1853
1869
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${d}`);
|
|
1854
|
-
const I = w.contract.rewardFundId;
|
|
1855
1870
|
if (o?.accountCap && !o.customCoinReceive)
|
|
1856
1871
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
1857
1872
|
if (o?.customCoinReceive) {
|
|
1858
|
-
let
|
|
1859
|
-
o.accountCap ?
|
|
1873
|
+
let $;
|
|
1874
|
+
o.accountCap ? $ = e.moveCall({
|
|
1860
1875
|
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1861
1876
|
arguments: [
|
|
1862
1877
|
e.object("0x06"),
|
|
@@ -1865,17 +1880,17 @@ async function _t(e, n, o) {
|
|
|
1865
1880
|
// Incentive V3 contract
|
|
1866
1881
|
e.object(u.storage),
|
|
1867
1882
|
// Protocol storage
|
|
1868
|
-
e.object(
|
|
1883
|
+
e.object(O),
|
|
1869
1884
|
// Reward fund
|
|
1870
1885
|
e.pure.vector("string", i),
|
|
1871
1886
|
// Asset IDs
|
|
1872
|
-
e.pure.vector("address",
|
|
1887
|
+
e.pure.vector("address", c),
|
|
1873
1888
|
// Rule IDs
|
|
1874
1889
|
h(o.accountCap, e.object)
|
|
1875
1890
|
// Account capability
|
|
1876
1891
|
],
|
|
1877
1892
|
typeArguments: [f]
|
|
1878
|
-
}) : g ?
|
|
1893
|
+
}) : g ? $ = e.moveCall({
|
|
1879
1894
|
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1880
1895
|
arguments: [
|
|
1881
1896
|
e.object("0x06"),
|
|
@@ -1884,17 +1899,17 @@ async function _t(e, n, o) {
|
|
|
1884
1899
|
// Incentive V3 contract
|
|
1885
1900
|
e.object(u.storage),
|
|
1886
1901
|
// Protocol storage
|
|
1887
|
-
e.object(
|
|
1902
|
+
e.object(O),
|
|
1888
1903
|
// Reward fund
|
|
1889
1904
|
e.pure.vector("string", i),
|
|
1890
1905
|
// Asset IDs
|
|
1891
|
-
e.pure.vector("address",
|
|
1906
|
+
e.pure.vector("address", c),
|
|
1892
1907
|
// Rule IDs
|
|
1893
1908
|
h(v, e.object)
|
|
1894
1909
|
// Account capability
|
|
1895
1910
|
],
|
|
1896
1911
|
typeArguments: [f]
|
|
1897
|
-
}) :
|
|
1912
|
+
}) : $ = e.moveCall({
|
|
1898
1913
|
target: `${u.package}::incentive_v3::claim_reward`,
|
|
1899
1914
|
arguments: [
|
|
1900
1915
|
e.object("0x06"),
|
|
@@ -1903,43 +1918,46 @@ async function _t(e, n, o) {
|
|
|
1903
1918
|
// Incentive V3 contract
|
|
1904
1919
|
e.object(u.storage),
|
|
1905
1920
|
// Protocol storage
|
|
1906
|
-
e.object(
|
|
1921
|
+
e.object(O),
|
|
1907
1922
|
// Reward fund
|
|
1908
1923
|
e.pure.vector("string", i),
|
|
1909
1924
|
// Asset IDs
|
|
1910
|
-
e.pure.vector("address",
|
|
1925
|
+
e.pure.vector("address", c)
|
|
1911
1926
|
// Rule IDs
|
|
1912
1927
|
],
|
|
1913
1928
|
typeArguments: [f]
|
|
1914
1929
|
});
|
|
1915
|
-
const [
|
|
1930
|
+
const [D] = e.moveCall({
|
|
1916
1931
|
target: "0x2::coin::from_balance",
|
|
1917
|
-
arguments: [
|
|
1932
|
+
arguments: [$],
|
|
1918
1933
|
typeArguments: [f]
|
|
1919
1934
|
});
|
|
1920
1935
|
if (o?.customCoinReceive.type === "transfer") {
|
|
1921
1936
|
if (!o.customCoinReceive.transfer)
|
|
1922
1937
|
throw new Error("customCoinReceive.transfer is required");
|
|
1923
1938
|
e.transferObjects(
|
|
1924
|
-
[
|
|
1939
|
+
[D],
|
|
1925
1940
|
h(o.customCoinReceive.transfer, e.pure.address)
|
|
1926
1941
|
);
|
|
1927
1942
|
}
|
|
1928
1943
|
if (o?.customCoinReceive.type === "depositNAVI") {
|
|
1929
|
-
const
|
|
1930
|
-
|
|
1931
|
-
[
|
|
1944
|
+
const ae = p(I.totalSupplyAmount).shiftedBy(-9), ie = p(I.supplyCapCeiling).shiftedBy(-27);
|
|
1945
|
+
ae.plus(l).isGreaterThan(ie) && o?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
1946
|
+
[D],
|
|
1932
1947
|
e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1933
|
-
) : await
|
|
1948
|
+
) : await Ce(e, I, D, {
|
|
1949
|
+
...o,
|
|
1950
|
+
market: I.market
|
|
1951
|
+
});
|
|
1934
1952
|
} else
|
|
1935
1953
|
a.push({
|
|
1936
|
-
coin:
|
|
1937
|
-
identifier:
|
|
1954
|
+
coin: D,
|
|
1955
|
+
identifier: I,
|
|
1938
1956
|
owner: y,
|
|
1939
1957
|
isEMode: g
|
|
1940
1958
|
});
|
|
1941
1959
|
} else if (o?.accountCap || g) {
|
|
1942
|
-
const
|
|
1960
|
+
const $ = e.moveCall({
|
|
1943
1961
|
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1944
1962
|
arguments: [
|
|
1945
1963
|
e.object("0x06"),
|
|
@@ -1948,23 +1966,23 @@ async function _t(e, n, o) {
|
|
|
1948
1966
|
// Incentive V3 contract
|
|
1949
1967
|
e.object(u.storage),
|
|
1950
1968
|
// Protocol storage
|
|
1951
|
-
e.object(
|
|
1969
|
+
e.object(O),
|
|
1952
1970
|
// Reward fund
|
|
1953
1971
|
e.pure.vector("string", i),
|
|
1954
1972
|
// Asset IDs
|
|
1955
|
-
e.pure.vector("address",
|
|
1973
|
+
e.pure.vector("address", c),
|
|
1956
1974
|
// Rule IDs
|
|
1957
1975
|
h(o?.accountCap || v, e.object)
|
|
1958
1976
|
// Account capability
|
|
1959
1977
|
],
|
|
1960
1978
|
typeArguments: [f]
|
|
1961
|
-
}), [
|
|
1979
|
+
}), [D] = e.moveCall({
|
|
1962
1980
|
target: "0x2::coin::from_balance",
|
|
1963
|
-
arguments: [
|
|
1981
|
+
arguments: [$],
|
|
1964
1982
|
typeArguments: [f]
|
|
1965
1983
|
});
|
|
1966
1984
|
e.transferObjects(
|
|
1967
|
-
[
|
|
1985
|
+
[D],
|
|
1968
1986
|
h(o?.accountCap || y, e.pure.address)
|
|
1969
1987
|
);
|
|
1970
1988
|
} else
|
|
@@ -1977,11 +1995,11 @@ async function _t(e, n, o) {
|
|
|
1977
1995
|
// Incentive V3 contract
|
|
1978
1996
|
e.object(u.storage),
|
|
1979
1997
|
// Protocol storage
|
|
1980
|
-
e.object(
|
|
1998
|
+
e.object(O),
|
|
1981
1999
|
// Reward fund
|
|
1982
2000
|
e.pure.vector("string", i),
|
|
1983
2001
|
// Asset IDs
|
|
1984
|
-
e.pure.vector("address",
|
|
2002
|
+
e.pure.vector("address", c)
|
|
1985
2003
|
// Rule IDs
|
|
1986
2004
|
],
|
|
1987
2005
|
typeArguments: [f]
|
|
@@ -1990,71 +2008,71 @@ async function _t(e, n, o) {
|
|
|
1990
2008
|
return a;
|
|
1991
2009
|
}
|
|
1992
2010
|
export {
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2011
|
+
K as Address,
|
|
2012
|
+
w as DEFAULT_CACHE_TIME,
|
|
2013
|
+
U as DEFAULT_MARKET_IDENTITY,
|
|
2014
|
+
Ye as FlashLoanAssetConfig,
|
|
2015
|
+
Ge as IncentiveAPYInfo,
|
|
2016
|
+
fe as IncentivePoolInfo,
|
|
2017
|
+
ze as IncentivePoolInfoByPhase,
|
|
2000
2018
|
E as MARKETS,
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2019
|
+
je as Market,
|
|
2020
|
+
Ke as OracleInfo,
|
|
2021
|
+
R as PoolOperator,
|
|
2022
|
+
Je as ReserveDataInfo,
|
|
2023
|
+
N as UserPositions,
|
|
2024
|
+
ye as UserStateInfo,
|
|
2025
|
+
xe as borrowCoinPTB,
|
|
2026
|
+
Ct as claimLendingRewardsPTB,
|
|
2027
|
+
Te as createAccountCapPTB,
|
|
2010
2028
|
nt as createEModeCapPTB,
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2029
|
+
Ce as depositCoinPTB,
|
|
2030
|
+
at as emodeIdentityId,
|
|
2031
|
+
Ae as enterEModePTB,
|
|
2032
|
+
rt as exitEModePTB,
|
|
2033
|
+
De as filterPriceFeeds,
|
|
2034
|
+
gt as flashloanPTB,
|
|
2035
|
+
Be as getAccountCapOwnerPTB,
|
|
2036
|
+
z as getAllFlashLoanAssets,
|
|
2037
|
+
tt as getBorrowFee,
|
|
2038
|
+
pt as getCoins,
|
|
2021
2039
|
_ as getConfig,
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2040
|
+
Qe as getFees,
|
|
2041
|
+
yt as getFlashLoanAsset,
|
|
2042
|
+
st as getHealthFactor,
|
|
2043
|
+
Pe as getHealthFactorPTB,
|
|
2044
|
+
$e as getLendingPositions,
|
|
2045
|
+
ct as getLendingState,
|
|
2046
|
+
ot as getMarket,
|
|
2029
2047
|
j as getMarketConfig,
|
|
2030
|
-
|
|
2048
|
+
Ie as getMarkets,
|
|
2031
2049
|
A as getPool,
|
|
2032
|
-
|
|
2050
|
+
q as getPools,
|
|
2033
2051
|
ne as getPriceFeeds,
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2052
|
+
mt as getPythStalePriceFeedId,
|
|
2053
|
+
Ve as getPythStalePriceFeedIdV2,
|
|
2054
|
+
lt as getSimulatedHealthFactor,
|
|
2055
|
+
te as getSimulatedHealthFactorPTB,
|
|
2056
|
+
Ze as getStats,
|
|
2057
|
+
ut as getTransactions,
|
|
2058
|
+
wt as getUserAvailableLendingRewards,
|
|
2059
|
+
_t as getUserClaimedRewardHistory,
|
|
2060
|
+
ee as getUserEModeCaps,
|
|
2061
|
+
kt as getUserTotalClaimedReward,
|
|
2062
|
+
vt as liquidatePTB,
|
|
2063
|
+
it as mergeCoinsPTB,
|
|
2064
|
+
b as normalizeCoinType,
|
|
2065
|
+
_e as parsePoolUID,
|
|
2048
2066
|
h as parseTxValue,
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2067
|
+
et as repayCoinPTB,
|
|
2068
|
+
ht as repayFlashLoanPTB,
|
|
2069
|
+
bt as summaryLendingRewards,
|
|
2070
|
+
ft as updateOraclePriceBeforeUserOperationPTB,
|
|
2071
|
+
Ee as updateOraclePricesPTB,
|
|
2072
|
+
Me as updatePythPriceFeeds,
|
|
2073
|
+
dt as verifyHealthFactorPTB,
|
|
2056
2074
|
P as withCache,
|
|
2057
2075
|
B as withSingleton,
|
|
2058
|
-
|
|
2076
|
+
Xe as withdrawCoinPTB
|
|
2059
2077
|
};
|
|
2060
2078
|
//# sourceMappingURL=index.esm.js.map
|