@naviprotocol/lending 2.0.0-beta.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts.map +1 -1
- package/dist/emode.d.ts.map +1 -1
- package/dist/index.esm.js +619 -623
- package/dist/index.esm.js.map +1 -1
- package/dist/oracle.d.ts.map +1 -1
- package/dist/pool.d.ts.map +1 -1
- package/dist/pyth.d.ts.map +1 -1
- package/dist/reward.d.ts.map +1 -1
- package/dist/utils.d.ts +31 -1
- package/dist/utils.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,137 +1,137 @@
|
|
|
1
1
|
import { Transaction as N } from "@mysten/sui/transactions";
|
|
2
|
-
import { bcs as
|
|
3
|
-
import { toHex as
|
|
4
|
-
import
|
|
2
|
+
import { bcs as l } from "@mysten/sui/bcs";
|
|
3
|
+
import { toHex as Ee, fromHex as Oe, normalizeStructTag as K, SUI_CLOCK_OBJECT_ID as Z, fromBase64 as Ve } from "@mysten/sui/utils";
|
|
4
|
+
import Me from "lodash.camelcase";
|
|
5
5
|
import p from "bignumber.js";
|
|
6
|
-
import { SuiJsonRpcClient as
|
|
6
|
+
import { SuiJsonRpcClient as De } from "@mysten/sui/jsonRpc";
|
|
7
7
|
import { SuiGraphQLClient as Ue } from "@mysten/sui/graphql";
|
|
8
|
-
import { GrpcWebFetchTransport as
|
|
9
|
-
const ne =
|
|
8
|
+
import { GrpcWebFetchTransport as Fe, SuiGrpcClient as Ne } from "@mysten/sui/grpc";
|
|
9
|
+
const ne = l.bytes(32).transform({
|
|
10
10
|
// To change the input type, you need to provide a type definition for the input
|
|
11
11
|
input: (e) => Oe(e),
|
|
12
|
-
output: (e) =>
|
|
13
|
-
}), Rt =
|
|
12
|
+
output: (e) => Ee(e)
|
|
13
|
+
}), Rt = l.struct("IncentiveAPYInfo", {
|
|
14
14
|
/** Asset identifier */
|
|
15
|
-
asset_id:
|
|
15
|
+
asset_id: l.u8(),
|
|
16
16
|
/** Annual Percentage Yield as a 256-bit integer */
|
|
17
|
-
apy:
|
|
17
|
+
apy: l.u256(),
|
|
18
18
|
/** List of supported coin types for this incentive */
|
|
19
|
-
coin_types:
|
|
20
|
-
}),
|
|
19
|
+
coin_types: l.vector(l.string())
|
|
20
|
+
}), Re = l.struct("IncentivePoolInfo", {
|
|
21
21
|
/** Unique pool identifier */
|
|
22
22
|
pool_id: ne,
|
|
23
23
|
/** Address holding the incentive funds */
|
|
24
24
|
funds: ne,
|
|
25
25
|
/** Current phase of the incentive program */
|
|
26
|
-
phase:
|
|
26
|
+
phase: l.u64(),
|
|
27
27
|
/** Timestamp when the incentive started */
|
|
28
|
-
start_at:
|
|
28
|
+
start_at: l.u64(),
|
|
29
29
|
/** Timestamp when the incentive ends */
|
|
30
|
-
end_at:
|
|
30
|
+
end_at: l.u64(),
|
|
31
31
|
/** Timestamp when the incentive was closed */
|
|
32
|
-
closed_at:
|
|
32
|
+
closed_at: l.u64(),
|
|
33
33
|
/** Total supply of incentive tokens */
|
|
34
|
-
total_supply:
|
|
34
|
+
total_supply: l.u64(),
|
|
35
35
|
/** Asset identifier for the incentive */
|
|
36
|
-
asset_id:
|
|
36
|
+
asset_id: l.u8(),
|
|
37
37
|
/** Option type for the incentive */
|
|
38
|
-
option:
|
|
38
|
+
option: l.u8(),
|
|
39
39
|
/** Factor used in incentive calculations */
|
|
40
|
-
factor:
|
|
40
|
+
factor: l.u256(),
|
|
41
41
|
/** Amount of incentives already distributed */
|
|
42
|
-
distributed:
|
|
42
|
+
distributed: l.u64(),
|
|
43
43
|
/** Amount of incentives currently available */
|
|
44
|
-
available:
|
|
44
|
+
available: l.u256(),
|
|
45
45
|
/** Total amount of incentives */
|
|
46
|
-
total:
|
|
47
|
-
}),
|
|
46
|
+
total: l.u256()
|
|
47
|
+
}), qt = l.struct("IncentivePoolInfoByPhase", {
|
|
48
48
|
/** Phase number */
|
|
49
|
-
phase:
|
|
49
|
+
phase: l.u64(),
|
|
50
50
|
/** List of incentive pools in this phase */
|
|
51
|
-
pools:
|
|
52
|
-
}),
|
|
51
|
+
pools: l.vector(Re)
|
|
52
|
+
}), Lt = l.struct("OracleInfo", {
|
|
53
53
|
/** Oracle identifier */
|
|
54
|
-
oracle_id:
|
|
54
|
+
oracle_id: l.u8(),
|
|
55
55
|
/** Current price as a 256-bit integer */
|
|
56
|
-
price:
|
|
56
|
+
price: l.u256(),
|
|
57
57
|
/** Number of decimal places for the price */
|
|
58
|
-
decimals:
|
|
58
|
+
decimals: l.u8(),
|
|
59
59
|
/** Whether the oracle data is valid */
|
|
60
|
-
valid:
|
|
61
|
-
}), zt =
|
|
60
|
+
valid: l.bool()
|
|
61
|
+
}), zt = l.struct("FlashLoanAssetConfig", {
|
|
62
62
|
/** Unique identifier for the flash loan asset */
|
|
63
|
-
id:
|
|
63
|
+
id: l.string(),
|
|
64
64
|
/** Asset identifier */
|
|
65
|
-
asset_id:
|
|
65
|
+
asset_id: l.u8(),
|
|
66
66
|
/** Coin type for the asset */
|
|
67
|
-
coin_type:
|
|
67
|
+
coin_type: l.string(),
|
|
68
68
|
/** Pool identifier for the flash loan */
|
|
69
|
-
pool_id:
|
|
69
|
+
pool_id: l.string(),
|
|
70
70
|
/** Rate paid to suppliers for flash loans */
|
|
71
|
-
rate_to_supplier:
|
|
71
|
+
rate_to_supplier: l.u64(),
|
|
72
72
|
/** Rate paid to treasury for flash loans */
|
|
73
|
-
rate_to_treasury:
|
|
73
|
+
rate_to_treasury: l.u64(),
|
|
74
74
|
/** Maximum flash loan amount */
|
|
75
|
-
max:
|
|
75
|
+
max: l.u64(),
|
|
76
76
|
/** Minimum flash loan amount */
|
|
77
|
-
min:
|
|
78
|
-
}),
|
|
77
|
+
min: l.u64()
|
|
78
|
+
}), qe = l.struct("ReserveDataInfo", {
|
|
79
79
|
/** Reserve identifier */
|
|
80
|
-
id:
|
|
80
|
+
id: l.u8(),
|
|
81
81
|
/** Oracle identifier for price feeds */
|
|
82
|
-
oracle_id:
|
|
82
|
+
oracle_id: l.u8(),
|
|
83
83
|
/** Coin type for the reserve */
|
|
84
|
-
coin_type:
|
|
84
|
+
coin_type: l.string(),
|
|
85
85
|
/** Maximum supply capacity */
|
|
86
|
-
supply_cap:
|
|
86
|
+
supply_cap: l.u256(),
|
|
87
87
|
/** Maximum borrow capacity */
|
|
88
|
-
borrow_cap:
|
|
88
|
+
borrow_cap: l.u256(),
|
|
89
89
|
/** Current supply interest rate */
|
|
90
|
-
supply_rate:
|
|
90
|
+
supply_rate: l.u256(),
|
|
91
91
|
/** Current borrow interest rate */
|
|
92
|
-
borrow_rate:
|
|
92
|
+
borrow_rate: l.u256(),
|
|
93
93
|
/** Current supply index for interest calculation */
|
|
94
|
-
supply_index:
|
|
94
|
+
supply_index: l.u256(),
|
|
95
95
|
/** Current borrow index for interest calculation */
|
|
96
|
-
borrow_index:
|
|
96
|
+
borrow_index: l.u256(),
|
|
97
97
|
/** Total amount supplied to the reserve */
|
|
98
|
-
total_supply:
|
|
98
|
+
total_supply: l.u256(),
|
|
99
99
|
/** Total amount borrowed from the reserve */
|
|
100
|
-
total_borrow:
|
|
100
|
+
total_borrow: l.u256(),
|
|
101
101
|
/** Timestamp of last update */
|
|
102
|
-
last_update_at:
|
|
102
|
+
last_update_at: l.u64(),
|
|
103
103
|
/** Loan-to-Value ratio for collateral */
|
|
104
|
-
ltv:
|
|
104
|
+
ltv: l.u256(),
|
|
105
105
|
/** Treasury factor for fee calculations */
|
|
106
|
-
treasury_factor:
|
|
106
|
+
treasury_factor: l.u256(),
|
|
107
107
|
/** Current treasury balance */
|
|
108
|
-
treasury_balance:
|
|
108
|
+
treasury_balance: l.u256(),
|
|
109
109
|
/** Base interest rate */
|
|
110
|
-
base_rate:
|
|
110
|
+
base_rate: l.u256(),
|
|
111
111
|
/** Interest rate multiplier */
|
|
112
|
-
multiplier:
|
|
112
|
+
multiplier: l.u256(),
|
|
113
113
|
/** Jump rate multiplier for high utilization */
|
|
114
|
-
jump_rate_multiplier:
|
|
114
|
+
jump_rate_multiplier: l.u256(),
|
|
115
115
|
/** Reserve factor for protocol fees */
|
|
116
|
-
reserve_factor:
|
|
116
|
+
reserve_factor: l.u256(),
|
|
117
117
|
/** Optimal utilization rate */
|
|
118
|
-
optimal_utilization:
|
|
118
|
+
optimal_utilization: l.u256(),
|
|
119
119
|
/** Liquidation ratio threshold */
|
|
120
|
-
liquidation_ratio:
|
|
120
|
+
liquidation_ratio: l.u256(),
|
|
121
121
|
/** Liquidation bonus for liquidators */
|
|
122
|
-
liquidation_bonus:
|
|
122
|
+
liquidation_bonus: l.u256(),
|
|
123
123
|
/** Liquidation threshold */
|
|
124
|
-
liquidation_threshold:
|
|
125
|
-
}), Le =
|
|
124
|
+
liquidation_threshold: l.u256()
|
|
125
|
+
}), Le = l.struct("UserStateInfo", {
|
|
126
126
|
/** Asset identifier */
|
|
127
|
-
asset_id:
|
|
127
|
+
asset_id: l.u8(),
|
|
128
128
|
/** User's current borrow balance */
|
|
129
|
-
borrow_balance:
|
|
129
|
+
borrow_balance: l.u256(),
|
|
130
130
|
/** User's current supply balance */
|
|
131
|
-
supply_balance:
|
|
132
|
-
}),
|
|
133
|
-
version:
|
|
134
|
-
},
|
|
131
|
+
supply_balance: l.u256()
|
|
132
|
+
}), ze = "2.0.1", E = {
|
|
133
|
+
version: ze
|
|
134
|
+
}, Ge = E.version, He = () => {
|
|
135
135
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
136
136
|
const e = process.version;
|
|
137
137
|
return `Node.js ${e.startsWith("v") ? e.substring(1) : e}`;
|
|
@@ -139,9 +139,9 @@ const ne = u.bytes(32).transform({
|
|
|
139
139
|
return "Node/Unknown";
|
|
140
140
|
}, We = () => {
|
|
141
141
|
let e = "";
|
|
142
|
-
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${
|
|
143
|
-
}, oe = We(),
|
|
144
|
-
class
|
|
142
|
+
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${Ge} (${He()})`), e;
|
|
143
|
+
}, oe = We(), fe = "0x2::sui::SUI";
|
|
144
|
+
class Je extends Error {
|
|
145
145
|
constructor(t) {
|
|
146
146
|
super(
|
|
147
147
|
`NAVI Sui SDK capability "${t}" requires an explicit graphql client; no public GraphQL fallback is configured`
|
|
@@ -151,22 +151,22 @@ class He extends Error {
|
|
|
151
151
|
function X(e) {
|
|
152
152
|
return e == null ? void 0 : String(e);
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function Ke(e, t) {
|
|
155
155
|
return (BigInt(e) + BigInt(t)).toString();
|
|
156
156
|
}
|
|
157
|
-
function
|
|
157
|
+
function Qe(e, t) {
|
|
158
158
|
return (BigInt(e) - BigInt(t)).toString();
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function ye(e) {
|
|
161
161
|
const t = e.core;
|
|
162
162
|
if (typeof t?.getBalance != "function" || typeof t?.listBalances != "function")
|
|
163
163
|
throw new Error("NAVI Sui balance helpers require a v2 Core API client");
|
|
164
164
|
return t;
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function ge(e, t = fe) {
|
|
167
167
|
const r = X(e.addressBalance ?? e.fundsInAddressBalance) ?? "0";
|
|
168
168
|
let o = X(e.balance ?? e.totalBalance), n = X(e.coinBalance);
|
|
169
|
-
return !n && o && (n =
|
|
169
|
+
return !n && o && (n = Qe(o, r)), !o && n && (o = Ke(n, r)), {
|
|
170
170
|
coinType: K(e.coinType ?? t),
|
|
171
171
|
totalBalance: o ?? "0",
|
|
172
172
|
coinBalance: n ?? "0",
|
|
@@ -174,36 +174,36 @@ function ye(e, t = me) {
|
|
|
174
174
|
...e.coinObjectCount === null || e.coinObjectCount === void 0 ? {} : { coinObjectCount: e.coinObjectCount }
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
|
-
function Gt(e, t =
|
|
177
|
+
function Gt(e, t = fe) {
|
|
178
178
|
const r = K(t);
|
|
179
179
|
return e.filter((o) => K(o.coinType) === r).reduce((o, n) => o + BigInt(n.balance), 0n).toString();
|
|
180
180
|
}
|
|
181
|
-
async function Wt(e, t) {
|
|
182
|
-
const r = await fe(e).getBalance(t), o = r.balance;
|
|
183
|
-
return ye((o && typeof o == "object" ? o : r) ?? {}, t.coinType);
|
|
184
|
-
}
|
|
185
181
|
async function Ht(e, t) {
|
|
186
|
-
const r = await
|
|
182
|
+
const r = await ye(e).getBalance(t), o = r.balance;
|
|
183
|
+
return ge((o && typeof o == "object" ? o : r) ?? {}, t.coinType);
|
|
184
|
+
}
|
|
185
|
+
async function Wt(e, t) {
|
|
186
|
+
const r = await ye(e).listBalances(t), { balances: o = [] } = r;
|
|
187
187
|
return {
|
|
188
|
-
balances: o.map((n) =>
|
|
188
|
+
balances: o.map((n) => ge(n)),
|
|
189
189
|
nextCursor: r.nextCursor ?? r.cursor ?? null
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
|
-
function
|
|
192
|
+
function Ye(e, t) {
|
|
193
193
|
if ("client" in t)
|
|
194
194
|
return t.client;
|
|
195
|
-
const r = new
|
|
195
|
+
const r = new Fe({
|
|
196
196
|
baseUrl: t.url,
|
|
197
197
|
meta: t.headers,
|
|
198
198
|
fetchInit: t.fetchInit,
|
|
199
199
|
fetch: t.fetch
|
|
200
200
|
});
|
|
201
|
-
return new
|
|
201
|
+
return new Ne({
|
|
202
202
|
network: e,
|
|
203
203
|
transport: r
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
-
function
|
|
206
|
+
function Ze(e, t) {
|
|
207
207
|
return "client" in t ? t.client : new Ue({
|
|
208
208
|
network: e,
|
|
209
209
|
url: t.url,
|
|
@@ -211,29 +211,29 @@ function Ye(e, t) {
|
|
|
211
211
|
fetch: t.fetch
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
|
-
function
|
|
215
|
-
return "client" in t ? t.client : new
|
|
214
|
+
function he(e, t) {
|
|
215
|
+
return "client" in t ? t.client : new De({
|
|
216
216
|
network: e,
|
|
217
217
|
url: t.url
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
|
-
function
|
|
221
|
-
const t =
|
|
220
|
+
function Xe(e) {
|
|
221
|
+
const t = Ye(e.network, e.grpc);
|
|
222
222
|
return {
|
|
223
223
|
network: e.network,
|
|
224
224
|
coreClient: t,
|
|
225
225
|
grpc: t,
|
|
226
|
-
graphql: e.graphql ?
|
|
227
|
-
legacyJsonRpc: e.legacyJsonRpc ?
|
|
226
|
+
graphql: e.graphql ? Ze(e.network, e.graphql) : void 0,
|
|
227
|
+
legacyJsonRpc: e.legacyJsonRpc ? he(e.network, e.legacyJsonRpc) : void 0,
|
|
228
228
|
services: e.services
|
|
229
229
|
};
|
|
230
230
|
}
|
|
231
231
|
function Jt(e, t) {
|
|
232
232
|
if (!e.graphql)
|
|
233
|
-
throw new
|
|
233
|
+
throw new Je(t);
|
|
234
234
|
return e.graphql;
|
|
235
235
|
}
|
|
236
|
-
function
|
|
236
|
+
function xe() {
|
|
237
237
|
const e = "NAVI Sui SDK requires an explicit v2 gRPC/Core client. Pass { network, grpc } or an explicit legacyJsonRpc client for deprecated compatibility.", t = new Proxy(
|
|
238
238
|
{},
|
|
239
239
|
{
|
|
@@ -255,10 +255,10 @@ function Xe() {
|
|
|
255
255
|
}
|
|
256
256
|
);
|
|
257
257
|
}
|
|
258
|
-
function
|
|
259
|
-
return e ? typeof e == "string" ?
|
|
258
|
+
function et(e, t = "mainnet") {
|
|
259
|
+
return e ? typeof e == "string" ? he(t, { url: e }) : Xe(e) : xe();
|
|
260
260
|
}
|
|
261
|
-
const
|
|
261
|
+
const tt = 16 * 1024;
|
|
262
262
|
function te(e) {
|
|
263
263
|
return e.replace(/^0x/i, "");
|
|
264
264
|
}
|
|
@@ -268,12 +268,12 @@ function ae(e) {
|
|
|
268
268
|
r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
|
|
269
269
|
return r;
|
|
270
270
|
}
|
|
271
|
-
function
|
|
271
|
+
function rt(e, t) {
|
|
272
272
|
return (e[t] << 8) + e[t + 1];
|
|
273
273
|
}
|
|
274
274
|
function ie(e) {
|
|
275
|
-
return
|
|
276
|
-
maxSize:
|
|
275
|
+
return l.vector(l.U8).serialize(Array.from(e), {
|
|
276
|
+
maxSize: tt
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
279
|
function ce(e, t) {
|
|
@@ -282,17 +282,17 @@ function ce(e, t) {
|
|
|
282
282
|
bcs: t
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
|
-
function rt(e) {
|
|
286
|
-
return u.vector(u.U8).serialize(Array.from(new TextEncoder().encode(e))).toBytes();
|
|
287
|
-
}
|
|
288
285
|
function nt(e) {
|
|
289
|
-
return
|
|
290
|
-
|
|
286
|
+
return l.vector(l.U8).serialize(Array.from(new TextEncoder().encode(e))).toBytes();
|
|
287
|
+
}
|
|
288
|
+
function ot(e) {
|
|
289
|
+
return l.struct("PriceIdentifier", {
|
|
290
|
+
bytes: l.vector(l.U8)
|
|
291
291
|
}).serialize({
|
|
292
292
|
bytes: Array.from(e)
|
|
293
293
|
}).toBytes();
|
|
294
294
|
}
|
|
295
|
-
function
|
|
295
|
+
function at(e) {
|
|
296
296
|
const t = [];
|
|
297
297
|
let r = 0, o = 0;
|
|
298
298
|
for (let n = 0; n < e.length; n += 1) {
|
|
@@ -301,19 +301,19 @@ function ot(e) {
|
|
|
301
301
|
}
|
|
302
302
|
return t.push(e.slice(o).trim()), t;
|
|
303
303
|
}
|
|
304
|
-
function
|
|
304
|
+
function it(e) {
|
|
305
305
|
const r = e.indexOf("::table::Table"), o = e.indexOf("<", r), n = e.lastIndexOf(">"), a = "::price_identifier::PriceIdentifier";
|
|
306
306
|
if (r < 0 || o < 0 || n <= o)
|
|
307
307
|
throw new Error(`Unexpected Pyth price table type: ${e}`);
|
|
308
|
-
const [c, i] =
|
|
308
|
+
const [c, i] = at(e.slice(o + 1, n));
|
|
309
309
|
if (!c?.endsWith(a) || !i?.endsWith("::object::ID"))
|
|
310
310
|
throw new Error(`Unexpected Pyth price table type arguments: ${e}`);
|
|
311
311
|
return c.slice(0, -a.length);
|
|
312
312
|
}
|
|
313
|
-
function
|
|
313
|
+
function ct(e) {
|
|
314
314
|
return Uint8Array.from(atob(e), (t) => t.charCodeAt(0));
|
|
315
315
|
}
|
|
316
|
-
class
|
|
316
|
+
class we {
|
|
317
317
|
constructor(t, r) {
|
|
318
318
|
this.endpoint = t.replace(/\/$/, ""), this.timeout = r?.timeout ?? 1e4;
|
|
319
319
|
}
|
|
@@ -341,7 +341,7 @@ class he {
|
|
|
341
341
|
throw new Error(`Unsupported Hermes price update encoding: ${o}`);
|
|
342
342
|
if (n.length === 0)
|
|
343
343
|
throw new Error("Hermes price update response did not include binary update data");
|
|
344
|
-
return n.map(
|
|
344
|
+
return n.map(ct);
|
|
345
345
|
}
|
|
346
346
|
async get(t, r, o) {
|
|
347
347
|
const n = new AbortController(), a = setTimeout(() => n.abort(), this.timeout), c = new URL(`${this.endpoint}${t}`);
|
|
@@ -361,7 +361,7 @@ class he {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
|
-
class
|
|
364
|
+
class st {
|
|
365
365
|
constructor(t, r, o) {
|
|
366
366
|
this.provider = t, this.pythStateId = r, this.wormholeStateId = o, this.priceFeedObjectIdCache = /* @__PURE__ */ new Map();
|
|
367
367
|
}
|
|
@@ -444,8 +444,11 @@ class ct {
|
|
|
444
444
|
const r = await this.getMoveObjectJson(t);
|
|
445
445
|
if (r?.fields) {
|
|
446
446
|
const o = r.fields;
|
|
447
|
-
if ("upgrade_cap" in o)
|
|
448
|
-
|
|
447
|
+
if ("upgrade_cap" in o) {
|
|
448
|
+
const n = o.upgrade_cap, a = n?.package ?? n?.fields?.package;
|
|
449
|
+
if (a)
|
|
450
|
+
return a;
|
|
451
|
+
}
|
|
449
452
|
}
|
|
450
453
|
throw new Error(`Cannot fetch package id for object ${t}`);
|
|
451
454
|
}
|
|
@@ -482,15 +485,15 @@ class ct {
|
|
|
482
485
|
async executePriceFeedUpdates(t, r, o, n, a) {
|
|
483
486
|
const c = [];
|
|
484
487
|
for (const [i, s] of o.entries()) {
|
|
485
|
-
const
|
|
486
|
-
if (!
|
|
488
|
+
const u = await this.getPriceFeedObjectId(s);
|
|
489
|
+
if (!u)
|
|
487
490
|
throw new Error(`Price feed ${s} not found, please create it first`);
|
|
488
|
-
c.push(
|
|
491
|
+
c.push(u), [n] = t.moveCall({
|
|
489
492
|
target: `${r}::pyth::update_single_price_feed`,
|
|
490
493
|
arguments: [
|
|
491
494
|
t.object(this.pythStateId),
|
|
492
495
|
n,
|
|
493
|
-
t.object(
|
|
496
|
+
t.object(u),
|
|
494
497
|
a[i],
|
|
495
498
|
t.object(Z)
|
|
496
499
|
]
|
|
@@ -513,7 +516,7 @@ class ct {
|
|
|
513
516
|
if (!this.priceFeedObjectIdCache.has(r)) {
|
|
514
517
|
const { id: o, fieldType: n } = await this.getPriceTableInfo(), a = this.getCoreProvider() ? ce(
|
|
515
518
|
`${n}::price_identifier::PriceIdentifier`,
|
|
516
|
-
|
|
519
|
+
ot(ae(r))
|
|
517
520
|
) : {
|
|
518
521
|
type: `${n}::price_identifier::PriceIdentifier`,
|
|
519
522
|
value: {
|
|
@@ -526,7 +529,7 @@ class ct {
|
|
|
526
529
|
}
|
|
527
530
|
async getPriceTableInfo() {
|
|
528
531
|
if (!this.priceTableInfo) {
|
|
529
|
-
const t = this.getCoreProvider() ? ce("vector<u8>",
|
|
532
|
+
const t = this.getCoreProvider() ? ce("vector<u8>", nt("price_info")) : {
|
|
530
533
|
type: "vector<u8>",
|
|
531
534
|
value: "price_info"
|
|
532
535
|
}, r = await this.getDynamicMoveObjectJson(this.pythStateId, t);
|
|
@@ -534,17 +537,17 @@ class ct {
|
|
|
534
537
|
throw new Error("Price Table not found, contract may not be initialized");
|
|
535
538
|
this.priceTableInfo = {
|
|
536
539
|
id: r.objectId,
|
|
537
|
-
fieldType:
|
|
540
|
+
fieldType: it(r.type)
|
|
538
541
|
};
|
|
539
542
|
}
|
|
540
543
|
return this.priceTableInfo;
|
|
541
544
|
}
|
|
542
545
|
extractVaaBytesFromAccumulatorMessage(t) {
|
|
543
|
-
const o = 7 + t[6] + 1, n =
|
|
546
|
+
const o = 7 + t[6] + 1, n = rt(t, o), a = o + 2;
|
|
544
547
|
return t.subarray(a, a + n);
|
|
545
548
|
}
|
|
546
549
|
}
|
|
547
|
-
const
|
|
550
|
+
const ut = "https://open-api.naviprotocol.io/api";
|
|
548
551
|
let J = {}, be = 0;
|
|
549
552
|
function lt(e) {
|
|
550
553
|
return e.replace(/\/+$/, "");
|
|
@@ -562,18 +565,18 @@ function Kt(e) {
|
|
|
562
565
|
function se() {
|
|
563
566
|
return be;
|
|
564
567
|
}
|
|
565
|
-
function
|
|
568
|
+
function O(e) {
|
|
566
569
|
const t = e?.services?.naviOpenApi ?? J.services?.naviOpenApi;
|
|
567
570
|
return {
|
|
568
|
-
baseUrl: lt(t?.baseUrl ??
|
|
571
|
+
baseUrl: lt(t?.baseUrl ?? ut),
|
|
569
572
|
headers: t?.headers
|
|
570
573
|
};
|
|
571
574
|
}
|
|
572
575
|
function M(e, t) {
|
|
573
|
-
const r =
|
|
576
|
+
const r = O(t), o = e.startsWith("/") ? e : `/${e}`;
|
|
574
577
|
return `${r.baseUrl}${o}`;
|
|
575
578
|
}
|
|
576
|
-
function
|
|
579
|
+
function dt(e) {
|
|
577
580
|
if (e instanceof Headers) {
|
|
578
581
|
const t = {};
|
|
579
582
|
return e.forEach((r, o) => {
|
|
@@ -582,54 +585,57 @@ function ut(e) {
|
|
|
582
585
|
}
|
|
583
586
|
return Array.isArray(e) ? Object.fromEntries(e) : e;
|
|
584
587
|
}
|
|
585
|
-
function
|
|
588
|
+
function D(e, t) {
|
|
586
589
|
return {
|
|
587
|
-
...
|
|
590
|
+
...dt(e),
|
|
588
591
|
...t?.headers ?? {}
|
|
589
592
|
};
|
|
590
593
|
}
|
|
591
|
-
|
|
592
|
-
function
|
|
593
|
-
|
|
594
|
+
et();
|
|
595
|
+
function V(e, t) {
|
|
596
|
+
if (!e)
|
|
597
|
+
throw new Error(
|
|
598
|
+
`${t} requires an explicit Sui v2 gRPC/Core client. Pass { client }; NAVI SDK v2 no longer provides an implicit default client.`
|
|
599
|
+
);
|
|
600
|
+
return e;
|
|
594
601
|
}
|
|
595
|
-
function
|
|
602
|
+
function ue(e) {
|
|
603
|
+
return e ? e instanceof Uint8Array ? Array.from(e) : Array.isArray(e) ? e : Array.from(Ve(e)) : [];
|
|
604
|
+
}
|
|
605
|
+
function pt(e) {
|
|
596
606
|
const t = e?.commandResults ?? [], r = e?.Transaction ?? e?.FailedTransaction ?? {}, o = r.effects?.errors?.[0] ?? r.effects?.status?.error ?? r.status?.error ?? r.status?.errors?.[0];
|
|
597
|
-
return {
|
|
607
|
+
return o && console.warn("[lending] devInspect(core simulate) returned error:", o), {
|
|
598
608
|
effects: r.effects,
|
|
599
609
|
events: r.events,
|
|
600
610
|
error: o,
|
|
601
611
|
results: t.map((n) => ({
|
|
602
|
-
returnValues: (n.returnValues ?? []).map((a) => [
|
|
612
|
+
returnValues: (n.returnValues ?? []).map((a) => [ue(a.bcs), ""]),
|
|
603
613
|
mutableReferenceOutputs: (n.mutatedReferences ?? []).map((a) => [
|
|
604
614
|
"",
|
|
605
|
-
|
|
615
|
+
ue(a.bcs),
|
|
606
616
|
""
|
|
607
617
|
])
|
|
608
618
|
}))
|
|
609
619
|
};
|
|
610
620
|
}
|
|
611
|
-
async function
|
|
621
|
+
async function L(e, t) {
|
|
612
622
|
const r = e?.core;
|
|
613
|
-
if (typeof r?.simulateTransaction
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
return dt(n);
|
|
626
|
-
}
|
|
627
|
-
return e.devInspectTransactionBlock({
|
|
628
|
-
transactionBlock: t.transactionBlock ?? t.transaction,
|
|
629
|
-
sender: t.sender
|
|
623
|
+
if (typeof r?.simulateTransaction != "function")
|
|
624
|
+
throw new Error("devInspectTransaction requires a Sui v2 Core-capable client");
|
|
625
|
+
const o = t.transaction ?? t.transactionBlock;
|
|
626
|
+
o instanceof N && o.setSenderIfNotSet(t.sender);
|
|
627
|
+
const n = await r.simulateTransaction({
|
|
628
|
+
transaction: o,
|
|
629
|
+
checksEnabled: !1,
|
|
630
|
+
include: {
|
|
631
|
+
effects: !0,
|
|
632
|
+
events: !0,
|
|
633
|
+
commandResults: !0
|
|
634
|
+
}
|
|
630
635
|
});
|
|
636
|
+
return pt(n);
|
|
631
637
|
}
|
|
632
|
-
function
|
|
638
|
+
function ve(e) {
|
|
633
639
|
return {
|
|
634
640
|
json: !!e?.showContent,
|
|
635
641
|
display: !!e?.showDisplay,
|
|
@@ -637,7 +643,7 @@ function we(e) {
|
|
|
637
643
|
objectBcs: !!e?.showBcs
|
|
638
644
|
};
|
|
639
645
|
}
|
|
640
|
-
function
|
|
646
|
+
function Ce(e) {
|
|
641
647
|
return !e || e instanceof Error ? {
|
|
642
648
|
error: e instanceof Error ? { code: "notFound", error: e.message } : void 0
|
|
643
649
|
} : {
|
|
@@ -657,36 +663,34 @@ function ve(e) {
|
|
|
657
663
|
}
|
|
658
664
|
};
|
|
659
665
|
}
|
|
660
|
-
async function
|
|
666
|
+
async function mt(e, t) {
|
|
661
667
|
const r = e?.core;
|
|
662
|
-
if (typeof r?.getObject
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
return e.getObject(t);
|
|
668
|
+
if (typeof r?.getObject != "function")
|
|
669
|
+
throw new Error("getSuiObject requires a Sui v2 Core-capable client");
|
|
670
|
+
const { object: o } = await r.getObject({
|
|
671
|
+
objectId: t.id,
|
|
672
|
+
include: ve(t.options)
|
|
673
|
+
});
|
|
674
|
+
return Ce(o);
|
|
670
675
|
}
|
|
671
|
-
async function
|
|
676
|
+
async function ft(e, t) {
|
|
672
677
|
const r = e?.core;
|
|
673
|
-
if (typeof r?.getObjects
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
return e.multiGetObjects(t);
|
|
678
|
+
if (typeof r?.getObjects != "function")
|
|
679
|
+
throw new Error("multiGetSuiObjects requires a Sui v2 Core-capable client");
|
|
680
|
+
const { objects: o } = await r.getObjects({
|
|
681
|
+
objectIds: t.ids,
|
|
682
|
+
include: ve(t.options)
|
|
683
|
+
});
|
|
684
|
+
return o.map(Ce);
|
|
681
685
|
}
|
|
682
|
-
function
|
|
686
|
+
function je(e) {
|
|
683
687
|
const t = [];
|
|
684
688
|
let r = !1;
|
|
685
689
|
return e.forEach((o, n) => {
|
|
686
690
|
const a = n === e.length - 1;
|
|
687
691
|
if (typeof o == "object" && o !== null && a) {
|
|
688
|
-
const { client: c, disableCache: i, cacheTime: s, ...
|
|
689
|
-
|
|
692
|
+
const { client: c, disableCache: i, cacheTime: s, ...u } = o;
|
|
693
|
+
u.__naviSdkServiceConfigVersion = se(), t.push(u), r = !0;
|
|
690
694
|
} else
|
|
691
695
|
t.push(o);
|
|
692
696
|
}), r || t.push({
|
|
@@ -696,7 +700,7 @@ function Ce(e) {
|
|
|
696
700
|
function A(e) {
|
|
697
701
|
const t = {};
|
|
698
702
|
return (...r) => {
|
|
699
|
-
const o =
|
|
703
|
+
const o = je(r);
|
|
700
704
|
return t[o] || (t[o] = e(...r).finally(() => {
|
|
701
705
|
delete t[o];
|
|
702
706
|
})), t[o];
|
|
@@ -705,7 +709,7 @@ function A(e) {
|
|
|
705
709
|
function $(e) {
|
|
706
710
|
let t = {};
|
|
707
711
|
return (...r) => {
|
|
708
|
-
const o = r[r.length - 1], n =
|
|
712
|
+
const o = r[r.length - 1], n = je(r), a = t[n];
|
|
709
713
|
return !o?.disableCache && typeof a?.data < "u" && (typeof o?.cacheTime > "u" || o.cacheTime > Date.now() - a.cacheAt) ? Promise.resolve(a.data) : e(...r).then((c) => (t[n] = {
|
|
710
714
|
data: c,
|
|
711
715
|
cacheAt: Date.now()
|
|
@@ -716,7 +720,7 @@ function x(e) {
|
|
|
716
720
|
return Array.isArray(e) ? e.map((t) => x(t)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
|
|
717
721
|
(t, r) => ({
|
|
718
722
|
...t,
|
|
719
|
-
[
|
|
723
|
+
[Me(r)]: x(e[r])
|
|
720
724
|
}),
|
|
721
725
|
{}
|
|
722
726
|
) : e;
|
|
@@ -726,7 +730,7 @@ function h(e, t) {
|
|
|
726
730
|
throw new Error("Transaction value is required");
|
|
727
731
|
return typeof e == "object" ? e : t(e);
|
|
728
732
|
}
|
|
729
|
-
function
|
|
733
|
+
function yt(e, t) {
|
|
730
734
|
return typeof t == "string" ? e.object(t) : typeof t == "object" && t.$kind ? t : e.object(t.contract.pool);
|
|
731
735
|
}
|
|
732
736
|
function Q(e, t, r) {
|
|
@@ -740,18 +744,18 @@ function Q(e, t, r) {
|
|
|
740
744
|
function C(e) {
|
|
741
745
|
return K(e);
|
|
742
746
|
}
|
|
743
|
-
function
|
|
747
|
+
function Ie(e) {
|
|
744
748
|
const t = (e || 0) / Math.pow(10, 27);
|
|
745
749
|
return t > Math.pow(10, 5) ? 1 / 0 : t;
|
|
746
750
|
}
|
|
747
|
-
new
|
|
751
|
+
new we("https://hermes.pyth.network", {
|
|
748
752
|
timeout: 2e4
|
|
749
753
|
});
|
|
750
|
-
const
|
|
754
|
+
const gt = 27, le = (e, t) => {
|
|
751
755
|
if (!Number(e) || !Number(t)) return new p(0);
|
|
752
|
-
const r = new p(1).shiftedBy(1 *
|
|
756
|
+
const r = new p(1).shiftedBy(1 * gt), o = r.multipliedBy(new p(0.5));
|
|
753
757
|
return new p(e).multipliedBy(new p(t)).plus(o).dividedBy(r).integerValue(p.ROUND_DOWN);
|
|
754
|
-
},
|
|
758
|
+
}, U = oe ? {
|
|
755
759
|
"User-Agent": oe
|
|
756
760
|
} : {};
|
|
757
761
|
function ee(e, t = "uniqueId") {
|
|
@@ -766,7 +770,7 @@ function de(e, t = "uniqueId") {
|
|
|
766
770
|
{}
|
|
767
771
|
);
|
|
768
772
|
}
|
|
769
|
-
function
|
|
773
|
+
function W(e, t) {
|
|
770
774
|
const r = e.emodes.find((n) => n.emodeId === t.emodeId);
|
|
771
775
|
if (!r)
|
|
772
776
|
throw new Error("EMode not found in pool");
|
|
@@ -780,39 +784,39 @@ function H(e, t) {
|
|
|
780
784
|
isEMode: !0
|
|
781
785
|
};
|
|
782
786
|
}
|
|
783
|
-
function
|
|
787
|
+
function ht(e) {
|
|
784
788
|
const [t, r] = e.split("-");
|
|
785
789
|
return !t || !r ? null : {
|
|
786
790
|
marketKey: t,
|
|
787
791
|
poolId: parseInt(r)
|
|
788
792
|
};
|
|
789
793
|
}
|
|
790
|
-
function
|
|
794
|
+
function B() {
|
|
791
795
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
792
796
|
}
|
|
793
797
|
var z = /* @__PURE__ */ ((e) => (e[e.Supply = 1] = "Supply", e[e.Withdraw = 2] = "Withdraw", e[e.Borrow = 3] = "Borrow", e[e.Repay = 4] = "Repay", e))(z || {});
|
|
794
798
|
const G = $(
|
|
795
799
|
A(
|
|
796
800
|
async (e) => {
|
|
797
|
-
const t = (e?.markets || [F.main]).map((a) => _(a)), r =
|
|
798
|
-
`/navi/pools?env=${e?.env || "prod"}&sdk=${
|
|
801
|
+
const t = (e?.markets || [F.main]).map((a) => _(a)), r = O(e), o = M(
|
|
802
|
+
`/navi/pools?env=${e?.env || "prod"}&sdk=${E.version}&market=${t.map(
|
|
799
803
|
(a) => a.key
|
|
800
804
|
)}`,
|
|
801
805
|
e
|
|
802
|
-
), n = await fetch(o, { headers: U
|
|
806
|
+
), n = await fetch(o, { headers: D(U, r) }).then(
|
|
803
807
|
(a) => a.json()
|
|
804
808
|
);
|
|
805
809
|
return n.data.forEach((a) => {
|
|
806
|
-
const i = n.meta.emodes.filter((
|
|
807
|
-
const
|
|
808
|
-
return a.market ===
|
|
809
|
-
}).filter((
|
|
810
|
+
const i = n.meta.emodes.filter((b) => {
|
|
811
|
+
const I = _(b.marketId);
|
|
812
|
+
return a.market === I.key && b.isActive;
|
|
813
|
+
}).filter((b) => !!b.assets.find((I) => I.assetId === a.id));
|
|
810
814
|
a.emodes = i;
|
|
811
|
-
const s = p(a.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(),
|
|
815
|
+
const s = p(a.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), u = p(a.borrowedAmount).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), m = p(s).multipliedBy(a.oracle.price).toString(), w = p(u).multipliedBy(a.oracle.price).toString(), y = p(a.supplyCapCeiling).shiftedBy(-27).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), g = p.max(
|
|
812
816
|
p(a.borrowedAmount),
|
|
813
817
|
p(a.validBorrowAmount)
|
|
814
|
-
).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), d = p(
|
|
815
|
-
a.poolSupplyAmount = s, a.poolBorrowAmount =
|
|
818
|
+
).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), d = p(y).multipliedBy(a.oracle.price).toString(), f = p(g).multipliedBy(a.oracle.price).toString();
|
|
819
|
+
a.poolSupplyAmount = s, a.poolBorrowAmount = u, a.poolSupplyValue = m, a.poolBorrowValue = w, a.poolSupplyCapAmount = y, a.poolBorrowCapAmount = g, a.poolSupplyCapValue = d, a.poolBorrowCapValue = f;
|
|
816
820
|
}), n.data;
|
|
817
821
|
}
|
|
818
822
|
)
|
|
@@ -820,7 +824,7 @@ const G = $(
|
|
|
820
824
|
async function S(e, t) {
|
|
821
825
|
let r = t?.market;
|
|
822
826
|
if (typeof e == "string") {
|
|
823
|
-
const a =
|
|
827
|
+
const a = ht(e);
|
|
824
828
|
a && (r = a.marketKey, e = a.poolId);
|
|
825
829
|
}
|
|
826
830
|
const o = await G({
|
|
@@ -837,22 +841,22 @@ async function S(e, t) {
|
|
|
837
841
|
}
|
|
838
842
|
const Qt = $(
|
|
839
843
|
A(async (e) => {
|
|
840
|
-
const t =
|
|
844
|
+
const t = O(e), r = M(`/navi/stats?sdk=${E.version}`, e);
|
|
841
845
|
return (await fetch(r, {
|
|
842
|
-
headers: U
|
|
846
|
+
headers: D(U, t)
|
|
843
847
|
}).then((n) => n.json())).data;
|
|
844
848
|
})
|
|
845
849
|
), Yt = $(
|
|
846
850
|
A(
|
|
847
851
|
async (e) => {
|
|
848
|
-
const t =
|
|
852
|
+
const t = O(e), r = M(`/navi/fee?sdk=${E.version}`, e);
|
|
849
853
|
return await fetch(r, {
|
|
850
|
-
headers: U
|
|
854
|
+
headers: D(U, t)
|
|
851
855
|
}).then((n) => n.json());
|
|
852
856
|
}
|
|
853
857
|
)
|
|
854
858
|
);
|
|
855
|
-
async function
|
|
859
|
+
async function wt(e, t, r, o) {
|
|
856
860
|
const n = await j({
|
|
857
861
|
...o,
|
|
858
862
|
cacheTime: v
|
|
@@ -908,7 +912,7 @@ async function Zt(e, t, r, o) {
|
|
|
908
912
|
let i;
|
|
909
913
|
if (n.version === 1)
|
|
910
914
|
if (o?.accountCap) {
|
|
911
|
-
const [
|
|
915
|
+
const [u] = e.moveCall({
|
|
912
916
|
target: `${n.package}::incentive_v3::withdraw_with_account_cap`,
|
|
913
917
|
arguments: [
|
|
914
918
|
e.object("0x06"),
|
|
@@ -923,9 +927,9 @@ async function Zt(e, t, r, o) {
|
|
|
923
927
|
],
|
|
924
928
|
typeArguments: [a.suiCoinType]
|
|
925
929
|
});
|
|
926
|
-
i =
|
|
930
|
+
i = u;
|
|
927
931
|
} else {
|
|
928
|
-
const [
|
|
932
|
+
const [u] = e.moveCall({
|
|
929
933
|
target: `${n.package}::incentive_v3::withdraw`,
|
|
930
934
|
arguments: [
|
|
931
935
|
e.object("0x06"),
|
|
@@ -939,10 +943,10 @@ async function Zt(e, t, r, o) {
|
|
|
939
943
|
],
|
|
940
944
|
typeArguments: [a.suiCoinType]
|
|
941
945
|
});
|
|
942
|
-
i =
|
|
946
|
+
i = u;
|
|
943
947
|
}
|
|
944
948
|
else if (o?.accountCap) {
|
|
945
|
-
const [
|
|
949
|
+
const [u] = e.moveCall({
|
|
946
950
|
target: `${n.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
947
951
|
arguments: [
|
|
948
952
|
e.object("0x06"),
|
|
@@ -958,9 +962,9 @@ async function Zt(e, t, r, o) {
|
|
|
958
962
|
],
|
|
959
963
|
typeArguments: [a.suiCoinType]
|
|
960
964
|
});
|
|
961
|
-
i =
|
|
965
|
+
i = u;
|
|
962
966
|
} else {
|
|
963
|
-
const [
|
|
967
|
+
const [u] = e.moveCall({
|
|
964
968
|
target: `${n.package}::incentive_v3::withdraw_v2`,
|
|
965
969
|
arguments: [
|
|
966
970
|
e.object("0x06"),
|
|
@@ -975,7 +979,7 @@ async function Zt(e, t, r, o) {
|
|
|
975
979
|
],
|
|
976
980
|
typeArguments: [a.suiCoinType]
|
|
977
981
|
});
|
|
978
|
-
i =
|
|
982
|
+
i = u;
|
|
979
983
|
}
|
|
980
984
|
return e.moveCall({
|
|
981
985
|
target: "0x2::coin::from_balance",
|
|
@@ -994,7 +998,7 @@ async function Xt(e, t, r, o) {
|
|
|
994
998
|
let i;
|
|
995
999
|
if (n.version === 1)
|
|
996
1000
|
if (o?.accountCap) {
|
|
997
|
-
const [
|
|
1001
|
+
const [u] = e.moveCall({
|
|
998
1002
|
target: `${n.package}::incentive_v3::borrow_with_account_cap`,
|
|
999
1003
|
arguments: [
|
|
1000
1004
|
e.object("0x06"),
|
|
@@ -1009,9 +1013,9 @@ async function Xt(e, t, r, o) {
|
|
|
1009
1013
|
],
|
|
1010
1014
|
typeArguments: [a.suiCoinType]
|
|
1011
1015
|
});
|
|
1012
|
-
i =
|
|
1016
|
+
i = u;
|
|
1013
1017
|
} else {
|
|
1014
|
-
const [
|
|
1018
|
+
const [u] = e.moveCall({
|
|
1015
1019
|
target: `${n.package}::incentive_v3::borrow`,
|
|
1016
1020
|
arguments: [
|
|
1017
1021
|
e.object("0x06"),
|
|
@@ -1025,10 +1029,10 @@ async function Xt(e, t, r, o) {
|
|
|
1025
1029
|
],
|
|
1026
1030
|
typeArguments: [a.suiCoinType]
|
|
1027
1031
|
});
|
|
1028
|
-
i =
|
|
1032
|
+
i = u;
|
|
1029
1033
|
}
|
|
1030
1034
|
else if (o?.accountCap) {
|
|
1031
|
-
const [
|
|
1035
|
+
const [u] = e.moveCall({
|
|
1032
1036
|
target: `${n.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
1033
1037
|
arguments: [
|
|
1034
1038
|
e.object("0x06"),
|
|
@@ -1044,9 +1048,9 @@ async function Xt(e, t, r, o) {
|
|
|
1044
1048
|
],
|
|
1045
1049
|
typeArguments: [a.suiCoinType]
|
|
1046
1050
|
});
|
|
1047
|
-
i =
|
|
1051
|
+
i = u;
|
|
1048
1052
|
} else {
|
|
1049
|
-
const [
|
|
1053
|
+
const [u] = e.moveCall({
|
|
1050
1054
|
target: `${n.package}::incentive_v3::borrow_v2`,
|
|
1051
1055
|
arguments: [
|
|
1052
1056
|
e.object("0x06"),
|
|
@@ -1061,7 +1065,7 @@ async function Xt(e, t, r, o) {
|
|
|
1061
1065
|
],
|
|
1062
1066
|
typeArguments: [a.suiCoinType]
|
|
1063
1067
|
});
|
|
1064
|
-
i =
|
|
1068
|
+
i = u;
|
|
1065
1069
|
}
|
|
1066
1070
|
return e.moveCall({
|
|
1067
1071
|
target: "0x2::coin::from_balance",
|
|
@@ -1127,7 +1131,7 @@ const er = $(
|
|
|
1127
1131
|
async (e) => {
|
|
1128
1132
|
const t = await j({
|
|
1129
1133
|
...e
|
|
1130
|
-
}), r = e?.client
|
|
1134
|
+
}), r = V(e?.client, "getBorrowFee");
|
|
1131
1135
|
if (e?.address && typeof e?.asset < "u")
|
|
1132
1136
|
try {
|
|
1133
1137
|
const a = await S(e.asset, e), c = new N();
|
|
@@ -1141,15 +1145,18 @@ const er = $(
|
|
|
1141
1145
|
],
|
|
1142
1146
|
typeArguments: []
|
|
1143
1147
|
});
|
|
1144
|
-
const i = await
|
|
1148
|
+
const i = await L(r, {
|
|
1145
1149
|
transactionBlock: c,
|
|
1146
1150
|
sender: e.address
|
|
1147
|
-
}), s = Q(i, [
|
|
1151
|
+
}), s = Q(i, [l.u64()]);
|
|
1148
1152
|
return (Number(s[0]) || 0) / 100;
|
|
1149
1153
|
} catch (a) {
|
|
1150
|
-
console.error(
|
|
1154
|
+
console.error(
|
|
1155
|
+
"[lending] getBorrowFee per-user query failed, falling back to global rate:",
|
|
1156
|
+
a
|
|
1157
|
+
);
|
|
1151
1158
|
}
|
|
1152
|
-
const n = (await
|
|
1159
|
+
const n = (await mt(r, {
|
|
1153
1160
|
id: t.incentiveV3,
|
|
1154
1161
|
options: { showType: !0, showOwner: !0, showContent: !0 }
|
|
1155
1162
|
})).data.content.fields.borrow_fee_rate;
|
|
@@ -1197,15 +1204,15 @@ class bt {
|
|
|
1197
1204
|
return;
|
|
1198
1205
|
}
|
|
1199
1206
|
r[s.uniqueId] || this.pools.push(s), s?.emodes?.forEach((m) => {
|
|
1200
|
-
o[m.uniqueId] || this.emodes.push(m), m.assets.forEach((
|
|
1201
|
-
|
|
1202
|
-
(
|
|
1203
|
-
) && n.add(s.uniqueId),
|
|
1207
|
+
o[m.uniqueId] || this.emodes.push(m), m.assets.forEach((w) => {
|
|
1208
|
+
w.isDebt && m.assets.find(
|
|
1209
|
+
(g) => g.isCollateral && g.ltv > 0 && g.assetId !== s.id
|
|
1210
|
+
) && n.add(s.uniqueId), w.isCollateral && m.assets.find((g) => g.isDebt && g.assetId !== s.id) && a.add(s.uniqueId);
|
|
1204
1211
|
});
|
|
1205
1212
|
}), i = i.plus(s.poolBorrowValue), c = c.plus(s.poolSupplyValue);
|
|
1206
1213
|
}), this.poolMap = ee(this.pools, "id"), this.emodeMap = de(this.emodes, "emodeId"), this.emodes.forEach((s) => {
|
|
1207
|
-
const
|
|
1208
|
-
this.emodePools.push(...
|
|
1214
|
+
const u = this.getEModePools(s.emodeId);
|
|
1215
|
+
this.emodePools.push(...u);
|
|
1209
1216
|
}), this._overview = {
|
|
1210
1217
|
marketTotalSupplyValue: c.toString(),
|
|
1211
1218
|
marketTotalBorrowValue: i.toString()
|
|
@@ -1246,7 +1253,7 @@ const _ = (e) => {
|
|
|
1246
1253
|
if (!r)
|
|
1247
1254
|
throw new Error("Market not found");
|
|
1248
1255
|
return r;
|
|
1249
|
-
},
|
|
1256
|
+
}, vt = $(
|
|
1250
1257
|
A(
|
|
1251
1258
|
async (e, t) => {
|
|
1252
1259
|
const r = await G({
|
|
@@ -1262,22 +1269,22 @@ const _ = (e) => {
|
|
|
1262
1269
|
)
|
|
1263
1270
|
), tr = $(
|
|
1264
1271
|
A(
|
|
1265
|
-
async (e, t) => (await
|
|
1272
|
+
async (e, t) => (await vt([e], t))[0]
|
|
1266
1273
|
)
|
|
1267
1274
|
), j = $(
|
|
1268
1275
|
A(
|
|
1269
1276
|
async (e) => {
|
|
1270
|
-
const t = _(e?.market || R), r =
|
|
1271
|
-
`/navi/config?env=${e?.env || "prod"}&sdk=${
|
|
1277
|
+
const t = _(e?.market || R), r = O(e), o = M(
|
|
1278
|
+
`/navi/config?env=${e?.env || "prod"}&sdk=${E.version}&market=${t.key}`,
|
|
1272
1279
|
e
|
|
1273
1280
|
);
|
|
1274
1281
|
return (await fetch(o, {
|
|
1275
|
-
headers: U
|
|
1282
|
+
headers: D(U, r)
|
|
1276
1283
|
}).then((a) => a.json())).data;
|
|
1277
1284
|
}
|
|
1278
1285
|
)
|
|
1279
1286
|
), v = 1e3 * 60 * 5;
|
|
1280
|
-
async function
|
|
1287
|
+
async function Ct(e, t) {
|
|
1281
1288
|
const r = await j({
|
|
1282
1289
|
cacheTime: v,
|
|
1283
1290
|
...t
|
|
@@ -1287,7 +1294,7 @@ async function vt(e, t) {
|
|
|
1287
1294
|
arguments: []
|
|
1288
1295
|
});
|
|
1289
1296
|
}
|
|
1290
|
-
async function
|
|
1297
|
+
async function jt(e, t, r) {
|
|
1291
1298
|
const o = await j({
|
|
1292
1299
|
cacheTime: v,
|
|
1293
1300
|
...r
|
|
@@ -1297,7 +1304,7 @@ async function Ct(e, t, r) {
|
|
|
1297
1304
|
arguments: [t]
|
|
1298
1305
|
});
|
|
1299
1306
|
}
|
|
1300
|
-
async function
|
|
1307
|
+
async function It(e, t, r) {
|
|
1301
1308
|
const o = await j({
|
|
1302
1309
|
...r,
|
|
1303
1310
|
cacheTime: v
|
|
@@ -1331,12 +1338,12 @@ async function nr(e, t, r) {
|
|
|
1331
1338
|
const o = await j({
|
|
1332
1339
|
cacheTime: v,
|
|
1333
1340
|
...r
|
|
1334
|
-
}), n = await
|
|
1335
|
-
await
|
|
1341
|
+
}), n = await Ct(e, r);
|
|
1342
|
+
await It(e, t, {
|
|
1336
1343
|
...r,
|
|
1337
1344
|
accountCap: n
|
|
1338
1345
|
});
|
|
1339
|
-
const a = await _(r?.market || R), c = await
|
|
1346
|
+
const a = await _(r?.market || R), c = await jt(e, n, r);
|
|
1340
1347
|
return e.moveCall({
|
|
1341
1348
|
target: `${o.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
1342
1349
|
arguments: [
|
|
@@ -1353,19 +1360,19 @@ const ke = $(
|
|
|
1353
1360
|
const r = await j({
|
|
1354
1361
|
cacheTime: v,
|
|
1355
1362
|
...t
|
|
1356
|
-
}), o = new N(), n = t?.client
|
|
1363
|
+
}), o = new N(), n = V(t?.client, "getUserEModeCaps");
|
|
1357
1364
|
o.moveCall({
|
|
1358
1365
|
target: `${r.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
1359
1366
|
arguments: [o.object(r.emode.contract.registryObject), o.pure.address(e)]
|
|
1360
1367
|
});
|
|
1361
|
-
const c = (await
|
|
1368
|
+
const c = (await L(n, {
|
|
1362
1369
|
transactionBlock: o,
|
|
1363
1370
|
sender: e
|
|
1364
|
-
})).results[0].returnValues, i =
|
|
1365
|
-
return i.map((m,
|
|
1371
|
+
})).results[0].returnValues, i = l.vector(l.u64()).parse(Uint8Array.from(c[0][0])), s = l.vector(l.u64()).parse(Uint8Array.from(c[1][0])), u = l.vector(l.Address).parse(Uint8Array.from(c[2][0]));
|
|
1372
|
+
return i.map((m, w) => ({
|
|
1366
1373
|
marketId: Number(m),
|
|
1367
|
-
emodeId: Number(s[
|
|
1368
|
-
accountCap:
|
|
1374
|
+
emodeId: Number(s[w]),
|
|
1375
|
+
accountCap: u[w].toString()
|
|
1369
1376
|
}));
|
|
1370
1377
|
}
|
|
1371
1378
|
)
|
|
@@ -1389,7 +1396,7 @@ function ar(e, t, r) {
|
|
|
1389
1396
|
let a = 0;
|
|
1390
1397
|
const c = [];
|
|
1391
1398
|
let i = "";
|
|
1392
|
-
if (t.sort((s,
|
|
1399
|
+
if (t.sort((s, u) => Number(u.balance) - Number(s.balance)).forEach((s) => {
|
|
1393
1400
|
if (!(o && a >= n) && Number(s.balance) !== 0) {
|
|
1394
1401
|
if (i || (i = s.coinType), i !== s.coinType)
|
|
1395
1402
|
throw new Error("All coins must be of the same type");
|
|
@@ -1403,7 +1410,7 @@ function ar(e, t, r) {
|
|
|
1403
1410
|
);
|
|
1404
1411
|
return C(i) === C("0x2::sui::SUI") && r?.useGasCoin ? o ? e.splitCoins(e.gas, [e.pure.u64(n)]) : e.gas : (c.length === 1 ? e.object(c[0]) : e.mergeCoins(c[0], c.slice(1)), o ? e.splitCoins(c[0], [e.pure.u64(n)]) : c[0]);
|
|
1405
1412
|
}
|
|
1406
|
-
async function
|
|
1413
|
+
async function _e(e, t, r, o, n, a, c) {
|
|
1407
1414
|
const i = await j({
|
|
1408
1415
|
...c,
|
|
1409
1416
|
cacheTime: v
|
|
@@ -1414,7 +1421,7 @@ async function Ie(e, t, r, o, n, a, c) {
|
|
|
1414
1421
|
e.object("0x06"),
|
|
1415
1422
|
e.object(i.storage),
|
|
1416
1423
|
e.object(i.oracle.priceOracle),
|
|
1417
|
-
|
|
1424
|
+
yt(e, s),
|
|
1418
1425
|
h(t, e.pure.address),
|
|
1419
1426
|
h(s.id, e.pure.u8),
|
|
1420
1427
|
h(o, e.pure.u64),
|
|
@@ -1424,11 +1431,11 @@ async function Ie(e, t, r, o, n, a, c) {
|
|
|
1424
1431
|
typeArguments: [s.suiCoinType]
|
|
1425
1432
|
});
|
|
1426
1433
|
}
|
|
1427
|
-
async function
|
|
1428
|
-
return
|
|
1434
|
+
async function _t(e, t, r) {
|
|
1435
|
+
return _e(e, t, 0, 0, 0, !1, r);
|
|
1429
1436
|
}
|
|
1430
|
-
async function
|
|
1431
|
-
const o = new N(), n = r?.client
|
|
1437
|
+
async function Te(e, t, r) {
|
|
1438
|
+
const o = new N(), n = V(r?.client, "getLendingStateBatch"), a = await G({
|
|
1432
1439
|
...r,
|
|
1433
1440
|
markets: Object.values(F)
|
|
1434
1441
|
}), c = ee(a), s = Array.from(new Set(t.map((d) => d.market))).map((d) => _(d));
|
|
@@ -1454,46 +1461,46 @@ async function _e(e, t, r) {
|
|
|
1454
1461
|
arguments: [o.object(f.storage), o.pure.address(d.address)]
|
|
1455
1462
|
});
|
|
1456
1463
|
}
|
|
1457
|
-
const m = (await
|
|
1464
|
+
const m = (await L(n, {
|
|
1458
1465
|
transactionBlock: o,
|
|
1459
1466
|
sender: e
|
|
1460
|
-
})).results || [],
|
|
1467
|
+
})).results || [], w = {};
|
|
1461
1468
|
s.forEach((d, f) => {
|
|
1462
1469
|
try {
|
|
1463
|
-
const
|
|
1464
|
-
for (const T of
|
|
1465
|
-
|
|
1470
|
+
const b = m[f]?.returnValues?.map((T) => l.vector(qe).parse(Uint8Array.from(T[0])))[0] || [], I = {};
|
|
1471
|
+
for (const T of b)
|
|
1472
|
+
I[T.id] = {
|
|
1466
1473
|
supplyIndex: T.supply_index,
|
|
1467
1474
|
borrowIndex: T.borrow_index
|
|
1468
1475
|
};
|
|
1469
|
-
|
|
1470
|
-
} catch (
|
|
1476
|
+
w[d.key] = I;
|
|
1477
|
+
} catch (b) {
|
|
1471
1478
|
console.warn(
|
|
1472
1479
|
`[@naviprotocol/lending] Failed to decode reserve data for market "${d.key}", falling back to open-api pool indices`,
|
|
1473
|
-
|
|
1480
|
+
b
|
|
1474
1481
|
);
|
|
1475
1482
|
}
|
|
1476
1483
|
});
|
|
1477
|
-
const
|
|
1478
|
-
return
|
|
1479
|
-
const
|
|
1480
|
-
d.forEach((
|
|
1481
|
-
if (
|
|
1484
|
+
const y = m.slice(s.length).map((d) => d.returnValues?.map((f) => l.vector(Le).parse(Uint8Array.from(f[0])))[0] || []), g = [];
|
|
1485
|
+
return y.forEach((d, f) => {
|
|
1486
|
+
const b = t[f], I = _(b.market), T = w[I.key] || {};
|
|
1487
|
+
d.forEach((k) => {
|
|
1488
|
+
if (k.supply_balance === "0" && k.borrow_balance === "0" && (b.emodeId === void 0 || !r?.includeZeroBalanceEmodePositions))
|
|
1482
1489
|
return;
|
|
1483
|
-
const
|
|
1484
|
-
if (!
|
|
1490
|
+
const P = c[`${I.key}-${k.asset_id}`];
|
|
1491
|
+
if (!P)
|
|
1485
1492
|
return;
|
|
1486
|
-
const
|
|
1487
|
-
|
|
1488
|
-
supplyBalance:
|
|
1489
|
-
borrowBalance:
|
|
1490
|
-
assetId:
|
|
1491
|
-
market:
|
|
1492
|
-
pool:
|
|
1493
|
-
emodeId:
|
|
1493
|
+
const H = T[k.asset_id], Y = H?.supplyIndex ?? P.currentSupplyIndex, Ae = H?.borrowIndex ?? P.currentBorrowIndex, Se = le(k.supply_balance, Y).toString(), $e = le(k.borrow_balance, Ae).toString();
|
|
1494
|
+
g.push({
|
|
1495
|
+
supplyBalance: Se,
|
|
1496
|
+
borrowBalance: $e,
|
|
1497
|
+
assetId: k.asset_id,
|
|
1498
|
+
market: I.key,
|
|
1499
|
+
pool: P,
|
|
1500
|
+
emodeId: b.emodeId
|
|
1494
1501
|
});
|
|
1495
1502
|
});
|
|
1496
|
-
}),
|
|
1503
|
+
}), g;
|
|
1497
1504
|
}
|
|
1498
1505
|
const ir = $(
|
|
1499
1506
|
async (e, t) => {
|
|
@@ -1501,58 +1508,58 @@ const ir = $(
|
|
|
1501
1508
|
address: e,
|
|
1502
1509
|
market: n.key
|
|
1503
1510
|
}));
|
|
1504
|
-
return await
|
|
1511
|
+
return await Te(e, o, t);
|
|
1505
1512
|
}
|
|
1506
1513
|
);
|
|
1507
1514
|
async function cr(e, t) {
|
|
1508
|
-
const r = t?.client
|
|
1509
|
-
await
|
|
1510
|
-
const n = await
|
|
1515
|
+
const r = V(t?.client, "getHealthFactor"), o = new N();
|
|
1516
|
+
await _t(o, e, t);
|
|
1517
|
+
const n = await L(r, {
|
|
1511
1518
|
transactionBlock: o,
|
|
1512
1519
|
sender: e
|
|
1513
|
-
}), a = Q(n, [
|
|
1514
|
-
return
|
|
1520
|
+
}), a = Q(n, [l.u256()]);
|
|
1521
|
+
return Ie(Number(a[0]) || 0);
|
|
1515
1522
|
}
|
|
1516
1523
|
async function sr(e, t, r, o) {
|
|
1517
|
-
const n = o?.client
|
|
1524
|
+
const n = V(o?.client, "getSimulatedHealthFactor"), a = new N();
|
|
1518
1525
|
let c = 0, i = 0;
|
|
1519
1526
|
const s = await S(t, o);
|
|
1520
|
-
if (r.forEach((
|
|
1521
|
-
|
|
1527
|
+
if (r.forEach((y) => {
|
|
1528
|
+
y.type === z.Supply ? c += y.amount : y.type === z.Withdraw ? c -= y.amount : y.type === z.Borrow ? i += y.amount : y.type === z.Repay && (i -= y.amount);
|
|
1522
1529
|
}), c * i < 0)
|
|
1523
1530
|
throw new Error("Invalid operations");
|
|
1524
|
-
const
|
|
1525
|
-
await
|
|
1531
|
+
const u = c > 0 || i > 0;
|
|
1532
|
+
await _e(
|
|
1526
1533
|
a,
|
|
1527
1534
|
e,
|
|
1528
1535
|
s,
|
|
1529
1536
|
Math.abs(c),
|
|
1530
1537
|
Math.abs(i),
|
|
1531
|
-
|
|
1538
|
+
u,
|
|
1532
1539
|
o
|
|
1533
1540
|
);
|
|
1534
|
-
const m = await
|
|
1541
|
+
const m = await L(n, {
|
|
1535
1542
|
transactionBlock: a,
|
|
1536
1543
|
sender: e
|
|
1537
|
-
}),
|
|
1538
|
-
return
|
|
1544
|
+
}), w = Q(m, [l.u256()]);
|
|
1545
|
+
return Ie(Number(w[0]) || 0);
|
|
1539
1546
|
}
|
|
1540
|
-
const
|
|
1547
|
+
const ur = A(
|
|
1541
1548
|
async (e, t) => {
|
|
1542
1549
|
const r = new URLSearchParams();
|
|
1543
1550
|
t?.cursor && r.set("cursor", t.cursor), r.set("userAddress", e);
|
|
1544
|
-
const o =
|
|
1545
|
-
`/navi/user/transactions?${r.toString()}&sdk=${
|
|
1551
|
+
const o = O(t), n = M(
|
|
1552
|
+
`/navi/user/transactions?${r.toString()}&sdk=${E.version}`,
|
|
1546
1553
|
t
|
|
1547
1554
|
);
|
|
1548
1555
|
return (await fetch(n, {
|
|
1549
|
-
headers: U
|
|
1556
|
+
headers: D(U, o)
|
|
1550
1557
|
}).then((c) => c.json())).data;
|
|
1551
1558
|
}
|
|
1552
1559
|
);
|
|
1553
|
-
async function
|
|
1560
|
+
async function lr(e, t) {
|
|
1554
1561
|
let r = null;
|
|
1555
|
-
const o = [], n = t?.client
|
|
1562
|
+
const o = [], n = V(t?.client, "getCoins"), a = n.core;
|
|
1556
1563
|
do {
|
|
1557
1564
|
let c;
|
|
1558
1565
|
if (t?.coinType)
|
|
@@ -1579,30 +1586,30 @@ async function ur(e, t) {
|
|
|
1579
1586
|
});
|
|
1580
1587
|
}
|
|
1581
1588
|
else if (typeof a?.listBalances == "function" && typeof a?.listCoins == "function") {
|
|
1582
|
-
const i =
|
|
1589
|
+
const i = /* @__PURE__ */ new Set();
|
|
1583
1590
|
let s = null;
|
|
1584
1591
|
do {
|
|
1585
|
-
const
|
|
1592
|
+
const u = await a.listBalances({
|
|
1586
1593
|
owner: e,
|
|
1587
1594
|
cursor: s,
|
|
1588
1595
|
limit: 100
|
|
1589
1596
|
});
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1597
|
+
for (const m of u.balances ?? [])
|
|
1598
|
+
m?.coinType && i.add(m.coinType);
|
|
1599
|
+
s = u.cursor ?? u.nextCursor ?? null;
|
|
1593
1600
|
} while (s);
|
|
1594
|
-
for (const
|
|
1601
|
+
for (const u of i) {
|
|
1595
1602
|
let m = null;
|
|
1596
1603
|
do {
|
|
1597
|
-
const
|
|
1604
|
+
const w = await a.listCoins({
|
|
1598
1605
|
owner: e,
|
|
1599
|
-
coinType:
|
|
1606
|
+
coinType: u,
|
|
1600
1607
|
cursor: m,
|
|
1601
1608
|
limit: 100
|
|
1602
1609
|
});
|
|
1603
1610
|
o.push(
|
|
1604
|
-
...(
|
|
1605
|
-
), m =
|
|
1611
|
+
...(w.objects ?? w.data ?? []).map((y) => pe(y, u)).filter(Boolean)
|
|
1612
|
+
), m = w.cursor ?? w.nextCursor ?? null;
|
|
1606
1613
|
} while (m);
|
|
1607
1614
|
}
|
|
1608
1615
|
break;
|
|
@@ -1623,16 +1630,9 @@ async function ur(e, t) {
|
|
|
1623
1630
|
} while (r);
|
|
1624
1631
|
return o;
|
|
1625
1632
|
}
|
|
1626
|
-
const
|
|
1633
|
+
const Tt = $(
|
|
1627
1634
|
async (e, t) => {
|
|
1628
|
-
const r = [], o = (t?.markets || Object.keys(F)).map((i) => _(i))
|
|
1629
|
-
let n = [];
|
|
1630
|
-
try {
|
|
1631
|
-
n = await ke(e, t);
|
|
1632
|
-
} catch (i) {
|
|
1633
|
-
console.error(i);
|
|
1634
|
-
}
|
|
1635
|
-
const a = o.map((i) => ({
|
|
1635
|
+
const r = [], o = (t?.markets || Object.keys(F)).map((i) => _(i)), n = await ke(e, t), a = o.map((i) => ({
|
|
1636
1636
|
address: e,
|
|
1637
1637
|
market: i.key
|
|
1638
1638
|
})).concat(
|
|
@@ -1642,88 +1642,88 @@ const _t = $(
|
|
|
1642
1642
|
emodeId: i.emodeId
|
|
1643
1643
|
}))
|
|
1644
1644
|
);
|
|
1645
|
-
return (await
|
|
1646
|
-
const s = typeof i.emodeId == "number" ? n.find((
|
|
1645
|
+
return (await Te(e, a, t)).forEach((i) => {
|
|
1646
|
+
const s = typeof i.emodeId == "number" ? n.find((u) => {
|
|
1647
1647
|
const m = _(i.market);
|
|
1648
|
-
return
|
|
1648
|
+
return u.emodeId === i.emodeId && u.marketId === m.id;
|
|
1649
1649
|
}) : void 0;
|
|
1650
1650
|
if (s) {
|
|
1651
1651
|
if (!i.pool.emodes.find((m) => m.emodeId === s.emodeId))
|
|
1652
1652
|
return;
|
|
1653
1653
|
if (p(i.supplyBalance).gte(0)) {
|
|
1654
|
-
const m = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN),
|
|
1655
|
-
if (m.gt(0) ||
|
|
1654
|
+
const m = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = W(i.pool, s);
|
|
1655
|
+
if (m.gt(0) || w.emode.isCollateral)
|
|
1656
1656
|
try {
|
|
1657
1657
|
r.push({
|
|
1658
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${
|
|
1658
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${B()}`,
|
|
1659
1659
|
wallet: e,
|
|
1660
1660
|
protocol: "navi",
|
|
1661
1661
|
market: i.market,
|
|
1662
1662
|
type: "navi-lending-emode-supply",
|
|
1663
1663
|
"navi-lending-emode-supply": {
|
|
1664
1664
|
amount: m.toString(),
|
|
1665
|
-
pool:
|
|
1665
|
+
pool: W(i.pool, s),
|
|
1666
1666
|
token: i.pool.token,
|
|
1667
1667
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1668
1668
|
emodeCap: s
|
|
1669
1669
|
}
|
|
1670
1670
|
});
|
|
1671
|
-
} catch (
|
|
1672
|
-
console.error(
|
|
1671
|
+
} catch (y) {
|
|
1672
|
+
console.error(y);
|
|
1673
1673
|
}
|
|
1674
1674
|
}
|
|
1675
1675
|
if (p(i.borrowBalance).gte(0)) {
|
|
1676
|
-
const m = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN),
|
|
1677
|
-
if (m.gt(0) ||
|
|
1676
|
+
const m = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = W(i.pool, s);
|
|
1677
|
+
if (m.gt(0) || w.emode.isDebt)
|
|
1678
1678
|
try {
|
|
1679
1679
|
r.push({
|
|
1680
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${
|
|
1680
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${B()}`,
|
|
1681
1681
|
wallet: e,
|
|
1682
1682
|
protocol: "navi",
|
|
1683
1683
|
market: i.market,
|
|
1684
1684
|
type: "navi-lending-emode-borrow",
|
|
1685
1685
|
"navi-lending-emode-borrow": {
|
|
1686
1686
|
amount: m.toString(),
|
|
1687
|
-
pool:
|
|
1687
|
+
pool: W(i.pool, s),
|
|
1688
1688
|
token: i.pool.token,
|
|
1689
1689
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1690
1690
|
emodeCap: s
|
|
1691
1691
|
}
|
|
1692
1692
|
});
|
|
1693
|
-
} catch (
|
|
1694
|
-
console.error(
|
|
1693
|
+
} catch (y) {
|
|
1694
|
+
console.error(y);
|
|
1695
1695
|
}
|
|
1696
1696
|
}
|
|
1697
1697
|
} else {
|
|
1698
1698
|
if (p(i.supplyBalance).gt(0)) {
|
|
1699
|
-
const
|
|
1699
|
+
const u = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1700
1700
|
r.push({
|
|
1701
|
-
id: `${i.pool.uniqueId}_navi-lending-supply-${
|
|
1701
|
+
id: `${i.pool.uniqueId}_navi-lending-supply-${B()}`,
|
|
1702
1702
|
wallet: e,
|
|
1703
1703
|
protocol: "navi",
|
|
1704
1704
|
type: "navi-lending-supply",
|
|
1705
1705
|
market: i.market,
|
|
1706
1706
|
"navi-lending-supply": {
|
|
1707
|
-
amount:
|
|
1707
|
+
amount: u.toString(),
|
|
1708
1708
|
pool: i.pool,
|
|
1709
1709
|
token: i.pool.token,
|
|
1710
|
-
valueUSD:
|
|
1710
|
+
valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
|
|
1711
1711
|
}
|
|
1712
1712
|
});
|
|
1713
1713
|
}
|
|
1714
1714
|
if (p(i.borrowBalance).gt(0)) {
|
|
1715
|
-
const
|
|
1715
|
+
const u = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1716
1716
|
r.push({
|
|
1717
|
-
id: `${i.pool.uniqueId}_navi-lending-borrow-${
|
|
1717
|
+
id: `${i.pool.uniqueId}_navi-lending-borrow-${B()}`,
|
|
1718
1718
|
wallet: e,
|
|
1719
1719
|
protocol: "navi",
|
|
1720
1720
|
market: i.market,
|
|
1721
1721
|
type: "navi-lending-borrow",
|
|
1722
1722
|
"navi-lending-borrow": {
|
|
1723
|
-
amount:
|
|
1723
|
+
amount: u.toString(),
|
|
1724
1724
|
pool: i.pool,
|
|
1725
1725
|
token: i.pool.token,
|
|
1726
|
-
valueUSD:
|
|
1726
|
+
valueUSD: u.multipliedBy(i.pool.oracle.price).toString()
|
|
1727
1727
|
}
|
|
1728
1728
|
});
|
|
1729
1729
|
}
|
|
@@ -1731,7 +1731,7 @@ const _t = $(
|
|
|
1731
1731
|
}), r;
|
|
1732
1732
|
}
|
|
1733
1733
|
);
|
|
1734
|
-
class
|
|
1734
|
+
class q {
|
|
1735
1735
|
constructor(t, r) {
|
|
1736
1736
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1737
1737
|
hf: 1 / 0,
|
|
@@ -1771,7 +1771,7 @@ class L {
|
|
|
1771
1771
|
}
|
|
1772
1772
|
filterPositionsByPool(t) {
|
|
1773
1773
|
const o = !!t.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1774
|
-
return new
|
|
1774
|
+
return new q(
|
|
1775
1775
|
this.positions.filter((n) => {
|
|
1776
1776
|
const a = n[n.type];
|
|
1777
1777
|
return o.includes(n.type) && a.pool.uniqueId === t.uniqueId;
|
|
@@ -1783,7 +1783,7 @@ class L {
|
|
|
1783
1783
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1784
1784
|
let a;
|
|
1785
1785
|
return o ? a = {
|
|
1786
|
-
id:
|
|
1786
|
+
id: B(),
|
|
1787
1787
|
wallet: "",
|
|
1788
1788
|
protocol: "navi",
|
|
1789
1789
|
market: "",
|
|
@@ -1796,7 +1796,7 @@ class L {
|
|
|
1796
1796
|
emodeCap: {}
|
|
1797
1797
|
}
|
|
1798
1798
|
} : a = {
|
|
1799
|
-
id:
|
|
1799
|
+
id: B(),
|
|
1800
1800
|
wallet: "",
|
|
1801
1801
|
protocol: "navi",
|
|
1802
1802
|
market: "",
|
|
@@ -1807,13 +1807,13 @@ class L {
|
|
|
1807
1807
|
token: t.token,
|
|
1808
1808
|
pool: t
|
|
1809
1809
|
}
|
|
1810
|
-
}, new
|
|
1810
|
+
}, new q([...this.positions, a], this._priceMap);
|
|
1811
1811
|
}
|
|
1812
1812
|
withdraw(t, r) {
|
|
1813
1813
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1814
1814
|
let a;
|
|
1815
1815
|
return o ? a = {
|
|
1816
|
-
id:
|
|
1816
|
+
id: B(),
|
|
1817
1817
|
wallet: "",
|
|
1818
1818
|
protocol: "navi",
|
|
1819
1819
|
market: "",
|
|
@@ -1826,7 +1826,7 @@ class L {
|
|
|
1826
1826
|
emodeCap: {}
|
|
1827
1827
|
}
|
|
1828
1828
|
} : a = {
|
|
1829
|
-
id:
|
|
1829
|
+
id: B(),
|
|
1830
1830
|
wallet: "",
|
|
1831
1831
|
protocol: "navi",
|
|
1832
1832
|
market: "",
|
|
@@ -1837,13 +1837,13 @@ class L {
|
|
|
1837
1837
|
token: t.token,
|
|
1838
1838
|
pool: t
|
|
1839
1839
|
}
|
|
1840
|
-
}, new
|
|
1840
|
+
}, new q([...this.positions, a], this._priceMap);
|
|
1841
1841
|
}
|
|
1842
1842
|
borrow(t, r) {
|
|
1843
1843
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1844
1844
|
let a;
|
|
1845
1845
|
return o ? a = {
|
|
1846
|
-
id:
|
|
1846
|
+
id: B(),
|
|
1847
1847
|
wallet: "",
|
|
1848
1848
|
protocol: "navi",
|
|
1849
1849
|
market: "",
|
|
@@ -1856,7 +1856,7 @@ class L {
|
|
|
1856
1856
|
emodeCap: {}
|
|
1857
1857
|
}
|
|
1858
1858
|
} : a = {
|
|
1859
|
-
id:
|
|
1859
|
+
id: B(),
|
|
1860
1860
|
wallet: "",
|
|
1861
1861
|
protocol: "navi",
|
|
1862
1862
|
market: "",
|
|
@@ -1867,13 +1867,13 @@ class L {
|
|
|
1867
1867
|
token: t.token,
|
|
1868
1868
|
pool: t
|
|
1869
1869
|
}
|
|
1870
|
-
}, new
|
|
1870
|
+
}, new q([...this.positions, a], this._priceMap);
|
|
1871
1871
|
}
|
|
1872
1872
|
repay(t, r) {
|
|
1873
1873
|
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1874
1874
|
let a;
|
|
1875
1875
|
return o ? a = {
|
|
1876
|
-
id:
|
|
1876
|
+
id: B(),
|
|
1877
1877
|
wallet: "",
|
|
1878
1878
|
protocol: "navi",
|
|
1879
1879
|
market: "",
|
|
@@ -1886,7 +1886,7 @@ class L {
|
|
|
1886
1886
|
emodeCap: {}
|
|
1887
1887
|
}
|
|
1888
1888
|
} : a = {
|
|
1889
|
-
id:
|
|
1889
|
+
id: B(),
|
|
1890
1890
|
wallet: "",
|
|
1891
1891
|
protocol: "navi",
|
|
1892
1892
|
market: "",
|
|
@@ -1897,72 +1897,72 @@ class L {
|
|
|
1897
1897
|
token: t.token,
|
|
1898
1898
|
pool: t
|
|
1899
1899
|
}
|
|
1900
|
-
}, new
|
|
1900
|
+
}, new q([...this.positions, a], this._priceMap);
|
|
1901
1901
|
}
|
|
1902
1902
|
resolveValueUSD(t) {
|
|
1903
1903
|
return Object.keys(this._priceMap).length > 0 ? p(t.amount).multipliedBy(this.getPrice(t.pool)).toString() : t.valueUSD;
|
|
1904
1904
|
}
|
|
1905
1905
|
getPositionsOverview(t) {
|
|
1906
1906
|
const r = {}, o = {};
|
|
1907
|
-
let n = new p(0), a = new p(0), c = new p(0), i = new p(0), s = new p(0),
|
|
1908
|
-
t.forEach((
|
|
1909
|
-
if (
|
|
1910
|
-
const d =
|
|
1907
|
+
let n = new p(0), a = new p(0), c = new p(0), i = new p(0), s = new p(0), u = new p(0);
|
|
1908
|
+
t.forEach((g) => {
|
|
1909
|
+
if (g.type === "navi-lending-supply") {
|
|
1910
|
+
const d = g["navi-lending-supply"], f = this.resolveValueUSD(d);
|
|
1911
1911
|
n = n.plus(f), s = s.plus(
|
|
1912
1912
|
new p(f).multipliedBy(d.pool.liquidationFactor.threshold)
|
|
1913
|
-
),
|
|
1913
|
+
), u = u.plus(
|
|
1914
1914
|
new p(f).multipliedBy(d.pool.ltvValue)
|
|
1915
1915
|
);
|
|
1916
|
-
} else if (
|
|
1917
|
-
const d =
|
|
1916
|
+
} else if (g.type === "navi-lending-borrow") {
|
|
1917
|
+
const d = g["navi-lending-borrow"];
|
|
1918
1918
|
a = a.plus(this.resolveValueUSD(d));
|
|
1919
|
-
} else if (
|
|
1920
|
-
const d =
|
|
1919
|
+
} else if (g.type === "navi-lending-emode-supply") {
|
|
1920
|
+
const d = g["navi-lending-emode-supply"], f = this.resolveValueUSD(d);
|
|
1921
1921
|
n = n.plus(f);
|
|
1922
|
-
const
|
|
1922
|
+
const b = d.pool.emode;
|
|
1923
1923
|
s = s.plus(
|
|
1924
|
-
new p(f).multipliedBy(
|
|
1925
|
-
),
|
|
1926
|
-
new p(f).multipliedBy(
|
|
1924
|
+
new p(f).multipliedBy(b.lt)
|
|
1925
|
+
), u = u.plus(
|
|
1926
|
+
new p(f).multipliedBy(b.ltv)
|
|
1927
1927
|
);
|
|
1928
|
-
} else if (
|
|
1929
|
-
const d =
|
|
1928
|
+
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1929
|
+
const d = g["navi-lending-emode-borrow"];
|
|
1930
1930
|
a = a.plus(this.resolveValueUSD(d));
|
|
1931
1931
|
}
|
|
1932
|
-
}), a = p.max(a, 0), n = p.max(n, 0), s = p.max(s, 0),
|
|
1933
|
-
if (
|
|
1934
|
-
const d =
|
|
1932
|
+
}), a = p.max(a, 0), n = p.max(n, 0), s = p.max(s, 0), u = p.max(u, 0), t.forEach((g) => {
|
|
1933
|
+
if (g.type === "navi-lending-supply") {
|
|
1934
|
+
const d = g["navi-lending-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
|
|
1935
1935
|
n.gt(0) && (c = c.plus(
|
|
1936
|
-
new p(f).dividedBy(n).multipliedBy(new p(
|
|
1936
|
+
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1937
1937
|
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1938
|
-
} else if (
|
|
1939
|
-
const d =
|
|
1938
|
+
} else if (g.type === "navi-lending-borrow") {
|
|
1939
|
+
const d = g["navi-lending-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
|
|
1940
1940
|
a.gt(0) && (i = i.plus(
|
|
1941
|
-
new p(f).dividedBy(a).multipliedBy(new p(
|
|
1941
|
+
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1942
1942
|
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1943
|
-
} else if (
|
|
1944
|
-
const d =
|
|
1943
|
+
} else if (g.type === "navi-lending-emode-supply") {
|
|
1944
|
+
const d = g["navi-lending-emode-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
|
|
1945
1945
|
n.gt(0) && (c = c.plus(
|
|
1946
|
-
new p(f).dividedBy(n).multipliedBy(new p(
|
|
1946
|
+
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1947
1947
|
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1948
|
-
} else if (
|
|
1949
|
-
const d =
|
|
1948
|
+
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1949
|
+
const d = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
|
|
1950
1950
|
a.gt(0) && (i = i.plus(
|
|
1951
|
-
new p(f).dividedBy(a).multipliedBy(new p(
|
|
1951
|
+
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1952
1952
|
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1953
1953
|
}
|
|
1954
1954
|
});
|
|
1955
|
-
const m = n.minus(a),
|
|
1955
|
+
const m = n.minus(a), w = n.minus(a).eq(0) ? new p(0) : n.multipliedBy(c).minus(a.multipliedBy(i)).div(n.minus(a));
|
|
1956
1956
|
return {
|
|
1957
1957
|
hf: a.toNumber() !== 0 ? s.dividedBy(a).toNumber() : 1 / 0,
|
|
1958
1958
|
netVaule: m.toString(),
|
|
1959
|
-
netWorthApr:
|
|
1959
|
+
netWorthApr: w.toString(),
|
|
1960
1960
|
totalSupplyValue: n.toString(),
|
|
1961
1961
|
totalBorrowValue: a.toString(),
|
|
1962
1962
|
totalsupplyApy: c.toString(),
|
|
1963
1963
|
totalBorrowApy: i.toString(),
|
|
1964
1964
|
maxLiquidationValue: s.toString(),
|
|
1965
|
-
maxLoanToVaule:
|
|
1965
|
+
maxLoanToVaule: u.toString(),
|
|
1966
1966
|
supply: r,
|
|
1967
1967
|
borrow: o
|
|
1968
1968
|
};
|
|
@@ -1984,12 +1984,12 @@ async function dr(e, t, r, o) {
|
|
|
1984
1984
|
]
|
|
1985
1985
|
});
|
|
1986
1986
|
}
|
|
1987
|
-
const
|
|
1987
|
+
const Pe = new we("https://hermes.pyth.network", {
|
|
1988
1988
|
timeout: 1e4
|
|
1989
1989
|
});
|
|
1990
1990
|
async function pr(e) {
|
|
1991
1991
|
try {
|
|
1992
|
-
const t = [], r = await
|
|
1992
|
+
const t = [], r = await Pe.getLatestPriceFeeds(e);
|
|
1993
1993
|
if (!r) return t;
|
|
1994
1994
|
const o = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1995
1995
|
for (const n of r) {
|
|
@@ -2009,42 +2009,42 @@ async function pr(e) {
|
|
|
2009
2009
|
throw new Error(`failed to get pyth stale price feed id, msg: ${t.message}`);
|
|
2010
2010
|
}
|
|
2011
2011
|
}
|
|
2012
|
-
async function
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
continue;
|
|
2023
|
-
}
|
|
2024
|
-
const s = e.find((d) => d.priceInfoObject == i.objectId);
|
|
2025
|
-
if (!s) {
|
|
2026
|
-
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
2027
|
-
continue;
|
|
2028
|
-
}
|
|
2029
|
-
const l = i.content.fields.price_info.fields.price_feed.fields.price.fields, { magnitude: m, negative: g } = l.price.fields, b = l.conf, y = l.timestamp;
|
|
2030
|
-
r.push({
|
|
2031
|
-
priceFeedId: s.priceFeedId,
|
|
2032
|
-
priceInfoObject: s.priceInfoObject,
|
|
2033
|
-
price: g ? "-" + m : m,
|
|
2034
|
-
conf: b,
|
|
2035
|
-
publishTime: Number(y),
|
|
2036
|
-
expiration: s.expiration
|
|
2037
|
-
});
|
|
2012
|
+
async function Pt(e, t) {
|
|
2013
|
+
const r = [], o = V(t?.client, "getOnChainPriceInfo"), n = e.map((c) => c.priceInfoObject), a = await ft(o, {
|
|
2014
|
+
ids: Array.from(new Set(n)),
|
|
2015
|
+
options: { showContent: !0 }
|
|
2016
|
+
});
|
|
2017
|
+
for (const c of a) {
|
|
2018
|
+
const i = c.data;
|
|
2019
|
+
if (!i || !i.content || i.content.dataType !== "moveObject") {
|
|
2020
|
+
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
2021
|
+
continue;
|
|
2038
2022
|
}
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2023
|
+
const s = e.find((f) => f.priceInfoObject == i.objectId);
|
|
2024
|
+
if (!s) {
|
|
2025
|
+
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
2026
|
+
continue;
|
|
2027
|
+
}
|
|
2028
|
+
const u = i.content.fields?.price_info?.price_feed?.price, m = u?.price;
|
|
2029
|
+
if (!m) {
|
|
2030
|
+
console.warn(`unexpected pyth price struct, priceInfoObject: ${i.objectId}`);
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
const { magnitude: w, negative: y } = m, g = u.conf, d = u.timestamp;
|
|
2034
|
+
r.push({
|
|
2035
|
+
priceFeedId: s.priceFeedId,
|
|
2036
|
+
priceInfoObject: s.priceInfoObject,
|
|
2037
|
+
price: y ? "-" + w : w,
|
|
2038
|
+
conf: g,
|
|
2039
|
+
publishTime: Number(d),
|
|
2040
|
+
expiration: s.expiration
|
|
2041
|
+
});
|
|
2043
2042
|
}
|
|
2043
|
+
return r;
|
|
2044
2044
|
}
|
|
2045
2045
|
async function Bt(e, t) {
|
|
2046
2046
|
try {
|
|
2047
|
-
const r = [], o = await
|
|
2047
|
+
const r = [], o = await Pt(e, t);
|
|
2048
2048
|
if (!o) return r;
|
|
2049
2049
|
const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
2050
2050
|
for (const a of o) {
|
|
@@ -2064,14 +2064,14 @@ async function Bt(e, t) {
|
|
|
2064
2064
|
throw new Error(`failed to get pyth stale price feed id, msg: ${r.message}`);
|
|
2065
2065
|
}
|
|
2066
2066
|
}
|
|
2067
|
-
async function
|
|
2068
|
-
const o = r?.client
|
|
2067
|
+
async function At(e, t, r) {
|
|
2068
|
+
const o = V(r?.client, "updatePythPriceFeeds"), n = await j({
|
|
2069
2069
|
...r,
|
|
2070
2070
|
cacheTime: v
|
|
2071
2071
|
});
|
|
2072
2072
|
try {
|
|
2073
|
-
const a = await
|
|
2074
|
-
return await new
|
|
2073
|
+
const a = await Pe.getPriceFeedsUpdateData(t);
|
|
2074
|
+
return await new st(
|
|
2075
2075
|
o,
|
|
2076
2076
|
n.oracle.pythStateId,
|
|
2077
2077
|
n.oracle.wormholeStateId
|
|
@@ -2080,23 +2080,18 @@ async function Pt(e, t, r) {
|
|
|
2080
2080
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
2081
2081
|
}
|
|
2082
2082
|
}
|
|
2083
|
-
async function
|
|
2083
|
+
async function me(e, t, r) {
|
|
2084
2084
|
const o = await j({
|
|
2085
2085
|
...r,
|
|
2086
2086
|
cacheTime: v
|
|
2087
2087
|
});
|
|
2088
2088
|
if (r?.updatePythPriceFeeds) {
|
|
2089
|
-
const n = t.filter((
|
|
2090
|
-
priceFeedId:
|
|
2091
|
-
priceInfoObject:
|
|
2089
|
+
const n = t.filter((c) => !!c.pythPriceFeedId && !!c.pythPriceInfoObject).map((c) => ({
|
|
2090
|
+
priceFeedId: c.pythPriceFeedId,
|
|
2091
|
+
priceInfoObject: c.pythPriceInfoObject,
|
|
2092
2092
|
expiration: 30
|
|
2093
|
-
}));
|
|
2094
|
-
|
|
2095
|
-
const a = await Bt(n, r);
|
|
2096
|
-
a.length > 0 && await Pt(e, a, r);
|
|
2097
|
-
} catch {
|
|
2098
|
-
console.error("Failed to update Pyth price feeds");
|
|
2099
|
-
}
|
|
2093
|
+
})), a = await Bt(n, r);
|
|
2094
|
+
a.length > 0 && await At(e, a, r);
|
|
2100
2095
|
}
|
|
2101
2096
|
for (const n of t)
|
|
2102
2097
|
r?.env === "dev" ? e.moveCall({
|
|
@@ -2155,38 +2150,48 @@ function St(e, t) {
|
|
|
2155
2150
|
}) || t?.pools && t.pools.find((n) => r.oracleId === n.oracleId)));
|
|
2156
2151
|
}
|
|
2157
2152
|
async function mr(e, t, r, o) {
|
|
2153
|
+
let n;
|
|
2158
2154
|
try {
|
|
2159
|
-
const
|
|
2155
|
+
const a = await Be({
|
|
2160
2156
|
...o
|
|
2161
|
-
}),
|
|
2162
|
-
r.forEach((
|
|
2163
|
-
|
|
2157
|
+
}), c = [];
|
|
2158
|
+
r.forEach((u) => {
|
|
2159
|
+
c.includes(u.market) || c.push(u.market);
|
|
2164
2160
|
});
|
|
2165
|
-
const
|
|
2161
|
+
const i = await Tt(t, {
|
|
2166
2162
|
...o,
|
|
2167
|
-
markets:
|
|
2168
|
-
}), i = St(n, {
|
|
2169
|
-
lendingPositions: c,
|
|
2170
|
-
pools: r
|
|
2163
|
+
markets: c
|
|
2171
2164
|
});
|
|
2172
|
-
return
|
|
2165
|
+
return n = St(a, {
|
|
2166
|
+
lendingPositions: i,
|
|
2167
|
+
pools: r
|
|
2168
|
+
}), await me(e, n, {
|
|
2173
2169
|
updatePythPriceFeeds: !0,
|
|
2174
2170
|
...o
|
|
2175
2171
|
});
|
|
2176
|
-
} catch (
|
|
2172
|
+
} catch (a) {
|
|
2177
2173
|
if (o?.throws)
|
|
2178
|
-
throw
|
|
2179
|
-
|
|
2174
|
+
throw a;
|
|
2175
|
+
if (console.error(a), n)
|
|
2176
|
+
try {
|
|
2177
|
+
return await me(e, n, {
|
|
2178
|
+
...o,
|
|
2179
|
+
updatePythPriceFeeds: !1
|
|
2180
|
+
});
|
|
2181
|
+
} catch (c) {
|
|
2182
|
+
console.error(c);
|
|
2183
|
+
}
|
|
2184
|
+
return e;
|
|
2180
2185
|
}
|
|
2181
2186
|
}
|
|
2182
2187
|
const re = $(
|
|
2183
2188
|
A(
|
|
2184
2189
|
async (e) => {
|
|
2185
|
-
const t =
|
|
2186
|
-
`/navi/flashloan?env=${e?.env || "prod"}&sdk=${
|
|
2190
|
+
const t = O(e), r = M(
|
|
2191
|
+
`/navi/flashloan?env=${e?.env || "prod"}&sdk=${E.version}&market=${e?.market || R}`,
|
|
2187
2192
|
e
|
|
2188
2193
|
), o = await fetch(r, {
|
|
2189
|
-
headers: U
|
|
2194
|
+
headers: D(U, t)
|
|
2190
2195
|
}).then((n) => n.json());
|
|
2191
2196
|
return Object.keys(o.data).map((n) => ({
|
|
2192
2197
|
...o.data[n],
|
|
@@ -2211,7 +2216,7 @@ async function yr(e, t, r, o) {
|
|
|
2211
2216
|
))
|
|
2212
2217
|
throw new Error("Pool does not support flashloan");
|
|
2213
2218
|
if (n.version === 1) {
|
|
2214
|
-
const [s,
|
|
2219
|
+
const [s, u] = e.moveCall({
|
|
2215
2220
|
target: `${n.package}::lending::flash_loan_with_ctx`,
|
|
2216
2221
|
arguments: [
|
|
2217
2222
|
e.object(n.flashloanConfig),
|
|
@@ -2220,9 +2225,9 @@ async function yr(e, t, r, o) {
|
|
|
2220
2225
|
],
|
|
2221
2226
|
typeArguments: [a.suiCoinType]
|
|
2222
2227
|
});
|
|
2223
|
-
return [s,
|
|
2228
|
+
return [s, u];
|
|
2224
2229
|
} else {
|
|
2225
|
-
const [s,
|
|
2230
|
+
const [s, u] = e.moveCall({
|
|
2226
2231
|
target: `${n.package}::lending::flash_loan_with_ctx_v2`,
|
|
2227
2232
|
arguments: [
|
|
2228
2233
|
e.object(n.flashloanConfig),
|
|
@@ -2232,7 +2237,7 @@ async function yr(e, t, r, o) {
|
|
|
2232
2237
|
],
|
|
2233
2238
|
typeArguments: [a.suiCoinType]
|
|
2234
2239
|
});
|
|
2235
|
-
return [s,
|
|
2240
|
+
return [s, u];
|
|
2236
2241
|
}
|
|
2237
2242
|
}
|
|
2238
2243
|
async function gr(e, t, r, o, n) {
|
|
@@ -2247,7 +2252,7 @@ async function gr(e, t, r, o, n) {
|
|
|
2247
2252
|
(m) => C(m.coinType) === C(c.suiCoinType)
|
|
2248
2253
|
))
|
|
2249
2254
|
throw new Error("Pool does not support flashloan");
|
|
2250
|
-
const [
|
|
2255
|
+
const [u] = e.moveCall({
|
|
2251
2256
|
target: `${a.package}::lending::flash_repay_with_ctx`,
|
|
2252
2257
|
arguments: [
|
|
2253
2258
|
e.object("0x06"),
|
|
@@ -2258,15 +2263,15 @@ async function gr(e, t, r, o, n) {
|
|
|
2258
2263
|
],
|
|
2259
2264
|
typeArguments: [c.suiCoinType]
|
|
2260
2265
|
});
|
|
2261
|
-
return [
|
|
2266
|
+
return [u];
|
|
2262
2267
|
}
|
|
2263
2268
|
async function hr(e, t, r, o, n, a) {
|
|
2264
2269
|
const c = {
|
|
2265
2270
|
...a,
|
|
2266
2271
|
cacheTime: v
|
|
2267
|
-
}, i = await j(c), s = await S(t, c),
|
|
2272
|
+
}, i = await j(c), s = await S(t, c), u = await S(o, c);
|
|
2268
2273
|
if (i.version === 1) {
|
|
2269
|
-
const [m,
|
|
2274
|
+
const [m, w] = e.moveCall({
|
|
2270
2275
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
2271
2276
|
arguments: [
|
|
2272
2277
|
e.object("0x06"),
|
|
@@ -2281,9 +2286,9 @@ async function hr(e, t, r, o, n, a) {
|
|
|
2281
2286
|
// Pay asset pool contract
|
|
2282
2287
|
h(r, e.object),
|
|
2283
2288
|
// Debt repayment amount
|
|
2284
|
-
e.pure.u8(
|
|
2289
|
+
e.pure.u8(u.id),
|
|
2285
2290
|
// Collateral asset ID
|
|
2286
|
-
e.object(
|
|
2291
|
+
e.object(u.contract.pool),
|
|
2287
2292
|
// Collateral asset pool contract
|
|
2288
2293
|
h(n, e.pure.address),
|
|
2289
2294
|
// Borrower address
|
|
@@ -2292,11 +2297,11 @@ async function hr(e, t, r, o, n, a) {
|
|
|
2292
2297
|
e.object(i.incentiveV3)
|
|
2293
2298
|
// Incentive V3 contract
|
|
2294
2299
|
],
|
|
2295
|
-
typeArguments: [s.suiCoinType,
|
|
2300
|
+
typeArguments: [s.suiCoinType, u.suiCoinType]
|
|
2296
2301
|
});
|
|
2297
|
-
return [m,
|
|
2302
|
+
return [m, w];
|
|
2298
2303
|
} else {
|
|
2299
|
-
const [m,
|
|
2304
|
+
const [m, w] = e.moveCall({
|
|
2300
2305
|
target: `${i.package}::incentive_v3::liquidation_v2`,
|
|
2301
2306
|
arguments: [
|
|
2302
2307
|
e.object("0x06"),
|
|
@@ -2311,9 +2316,9 @@ async function hr(e, t, r, o, n, a) {
|
|
|
2311
2316
|
// Pay asset pool contract
|
|
2312
2317
|
h(r, e.object),
|
|
2313
2318
|
// Debt repayment amount
|
|
2314
|
-
e.pure.u8(
|
|
2319
|
+
e.pure.u8(u.id),
|
|
2315
2320
|
// Collateral asset ID
|
|
2316
|
-
e.object(
|
|
2321
|
+
e.object(u.contract.pool),
|
|
2317
2322
|
// Collateral asset pool contract
|
|
2318
2323
|
h(n, e.pure.address),
|
|
2319
2324
|
// Borrower address
|
|
@@ -2324,98 +2329,89 @@ async function hr(e, t, r, o, n, a) {
|
|
|
2324
2329
|
e.object("0x05")
|
|
2325
2330
|
// SuiSystemState object
|
|
2326
2331
|
],
|
|
2327
|
-
typeArguments: [s.suiCoinType,
|
|
2332
|
+
typeArguments: [s.suiCoinType, u.suiCoinType]
|
|
2328
2333
|
});
|
|
2329
|
-
return [m,
|
|
2334
|
+
return [m, w];
|
|
2330
2335
|
}
|
|
2331
2336
|
}
|
|
2332
2337
|
async function $t(e, t, r) {
|
|
2333
|
-
const o = r?.client
|
|
2338
|
+
const o = V(r?.client, "getLendingRewardsBatch"), n = await G({
|
|
2334
2339
|
...r,
|
|
2335
2340
|
markets: Object.values(F),
|
|
2336
2341
|
cacheTime: v
|
|
2337
|
-
}),
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
{
|
|
2366
|
-
|
|
2367
|
-
},
|
|
2368
|
-
[
|
|
2369
|
-
u.vector(u.string()),
|
|
2342
|
+
}), a = await Be(r), c = [];
|
|
2343
|
+
return await Promise.all(
|
|
2344
|
+
t.map(async (i) => {
|
|
2345
|
+
try {
|
|
2346
|
+
const s = await j({
|
|
2347
|
+
...r,
|
|
2348
|
+
cacheTime: v,
|
|
2349
|
+
market: i.market
|
|
2350
|
+
}), u = new N();
|
|
2351
|
+
u.moveCall({
|
|
2352
|
+
target: `${s.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
2353
|
+
arguments: [
|
|
2354
|
+
u.object("0x06"),
|
|
2355
|
+
// Clock object
|
|
2356
|
+
u.object(s.storage),
|
|
2357
|
+
// Protocol storage
|
|
2358
|
+
u.object(s.incentiveV3),
|
|
2359
|
+
// Incentive V3 contract
|
|
2360
|
+
u.pure.address(i.address)
|
|
2361
|
+
// User address
|
|
2362
|
+
]
|
|
2363
|
+
});
|
|
2364
|
+
const w = (await L(o, {
|
|
2365
|
+
transactionBlock: u,
|
|
2366
|
+
sender: e
|
|
2367
|
+
}))?.results?.[0];
|
|
2368
|
+
if (!w)
|
|
2369
|
+
return;
|
|
2370
|
+
const y = Q({ results: [w] }, [
|
|
2371
|
+
l.vector(l.string()),
|
|
2370
2372
|
// Asset coin types
|
|
2371
|
-
|
|
2373
|
+
l.vector(l.string()),
|
|
2372
2374
|
// Reward coin types
|
|
2373
|
-
|
|
2375
|
+
l.vector(l.u8()),
|
|
2374
2376
|
// Reward options
|
|
2375
|
-
|
|
2377
|
+
l.vector(l.Address),
|
|
2376
2378
|
// Rule IDs
|
|
2377
|
-
|
|
2379
|
+
l.vector(l.u256())
|
|
2378
2380
|
// Claimable amounts
|
|
2379
|
-
]
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2381
|
+
]);
|
|
2382
|
+
if (y.length === 5 && Array.isArray(y[0])) {
|
|
2383
|
+
const g = y[0].length;
|
|
2384
|
+
for (let d = 0; d < g; d++) {
|
|
2385
|
+
const f = a.find(
|
|
2386
|
+
(I) => C(I.coinType) === C(y[1][d])
|
|
2387
|
+
), b = n.find(
|
|
2388
|
+
(I) => C(I.coinType) === C(y[0][d]) && I.market === i.market
|
|
2389
|
+
);
|
|
2390
|
+
!f || !b || c.push({
|
|
2391
|
+
assetId: b.id,
|
|
2392
|
+
assetCoinType: C(y[0][d]),
|
|
2393
|
+
rewardCoinType: C(y[1][d]),
|
|
2394
|
+
option: Number(y[2][d]),
|
|
2395
|
+
userClaimableReward: Number(y[4][d]) / Math.pow(10, f.priceDecimal),
|
|
2396
|
+
ruleIds: Array.isArray(y[3][d]) ? y[3][d] : [y[3][d]],
|
|
2397
|
+
market: i.market,
|
|
2398
|
+
owner: i.owner,
|
|
2399
|
+
address: i.address,
|
|
2400
|
+
emodeId: i.emodeId
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
} catch (s) {
|
|
2405
|
+
console.error(
|
|
2406
|
+
`[lending] getLendingRewardsBatch task failed (market=${i.market}, address=${i.address}):`,
|
|
2407
|
+
s
|
|
2393
2408
|
);
|
|
2394
|
-
!f || !w || l.push({
|
|
2395
|
-
assetId: w.id,
|
|
2396
|
-
assetCoinType: C(m[0][d]),
|
|
2397
|
-
rewardCoinType: C(m[1][d]),
|
|
2398
|
-
option: Number(m[2][d]),
|
|
2399
|
-
userClaimableReward: Number(m[4][d]) / Math.pow(10, f.priceDecimal),
|
|
2400
|
-
ruleIds: Array.isArray(m[3][d]) ? m[3][d] : [m[3][d]],
|
|
2401
|
-
market: b.market,
|
|
2402
|
-
owner: b.owner,
|
|
2403
|
-
address: b.address,
|
|
2404
|
-
emodeId: b.emodeId
|
|
2405
|
-
});
|
|
2406
2409
|
}
|
|
2407
|
-
}
|
|
2408
|
-
|
|
2410
|
+
})
|
|
2411
|
+
), c;
|
|
2409
2412
|
}
|
|
2410
|
-
async function
|
|
2411
|
-
const r = (t?.markets || [F.main]).map((a) => _(a))
|
|
2412
|
-
let o = [];
|
|
2413
|
-
try {
|
|
2414
|
-
o = await ke(e, t);
|
|
2415
|
-
} catch (a) {
|
|
2416
|
-
console.error(a);
|
|
2417
|
-
}
|
|
2418
|
-
const n = r.map((a) => ({
|
|
2413
|
+
async function wr(e, t) {
|
|
2414
|
+
const r = (t?.markets || [F.main]).map((a) => _(a)), o = await ke(e, t), n = r.map((a) => ({
|
|
2419
2415
|
address: e,
|
|
2420
2416
|
owner: e,
|
|
2421
2417
|
market: a.key
|
|
@@ -2432,7 +2428,7 @@ async function br(e, t) {
|
|
|
2432
2428
|
);
|
|
2433
2429
|
return await $t(e, n, t);
|
|
2434
2430
|
}
|
|
2435
|
-
function
|
|
2431
|
+
function br(e) {
|
|
2436
2432
|
const t = /* @__PURE__ */ new Map();
|
|
2437
2433
|
e.forEach((o) => {
|
|
2438
2434
|
const n = o.assetId, a = o.option, c = `${n}-${a}-${o.rewardCoinType}-${o.market}`;
|
|
@@ -2448,8 +2444,8 @@ function wr(e) {
|
|
|
2448
2444
|
for (const { assetId: o, rewardType: n, coinType: a, total: c, market: i } of t.values()) {
|
|
2449
2445
|
const s = `${o}-${n}-${i}`;
|
|
2450
2446
|
r.has(s) || r.set(s, { assetId: o, rewardType: n, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
2451
|
-
const
|
|
2452
|
-
|
|
2447
|
+
const u = r.get(s);
|
|
2448
|
+
u.rewards.set(a, (u.rewards.get(a) || 0) + c);
|
|
2453
2449
|
}
|
|
2454
2450
|
return Array.from(r.values()).map((o) => ({
|
|
2455
2451
|
assetId: o.assetId,
|
|
@@ -2463,21 +2459,21 @@ function wr(e) {
|
|
|
2463
2459
|
}
|
|
2464
2460
|
const vr = A(
|
|
2465
2461
|
async (e, t) => {
|
|
2466
|
-
const r =
|
|
2467
|
-
`/navi/user/total_claimed_reward?userAddress=${e}&sdk=${
|
|
2462
|
+
const r = O(t), o = M(
|
|
2463
|
+
`/navi/user/total_claimed_reward?userAddress=${e}&sdk=${E.version}&market=${t?.market || R}`,
|
|
2468
2464
|
t
|
|
2469
2465
|
);
|
|
2470
2466
|
return (await fetch(o, {
|
|
2471
|
-
headers: U
|
|
2467
|
+
headers: D(U, r)
|
|
2472
2468
|
}).then((a) => a.json())).data;
|
|
2473
2469
|
}
|
|
2474
2470
|
), Cr = A(
|
|
2475
2471
|
async (e, t) => {
|
|
2476
|
-
const r =
|
|
2477
|
-
`/navi/user/rewards?userAddress=${e}&page=${t?.page || 1}&pageSize=${t?.size || 400}&sdk=${
|
|
2472
|
+
const r = O(t), o = M(
|
|
2473
|
+
`/navi/user/rewards?userAddress=${e}&page=${t?.page || 1}&pageSize=${t?.size || 400}&sdk=${E.version}&market=${t?.market || R}`,
|
|
2478
2474
|
t
|
|
2479
2475
|
), n = await fetch(o, {
|
|
2480
|
-
headers: U
|
|
2476
|
+
headers: D(U, r)
|
|
2481
2477
|
}).then((a) => a.json());
|
|
2482
2478
|
return x({
|
|
2483
2479
|
data: n.data.rewards
|
|
@@ -2491,42 +2487,42 @@ async function jr(e, t, r) {
|
|
|
2491
2487
|
cacheTime: v
|
|
2492
2488
|
}), n = /* @__PURE__ */ new Map();
|
|
2493
2489
|
for (const c of t) {
|
|
2494
|
-
const { rewardCoinType: i, ruleIds: s, market:
|
|
2490
|
+
const { rewardCoinType: i, ruleIds: s, market: u, owner: m, address: w, emodeId: y } = c, g = `${i}___${w}__${u}`;
|
|
2495
2491
|
for (const d of s) {
|
|
2496
|
-
n.has(
|
|
2492
|
+
n.has(g) || n.set(g, {
|
|
2497
2493
|
assetIds: [],
|
|
2498
2494
|
ruleIds: [],
|
|
2499
2495
|
amount: 0,
|
|
2500
|
-
market:
|
|
2496
|
+
market: u,
|
|
2501
2497
|
owner: m,
|
|
2502
|
-
address:
|
|
2503
|
-
isEMode: typeof
|
|
2498
|
+
address: w,
|
|
2499
|
+
isEMode: typeof y < "u"
|
|
2504
2500
|
});
|
|
2505
|
-
const f = n.get(
|
|
2501
|
+
const f = n.get(g);
|
|
2506
2502
|
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(d), f.amount += c.userClaimableReward;
|
|
2507
2503
|
}
|
|
2508
2504
|
}
|
|
2509
2505
|
const a = [];
|
|
2510
2506
|
for (const [
|
|
2511
2507
|
c,
|
|
2512
|
-
{ assetIds: i, ruleIds: s, amount:
|
|
2508
|
+
{ assetIds: i, ruleIds: s, amount: u, market: m, owner: w, address: y, isEMode: g }
|
|
2513
2509
|
] of n) {
|
|
2514
2510
|
const d = await j({
|
|
2515
2511
|
...r,
|
|
2516
2512
|
cacheTime: v,
|
|
2517
2513
|
market: m
|
|
2518
|
-
}), f = c.split("___")[0],
|
|
2519
|
-
(
|
|
2514
|
+
}), f = c.split("___")[0], b = o.filter(
|
|
2515
|
+
(k) => C(k.suiCoinType) === C(f)
|
|
2520
2516
|
);
|
|
2521
|
-
|
|
2522
|
-
const
|
|
2517
|
+
b.sort((k, P) => k.market === m ? -1 : 1);
|
|
2518
|
+
const I = b[0], T = d.rewardFunds[C(f)];
|
|
2523
2519
|
if (!T)
|
|
2524
2520
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${m}`);
|
|
2525
2521
|
if (r?.accountCap && !r.customCoinReceive)
|
|
2526
2522
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
2527
2523
|
if (r?.customCoinReceive) {
|
|
2528
|
-
let
|
|
2529
|
-
r.accountCap ?
|
|
2524
|
+
let k;
|
|
2525
|
+
r.accountCap ? k = e.moveCall({
|
|
2530
2526
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2531
2527
|
arguments: [
|
|
2532
2528
|
e.object("0x06"),
|
|
@@ -2545,7 +2541,7 @@ async function jr(e, t, r) {
|
|
|
2545
2541
|
// Account capability
|
|
2546
2542
|
],
|
|
2547
2543
|
typeArguments: [f]
|
|
2548
|
-
}) :
|
|
2544
|
+
}) : g ? k = e.moveCall({
|
|
2549
2545
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2550
2546
|
arguments: [
|
|
2551
2547
|
e.object("0x06"),
|
|
@@ -2560,11 +2556,11 @@ async function jr(e, t, r) {
|
|
|
2560
2556
|
// Asset IDs
|
|
2561
2557
|
e.pure.vector("address", s),
|
|
2562
2558
|
// Rule IDs
|
|
2563
|
-
h(
|
|
2559
|
+
h(y, e.object)
|
|
2564
2560
|
// Account capability
|
|
2565
2561
|
],
|
|
2566
2562
|
typeArguments: [f]
|
|
2567
|
-
}) :
|
|
2563
|
+
}) : k = e.moveCall({
|
|
2568
2564
|
target: `${d.package}::incentive_v3::claim_reward`,
|
|
2569
2565
|
arguments: [
|
|
2570
2566
|
e.object("0x06"),
|
|
@@ -2582,37 +2578,37 @@ async function jr(e, t, r) {
|
|
|
2582
2578
|
],
|
|
2583
2579
|
typeArguments: [f]
|
|
2584
2580
|
});
|
|
2585
|
-
const [
|
|
2581
|
+
const [P] = e.moveCall({
|
|
2586
2582
|
target: "0x2::coin::from_balance",
|
|
2587
|
-
arguments: [
|
|
2583
|
+
arguments: [k],
|
|
2588
2584
|
typeArguments: [f]
|
|
2589
2585
|
});
|
|
2590
2586
|
if (r?.customCoinReceive.type === "transfer") {
|
|
2591
2587
|
if (!r.customCoinReceive.transfer)
|
|
2592
2588
|
throw new Error("customCoinReceive.transfer is required");
|
|
2593
2589
|
e.transferObjects(
|
|
2594
|
-
[
|
|
2590
|
+
[P],
|
|
2595
2591
|
h(r.customCoinReceive.transfer, e.pure.address)
|
|
2596
2592
|
);
|
|
2597
2593
|
}
|
|
2598
2594
|
if (r?.customCoinReceive.type === "depositNAVI") {
|
|
2599
|
-
const
|
|
2600
|
-
|
|
2601
|
-
[
|
|
2595
|
+
const H = p(I.totalSupplyAmount).shiftedBy(-9), Y = p(I.supplyCapCeiling).shiftedBy(-27);
|
|
2596
|
+
H.plus(u).isGreaterThan(Y) && r?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
2597
|
+
[P],
|
|
2602
2598
|
e.pure.address(r.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
2603
|
-
) : await
|
|
2599
|
+
) : await wt(e, I, P, {
|
|
2604
2600
|
...r,
|
|
2605
|
-
market:
|
|
2601
|
+
market: I.market
|
|
2606
2602
|
});
|
|
2607
2603
|
} else
|
|
2608
2604
|
a.push({
|
|
2609
|
-
coin:
|
|
2610
|
-
identifier:
|
|
2611
|
-
owner:
|
|
2612
|
-
isEMode:
|
|
2605
|
+
coin: P,
|
|
2606
|
+
identifier: I,
|
|
2607
|
+
owner: w,
|
|
2608
|
+
isEMode: g
|
|
2613
2609
|
});
|
|
2614
|
-
} else if (r?.accountCap ||
|
|
2615
|
-
const
|
|
2610
|
+
} else if (r?.accountCap || g) {
|
|
2611
|
+
const k = e.moveCall({
|
|
2616
2612
|
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2617
2613
|
arguments: [
|
|
2618
2614
|
e.object("0x06"),
|
|
@@ -2627,18 +2623,18 @@ async function jr(e, t, r) {
|
|
|
2627
2623
|
// Asset IDs
|
|
2628
2624
|
e.pure.vector("address", s),
|
|
2629
2625
|
// Rule IDs
|
|
2630
|
-
h(r?.accountCap ||
|
|
2626
|
+
h(r?.accountCap || y, e.object)
|
|
2631
2627
|
// Account capability
|
|
2632
2628
|
],
|
|
2633
2629
|
typeArguments: [f]
|
|
2634
|
-
}), [
|
|
2630
|
+
}), [P] = e.moveCall({
|
|
2635
2631
|
target: "0x2::coin::from_balance",
|
|
2636
|
-
arguments: [
|
|
2632
|
+
arguments: [k],
|
|
2637
2633
|
typeArguments: [f]
|
|
2638
2634
|
});
|
|
2639
2635
|
e.transferObjects(
|
|
2640
|
-
[
|
|
2641
|
-
h(r?.accountCap ||
|
|
2636
|
+
[P],
|
|
2637
|
+
h(r?.accountCap || w, e.pure.address)
|
|
2642
2638
|
);
|
|
2643
2639
|
} else
|
|
2644
2640
|
e.moveCall({
|
|
@@ -2668,78 +2664,78 @@ export {
|
|
|
2668
2664
|
R as DEFAULT_MARKET_IDENTITY,
|
|
2669
2665
|
zt as FlashLoanAssetConfig,
|
|
2670
2666
|
Rt as IncentiveAPYInfo,
|
|
2671
|
-
|
|
2672
|
-
|
|
2667
|
+
Re as IncentivePoolInfo,
|
|
2668
|
+
qt as IncentivePoolInfoByPhase,
|
|
2673
2669
|
F as MARKETS,
|
|
2674
2670
|
bt as Market,
|
|
2675
|
-
|
|
2676
|
-
|
|
2671
|
+
Je as NaviMissingGraphQLClientError,
|
|
2672
|
+
Lt as OracleInfo,
|
|
2677
2673
|
z as PoolOperator,
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2674
|
+
qe as ReserveDataInfo,
|
|
2675
|
+
we as SuiPriceServiceConnection,
|
|
2676
|
+
st as SuiPythClient,
|
|
2677
|
+
q as UserPositions,
|
|
2682
2678
|
Le as UserStateInfo,
|
|
2683
2679
|
Xt as borrowCoinPTB,
|
|
2684
2680
|
M as buildNaviOpenApiUrl,
|
|
2685
2681
|
jr as claimLendingRewardsPTB,
|
|
2686
2682
|
Kt as configureNaviSdk,
|
|
2687
|
-
|
|
2683
|
+
Ct as createAccountCapPTB,
|
|
2688
2684
|
nr as createEModeCapPTB,
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2685
|
+
he as createNaviLegacyJsonRpcClient,
|
|
2686
|
+
et as createNaviSuiClient,
|
|
2687
|
+
Xe as createNaviSuiClientBundle,
|
|
2688
|
+
wt as depositCoinPTB,
|
|
2693
2689
|
or as emodeIdentityId,
|
|
2694
|
-
|
|
2690
|
+
It as enterEModePTB,
|
|
2695
2691
|
rr as exitEModePTB,
|
|
2696
2692
|
St as filterPriceFeeds,
|
|
2697
2693
|
yr as flashloanPTB,
|
|
2698
|
-
|
|
2699
|
-
|
|
2694
|
+
jt as getAccountCapOwnerPTB,
|
|
2695
|
+
Ht as getAddressBalance,
|
|
2700
2696
|
re as getAllFlashLoanAssets,
|
|
2701
2697
|
er as getBorrowFee,
|
|
2702
2698
|
Gt as getCoinObjectOnlyBalance,
|
|
2703
|
-
|
|
2699
|
+
lr as getCoins,
|
|
2704
2700
|
j as getConfig,
|
|
2705
2701
|
Yt as getFees,
|
|
2706
2702
|
fr as getFlashLoanAsset,
|
|
2707
2703
|
cr as getHealthFactor,
|
|
2708
|
-
|
|
2709
|
-
|
|
2704
|
+
_t as getHealthFactorPTB,
|
|
2705
|
+
Tt as getLendingPositions,
|
|
2710
2706
|
ir as getLendingState,
|
|
2711
2707
|
tr as getMarket,
|
|
2712
2708
|
_ as getMarketConfig,
|
|
2713
|
-
|
|
2709
|
+
vt as getMarkets,
|
|
2714
2710
|
S as getPool,
|
|
2715
2711
|
G as getPools,
|
|
2716
2712
|
Be as getPriceFeeds,
|
|
2717
2713
|
pr as getPythStalePriceFeedId,
|
|
2718
2714
|
Bt as getPythStalePriceFeedIdV2,
|
|
2719
2715
|
sr as getSimulatedHealthFactor,
|
|
2720
|
-
|
|
2716
|
+
_e as getSimulatedHealthFactorPTB,
|
|
2721
2717
|
Qt as getStats,
|
|
2722
|
-
|
|
2723
|
-
|
|
2718
|
+
ur as getTransactions,
|
|
2719
|
+
wr as getUserAvailableLendingRewards,
|
|
2724
2720
|
Cr as getUserClaimedRewardHistory,
|
|
2725
2721
|
ke as getUserEModeCaps,
|
|
2726
2722
|
vr as getUserTotalClaimedReward,
|
|
2727
2723
|
hr as liquidatePTB,
|
|
2728
|
-
|
|
2724
|
+
Wt as listAddressBalances,
|
|
2729
2725
|
ar as mergeCoinsPTB,
|
|
2730
|
-
|
|
2731
|
-
|
|
2726
|
+
D as mergeServiceHeaders,
|
|
2727
|
+
ge as normalizeAddressBalance,
|
|
2732
2728
|
C as normalizeCoinType,
|
|
2733
|
-
|
|
2729
|
+
ht as parsePoolUID,
|
|
2734
2730
|
h as parseTxValue,
|
|
2735
2731
|
xt as repayCoinPTB,
|
|
2736
2732
|
gr as repayFlashLoanPTB,
|
|
2737
2733
|
Jt as requireNaviGraphQLClient,
|
|
2738
|
-
|
|
2739
|
-
|
|
2734
|
+
O as resolveNaviOpenApiEndpoint,
|
|
2735
|
+
br as summaryLendingRewards,
|
|
2740
2736
|
mr as updateOraclePriceBeforeUserOperationPTB,
|
|
2741
|
-
|
|
2742
|
-
|
|
2737
|
+
me as updateOraclePricesPTB,
|
|
2738
|
+
At as updatePythPriceFeeds,
|
|
2743
2739
|
dr as verifyHealthFactorPTB,
|
|
2744
2740
|
$ as withCache,
|
|
2745
2741
|
A as withSingleton,
|