@naviprotocol/lending 1.4.4-beta.3 → 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 +668 -663
- package/dist/index.esm.js.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,210 +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
154
|
const { client: a, disableCache: s, cacheTime: i, ...c } = o;
|
|
155
|
-
|
|
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 !
|
|
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
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 s =
|
|
264
|
-
const
|
|
265
|
-
return t.market ===
|
|
266
|
-
}).filter((f) => !!f.assets.find((
|
|
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
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(),
|
|
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 = c, t.poolSupplyValue =
|
|
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
|
-
|
|
314
|
-
const s =
|
|
310
|
+
...n,
|
|
311
|
+
cacheTime: w
|
|
312
|
+
}), a = await A(r, n);
|
|
313
|
+
n?.market;
|
|
314
|
+
const s = n?.env || "prod";
|
|
315
315
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
316
316
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
317
317
|
const i = typeof o == "object" && o.$kind === "GasCoin";
|
|
318
|
-
if (
|
|
319
|
-
if (!
|
|
318
|
+
if (b(a.suiCoinType) === b("0x2::sui::SUI") && i) {
|
|
319
|
+
if (!n?.amount)
|
|
320
320
|
throw new Error("Amount is required for sui coin");
|
|
321
|
-
o = e.splitCoins(o, [
|
|
321
|
+
o = e.splitCoins(o, [n.amount]);
|
|
322
322
|
}
|
|
323
323
|
let c;
|
|
324
|
-
return typeof
|
|
324
|
+
return typeof n?.amount < "u" ? c = h(n.amount, e.pure.u64) : c = e.moveCall({
|
|
325
325
|
target: "0x2::coin::value",
|
|
326
326
|
arguments: [h(o, e.object)],
|
|
327
327
|
typeArguments: [a.suiCoinType]
|
|
328
|
-
}),
|
|
328
|
+
}), n?.accountCap ? e.moveCall({
|
|
329
329
|
target: `${t.package}::incentive_v3::deposit_with_account_cap`,
|
|
330
330
|
arguments: [
|
|
331
331
|
e.object("0x06"),
|
|
@@ -335,7 +335,7 @@ async function _e(e, n, o, r) {
|
|
|
335
335
|
h(o, e.object),
|
|
336
336
|
e.object(t.incentiveV2),
|
|
337
337
|
e.object(t.incentiveV3),
|
|
338
|
-
h(
|
|
338
|
+
h(n.accountCap, e.object)
|
|
339
339
|
],
|
|
340
340
|
typeArguments: [a.suiCoinType]
|
|
341
341
|
}) : e.moveCall({
|
|
@@ -356,15 +356,15 @@ async function _e(e, n, o, r) {
|
|
|
356
356
|
arguments: [e.object(a.contract.pool), e.object("0x05")]
|
|
357
357
|
}), e;
|
|
358
358
|
}
|
|
359
|
-
async function
|
|
359
|
+
async function Xe(e, r, o, n) {
|
|
360
360
|
const t = await _({
|
|
361
|
-
...
|
|
362
|
-
cacheTime:
|
|
363
|
-
}), a = await A(
|
|
361
|
+
...n,
|
|
362
|
+
cacheTime: w
|
|
363
|
+
}), a = await A(r, n), s = h(o, e.pure.u64);
|
|
364
364
|
let i;
|
|
365
365
|
if (t.version === 1)
|
|
366
|
-
if (
|
|
367
|
-
const [
|
|
366
|
+
if (n?.accountCap) {
|
|
367
|
+
const [l] = e.moveCall({
|
|
368
368
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap`,
|
|
369
369
|
arguments: [
|
|
370
370
|
e.object("0x06"),
|
|
@@ -375,13 +375,13 @@ async function Qe(e, n, o, r) {
|
|
|
375
375
|
s,
|
|
376
376
|
e.object(t.incentiveV2),
|
|
377
377
|
e.object(t.incentiveV3),
|
|
378
|
-
h(
|
|
378
|
+
h(n.accountCap, e.object)
|
|
379
379
|
],
|
|
380
380
|
typeArguments: [a.suiCoinType]
|
|
381
381
|
});
|
|
382
|
-
i =
|
|
382
|
+
i = l;
|
|
383
383
|
} else {
|
|
384
|
-
const [
|
|
384
|
+
const [l] = e.moveCall({
|
|
385
385
|
target: `${t.package}::incentive_v3::withdraw`,
|
|
386
386
|
arguments: [
|
|
387
387
|
e.object("0x06"),
|
|
@@ -395,10 +395,10 @@ async function Qe(e, n, o, r) {
|
|
|
395
395
|
],
|
|
396
396
|
typeArguments: [a.suiCoinType]
|
|
397
397
|
});
|
|
398
|
-
i =
|
|
398
|
+
i = l;
|
|
399
399
|
}
|
|
400
|
-
else if (
|
|
401
|
-
const [
|
|
400
|
+
else if (n?.accountCap) {
|
|
401
|
+
const [l] = e.moveCall({
|
|
402
402
|
target: `${t.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
403
403
|
arguments: [
|
|
404
404
|
e.object("0x06"),
|
|
@@ -409,14 +409,14 @@ async function Qe(e, n, o, r) {
|
|
|
409
409
|
s,
|
|
410
410
|
e.object(t.incentiveV2),
|
|
411
411
|
e.object(t.incentiveV3),
|
|
412
|
-
h(
|
|
412
|
+
h(n.accountCap, e.object),
|
|
413
413
|
e.object("0x05")
|
|
414
414
|
],
|
|
415
415
|
typeArguments: [a.suiCoinType]
|
|
416
416
|
});
|
|
417
|
-
i =
|
|
417
|
+
i = l;
|
|
418
418
|
} else {
|
|
419
|
-
const [
|
|
419
|
+
const [l] = e.moveCall({
|
|
420
420
|
target: `${t.package}::incentive_v3::withdraw_v2`,
|
|
421
421
|
arguments: [
|
|
422
422
|
e.object("0x06"),
|
|
@@ -431,7 +431,7 @@ async function Qe(e, n, o, r) {
|
|
|
431
431
|
],
|
|
432
432
|
typeArguments: [a.suiCoinType]
|
|
433
433
|
});
|
|
434
|
-
i =
|
|
434
|
+
i = l;
|
|
435
435
|
}
|
|
436
436
|
return e.moveCall({
|
|
437
437
|
target: "0x2::coin::from_balance",
|
|
@@ -439,18 +439,18 @@ async function Qe(e, n, o, r) {
|
|
|
439
439
|
typeArguments: [a.suiCoinType]
|
|
440
440
|
});
|
|
441
441
|
}
|
|
442
|
-
async function
|
|
442
|
+
async function xe(e, r, o, n) {
|
|
443
443
|
const t = await _({
|
|
444
|
-
...
|
|
445
|
-
cacheTime:
|
|
446
|
-
}), a = await A(
|
|
444
|
+
...n,
|
|
445
|
+
cacheTime: w
|
|
446
|
+
}), a = await A(r, n);
|
|
447
447
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
448
448
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
449
449
|
const s = h(o, e.pure.u64);
|
|
450
450
|
let i;
|
|
451
451
|
if (t.version === 1)
|
|
452
|
-
if (
|
|
453
|
-
const [
|
|
452
|
+
if (n?.accountCap) {
|
|
453
|
+
const [l] = e.moveCall({
|
|
454
454
|
target: `${t.package}::incentive_v3::borrow_with_account_cap`,
|
|
455
455
|
arguments: [
|
|
456
456
|
e.object("0x06"),
|
|
@@ -461,13 +461,13 @@ async function Xe(e, n, o, r) {
|
|
|
461
461
|
s,
|
|
462
462
|
e.object(t.incentiveV2),
|
|
463
463
|
e.object(t.incentiveV3),
|
|
464
|
-
h(
|
|
464
|
+
h(n.accountCap, e.object)
|
|
465
465
|
],
|
|
466
466
|
typeArguments: [a.suiCoinType]
|
|
467
467
|
});
|
|
468
|
-
i =
|
|
468
|
+
i = l;
|
|
469
469
|
} else {
|
|
470
|
-
const [
|
|
470
|
+
const [l] = e.moveCall({
|
|
471
471
|
target: `${t.package}::incentive_v3::borrow`,
|
|
472
472
|
arguments: [
|
|
473
473
|
e.object("0x06"),
|
|
@@ -481,10 +481,10 @@ async function Xe(e, n, o, r) {
|
|
|
481
481
|
],
|
|
482
482
|
typeArguments: [a.suiCoinType]
|
|
483
483
|
});
|
|
484
|
-
i =
|
|
484
|
+
i = l;
|
|
485
485
|
}
|
|
486
|
-
else if (
|
|
487
|
-
const [
|
|
486
|
+
else if (n?.accountCap) {
|
|
487
|
+
const [l] = e.moveCall({
|
|
488
488
|
target: `${t.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
489
489
|
arguments: [
|
|
490
490
|
e.object("0x06"),
|
|
@@ -495,14 +495,14 @@ async function Xe(e, n, o, r) {
|
|
|
495
495
|
s,
|
|
496
496
|
e.object(t.incentiveV2),
|
|
497
497
|
e.object(t.incentiveV3),
|
|
498
|
-
h(
|
|
498
|
+
h(n.accountCap, e.object),
|
|
499
499
|
e.object("0x05")
|
|
500
500
|
],
|
|
501
501
|
typeArguments: [a.suiCoinType]
|
|
502
502
|
});
|
|
503
|
-
i =
|
|
503
|
+
i = l;
|
|
504
504
|
} else {
|
|
505
|
-
const [
|
|
505
|
+
const [l] = e.moveCall({
|
|
506
506
|
target: `${t.package}::incentive_v3::borrow_v2`,
|
|
507
507
|
arguments: [
|
|
508
508
|
e.object("0x06"),
|
|
@@ -517,7 +517,7 @@ async function Xe(e, n, o, r) {
|
|
|
517
517
|
],
|
|
518
518
|
typeArguments: [a.suiCoinType]
|
|
519
519
|
});
|
|
520
|
-
i =
|
|
520
|
+
i = l;
|
|
521
521
|
}
|
|
522
522
|
return e.moveCall({
|
|
523
523
|
target: "0x2::coin::from_balance",
|
|
@@ -525,22 +525,22 @@ async function Xe(e, n, o, r) {
|
|
|
525
525
|
typeArguments: [a.suiCoinType]
|
|
526
526
|
});
|
|
527
527
|
}
|
|
528
|
-
async function
|
|
528
|
+
async function et(e, r, o, n) {
|
|
529
529
|
const t = await _({
|
|
530
|
-
...
|
|
531
|
-
cacheTime:
|
|
532
|
-
}), a = await A(
|
|
533
|
-
if (
|
|
534
|
-
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)
|
|
535
535
|
throw new Error("Amount is required for sui coin");
|
|
536
|
-
o = e.splitCoins(o, [
|
|
536
|
+
o = e.splitCoins(o, [n.amount]);
|
|
537
537
|
}
|
|
538
538
|
let i;
|
|
539
|
-
if (typeof
|
|
539
|
+
if (typeof n?.amount < "u" ? i = h(n.amount, e.pure.u64) : i = e.moveCall({
|
|
540
540
|
target: "0x2::coin::value",
|
|
541
541
|
arguments: [h(o, e.object)],
|
|
542
542
|
typeArguments: [a.suiCoinType]
|
|
543
|
-
}),
|
|
543
|
+
}), n?.accountCap) {
|
|
544
544
|
const [c] = e.moveCall({
|
|
545
545
|
target: `${t.package}::incentive_v3::repay_with_account_cap`,
|
|
546
546
|
arguments: [
|
|
@@ -552,7 +552,7 @@ async function xe(e, n, o, r) {
|
|
|
552
552
|
h(o, e.object),
|
|
553
553
|
e.object(t.incentiveV2),
|
|
554
554
|
e.object(t.incentiveV3),
|
|
555
|
-
h(
|
|
555
|
+
h(n.accountCap, e.object)
|
|
556
556
|
],
|
|
557
557
|
typeArguments: [a.suiCoinType]
|
|
558
558
|
});
|
|
@@ -578,19 +578,19 @@ async function xe(e, n, o, r) {
|
|
|
578
578
|
typeArguments: [a.suiCoinType]
|
|
579
579
|
}), e;
|
|
580
580
|
}
|
|
581
|
-
const
|
|
581
|
+
const tt = P(
|
|
582
582
|
B(
|
|
583
583
|
async (e) => {
|
|
584
|
-
const
|
|
584
|
+
const r = await _({
|
|
585
585
|
...e
|
|
586
586
|
});
|
|
587
587
|
if (e?.address && typeof e?.asset < "u")
|
|
588
588
|
try {
|
|
589
|
-
const t = await A(e.asset, e), a = e?.client ??
|
|
589
|
+
const t = await A(e.asset, e), a = e?.client ?? S, s = new N();
|
|
590
590
|
s.moveCall({
|
|
591
|
-
target: `${
|
|
591
|
+
target: `${r.package}::incentive_v3::get_borrow_fee_v2`,
|
|
592
592
|
arguments: [
|
|
593
|
-
s.object(
|
|
593
|
+
s.object(r.incentiveV3),
|
|
594
594
|
s.pure.address(e.address),
|
|
595
595
|
s.pure.u8(t.id),
|
|
596
596
|
s.pure.u64(1e4)
|
|
@@ -600,19 +600,19 @@ const et = P(
|
|
|
600
600
|
const i = await a.devInspectTransactionBlock({
|
|
601
601
|
transactionBlock: s,
|
|
602
602
|
sender: e.address
|
|
603
|
-
}), c =
|
|
603
|
+
}), c = W(i, [C.u64()]);
|
|
604
604
|
return (Number(c[0]) || 0) / 100;
|
|
605
605
|
} catch (t) {
|
|
606
606
|
console.error(t);
|
|
607
607
|
}
|
|
608
|
-
const
|
|
609
|
-
id:
|
|
608
|
+
const n = (await S.getObject({
|
|
609
|
+
id: r.incentiveV3,
|
|
610
610
|
options: { showType: !0, showOwner: !0, showContent: !0 }
|
|
611
611
|
})).data.content.fields.borrow_fee_rate;
|
|
612
|
-
return Number(
|
|
612
|
+
return Number(n) / 100;
|
|
613
613
|
}
|
|
614
614
|
)
|
|
615
|
-
),
|
|
615
|
+
), U = "main", E = {
|
|
616
616
|
main: {
|
|
617
617
|
id: 0,
|
|
618
618
|
key: "main",
|
|
@@ -629,52 +629,52 @@ const et = P(
|
|
|
629
629
|
name: "Sui Eco Market"
|
|
630
630
|
}
|
|
631
631
|
};
|
|
632
|
-
class
|
|
633
|
-
constructor(
|
|
632
|
+
class je {
|
|
633
|
+
constructor(r, o) {
|
|
634
634
|
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
635
635
|
marketTotalSupplyValue: "0",
|
|
636
636
|
marketTotalBorrowValue: "0"
|
|
637
|
-
}, this.config =
|
|
637
|
+
}, this.config = I(r), this.initPools(o);
|
|
638
638
|
}
|
|
639
639
|
get overview() {
|
|
640
640
|
return this._overview;
|
|
641
641
|
}
|
|
642
|
-
initPools(
|
|
643
|
-
const o =
|
|
642
|
+
initPools(r) {
|
|
643
|
+
const o = G(this.pools), n = Z(this.emodes), t = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
644
644
|
let s = p(0), i = p(0);
|
|
645
|
-
|
|
645
|
+
r.forEach((c) => {
|
|
646
646
|
if (!this.checkMarket(c.market)) {
|
|
647
647
|
console.warn(`Pool is not in market ${this.config.name}`, c);
|
|
648
648
|
return;
|
|
649
649
|
}
|
|
650
650
|
o[c.uniqueId] || this.pools.push(c), c?.emodes?.forEach((d) => {
|
|
651
|
-
|
|
651
|
+
n[d.uniqueId] || this.emodes.push(d), d.assets.forEach((y) => {
|
|
652
652
|
y.isDebt && d.assets.find(
|
|
653
653
|
(g) => g.isCollateral && g.ltv > 0 && g.assetId !== c.id
|
|
654
654
|
) && t.add(c.uniqueId), y.isCollateral && d.assets.find((g) => g.isDebt && g.assetId !== c.id) && a.add(c.uniqueId);
|
|
655
655
|
});
|
|
656
656
|
}), i = i.plus(c.poolBorrowValue), s = s.plus(c.poolSupplyValue);
|
|
657
|
-
}), this.poolMap =
|
|
658
|
-
const
|
|
659
|
-
this.emodePools.push(...
|
|
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);
|
|
660
660
|
}), this._overview = {
|
|
661
661
|
marketTotalSupplyValue: s.toString(),
|
|
662
662
|
marketTotalBorrowValue: i.toString()
|
|
663
663
|
}, this.emodeBorrowablePools = this.pools.filter((c) => t.has(c.uniqueId)), this.emodeSupplyablePools = this.pools.filter((c) => a.has(c.uniqueId));
|
|
664
664
|
}
|
|
665
|
-
getEMode(
|
|
666
|
-
return this.emodeMap[
|
|
665
|
+
getEMode(r) {
|
|
666
|
+
return this.emodeMap[r] || null;
|
|
667
667
|
}
|
|
668
|
-
getEModeRelatePools(
|
|
669
|
-
const { collateral:
|
|
670
|
-
return
|
|
668
|
+
getEModeRelatePools(r, o) {
|
|
669
|
+
const { collateral: n, debt: t, emodeId: a } = o || {}, s = [];
|
|
670
|
+
return r.emodes.forEach((i) => {
|
|
671
671
|
typeof a == "number" && a !== i.emodeId || i.assets.forEach((c) => {
|
|
672
|
-
typeof
|
|
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]);
|
|
673
673
|
});
|
|
674
674
|
}), s;
|
|
675
675
|
}
|
|
676
|
-
getEModePools(
|
|
677
|
-
const o = this.getEMode(
|
|
676
|
+
getEModePools(r) {
|
|
677
|
+
const o = this.getEMode(r);
|
|
678
678
|
return o ? o.assets.map((t) => t.assetId).map((t) => this.poolMap[t]).filter((t) => !!t).map((t) => {
|
|
679
679
|
const a = o.assets.find((s) => s.assetId === t.id);
|
|
680
680
|
return {
|
|
@@ -687,161 +687,161 @@ class Ce {
|
|
|
687
687
|
};
|
|
688
688
|
}) : [];
|
|
689
689
|
}
|
|
690
|
-
checkMarket(
|
|
690
|
+
checkMarket(r) {
|
|
691
691
|
let o = !1;
|
|
692
|
-
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;
|
|
693
693
|
}
|
|
694
694
|
}
|
|
695
|
-
const
|
|
696
|
-
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);
|
|
697
697
|
if (!o)
|
|
698
698
|
throw new Error("Market not found");
|
|
699
699
|
return o;
|
|
700
|
-
},
|
|
700
|
+
}, Ie = P(
|
|
701
701
|
B(
|
|
702
|
-
async (e,
|
|
703
|
-
const o = await
|
|
702
|
+
async (e, r) => {
|
|
703
|
+
const o = await q({
|
|
704
704
|
cacheTime: 6e4,
|
|
705
|
-
...
|
|
705
|
+
...r,
|
|
706
706
|
markets: e
|
|
707
707
|
});
|
|
708
|
-
return e.map((
|
|
709
|
-
const t =
|
|
710
|
-
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);
|
|
711
711
|
});
|
|
712
712
|
}
|
|
713
713
|
)
|
|
714
|
-
),
|
|
714
|
+
), ot = P(
|
|
715
715
|
B(
|
|
716
|
-
async (e,
|
|
716
|
+
async (e, r) => (await Ie([e], r))[0]
|
|
717
717
|
)
|
|
718
718
|
), _ = P(
|
|
719
719
|
B(
|
|
720
720
|
async (e) => {
|
|
721
|
-
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}`;
|
|
722
722
|
return (await fetch(o, { headers: M }).then((t) => t.json())).data;
|
|
723
723
|
}
|
|
724
724
|
)
|
|
725
|
-
),
|
|
726
|
-
async function
|
|
725
|
+
), w = 1e3 * 60 * 5;
|
|
726
|
+
async function Te(e, r) {
|
|
727
727
|
const o = await _({
|
|
728
|
-
cacheTime:
|
|
729
|
-
...
|
|
728
|
+
cacheTime: w,
|
|
729
|
+
...r
|
|
730
730
|
});
|
|
731
731
|
return e.moveCall({
|
|
732
732
|
target: `${o.package}::lending::create_account`,
|
|
733
733
|
arguments: []
|
|
734
734
|
});
|
|
735
735
|
}
|
|
736
|
-
async function
|
|
737
|
-
const
|
|
738
|
-
cacheTime:
|
|
736
|
+
async function Be(e, r, o) {
|
|
737
|
+
const n = await _({
|
|
738
|
+
cacheTime: w,
|
|
739
739
|
...o
|
|
740
740
|
});
|
|
741
741
|
return e.moveCall({
|
|
742
|
-
target: `${
|
|
743
|
-
arguments: [
|
|
742
|
+
target: `${n.package}::account::account_owner`,
|
|
743
|
+
arguments: [r]
|
|
744
744
|
});
|
|
745
745
|
}
|
|
746
|
-
async function
|
|
747
|
-
const
|
|
746
|
+
async function Ae(e, r, o) {
|
|
747
|
+
const n = await _({
|
|
748
748
|
...o,
|
|
749
|
-
cacheTime:
|
|
749
|
+
cacheTime: w
|
|
750
750
|
});
|
|
751
751
|
return o?.accountCap ? e.moveCall({
|
|
752
|
-
target: `${
|
|
752
|
+
target: `${n.package}::lending::enter_emode_with_account_cap`,
|
|
753
753
|
arguments: [
|
|
754
|
-
e.object(
|
|
755
|
-
h(
|
|
754
|
+
e.object(n.storage),
|
|
755
|
+
h(r, e.pure.u64),
|
|
756
756
|
h(o.accountCap, e.object)
|
|
757
757
|
]
|
|
758
758
|
}) : e.moveCall({
|
|
759
|
-
target: `${
|
|
760
|
-
arguments: [e.object(
|
|
759
|
+
target: `${n.package}::lending::enter_emode`,
|
|
760
|
+
arguments: [e.object(n.storage), h(r, e.pure.u64)]
|
|
761
761
|
}), e;
|
|
762
762
|
}
|
|
763
|
-
async function
|
|
763
|
+
async function rt(e, r) {
|
|
764
764
|
const o = await _({
|
|
765
|
-
...
|
|
766
|
-
cacheTime:
|
|
765
|
+
...r,
|
|
766
|
+
cacheTime: w
|
|
767
767
|
});
|
|
768
|
-
return
|
|
768
|
+
return r?.accountCap ? e.moveCall({
|
|
769
769
|
target: `${o.package}::lending::exit_emode_with_account_cap`,
|
|
770
|
-
arguments: [e.object(o.storage), h(
|
|
770
|
+
arguments: [e.object(o.storage), h(r.accountCap, e.object)]
|
|
771
771
|
}) : e.moveCall({
|
|
772
772
|
target: `${o.package}::lending::exit_emode`,
|
|
773
773
|
arguments: [e.object(o.storage)]
|
|
774
774
|
}), e;
|
|
775
775
|
}
|
|
776
|
-
async function nt(e,
|
|
777
|
-
const
|
|
778
|
-
cacheTime:
|
|
776
|
+
async function nt(e, r, o) {
|
|
777
|
+
const n = await _({
|
|
778
|
+
cacheTime: w,
|
|
779
779
|
...o
|
|
780
|
-
}), t = await
|
|
781
|
-
await
|
|
780
|
+
}), t = await Te(e, o);
|
|
781
|
+
await Ae(e, r, {
|
|
782
782
|
...o,
|
|
783
783
|
accountCap: t
|
|
784
784
|
});
|
|
785
|
-
const a = await
|
|
785
|
+
const a = await I(o?.market || U), s = await Be(e, t, o);
|
|
786
786
|
return e.moveCall({
|
|
787
|
-
target: `${
|
|
787
|
+
target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
788
788
|
arguments: [
|
|
789
|
-
e.object(
|
|
789
|
+
e.object(n.emode.contract.registryObject),
|
|
790
790
|
s,
|
|
791
791
|
h(a.id, e.pure.u64),
|
|
792
|
-
h(
|
|
792
|
+
h(r, e.pure.u64)
|
|
793
793
|
]
|
|
794
794
|
}), t;
|
|
795
795
|
}
|
|
796
|
-
const
|
|
796
|
+
const ee = P(
|
|
797
797
|
B(
|
|
798
|
-
async (e,
|
|
798
|
+
async (e, r) => {
|
|
799
799
|
const o = await _({
|
|
800
|
-
cacheTime:
|
|
801
|
-
...
|
|
802
|
-
}),
|
|
803
|
-
|
|
800
|
+
cacheTime: w,
|
|
801
|
+
...r
|
|
802
|
+
}), n = new N(), t = r?.client ?? S;
|
|
803
|
+
n.moveCall({
|
|
804
804
|
target: `${o.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
805
|
-
arguments: [
|
|
805
|
+
arguments: [n.object(o.emode.contract.registryObject), n.pure.address(e)]
|
|
806
806
|
});
|
|
807
807
|
const s = (await t.devInspectTransactionBlock({
|
|
808
|
-
transactionBlock:
|
|
808
|
+
transactionBlock: n,
|
|
809
809
|
sender: e
|
|
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])),
|
|
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]));
|
|
811
811
|
return i.map((d, y) => ({
|
|
812
812
|
marketId: Number(d),
|
|
813
813
|
emodeId: Number(c[y]),
|
|
814
|
-
accountCap:
|
|
814
|
+
accountCap: l[y].toString()
|
|
815
815
|
}));
|
|
816
816
|
}
|
|
817
817
|
)
|
|
818
818
|
);
|
|
819
|
-
function
|
|
820
|
-
return `${
|
|
819
|
+
function at(e) {
|
|
820
|
+
return `${I(e.marketId).key}-${e.emodeId}`;
|
|
821
821
|
}
|
|
822
|
-
function
|
|
823
|
-
const
|
|
822
|
+
function it(e, r, o) {
|
|
823
|
+
const n = typeof o?.balance == "number", t = n ? o.balance : 0;
|
|
824
824
|
let a = 0;
|
|
825
825
|
const s = [];
|
|
826
826
|
let i = "";
|
|
827
|
-
if (
|
|
828
|
-
if (!(
|
|
827
|
+
if (r.sort((c, l) => Number(l.balance) - Number(c.balance)).forEach((c) => {
|
|
828
|
+
if (!(n && a >= t) && Number(c.balance) !== 0) {
|
|
829
829
|
if (i || (i = c.coinType), i !== c.coinType)
|
|
830
830
|
throw new Error("All coins must be of the same type");
|
|
831
831
|
a += Number(c.balance), s.push(c.coinObjectId);
|
|
832
832
|
}
|
|
833
833
|
}), s.length === 0)
|
|
834
834
|
throw new Error("No coins to merge");
|
|
835
|
-
if (
|
|
835
|
+
if (n && a < t)
|
|
836
836
|
throw new Error(
|
|
837
837
|
`Balance is less than the specified balance: ${a} < ${t}`
|
|
838
838
|
);
|
|
839
|
-
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]);
|
|
840
840
|
}
|
|
841
|
-
async function
|
|
841
|
+
async function te(e, r, o, n, t, a, s) {
|
|
842
842
|
const i = await _({
|
|
843
843
|
...s,
|
|
844
|
-
cacheTime:
|
|
844
|
+
cacheTime: w
|
|
845
845
|
}), c = await A(o, s);
|
|
846
846
|
return e.moveCall({
|
|
847
847
|
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
@@ -849,123 +849,123 @@ async function ee(e, n, o, r, t, a, s) {
|
|
|
849
849
|
e.object("0x06"),
|
|
850
850
|
e.object(i.storage),
|
|
851
851
|
e.object(i.oracle.priceOracle),
|
|
852
|
-
|
|
853
|
-
h(
|
|
852
|
+
be(e, c),
|
|
853
|
+
h(r, e.pure.address),
|
|
854
854
|
h(c.id, e.pure.u8),
|
|
855
|
-
h(
|
|
855
|
+
h(n, e.pure.u64),
|
|
856
856
|
h(t, e.pure.u64),
|
|
857
857
|
h(a, e.pure.bool)
|
|
858
858
|
],
|
|
859
859
|
typeArguments: [c.suiCoinType]
|
|
860
860
|
});
|
|
861
861
|
}
|
|
862
|
-
async function
|
|
863
|
-
return
|
|
862
|
+
async function Pe(e, r, o) {
|
|
863
|
+
return te(e, r, 0, 0, 0, !1, o);
|
|
864
864
|
}
|
|
865
|
-
async function
|
|
866
|
-
const
|
|
865
|
+
async function oe(e, r, o) {
|
|
866
|
+
const n = new N(), t = o?.client ?? S, a = await q({
|
|
867
867
|
...o,
|
|
868
868
|
markets: Object.values(E)
|
|
869
|
-
}), s =
|
|
870
|
-
for (let d of
|
|
869
|
+
}), s = G(a);
|
|
870
|
+
for (let d of r) {
|
|
871
871
|
const y = await _({
|
|
872
872
|
...o,
|
|
873
|
-
cacheTime:
|
|
873
|
+
cacheTime: w,
|
|
874
874
|
market: d.market
|
|
875
875
|
});
|
|
876
|
-
|
|
876
|
+
n.moveCall({
|
|
877
877
|
target: `${y.uiGetter}::getter_unchecked::get_user_state`,
|
|
878
|
-
arguments: [
|
|
878
|
+
arguments: [n.object(y.storage), n.pure.address(d.address)]
|
|
879
879
|
});
|
|
880
880
|
}
|
|
881
881
|
const c = ((await t.devInspectTransactionBlock({
|
|
882
|
-
transactionBlock:
|
|
882
|
+
transactionBlock: n,
|
|
883
883
|
sender: e
|
|
884
|
-
})).results || []).map((d) => d.returnValues?.map((y) => C.vector(
|
|
884
|
+
})).results || []).map((d) => d.returnValues?.map((y) => C.vector(ye).parse(Uint8Array.from(y[0])))[0] || []), l = [];
|
|
885
885
|
return c.forEach((d, y) => {
|
|
886
|
-
const v =
|
|
887
|
-
d.forEach((
|
|
888
|
-
if (
|
|
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))
|
|
889
889
|
return;
|
|
890
|
-
const f = s[`${g.key}-${
|
|
890
|
+
const f = s[`${g.key}-${u.asset_id}`];
|
|
891
891
|
if (!f)
|
|
892
892
|
return;
|
|
893
|
-
const
|
|
894
|
-
|
|
893
|
+
const k = J(
|
|
894
|
+
u.supply_balance,
|
|
895
895
|
f.currentSupplyIndex
|
|
896
|
-
).toString(),
|
|
897
|
-
|
|
896
|
+
).toString(), j = J(
|
|
897
|
+
u.borrow_balance,
|
|
898
898
|
f.currentBorrowIndex
|
|
899
899
|
).toString();
|
|
900
|
-
|
|
901
|
-
supplyBalance:
|
|
902
|
-
borrowBalance:
|
|
903
|
-
assetId:
|
|
900
|
+
l.push({
|
|
901
|
+
supplyBalance: k,
|
|
902
|
+
borrowBalance: j,
|
|
903
|
+
assetId: u.asset_id,
|
|
904
904
|
market: g.key,
|
|
905
905
|
pool: f,
|
|
906
906
|
emodeId: v.emodeId
|
|
907
907
|
});
|
|
908
908
|
});
|
|
909
|
-
}),
|
|
909
|
+
}), l;
|
|
910
910
|
}
|
|
911
|
-
const
|
|
912
|
-
async (e,
|
|
913
|
-
const
|
|
911
|
+
const ct = P(
|
|
912
|
+
async (e, r) => {
|
|
913
|
+
const n = (r?.markets || Object.keys(E)).map((t) => I(t)).map((t) => ({
|
|
914
914
|
address: e,
|
|
915
915
|
market: t.key
|
|
916
916
|
}));
|
|
917
|
-
return await
|
|
917
|
+
return await oe(e, n, r);
|
|
918
918
|
}
|
|
919
919
|
);
|
|
920
|
-
async function
|
|
921
|
-
const o =
|
|
922
|
-
await
|
|
920
|
+
async function st(e, r) {
|
|
921
|
+
const o = r?.client ?? S, n = new N();
|
|
922
|
+
await Pe(n, e, r);
|
|
923
923
|
const t = await o.devInspectTransactionBlock({
|
|
924
|
-
transactionBlock:
|
|
924
|
+
transactionBlock: n,
|
|
925
925
|
sender: e
|
|
926
|
-
}), a =
|
|
927
|
-
return
|
|
926
|
+
}), a = W(t, [C.u256()]);
|
|
927
|
+
return x(Number(a[0]) || 0);
|
|
928
928
|
}
|
|
929
|
-
async function
|
|
930
|
-
const t =
|
|
929
|
+
async function lt(e, r, o, n) {
|
|
930
|
+
const t = n?.client ?? S, a = new N();
|
|
931
931
|
let s = 0, i = 0;
|
|
932
|
-
const c = await A(
|
|
932
|
+
const c = await A(r, n);
|
|
933
933
|
if (o.forEach((v) => {
|
|
934
|
-
v.type ===
|
|
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
935
|
}), s * i < 0)
|
|
936
936
|
throw new Error("Invalid operations");
|
|
937
|
-
const
|
|
938
|
-
await
|
|
937
|
+
const l = s > 0 || i > 0;
|
|
938
|
+
await te(
|
|
939
939
|
a,
|
|
940
940
|
e,
|
|
941
941
|
c,
|
|
942
942
|
Math.abs(s),
|
|
943
943
|
Math.abs(i),
|
|
944
|
-
|
|
945
|
-
|
|
944
|
+
l,
|
|
945
|
+
n
|
|
946
946
|
);
|
|
947
947
|
const d = await t.devInspectTransactionBlock({
|
|
948
948
|
transactionBlock: a,
|
|
949
949
|
sender: e
|
|
950
|
-
}), y =
|
|
951
|
-
return
|
|
950
|
+
}), y = W(d, [C.u256()]);
|
|
951
|
+
return x(Number(y[0]) || 0);
|
|
952
952
|
}
|
|
953
953
|
const ut = B(
|
|
954
|
-
async (e,
|
|
954
|
+
async (e, r) => {
|
|
955
955
|
const o = new URLSearchParams();
|
|
956
|
-
|
|
957
|
-
const
|
|
958
|
-
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;
|
|
959
959
|
}
|
|
960
960
|
);
|
|
961
|
-
async function
|
|
961
|
+
async function pt(e, r) {
|
|
962
962
|
let o = null;
|
|
963
|
-
const
|
|
963
|
+
const n = [], t = r?.client ?? S;
|
|
964
964
|
do {
|
|
965
965
|
let a;
|
|
966
|
-
if (
|
|
966
|
+
if (r?.coinType ? a = await t.getCoins({
|
|
967
967
|
owner: e,
|
|
968
|
-
coinType:
|
|
968
|
+
coinType: r?.coinType,
|
|
969
969
|
cursor: o,
|
|
970
970
|
limit: 100
|
|
971
971
|
}) : a = await t.getAllCoins({
|
|
@@ -974,39 +974,39 @@ async function lt(e, n) {
|
|
|
974
974
|
limit: 100
|
|
975
975
|
}), !a.data || !a.data.length)
|
|
976
976
|
break;
|
|
977
|
-
|
|
977
|
+
n.push(...a.data), o = a.nextCursor;
|
|
978
978
|
} while (o);
|
|
979
|
-
return
|
|
979
|
+
return n;
|
|
980
980
|
}
|
|
981
|
-
const
|
|
982
|
-
async (e,
|
|
983
|
-
const o = [],
|
|
981
|
+
const $e = P(
|
|
982
|
+
async (e, r) => {
|
|
983
|
+
const o = [], n = (r?.markets || Object.keys(E)).map((i) => I(i));
|
|
984
984
|
let t = [];
|
|
985
985
|
try {
|
|
986
|
-
t = await
|
|
986
|
+
t = await ee(e, r);
|
|
987
987
|
} catch (i) {
|
|
988
988
|
console.error(i);
|
|
989
989
|
}
|
|
990
|
-
const a =
|
|
990
|
+
const a = n.map((i) => ({
|
|
991
991
|
address: e,
|
|
992
992
|
market: i.key
|
|
993
993
|
})).concat(
|
|
994
|
-
t.filter((i) => !!
|
|
994
|
+
t.filter((i) => !!n.find((c) => c.id === i.marketId)).map((i) => ({
|
|
995
995
|
address: i.accountCap,
|
|
996
|
-
market:
|
|
996
|
+
market: I(i.marketId).key,
|
|
997
997
|
emodeId: i.emodeId
|
|
998
998
|
}))
|
|
999
999
|
);
|
|
1000
|
-
return (await
|
|
1001
|
-
const c = typeof i.emodeId == "number" ? t.find((
|
|
1002
|
-
const d =
|
|
1003
|
-
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;
|
|
1004
1004
|
}) : void 0;
|
|
1005
1005
|
if (c) {
|
|
1006
1006
|
if (!i.pool.emodes.find((d) => d.emodeId === c.emodeId))
|
|
1007
1007
|
return;
|
|
1008
1008
|
if (p(i.supplyBalance).gte(0)) {
|
|
1009
|
-
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);
|
|
1010
1010
|
if (d.gt(0) || y.emode.isCollateral)
|
|
1011
1011
|
try {
|
|
1012
1012
|
o.push({
|
|
@@ -1017,7 +1017,7 @@ const Pe = P(
|
|
|
1017
1017
|
type: "navi-lending-emode-supply",
|
|
1018
1018
|
"navi-lending-emode-supply": {
|
|
1019
1019
|
amount: d.toString(),
|
|
1020
|
-
pool:
|
|
1020
|
+
pool: L(i.pool, c),
|
|
1021
1021
|
token: i.pool.token,
|
|
1022
1022
|
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
1023
1023
|
emodeCap: c
|
|
@@ -1028,7 +1028,7 @@ const Pe = P(
|
|
|
1028
1028
|
}
|
|
1029
1029
|
}
|
|
1030
1030
|
if (p(i.borrowBalance).gte(0)) {
|
|
1031
|
-
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);
|
|
1032
1032
|
if (d.gt(0) || y.emode.isDebt)
|
|
1033
1033
|
try {
|
|
1034
1034
|
o.push({
|
|
@@ -1039,7 +1039,7 @@ const Pe = P(
|
|
|
1039
1039
|
type: "navi-lending-emode-borrow",
|
|
1040
1040
|
"navi-lending-emode-borrow": {
|
|
1041
1041
|
amount: d.toString(),
|
|
1042
|
-
pool:
|
|
1042
|
+
pool: L(i.pool, c),
|
|
1043
1043
|
token: i.pool.token,
|
|
1044
1044
|
valueUSD: d.multipliedBy(i.pool.oracle.price).toString(),
|
|
1045
1045
|
emodeCap: c
|
|
@@ -1051,7 +1051,7 @@ const Pe = P(
|
|
|
1051
1051
|
}
|
|
1052
1052
|
} else {
|
|
1053
1053
|
if (p(i.supplyBalance).gt(0)) {
|
|
1054
|
-
const
|
|
1054
|
+
const l = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1055
1055
|
o.push({
|
|
1056
1056
|
id: `${i.pool.uniqueId}_navi-lending-supply-${T()}`,
|
|
1057
1057
|
wallet: e,
|
|
@@ -1059,15 +1059,15 @@ const Pe = P(
|
|
|
1059
1059
|
type: "navi-lending-supply",
|
|
1060
1060
|
market: i.market,
|
|
1061
1061
|
"navi-lending-supply": {
|
|
1062
|
-
amount:
|
|
1062
|
+
amount: l.toString(),
|
|
1063
1063
|
pool: i.pool,
|
|
1064
1064
|
token: i.pool.token,
|
|
1065
|
-
valueUSD:
|
|
1065
|
+
valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
|
|
1066
1066
|
}
|
|
1067
1067
|
});
|
|
1068
1068
|
}
|
|
1069
1069
|
if (p(i.borrowBalance).gt(0)) {
|
|
1070
|
-
const
|
|
1070
|
+
const l = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1071
1071
|
o.push({
|
|
1072
1072
|
id: `${i.pool.uniqueId}_navi-lending-borrow-${T()}`,
|
|
1073
1073
|
wallet: e,
|
|
@@ -1075,10 +1075,10 @@ const Pe = P(
|
|
|
1075
1075
|
market: i.market,
|
|
1076
1076
|
type: "navi-lending-borrow",
|
|
1077
1077
|
"navi-lending-borrow": {
|
|
1078
|
-
amount:
|
|
1078
|
+
amount: l.toString(),
|
|
1079
1079
|
pool: i.pool,
|
|
1080
1080
|
token: i.pool.token,
|
|
1081
|
-
valueUSD:
|
|
1081
|
+
valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
|
|
1082
1082
|
}
|
|
1083
1083
|
});
|
|
1084
1084
|
}
|
|
@@ -1087,7 +1087,7 @@ const Pe = P(
|
|
|
1087
1087
|
}
|
|
1088
1088
|
);
|
|
1089
1089
|
class O {
|
|
1090
|
-
constructor(
|
|
1090
|
+
constructor(r, o) {
|
|
1091
1091
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1092
1092
|
hf: 1 / 0,
|
|
1093
1093
|
netVaule: "0",
|
|
@@ -1100,7 +1100,7 @@ class O {
|
|
|
1100
1100
|
maxLoanToVaule: "0",
|
|
1101
1101
|
supply: {},
|
|
1102
1102
|
borrow: {}
|
|
1103
|
-
}, this._priceMap = o || {}, this.positions =
|
|
1103
|
+
}, this._priceMap = o || {}, this.positions = r;
|
|
1104
1104
|
}
|
|
1105
1105
|
get positions() {
|
|
1106
1106
|
return this._positions;
|
|
@@ -1111,33 +1111,33 @@ class O {
|
|
|
1111
1111
|
get priceMap() {
|
|
1112
1112
|
return this._priceMap;
|
|
1113
1113
|
}
|
|
1114
|
-
set positions(
|
|
1115
|
-
this._positions =
|
|
1114
|
+
set positions(r) {
|
|
1115
|
+
this._positions = r, this._overview = this.getPositionsOverview(r);
|
|
1116
1116
|
}
|
|
1117
|
-
updatePriceMap(
|
|
1118
|
-
return this._priceMap =
|
|
1117
|
+
updatePriceMap(r) {
|
|
1118
|
+
return this._priceMap = r, this._overview = this.getPositionsOverview(this._positions), this;
|
|
1119
1119
|
}
|
|
1120
|
-
getPrice(
|
|
1121
|
-
const o =
|
|
1120
|
+
getPrice(r) {
|
|
1121
|
+
const o = b(r.suiCoinType);
|
|
1122
1122
|
if (this._priceMap[o] !== void 0)
|
|
1123
1123
|
return this._priceMap[o].toString();
|
|
1124
|
-
const
|
|
1125
|
-
return this._priceMap[
|
|
1124
|
+
const n = r.suiCoinType;
|
|
1125
|
+
return this._priceMap[n] !== void 0 ? this._priceMap[n].toString() : r.oracle.price;
|
|
1126
1126
|
}
|
|
1127
|
-
filterPositionsByPool(
|
|
1128
|
-
const
|
|
1127
|
+
filterPositionsByPool(r) {
|
|
1128
|
+
const n = !!r.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1129
1129
|
return new O(
|
|
1130
1130
|
this.positions.filter((t) => {
|
|
1131
1131
|
const a = t[t.type];
|
|
1132
|
-
return
|
|
1132
|
+
return n.includes(t.type) && a.pool.uniqueId === r.uniqueId;
|
|
1133
1133
|
}),
|
|
1134
1134
|
this._priceMap
|
|
1135
1135
|
);
|
|
1136
1136
|
}
|
|
1137
|
-
deposit(
|
|
1138
|
-
const
|
|
1137
|
+
deposit(r, o) {
|
|
1138
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1139
1139
|
let a;
|
|
1140
|
-
return
|
|
1140
|
+
return n ? a = {
|
|
1141
1141
|
id: T(),
|
|
1142
1142
|
wallet: "",
|
|
1143
1143
|
protocol: "navi",
|
|
@@ -1146,8 +1146,8 @@ class O {
|
|
|
1146
1146
|
"navi-lending-emode-supply": {
|
|
1147
1147
|
amount: o.toString(),
|
|
1148
1148
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1149
|
-
token:
|
|
1150
|
-
pool:
|
|
1149
|
+
token: r.token,
|
|
1150
|
+
pool: r,
|
|
1151
1151
|
emodeCap: {}
|
|
1152
1152
|
}
|
|
1153
1153
|
} : a = {
|
|
@@ -1159,15 +1159,15 @@ class O {
|
|
|
1159
1159
|
"navi-lending-supply": {
|
|
1160
1160
|
amount: o.toString(),
|
|
1161
1161
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1162
|
-
token:
|
|
1163
|
-
pool:
|
|
1162
|
+
token: r.token,
|
|
1163
|
+
pool: r
|
|
1164
1164
|
}
|
|
1165
1165
|
}, new O([...this.positions, a], this._priceMap);
|
|
1166
1166
|
}
|
|
1167
|
-
withdraw(
|
|
1168
|
-
const
|
|
1167
|
+
withdraw(r, o) {
|
|
1168
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1169
1169
|
let a;
|
|
1170
|
-
return
|
|
1170
|
+
return n ? a = {
|
|
1171
1171
|
id: T(),
|
|
1172
1172
|
wallet: "",
|
|
1173
1173
|
protocol: "navi",
|
|
@@ -1176,8 +1176,8 @@ class O {
|
|
|
1176
1176
|
"navi-lending-emode-supply": {
|
|
1177
1177
|
amount: (-o).toString(),
|
|
1178
1178
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1179
|
-
token:
|
|
1180
|
-
pool:
|
|
1179
|
+
token: r.token,
|
|
1180
|
+
pool: r,
|
|
1181
1181
|
emodeCap: {}
|
|
1182
1182
|
}
|
|
1183
1183
|
} : a = {
|
|
@@ -1189,15 +1189,15 @@ class O {
|
|
|
1189
1189
|
"navi-lending-supply": {
|
|
1190
1190
|
amount: (-o).toString(),
|
|
1191
1191
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1192
|
-
token:
|
|
1193
|
-
pool:
|
|
1192
|
+
token: r.token,
|
|
1193
|
+
pool: r
|
|
1194
1194
|
}
|
|
1195
1195
|
}, new O([...this.positions, a], this._priceMap);
|
|
1196
1196
|
}
|
|
1197
|
-
borrow(
|
|
1198
|
-
const
|
|
1197
|
+
borrow(r, o) {
|
|
1198
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1199
1199
|
let a;
|
|
1200
|
-
return
|
|
1200
|
+
return n ? a = {
|
|
1201
1201
|
id: T(),
|
|
1202
1202
|
wallet: "",
|
|
1203
1203
|
protocol: "navi",
|
|
@@ -1206,8 +1206,8 @@ class O {
|
|
|
1206
1206
|
"navi-lending-emode-borrow": {
|
|
1207
1207
|
amount: o.toString(),
|
|
1208
1208
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1209
|
-
token:
|
|
1210
|
-
pool:
|
|
1209
|
+
token: r.token,
|
|
1210
|
+
pool: r,
|
|
1211
1211
|
emodeCap: {}
|
|
1212
1212
|
}
|
|
1213
1213
|
} : a = {
|
|
@@ -1219,15 +1219,15 @@ class O {
|
|
|
1219
1219
|
"navi-lending-borrow": {
|
|
1220
1220
|
amount: o.toString(),
|
|
1221
1221
|
valueUSD: p(o).multipliedBy(t).toString(),
|
|
1222
|
-
token:
|
|
1223
|
-
pool:
|
|
1222
|
+
token: r.token,
|
|
1223
|
+
pool: r
|
|
1224
1224
|
}
|
|
1225
1225
|
}, new O([...this.positions, a], this._priceMap);
|
|
1226
1226
|
}
|
|
1227
|
-
repay(
|
|
1228
|
-
const
|
|
1227
|
+
repay(r, o) {
|
|
1228
|
+
const n = !!r.isEMode, t = this.getPrice(r);
|
|
1229
1229
|
let a;
|
|
1230
|
-
return
|
|
1230
|
+
return n ? a = {
|
|
1231
1231
|
id: T(),
|
|
1232
1232
|
wallet: "",
|
|
1233
1233
|
protocol: "navi",
|
|
@@ -1236,8 +1236,8 @@ class O {
|
|
|
1236
1236
|
"navi-lending-emode-borrow": {
|
|
1237
1237
|
amount: (-o).toString(),
|
|
1238
1238
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1239
|
-
token:
|
|
1240
|
-
pool:
|
|
1239
|
+
token: r.token,
|
|
1240
|
+
pool: r,
|
|
1241
1241
|
emodeCap: {}
|
|
1242
1242
|
}
|
|
1243
1243
|
} : a = {
|
|
@@ -1249,62 +1249,62 @@ class O {
|
|
|
1249
1249
|
"navi-lending-borrow": {
|
|
1250
1250
|
amount: (-o).toString(),
|
|
1251
1251
|
valueUSD: p(-o).multipliedBy(t).toString(),
|
|
1252
|
-
token:
|
|
1253
|
-
pool:
|
|
1252
|
+
token: r.token,
|
|
1253
|
+
pool: r
|
|
1254
1254
|
}
|
|
1255
1255
|
}, new O([...this.positions, a], this._priceMap);
|
|
1256
1256
|
}
|
|
1257
|
-
resolveValueUSD(
|
|
1258
|
-
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;
|
|
1259
1259
|
}
|
|
1260
|
-
getPositionsOverview(
|
|
1261
|
-
const o = {},
|
|
1262
|
-
let t = new p(0), a = new p(0), s = new p(0), i = new p(0), c = new p(0),
|
|
1263
|
-
|
|
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) => {
|
|
1264
1264
|
if (g.type === "navi-lending-supply") {
|
|
1265
|
-
const
|
|
1265
|
+
const u = g["navi-lending-supply"], f = this.resolveValueUSD(u);
|
|
1266
1266
|
t = t.plus(f), c = c.plus(
|
|
1267
|
-
new p(f).multipliedBy(
|
|
1268
|
-
),
|
|
1269
|
-
new p(f).multipliedBy(
|
|
1267
|
+
new p(f).multipliedBy(u.pool.liquidationFactor.threshold)
|
|
1268
|
+
), l = l.plus(
|
|
1269
|
+
new p(f).multipliedBy(u.pool.ltvValue)
|
|
1270
1270
|
);
|
|
1271
1271
|
} else if (g.type === "navi-lending-borrow") {
|
|
1272
|
-
const
|
|
1273
|
-
a = a.plus(this.resolveValueUSD(
|
|
1272
|
+
const u = g["navi-lending-borrow"];
|
|
1273
|
+
a = a.plus(this.resolveValueUSD(u));
|
|
1274
1274
|
} else if (g.type === "navi-lending-emode-supply") {
|
|
1275
|
-
const
|
|
1275
|
+
const u = g["navi-lending-emode-supply"], f = this.resolveValueUSD(u);
|
|
1276
1276
|
t = t.plus(f);
|
|
1277
|
-
const
|
|
1277
|
+
const k = u.pool.emode;
|
|
1278
1278
|
c = c.plus(
|
|
1279
|
-
new p(f).multipliedBy(
|
|
1280
|
-
),
|
|
1281
|
-
new p(f).multipliedBy(
|
|
1279
|
+
new p(f).multipliedBy(k.lt)
|
|
1280
|
+
), l = l.plus(
|
|
1281
|
+
new p(f).multipliedBy(k.ltv)
|
|
1282
1282
|
);
|
|
1283
1283
|
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1284
|
-
const
|
|
1285
|
-
a = a.plus(this.resolveValueUSD(
|
|
1284
|
+
const u = g["navi-lending-emode-borrow"];
|
|
1285
|
+
a = a.plus(this.resolveValueUSD(u));
|
|
1286
1286
|
}
|
|
1287
|
-
}), a = p.max(a, 0), t = p.max(t, 0), c = p.max(c, 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) => {
|
|
1288
1288
|
if (g.type === "navi-lending-supply") {
|
|
1289
|
-
const
|
|
1289
|
+
const u = g["navi-lending-supply"], f = this.resolveValueUSD(u), k = u.pool.supplyIncentiveApyInfo.apy;
|
|
1290
1290
|
t.gt(0) && (s = s.plus(
|
|
1291
|
-
new p(f).dividedBy(t).multipliedBy(new p(
|
|
1292
|
-
)), o[
|
|
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();
|
|
1293
1293
|
} else if (g.type === "navi-lending-borrow") {
|
|
1294
|
-
const
|
|
1294
|
+
const u = g["navi-lending-borrow"], f = this.resolveValueUSD(u), k = u.pool.borrowIncentiveApyInfo.apy;
|
|
1295
1295
|
a.gt(0) && (i = i.plus(
|
|
1296
|
-
new p(f).dividedBy(a).multipliedBy(new p(
|
|
1297
|
-
)),
|
|
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();
|
|
1298
1298
|
} else if (g.type === "navi-lending-emode-supply") {
|
|
1299
|
-
const
|
|
1299
|
+
const u = g["navi-lending-emode-supply"], f = this.resolveValueUSD(u), k = u.pool.supplyIncentiveApyInfo.apy;
|
|
1300
1300
|
t.gt(0) && (s = s.plus(
|
|
1301
|
-
new p(f).dividedBy(t).multipliedBy(new p(
|
|
1302
|
-
)), o[
|
|
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();
|
|
1303
1303
|
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1304
|
-
const
|
|
1304
|
+
const u = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(u), k = u.pool.borrowIncentiveApyInfo.apy;
|
|
1305
1305
|
a.gt(0) && (i = i.plus(
|
|
1306
|
-
new p(f).dividedBy(a).multipliedBy(new p(
|
|
1307
|
-
)),
|
|
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();
|
|
1308
1308
|
}
|
|
1309
1309
|
});
|
|
1310
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));
|
|
@@ -1317,16 +1317,16 @@ class O {
|
|
|
1317
1317
|
totalsupplyApy: s.toString(),
|
|
1318
1318
|
totalBorrowApy: i.toString(),
|
|
1319
1319
|
maxLiquidationValue: c.toString(),
|
|
1320
|
-
maxLoanToVaule:
|
|
1320
|
+
maxLoanToVaule: l.toString(),
|
|
1321
1321
|
supply: o,
|
|
1322
|
-
borrow:
|
|
1322
|
+
borrow: n
|
|
1323
1323
|
};
|
|
1324
1324
|
}
|
|
1325
1325
|
}
|
|
1326
|
-
async function
|
|
1326
|
+
async function dt(e, r, o, n) {
|
|
1327
1327
|
const t = await _({
|
|
1328
|
-
...
|
|
1329
|
-
cacheTime:
|
|
1328
|
+
...n,
|
|
1329
|
+
cacheTime: w
|
|
1330
1330
|
});
|
|
1331
1331
|
t.limter && e.moveCall({
|
|
1332
1332
|
target: `${t.limter}::navi_adaptor::verify_navi_position_healthy`,
|
|
@@ -1334,39 +1334,39 @@ async function pt(e, n, o, r) {
|
|
|
1334
1334
|
e.object("0x06"),
|
|
1335
1335
|
e.object(t.storage),
|
|
1336
1336
|
e.object(t.priceOracle),
|
|
1337
|
-
h(
|
|
1337
|
+
h(r, e.pure.address),
|
|
1338
1338
|
e.pure.u256(new p(o).shiftedBy(27).toNumber())
|
|
1339
1339
|
]
|
|
1340
1340
|
});
|
|
1341
1341
|
}
|
|
1342
|
-
const
|
|
1342
|
+
const re = new Q("https://hermes.pyth.network", {
|
|
1343
1343
|
timeout: 1e4
|
|
1344
1344
|
});
|
|
1345
|
-
async function
|
|
1345
|
+
async function mt(e) {
|
|
1346
1346
|
try {
|
|
1347
|
-
const
|
|
1348
|
-
if (!o) return
|
|
1349
|
-
const
|
|
1347
|
+
const r = [], o = await re.getLatestPriceFeeds(e);
|
|
1348
|
+
if (!o) return r;
|
|
1349
|
+
const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1350
1350
|
for (const t of o) {
|
|
1351
1351
|
const a = t.getPriceUnchecked();
|
|
1352
|
-
if (a.publishTime >
|
|
1352
|
+
if (a.publishTime > n) {
|
|
1353
1353
|
console.warn(
|
|
1354
|
-
`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}`
|
|
1355
1355
|
);
|
|
1356
1356
|
continue;
|
|
1357
1357
|
}
|
|
1358
|
-
|
|
1359
|
-
`stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${
|
|
1360
|
-
),
|
|
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));
|
|
1361
1361
|
}
|
|
1362
|
-
return
|
|
1363
|
-
} catch (
|
|
1364
|
-
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}`);
|
|
1365
1365
|
}
|
|
1366
1366
|
}
|
|
1367
|
-
async function
|
|
1367
|
+
async function Se(e, r) {
|
|
1368
1368
|
try {
|
|
1369
|
-
const o = [],
|
|
1369
|
+
const o = [], n = r?.client ?? S, t = e.map((s) => s.priceInfoObject), a = await n.multiGetObjects({
|
|
1370
1370
|
ids: Array.from(new Set(t)),
|
|
1371
1371
|
options: { showContent: !0 }
|
|
1372
1372
|
});
|
|
@@ -1376,12 +1376,12 @@ async function $e(e, n) {
|
|
|
1376
1376
|
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
1377
1377
|
continue;
|
|
1378
1378
|
}
|
|
1379
|
-
const c = e.find((
|
|
1379
|
+
const c = e.find((u) => u.priceInfoObject == i.objectId);
|
|
1380
1380
|
if (!c) {
|
|
1381
1381
|
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
1382
1382
|
continue;
|
|
1383
1383
|
}
|
|
1384
|
-
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;
|
|
1385
1385
|
o.push({
|
|
1386
1386
|
priceFeedId: c.priceFeedId,
|
|
1387
1387
|
priceInfoObject: c.priceInfoObject,
|
|
@@ -1397,12 +1397,12 @@ async function $e(e, n) {
|
|
|
1397
1397
|
return;
|
|
1398
1398
|
}
|
|
1399
1399
|
}
|
|
1400
|
-
async function
|
|
1400
|
+
async function Ve(e, r) {
|
|
1401
1401
|
try {
|
|
1402
|
-
const o = [],
|
|
1403
|
-
if (!
|
|
1402
|
+
const o = [], n = await Se(e, r);
|
|
1403
|
+
if (!n) return o;
|
|
1404
1404
|
const t = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1405
|
-
for (const a of
|
|
1405
|
+
for (const a of n) {
|
|
1406
1406
|
if (a.publishTime > t) {
|
|
1407
1407
|
console.warn(
|
|
1408
1408
|
`pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${t}`
|
|
@@ -1419,51 +1419,51 @@ async function Se(e, n) {
|
|
|
1419
1419
|
throw new Error(`failed to get pyth stale price feed id, msg: ${o.message}`);
|
|
1420
1420
|
}
|
|
1421
1421
|
}
|
|
1422
|
-
async function
|
|
1423
|
-
const
|
|
1422
|
+
async function Me(e, r, o) {
|
|
1423
|
+
const n = o?.client ?? S, t = await _({
|
|
1424
1424
|
...o,
|
|
1425
|
-
cacheTime:
|
|
1425
|
+
cacheTime: w
|
|
1426
1426
|
});
|
|
1427
1427
|
try {
|
|
1428
|
-
const a = await
|
|
1429
|
-
return await new
|
|
1430
|
-
|
|
1428
|
+
const a = await re.getPriceFeedsUpdateData(r);
|
|
1429
|
+
return await new me(
|
|
1430
|
+
n,
|
|
1431
1431
|
t.oracle.pythStateId,
|
|
1432
1432
|
t.oracle.wormholeStateId
|
|
1433
|
-
).updatePriceFeeds(e, a,
|
|
1433
|
+
).updatePriceFeeds(e, a, r);
|
|
1434
1434
|
} catch (a) {
|
|
1435
1435
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
1436
1436
|
}
|
|
1437
1437
|
}
|
|
1438
|
-
async function
|
|
1439
|
-
const
|
|
1438
|
+
async function Ee(e, r, o) {
|
|
1439
|
+
const n = await _({
|
|
1440
1440
|
...o,
|
|
1441
|
-
cacheTime:
|
|
1441
|
+
cacheTime: w
|
|
1442
1442
|
});
|
|
1443
1443
|
if (o?.updatePythPriceFeeds) {
|
|
1444
|
-
const t =
|
|
1444
|
+
const t = r.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
|
|
1445
1445
|
priceFeedId: a.pythPriceFeedId,
|
|
1446
1446
|
priceInfoObject: a.pythPriceInfoObject,
|
|
1447
1447
|
expiration: 30
|
|
1448
1448
|
}));
|
|
1449
1449
|
try {
|
|
1450
|
-
const a = await
|
|
1451
|
-
a.length > 0 && await
|
|
1450
|
+
const a = await Ve(t, o);
|
|
1451
|
+
a.length > 0 && await Me(e, a, o);
|
|
1452
1452
|
} catch {
|
|
1453
1453
|
console.error("Failed to update Pyth price feeds");
|
|
1454
1454
|
}
|
|
1455
1455
|
}
|
|
1456
|
-
for (const t of
|
|
1456
|
+
for (const t of r)
|
|
1457
1457
|
o?.env === "dev" ? e.moveCall({
|
|
1458
|
-
target: `${
|
|
1458
|
+
target: `${n.oracle.packageId}::oracle_pro::update_single_price`,
|
|
1459
1459
|
arguments: [
|
|
1460
1460
|
e.object("0x6"),
|
|
1461
1461
|
// Clock object
|
|
1462
|
-
e.object(
|
|
1462
|
+
e.object(n.oracle.oracleConfig),
|
|
1463
1463
|
// Oracle configuration
|
|
1464
|
-
e.object(
|
|
1464
|
+
e.object(n.oracle.priceOracle),
|
|
1465
1465
|
// Price oracle contract
|
|
1466
|
-
e.object(
|
|
1466
|
+
e.object(n.oracle.supraOracleHolder),
|
|
1467
1467
|
// Supra oracle holder
|
|
1468
1468
|
e.object(t.pythPriceInfoObject),
|
|
1469
1469
|
// Pyth price info object
|
|
@@ -1471,19 +1471,19 @@ async function Me(e, n, o) {
|
|
|
1471
1471
|
// Price feed ID
|
|
1472
1472
|
]
|
|
1473
1473
|
}) : e.moveCall({
|
|
1474
|
-
target: `${
|
|
1474
|
+
target: `${n.oracle.packageId}::oracle_pro::update_single_price_v2`,
|
|
1475
1475
|
arguments: [
|
|
1476
1476
|
e.object("0x6"),
|
|
1477
1477
|
// Clock object
|
|
1478
|
-
e.object(
|
|
1478
|
+
e.object(n.oracle.oracleConfig),
|
|
1479
1479
|
// Oracle configuration
|
|
1480
|
-
e.object(
|
|
1480
|
+
e.object(n.oracle.priceOracle),
|
|
1481
1481
|
// Price oracle contract
|
|
1482
|
-
e.object(
|
|
1482
|
+
e.object(n.oracle.supraOracleHolder),
|
|
1483
1483
|
// Supra oracle holder
|
|
1484
1484
|
e.object(t.pythPriceInfoObject),
|
|
1485
1485
|
// Pyth price info object
|
|
1486
|
-
e.object(
|
|
1486
|
+
e.object(n.oracle.switchboardAggregator),
|
|
1487
1487
|
e.pure.address(t.feedId)
|
|
1488
1488
|
// Price feed ID
|
|
1489
1489
|
]
|
|
@@ -1493,11 +1493,11 @@ async function Me(e, n, o) {
|
|
|
1493
1493
|
async function ne(e) {
|
|
1494
1494
|
return (await _({
|
|
1495
1495
|
...e,
|
|
1496
|
-
cacheTime:
|
|
1496
|
+
cacheTime: w
|
|
1497
1497
|
})).oracle.feeds;
|
|
1498
1498
|
}
|
|
1499
|
-
function
|
|
1500
|
-
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) => {
|
|
1501
1501
|
if (![
|
|
1502
1502
|
"navi-lending-supply",
|
|
1503
1503
|
"navi-lending-borrow",
|
|
@@ -1507,61 +1507,61 @@ function Ee(e, n) {
|
|
|
1507
1507
|
return !1;
|
|
1508
1508
|
const s = t[t.type]?.pool;
|
|
1509
1509
|
return o.oracleId === s?.oracleId;
|
|
1510
|
-
}) ||
|
|
1510
|
+
}) || r?.pools && r.pools.find((t) => o.oracleId === t.oracleId)));
|
|
1511
1511
|
}
|
|
1512
|
-
async function
|
|
1512
|
+
async function ft(e, r, o, n) {
|
|
1513
1513
|
try {
|
|
1514
1514
|
const t = await ne({
|
|
1515
|
-
...
|
|
1515
|
+
...n
|
|
1516
1516
|
}), a = [];
|
|
1517
|
-
o.forEach((
|
|
1518
|
-
a.includes(
|
|
1517
|
+
o.forEach((l) => {
|
|
1518
|
+
a.includes(l.market) || a.push(l.market);
|
|
1519
1519
|
});
|
|
1520
|
-
const s = await
|
|
1521
|
-
...
|
|
1520
|
+
const s = await $e(r, {
|
|
1521
|
+
...n,
|
|
1522
1522
|
markets: a
|
|
1523
|
-
}), i =
|
|
1523
|
+
}), i = De(t, {
|
|
1524
1524
|
lendingPositions: s,
|
|
1525
1525
|
pools: o
|
|
1526
1526
|
});
|
|
1527
|
-
return await
|
|
1527
|
+
return await Ee(e, i, {
|
|
1528
1528
|
updatePythPriceFeeds: !0,
|
|
1529
|
-
...
|
|
1529
|
+
...n
|
|
1530
1530
|
});
|
|
1531
1531
|
} catch (t) {
|
|
1532
|
-
if (
|
|
1532
|
+
if (n?.throws)
|
|
1533
1533
|
throw t;
|
|
1534
1534
|
return console.error(t), e;
|
|
1535
1535
|
}
|
|
1536
1536
|
}
|
|
1537
|
-
const
|
|
1537
|
+
const z = P(
|
|
1538
1538
|
B(
|
|
1539
1539
|
async (e) => {
|
|
1540
|
-
const
|
|
1541
|
-
return Object.keys(o.data).map((
|
|
1542
|
-
...o.data[
|
|
1543
|
-
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
|
|
1544
1544
|
}));
|
|
1545
1545
|
}
|
|
1546
1546
|
)
|
|
1547
1547
|
);
|
|
1548
|
-
async function
|
|
1549
|
-
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;
|
|
1550
1550
|
}
|
|
1551
|
-
async function
|
|
1551
|
+
async function gt(e, r, o, n) {
|
|
1552
1552
|
const t = await _({
|
|
1553
|
-
...
|
|
1554
|
-
cacheTime:
|
|
1555
|
-
}), a = await A(
|
|
1556
|
-
if (!(await
|
|
1557
|
-
...
|
|
1558
|
-
cacheTime:
|
|
1553
|
+
...n,
|
|
1554
|
+
cacheTime: w
|
|
1555
|
+
}), a = await A(r, n);
|
|
1556
|
+
if (!(await z({
|
|
1557
|
+
...n,
|
|
1558
|
+
cacheTime: w
|
|
1559
1559
|
})).some(
|
|
1560
|
-
(c) =>
|
|
1560
|
+
(c) => b(c.coinType) === b(a.suiCoinType)
|
|
1561
1561
|
))
|
|
1562
1562
|
throw new Error("Pool does not support flashloan");
|
|
1563
1563
|
if (t.version === 1) {
|
|
1564
|
-
const [c,
|
|
1564
|
+
const [c, l] = e.moveCall({
|
|
1565
1565
|
target: `${t.package}::lending::flash_loan_with_ctx`,
|
|
1566
1566
|
arguments: [
|
|
1567
1567
|
e.object(t.flashloanConfig),
|
|
@@ -1570,9 +1570,9 @@ async function yt(e, n, o, r) {
|
|
|
1570
1570
|
],
|
|
1571
1571
|
typeArguments: [a.suiCoinType]
|
|
1572
1572
|
});
|
|
1573
|
-
return [c,
|
|
1573
|
+
return [c, l];
|
|
1574
1574
|
} else {
|
|
1575
|
-
const [c,
|
|
1575
|
+
const [c, l] = e.moveCall({
|
|
1576
1576
|
target: `${t.package}::lending::flash_loan_with_ctx_v2`,
|
|
1577
1577
|
arguments: [
|
|
1578
1578
|
e.object(t.flashloanConfig),
|
|
@@ -1582,39 +1582,39 @@ async function yt(e, n, o, r) {
|
|
|
1582
1582
|
],
|
|
1583
1583
|
typeArguments: [a.suiCoinType]
|
|
1584
1584
|
});
|
|
1585
|
-
return [c,
|
|
1585
|
+
return [c, l];
|
|
1586
1586
|
}
|
|
1587
1587
|
}
|
|
1588
|
-
async function
|
|
1588
|
+
async function ht(e, r, o, n, t) {
|
|
1589
1589
|
const a = await _({
|
|
1590
1590
|
...t,
|
|
1591
|
-
cacheTime:
|
|
1592
|
-
}), s = await A(
|
|
1593
|
-
if (!(await
|
|
1591
|
+
cacheTime: w
|
|
1592
|
+
}), s = await A(r, t);
|
|
1593
|
+
if (!(await z({
|
|
1594
1594
|
...t,
|
|
1595
|
-
cacheTime:
|
|
1595
|
+
cacheTime: w
|
|
1596
1596
|
})).some(
|
|
1597
|
-
(d) =>
|
|
1597
|
+
(d) => b(d.coinType) === b(s.suiCoinType)
|
|
1598
1598
|
))
|
|
1599
1599
|
throw new Error("Pool does not support flashloan");
|
|
1600
|
-
const [
|
|
1600
|
+
const [l] = e.moveCall({
|
|
1601
1601
|
target: `${a.package}::lending::flash_repay_with_ctx`,
|
|
1602
1602
|
arguments: [
|
|
1603
1603
|
e.object("0x06"),
|
|
1604
1604
|
e.object(a.storage),
|
|
1605
1605
|
e.object(s.contract.pool),
|
|
1606
1606
|
h(o, e.object),
|
|
1607
|
-
h(
|
|
1607
|
+
h(n, e.object)
|
|
1608
1608
|
],
|
|
1609
1609
|
typeArguments: [s.suiCoinType]
|
|
1610
1610
|
});
|
|
1611
|
-
return [
|
|
1611
|
+
return [l];
|
|
1612
1612
|
}
|
|
1613
|
-
async function
|
|
1613
|
+
async function vt(e, r, o, n, t, a) {
|
|
1614
1614
|
const s = {
|
|
1615
1615
|
...a,
|
|
1616
|
-
cacheTime:
|
|
1617
|
-
}, i = await _(s), c = await A(
|
|
1616
|
+
cacheTime: w
|
|
1617
|
+
}, i = await _(s), c = await A(r, s), l = await A(n, s);
|
|
1618
1618
|
if (i.version === 1) {
|
|
1619
1619
|
const [d, y] = e.moveCall({
|
|
1620
1620
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
@@ -1631,9 +1631,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1631
1631
|
// Pay asset pool contract
|
|
1632
1632
|
h(o, e.object),
|
|
1633
1633
|
// Debt repayment amount
|
|
1634
|
-
e.pure.u8(
|
|
1634
|
+
e.pure.u8(l.id),
|
|
1635
1635
|
// Collateral asset ID
|
|
1636
|
-
e.object(
|
|
1636
|
+
e.object(l.contract.pool),
|
|
1637
1637
|
// Collateral asset pool contract
|
|
1638
1638
|
h(t, e.pure.address),
|
|
1639
1639
|
// Borrower address
|
|
@@ -1642,7 +1642,7 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1642
1642
|
e.object(i.incentiveV3)
|
|
1643
1643
|
// Incentive V3 contract
|
|
1644
1644
|
],
|
|
1645
|
-
typeArguments: [c.suiCoinType,
|
|
1645
|
+
typeArguments: [c.suiCoinType, l.suiCoinType]
|
|
1646
1646
|
});
|
|
1647
1647
|
return [d, y];
|
|
1648
1648
|
} else {
|
|
@@ -1661,9 +1661,9 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1661
1661
|
// Pay asset pool contract
|
|
1662
1662
|
h(o, e.object),
|
|
1663
1663
|
// Debt repayment amount
|
|
1664
|
-
e.pure.u8(
|
|
1664
|
+
e.pure.u8(l.id),
|
|
1665
1665
|
// Collateral asset ID
|
|
1666
|
-
e.object(
|
|
1666
|
+
e.object(l.contract.pool),
|
|
1667
1667
|
// Collateral asset pool contract
|
|
1668
1668
|
h(t, e.pure.address),
|
|
1669
1669
|
// Borrower address
|
|
@@ -1674,21 +1674,21 @@ async function ht(e, n, o, r, t, a) {
|
|
|
1674
1674
|
e.object("0x05")
|
|
1675
1675
|
// SuiSystemState object
|
|
1676
1676
|
],
|
|
1677
|
-
typeArguments: [c.suiCoinType,
|
|
1677
|
+
typeArguments: [c.suiCoinType, l.suiCoinType]
|
|
1678
1678
|
});
|
|
1679
1679
|
return [d, y];
|
|
1680
1680
|
}
|
|
1681
1681
|
}
|
|
1682
|
-
async function
|
|
1683
|
-
const
|
|
1682
|
+
async function Ue(e, r, o) {
|
|
1683
|
+
const n = o?.client ?? S, t = new N(), a = await q({
|
|
1684
1684
|
...o,
|
|
1685
1685
|
markets: Object.values(E),
|
|
1686
|
-
cacheTime:
|
|
1686
|
+
cacheTime: w
|
|
1687
1687
|
}), s = await ne(o);
|
|
1688
|
-
for (let d of
|
|
1688
|
+
for (let d of r) {
|
|
1689
1689
|
const y = await _({
|
|
1690
1690
|
...o,
|
|
1691
|
-
cacheTime:
|
|
1691
|
+
cacheTime: w,
|
|
1692
1692
|
market: d.market
|
|
1693
1693
|
});
|
|
1694
1694
|
t.moveCall({
|
|
@@ -1705,13 +1705,13 @@ async function De(e, n, o) {
|
|
|
1705
1705
|
]
|
|
1706
1706
|
});
|
|
1707
1707
|
}
|
|
1708
|
-
const i = await
|
|
1708
|
+
const i = await n.devInspectTransactionBlock({
|
|
1709
1709
|
transactionBlock: t,
|
|
1710
1710
|
sender: e
|
|
1711
1711
|
}), c = [];
|
|
1712
1712
|
i?.results?.forEach((d) => {
|
|
1713
1713
|
c.push(
|
|
1714
|
-
|
|
1714
|
+
W(
|
|
1715
1715
|
{
|
|
1716
1716
|
results: [d]
|
|
1717
1717
|
},
|
|
@@ -1730,24 +1730,24 @@ async function De(e, n, o) {
|
|
|
1730
1730
|
)
|
|
1731
1731
|
);
|
|
1732
1732
|
});
|
|
1733
|
-
const
|
|
1733
|
+
const l = [];
|
|
1734
1734
|
return c.forEach((d, y) => {
|
|
1735
|
-
const v =
|
|
1735
|
+
const v = r[y];
|
|
1736
1736
|
if (d.length === 5 && Array.isArray(d[0])) {
|
|
1737
1737
|
const g = d[0].length;
|
|
1738
|
-
for (let
|
|
1738
|
+
for (let u = 0; u < g; u++) {
|
|
1739
1739
|
const f = s.find(
|
|
1740
|
-
(
|
|
1741
|
-
),
|
|
1742
|
-
(
|
|
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
|
|
1743
1743
|
);
|
|
1744
|
-
!f || !
|
|
1745
|
-
assetId:
|
|
1746
|
-
assetCoinType:
|
|
1747
|
-
rewardCoinType:
|
|
1748
|
-
option: Number(d[2][
|
|
1749
|
-
userClaimableReward: Number(d[4][
|
|
1750
|
-
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]],
|
|
1751
1751
|
market: v.market,
|
|
1752
1752
|
owner: v.owner,
|
|
1753
1753
|
address: v.address,
|
|
@@ -1755,13 +1755,13 @@ async function De(e, n, o) {
|
|
|
1755
1755
|
});
|
|
1756
1756
|
}
|
|
1757
1757
|
}
|
|
1758
|
-
}),
|
|
1758
|
+
}), l;
|
|
1759
1759
|
}
|
|
1760
|
-
async function
|
|
1761
|
-
const o = (
|
|
1762
|
-
let
|
|
1760
|
+
async function wt(e, r) {
|
|
1761
|
+
const o = (r?.markets || [E.main]).map((a) => I(a));
|
|
1762
|
+
let n = [];
|
|
1763
1763
|
try {
|
|
1764
|
-
|
|
1764
|
+
n = await ee(e, r);
|
|
1765
1765
|
} catch (a) {
|
|
1766
1766
|
console.error(a);
|
|
1767
1767
|
}
|
|
@@ -1770,8 +1770,8 @@ async function vt(e, n) {
|
|
|
1770
1770
|
owner: e,
|
|
1771
1771
|
market: a.key
|
|
1772
1772
|
})).concat(
|
|
1773
|
-
|
|
1774
|
-
const s =
|
|
1773
|
+
n.filter((a) => !!o.find((s) => s.id === a.marketId)).map((a) => {
|
|
1774
|
+
const s = I(a.marketId);
|
|
1775
1775
|
return {
|
|
1776
1776
|
address: a.accountCap,
|
|
1777
1777
|
owner: e,
|
|
@@ -1780,99 +1780,101 @@ async function vt(e, n) {
|
|
|
1780
1780
|
};
|
|
1781
1781
|
})
|
|
1782
1782
|
);
|
|
1783
|
-
return await
|
|
1783
|
+
return await Ue(e, t, r);
|
|
1784
1784
|
}
|
|
1785
|
-
function
|
|
1786
|
-
const
|
|
1787
|
-
e.forEach((
|
|
1788
|
-
const t =
|
|
1789
|
-
|
|
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, {
|
|
1790
1790
|
assetId: t,
|
|
1791
1791
|
rewardType: a,
|
|
1792
|
-
coinType:
|
|
1793
|
-
total: Number(
|
|
1794
|
-
market:
|
|
1792
|
+
coinType: n.rewardCoinType,
|
|
1793
|
+
total: Number(n.userClaimableReward),
|
|
1794
|
+
market: n.market
|
|
1795
1795
|
});
|
|
1796
1796
|
});
|
|
1797
1797
|
const o = /* @__PURE__ */ new Map();
|
|
1798
|
-
for (const { assetId:
|
|
1799
|
-
const c = `${
|
|
1800
|
-
o.has(c) || o.set(c, { assetId:
|
|
1801
|
-
const
|
|
1802
|
-
|
|
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);
|
|
1803
1803
|
}
|
|
1804
|
-
return Array.from(o.values()).map((
|
|
1805
|
-
assetId:
|
|
1806
|
-
rewardType:
|
|
1807
|
-
market:
|
|
1808
|
-
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]) => ({
|
|
1809
1809
|
coinType: t,
|
|
1810
1810
|
available: a.toFixed(6)
|
|
1811
1811
|
}))
|
|
1812
1812
|
}));
|
|
1813
1813
|
}
|
|
1814
|
-
const
|
|
1815
|
-
async (e,
|
|
1816
|
-
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}`;
|
|
1817
1817
|
return (await fetch(o, { headers: M }).then((t) => t.json())).data;
|
|
1818
1818
|
}
|
|
1819
|
-
),
|
|
1820
|
-
async (e,
|
|
1821
|
-
const o = `https://open-api.naviprotocol.io/api/navi/user/rewards?userAddress=${e}&page=${
|
|
1822
|
-
return
|
|
1823
|
-
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
|
|
1824
1824
|
});
|
|
1825
1825
|
}
|
|
1826
1826
|
);
|
|
1827
|
-
async function
|
|
1828
|
-
const
|
|
1827
|
+
async function Ct(e, r, o) {
|
|
1828
|
+
const n = await q({
|
|
1829
1829
|
...o,
|
|
1830
1830
|
markets: Object.values(E),
|
|
1831
|
-
cacheTime:
|
|
1831
|
+
cacheTime: w
|
|
1832
1832
|
}), t = /* @__PURE__ */ new Map();
|
|
1833
|
-
for (const s of
|
|
1834
|
-
const { rewardCoinType: i, ruleIds: c, market:
|
|
1835
|
-
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) {
|
|
1836
1836
|
t.has(g) || t.set(g, {
|
|
1837
1837
|
assetIds: [],
|
|
1838
1838
|
ruleIds: [],
|
|
1839
1839
|
amount: 0,
|
|
1840
|
-
market:
|
|
1840
|
+
market: l,
|
|
1841
1841
|
owner: d,
|
|
1842
1842
|
address: y,
|
|
1843
1843
|
isEMode: typeof v < "u"
|
|
1844
1844
|
});
|
|
1845
1845
|
const f = t.get(g);
|
|
1846
|
-
f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(
|
|
1846
|
+
f.assetIds.push(s.assetCoinType.replace("0x", "")), f.ruleIds.push(u), f.amount += s.userClaimableReward;
|
|
1847
1847
|
}
|
|
1848
1848
|
}
|
|
1849
1849
|
const a = [];
|
|
1850
1850
|
for (const [
|
|
1851
1851
|
s,
|
|
1852
|
-
{ assetIds: i, ruleIds: c, amount:
|
|
1852
|
+
{ assetIds: i, ruleIds: c, amount: l, market: d, owner: y, address: v, isEMode: g }
|
|
1853
1853
|
] of t) {
|
|
1854
|
-
const
|
|
1854
|
+
const u = await _({
|
|
1855
1855
|
...o,
|
|
1856
|
-
cacheTime:
|
|
1856
|
+
cacheTime: w,
|
|
1857
1857
|
market: d
|
|
1858
|
-
}), f = s.split("___")[0],
|
|
1859
|
-
|
|
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)
|
|
1860
1862
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${d}`);
|
|
1861
|
-
const
|
|
1863
|
+
const F = j.contract.rewardFundId;
|
|
1862
1864
|
if (o?.accountCap && !o.customCoinReceive)
|
|
1863
1865
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
1864
1866
|
if (o?.customCoinReceive) {
|
|
1865
|
-
let
|
|
1866
|
-
o.accountCap ?
|
|
1867
|
-
target: `${
|
|
1867
|
+
let $;
|
|
1868
|
+
o.accountCap ? $ = e.moveCall({
|
|
1869
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1868
1870
|
arguments: [
|
|
1869
1871
|
e.object("0x06"),
|
|
1870
1872
|
// Clock object
|
|
1871
|
-
e.object(
|
|
1873
|
+
e.object(u.incentiveV3),
|
|
1872
1874
|
// Incentive V3 contract
|
|
1873
|
-
e.object(
|
|
1875
|
+
e.object(u.storage),
|
|
1874
1876
|
// Protocol storage
|
|
1875
|
-
e.object(
|
|
1877
|
+
e.object(F),
|
|
1876
1878
|
// Reward fund
|
|
1877
1879
|
e.pure.vector("string", i),
|
|
1878
1880
|
// Asset IDs
|
|
@@ -1882,16 +1884,16 @@ async function _t(e, n, o) {
|
|
|
1882
1884
|
// Account capability
|
|
1883
1885
|
],
|
|
1884
1886
|
typeArguments: [f]
|
|
1885
|
-
}) : g ?
|
|
1886
|
-
target: `${
|
|
1887
|
+
}) : g ? $ = e.moveCall({
|
|
1888
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1887
1889
|
arguments: [
|
|
1888
1890
|
e.object("0x06"),
|
|
1889
1891
|
// Clock object
|
|
1890
|
-
e.object(
|
|
1892
|
+
e.object(u.incentiveV3),
|
|
1891
1893
|
// Incentive V3 contract
|
|
1892
|
-
e.object(
|
|
1894
|
+
e.object(u.storage),
|
|
1893
1895
|
// Protocol storage
|
|
1894
|
-
e.object(
|
|
1896
|
+
e.object(F),
|
|
1895
1897
|
// Reward fund
|
|
1896
1898
|
e.pure.vector("string", i),
|
|
1897
1899
|
// Asset IDs
|
|
@@ -1901,16 +1903,16 @@ async function _t(e, n, o) {
|
|
|
1901
1903
|
// Account capability
|
|
1902
1904
|
],
|
|
1903
1905
|
typeArguments: [f]
|
|
1904
|
-
}) :
|
|
1905
|
-
target: `${
|
|
1906
|
+
}) : $ = e.moveCall({
|
|
1907
|
+
target: `${u.package}::incentive_v3::claim_reward`,
|
|
1906
1908
|
arguments: [
|
|
1907
1909
|
e.object("0x06"),
|
|
1908
1910
|
// Clock object
|
|
1909
|
-
e.object(
|
|
1911
|
+
e.object(u.incentiveV3),
|
|
1910
1912
|
// Incentive V3 contract
|
|
1911
|
-
e.object(
|
|
1913
|
+
e.object(u.storage),
|
|
1912
1914
|
// Protocol storage
|
|
1913
|
-
e.object(
|
|
1915
|
+
e.object(F),
|
|
1914
1916
|
// Reward fund
|
|
1915
1917
|
e.pure.vector("string", i),
|
|
1916
1918
|
// Asset IDs
|
|
@@ -1919,43 +1921,46 @@ async function _t(e, n, o) {
|
|
|
1919
1921
|
],
|
|
1920
1922
|
typeArguments: [f]
|
|
1921
1923
|
});
|
|
1922
|
-
const [
|
|
1924
|
+
const [D] = e.moveCall({
|
|
1923
1925
|
target: "0x2::coin::from_balance",
|
|
1924
|
-
arguments: [
|
|
1926
|
+
arguments: [$],
|
|
1925
1927
|
typeArguments: [f]
|
|
1926
1928
|
});
|
|
1927
1929
|
if (o?.customCoinReceive.type === "transfer") {
|
|
1928
1930
|
if (!o.customCoinReceive.transfer)
|
|
1929
1931
|
throw new Error("customCoinReceive.transfer is required");
|
|
1930
1932
|
e.transferObjects(
|
|
1931
|
-
[
|
|
1933
|
+
[D],
|
|
1932
1934
|
h(o.customCoinReceive.transfer, e.pure.address)
|
|
1933
1935
|
);
|
|
1934
1936
|
}
|
|
1935
1937
|
if (o?.customCoinReceive.type === "depositNAVI") {
|
|
1936
|
-
const
|
|
1937
|
-
|
|
1938
|
-
[
|
|
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],
|
|
1939
1941
|
e.pure.address(o.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1940
|
-
) : await
|
|
1942
|
+
) : await Ce(e, j, D, {
|
|
1943
|
+
...o,
|
|
1944
|
+
market: j.market
|
|
1945
|
+
});
|
|
1941
1946
|
} else
|
|
1942
1947
|
a.push({
|
|
1943
|
-
coin:
|
|
1944
|
-
identifier:
|
|
1948
|
+
coin: D,
|
|
1949
|
+
identifier: j,
|
|
1945
1950
|
owner: y,
|
|
1946
1951
|
isEMode: g
|
|
1947
1952
|
});
|
|
1948
1953
|
} else if (o?.accountCap || g) {
|
|
1949
|
-
const
|
|
1950
|
-
target: `${
|
|
1954
|
+
const $ = e.moveCall({
|
|
1955
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1951
1956
|
arguments: [
|
|
1952
1957
|
e.object("0x06"),
|
|
1953
1958
|
// Clock object
|
|
1954
|
-
e.object(
|
|
1959
|
+
e.object(u.incentiveV3),
|
|
1955
1960
|
// Incentive V3 contract
|
|
1956
|
-
e.object(
|
|
1961
|
+
e.object(u.storage),
|
|
1957
1962
|
// Protocol storage
|
|
1958
|
-
e.object(
|
|
1963
|
+
e.object(F),
|
|
1959
1964
|
// Reward fund
|
|
1960
1965
|
e.pure.vector("string", i),
|
|
1961
1966
|
// Asset IDs
|
|
@@ -1965,26 +1970,26 @@ async function _t(e, n, o) {
|
|
|
1965
1970
|
// Account capability
|
|
1966
1971
|
],
|
|
1967
1972
|
typeArguments: [f]
|
|
1968
|
-
}), [
|
|
1973
|
+
}), [D] = e.moveCall({
|
|
1969
1974
|
target: "0x2::coin::from_balance",
|
|
1970
|
-
arguments: [
|
|
1975
|
+
arguments: [$],
|
|
1971
1976
|
typeArguments: [f]
|
|
1972
1977
|
});
|
|
1973
1978
|
e.transferObjects(
|
|
1974
|
-
[
|
|
1979
|
+
[D],
|
|
1975
1980
|
h(o?.accountCap || y, e.pure.address)
|
|
1976
1981
|
);
|
|
1977
1982
|
} else
|
|
1978
1983
|
e.moveCall({
|
|
1979
|
-
target: `${
|
|
1984
|
+
target: `${u.package}::incentive_v3::claim_reward_entry`,
|
|
1980
1985
|
arguments: [
|
|
1981
1986
|
e.object("0x06"),
|
|
1982
1987
|
// Clock object
|
|
1983
|
-
e.object(
|
|
1988
|
+
e.object(u.incentiveV3),
|
|
1984
1989
|
// Incentive V3 contract
|
|
1985
|
-
e.object(
|
|
1990
|
+
e.object(u.storage),
|
|
1986
1991
|
// Protocol storage
|
|
1987
|
-
e.object(
|
|
1992
|
+
e.object(F),
|
|
1988
1993
|
// Reward fund
|
|
1989
1994
|
e.pure.vector("string", i),
|
|
1990
1995
|
// Asset IDs
|
|
@@ -1997,71 +2002,71 @@ async function _t(e, n, o) {
|
|
|
1997
2002
|
return a;
|
|
1998
2003
|
}
|
|
1999
2004
|
export {
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
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,
|
|
2007
2012
|
E as MARKETS,
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2013
|
+
je as Market,
|
|
2014
|
+
Ke as OracleInfo,
|
|
2015
|
+
R as PoolOperator,
|
|
2016
|
+
Je as ReserveDataInfo,
|
|
2012
2017
|
O as UserPositions,
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2018
|
+
ye as UserStateInfo,
|
|
2019
|
+
xe as borrowCoinPTB,
|
|
2020
|
+
Ct as claimLendingRewardsPTB,
|
|
2021
|
+
Te as createAccountCapPTB,
|
|
2017
2022
|
nt as createEModeCapPTB,
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
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,
|
|
2028
2033
|
_ as getConfig,
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
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,
|
|
2038
2043
|
A as getPool,
|
|
2039
|
-
|
|
2044
|
+
q as getPools,
|
|
2040
2045
|
ne as getPriceFeeds,
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
+
mt as getPythStalePriceFeedId,
|
|
2047
|
+
Ve as getPythStalePriceFeedIdV2,
|
|
2048
|
+
lt as getSimulatedHealthFactor,
|
|
2049
|
+
te as getSimulatedHealthFactorPTB,
|
|
2050
|
+
Ze as getStats,
|
|
2046
2051
|
ut as getTransactions,
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
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,
|
|
2055
2060
|
h as parseTxValue,
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
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,
|
|
2063
2068
|
P as withCache,
|
|
2064
2069
|
B as withSingleton,
|
|
2065
|
-
|
|
2070
|
+
Xe as withdrawCoinPTB
|
|
2066
2071
|
};
|
|
2067
2072
|
//# sourceMappingURL=index.esm.js.map
|