@naviprotocol/lending 2.0.0-beta.0 → 2.0.0
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 +2 -2
- package/dist/account.d.ts.map +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/flashloan.d.ts +5 -5
- package/dist/flashloan.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1510 -1064
- package/dist/index.esm.js.map +1 -1
- package/dist/liquidate.d.ts +2 -2
- package/dist/liquidate.d.ts.map +1 -1
- package/dist/oracle.d.ts +3 -3
- package/dist/oracle.d.ts.map +1 -1
- package/dist/pool.d.ts +9 -9
- package/dist/pool.d.ts.map +1 -1
- package/dist/pyth.d.ts +6 -1
- package/dist/pyth.d.ts.map +1 -1
- package/dist/reward.d.ts +5 -5
- package/dist/reward.d.ts.map +1 -1
- package/dist/services.d.ts +22 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/sui.d.ts +106 -2
- package/dist/sui.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +15 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/index.esm.js
CHANGED
|
@@ -1,183 +1,330 @@
|
|
|
1
|
-
import { Transaction as
|
|
2
|
-
import { bcs as
|
|
3
|
-
import { toHex as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { Transaction as N } from "@mysten/sui/transactions";
|
|
2
|
+
import { bcs as u } from "@mysten/sui/bcs";
|
|
3
|
+
import { toHex as $e, fromHex as Oe, normalizeStructTag as K, SUI_CLOCK_OBJECT_ID as Z, fromBase64 as Ee } from "@mysten/sui/utils";
|
|
4
|
+
import Ve from "lodash.camelcase";
|
|
5
|
+
import p from "bignumber.js";
|
|
6
|
+
import { SuiJsonRpcClient as Me } from "@mysten/sui/jsonRpc";
|
|
7
|
+
import { SuiGraphQLClient as De } from "@mysten/sui/graphql";
|
|
8
|
+
import { GrpcWebFetchTransport as Ue, SuiGrpcClient as Fe } from "@mysten/sui/grpc";
|
|
9
|
+
const ne = u.bytes(32).transform({
|
|
8
10
|
// To change the input type, you need to provide a type definition for the input
|
|
9
|
-
input: (e) =>
|
|
10
|
-
output: (e) =>
|
|
11
|
-
}),
|
|
11
|
+
input: (e) => Oe(e),
|
|
12
|
+
output: (e) => $e(e)
|
|
13
|
+
}), Rt = u.struct("IncentiveAPYInfo", {
|
|
12
14
|
/** Asset identifier */
|
|
13
|
-
asset_id:
|
|
15
|
+
asset_id: u.u8(),
|
|
14
16
|
/** Annual Percentage Yield as a 256-bit integer */
|
|
15
|
-
apy:
|
|
17
|
+
apy: u.u256(),
|
|
16
18
|
/** List of supported coin types for this incentive */
|
|
17
|
-
coin_types:
|
|
18
|
-
}),
|
|
19
|
+
coin_types: u.vector(u.string())
|
|
20
|
+
}), Ne = u.struct("IncentivePoolInfo", {
|
|
19
21
|
/** Unique pool identifier */
|
|
20
|
-
pool_id:
|
|
22
|
+
pool_id: ne,
|
|
21
23
|
/** Address holding the incentive funds */
|
|
22
|
-
funds:
|
|
24
|
+
funds: ne,
|
|
23
25
|
/** Current phase of the incentive program */
|
|
24
|
-
phase:
|
|
26
|
+
phase: u.u64(),
|
|
25
27
|
/** Timestamp when the incentive started */
|
|
26
|
-
start_at:
|
|
28
|
+
start_at: u.u64(),
|
|
27
29
|
/** Timestamp when the incentive ends */
|
|
28
|
-
end_at:
|
|
30
|
+
end_at: u.u64(),
|
|
29
31
|
/** Timestamp when the incentive was closed */
|
|
30
|
-
closed_at:
|
|
32
|
+
closed_at: u.u64(),
|
|
31
33
|
/** Total supply of incentive tokens */
|
|
32
|
-
total_supply:
|
|
34
|
+
total_supply: u.u64(),
|
|
33
35
|
/** Asset identifier for the incentive */
|
|
34
|
-
asset_id:
|
|
36
|
+
asset_id: u.u8(),
|
|
35
37
|
/** Option type for the incentive */
|
|
36
|
-
option:
|
|
38
|
+
option: u.u8(),
|
|
37
39
|
/** Factor used in incentive calculations */
|
|
38
|
-
factor:
|
|
40
|
+
factor: u.u256(),
|
|
39
41
|
/** Amount of incentives already distributed */
|
|
40
|
-
distributed:
|
|
42
|
+
distributed: u.u64(),
|
|
41
43
|
/** Amount of incentives currently available */
|
|
42
|
-
available:
|
|
44
|
+
available: u.u256(),
|
|
43
45
|
/** Total amount of incentives */
|
|
44
|
-
total:
|
|
45
|
-
}),
|
|
46
|
+
total: u.u256()
|
|
47
|
+
}), Lt = u.struct("IncentivePoolInfoByPhase", {
|
|
46
48
|
/** Phase number */
|
|
47
|
-
phase:
|
|
49
|
+
phase: u.u64(),
|
|
48
50
|
/** List of incentive pools in this phase */
|
|
49
|
-
pools:
|
|
50
|
-
}),
|
|
51
|
+
pools: u.vector(Ne)
|
|
52
|
+
}), qt = u.struct("OracleInfo", {
|
|
51
53
|
/** Oracle identifier */
|
|
52
|
-
oracle_id:
|
|
54
|
+
oracle_id: u.u8(),
|
|
53
55
|
/** Current price as a 256-bit integer */
|
|
54
|
-
price:
|
|
56
|
+
price: u.u256(),
|
|
55
57
|
/** Number of decimal places for the price */
|
|
56
|
-
decimals:
|
|
58
|
+
decimals: u.u8(),
|
|
57
59
|
/** Whether the oracle data is valid */
|
|
58
|
-
valid:
|
|
59
|
-
}),
|
|
60
|
+
valid: u.bool()
|
|
61
|
+
}), zt = u.struct("FlashLoanAssetConfig", {
|
|
60
62
|
/** Unique identifier for the flash loan asset */
|
|
61
|
-
id:
|
|
63
|
+
id: u.string(),
|
|
62
64
|
/** Asset identifier */
|
|
63
|
-
asset_id:
|
|
65
|
+
asset_id: u.u8(),
|
|
64
66
|
/** Coin type for the asset */
|
|
65
|
-
coin_type:
|
|
67
|
+
coin_type: u.string(),
|
|
66
68
|
/** Pool identifier for the flash loan */
|
|
67
|
-
pool_id:
|
|
69
|
+
pool_id: u.string(),
|
|
68
70
|
/** Rate paid to suppliers for flash loans */
|
|
69
|
-
rate_to_supplier:
|
|
71
|
+
rate_to_supplier: u.u64(),
|
|
70
72
|
/** Rate paid to treasury for flash loans */
|
|
71
|
-
rate_to_treasury:
|
|
73
|
+
rate_to_treasury: u.u64(),
|
|
72
74
|
/** Maximum flash loan amount */
|
|
73
|
-
max:
|
|
75
|
+
max: u.u64(),
|
|
74
76
|
/** Minimum flash loan amount */
|
|
75
|
-
min:
|
|
76
|
-
}),
|
|
77
|
+
min: u.u64()
|
|
78
|
+
}), Re = u.struct("ReserveDataInfo", {
|
|
77
79
|
/** Reserve identifier */
|
|
78
|
-
id:
|
|
80
|
+
id: u.u8(),
|
|
79
81
|
/** Oracle identifier for price feeds */
|
|
80
|
-
oracle_id:
|
|
82
|
+
oracle_id: u.u8(),
|
|
81
83
|
/** Coin type for the reserve */
|
|
82
|
-
coin_type:
|
|
84
|
+
coin_type: u.string(),
|
|
83
85
|
/** Maximum supply capacity */
|
|
84
|
-
supply_cap:
|
|
86
|
+
supply_cap: u.u256(),
|
|
85
87
|
/** Maximum borrow capacity */
|
|
86
|
-
borrow_cap:
|
|
88
|
+
borrow_cap: u.u256(),
|
|
87
89
|
/** Current supply interest rate */
|
|
88
|
-
supply_rate:
|
|
90
|
+
supply_rate: u.u256(),
|
|
89
91
|
/** Current borrow interest rate */
|
|
90
|
-
borrow_rate:
|
|
92
|
+
borrow_rate: u.u256(),
|
|
91
93
|
/** Current supply index for interest calculation */
|
|
92
|
-
supply_index:
|
|
94
|
+
supply_index: u.u256(),
|
|
93
95
|
/** Current borrow index for interest calculation */
|
|
94
|
-
borrow_index:
|
|
96
|
+
borrow_index: u.u256(),
|
|
95
97
|
/** Total amount supplied to the reserve */
|
|
96
|
-
total_supply:
|
|
98
|
+
total_supply: u.u256(),
|
|
97
99
|
/** Total amount borrowed from the reserve */
|
|
98
|
-
total_borrow:
|
|
100
|
+
total_borrow: u.u256(),
|
|
99
101
|
/** Timestamp of last update */
|
|
100
|
-
last_update_at:
|
|
102
|
+
last_update_at: u.u64(),
|
|
101
103
|
/** Loan-to-Value ratio for collateral */
|
|
102
|
-
ltv:
|
|
104
|
+
ltv: u.u256(),
|
|
103
105
|
/** Treasury factor for fee calculations */
|
|
104
|
-
treasury_factor:
|
|
106
|
+
treasury_factor: u.u256(),
|
|
105
107
|
/** Current treasury balance */
|
|
106
|
-
treasury_balance:
|
|
108
|
+
treasury_balance: u.u256(),
|
|
107
109
|
/** Base interest rate */
|
|
108
|
-
base_rate:
|
|
110
|
+
base_rate: u.u256(),
|
|
109
111
|
/** Interest rate multiplier */
|
|
110
|
-
multiplier:
|
|
112
|
+
multiplier: u.u256(),
|
|
111
113
|
/** Jump rate multiplier for high utilization */
|
|
112
|
-
jump_rate_multiplier:
|
|
114
|
+
jump_rate_multiplier: u.u256(),
|
|
113
115
|
/** Reserve factor for protocol fees */
|
|
114
|
-
reserve_factor:
|
|
116
|
+
reserve_factor: u.u256(),
|
|
115
117
|
/** Optimal utilization rate */
|
|
116
|
-
optimal_utilization:
|
|
118
|
+
optimal_utilization: u.u256(),
|
|
117
119
|
/** Liquidation ratio threshold */
|
|
118
|
-
liquidation_ratio:
|
|
120
|
+
liquidation_ratio: u.u256(),
|
|
119
121
|
/** Liquidation bonus for liquidators */
|
|
120
|
-
liquidation_bonus:
|
|
122
|
+
liquidation_bonus: u.u256(),
|
|
121
123
|
/** Liquidation threshold */
|
|
122
|
-
liquidation_threshold:
|
|
123
|
-
}),
|
|
124
|
+
liquidation_threshold: u.u256()
|
|
125
|
+
}), Le = u.struct("UserStateInfo", {
|
|
124
126
|
/** Asset identifier */
|
|
125
|
-
asset_id:
|
|
127
|
+
asset_id: u.u8(),
|
|
126
128
|
/** User's current borrow balance */
|
|
127
|
-
borrow_balance:
|
|
129
|
+
borrow_balance: u.u256(),
|
|
128
130
|
/** User's current supply balance */
|
|
129
|
-
supply_balance:
|
|
130
|
-
}),
|
|
131
|
-
version:
|
|
132
|
-
},
|
|
131
|
+
supply_balance: u.u256()
|
|
132
|
+
}), qe = "2.0.0", O = {
|
|
133
|
+
version: qe
|
|
134
|
+
}, ze = O.version, Ge = () => {
|
|
133
135
|
if (typeof process < "u" && process.versions && process.versions.node) {
|
|
134
136
|
const e = process.version;
|
|
135
137
|
return `Node.js ${e.startsWith("v") ? e.substring(1) : e}`;
|
|
136
138
|
}
|
|
137
139
|
return "Node/Unknown";
|
|
138
|
-
},
|
|
140
|
+
}, We = () => {
|
|
139
141
|
let e = "";
|
|
140
|
-
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
return typeof process < "u" && process.versions && process.versions.node && (e = `lending/${ze} (${Ge()})`), e;
|
|
143
|
+
}, oe = We(), me = "0x2::sui::SUI";
|
|
144
|
+
class He extends Error {
|
|
145
|
+
constructor(t) {
|
|
146
|
+
super(
|
|
147
|
+
`NAVI Sui SDK capability "${t}" requires an explicit graphql client; no public GraphQL fallback is configured`
|
|
148
|
+
), this.name = "NaviMissingGraphQLClientError";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function X(e) {
|
|
152
|
+
return e == null ? void 0 : String(e);
|
|
153
|
+
}
|
|
154
|
+
function Je(e, t) {
|
|
155
|
+
return (BigInt(e) + BigInt(t)).toString();
|
|
156
|
+
}
|
|
157
|
+
function Ke(e, t) {
|
|
158
|
+
return (BigInt(e) - BigInt(t)).toString();
|
|
159
|
+
}
|
|
160
|
+
function fe(e) {
|
|
161
|
+
const t = e.core;
|
|
162
|
+
if (typeof t?.getBalance != "function" || typeof t?.listBalances != "function")
|
|
163
|
+
throw new Error("NAVI Sui balance helpers require a v2 Core API client");
|
|
164
|
+
return t;
|
|
165
|
+
}
|
|
166
|
+
function ye(e, t = me) {
|
|
167
|
+
const r = X(e.addressBalance ?? e.fundsInAddressBalance) ?? "0";
|
|
168
|
+
let o = X(e.balance ?? e.totalBalance), n = X(e.coinBalance);
|
|
169
|
+
return !n && o && (n = Ke(o, r)), !o && n && (o = Je(n, r)), {
|
|
170
|
+
coinType: K(e.coinType ?? t),
|
|
171
|
+
totalBalance: o ?? "0",
|
|
172
|
+
coinBalance: n ?? "0",
|
|
173
|
+
addressBalance: r,
|
|
174
|
+
...e.coinObjectCount === null || e.coinObjectCount === void 0 ? {} : { coinObjectCount: e.coinObjectCount }
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function Gt(e, t = me) {
|
|
178
|
+
const r = K(t);
|
|
179
|
+
return e.filter((o) => K(o.coinType) === r).reduce((o, n) => o + BigInt(n.balance), 0n).toString();
|
|
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
|
+
async function Ht(e, t) {
|
|
186
|
+
const r = await fe(e).listBalances(t), { balances: o = [] } = r;
|
|
187
|
+
return {
|
|
188
|
+
balances: o.map((n) => ye(n)),
|
|
189
|
+
nextCursor: r.nextCursor ?? r.cursor ?? null
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function Qe(e, t) {
|
|
193
|
+
if ("client" in t)
|
|
194
|
+
return t.client;
|
|
195
|
+
const r = new Ue({
|
|
196
|
+
baseUrl: t.url,
|
|
197
|
+
meta: t.headers,
|
|
198
|
+
fetchInit: t.fetchInit,
|
|
199
|
+
fetch: t.fetch
|
|
200
|
+
});
|
|
201
|
+
return new Fe({
|
|
202
|
+
network: e,
|
|
203
|
+
transport: r
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function Ye(e, t) {
|
|
207
|
+
return "client" in t ? t.client : new De({
|
|
208
|
+
network: e,
|
|
209
|
+
url: t.url,
|
|
210
|
+
headers: t.headers,
|
|
211
|
+
fetch: t.fetch
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function ge(e, t) {
|
|
215
|
+
return "client" in t ? t.client : new Me({
|
|
216
|
+
network: e,
|
|
217
|
+
url: t.url
|
|
146
218
|
});
|
|
147
219
|
}
|
|
148
|
-
|
|
149
|
-
|
|
220
|
+
function Ze(e) {
|
|
221
|
+
const t = Qe(e.network, e.grpc);
|
|
222
|
+
return {
|
|
223
|
+
network: e.network,
|
|
224
|
+
coreClient: t,
|
|
225
|
+
grpc: t,
|
|
226
|
+
graphql: e.graphql ? Ye(e.network, e.graphql) : void 0,
|
|
227
|
+
legacyJsonRpc: e.legacyJsonRpc ? ge(e.network, e.legacyJsonRpc) : void 0,
|
|
228
|
+
services: e.services
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function Jt(e, t) {
|
|
232
|
+
if (!e.graphql)
|
|
233
|
+
throw new He(t);
|
|
234
|
+
return e.graphql;
|
|
235
|
+
}
|
|
236
|
+
function Xe() {
|
|
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
|
+
{},
|
|
239
|
+
{
|
|
240
|
+
get() {
|
|
241
|
+
throw new Error(e);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
);
|
|
245
|
+
return new Proxy(
|
|
246
|
+
{ core: t },
|
|
247
|
+
{
|
|
248
|
+
get(r, o) {
|
|
249
|
+
if (o === "core")
|
|
250
|
+
return r.core;
|
|
251
|
+
if (o === "network")
|
|
252
|
+
return "mainnet";
|
|
253
|
+
throw new Error(e);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
function xe(e, t = "mainnet") {
|
|
259
|
+
return e ? typeof e == "string" ? ge(t, { url: e }) : Ze(e) : Xe();
|
|
260
|
+
}
|
|
261
|
+
const et = 16 * 1024;
|
|
262
|
+
function te(e) {
|
|
150
263
|
return e.replace(/^0x/i, "");
|
|
151
264
|
}
|
|
152
|
-
function
|
|
153
|
-
const t =
|
|
154
|
-
for (let
|
|
155
|
-
r[
|
|
265
|
+
function ae(e) {
|
|
266
|
+
const t = te(e), r = new Uint8Array(t.length / 2);
|
|
267
|
+
for (let o = 0; o < r.length; o += 1)
|
|
268
|
+
r[o] = parseInt(t.slice(o * 2, o * 2 + 2), 16);
|
|
156
269
|
return r;
|
|
157
270
|
}
|
|
158
|
-
function
|
|
271
|
+
function tt(e, t) {
|
|
159
272
|
return (e[t] << 8) + e[t + 1];
|
|
160
273
|
}
|
|
161
|
-
function
|
|
162
|
-
return
|
|
163
|
-
maxSize:
|
|
274
|
+
function ie(e) {
|
|
275
|
+
return u.vector(u.U8).serialize(Array.from(e), {
|
|
276
|
+
maxSize: et
|
|
164
277
|
});
|
|
165
278
|
}
|
|
166
|
-
function
|
|
279
|
+
function ce(e, t) {
|
|
280
|
+
return {
|
|
281
|
+
type: e,
|
|
282
|
+
bcs: t
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
function rt(e) {
|
|
286
|
+
return u.vector(u.U8).serialize(Array.from(new TextEncoder().encode(e))).toBytes();
|
|
287
|
+
}
|
|
288
|
+
function nt(e) {
|
|
289
|
+
return u.struct("PriceIdentifier", {
|
|
290
|
+
bytes: u.vector(u.U8)
|
|
291
|
+
}).serialize({
|
|
292
|
+
bytes: Array.from(e)
|
|
293
|
+
}).toBytes();
|
|
294
|
+
}
|
|
295
|
+
function ot(e) {
|
|
296
|
+
const t = [];
|
|
297
|
+
let r = 0, o = 0;
|
|
298
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
299
|
+
const a = e[n];
|
|
300
|
+
a === "<" ? r += 1 : a === ">" ? r -= 1 : a === "," && r === 0 && (t.push(e.slice(o, n).trim()), o = n + 1);
|
|
301
|
+
}
|
|
302
|
+
return t.push(e.slice(o).trim()), t;
|
|
303
|
+
}
|
|
304
|
+
function at(e) {
|
|
305
|
+
const r = e.indexOf("::table::Table"), o = e.indexOf("<", r), n = e.lastIndexOf(">"), a = "::price_identifier::PriceIdentifier";
|
|
306
|
+
if (r < 0 || o < 0 || n <= o)
|
|
307
|
+
throw new Error(`Unexpected Pyth price table type: ${e}`);
|
|
308
|
+
const [c, i] = ot(e.slice(o + 1, n));
|
|
309
|
+
if (!c?.endsWith(a) || !i?.endsWith("::object::ID"))
|
|
310
|
+
throw new Error(`Unexpected Pyth price table type arguments: ${e}`);
|
|
311
|
+
return c.slice(0, -a.length);
|
|
312
|
+
}
|
|
313
|
+
function it(e) {
|
|
167
314
|
return Uint8Array.from(atob(e), (t) => t.charCodeAt(0));
|
|
168
315
|
}
|
|
169
|
-
class
|
|
316
|
+
class he {
|
|
170
317
|
constructor(t, r) {
|
|
171
318
|
this.endpoint = t.replace(/\/$/, ""), this.timeout = r?.timeout ?? 1e4;
|
|
172
319
|
}
|
|
173
320
|
async getLatestPriceFeeds(t) {
|
|
174
|
-
return (await this.get("/api/latest_price_feeds", t)).map((
|
|
175
|
-
id:
|
|
321
|
+
return (await this.get("/api/latest_price_feeds", t)).map((o) => ({
|
|
322
|
+
id: o.id,
|
|
176
323
|
getPriceUnchecked: () => ({
|
|
177
|
-
price:
|
|
178
|
-
conf:
|
|
179
|
-
expo:
|
|
180
|
-
publishTime:
|
|
324
|
+
price: o.price.price,
|
|
325
|
+
conf: o.price.conf,
|
|
326
|
+
expo: o.price.expo,
|
|
327
|
+
publishTime: o.price.publish_time
|
|
181
328
|
})
|
|
182
329
|
}));
|
|
183
330
|
}
|
|
@@ -189,22 +336,22 @@ class te {
|
|
|
189
336
|
encoding: "base64",
|
|
190
337
|
parsed: "false"
|
|
191
338
|
}
|
|
192
|
-
),
|
|
193
|
-
if (
|
|
194
|
-
throw new Error(`Unsupported Hermes price update encoding: ${
|
|
195
|
-
if (
|
|
339
|
+
), o = r.binary?.encoding, n = r.binary?.data ?? [];
|
|
340
|
+
if (o && o !== "base64")
|
|
341
|
+
throw new Error(`Unsupported Hermes price update encoding: ${o}`);
|
|
342
|
+
if (n.length === 0)
|
|
196
343
|
throw new Error("Hermes price update response did not include binary update data");
|
|
197
|
-
return
|
|
344
|
+
return n.map(it);
|
|
198
345
|
}
|
|
199
|
-
async get(t, r,
|
|
200
|
-
const
|
|
201
|
-
for (const [i, s] of Object.entries(
|
|
346
|
+
async get(t, r, o) {
|
|
347
|
+
const n = new AbortController(), a = setTimeout(() => n.abort(), this.timeout), c = new URL(`${this.endpoint}${t}`);
|
|
348
|
+
for (const [i, s] of Object.entries(o ?? {}))
|
|
202
349
|
c.searchParams.set(i, s);
|
|
203
350
|
for (const i of r)
|
|
204
|
-
c.searchParams.append("ids[]",
|
|
351
|
+
c.searchParams.append("ids[]", te(i));
|
|
205
352
|
try {
|
|
206
353
|
const i = await fetch(c, {
|
|
207
|
-
signal:
|
|
354
|
+
signal: n.signal
|
|
208
355
|
});
|
|
209
356
|
if (!i.ok)
|
|
210
357
|
throw new Error(`Hermes request failed: ${i.status} ${i.statusText}`);
|
|
@@ -214,91 +361,147 @@ class te {
|
|
|
214
361
|
}
|
|
215
362
|
}
|
|
216
363
|
}
|
|
217
|
-
class
|
|
218
|
-
constructor(t, r,
|
|
219
|
-
this.provider = t, this.pythStateId = r, this.wormholeStateId =
|
|
364
|
+
class ct {
|
|
365
|
+
constructor(t, r, o) {
|
|
366
|
+
this.provider = t, this.pythStateId = r, this.wormholeStateId = o, this.priceFeedObjectIdCache = /* @__PURE__ */ new Map();
|
|
367
|
+
}
|
|
368
|
+
getCoreProvider() {
|
|
369
|
+
const t = this.provider.core;
|
|
370
|
+
return t && typeof t.getObject == "function" && typeof t.getDynamicObjectField == "function" ? t : null;
|
|
371
|
+
}
|
|
372
|
+
async getMoveObjectJson(t) {
|
|
373
|
+
const r = this.getCoreProvider();
|
|
374
|
+
if (r) {
|
|
375
|
+
const n = await r.getObject({
|
|
376
|
+
objectId: t,
|
|
377
|
+
include: { json: !0 }
|
|
378
|
+
});
|
|
379
|
+
return n.object ? {
|
|
380
|
+
objectId: n.object.objectId,
|
|
381
|
+
type: n.object.type,
|
|
382
|
+
fields: n.object.json
|
|
383
|
+
} : null;
|
|
384
|
+
}
|
|
385
|
+
if (!this.provider.getObject)
|
|
386
|
+
throw new Error("Sui Pyth provider does not support getObject");
|
|
387
|
+
const o = await this.provider.getObject({
|
|
388
|
+
id: t,
|
|
389
|
+
options: { showContent: !0 }
|
|
390
|
+
});
|
|
391
|
+
return !o.data || !o.data.content || o.data.content.dataType !== "moveObject" ? null : {
|
|
392
|
+
objectId: o.data.objectId,
|
|
393
|
+
type: o.data.type,
|
|
394
|
+
fields: o.data.content.fields
|
|
395
|
+
};
|
|
220
396
|
}
|
|
221
|
-
async
|
|
222
|
-
const o =
|
|
397
|
+
async getDynamicMoveObjectJson(t, r) {
|
|
398
|
+
const o = this.getCoreProvider();
|
|
399
|
+
if (o) {
|
|
400
|
+
const a = await o.getDynamicObjectField({
|
|
401
|
+
parentId: t,
|
|
402
|
+
name: r,
|
|
403
|
+
include: { json: !0 }
|
|
404
|
+
});
|
|
405
|
+
return a.object ? {
|
|
406
|
+
objectId: a.object.objectId,
|
|
407
|
+
type: a.object.type,
|
|
408
|
+
fields: a.object.json
|
|
409
|
+
} : null;
|
|
410
|
+
}
|
|
411
|
+
if (!this.provider.getDynamicFieldObject)
|
|
412
|
+
throw new Error("Sui Pyth provider does not support getDynamicFieldObject");
|
|
413
|
+
const n = await this.provider.getDynamicFieldObject({
|
|
414
|
+
parentId: t,
|
|
415
|
+
name: r
|
|
416
|
+
});
|
|
417
|
+
return n.data ? n.data.content ? n.data.content.dataType !== "moveObject" ? null : {
|
|
418
|
+
objectId: n.data.objectId,
|
|
419
|
+
type: n.data.type,
|
|
420
|
+
fields: n.data.content.fields
|
|
421
|
+
} : {
|
|
422
|
+
objectId: n.data.objectId,
|
|
423
|
+
type: n.data.type,
|
|
424
|
+
fields: void 0
|
|
425
|
+
} : null;
|
|
426
|
+
}
|
|
427
|
+
async updatePriceFeeds(t, r, o) {
|
|
428
|
+
const n = await this.getPythPackageId(), a = await this.verifyVaasAndGetHotPotato(t, r, n), c = await this.getBaseUpdateFee(), i = t.splitCoins(
|
|
223
429
|
t.gas,
|
|
224
|
-
|
|
430
|
+
o.map(() => t.pure.u64(c))
|
|
225
431
|
);
|
|
226
|
-
return this.executePriceFeedUpdates(t,
|
|
432
|
+
return this.executePriceFeedUpdates(t, n, o, a, i);
|
|
227
433
|
}
|
|
228
434
|
async getBaseUpdateFee() {
|
|
229
435
|
if (this.baseUpdateFee === void 0) {
|
|
230
|
-
const t = await this.
|
|
231
|
-
|
|
232
|
-
options: { showContent: !0 }
|
|
233
|
-
});
|
|
234
|
-
if (!t.data || !t.data.content || t.data.content.dataType !== "moveObject")
|
|
436
|
+
const t = await this.getMoveObjectJson(this.pythStateId);
|
|
437
|
+
if (!t?.fields)
|
|
235
438
|
throw new Error("Unable to fetch pyth state object");
|
|
236
|
-
this.baseUpdateFee = Number(t.
|
|
439
|
+
this.baseUpdateFee = Number(t.fields.base_update_fee);
|
|
237
440
|
}
|
|
238
441
|
return this.baseUpdateFee;
|
|
239
442
|
}
|
|
240
443
|
async getPackageId(t) {
|
|
241
|
-
const r = await this.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
444
|
+
const r = await this.getMoveObjectJson(t);
|
|
445
|
+
if (r?.fields) {
|
|
446
|
+
const o = r.fields;
|
|
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
|
+
}
|
|
249
452
|
}
|
|
250
453
|
throw new Error(`Cannot fetch package id for object ${t}`);
|
|
251
454
|
}
|
|
252
455
|
async verifyVaas(t, r) {
|
|
253
|
-
const
|
|
254
|
-
return t.map((
|
|
456
|
+
const o = await this.getWormholePackageId();
|
|
457
|
+
return t.map((n) => {
|
|
255
458
|
const [a] = r.moveCall({
|
|
256
|
-
target: `${
|
|
459
|
+
target: `${o}::vaa::parse_and_verify`,
|
|
257
460
|
arguments: [
|
|
258
461
|
r.object(this.wormholeStateId),
|
|
259
|
-
r.pure(
|
|
260
|
-
r.object(
|
|
462
|
+
r.pure(ie(n)),
|
|
463
|
+
r.object(Z)
|
|
261
464
|
]
|
|
262
465
|
});
|
|
263
466
|
return a;
|
|
264
467
|
});
|
|
265
468
|
}
|
|
266
|
-
async verifyVaasAndGetHotPotato(t, r,
|
|
469
|
+
async verifyVaasAndGetHotPotato(t, r, o) {
|
|
267
470
|
if (r.length > 1)
|
|
268
471
|
throw new Error(
|
|
269
472
|
"SDK does not support sending multiple accumulator messages in a single transaction"
|
|
270
473
|
);
|
|
271
|
-
const
|
|
272
|
-
target: `${
|
|
474
|
+
const n = this.extractVaaBytesFromAccumulatorMessage(r[0]), [a] = await this.verifyVaas([n], t), [c] = t.moveCall({
|
|
475
|
+
target: `${o}::pyth::create_authenticated_price_infos_using_accumulator`,
|
|
273
476
|
arguments: [
|
|
274
477
|
t.object(this.pythStateId),
|
|
275
|
-
t.pure(
|
|
478
|
+
t.pure(ie(r[0])),
|
|
276
479
|
a,
|
|
277
|
-
t.object(
|
|
480
|
+
t.object(Z)
|
|
278
481
|
]
|
|
279
482
|
});
|
|
280
483
|
return c;
|
|
281
484
|
}
|
|
282
|
-
async executePriceFeedUpdates(t, r,
|
|
485
|
+
async executePriceFeedUpdates(t, r, o, n, a) {
|
|
283
486
|
const c = [];
|
|
284
|
-
for (const [i, s] of
|
|
285
|
-
const
|
|
286
|
-
if (!
|
|
487
|
+
for (const [i, s] of o.entries()) {
|
|
488
|
+
const l = await this.getPriceFeedObjectId(s);
|
|
489
|
+
if (!l)
|
|
287
490
|
throw new Error(`Price feed ${s} not found, please create it first`);
|
|
288
|
-
c.push(
|
|
491
|
+
c.push(l), [n] = t.moveCall({
|
|
289
492
|
target: `${r}::pyth::update_single_price_feed`,
|
|
290
493
|
arguments: [
|
|
291
494
|
t.object(this.pythStateId),
|
|
292
|
-
|
|
293
|
-
t.object(
|
|
495
|
+
n,
|
|
496
|
+
t.object(l),
|
|
294
497
|
a[i],
|
|
295
|
-
t.object(
|
|
498
|
+
t.object(Z)
|
|
296
499
|
]
|
|
297
500
|
});
|
|
298
501
|
}
|
|
299
502
|
return t.moveCall({
|
|
300
503
|
target: `${r}::hot_potato_vector::destroy`,
|
|
301
|
-
arguments: [
|
|
504
|
+
arguments: [n],
|
|
302
505
|
typeArguments: [`${r}::price_info::PriceInfo`]
|
|
303
506
|
}), c;
|
|
304
507
|
}
|
|
@@ -309,337 +512,473 @@ class $e {
|
|
|
309
512
|
return this.pythPackageId || (this.pythPackageId = await this.getPackageId(this.pythStateId)), this.pythPackageId;
|
|
310
513
|
}
|
|
311
514
|
async getPriceFeedObjectId(t) {
|
|
312
|
-
const r =
|
|
515
|
+
const r = te(t);
|
|
313
516
|
if (!this.priceFeedObjectIdCache.has(r)) {
|
|
314
|
-
const { id:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
517
|
+
const { id: o, fieldType: n } = await this.getPriceTableInfo(), a = this.getCoreProvider() ? ce(
|
|
518
|
+
`${n}::price_identifier::PriceIdentifier`,
|
|
519
|
+
nt(ae(r))
|
|
520
|
+
) : {
|
|
521
|
+
type: `${n}::price_identifier::PriceIdentifier`,
|
|
522
|
+
value: {
|
|
523
|
+
bytes: Array.from(ae(r))
|
|
321
524
|
}
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
this.priceFeedObjectIdCache.set(r, void 0);
|
|
325
|
-
else {
|
|
326
|
-
if (a.data.content.dataType !== "moveObject")
|
|
327
|
-
throw new Error("Price feed type mismatch");
|
|
328
|
-
this.priceFeedObjectIdCache.set(r, a.data.content.fields.value);
|
|
329
|
-
}
|
|
525
|
+
}, c = await this.getDynamicMoveObjectJson(o, a);
|
|
526
|
+
c?.fields ? this.priceFeedObjectIdCache.set(r, c.fields.value) : this.priceFeedObjectIdCache.set(r, void 0);
|
|
330
527
|
}
|
|
331
528
|
return this.priceFeedObjectIdCache.get(r);
|
|
332
529
|
}
|
|
333
530
|
async getPriceTableInfo() {
|
|
334
531
|
if (!this.priceTableInfo) {
|
|
335
|
-
const t =
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
if (!t.data || !t.data.type)
|
|
532
|
+
const t = this.getCoreProvider() ? ce("vector<u8>", rt("price_info")) : {
|
|
533
|
+
type: "vector<u8>",
|
|
534
|
+
value: "price_info"
|
|
535
|
+
}, r = await this.getDynamicMoveObjectJson(this.pythStateId, t);
|
|
536
|
+
if (!r?.type)
|
|
343
537
|
throw new Error("Price Table not found, contract may not be initialized");
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
fieldType: r
|
|
538
|
+
this.priceTableInfo = {
|
|
539
|
+
id: r.objectId,
|
|
540
|
+
fieldType: at(r.type)
|
|
348
541
|
};
|
|
349
542
|
}
|
|
350
543
|
return this.priceTableInfo;
|
|
351
544
|
}
|
|
352
545
|
extractVaaBytesFromAccumulatorMessage(t) {
|
|
353
|
-
const
|
|
354
|
-
return t.subarray(a, a +
|
|
546
|
+
const o = 7 + t[6] + 1, n = tt(t, o), a = o + 2;
|
|
547
|
+
return t.subarray(a, a + n);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const st = "https://open-api.naviprotocol.io/api";
|
|
551
|
+
let J = {}, we = 0;
|
|
552
|
+
function lt(e) {
|
|
553
|
+
return e.replace(/\/+$/, "");
|
|
554
|
+
}
|
|
555
|
+
function Kt(e) {
|
|
556
|
+
J = {
|
|
557
|
+
...J,
|
|
558
|
+
...e,
|
|
559
|
+
services: {
|
|
560
|
+
...J.services,
|
|
561
|
+
...e.services
|
|
562
|
+
}
|
|
563
|
+
}, we += 1;
|
|
564
|
+
}
|
|
565
|
+
function se() {
|
|
566
|
+
return we;
|
|
567
|
+
}
|
|
568
|
+
function E(e) {
|
|
569
|
+
const t = e?.services?.naviOpenApi ?? J.services?.naviOpenApi;
|
|
570
|
+
return {
|
|
571
|
+
baseUrl: lt(t?.baseUrl ?? st),
|
|
572
|
+
headers: t?.headers
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
function M(e, t) {
|
|
576
|
+
const r = E(t), o = e.startsWith("/") ? e : `/${e}`;
|
|
577
|
+
return `${r.baseUrl}${o}`;
|
|
578
|
+
}
|
|
579
|
+
function ut(e) {
|
|
580
|
+
if (e instanceof Headers) {
|
|
581
|
+
const t = {};
|
|
582
|
+
return e.forEach((r, o) => {
|
|
583
|
+
t[o] = r;
|
|
584
|
+
}), t;
|
|
585
|
+
}
|
|
586
|
+
return Array.isArray(e) ? Object.fromEntries(e) : e;
|
|
587
|
+
}
|
|
588
|
+
function D(e, t) {
|
|
589
|
+
return {
|
|
590
|
+
...ut(e),
|
|
591
|
+
...t?.headers ?? {}
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
const V = xe();
|
|
595
|
+
function le(e) {
|
|
596
|
+
return e ? e instanceof Uint8Array ? Array.from(e) : Array.isArray(e) ? e : Array.from(Ee(e)) : [];
|
|
597
|
+
}
|
|
598
|
+
function dt(e) {
|
|
599
|
+
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];
|
|
600
|
+
return o && console.warn("[lending] devInspect(core simulate) returned error:", o), {
|
|
601
|
+
effects: r.effects,
|
|
602
|
+
events: r.events,
|
|
603
|
+
error: o,
|
|
604
|
+
results: t.map((n) => ({
|
|
605
|
+
returnValues: (n.returnValues ?? []).map((a) => [le(a.bcs), ""]),
|
|
606
|
+
mutableReferenceOutputs: (n.mutatedReferences ?? []).map((a) => [
|
|
607
|
+
"",
|
|
608
|
+
le(a.bcs),
|
|
609
|
+
""
|
|
610
|
+
])
|
|
611
|
+
}))
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
async function q(e, t) {
|
|
615
|
+
const r = e?.core;
|
|
616
|
+
if (typeof r?.simulateTransaction == "function") {
|
|
617
|
+
const o = t.transaction ?? t.transactionBlock;
|
|
618
|
+
o instanceof N && o.setSenderIfNotSet(t.sender);
|
|
619
|
+
const n = await r.simulateTransaction({
|
|
620
|
+
transaction: o,
|
|
621
|
+
checksEnabled: !1,
|
|
622
|
+
include: {
|
|
623
|
+
effects: !0,
|
|
624
|
+
events: !0,
|
|
625
|
+
commandResults: !0
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
return dt(n);
|
|
629
|
+
}
|
|
630
|
+
return e.devInspectTransactionBlock({
|
|
631
|
+
transactionBlock: t.transactionBlock ?? t.transaction,
|
|
632
|
+
sender: t.sender
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
function be(e) {
|
|
636
|
+
return {
|
|
637
|
+
json: !!e?.showContent,
|
|
638
|
+
display: !!e?.showDisplay,
|
|
639
|
+
previousTransaction: !!e?.showPreviousTransaction,
|
|
640
|
+
objectBcs: !!e?.showBcs
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function ve(e) {
|
|
644
|
+
return !e || e instanceof Error ? {
|
|
645
|
+
error: e instanceof Error ? { code: "notFound", error: e.message } : void 0
|
|
646
|
+
} : {
|
|
647
|
+
data: {
|
|
648
|
+
objectId: e.objectId,
|
|
649
|
+
version: e.version,
|
|
650
|
+
digest: e.digest,
|
|
651
|
+
type: e.type,
|
|
652
|
+
owner: e.owner,
|
|
653
|
+
previousTransaction: e.previousTransaction,
|
|
654
|
+
content: e.json === void 0 ? void 0 : {
|
|
655
|
+
dataType: "moveObject",
|
|
656
|
+
type: e.type,
|
|
657
|
+
fields: e.json
|
|
658
|
+
},
|
|
659
|
+
display: e.display
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
async function pt(e, t) {
|
|
664
|
+
const r = e?.core;
|
|
665
|
+
if (typeof r?.getObject == "function") {
|
|
666
|
+
const { object: o } = await r.getObject({
|
|
667
|
+
objectId: t.id,
|
|
668
|
+
include: be(t.options)
|
|
669
|
+
});
|
|
670
|
+
return ve(o);
|
|
671
|
+
}
|
|
672
|
+
return e.getObject(t);
|
|
673
|
+
}
|
|
674
|
+
async function mt(e, t) {
|
|
675
|
+
const r = e?.core;
|
|
676
|
+
if (typeof r?.getObjects == "function") {
|
|
677
|
+
const { objects: o } = await r.getObjects({
|
|
678
|
+
objectIds: t.ids,
|
|
679
|
+
include: be(t.options)
|
|
680
|
+
});
|
|
681
|
+
return o.map(ve);
|
|
355
682
|
}
|
|
683
|
+
return e.multiGetObjects(t);
|
|
356
684
|
}
|
|
357
|
-
|
|
358
|
-
function oe(e) {
|
|
685
|
+
function Ce(e) {
|
|
359
686
|
const t = [];
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
687
|
+
let r = !1;
|
|
688
|
+
return e.forEach((o, n) => {
|
|
689
|
+
const a = n === e.length - 1;
|
|
690
|
+
if (typeof o == "object" && o !== null && a) {
|
|
691
|
+
const { client: c, disableCache: i, cacheTime: s, ...l } = o;
|
|
692
|
+
l.__naviSdkServiceConfigVersion = se(), t.push(l), r = !0;
|
|
365
693
|
} else
|
|
366
|
-
t.push(
|
|
694
|
+
t.push(o);
|
|
695
|
+
}), r || t.push({
|
|
696
|
+
__naviSdkServiceConfigVersion: se()
|
|
367
697
|
}), JSON.stringify(t);
|
|
368
698
|
}
|
|
369
699
|
function A(e) {
|
|
370
700
|
const t = {};
|
|
371
701
|
return (...r) => {
|
|
372
|
-
const
|
|
373
|
-
return t[
|
|
374
|
-
delete t[
|
|
375
|
-
})), t[
|
|
702
|
+
const o = Ce(r);
|
|
703
|
+
return t[o] || (t[o] = e(...r).finally(() => {
|
|
704
|
+
delete t[o];
|
|
705
|
+
})), t[o];
|
|
376
706
|
};
|
|
377
707
|
}
|
|
378
|
-
function
|
|
708
|
+
function $(e) {
|
|
379
709
|
let t = {};
|
|
380
710
|
return (...r) => {
|
|
381
|
-
const
|
|
382
|
-
return !
|
|
711
|
+
const o = r[r.length - 1], n = Ce(r), a = t[n];
|
|
712
|
+
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] = {
|
|
383
713
|
data: c,
|
|
384
714
|
cacheAt: Date.now()
|
|
385
715
|
}, c));
|
|
386
716
|
};
|
|
387
717
|
}
|
|
388
|
-
function
|
|
389
|
-
return Array.isArray(e) ? e.map((t) =>
|
|
718
|
+
function x(e) {
|
|
719
|
+
return Array.isArray(e) ? e.map((t) => x(t)) : e != null && typeof e == "object" ? Object.keys(e).reduce(
|
|
390
720
|
(t, r) => ({
|
|
391
721
|
...t,
|
|
392
|
-
[
|
|
722
|
+
[Ve(r)]: x(e[r])
|
|
393
723
|
}),
|
|
394
724
|
{}
|
|
395
725
|
) : e;
|
|
396
726
|
}
|
|
397
|
-
function
|
|
398
|
-
if (
|
|
727
|
+
function h(e, t) {
|
|
728
|
+
if (e == null)
|
|
399
729
|
throw new Error("Transaction value is required");
|
|
400
730
|
return typeof e == "object" ? e : t(e);
|
|
401
731
|
}
|
|
402
|
-
function
|
|
732
|
+
function ft(e, t) {
|
|
403
733
|
return typeof t == "string" ? e.object(t) : typeof t == "object" && t.$kind ? t : e.object(t.contract.pool);
|
|
404
734
|
}
|
|
405
|
-
function
|
|
735
|
+
function Q(e, t, r) {
|
|
406
736
|
if (e.results && e.results.length > 0) {
|
|
407
737
|
if (e.results[0].returnValues && e.results[0].returnValues.length > 0)
|
|
408
|
-
return e.results[0].returnValues.map((
|
|
738
|
+
return e.results[0].returnValues.map((o, n) => (t[n] || t[0]).parse(Uint8Array.from(o[0])));
|
|
409
739
|
} else if (e.error)
|
|
410
740
|
return console.log(`Get an error, msg: ${e.error}`), [];
|
|
411
741
|
return [];
|
|
412
742
|
}
|
|
413
|
-
function
|
|
414
|
-
return
|
|
743
|
+
function C(e) {
|
|
744
|
+
return K(e);
|
|
415
745
|
}
|
|
416
|
-
function
|
|
746
|
+
function je(e) {
|
|
417
747
|
const t = (e || 0) / Math.pow(10, 27);
|
|
418
748
|
return t > Math.pow(10, 5) ? 1 / 0 : t;
|
|
419
749
|
}
|
|
420
|
-
new
|
|
750
|
+
new he("https://hermes.pyth.network", {
|
|
421
751
|
timeout: 2e4
|
|
422
752
|
});
|
|
423
|
-
const
|
|
424
|
-
if (!Number(e) || !Number(t)) return new
|
|
425
|
-
const r = new
|
|
426
|
-
return new
|
|
427
|
-
},
|
|
428
|
-
"User-Agent":
|
|
753
|
+
const yt = 27, ue = (e, t) => {
|
|
754
|
+
if (!Number(e) || !Number(t)) return new p(0);
|
|
755
|
+
const r = new p(1).shiftedBy(1 * yt), o = r.multipliedBy(new p(0.5));
|
|
756
|
+
return new p(e).multipliedBy(new p(t)).plus(o).dividedBy(r).integerValue(p.ROUND_DOWN);
|
|
757
|
+
}, U = oe ? {
|
|
758
|
+
"User-Agent": oe
|
|
429
759
|
} : {};
|
|
430
|
-
function
|
|
760
|
+
function ee(e, t = "uniqueId") {
|
|
431
761
|
return e.reduce(
|
|
432
|
-
(r,
|
|
762
|
+
(r, o) => (r[o[t]] = o, r),
|
|
433
763
|
{}
|
|
434
764
|
);
|
|
435
765
|
}
|
|
436
|
-
function
|
|
766
|
+
function de(e, t = "uniqueId") {
|
|
437
767
|
return e.reduce(
|
|
438
|
-
(r,
|
|
768
|
+
(r, o) => (r[o[t]] = o, r),
|
|
439
769
|
{}
|
|
440
770
|
);
|
|
441
771
|
}
|
|
442
|
-
function
|
|
443
|
-
const r = e.emodes.find((
|
|
772
|
+
function H(e, t) {
|
|
773
|
+
const r = e.emodes.find((n) => n.emodeId === t.emodeId);
|
|
444
774
|
if (!r)
|
|
445
775
|
throw new Error("EMode not found in pool");
|
|
446
|
-
const
|
|
776
|
+
const o = r.assets.find((n) => n.assetId === e.id);
|
|
447
777
|
return {
|
|
448
778
|
...e,
|
|
449
779
|
emode: {
|
|
450
|
-
...
|
|
780
|
+
...o,
|
|
451
781
|
emodeId: r.emodeId
|
|
452
782
|
},
|
|
453
783
|
isEMode: !0
|
|
454
784
|
};
|
|
455
785
|
}
|
|
456
|
-
function
|
|
786
|
+
function gt(e) {
|
|
457
787
|
const [t, r] = e.split("-");
|
|
458
788
|
return !t || !r ? null : {
|
|
459
789
|
marketKey: t,
|
|
460
790
|
poolId: parseInt(r)
|
|
461
791
|
};
|
|
462
792
|
}
|
|
463
|
-
function
|
|
793
|
+
function P() {
|
|
464
794
|
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
465
795
|
}
|
|
466
|
-
var
|
|
467
|
-
const
|
|
796
|
+
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 || {});
|
|
797
|
+
const G = $(
|
|
468
798
|
A(
|
|
469
799
|
async (e) => {
|
|
470
|
-
const t = (e?.markets || [
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const i =
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
).
|
|
483
|
-
|
|
800
|
+
const t = (e?.markets || [F.main]).map((a) => _(a)), r = E(e), o = M(
|
|
801
|
+
`/navi/pools?env=${e?.env || "prod"}&sdk=${O.version}&market=${t.map(
|
|
802
|
+
(a) => a.key
|
|
803
|
+
)}`,
|
|
804
|
+
e
|
|
805
|
+
), n = await fetch(o, { headers: D(U, r) }).then(
|
|
806
|
+
(a) => a.json()
|
|
807
|
+
);
|
|
808
|
+
return n.data.forEach((a) => {
|
|
809
|
+
const i = n.meta.emodes.filter((b) => {
|
|
810
|
+
const k = _(b.marketId);
|
|
811
|
+
return a.market === k.key && b.isActive;
|
|
812
|
+
}).filter((b) => !!b.assets.find((k) => k.assetId === a.id));
|
|
813
|
+
a.emodes = i;
|
|
814
|
+
const s = p(a.totalSupplyAmount).div(Math.pow(10, 9)).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), l = p(a.borrowedAmount).shiftedBy(-9).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), m = p(s).multipliedBy(a.oracle.price).toString(), w = p(l).multipliedBy(a.oracle.price).toString(), y = p(a.supplyCapCeiling).shiftedBy(-27).decimalPlaces(a.token.decimals, p.ROUND_DOWN).toString(), g = p.max(
|
|
815
|
+
p(a.borrowedAmount),
|
|
816
|
+
p(a.validBorrowAmount)
|
|
817
|
+
).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();
|
|
818
|
+
a.poolSupplyAmount = s, a.poolBorrowAmount = l, a.poolSupplyValue = m, a.poolBorrowValue = w, a.poolSupplyCapAmount = y, a.poolBorrowCapAmount = g, a.poolSupplyCapValue = d, a.poolBorrowCapValue = f;
|
|
484
819
|
}), n.data;
|
|
485
820
|
}
|
|
486
821
|
)
|
|
487
822
|
);
|
|
488
|
-
async function
|
|
823
|
+
async function S(e, t) {
|
|
489
824
|
let r = t?.market;
|
|
490
825
|
if (typeof e == "string") {
|
|
491
|
-
const a =
|
|
826
|
+
const a = gt(e);
|
|
492
827
|
a && (r = a.marketKey, e = a.poolId);
|
|
493
828
|
}
|
|
494
|
-
const
|
|
829
|
+
const o = await G({
|
|
495
830
|
...t,
|
|
496
|
-
markets: [r ||
|
|
497
|
-
cacheTime:
|
|
831
|
+
markets: [r || R],
|
|
832
|
+
cacheTime: v
|
|
498
833
|
});
|
|
499
834
|
if (typeof e == "object")
|
|
500
835
|
return e;
|
|
501
|
-
const
|
|
502
|
-
if (!
|
|
836
|
+
const n = o.find((a) => typeof e == "string" ? C(a.suiCoinType) === C(e) : typeof e == "number" ? a.id === e : !1);
|
|
837
|
+
if (!n)
|
|
503
838
|
throw new Error("Pool not found");
|
|
504
|
-
return
|
|
839
|
+
return n.isDeprecated && console.log(`The lending pool for coinType ${n.suiCoinType} is going to be deprecated.`), n;
|
|
505
840
|
}
|
|
506
|
-
const
|
|
841
|
+
const Qt = $(
|
|
507
842
|
A(async (e) => {
|
|
508
|
-
const t =
|
|
509
|
-
return (await fetch(
|
|
843
|
+
const t = E(e), r = M(`/navi/stats?sdk=${O.version}`, e);
|
|
844
|
+
return (await fetch(r, {
|
|
845
|
+
headers: D(U, t)
|
|
846
|
+
}).then((n) => n.json())).data;
|
|
510
847
|
})
|
|
511
|
-
),
|
|
848
|
+
), Yt = $(
|
|
512
849
|
A(
|
|
513
850
|
async (e) => {
|
|
514
|
-
const t =
|
|
515
|
-
return await fetch(
|
|
851
|
+
const t = E(e), r = M(`/navi/fee?sdk=${O.version}`, e);
|
|
852
|
+
return await fetch(r, {
|
|
853
|
+
headers: D(U, t)
|
|
854
|
+
}).then((n) => n.json());
|
|
516
855
|
}
|
|
517
856
|
)
|
|
518
857
|
);
|
|
519
|
-
async function
|
|
520
|
-
const
|
|
521
|
-
...
|
|
522
|
-
cacheTime:
|
|
523
|
-
}), a = await
|
|
858
|
+
async function ht(e, t, r, o) {
|
|
859
|
+
const n = await j({
|
|
860
|
+
...o,
|
|
861
|
+
cacheTime: v
|
|
862
|
+
}), a = await S(t, o), c = o?.market || R, i = o?.env || "prod";
|
|
524
863
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
525
864
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
526
|
-
if (
|
|
527
|
-
if (!
|
|
865
|
+
if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
866
|
+
if (!o?.amount)
|
|
528
867
|
throw new Error("Amount is required for sui coin");
|
|
529
|
-
r = e.splitCoins(r, [
|
|
868
|
+
r = e.splitCoins(r, [o.amount]);
|
|
530
869
|
}
|
|
531
870
|
let s;
|
|
532
|
-
return typeof
|
|
871
|
+
return typeof o?.amount < "u" ? s = h(o.amount, e.pure.u64) : s = e.moveCall({
|
|
533
872
|
target: "0x2::coin::value",
|
|
534
|
-
arguments: [
|
|
873
|
+
arguments: [h(r, e.object)],
|
|
535
874
|
typeArguments: [a.suiCoinType]
|
|
536
|
-
}),
|
|
537
|
-
target: `${
|
|
875
|
+
}), o?.accountCap ? e.moveCall({
|
|
876
|
+
target: `${n.package}::incentive_v3::deposit_with_account_cap`,
|
|
538
877
|
arguments: [
|
|
539
878
|
e.object("0x06"),
|
|
540
|
-
e.object(
|
|
879
|
+
e.object(n.storage),
|
|
541
880
|
e.object(a.contract.pool),
|
|
542
881
|
e.pure.u8(a.id),
|
|
543
|
-
|
|
544
|
-
e.object(
|
|
545
|
-
e.object(
|
|
546
|
-
|
|
882
|
+
h(r, e.object),
|
|
883
|
+
e.object(n.incentiveV2),
|
|
884
|
+
e.object(n.incentiveV3),
|
|
885
|
+
h(o.accountCap, e.object)
|
|
547
886
|
],
|
|
548
887
|
typeArguments: [a.suiCoinType]
|
|
549
888
|
}) : e.moveCall({
|
|
550
|
-
target: `${
|
|
889
|
+
target: `${n.package}::incentive_v3::entry_deposit`,
|
|
551
890
|
arguments: [
|
|
552
891
|
e.object("0x06"),
|
|
553
|
-
e.object(
|
|
892
|
+
e.object(n.storage),
|
|
554
893
|
e.object(a.contract.pool),
|
|
555
894
|
e.pure.u8(a.id),
|
|
556
|
-
|
|
895
|
+
h(r, e.object),
|
|
557
896
|
s,
|
|
558
|
-
e.object(
|
|
559
|
-
e.object(
|
|
897
|
+
e.object(n.incentiveV2),
|
|
898
|
+
e.object(n.incentiveV3)
|
|
560
899
|
],
|
|
561
900
|
typeArguments: [a.suiCoinType]
|
|
562
|
-
}),
|
|
563
|
-
target: `${
|
|
901
|
+
}), n.version === 2 && a.token.symbol === "SUI" && i === "prod" && c === "main" && e.moveCall({
|
|
902
|
+
target: `${n.package}::pool::refresh_stake`,
|
|
564
903
|
arguments: [e.object(a.contract.pool), e.object("0x05")]
|
|
565
904
|
}), e;
|
|
566
905
|
}
|
|
567
|
-
async function
|
|
568
|
-
const
|
|
569
|
-
...
|
|
570
|
-
cacheTime:
|
|
571
|
-
}), a = await
|
|
906
|
+
async function Zt(e, t, r, o) {
|
|
907
|
+
const n = await j({
|
|
908
|
+
...o,
|
|
909
|
+
cacheTime: v
|
|
910
|
+
}), a = await S(t, o), c = h(r, e.pure.u64);
|
|
572
911
|
let i;
|
|
573
|
-
if (
|
|
574
|
-
if (
|
|
575
|
-
const [
|
|
576
|
-
target: `${
|
|
912
|
+
if (n.version === 1)
|
|
913
|
+
if (o?.accountCap) {
|
|
914
|
+
const [l] = e.moveCall({
|
|
915
|
+
target: `${n.package}::incentive_v3::withdraw_with_account_cap`,
|
|
577
916
|
arguments: [
|
|
578
917
|
e.object("0x06"),
|
|
579
|
-
e.object(
|
|
580
|
-
e.object(
|
|
918
|
+
e.object(n.priceOracle),
|
|
919
|
+
e.object(n.storage),
|
|
581
920
|
e.object(a.contract.pool),
|
|
582
921
|
e.pure.u8(a.id),
|
|
583
922
|
c,
|
|
584
|
-
e.object(
|
|
585
|
-
e.object(
|
|
586
|
-
|
|
923
|
+
e.object(n.incentiveV2),
|
|
924
|
+
e.object(n.incentiveV3),
|
|
925
|
+
h(o.accountCap, e.object)
|
|
587
926
|
],
|
|
588
927
|
typeArguments: [a.suiCoinType]
|
|
589
928
|
});
|
|
590
|
-
i =
|
|
929
|
+
i = l;
|
|
591
930
|
} else {
|
|
592
|
-
const [
|
|
593
|
-
target: `${
|
|
931
|
+
const [l] = e.moveCall({
|
|
932
|
+
target: `${n.package}::incentive_v3::withdraw`,
|
|
594
933
|
arguments: [
|
|
595
934
|
e.object("0x06"),
|
|
596
|
-
e.object(
|
|
597
|
-
e.object(
|
|
935
|
+
e.object(n.priceOracle),
|
|
936
|
+
e.object(n.storage),
|
|
598
937
|
e.object(a.contract.pool),
|
|
599
938
|
e.pure.u8(a.id),
|
|
600
939
|
c,
|
|
601
|
-
e.object(
|
|
602
|
-
e.object(
|
|
940
|
+
e.object(n.incentiveV2),
|
|
941
|
+
e.object(n.incentiveV3)
|
|
603
942
|
],
|
|
604
943
|
typeArguments: [a.suiCoinType]
|
|
605
944
|
});
|
|
606
|
-
i =
|
|
945
|
+
i = l;
|
|
607
946
|
}
|
|
608
|
-
else if (
|
|
609
|
-
const [
|
|
610
|
-
target: `${
|
|
947
|
+
else if (o?.accountCap) {
|
|
948
|
+
const [l] = e.moveCall({
|
|
949
|
+
target: `${n.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
611
950
|
arguments: [
|
|
612
951
|
e.object("0x06"),
|
|
613
|
-
e.object(
|
|
614
|
-
e.object(
|
|
952
|
+
e.object(n.priceOracle),
|
|
953
|
+
e.object(n.storage),
|
|
615
954
|
e.object(a.contract.pool),
|
|
616
955
|
e.pure.u8(a.id),
|
|
617
956
|
c,
|
|
618
|
-
e.object(
|
|
619
|
-
e.object(
|
|
620
|
-
|
|
957
|
+
e.object(n.incentiveV2),
|
|
958
|
+
e.object(n.incentiveV3),
|
|
959
|
+
h(o.accountCap, e.object),
|
|
621
960
|
e.object("0x05")
|
|
622
961
|
],
|
|
623
962
|
typeArguments: [a.suiCoinType]
|
|
624
963
|
});
|
|
625
|
-
i =
|
|
964
|
+
i = l;
|
|
626
965
|
} else {
|
|
627
|
-
const [
|
|
628
|
-
target: `${
|
|
966
|
+
const [l] = e.moveCall({
|
|
967
|
+
target: `${n.package}::incentive_v3::withdraw_v2`,
|
|
629
968
|
arguments: [
|
|
630
969
|
e.object("0x06"),
|
|
631
|
-
e.object(
|
|
632
|
-
e.object(
|
|
970
|
+
e.object(n.priceOracle),
|
|
971
|
+
e.object(n.storage),
|
|
633
972
|
e.object(a.contract.pool),
|
|
634
973
|
e.pure.u8(a.id),
|
|
635
974
|
c,
|
|
636
|
-
e.object(
|
|
637
|
-
e.object(
|
|
975
|
+
e.object(n.incentiveV2),
|
|
976
|
+
e.object(n.incentiveV3),
|
|
638
977
|
e.object("0x05")
|
|
639
978
|
],
|
|
640
979
|
typeArguments: [a.suiCoinType]
|
|
641
980
|
});
|
|
642
|
-
i =
|
|
981
|
+
i = l;
|
|
643
982
|
}
|
|
644
983
|
return e.moveCall({
|
|
645
984
|
target: "0x2::coin::from_balance",
|
|
@@ -647,85 +986,85 @@ async function it(e, t, r, n) {
|
|
|
647
986
|
typeArguments: [a.suiCoinType]
|
|
648
987
|
});
|
|
649
988
|
}
|
|
650
|
-
async function
|
|
651
|
-
const
|
|
652
|
-
...
|
|
653
|
-
cacheTime:
|
|
654
|
-
}), a = await
|
|
989
|
+
async function Xt(e, t, r, o) {
|
|
990
|
+
const n = await j({
|
|
991
|
+
...o,
|
|
992
|
+
cacheTime: v
|
|
993
|
+
}), a = await S(t, o);
|
|
655
994
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
656
995
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
657
|
-
const c =
|
|
996
|
+
const c = h(r, e.pure.u64);
|
|
658
997
|
let i;
|
|
659
|
-
if (
|
|
660
|
-
if (
|
|
661
|
-
const [
|
|
662
|
-
target: `${
|
|
998
|
+
if (n.version === 1)
|
|
999
|
+
if (o?.accountCap) {
|
|
1000
|
+
const [l] = e.moveCall({
|
|
1001
|
+
target: `${n.package}::incentive_v3::borrow_with_account_cap`,
|
|
663
1002
|
arguments: [
|
|
664
1003
|
e.object("0x06"),
|
|
665
|
-
e.object(
|
|
666
|
-
e.object(
|
|
1004
|
+
e.object(n.priceOracle),
|
|
1005
|
+
e.object(n.storage),
|
|
667
1006
|
e.object(a.contract.pool),
|
|
668
1007
|
e.pure.u8(a.id),
|
|
669
1008
|
c,
|
|
670
|
-
e.object(
|
|
671
|
-
e.object(
|
|
672
|
-
|
|
1009
|
+
e.object(n.incentiveV2),
|
|
1010
|
+
e.object(n.incentiveV3),
|
|
1011
|
+
h(o.accountCap, e.object)
|
|
673
1012
|
],
|
|
674
1013
|
typeArguments: [a.suiCoinType]
|
|
675
1014
|
});
|
|
676
|
-
i =
|
|
1015
|
+
i = l;
|
|
677
1016
|
} else {
|
|
678
|
-
const [
|
|
679
|
-
target: `${
|
|
1017
|
+
const [l] = e.moveCall({
|
|
1018
|
+
target: `${n.package}::incentive_v3::borrow`,
|
|
680
1019
|
arguments: [
|
|
681
1020
|
e.object("0x06"),
|
|
682
|
-
e.object(
|
|
683
|
-
e.object(
|
|
1021
|
+
e.object(n.priceOracle),
|
|
1022
|
+
e.object(n.storage),
|
|
684
1023
|
e.object(a.contract.pool),
|
|
685
1024
|
e.pure.u8(a.id),
|
|
686
1025
|
c,
|
|
687
|
-
e.object(
|
|
688
|
-
e.object(
|
|
1026
|
+
e.object(n.incentiveV2),
|
|
1027
|
+
e.object(n.incentiveV3)
|
|
689
1028
|
],
|
|
690
1029
|
typeArguments: [a.suiCoinType]
|
|
691
1030
|
});
|
|
692
|
-
i =
|
|
1031
|
+
i = l;
|
|
693
1032
|
}
|
|
694
|
-
else if (
|
|
695
|
-
const [
|
|
696
|
-
target: `${
|
|
1033
|
+
else if (o?.accountCap) {
|
|
1034
|
+
const [l] = e.moveCall({
|
|
1035
|
+
target: `${n.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
697
1036
|
arguments: [
|
|
698
1037
|
e.object("0x06"),
|
|
699
|
-
e.object(
|
|
700
|
-
e.object(
|
|
1038
|
+
e.object(n.priceOracle),
|
|
1039
|
+
e.object(n.storage),
|
|
701
1040
|
e.object(a.contract.pool),
|
|
702
1041
|
e.pure.u8(a.id),
|
|
703
1042
|
c,
|
|
704
|
-
e.object(
|
|
705
|
-
e.object(
|
|
706
|
-
|
|
1043
|
+
e.object(n.incentiveV2),
|
|
1044
|
+
e.object(n.incentiveV3),
|
|
1045
|
+
h(o.accountCap, e.object),
|
|
707
1046
|
e.object("0x05")
|
|
708
1047
|
],
|
|
709
1048
|
typeArguments: [a.suiCoinType]
|
|
710
1049
|
});
|
|
711
|
-
i =
|
|
1050
|
+
i = l;
|
|
712
1051
|
} else {
|
|
713
|
-
const [
|
|
714
|
-
target: `${
|
|
1052
|
+
const [l] = e.moveCall({
|
|
1053
|
+
target: `${n.package}::incentive_v3::borrow_v2`,
|
|
715
1054
|
arguments: [
|
|
716
1055
|
e.object("0x06"),
|
|
717
|
-
e.object(
|
|
718
|
-
e.object(
|
|
1056
|
+
e.object(n.priceOracle),
|
|
1057
|
+
e.object(n.storage),
|
|
719
1058
|
e.object(a.contract.pool),
|
|
720
1059
|
e.pure.u8(a.id),
|
|
721
1060
|
c,
|
|
722
|
-
e.object(
|
|
723
|
-
e.object(
|
|
1061
|
+
e.object(n.incentiveV2),
|
|
1062
|
+
e.object(n.incentiveV3),
|
|
724
1063
|
e.object("0x05")
|
|
725
1064
|
],
|
|
726
1065
|
typeArguments: [a.suiCoinType]
|
|
727
1066
|
});
|
|
728
|
-
i =
|
|
1067
|
+
i = l;
|
|
729
1068
|
}
|
|
730
1069
|
return e.moveCall({
|
|
731
1070
|
target: "0x2::coin::from_balance",
|
|
@@ -733,34 +1072,34 @@ async function ct(e, t, r, n) {
|
|
|
733
1072
|
typeArguments: [a.suiCoinType]
|
|
734
1073
|
});
|
|
735
1074
|
}
|
|
736
|
-
async function
|
|
737
|
-
const
|
|
738
|
-
...
|
|
739
|
-
cacheTime:
|
|
740
|
-
}), a = await
|
|
741
|
-
if (
|
|
742
|
-
if (!
|
|
1075
|
+
async function xt(e, t, r, o) {
|
|
1076
|
+
const n = await j({
|
|
1077
|
+
...o,
|
|
1078
|
+
cacheTime: v
|
|
1079
|
+
}), a = await S(t, o);
|
|
1080
|
+
if (C(a.suiCoinType) === C("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
1081
|
+
if (!o?.amount)
|
|
743
1082
|
throw new Error("Amount is required for sui coin");
|
|
744
|
-
r = e.splitCoins(r, [
|
|
1083
|
+
r = e.splitCoins(r, [o.amount]);
|
|
745
1084
|
}
|
|
746
1085
|
let c;
|
|
747
|
-
if (typeof
|
|
1086
|
+
if (typeof o?.amount < "u" ? c = h(o.amount, e.pure.u64) : c = e.moveCall({
|
|
748
1087
|
target: "0x2::coin::value",
|
|
749
|
-
arguments: [
|
|
1088
|
+
arguments: [h(r, e.object)],
|
|
750
1089
|
typeArguments: [a.suiCoinType]
|
|
751
|
-
}),
|
|
1090
|
+
}), o?.accountCap) {
|
|
752
1091
|
const [i] = e.moveCall({
|
|
753
|
-
target: `${
|
|
1092
|
+
target: `${n.package}::incentive_v3::repay_with_account_cap`,
|
|
754
1093
|
arguments: [
|
|
755
1094
|
e.object("0x06"),
|
|
756
|
-
e.object(
|
|
757
|
-
e.object(
|
|
1095
|
+
e.object(n.priceOracle),
|
|
1096
|
+
e.object(n.storage),
|
|
758
1097
|
e.object(a.contract.pool),
|
|
759
1098
|
e.pure.u8(a.id),
|
|
760
|
-
|
|
761
|
-
e.object(
|
|
762
|
-
e.object(
|
|
763
|
-
|
|
1099
|
+
h(r, e.object),
|
|
1100
|
+
e.object(n.incentiveV2),
|
|
1101
|
+
e.object(n.incentiveV3),
|
|
1102
|
+
h(o.accountCap, e.object)
|
|
764
1103
|
],
|
|
765
1104
|
typeArguments: [a.suiCoinType]
|
|
766
1105
|
});
|
|
@@ -771,56 +1110,59 @@ async function st(e, t, r, n) {
|
|
|
771
1110
|
});
|
|
772
1111
|
} else
|
|
773
1112
|
return e.moveCall({
|
|
774
|
-
target: `${
|
|
1113
|
+
target: `${n.package}::incentive_v3::entry_repay`,
|
|
775
1114
|
arguments: [
|
|
776
1115
|
e.object("0x06"),
|
|
777
|
-
e.object(
|
|
778
|
-
e.object(
|
|
1116
|
+
e.object(n.priceOracle),
|
|
1117
|
+
e.object(n.storage),
|
|
779
1118
|
e.object(a.contract.pool),
|
|
780
1119
|
e.pure.u8(a.id),
|
|
781
|
-
|
|
1120
|
+
h(r, e.object),
|
|
782
1121
|
c,
|
|
783
|
-
e.object(
|
|
784
|
-
e.object(
|
|
1122
|
+
e.object(n.incentiveV2),
|
|
1123
|
+
e.object(n.incentiveV3)
|
|
785
1124
|
],
|
|
786
1125
|
typeArguments: [a.suiCoinType]
|
|
787
1126
|
}), e;
|
|
788
1127
|
}
|
|
789
|
-
const
|
|
1128
|
+
const er = $(
|
|
790
1129
|
A(
|
|
791
1130
|
async (e) => {
|
|
792
|
-
const t = await
|
|
1131
|
+
const t = await j({
|
|
793
1132
|
...e
|
|
794
|
-
});
|
|
1133
|
+
}), r = e?.client ?? V;
|
|
795
1134
|
if (e?.address && typeof e?.asset < "u")
|
|
796
1135
|
try {
|
|
797
|
-
const
|
|
1136
|
+
const a = await S(e.asset, e), c = new N();
|
|
798
1137
|
c.moveCall({
|
|
799
1138
|
target: `${t.package}::incentive_v3::get_borrow_fee_v2`,
|
|
800
1139
|
arguments: [
|
|
801
1140
|
c.object(t.incentiveV3),
|
|
802
1141
|
c.pure.address(e.address),
|
|
803
|
-
c.pure.u8(
|
|
1142
|
+
c.pure.u8(a.id),
|
|
804
1143
|
c.pure.u64(1e4)
|
|
805
1144
|
],
|
|
806
1145
|
typeArguments: []
|
|
807
1146
|
});
|
|
808
|
-
const i = await
|
|
1147
|
+
const i = await q(r, {
|
|
809
1148
|
transactionBlock: c,
|
|
810
1149
|
sender: e.address
|
|
811
|
-
}), s =
|
|
1150
|
+
}), s = Q(i, [u.u64()]);
|
|
812
1151
|
return (Number(s[0]) || 0) / 100;
|
|
813
|
-
} catch (
|
|
814
|
-
console.error(
|
|
1152
|
+
} catch (a) {
|
|
1153
|
+
console.error(
|
|
1154
|
+
"[lending] getBorrowFee per-user query failed, falling back to global rate:",
|
|
1155
|
+
a
|
|
1156
|
+
);
|
|
815
1157
|
}
|
|
816
|
-
const n = (await
|
|
1158
|
+
const n = (await pt(r, {
|
|
817
1159
|
id: t.incentiveV3,
|
|
818
1160
|
options: { showType: !0, showOwner: !0, showContent: !0 }
|
|
819
1161
|
})).data.content.fields.borrow_fee_rate;
|
|
820
1162
|
return Number(n) / 100;
|
|
821
1163
|
}
|
|
822
1164
|
)
|
|
823
|
-
),
|
|
1165
|
+
), R = "main", F = {
|
|
824
1166
|
main: {
|
|
825
1167
|
id: 0,
|
|
826
1168
|
key: "main",
|
|
@@ -842,56 +1184,56 @@ const lt = S(
|
|
|
842
1184
|
name: "Sui Eco Market"
|
|
843
1185
|
}
|
|
844
1186
|
};
|
|
845
|
-
class
|
|
1187
|
+
class wt {
|
|
846
1188
|
constructor(t, r) {
|
|
847
1189
|
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
848
1190
|
marketTotalSupplyValue: "0",
|
|
849
1191
|
marketTotalBorrowValue: "0"
|
|
850
|
-
}, this.config =
|
|
1192
|
+
}, this.config = _(t), this.initPools(r);
|
|
851
1193
|
}
|
|
852
1194
|
get overview() {
|
|
853
1195
|
return this._overview;
|
|
854
1196
|
}
|
|
855
1197
|
initPools(t) {
|
|
856
|
-
const r =
|
|
857
|
-
let c =
|
|
1198
|
+
const r = ee(this.pools), o = de(this.emodes), n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
|
|
1199
|
+
let c = p(0), i = p(0);
|
|
858
1200
|
t.forEach((s) => {
|
|
859
1201
|
if (!this.checkMarket(s.market)) {
|
|
860
1202
|
console.warn(`Pool is not in market ${this.config.name}`, s);
|
|
861
1203
|
return;
|
|
862
1204
|
}
|
|
863
1205
|
r[s.uniqueId] || this.pools.push(s), s?.emodes?.forEach((m) => {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
(
|
|
867
|
-
) &&
|
|
1206
|
+
o[m.uniqueId] || this.emodes.push(m), m.assets.forEach((w) => {
|
|
1207
|
+
w.isDebt && m.assets.find(
|
|
1208
|
+
(g) => g.isCollateral && g.ltv > 0 && g.assetId !== s.id
|
|
1209
|
+
) && n.add(s.uniqueId), w.isCollateral && m.assets.find((g) => g.isDebt && g.assetId !== s.id) && a.add(s.uniqueId);
|
|
868
1210
|
});
|
|
869
1211
|
}), i = i.plus(s.poolBorrowValue), c = c.plus(s.poolSupplyValue);
|
|
870
|
-
}), this.poolMap =
|
|
871
|
-
const
|
|
872
|
-
this.emodePools.push(...
|
|
1212
|
+
}), this.poolMap = ee(this.pools, "id"), this.emodeMap = de(this.emodes, "emodeId"), this.emodes.forEach((s) => {
|
|
1213
|
+
const l = this.getEModePools(s.emodeId);
|
|
1214
|
+
this.emodePools.push(...l);
|
|
873
1215
|
}), this._overview = {
|
|
874
1216
|
marketTotalSupplyValue: c.toString(),
|
|
875
1217
|
marketTotalBorrowValue: i.toString()
|
|
876
|
-
}, this.emodeBorrowablePools = this.pools.filter((s) =>
|
|
1218
|
+
}, this.emodeBorrowablePools = this.pools.filter((s) => n.has(s.uniqueId)), this.emodeSupplyablePools = this.pools.filter((s) => a.has(s.uniqueId));
|
|
877
1219
|
}
|
|
878
1220
|
getEMode(t) {
|
|
879
1221
|
return this.emodeMap[t] || null;
|
|
880
1222
|
}
|
|
881
1223
|
getEModeRelatePools(t, r) {
|
|
882
|
-
const { collateral:
|
|
1224
|
+
const { collateral: o, debt: n, emodeId: a } = r || {}, c = [];
|
|
883
1225
|
return t.emodes.forEach((i) => {
|
|
884
1226
|
typeof a == "number" && a !== i.emodeId || i.assets.forEach((s) => {
|
|
885
|
-
typeof
|
|
1227
|
+
typeof o == "boolean" && o && s.isCollateral && s.assetId === t.id && c.push(this.poolMap[s.assetId]), typeof n == "boolean" && n && s.isDebt && s.assetId === t.id && c.push(this.poolMap[s.assetId]);
|
|
886
1228
|
});
|
|
887
1229
|
}), c;
|
|
888
1230
|
}
|
|
889
1231
|
getEModePools(t) {
|
|
890
1232
|
const r = this.getEMode(t);
|
|
891
|
-
return r ? r.assets.map((
|
|
892
|
-
const a = r.assets.find((c) => c.assetId ===
|
|
1233
|
+
return r ? r.assets.map((n) => n.assetId).map((n) => this.poolMap[n]).filter((n) => !!n).map((n) => {
|
|
1234
|
+
const a = r.assets.find((c) => c.assetId === n.id);
|
|
893
1235
|
return {
|
|
894
|
-
...
|
|
1236
|
+
...n,
|
|
895
1237
|
emode: {
|
|
896
1238
|
...a,
|
|
897
1239
|
emodeId: r.emodeId
|
|
@@ -905,40 +1247,45 @@ class Ue {
|
|
|
905
1247
|
return typeof t == "number" && t === this.config.id && (r = !0), typeof t == "string" && t === this.config.key && (r = !0), typeof t == "object" && t.id === this.config.id && (r = !0), r;
|
|
906
1248
|
}
|
|
907
1249
|
}
|
|
908
|
-
const
|
|
909
|
-
const r = Object.values(
|
|
1250
|
+
const _ = (e) => {
|
|
1251
|
+
const r = Object.values(F).find((o) => typeof e == "number" ? o.id === e : typeof e == "string" ? o.key === e : o.id === e.id);
|
|
910
1252
|
if (!r)
|
|
911
1253
|
throw new Error("Market not found");
|
|
912
1254
|
return r;
|
|
913
|
-
},
|
|
1255
|
+
}, bt = $(
|
|
914
1256
|
A(
|
|
915
1257
|
async (e, t) => {
|
|
916
|
-
const r = await
|
|
1258
|
+
const r = await G({
|
|
917
1259
|
cacheTime: 6e4,
|
|
918
1260
|
...t,
|
|
919
1261
|
markets: e
|
|
920
1262
|
});
|
|
921
|
-
return e.map((
|
|
922
|
-
const
|
|
923
|
-
return new
|
|
1263
|
+
return e.map((o) => {
|
|
1264
|
+
const n = _(o), a = r.filter((c) => c.market === n.key);
|
|
1265
|
+
return new wt(o, a);
|
|
924
1266
|
});
|
|
925
1267
|
}
|
|
926
1268
|
)
|
|
927
|
-
),
|
|
1269
|
+
), tr = $(
|
|
928
1270
|
A(
|
|
929
|
-
async (e, t) => (await
|
|
1271
|
+
async (e, t) => (await bt([e], t))[0]
|
|
930
1272
|
)
|
|
931
|
-
),
|
|
1273
|
+
), j = $(
|
|
932
1274
|
A(
|
|
933
1275
|
async (e) => {
|
|
934
|
-
const t =
|
|
935
|
-
|
|
1276
|
+
const t = _(e?.market || R), r = E(e), o = M(
|
|
1277
|
+
`/navi/config?env=${e?.env || "prod"}&sdk=${O.version}&market=${t.key}`,
|
|
1278
|
+
e
|
|
1279
|
+
);
|
|
1280
|
+
return (await fetch(o, {
|
|
1281
|
+
headers: D(U, r)
|
|
1282
|
+
}).then((a) => a.json())).data;
|
|
936
1283
|
}
|
|
937
1284
|
)
|
|
938
|
-
),
|
|
939
|
-
async function
|
|
940
|
-
const r = await
|
|
941
|
-
cacheTime:
|
|
1285
|
+
), v = 1e3 * 60 * 5;
|
|
1286
|
+
async function vt(e, t) {
|
|
1287
|
+
const r = await j({
|
|
1288
|
+
cacheTime: v,
|
|
942
1289
|
...t
|
|
943
1290
|
});
|
|
944
1291
|
return e.moveCall({
|
|
@@ -946,374 +1293,443 @@ async function De(e, t) {
|
|
|
946
1293
|
arguments: []
|
|
947
1294
|
});
|
|
948
1295
|
}
|
|
949
|
-
async function
|
|
950
|
-
const
|
|
951
|
-
cacheTime:
|
|
1296
|
+
async function Ct(e, t, r) {
|
|
1297
|
+
const o = await j({
|
|
1298
|
+
cacheTime: v,
|
|
952
1299
|
...r
|
|
953
1300
|
});
|
|
954
1301
|
return e.moveCall({
|
|
955
|
-
target: `${
|
|
1302
|
+
target: `${o.package}::account::account_owner`,
|
|
956
1303
|
arguments: [t]
|
|
957
1304
|
});
|
|
958
1305
|
}
|
|
959
|
-
async function
|
|
960
|
-
const
|
|
1306
|
+
async function jt(e, t, r) {
|
|
1307
|
+
const o = await j({
|
|
961
1308
|
...r,
|
|
962
|
-
cacheTime:
|
|
1309
|
+
cacheTime: v
|
|
963
1310
|
});
|
|
964
1311
|
return r?.accountCap ? e.moveCall({
|
|
965
|
-
target: `${
|
|
1312
|
+
target: `${o.package}::lending::enter_emode_with_account_cap`,
|
|
966
1313
|
arguments: [
|
|
967
|
-
e.object(
|
|
968
|
-
|
|
969
|
-
|
|
1314
|
+
e.object(o.storage),
|
|
1315
|
+
h(t, e.pure.u64),
|
|
1316
|
+
h(r.accountCap, e.object)
|
|
970
1317
|
]
|
|
971
1318
|
}) : e.moveCall({
|
|
972
|
-
target: `${
|
|
973
|
-
arguments: [e.object(
|
|
1319
|
+
target: `${o.package}::lending::enter_emode`,
|
|
1320
|
+
arguments: [e.object(o.storage), h(t, e.pure.u64)]
|
|
974
1321
|
}), e;
|
|
975
1322
|
}
|
|
976
|
-
async function
|
|
977
|
-
const r = await
|
|
1323
|
+
async function rr(e, t) {
|
|
1324
|
+
const r = await j({
|
|
978
1325
|
...t,
|
|
979
|
-
cacheTime:
|
|
1326
|
+
cacheTime: v
|
|
980
1327
|
});
|
|
981
1328
|
return t?.accountCap ? e.moveCall({
|
|
982
1329
|
target: `${r.package}::lending::exit_emode_with_account_cap`,
|
|
983
|
-
arguments: [e.object(r.storage),
|
|
1330
|
+
arguments: [e.object(r.storage), h(t.accountCap, e.object)]
|
|
984
1331
|
}) : e.moveCall({
|
|
985
1332
|
target: `${r.package}::lending::exit_emode`,
|
|
986
1333
|
arguments: [e.object(r.storage)]
|
|
987
1334
|
}), e;
|
|
988
1335
|
}
|
|
989
|
-
async function
|
|
990
|
-
const
|
|
991
|
-
cacheTime:
|
|
1336
|
+
async function nr(e, t, r) {
|
|
1337
|
+
const o = await j({
|
|
1338
|
+
cacheTime: v,
|
|
992
1339
|
...r
|
|
993
|
-
}),
|
|
994
|
-
await
|
|
1340
|
+
}), n = await vt(e, r);
|
|
1341
|
+
await jt(e, t, {
|
|
995
1342
|
...r,
|
|
996
|
-
accountCap:
|
|
1343
|
+
accountCap: n
|
|
997
1344
|
});
|
|
998
|
-
const a = await
|
|
1345
|
+
const a = await _(r?.market || R), c = await Ct(e, n, r);
|
|
999
1346
|
return e.moveCall({
|
|
1000
|
-
target: `${
|
|
1347
|
+
target: `${o.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
1001
1348
|
arguments: [
|
|
1002
|
-
e.object(
|
|
1349
|
+
e.object(o.emode.contract.registryObject),
|
|
1003
1350
|
c,
|
|
1004
|
-
|
|
1005
|
-
|
|
1351
|
+
h(a.id, e.pure.u64),
|
|
1352
|
+
h(t, e.pure.u64)
|
|
1006
1353
|
]
|
|
1007
|
-
}),
|
|
1354
|
+
}), n;
|
|
1008
1355
|
}
|
|
1009
|
-
const
|
|
1356
|
+
const ke = $(
|
|
1010
1357
|
A(
|
|
1011
1358
|
async (e, t) => {
|
|
1012
|
-
const r = await
|
|
1013
|
-
cacheTime:
|
|
1359
|
+
const r = await j({
|
|
1360
|
+
cacheTime: v,
|
|
1014
1361
|
...t
|
|
1015
|
-
}),
|
|
1016
|
-
|
|
1362
|
+
}), o = new N(), n = t?.client ?? V;
|
|
1363
|
+
o.moveCall({
|
|
1017
1364
|
target: `${r.emode.contract.registryPackage}::registry::find_user_emode_account_caps`,
|
|
1018
|
-
arguments: [
|
|
1365
|
+
arguments: [o.object(r.emode.contract.registryObject), o.pure.address(e)]
|
|
1019
1366
|
});
|
|
1020
|
-
const c = (await
|
|
1021
|
-
transactionBlock:
|
|
1367
|
+
const c = (await q(n, {
|
|
1368
|
+
transactionBlock: o,
|
|
1022
1369
|
sender: e
|
|
1023
|
-
})).results[0].returnValues, i =
|
|
1024
|
-
return i.map((m,
|
|
1370
|
+
})).results[0].returnValues, i = u.vector(u.u64()).parse(Uint8Array.from(c[0][0])), s = u.vector(u.u64()).parse(Uint8Array.from(c[1][0])), l = u.vector(u.Address).parse(Uint8Array.from(c[2][0]));
|
|
1371
|
+
return i.map((m, w) => ({
|
|
1025
1372
|
marketId: Number(m),
|
|
1026
|
-
emodeId: Number(s[
|
|
1027
|
-
accountCap:
|
|
1373
|
+
emodeId: Number(s[w]),
|
|
1374
|
+
accountCap: l[w].toString()
|
|
1028
1375
|
}));
|
|
1029
1376
|
}
|
|
1030
1377
|
)
|
|
1031
1378
|
);
|
|
1032
|
-
function
|
|
1033
|
-
return `${
|
|
1379
|
+
function or(e) {
|
|
1380
|
+
return `${_(e.marketId).key}-${e.emodeId}`;
|
|
1034
1381
|
}
|
|
1035
|
-
function
|
|
1036
|
-
|
|
1382
|
+
function kt(e, t) {
|
|
1383
|
+
return e.coinType ? e.coinType : t || (typeof e.type == "string" ? e.type.match(/::coin::Coin<(.+)>$/) : null)?.[1];
|
|
1384
|
+
}
|
|
1385
|
+
function pe(e, t) {
|
|
1386
|
+
const r = kt(e, t), o = e.coinObjectId ?? e.objectId;
|
|
1387
|
+
return !r || !o || e.balance === void 0 || e.balance === null ? null : {
|
|
1388
|
+
...e,
|
|
1389
|
+
coinType: C(r),
|
|
1390
|
+
coinObjectId: o
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
function ar(e, t, r) {
|
|
1394
|
+
const o = typeof r?.balance == "number", n = o ? r.balance : 0;
|
|
1037
1395
|
let a = 0;
|
|
1038
1396
|
const c = [];
|
|
1039
1397
|
let i = "";
|
|
1040
|
-
if (t.sort((s,
|
|
1041
|
-
if (!(
|
|
1398
|
+
if (t.sort((s, l) => Number(l.balance) - Number(s.balance)).forEach((s) => {
|
|
1399
|
+
if (!(o && a >= n) && Number(s.balance) !== 0) {
|
|
1042
1400
|
if (i || (i = s.coinType), i !== s.coinType)
|
|
1043
1401
|
throw new Error("All coins must be of the same type");
|
|
1044
1402
|
a += Number(s.balance), c.push(s.coinObjectId);
|
|
1045
1403
|
}
|
|
1046
1404
|
}), c.length === 0)
|
|
1047
1405
|
throw new Error("No coins to merge");
|
|
1048
|
-
if (
|
|
1406
|
+
if (o && a < n)
|
|
1049
1407
|
throw new Error(
|
|
1050
|
-
`Balance is less than the specified balance: ${a} < ${
|
|
1408
|
+
`Balance is less than the specified balance: ${a} < ${n}`
|
|
1051
1409
|
);
|
|
1052
|
-
return
|
|
1410
|
+
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]);
|
|
1053
1411
|
}
|
|
1054
|
-
async function
|
|
1055
|
-
const i = await
|
|
1412
|
+
async function Ie(e, t, r, o, n, a, c) {
|
|
1413
|
+
const i = await j({
|
|
1056
1414
|
...c,
|
|
1057
|
-
cacheTime:
|
|
1058
|
-
}), s = await
|
|
1415
|
+
cacheTime: v
|
|
1416
|
+
}), s = await S(r, c);
|
|
1059
1417
|
return e.moveCall({
|
|
1060
1418
|
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
1061
1419
|
arguments: [
|
|
1062
1420
|
e.object("0x06"),
|
|
1063
1421
|
e.object(i.storage),
|
|
1064
1422
|
e.object(i.oracle.priceOracle),
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1423
|
+
ft(e, s),
|
|
1424
|
+
h(t, e.pure.address),
|
|
1425
|
+
h(s.id, e.pure.u8),
|
|
1426
|
+
h(o, e.pure.u64),
|
|
1427
|
+
h(n, e.pure.u64),
|
|
1428
|
+
h(a, e.pure.bool)
|
|
1071
1429
|
],
|
|
1072
1430
|
typeArguments: [s.suiCoinType]
|
|
1073
1431
|
});
|
|
1074
1432
|
}
|
|
1075
|
-
async function
|
|
1076
|
-
return
|
|
1433
|
+
async function It(e, t, r) {
|
|
1434
|
+
return Ie(e, t, 0, 0, 0, !1, r);
|
|
1077
1435
|
}
|
|
1078
|
-
async function
|
|
1079
|
-
const
|
|
1436
|
+
async function _e(e, t, r) {
|
|
1437
|
+
const o = new N(), n = r?.client ?? V, a = await G({
|
|
1080
1438
|
...r,
|
|
1081
|
-
markets: Object.values(
|
|
1082
|
-
}), c =
|
|
1083
|
-
for (const
|
|
1084
|
-
const f = await
|
|
1439
|
+
markets: Object.values(F)
|
|
1440
|
+
}), c = ee(a), s = Array.from(new Set(t.map((d) => d.market))).map((d) => _(d));
|
|
1441
|
+
for (const d of s) {
|
|
1442
|
+
const f = await j({
|
|
1085
1443
|
...r,
|
|
1086
|
-
cacheTime:
|
|
1087
|
-
market:
|
|
1444
|
+
cacheTime: v,
|
|
1445
|
+
market: d.key
|
|
1088
1446
|
});
|
|
1089
|
-
|
|
1447
|
+
o.moveCall({
|
|
1090
1448
|
target: `${f.uiGetter}::getter::get_reserve_data`,
|
|
1091
|
-
arguments: [
|
|
1449
|
+
arguments: [o.object(f.storage)]
|
|
1092
1450
|
});
|
|
1093
1451
|
}
|
|
1094
|
-
for (let
|
|
1095
|
-
const f = await
|
|
1452
|
+
for (let d of t) {
|
|
1453
|
+
const f = await j({
|
|
1096
1454
|
...r,
|
|
1097
|
-
cacheTime:
|
|
1098
|
-
market:
|
|
1455
|
+
cacheTime: v,
|
|
1456
|
+
market: d.market
|
|
1099
1457
|
});
|
|
1100
|
-
|
|
1458
|
+
o.moveCall({
|
|
1101
1459
|
target: `${f.uiGetter}::getter_unchecked::get_user_state`,
|
|
1102
|
-
arguments: [
|
|
1460
|
+
arguments: [o.object(f.storage), o.pure.address(d.address)]
|
|
1103
1461
|
});
|
|
1104
1462
|
}
|
|
1105
|
-
const m = (await
|
|
1106
|
-
transactionBlock:
|
|
1463
|
+
const m = (await q(n, {
|
|
1464
|
+
transactionBlock: o,
|
|
1107
1465
|
sender: e
|
|
1108
|
-
})).results || [],
|
|
1109
|
-
s.forEach((
|
|
1466
|
+
})).results || [], w = {};
|
|
1467
|
+
s.forEach((d, f) => {
|
|
1110
1468
|
try {
|
|
1111
|
-
const
|
|
1112
|
-
for (const T of
|
|
1113
|
-
|
|
1469
|
+
const b = m[f]?.returnValues?.map((T) => u.vector(Re).parse(Uint8Array.from(T[0])))[0] || [], k = {};
|
|
1470
|
+
for (const T of b)
|
|
1471
|
+
k[T.id] = {
|
|
1114
1472
|
supplyIndex: T.supply_index,
|
|
1115
1473
|
borrowIndex: T.borrow_index
|
|
1116
1474
|
};
|
|
1117
|
-
|
|
1118
|
-
} catch (
|
|
1475
|
+
w[d.key] = k;
|
|
1476
|
+
} catch (b) {
|
|
1119
1477
|
console.warn(
|
|
1120
|
-
`[@naviprotocol/lending] Failed to decode reserve data for market "${
|
|
1121
|
-
|
|
1478
|
+
`[@naviprotocol/lending] Failed to decode reserve data for market "${d.key}", falling back to open-api pool indices`,
|
|
1479
|
+
b
|
|
1122
1480
|
);
|
|
1123
1481
|
}
|
|
1124
1482
|
});
|
|
1125
|
-
const
|
|
1126
|
-
return
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
if (
|
|
1483
|
+
const y = m.slice(s.length).map((d) => d.returnValues?.map((f) => u.vector(Le).parse(Uint8Array.from(f[0])))[0] || []), g = [];
|
|
1484
|
+
return y.forEach((d, f) => {
|
|
1485
|
+
const b = t[f], k = _(b.market), T = w[k.key] || {};
|
|
1486
|
+
d.forEach((I) => {
|
|
1487
|
+
if (I.supply_balance === "0" && I.borrow_balance === "0" && (b.emodeId === void 0 || !r?.includeZeroBalanceEmodePositions))
|
|
1130
1488
|
return;
|
|
1131
|
-
const
|
|
1132
|
-
if (!
|
|
1489
|
+
const B = c[`${k.key}-${I.asset_id}`];
|
|
1490
|
+
if (!B)
|
|
1133
1491
|
return;
|
|
1134
|
-
const
|
|
1135
|
-
|
|
1136
|
-
supplyBalance:
|
|
1137
|
-
borrowBalance:
|
|
1138
|
-
assetId:
|
|
1139
|
-
market:
|
|
1140
|
-
pool:
|
|
1141
|
-
emodeId:
|
|
1492
|
+
const W = T[I.asset_id], Y = W?.supplyIndex ?? B.currentSupplyIndex, Pe = W?.borrowIndex ?? B.currentBorrowIndex, Ae = ue(I.supply_balance, Y).toString(), Se = ue(I.borrow_balance, Pe).toString();
|
|
1493
|
+
g.push({
|
|
1494
|
+
supplyBalance: Ae,
|
|
1495
|
+
borrowBalance: Se,
|
|
1496
|
+
assetId: I.asset_id,
|
|
1497
|
+
market: k.key,
|
|
1498
|
+
pool: B,
|
|
1499
|
+
emodeId: b.emodeId
|
|
1142
1500
|
});
|
|
1143
1501
|
});
|
|
1144
|
-
}),
|
|
1502
|
+
}), g;
|
|
1145
1503
|
}
|
|
1146
|
-
const
|
|
1504
|
+
const ir = $(
|
|
1147
1505
|
async (e, t) => {
|
|
1148
|
-
const
|
|
1506
|
+
const o = (t?.markets || Object.keys(F)).map((n) => _(n)).map((n) => ({
|
|
1149
1507
|
address: e,
|
|
1150
|
-
market:
|
|
1508
|
+
market: n.key
|
|
1151
1509
|
}));
|
|
1152
|
-
return await
|
|
1510
|
+
return await _e(e, o, t);
|
|
1153
1511
|
}
|
|
1154
1512
|
);
|
|
1155
|
-
async function
|
|
1156
|
-
const r = t?.client ?? V,
|
|
1157
|
-
await
|
|
1158
|
-
const
|
|
1159
|
-
transactionBlock:
|
|
1513
|
+
async function cr(e, t) {
|
|
1514
|
+
const r = t?.client ?? V, o = new N();
|
|
1515
|
+
await It(o, e, t);
|
|
1516
|
+
const n = await q(r, {
|
|
1517
|
+
transactionBlock: o,
|
|
1160
1518
|
sender: e
|
|
1161
|
-
}), a =
|
|
1162
|
-
return
|
|
1519
|
+
}), a = Q(n, [u.u256()]);
|
|
1520
|
+
return je(Number(a[0]) || 0);
|
|
1163
1521
|
}
|
|
1164
|
-
async function
|
|
1165
|
-
const
|
|
1522
|
+
async function sr(e, t, r, o) {
|
|
1523
|
+
const n = o?.client ?? V, a = new N();
|
|
1166
1524
|
let c = 0, i = 0;
|
|
1167
|
-
const s = await
|
|
1168
|
-
if (r.forEach((
|
|
1169
|
-
|
|
1525
|
+
const s = await S(t, o);
|
|
1526
|
+
if (r.forEach((y) => {
|
|
1527
|
+
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);
|
|
1170
1528
|
}), c * i < 0)
|
|
1171
1529
|
throw new Error("Invalid operations");
|
|
1172
|
-
const
|
|
1173
|
-
await
|
|
1530
|
+
const l = c > 0 || i > 0;
|
|
1531
|
+
await Ie(
|
|
1174
1532
|
a,
|
|
1175
1533
|
e,
|
|
1176
1534
|
s,
|
|
1177
1535
|
Math.abs(c),
|
|
1178
1536
|
Math.abs(i),
|
|
1179
|
-
|
|
1180
|
-
|
|
1537
|
+
l,
|
|
1538
|
+
o
|
|
1181
1539
|
);
|
|
1182
|
-
const m = await
|
|
1540
|
+
const m = await q(n, {
|
|
1183
1541
|
transactionBlock: a,
|
|
1184
1542
|
sender: e
|
|
1185
|
-
}),
|
|
1186
|
-
return
|
|
1543
|
+
}), w = Q(m, [u.u256()]);
|
|
1544
|
+
return je(Number(w[0]) || 0);
|
|
1187
1545
|
}
|
|
1188
|
-
const
|
|
1546
|
+
const lr = A(
|
|
1189
1547
|
async (e, t) => {
|
|
1190
1548
|
const r = new URLSearchParams();
|
|
1191
1549
|
t?.cursor && r.set("cursor", t.cursor), r.set("userAddress", e);
|
|
1192
|
-
const
|
|
1193
|
-
|
|
1550
|
+
const o = E(t), n = M(
|
|
1551
|
+
`/navi/user/transactions?${r.toString()}&sdk=${O.version}`,
|
|
1552
|
+
t
|
|
1553
|
+
);
|
|
1554
|
+
return (await fetch(n, {
|
|
1555
|
+
headers: D(U, o)
|
|
1556
|
+
}).then((c) => c.json())).data;
|
|
1194
1557
|
}
|
|
1195
1558
|
);
|
|
1196
|
-
async function
|
|
1559
|
+
async function ur(e, t) {
|
|
1197
1560
|
let r = null;
|
|
1198
|
-
const
|
|
1561
|
+
const o = [], n = t?.client ?? V, a = n.core;
|
|
1199
1562
|
do {
|
|
1200
|
-
let
|
|
1201
|
-
if (t?.coinType
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1563
|
+
let c;
|
|
1564
|
+
if (t?.coinType)
|
|
1565
|
+
if (typeof a?.listCoins == "function") {
|
|
1566
|
+
const i = await a.listCoins({
|
|
1567
|
+
owner: e,
|
|
1568
|
+
coinType: t?.coinType,
|
|
1569
|
+
cursor: r,
|
|
1570
|
+
limit: 100
|
|
1571
|
+
});
|
|
1572
|
+
c = {
|
|
1573
|
+
data: (i.objects ?? i.data ?? []).map((s) => pe(s, t?.coinType)).filter(Boolean),
|
|
1574
|
+
nextCursor: i.cursor ?? i.nextCursor ?? null,
|
|
1575
|
+
hasNextPage: i.hasNextPage ?? !1
|
|
1576
|
+
};
|
|
1577
|
+
} else {
|
|
1578
|
+
if (typeof n.getCoins != "function")
|
|
1579
|
+
throw new Error("getCoins requires core.listCoins or an explicit legacy getCoins client");
|
|
1580
|
+
c = await n.getCoins({
|
|
1581
|
+
owner: e,
|
|
1582
|
+
coinType: t?.coinType,
|
|
1583
|
+
cursor: r,
|
|
1584
|
+
limit: 100
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
else if (typeof a?.listBalances == "function" && typeof a?.listCoins == "function") {
|
|
1588
|
+
const i = /* @__PURE__ */ new Set();
|
|
1589
|
+
let s = null;
|
|
1590
|
+
do {
|
|
1591
|
+
const l = await a.listBalances({
|
|
1592
|
+
owner: e,
|
|
1593
|
+
cursor: s,
|
|
1594
|
+
limit: 100
|
|
1595
|
+
});
|
|
1596
|
+
for (const m of l.balances ?? [])
|
|
1597
|
+
m?.coinType && i.add(m.coinType);
|
|
1598
|
+
s = l.cursor ?? l.nextCursor ?? null;
|
|
1599
|
+
} while (s);
|
|
1600
|
+
for (const l of i) {
|
|
1601
|
+
let m = null;
|
|
1602
|
+
do {
|
|
1603
|
+
const w = await a.listCoins({
|
|
1604
|
+
owner: e,
|
|
1605
|
+
coinType: l,
|
|
1606
|
+
cursor: m,
|
|
1607
|
+
limit: 100
|
|
1608
|
+
});
|
|
1609
|
+
o.push(
|
|
1610
|
+
...(w.objects ?? w.data ?? []).map((y) => pe(y, l)).filter(Boolean)
|
|
1611
|
+
), m = w.cursor ?? w.nextCursor ?? null;
|
|
1612
|
+
} while (m);
|
|
1613
|
+
}
|
|
1211
1614
|
break;
|
|
1212
|
-
|
|
1615
|
+
} else {
|
|
1616
|
+
if (typeof n.getAllCoins != "function")
|
|
1617
|
+
throw new Error(
|
|
1618
|
+
"getCoins requires core.listBalances/core.listCoins or an explicit legacy getAllCoins client"
|
|
1619
|
+
);
|
|
1620
|
+
c = await n.getAllCoins({
|
|
1621
|
+
owner: e,
|
|
1622
|
+
cursor: r,
|
|
1623
|
+
limit: 100
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
if (!c.data || !c.data.length)
|
|
1627
|
+
break;
|
|
1628
|
+
o.push(...c.data), r = c.nextCursor;
|
|
1213
1629
|
} while (r);
|
|
1214
|
-
return
|
|
1630
|
+
return o;
|
|
1215
1631
|
}
|
|
1216
|
-
const
|
|
1632
|
+
const _t = $(
|
|
1217
1633
|
async (e, t) => {
|
|
1218
|
-
const r = [],
|
|
1219
|
-
let
|
|
1634
|
+
const r = [], o = (t?.markets || Object.keys(F)).map((i) => _(i));
|
|
1635
|
+
let n = [];
|
|
1220
1636
|
try {
|
|
1221
|
-
|
|
1637
|
+
n = await ke(e, t);
|
|
1222
1638
|
} catch (i) {
|
|
1223
1639
|
console.error(i);
|
|
1224
1640
|
}
|
|
1225
|
-
const a =
|
|
1641
|
+
const a = o.map((i) => ({
|
|
1226
1642
|
address: e,
|
|
1227
1643
|
market: i.key
|
|
1228
1644
|
})).concat(
|
|
1229
|
-
|
|
1645
|
+
n.filter((i) => !!o.find((s) => s.id === i.marketId)).map((i) => ({
|
|
1230
1646
|
address: i.accountCap,
|
|
1231
|
-
market:
|
|
1647
|
+
market: _(i.marketId).key,
|
|
1232
1648
|
emodeId: i.emodeId
|
|
1233
1649
|
}))
|
|
1234
1650
|
);
|
|
1235
|
-
return (await
|
|
1236
|
-
const s = typeof i.emodeId == "number" ?
|
|
1237
|
-
const m =
|
|
1238
|
-
return
|
|
1651
|
+
return (await _e(e, a, t)).forEach((i) => {
|
|
1652
|
+
const s = typeof i.emodeId == "number" ? n.find((l) => {
|
|
1653
|
+
const m = _(i.market);
|
|
1654
|
+
return l.emodeId === i.emodeId && l.marketId === m.id;
|
|
1239
1655
|
}) : void 0;
|
|
1240
1656
|
if (s) {
|
|
1241
1657
|
if (!i.pool.emodes.find((m) => m.emodeId === s.emodeId))
|
|
1242
1658
|
return;
|
|
1243
|
-
if (
|
|
1244
|
-
const m =
|
|
1245
|
-
if (m.gt(0) ||
|
|
1659
|
+
if (p(i.supplyBalance).gte(0)) {
|
|
1660
|
+
const m = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = H(i.pool, s);
|
|
1661
|
+
if (m.gt(0) || w.emode.isCollateral)
|
|
1246
1662
|
try {
|
|
1247
1663
|
r.push({
|
|
1248
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${
|
|
1664
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${P()}`,
|
|
1249
1665
|
wallet: e,
|
|
1250
1666
|
protocol: "navi",
|
|
1251
1667
|
market: i.market,
|
|
1252
1668
|
type: "navi-lending-emode-supply",
|
|
1253
1669
|
"navi-lending-emode-supply": {
|
|
1254
1670
|
amount: m.toString(),
|
|
1255
|
-
pool:
|
|
1671
|
+
pool: H(i.pool, s),
|
|
1256
1672
|
token: i.pool.token,
|
|
1257
1673
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1258
1674
|
emodeCap: s
|
|
1259
1675
|
}
|
|
1260
1676
|
});
|
|
1261
|
-
} catch (
|
|
1262
|
-
console.error(
|
|
1677
|
+
} catch (y) {
|
|
1678
|
+
console.error(y);
|
|
1263
1679
|
}
|
|
1264
1680
|
}
|
|
1265
|
-
if (
|
|
1266
|
-
const m =
|
|
1267
|
-
if (m.gt(0) ||
|
|
1681
|
+
if (p(i.borrowBalance).gte(0)) {
|
|
1682
|
+
const m = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN), w = H(i.pool, s);
|
|
1683
|
+
if (m.gt(0) || w.emode.isDebt)
|
|
1268
1684
|
try {
|
|
1269
1685
|
r.push({
|
|
1270
|
-
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${
|
|
1686
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${P()}`,
|
|
1271
1687
|
wallet: e,
|
|
1272
1688
|
protocol: "navi",
|
|
1273
1689
|
market: i.market,
|
|
1274
1690
|
type: "navi-lending-emode-borrow",
|
|
1275
1691
|
"navi-lending-emode-borrow": {
|
|
1276
1692
|
amount: m.toString(),
|
|
1277
|
-
pool:
|
|
1693
|
+
pool: H(i.pool, s),
|
|
1278
1694
|
token: i.pool.token,
|
|
1279
1695
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1280
1696
|
emodeCap: s
|
|
1281
1697
|
}
|
|
1282
1698
|
});
|
|
1283
|
-
} catch (
|
|
1284
|
-
console.error(
|
|
1699
|
+
} catch (y) {
|
|
1700
|
+
console.error(y);
|
|
1285
1701
|
}
|
|
1286
1702
|
}
|
|
1287
1703
|
} else {
|
|
1288
|
-
if (
|
|
1289
|
-
const
|
|
1704
|
+
if (p(i.supplyBalance).gt(0)) {
|
|
1705
|
+
const l = p(i.supplyBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1290
1706
|
r.push({
|
|
1291
|
-
id: `${i.pool.uniqueId}_navi-lending-supply-${
|
|
1707
|
+
id: `${i.pool.uniqueId}_navi-lending-supply-${P()}`,
|
|
1292
1708
|
wallet: e,
|
|
1293
1709
|
protocol: "navi",
|
|
1294
1710
|
type: "navi-lending-supply",
|
|
1295
1711
|
market: i.market,
|
|
1296
1712
|
"navi-lending-supply": {
|
|
1297
|
-
amount:
|
|
1713
|
+
amount: l.toString(),
|
|
1298
1714
|
pool: i.pool,
|
|
1299
1715
|
token: i.pool.token,
|
|
1300
|
-
valueUSD:
|
|
1716
|
+
valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
|
|
1301
1717
|
}
|
|
1302
1718
|
});
|
|
1303
1719
|
}
|
|
1304
|
-
if (
|
|
1305
|
-
const
|
|
1720
|
+
if (p(i.borrowBalance).gt(0)) {
|
|
1721
|
+
const l = p(i.borrowBalance).shiftedBy(-9).decimalPlaces(i.pool.token.decimals, p.ROUND_DOWN);
|
|
1306
1722
|
r.push({
|
|
1307
|
-
id: `${i.pool.uniqueId}_navi-lending-borrow-${
|
|
1723
|
+
id: `${i.pool.uniqueId}_navi-lending-borrow-${P()}`,
|
|
1308
1724
|
wallet: e,
|
|
1309
1725
|
protocol: "navi",
|
|
1310
1726
|
market: i.market,
|
|
1311
1727
|
type: "navi-lending-borrow",
|
|
1312
1728
|
"navi-lending-borrow": {
|
|
1313
|
-
amount:
|
|
1729
|
+
amount: l.toString(),
|
|
1314
1730
|
pool: i.pool,
|
|
1315
1731
|
token: i.pool.token,
|
|
1316
|
-
valueUSD:
|
|
1732
|
+
valueUSD: l.multipliedBy(i.pool.oracle.price).toString()
|
|
1317
1733
|
}
|
|
1318
1734
|
});
|
|
1319
1735
|
}
|
|
@@ -1321,7 +1737,7 @@ const qe = S(
|
|
|
1321
1737
|
}), r;
|
|
1322
1738
|
}
|
|
1323
1739
|
);
|
|
1324
|
-
class
|
|
1740
|
+
class L {
|
|
1325
1741
|
constructor(t, r) {
|
|
1326
1742
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1327
1743
|
hf: 1 / 0,
|
|
@@ -1353,256 +1769,256 @@ class D {
|
|
|
1353
1769
|
return this._priceMap = t, this._overview = this.getPositionsOverview(this._positions), this;
|
|
1354
1770
|
}
|
|
1355
1771
|
getPrice(t) {
|
|
1356
|
-
const r =
|
|
1772
|
+
const r = C(t.suiCoinType);
|
|
1357
1773
|
if (this._priceMap[r] !== void 0)
|
|
1358
1774
|
return this._priceMap[r].toString();
|
|
1359
|
-
const
|
|
1360
|
-
return this._priceMap[
|
|
1775
|
+
const o = t.suiCoinType;
|
|
1776
|
+
return this._priceMap[o] !== void 0 ? this._priceMap[o].toString() : t.oracle.price;
|
|
1361
1777
|
}
|
|
1362
1778
|
filterPositionsByPool(t) {
|
|
1363
|
-
const
|
|
1364
|
-
return new
|
|
1365
|
-
this.positions.filter((
|
|
1366
|
-
const a =
|
|
1367
|
-
return
|
|
1779
|
+
const o = !!t.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1780
|
+
return new L(
|
|
1781
|
+
this.positions.filter((n) => {
|
|
1782
|
+
const a = n[n.type];
|
|
1783
|
+
return o.includes(n.type) && a.pool.uniqueId === t.uniqueId;
|
|
1368
1784
|
}),
|
|
1369
1785
|
this._priceMap
|
|
1370
1786
|
);
|
|
1371
1787
|
}
|
|
1372
1788
|
deposit(t, r) {
|
|
1373
|
-
const
|
|
1789
|
+
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1374
1790
|
let a;
|
|
1375
|
-
return
|
|
1376
|
-
id:
|
|
1791
|
+
return o ? a = {
|
|
1792
|
+
id: P(),
|
|
1377
1793
|
wallet: "",
|
|
1378
1794
|
protocol: "navi",
|
|
1379
1795
|
market: "",
|
|
1380
1796
|
type: "navi-lending-emode-supply",
|
|
1381
1797
|
"navi-lending-emode-supply": {
|
|
1382
1798
|
amount: r.toString(),
|
|
1383
|
-
valueUSD:
|
|
1799
|
+
valueUSD: p(r).multipliedBy(n).toString(),
|
|
1384
1800
|
token: t.token,
|
|
1385
1801
|
pool: t,
|
|
1386
1802
|
emodeCap: {}
|
|
1387
1803
|
}
|
|
1388
1804
|
} : a = {
|
|
1389
|
-
id:
|
|
1805
|
+
id: P(),
|
|
1390
1806
|
wallet: "",
|
|
1391
1807
|
protocol: "navi",
|
|
1392
1808
|
market: "",
|
|
1393
1809
|
type: "navi-lending-supply",
|
|
1394
1810
|
"navi-lending-supply": {
|
|
1395
1811
|
amount: r.toString(),
|
|
1396
|
-
valueUSD:
|
|
1812
|
+
valueUSD: p(r).multipliedBy(n).toString(),
|
|
1397
1813
|
token: t.token,
|
|
1398
1814
|
pool: t
|
|
1399
1815
|
}
|
|
1400
|
-
}, new
|
|
1816
|
+
}, new L([...this.positions, a], this._priceMap);
|
|
1401
1817
|
}
|
|
1402
1818
|
withdraw(t, r) {
|
|
1403
|
-
const
|
|
1819
|
+
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1404
1820
|
let a;
|
|
1405
|
-
return
|
|
1406
|
-
id:
|
|
1821
|
+
return o ? a = {
|
|
1822
|
+
id: P(),
|
|
1407
1823
|
wallet: "",
|
|
1408
1824
|
protocol: "navi",
|
|
1409
1825
|
market: "",
|
|
1410
1826
|
type: "navi-lending-emode-supply",
|
|
1411
1827
|
"navi-lending-emode-supply": {
|
|
1412
1828
|
amount: (-r).toString(),
|
|
1413
|
-
valueUSD:
|
|
1829
|
+
valueUSD: p(-r).multipliedBy(n).toString(),
|
|
1414
1830
|
token: t.token,
|
|
1415
1831
|
pool: t,
|
|
1416
1832
|
emodeCap: {}
|
|
1417
1833
|
}
|
|
1418
1834
|
} : a = {
|
|
1419
|
-
id:
|
|
1835
|
+
id: P(),
|
|
1420
1836
|
wallet: "",
|
|
1421
1837
|
protocol: "navi",
|
|
1422
1838
|
market: "",
|
|
1423
1839
|
type: "navi-lending-supply",
|
|
1424
1840
|
"navi-lending-supply": {
|
|
1425
1841
|
amount: (-r).toString(),
|
|
1426
|
-
valueUSD:
|
|
1842
|
+
valueUSD: p(-r).multipliedBy(n).toString(),
|
|
1427
1843
|
token: t.token,
|
|
1428
1844
|
pool: t
|
|
1429
1845
|
}
|
|
1430
|
-
}, new
|
|
1846
|
+
}, new L([...this.positions, a], this._priceMap);
|
|
1431
1847
|
}
|
|
1432
1848
|
borrow(t, r) {
|
|
1433
|
-
const
|
|
1849
|
+
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1434
1850
|
let a;
|
|
1435
|
-
return
|
|
1436
|
-
id:
|
|
1851
|
+
return o ? a = {
|
|
1852
|
+
id: P(),
|
|
1437
1853
|
wallet: "",
|
|
1438
1854
|
protocol: "navi",
|
|
1439
1855
|
market: "",
|
|
1440
1856
|
type: "navi-lending-emode-borrow",
|
|
1441
1857
|
"navi-lending-emode-borrow": {
|
|
1442
1858
|
amount: r.toString(),
|
|
1443
|
-
valueUSD:
|
|
1859
|
+
valueUSD: p(r).multipliedBy(n).toString(),
|
|
1444
1860
|
token: t.token,
|
|
1445
1861
|
pool: t,
|
|
1446
1862
|
emodeCap: {}
|
|
1447
1863
|
}
|
|
1448
1864
|
} : a = {
|
|
1449
|
-
id:
|
|
1865
|
+
id: P(),
|
|
1450
1866
|
wallet: "",
|
|
1451
1867
|
protocol: "navi",
|
|
1452
1868
|
market: "",
|
|
1453
1869
|
type: "navi-lending-borrow",
|
|
1454
1870
|
"navi-lending-borrow": {
|
|
1455
1871
|
amount: r.toString(),
|
|
1456
|
-
valueUSD:
|
|
1872
|
+
valueUSD: p(r).multipliedBy(n).toString(),
|
|
1457
1873
|
token: t.token,
|
|
1458
1874
|
pool: t
|
|
1459
1875
|
}
|
|
1460
|
-
}, new
|
|
1876
|
+
}, new L([...this.positions, a], this._priceMap);
|
|
1461
1877
|
}
|
|
1462
1878
|
repay(t, r) {
|
|
1463
|
-
const
|
|
1879
|
+
const o = !!t.isEMode, n = this.getPrice(t);
|
|
1464
1880
|
let a;
|
|
1465
|
-
return
|
|
1466
|
-
id:
|
|
1881
|
+
return o ? a = {
|
|
1882
|
+
id: P(),
|
|
1467
1883
|
wallet: "",
|
|
1468
1884
|
protocol: "navi",
|
|
1469
1885
|
market: "",
|
|
1470
1886
|
type: "navi-lending-emode-borrow",
|
|
1471
1887
|
"navi-lending-emode-borrow": {
|
|
1472
1888
|
amount: (-r).toString(),
|
|
1473
|
-
valueUSD:
|
|
1889
|
+
valueUSD: p(-r).multipliedBy(n).toString(),
|
|
1474
1890
|
token: t.token,
|
|
1475
1891
|
pool: t,
|
|
1476
1892
|
emodeCap: {}
|
|
1477
1893
|
}
|
|
1478
1894
|
} : a = {
|
|
1479
|
-
id:
|
|
1895
|
+
id: P(),
|
|
1480
1896
|
wallet: "",
|
|
1481
1897
|
protocol: "navi",
|
|
1482
1898
|
market: "",
|
|
1483
1899
|
type: "navi-lending-borrow",
|
|
1484
1900
|
"navi-lending-borrow": {
|
|
1485
1901
|
amount: (-r).toString(),
|
|
1486
|
-
valueUSD:
|
|
1902
|
+
valueUSD: p(-r).multipliedBy(n).toString(),
|
|
1487
1903
|
token: t.token,
|
|
1488
1904
|
pool: t
|
|
1489
1905
|
}
|
|
1490
|
-
}, new
|
|
1906
|
+
}, new L([...this.positions, a], this._priceMap);
|
|
1491
1907
|
}
|
|
1492
1908
|
resolveValueUSD(t) {
|
|
1493
|
-
return Object.keys(this._priceMap).length > 0 ?
|
|
1909
|
+
return Object.keys(this._priceMap).length > 0 ? p(t.amount).multipliedBy(this.getPrice(t.pool)).toString() : t.valueUSD;
|
|
1494
1910
|
}
|
|
1495
1911
|
getPositionsOverview(t) {
|
|
1496
|
-
const r = {},
|
|
1497
|
-
let
|
|
1498
|
-
t.forEach((
|
|
1499
|
-
if (
|
|
1500
|
-
const
|
|
1501
|
-
|
|
1502
|
-
new
|
|
1503
|
-
),
|
|
1504
|
-
new
|
|
1912
|
+
const r = {}, o = {};
|
|
1913
|
+
let n = new p(0), a = new p(0), c = new p(0), i = new p(0), s = new p(0), l = new p(0);
|
|
1914
|
+
t.forEach((g) => {
|
|
1915
|
+
if (g.type === "navi-lending-supply") {
|
|
1916
|
+
const d = g["navi-lending-supply"], f = this.resolveValueUSD(d);
|
|
1917
|
+
n = n.plus(f), s = s.plus(
|
|
1918
|
+
new p(f).multipliedBy(d.pool.liquidationFactor.threshold)
|
|
1919
|
+
), l = l.plus(
|
|
1920
|
+
new p(f).multipliedBy(d.pool.ltvValue)
|
|
1505
1921
|
);
|
|
1506
|
-
} else if (
|
|
1507
|
-
const
|
|
1508
|
-
a = a.plus(this.resolveValueUSD(
|
|
1509
|
-
} else if (
|
|
1510
|
-
const
|
|
1511
|
-
|
|
1512
|
-
const
|
|
1922
|
+
} else if (g.type === "navi-lending-borrow") {
|
|
1923
|
+
const d = g["navi-lending-borrow"];
|
|
1924
|
+
a = a.plus(this.resolveValueUSD(d));
|
|
1925
|
+
} else if (g.type === "navi-lending-emode-supply") {
|
|
1926
|
+
const d = g["navi-lending-emode-supply"], f = this.resolveValueUSD(d);
|
|
1927
|
+
n = n.plus(f);
|
|
1928
|
+
const b = d.pool.emode;
|
|
1513
1929
|
s = s.plus(
|
|
1514
|
-
new
|
|
1515
|
-
),
|
|
1516
|
-
new
|
|
1930
|
+
new p(f).multipliedBy(b.lt)
|
|
1931
|
+
), l = l.plus(
|
|
1932
|
+
new p(f).multipliedBy(b.ltv)
|
|
1517
1933
|
);
|
|
1518
|
-
} else if (
|
|
1519
|
-
const
|
|
1520
|
-
a = a.plus(this.resolveValueUSD(
|
|
1934
|
+
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1935
|
+
const d = g["navi-lending-emode-borrow"];
|
|
1936
|
+
a = a.plus(this.resolveValueUSD(d));
|
|
1521
1937
|
}
|
|
1522
|
-
}), a =
|
|
1523
|
-
if (
|
|
1524
|
-
const
|
|
1525
|
-
|
|
1526
|
-
new
|
|
1527
|
-
)), r[
|
|
1528
|
-
} else if (
|
|
1529
|
-
const
|
|
1938
|
+
}), a = p.max(a, 0), n = p.max(n, 0), s = p.max(s, 0), l = p.max(l, 0), t.forEach((g) => {
|
|
1939
|
+
if (g.type === "navi-lending-supply") {
|
|
1940
|
+
const d = g["navi-lending-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
|
|
1941
|
+
n.gt(0) && (c = c.plus(
|
|
1942
|
+
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1943
|
+
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1944
|
+
} else if (g.type === "navi-lending-borrow") {
|
|
1945
|
+
const d = g["navi-lending-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
|
|
1530
1946
|
a.gt(0) && (i = i.plus(
|
|
1531
|
-
new
|
|
1532
|
-
)),
|
|
1533
|
-
} else if (
|
|
1534
|
-
const
|
|
1535
|
-
|
|
1536
|
-
new
|
|
1537
|
-
)), r[
|
|
1538
|
-
} else if (
|
|
1539
|
-
const
|
|
1947
|
+
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1948
|
+
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1949
|
+
} else if (g.type === "navi-lending-emode-supply") {
|
|
1950
|
+
const d = g["navi-lending-emode-supply"], f = this.resolveValueUSD(d), b = d.pool.supplyIncentiveApyInfo.apy;
|
|
1951
|
+
n.gt(0) && (c = c.plus(
|
|
1952
|
+
new p(f).dividedBy(n).multipliedBy(new p(b).dividedBy(100))
|
|
1953
|
+
)), r[d.pool.suiCoinType] = p(r[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1954
|
+
} else if (g.type === "navi-lending-emode-borrow") {
|
|
1955
|
+
const d = g["navi-lending-emode-borrow"], f = this.resolveValueUSD(d), b = d.pool.borrowIncentiveApyInfo.apy;
|
|
1540
1956
|
a.gt(0) && (i = i.plus(
|
|
1541
|
-
new
|
|
1542
|
-
)),
|
|
1957
|
+
new p(f).dividedBy(a).multipliedBy(new p(b).dividedBy(100))
|
|
1958
|
+
)), o[d.pool.suiCoinType] = p(o[d.pool.suiCoinType] || 0).plus(d.amount).toString();
|
|
1543
1959
|
}
|
|
1544
1960
|
});
|
|
1545
|
-
const m =
|
|
1961
|
+
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));
|
|
1546
1962
|
return {
|
|
1547
1963
|
hf: a.toNumber() !== 0 ? s.dividedBy(a).toNumber() : 1 / 0,
|
|
1548
1964
|
netVaule: m.toString(),
|
|
1549
|
-
netWorthApr:
|
|
1550
|
-
totalSupplyValue:
|
|
1965
|
+
netWorthApr: w.toString(),
|
|
1966
|
+
totalSupplyValue: n.toString(),
|
|
1551
1967
|
totalBorrowValue: a.toString(),
|
|
1552
1968
|
totalsupplyApy: c.toString(),
|
|
1553
1969
|
totalBorrowApy: i.toString(),
|
|
1554
1970
|
maxLiquidationValue: s.toString(),
|
|
1555
|
-
maxLoanToVaule:
|
|
1971
|
+
maxLoanToVaule: l.toString(),
|
|
1556
1972
|
supply: r,
|
|
1557
|
-
borrow:
|
|
1973
|
+
borrow: o
|
|
1558
1974
|
};
|
|
1559
1975
|
}
|
|
1560
1976
|
}
|
|
1561
|
-
async function
|
|
1562
|
-
const
|
|
1563
|
-
...
|
|
1564
|
-
cacheTime:
|
|
1977
|
+
async function dr(e, t, r, o) {
|
|
1978
|
+
const n = await j({
|
|
1979
|
+
...o,
|
|
1980
|
+
cacheTime: v
|
|
1565
1981
|
});
|
|
1566
|
-
|
|
1567
|
-
target: `${
|
|
1982
|
+
n.limter && e.moveCall({
|
|
1983
|
+
target: `${n.limter}::navi_adaptor::verify_navi_position_healthy`,
|
|
1568
1984
|
arguments: [
|
|
1569
1985
|
e.object("0x06"),
|
|
1570
|
-
e.object(
|
|
1571
|
-
e.object(
|
|
1572
|
-
|
|
1573
|
-
e.pure.u256(new
|
|
1986
|
+
e.object(n.storage),
|
|
1987
|
+
e.object(n.priceOracle),
|
|
1988
|
+
h(t, e.pure.address),
|
|
1989
|
+
e.pure.u256(new p(r).shiftedBy(27).toNumber())
|
|
1574
1990
|
]
|
|
1575
1991
|
});
|
|
1576
1992
|
}
|
|
1577
|
-
const
|
|
1993
|
+
const Te = new he("https://hermes.pyth.network", {
|
|
1578
1994
|
timeout: 1e4
|
|
1579
1995
|
});
|
|
1580
|
-
async function
|
|
1996
|
+
async function pr(e) {
|
|
1581
1997
|
try {
|
|
1582
|
-
const t = [], r = await
|
|
1998
|
+
const t = [], r = await Te.getLatestPriceFeeds(e);
|
|
1583
1999
|
if (!r) return t;
|
|
1584
|
-
const
|
|
1585
|
-
for (const
|
|
1586
|
-
const a =
|
|
1587
|
-
if (a.publishTime >
|
|
2000
|
+
const o = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
2001
|
+
for (const n of r) {
|
|
2002
|
+
const a = n.getPriceUnchecked();
|
|
2003
|
+
if (a.publishTime > o) {
|
|
1588
2004
|
console.warn(
|
|
1589
|
-
`pyth price feed is invalid, id: ${
|
|
2005
|
+
`pyth price feed is invalid, id: ${n.id}, publish time: ${a.publishTime}, current timestamp: ${o}`
|
|
1590
2006
|
);
|
|
1591
2007
|
continue;
|
|
1592
2008
|
}
|
|
1593
|
-
|
|
1594
|
-
`stale price feed, id: ${
|
|
1595
|
-
), t.push(
|
|
2009
|
+
o - n.getPriceUnchecked().publishTime > 30 && (console.info(
|
|
2010
|
+
`stale price feed, id: ${n.id}, publish time: ${a.publishTime}, current timestamp: ${o}`
|
|
2011
|
+
), t.push(n.id));
|
|
1596
2012
|
}
|
|
1597
2013
|
return t;
|
|
1598
2014
|
} catch (t) {
|
|
1599
2015
|
throw new Error(`failed to get pyth stale price feed id, msg: ${t.message}`);
|
|
1600
2016
|
}
|
|
1601
2017
|
}
|
|
1602
|
-
async function
|
|
2018
|
+
async function Tt(e, t) {
|
|
1603
2019
|
try {
|
|
1604
|
-
const r = [],
|
|
1605
|
-
ids: Array.from(new Set(
|
|
2020
|
+
const r = [], o = t?.client ?? V, n = e.map((c) => c.priceInfoObject), a = await mt(o, {
|
|
2021
|
+
ids: Array.from(new Set(n)),
|
|
1606
2022
|
options: { showContent: !0 }
|
|
1607
2023
|
});
|
|
1608
2024
|
for (const c of a) {
|
|
@@ -1611,18 +2027,23 @@ async function Le(e, t) {
|
|
|
1611
2027
|
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
1612
2028
|
continue;
|
|
1613
2029
|
}
|
|
1614
|
-
const s = e.find((
|
|
2030
|
+
const s = e.find((f) => f.priceInfoObject == i.objectId);
|
|
1615
2031
|
if (!s) {
|
|
1616
2032
|
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
1617
2033
|
continue;
|
|
1618
2034
|
}
|
|
1619
|
-
const
|
|
2035
|
+
const l = i.content.fields?.price_info?.price_feed?.price, m = l?.price;
|
|
2036
|
+
if (!m) {
|
|
2037
|
+
console.warn(`unexpected pyth price struct, priceInfoObject: ${i.objectId}`);
|
|
2038
|
+
continue;
|
|
2039
|
+
}
|
|
2040
|
+
const { magnitude: w, negative: y } = m, g = l.conf, d = l.timestamp;
|
|
1620
2041
|
r.push({
|
|
1621
2042
|
priceFeedId: s.priceFeedId,
|
|
1622
2043
|
priceInfoObject: s.priceInfoObject,
|
|
1623
|
-
price:
|
|
1624
|
-
conf:
|
|
1625
|
-
publishTime: Number(
|
|
2044
|
+
price: y ? "-" + w : w,
|
|
2045
|
+
conf: g,
|
|
2046
|
+
publishTime: Number(d),
|
|
1626
2047
|
expiration: s.expiration
|
|
1627
2048
|
});
|
|
1628
2049
|
}
|
|
@@ -1632,21 +2053,21 @@ async function Le(e, t) {
|
|
|
1632
2053
|
return;
|
|
1633
2054
|
}
|
|
1634
2055
|
}
|
|
1635
|
-
async function
|
|
2056
|
+
async function Bt(e, t) {
|
|
1636
2057
|
try {
|
|
1637
|
-
const r = [],
|
|
1638
|
-
if (!
|
|
1639
|
-
const
|
|
1640
|
-
for (const a of
|
|
1641
|
-
if (a.publishTime >
|
|
2058
|
+
const r = [], o = await Tt(e, t);
|
|
2059
|
+
if (!o) return r;
|
|
2060
|
+
const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
2061
|
+
for (const a of o) {
|
|
2062
|
+
if (a.publishTime > n) {
|
|
1642
2063
|
console.warn(
|
|
1643
|
-
`pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${
|
|
2064
|
+
`pyth price feed is invalid, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${n}`
|
|
1644
2065
|
);
|
|
1645
2066
|
continue;
|
|
1646
2067
|
}
|
|
1647
2068
|
const c = a.expiration || 60;
|
|
1648
|
-
|
|
1649
|
-
`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${
|
|
2069
|
+
n - a.publishTime > c && (console.info(
|
|
2070
|
+
`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${n}`
|
|
1650
2071
|
), r.push(a.priceFeedId));
|
|
1651
2072
|
}
|
|
1652
2073
|
return r;
|
|
@@ -1654,204 +2075,209 @@ async function He(e, t) {
|
|
|
1654
2075
|
throw new Error(`failed to get pyth stale price feed id, msg: ${r.message}`);
|
|
1655
2076
|
}
|
|
1656
2077
|
}
|
|
1657
|
-
async function
|
|
1658
|
-
const
|
|
2078
|
+
async function Pt(e, t, r) {
|
|
2079
|
+
const o = r?.client ?? V, n = await j({
|
|
1659
2080
|
...r,
|
|
1660
|
-
cacheTime:
|
|
2081
|
+
cacheTime: v
|
|
1661
2082
|
});
|
|
1662
2083
|
try {
|
|
1663
|
-
const a = await
|
|
1664
|
-
return await new
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
2084
|
+
const a = await Te.getPriceFeedsUpdateData(t);
|
|
2085
|
+
return await new ct(
|
|
2086
|
+
o,
|
|
2087
|
+
n.oracle.pythStateId,
|
|
2088
|
+
n.oracle.wormholeStateId
|
|
1668
2089
|
).updatePriceFeeds(e, a, t);
|
|
1669
2090
|
} catch (a) {
|
|
1670
2091
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
1671
2092
|
}
|
|
1672
2093
|
}
|
|
1673
|
-
async function
|
|
1674
|
-
const
|
|
2094
|
+
async function At(e, t, r) {
|
|
2095
|
+
const o = await j({
|
|
1675
2096
|
...r,
|
|
1676
|
-
cacheTime:
|
|
2097
|
+
cacheTime: v
|
|
1677
2098
|
});
|
|
1678
2099
|
if (r?.updatePythPriceFeeds) {
|
|
1679
|
-
const
|
|
2100
|
+
const n = t.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
|
|
1680
2101
|
priceFeedId: a.pythPriceFeedId,
|
|
1681
2102
|
priceInfoObject: a.pythPriceInfoObject,
|
|
1682
2103
|
expiration: 30
|
|
1683
2104
|
}));
|
|
1684
2105
|
try {
|
|
1685
|
-
const a = await
|
|
1686
|
-
a.length > 0 && await
|
|
2106
|
+
const a = await Bt(n, r);
|
|
2107
|
+
a.length > 0 && await Pt(e, a, r);
|
|
1687
2108
|
} catch {
|
|
1688
2109
|
console.error("Failed to update Pyth price feeds");
|
|
1689
2110
|
}
|
|
1690
2111
|
}
|
|
1691
|
-
for (const
|
|
2112
|
+
for (const n of t)
|
|
1692
2113
|
r?.env === "dev" ? e.moveCall({
|
|
1693
|
-
target: `${
|
|
2114
|
+
target: `${o.oracle.packageId}::oracle_pro::update_single_price`,
|
|
1694
2115
|
arguments: [
|
|
1695
2116
|
e.object("0x6"),
|
|
1696
2117
|
// Clock object
|
|
1697
|
-
e.object(
|
|
2118
|
+
e.object(o.oracle.oracleConfig),
|
|
1698
2119
|
// Oracle configuration
|
|
1699
|
-
e.object(
|
|
2120
|
+
e.object(o.oracle.priceOracle),
|
|
1700
2121
|
// Price oracle contract
|
|
1701
|
-
e.object(
|
|
2122
|
+
e.object(o.oracle.supraOracleHolder),
|
|
1702
2123
|
// Supra oracle holder
|
|
1703
|
-
e.object(
|
|
2124
|
+
e.object(n.pythPriceInfoObject),
|
|
1704
2125
|
// Pyth price info object
|
|
1705
|
-
e.pure.address(
|
|
2126
|
+
e.pure.address(n.feedId)
|
|
1706
2127
|
// Price feed ID
|
|
1707
2128
|
]
|
|
1708
2129
|
}) : e.moveCall({
|
|
1709
|
-
target: `${
|
|
2130
|
+
target: `${o.oracle.packageId}::oracle_pro::update_single_price_v2`,
|
|
1710
2131
|
arguments: [
|
|
1711
2132
|
e.object("0x6"),
|
|
1712
2133
|
// Clock object
|
|
1713
|
-
e.object(
|
|
2134
|
+
e.object(o.oracle.oracleConfig),
|
|
1714
2135
|
// Oracle configuration
|
|
1715
|
-
e.object(
|
|
2136
|
+
e.object(o.oracle.priceOracle),
|
|
1716
2137
|
// Price oracle contract
|
|
1717
|
-
e.object(
|
|
2138
|
+
e.object(o.oracle.supraOracleHolder),
|
|
1718
2139
|
// Supra oracle holder
|
|
1719
|
-
e.object(
|
|
2140
|
+
e.object(n.pythPriceInfoObject),
|
|
1720
2141
|
// Pyth price info object
|
|
1721
|
-
e.object(
|
|
1722
|
-
e.pure.address(
|
|
2142
|
+
e.object(o.oracle.switchboardAggregator),
|
|
2143
|
+
e.pure.address(n.feedId)
|
|
1723
2144
|
// Price feed ID
|
|
1724
2145
|
]
|
|
1725
2146
|
});
|
|
1726
2147
|
return e;
|
|
1727
2148
|
}
|
|
1728
|
-
async function
|
|
1729
|
-
return (await
|
|
2149
|
+
async function Be(e) {
|
|
2150
|
+
return (await j({
|
|
1730
2151
|
...e,
|
|
1731
|
-
cacheTime:
|
|
2152
|
+
cacheTime: v
|
|
1732
2153
|
})).oracle.feeds;
|
|
1733
2154
|
}
|
|
1734
|
-
function
|
|
1735
|
-
return e.filter((r) => !!(t?.lendingState && t.lendingState.find((
|
|
2155
|
+
function St(e, t) {
|
|
2156
|
+
return e.filter((r) => !!(t?.lendingState && t.lendingState.find((n) => r.oracleId === n.pool.oracleId) || t?.lendingPositions && t.lendingPositions.find((n) => {
|
|
1736
2157
|
if (![
|
|
1737
2158
|
"navi-lending-supply",
|
|
1738
2159
|
"navi-lending-borrow",
|
|
1739
2160
|
"navi-lending-emode-supply",
|
|
1740
2161
|
"navi-lending-emode-borrow"
|
|
1741
|
-
].includes(
|
|
2162
|
+
].includes(n.type))
|
|
1742
2163
|
return !1;
|
|
1743
|
-
const c =
|
|
2164
|
+
const c = n[n.type]?.pool;
|
|
1744
2165
|
return r.oracleId === c?.oracleId;
|
|
1745
|
-
}) || t?.pools && t.pools.find((
|
|
2166
|
+
}) || t?.pools && t.pools.find((n) => r.oracleId === n.oracleId)));
|
|
1746
2167
|
}
|
|
1747
|
-
async function
|
|
2168
|
+
async function mr(e, t, r, o) {
|
|
1748
2169
|
try {
|
|
1749
|
-
const
|
|
1750
|
-
...
|
|
2170
|
+
const n = await Be({
|
|
2171
|
+
...o
|
|
1751
2172
|
}), a = [];
|
|
1752
|
-
r.forEach((
|
|
1753
|
-
a.includes(
|
|
2173
|
+
r.forEach((l) => {
|
|
2174
|
+
a.includes(l.market) || a.push(l.market);
|
|
1754
2175
|
});
|
|
1755
|
-
const c = await
|
|
1756
|
-
...
|
|
2176
|
+
const c = await _t(t, {
|
|
2177
|
+
...o,
|
|
1757
2178
|
markets: a
|
|
1758
|
-
}), i =
|
|
2179
|
+
}), i = St(n, {
|
|
1759
2180
|
lendingPositions: c,
|
|
1760
2181
|
pools: r
|
|
1761
2182
|
});
|
|
1762
|
-
return await
|
|
2183
|
+
return await At(e, i, {
|
|
1763
2184
|
updatePythPriceFeeds: !0,
|
|
1764
|
-
...
|
|
2185
|
+
...o
|
|
1765
2186
|
});
|
|
1766
|
-
} catch (
|
|
1767
|
-
if (
|
|
1768
|
-
throw
|
|
1769
|
-
return console.error(
|
|
2187
|
+
} catch (n) {
|
|
2188
|
+
if (o?.throws)
|
|
2189
|
+
throw n;
|
|
2190
|
+
return console.error(n), e;
|
|
1770
2191
|
}
|
|
1771
2192
|
}
|
|
1772
|
-
const
|
|
2193
|
+
const re = $(
|
|
1773
2194
|
A(
|
|
1774
2195
|
async (e) => {
|
|
1775
|
-
const t =
|
|
1776
|
-
|
|
1777
|
-
|
|
2196
|
+
const t = E(e), r = M(
|
|
2197
|
+
`/navi/flashloan?env=${e?.env || "prod"}&sdk=${O.version}&market=${e?.market || R}`,
|
|
2198
|
+
e
|
|
2199
|
+
), o = await fetch(r, {
|
|
2200
|
+
headers: D(U, t)
|
|
2201
|
+
}).then((n) => n.json());
|
|
2202
|
+
return Object.keys(o.data).map((n) => ({
|
|
2203
|
+
...o.data[n],
|
|
1778
2204
|
coinType: n
|
|
1779
2205
|
}));
|
|
1780
2206
|
}
|
|
1781
2207
|
)
|
|
1782
2208
|
);
|
|
1783
|
-
async function
|
|
1784
|
-
return (await
|
|
2209
|
+
async function fr(e, t) {
|
|
2210
|
+
return (await re(t)).find((o) => typeof e == "string" ? C(o.coinType) === C(e) : typeof e == "number" ? o.assetId === e : o.assetId === e.id) || null;
|
|
1785
2211
|
}
|
|
1786
|
-
async function
|
|
1787
|
-
const
|
|
1788
|
-
...
|
|
1789
|
-
cacheTime:
|
|
1790
|
-
}), a = await
|
|
1791
|
-
if (!(await
|
|
1792
|
-
...
|
|
1793
|
-
cacheTime:
|
|
2212
|
+
async function yr(e, t, r, o) {
|
|
2213
|
+
const n = await j({
|
|
2214
|
+
...o,
|
|
2215
|
+
cacheTime: v
|
|
2216
|
+
}), a = await S(t, o);
|
|
2217
|
+
if (!(await re({
|
|
2218
|
+
...o,
|
|
2219
|
+
cacheTime: v
|
|
1794
2220
|
})).some(
|
|
1795
|
-
(s) =>
|
|
2221
|
+
(s) => C(s.coinType) === C(a.suiCoinType)
|
|
1796
2222
|
))
|
|
1797
2223
|
throw new Error("Pool does not support flashloan");
|
|
1798
|
-
if (
|
|
1799
|
-
const [s,
|
|
1800
|
-
target: `${
|
|
2224
|
+
if (n.version === 1) {
|
|
2225
|
+
const [s, l] = e.moveCall({
|
|
2226
|
+
target: `${n.package}::lending::flash_loan_with_ctx`,
|
|
1801
2227
|
arguments: [
|
|
1802
|
-
e.object(
|
|
2228
|
+
e.object(n.flashloanConfig),
|
|
1803
2229
|
e.object(a.contract.pool),
|
|
1804
|
-
|
|
2230
|
+
h(r, e.pure.u64)
|
|
1805
2231
|
],
|
|
1806
2232
|
typeArguments: [a.suiCoinType]
|
|
1807
2233
|
});
|
|
1808
|
-
return [s,
|
|
2234
|
+
return [s, l];
|
|
1809
2235
|
} else {
|
|
1810
|
-
const [s,
|
|
1811
|
-
target: `${
|
|
2236
|
+
const [s, l] = e.moveCall({
|
|
2237
|
+
target: `${n.package}::lending::flash_loan_with_ctx_v2`,
|
|
1812
2238
|
arguments: [
|
|
1813
|
-
e.object(
|
|
2239
|
+
e.object(n.flashloanConfig),
|
|
1814
2240
|
e.object(a.contract.pool),
|
|
1815
|
-
|
|
2241
|
+
h(r, e.pure.u64),
|
|
1816
2242
|
e.object("0x05")
|
|
1817
2243
|
],
|
|
1818
2244
|
typeArguments: [a.suiCoinType]
|
|
1819
2245
|
});
|
|
1820
|
-
return [s,
|
|
2246
|
+
return [s, l];
|
|
1821
2247
|
}
|
|
1822
2248
|
}
|
|
1823
|
-
async function
|
|
1824
|
-
const a = await
|
|
1825
|
-
...
|
|
1826
|
-
cacheTime:
|
|
1827
|
-
}), c = await
|
|
1828
|
-
if (!(await
|
|
1829
|
-
...
|
|
1830
|
-
cacheTime:
|
|
2249
|
+
async function gr(e, t, r, o, n) {
|
|
2250
|
+
const a = await j({
|
|
2251
|
+
...n,
|
|
2252
|
+
cacheTime: v
|
|
2253
|
+
}), c = await S(t, n);
|
|
2254
|
+
if (!(await re({
|
|
2255
|
+
...n,
|
|
2256
|
+
cacheTime: v
|
|
1831
2257
|
})).some(
|
|
1832
|
-
(m) =>
|
|
2258
|
+
(m) => C(m.coinType) === C(c.suiCoinType)
|
|
1833
2259
|
))
|
|
1834
2260
|
throw new Error("Pool does not support flashloan");
|
|
1835
|
-
const [
|
|
2261
|
+
const [l] = e.moveCall({
|
|
1836
2262
|
target: `${a.package}::lending::flash_repay_with_ctx`,
|
|
1837
2263
|
arguments: [
|
|
1838
2264
|
e.object("0x06"),
|
|
1839
2265
|
e.object(a.storage),
|
|
1840
2266
|
e.object(c.contract.pool),
|
|
1841
|
-
|
|
1842
|
-
|
|
2267
|
+
h(r, e.object),
|
|
2268
|
+
h(o, e.object)
|
|
1843
2269
|
],
|
|
1844
2270
|
typeArguments: [c.suiCoinType]
|
|
1845
2271
|
});
|
|
1846
|
-
return [
|
|
2272
|
+
return [l];
|
|
1847
2273
|
}
|
|
1848
|
-
async function
|
|
2274
|
+
async function hr(e, t, r, o, n, a) {
|
|
1849
2275
|
const c = {
|
|
1850
2276
|
...a,
|
|
1851
|
-
cacheTime:
|
|
1852
|
-
}, i = await
|
|
2277
|
+
cacheTime: v
|
|
2278
|
+
}, i = await j(c), s = await S(t, c), l = await S(o, c);
|
|
1853
2279
|
if (i.version === 1) {
|
|
1854
|
-
const [m,
|
|
2280
|
+
const [m, w] = e.moveCall({
|
|
1855
2281
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
1856
2282
|
arguments: [
|
|
1857
2283
|
e.object("0x06"),
|
|
@@ -1864,24 +2290,24 @@ async function Tt(e, t, r, n, o, a) {
|
|
|
1864
2290
|
// Pay asset ID
|
|
1865
2291
|
e.object(s.contract.pool),
|
|
1866
2292
|
// Pay asset pool contract
|
|
1867
|
-
|
|
2293
|
+
h(r, e.object),
|
|
1868
2294
|
// Debt repayment amount
|
|
1869
|
-
e.pure.u8(
|
|
2295
|
+
e.pure.u8(l.id),
|
|
1870
2296
|
// Collateral asset ID
|
|
1871
|
-
e.object(
|
|
2297
|
+
e.object(l.contract.pool),
|
|
1872
2298
|
// Collateral asset pool contract
|
|
1873
|
-
|
|
2299
|
+
h(n, e.pure.address),
|
|
1874
2300
|
// Borrower address
|
|
1875
2301
|
e.object(i.incentiveV2),
|
|
1876
2302
|
// Incentive V2 contract
|
|
1877
2303
|
e.object(i.incentiveV3)
|
|
1878
2304
|
// Incentive V3 contract
|
|
1879
2305
|
],
|
|
1880
|
-
typeArguments: [s.suiCoinType,
|
|
2306
|
+
typeArguments: [s.suiCoinType, l.suiCoinType]
|
|
1881
2307
|
});
|
|
1882
|
-
return [m,
|
|
2308
|
+
return [m, w];
|
|
1883
2309
|
} else {
|
|
1884
|
-
const [m,
|
|
2310
|
+
const [m, w] = e.moveCall({
|
|
1885
2311
|
target: `${i.package}::incentive_v3::liquidation_v2`,
|
|
1886
2312
|
arguments: [
|
|
1887
2313
|
e.object("0x06"),
|
|
@@ -1894,13 +2320,13 @@ async function Tt(e, t, r, n, o, a) {
|
|
|
1894
2320
|
// Pay asset ID
|
|
1895
2321
|
e.object(s.contract.pool),
|
|
1896
2322
|
// Pay asset pool contract
|
|
1897
|
-
|
|
2323
|
+
h(r, e.object),
|
|
1898
2324
|
// Debt repayment amount
|
|
1899
|
-
e.pure.u8(
|
|
2325
|
+
e.pure.u8(l.id),
|
|
1900
2326
|
// Collateral asset ID
|
|
1901
|
-
e.object(
|
|
2327
|
+
e.object(l.contract.pool),
|
|
1902
2328
|
// Collateral asset pool contract
|
|
1903
|
-
|
|
2329
|
+
h(n, e.pure.address),
|
|
1904
2330
|
// Borrower address
|
|
1905
2331
|
e.object(i.incentiveV2),
|
|
1906
2332
|
// Incentive V2 contract
|
|
@@ -1909,104 +2335,102 @@ async function Tt(e, t, r, n, o, a) {
|
|
|
1909
2335
|
e.object("0x05")
|
|
1910
2336
|
// SuiSystemState object
|
|
1911
2337
|
],
|
|
1912
|
-
typeArguments: [s.suiCoinType,
|
|
2338
|
+
typeArguments: [s.suiCoinType, l.suiCoinType]
|
|
1913
2339
|
});
|
|
1914
|
-
return [m,
|
|
2340
|
+
return [m, w];
|
|
1915
2341
|
}
|
|
1916
2342
|
}
|
|
1917
|
-
async function
|
|
1918
|
-
const
|
|
2343
|
+
async function $t(e, t, r) {
|
|
2344
|
+
const o = r?.client ?? V, n = await G({
|
|
1919
2345
|
...r,
|
|
1920
|
-
markets: Object.values(
|
|
1921
|
-
cacheTime:
|
|
1922
|
-
}),
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
{
|
|
1951
|
-
|
|
1952
|
-
},
|
|
1953
|
-
[
|
|
1954
|
-
l.vector(l.string()),
|
|
2346
|
+
markets: Object.values(F),
|
|
2347
|
+
cacheTime: v
|
|
2348
|
+
}), a = await Be(r), c = [];
|
|
2349
|
+
return await Promise.all(
|
|
2350
|
+
t.map(async (i) => {
|
|
2351
|
+
try {
|
|
2352
|
+
const s = await j({
|
|
2353
|
+
...r,
|
|
2354
|
+
cacheTime: v,
|
|
2355
|
+
market: i.market
|
|
2356
|
+
}), l = new N();
|
|
2357
|
+
l.moveCall({
|
|
2358
|
+
target: `${s.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
2359
|
+
arguments: [
|
|
2360
|
+
l.object("0x06"),
|
|
2361
|
+
// Clock object
|
|
2362
|
+
l.object(s.storage),
|
|
2363
|
+
// Protocol storage
|
|
2364
|
+
l.object(s.incentiveV3),
|
|
2365
|
+
// Incentive V3 contract
|
|
2366
|
+
l.pure.address(i.address)
|
|
2367
|
+
// User address
|
|
2368
|
+
]
|
|
2369
|
+
});
|
|
2370
|
+
const w = (await q(o, {
|
|
2371
|
+
transactionBlock: l,
|
|
2372
|
+
sender: e
|
|
2373
|
+
}))?.results?.[0];
|
|
2374
|
+
if (!w)
|
|
2375
|
+
return;
|
|
2376
|
+
const y = Q({ results: [w] }, [
|
|
2377
|
+
u.vector(u.string()),
|
|
1955
2378
|
// Asset coin types
|
|
1956
|
-
|
|
2379
|
+
u.vector(u.string()),
|
|
1957
2380
|
// Reward coin types
|
|
1958
|
-
|
|
2381
|
+
u.vector(u.u8()),
|
|
1959
2382
|
// Reward options
|
|
1960
|
-
|
|
2383
|
+
u.vector(u.Address),
|
|
1961
2384
|
// Rule IDs
|
|
1962
|
-
|
|
2385
|
+
u.vector(u.u256())
|
|
1963
2386
|
// Claimable amounts
|
|
1964
|
-
]
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2387
|
+
]);
|
|
2388
|
+
if (y.length === 5 && Array.isArray(y[0])) {
|
|
2389
|
+
const g = y[0].length;
|
|
2390
|
+
for (let d = 0; d < g; d++) {
|
|
2391
|
+
const f = a.find(
|
|
2392
|
+
(k) => C(k.coinType) === C(y[1][d])
|
|
2393
|
+
), b = n.find(
|
|
2394
|
+
(k) => C(k.coinType) === C(y[0][d]) && k.market === i.market
|
|
2395
|
+
);
|
|
2396
|
+
!f || !b || c.push({
|
|
2397
|
+
assetId: b.id,
|
|
2398
|
+
assetCoinType: C(y[0][d]),
|
|
2399
|
+
rewardCoinType: C(y[1][d]),
|
|
2400
|
+
option: Number(y[2][d]),
|
|
2401
|
+
userClaimableReward: Number(y[4][d]) / Math.pow(10, f.priceDecimal),
|
|
2402
|
+
ruleIds: Array.isArray(y[3][d]) ? y[3][d] : [y[3][d]],
|
|
2403
|
+
market: i.market,
|
|
2404
|
+
owner: i.owner,
|
|
2405
|
+
address: i.address,
|
|
2406
|
+
emodeId: i.emodeId
|
|
2407
|
+
});
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
} catch (s) {
|
|
2411
|
+
console.error(
|
|
2412
|
+
`[lending] getLendingRewardsBatch task failed (market=${i.market}, address=${i.address}):`,
|
|
2413
|
+
s
|
|
1978
2414
|
);
|
|
1979
|
-
!f || !v || p.push({
|
|
1980
|
-
assetId: v.id,
|
|
1981
|
-
assetCoinType: k(m[0][u]),
|
|
1982
|
-
rewardCoinType: k(m[1][u]),
|
|
1983
|
-
option: Number(m[2][u]),
|
|
1984
|
-
userClaimableReward: Number(m[4][u]) / Math.pow(10, f.priceDecimal),
|
|
1985
|
-
ruleIds: Array.isArray(m[3][u]) ? m[3][u] : [m[3][u]],
|
|
1986
|
-
market: w.market,
|
|
1987
|
-
owner: w.owner,
|
|
1988
|
-
address: w.address,
|
|
1989
|
-
emodeId: w.emodeId
|
|
1990
|
-
});
|
|
1991
2415
|
}
|
|
1992
|
-
}
|
|
1993
|
-
|
|
2416
|
+
})
|
|
2417
|
+
), c;
|
|
1994
2418
|
}
|
|
1995
|
-
async function
|
|
1996
|
-
const r = (t?.markets || [
|
|
1997
|
-
let
|
|
2419
|
+
async function wr(e, t) {
|
|
2420
|
+
const r = (t?.markets || [F.main]).map((a) => _(a));
|
|
2421
|
+
let o = [];
|
|
1998
2422
|
try {
|
|
1999
|
-
|
|
2423
|
+
o = await ke(e, t);
|
|
2000
2424
|
} catch (a) {
|
|
2001
2425
|
console.error(a);
|
|
2002
2426
|
}
|
|
2003
|
-
const
|
|
2427
|
+
const n = r.map((a) => ({
|
|
2004
2428
|
address: e,
|
|
2005
2429
|
owner: e,
|
|
2006
2430
|
market: a.key
|
|
2007
2431
|
})).concat(
|
|
2008
|
-
|
|
2009
|
-
const c =
|
|
2432
|
+
o.filter((a) => !!r.find((c) => c.id === a.marketId)).map((a) => {
|
|
2433
|
+
const c = _(a.marketId);
|
|
2010
2434
|
return {
|
|
2011
2435
|
address: a.accountCap,
|
|
2012
2436
|
owner: e,
|
|
@@ -2015,100 +2439,110 @@ async function Pt(e, t) {
|
|
|
2015
2439
|
};
|
|
2016
2440
|
})
|
|
2017
2441
|
);
|
|
2018
|
-
return await
|
|
2442
|
+
return await $t(e, n, t);
|
|
2019
2443
|
}
|
|
2020
|
-
function
|
|
2444
|
+
function br(e) {
|
|
2021
2445
|
const t = /* @__PURE__ */ new Map();
|
|
2022
|
-
e.forEach((
|
|
2023
|
-
const
|
|
2024
|
-
t.has(c) ? t.get(c).total +=
|
|
2025
|
-
assetId:
|
|
2446
|
+
e.forEach((o) => {
|
|
2447
|
+
const n = o.assetId, a = o.option, c = `${n}-${a}-${o.rewardCoinType}-${o.market}`;
|
|
2448
|
+
t.has(c) ? t.get(c).total += o.userClaimableReward : t.set(c, {
|
|
2449
|
+
assetId: n,
|
|
2026
2450
|
rewardType: a,
|
|
2027
|
-
coinType:
|
|
2028
|
-
total: Number(
|
|
2029
|
-
market:
|
|
2451
|
+
coinType: o.rewardCoinType,
|
|
2452
|
+
total: Number(o.userClaimableReward),
|
|
2453
|
+
market: o.market
|
|
2030
2454
|
});
|
|
2031
2455
|
});
|
|
2032
2456
|
const r = /* @__PURE__ */ new Map();
|
|
2033
|
-
for (const { assetId:
|
|
2034
|
-
const s = `${
|
|
2035
|
-
r.has(s) || r.set(s, { assetId:
|
|
2036
|
-
const
|
|
2037
|
-
|
|
2038
|
-
}
|
|
2039
|
-
return Array.from(r.values()).map((
|
|
2040
|
-
assetId:
|
|
2041
|
-
rewardType:
|
|
2042
|
-
market:
|
|
2043
|
-
rewards: Array.from(
|
|
2044
|
-
coinType:
|
|
2457
|
+
for (const { assetId: o, rewardType: n, coinType: a, total: c, market: i } of t.values()) {
|
|
2458
|
+
const s = `${o}-${n}-${i}`;
|
|
2459
|
+
r.has(s) || r.set(s, { assetId: o, rewardType: n, market: i, rewards: /* @__PURE__ */ new Map() });
|
|
2460
|
+
const l = r.get(s);
|
|
2461
|
+
l.rewards.set(a, (l.rewards.get(a) || 0) + c);
|
|
2462
|
+
}
|
|
2463
|
+
return Array.from(r.values()).map((o) => ({
|
|
2464
|
+
assetId: o.assetId,
|
|
2465
|
+
rewardType: o.rewardType,
|
|
2466
|
+
market: o.market,
|
|
2467
|
+
rewards: Array.from(o.rewards.entries()).map(([n, a]) => ({
|
|
2468
|
+
coinType: n,
|
|
2045
2469
|
available: a.toFixed(6)
|
|
2046
2470
|
}))
|
|
2047
2471
|
}));
|
|
2048
2472
|
}
|
|
2049
|
-
const
|
|
2473
|
+
const vr = A(
|
|
2050
2474
|
async (e, t) => {
|
|
2051
|
-
const r =
|
|
2052
|
-
|
|
2475
|
+
const r = E(t), o = M(
|
|
2476
|
+
`/navi/user/total_claimed_reward?userAddress=${e}&sdk=${O.version}&market=${t?.market || R}`,
|
|
2477
|
+
t
|
|
2478
|
+
);
|
|
2479
|
+
return (await fetch(o, {
|
|
2480
|
+
headers: D(U, r)
|
|
2481
|
+
}).then((a) => a.json())).data;
|
|
2053
2482
|
}
|
|
2054
|
-
),
|
|
2483
|
+
), Cr = A(
|
|
2055
2484
|
async (e, t) => {
|
|
2056
|
-
const r =
|
|
2057
|
-
|
|
2485
|
+
const r = E(t), o = M(
|
|
2486
|
+
`/navi/user/rewards?userAddress=${e}&page=${t?.page || 1}&pageSize=${t?.size || 400}&sdk=${O.version}&market=${t?.market || R}`,
|
|
2487
|
+
t
|
|
2488
|
+
), n = await fetch(o, {
|
|
2489
|
+
headers: D(U, r)
|
|
2490
|
+
}).then((a) => a.json());
|
|
2491
|
+
return x({
|
|
2058
2492
|
data: n.data.rewards
|
|
2059
2493
|
});
|
|
2060
2494
|
}
|
|
2061
2495
|
);
|
|
2062
|
-
async function
|
|
2063
|
-
const
|
|
2496
|
+
async function jr(e, t, r) {
|
|
2497
|
+
const o = await G({
|
|
2064
2498
|
...r,
|
|
2065
|
-
markets: Object.values(
|
|
2066
|
-
cacheTime:
|
|
2067
|
-
}),
|
|
2499
|
+
markets: Object.values(F),
|
|
2500
|
+
cacheTime: v
|
|
2501
|
+
}), n = /* @__PURE__ */ new Map();
|
|
2068
2502
|
for (const c of t) {
|
|
2069
|
-
const { rewardCoinType: i, ruleIds: s, market:
|
|
2070
|
-
for (const
|
|
2071
|
-
|
|
2503
|
+
const { rewardCoinType: i, ruleIds: s, market: l, owner: m, address: w, emodeId: y } = c, g = `${i}___${w}__${l}`;
|
|
2504
|
+
for (const d of s) {
|
|
2505
|
+
n.has(g) || n.set(g, {
|
|
2072
2506
|
assetIds: [],
|
|
2073
2507
|
ruleIds: [],
|
|
2074
2508
|
amount: 0,
|
|
2075
|
-
market:
|
|
2509
|
+
market: l,
|
|
2076
2510
|
owner: m,
|
|
2077
|
-
address:
|
|
2078
|
-
isEMode: typeof
|
|
2511
|
+
address: w,
|
|
2512
|
+
isEMode: typeof y < "u"
|
|
2079
2513
|
});
|
|
2080
|
-
const f =
|
|
2081
|
-
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(
|
|
2514
|
+
const f = n.get(g);
|
|
2515
|
+
f.assetIds.push(c.assetCoinType.replace("0x", "")), f.ruleIds.push(d), f.amount += c.userClaimableReward;
|
|
2082
2516
|
}
|
|
2083
2517
|
}
|
|
2084
2518
|
const a = [];
|
|
2085
2519
|
for (const [
|
|
2086
2520
|
c,
|
|
2087
|
-
{ assetIds: i, ruleIds: s, amount:
|
|
2088
|
-
] of
|
|
2089
|
-
const
|
|
2521
|
+
{ assetIds: i, ruleIds: s, amount: l, market: m, owner: w, address: y, isEMode: g }
|
|
2522
|
+
] of n) {
|
|
2523
|
+
const d = await j({
|
|
2090
2524
|
...r,
|
|
2091
|
-
cacheTime:
|
|
2525
|
+
cacheTime: v,
|
|
2092
2526
|
market: m
|
|
2093
|
-
}), f = c.split("___")[0],
|
|
2094
|
-
(
|
|
2527
|
+
}), f = c.split("___")[0], b = o.filter(
|
|
2528
|
+
(I) => C(I.suiCoinType) === C(f)
|
|
2095
2529
|
);
|
|
2096
|
-
|
|
2097
|
-
const
|
|
2530
|
+
b.sort((I, B) => I.market === m ? -1 : 1);
|
|
2531
|
+
const k = b[0], T = d.rewardFunds[C(f)];
|
|
2098
2532
|
if (!T)
|
|
2099
2533
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${m}`);
|
|
2100
2534
|
if (r?.accountCap && !r.customCoinReceive)
|
|
2101
2535
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
2102
2536
|
if (r?.customCoinReceive) {
|
|
2103
|
-
let
|
|
2104
|
-
r.accountCap ?
|
|
2105
|
-
target: `${
|
|
2537
|
+
let I;
|
|
2538
|
+
r.accountCap ? I = e.moveCall({
|
|
2539
|
+
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2106
2540
|
arguments: [
|
|
2107
2541
|
e.object("0x06"),
|
|
2108
2542
|
// Clock object
|
|
2109
|
-
e.object(
|
|
2543
|
+
e.object(d.incentiveV3),
|
|
2110
2544
|
// Incentive V3 contract
|
|
2111
|
-
e.object(
|
|
2545
|
+
e.object(d.storage),
|
|
2112
2546
|
// Protocol storage
|
|
2113
2547
|
e.object(T),
|
|
2114
2548
|
// Reward fund
|
|
@@ -2116,18 +2550,18 @@ async function St(e, t, r) {
|
|
|
2116
2550
|
// Asset IDs
|
|
2117
2551
|
e.pure.vector("address", s),
|
|
2118
2552
|
// Rule IDs
|
|
2119
|
-
|
|
2553
|
+
h(r.accountCap, e.object)
|
|
2120
2554
|
// Account capability
|
|
2121
2555
|
],
|
|
2122
2556
|
typeArguments: [f]
|
|
2123
|
-
}) :
|
|
2124
|
-
target: `${
|
|
2557
|
+
}) : g ? I = e.moveCall({
|
|
2558
|
+
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2125
2559
|
arguments: [
|
|
2126
2560
|
e.object("0x06"),
|
|
2127
2561
|
// Clock object
|
|
2128
|
-
e.object(
|
|
2562
|
+
e.object(d.incentiveV3),
|
|
2129
2563
|
// Incentive V3 contract
|
|
2130
|
-
e.object(
|
|
2564
|
+
e.object(d.storage),
|
|
2131
2565
|
// Protocol storage
|
|
2132
2566
|
e.object(T),
|
|
2133
2567
|
// Reward fund
|
|
@@ -2135,18 +2569,18 @@ async function St(e, t, r) {
|
|
|
2135
2569
|
// Asset IDs
|
|
2136
2570
|
e.pure.vector("address", s),
|
|
2137
2571
|
// Rule IDs
|
|
2138
|
-
|
|
2572
|
+
h(y, e.object)
|
|
2139
2573
|
// Account capability
|
|
2140
2574
|
],
|
|
2141
2575
|
typeArguments: [f]
|
|
2142
|
-
}) :
|
|
2143
|
-
target: `${
|
|
2576
|
+
}) : I = e.moveCall({
|
|
2577
|
+
target: `${d.package}::incentive_v3::claim_reward`,
|
|
2144
2578
|
arguments: [
|
|
2145
2579
|
e.object("0x06"),
|
|
2146
2580
|
// Clock object
|
|
2147
|
-
e.object(
|
|
2581
|
+
e.object(d.incentiveV3),
|
|
2148
2582
|
// Incentive V3 contract
|
|
2149
|
-
e.object(
|
|
2583
|
+
e.object(d.storage),
|
|
2150
2584
|
// Protocol storage
|
|
2151
2585
|
e.object(T),
|
|
2152
2586
|
// Reward fund
|
|
@@ -2157,44 +2591,44 @@ async function St(e, t, r) {
|
|
|
2157
2591
|
],
|
|
2158
2592
|
typeArguments: [f]
|
|
2159
2593
|
});
|
|
2160
|
-
const [
|
|
2594
|
+
const [B] = e.moveCall({
|
|
2161
2595
|
target: "0x2::coin::from_balance",
|
|
2162
|
-
arguments: [
|
|
2596
|
+
arguments: [I],
|
|
2163
2597
|
typeArguments: [f]
|
|
2164
2598
|
});
|
|
2165
2599
|
if (r?.customCoinReceive.type === "transfer") {
|
|
2166
2600
|
if (!r.customCoinReceive.transfer)
|
|
2167
2601
|
throw new Error("customCoinReceive.transfer is required");
|
|
2168
2602
|
e.transferObjects(
|
|
2169
|
-
[
|
|
2170
|
-
|
|
2603
|
+
[B],
|
|
2604
|
+
h(r.customCoinReceive.transfer, e.pure.address)
|
|
2171
2605
|
);
|
|
2172
2606
|
}
|
|
2173
2607
|
if (r?.customCoinReceive.type === "depositNAVI") {
|
|
2174
|
-
const
|
|
2175
|
-
|
|
2176
|
-
[
|
|
2608
|
+
const W = p(k.totalSupplyAmount).shiftedBy(-9), Y = p(k.supplyCapCeiling).shiftedBy(-27);
|
|
2609
|
+
W.plus(l).isGreaterThan(Y) && r?.customCoinReceive.depositNAVI?.fallbackReceiveAddress ? e.transferObjects(
|
|
2610
|
+
[B],
|
|
2177
2611
|
e.pure.address(r.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
2178
|
-
) : await
|
|
2612
|
+
) : await ht(e, k, B, {
|
|
2179
2613
|
...r,
|
|
2180
|
-
market:
|
|
2614
|
+
market: k.market
|
|
2181
2615
|
});
|
|
2182
2616
|
} else
|
|
2183
2617
|
a.push({
|
|
2184
|
-
coin:
|
|
2185
|
-
identifier:
|
|
2186
|
-
owner:
|
|
2187
|
-
isEMode:
|
|
2618
|
+
coin: B,
|
|
2619
|
+
identifier: k,
|
|
2620
|
+
owner: w,
|
|
2621
|
+
isEMode: g
|
|
2188
2622
|
});
|
|
2189
|
-
} else if (r?.accountCap ||
|
|
2190
|
-
const
|
|
2191
|
-
target: `${
|
|
2623
|
+
} else if (r?.accountCap || g) {
|
|
2624
|
+
const I = e.moveCall({
|
|
2625
|
+
target: `${d.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
2192
2626
|
arguments: [
|
|
2193
2627
|
e.object("0x06"),
|
|
2194
2628
|
// Clock object
|
|
2195
|
-
e.object(
|
|
2629
|
+
e.object(d.incentiveV3),
|
|
2196
2630
|
// Incentive V3 contract
|
|
2197
|
-
e.object(
|
|
2631
|
+
e.object(d.storage),
|
|
2198
2632
|
// Protocol storage
|
|
2199
2633
|
e.object(T),
|
|
2200
2634
|
// Reward fund
|
|
@@ -2202,28 +2636,28 @@ async function St(e, t, r) {
|
|
|
2202
2636
|
// Asset IDs
|
|
2203
2637
|
e.pure.vector("address", s),
|
|
2204
2638
|
// Rule IDs
|
|
2205
|
-
|
|
2639
|
+
h(r?.accountCap || y, e.object)
|
|
2206
2640
|
// Account capability
|
|
2207
2641
|
],
|
|
2208
2642
|
typeArguments: [f]
|
|
2209
|
-
}), [
|
|
2643
|
+
}), [B] = e.moveCall({
|
|
2210
2644
|
target: "0x2::coin::from_balance",
|
|
2211
|
-
arguments: [
|
|
2645
|
+
arguments: [I],
|
|
2212
2646
|
typeArguments: [f]
|
|
2213
2647
|
});
|
|
2214
2648
|
e.transferObjects(
|
|
2215
|
-
[
|
|
2216
|
-
|
|
2649
|
+
[B],
|
|
2650
|
+
h(r?.accountCap || w, e.pure.address)
|
|
2217
2651
|
);
|
|
2218
2652
|
} else
|
|
2219
2653
|
e.moveCall({
|
|
2220
|
-
target: `${
|
|
2654
|
+
target: `${d.package}::incentive_v3::claim_reward_entry`,
|
|
2221
2655
|
arguments: [
|
|
2222
2656
|
e.object("0x06"),
|
|
2223
2657
|
// Clock object
|
|
2224
|
-
e.object(
|
|
2658
|
+
e.object(d.incentiveV3),
|
|
2225
2659
|
// Incentive V3 contract
|
|
2226
|
-
e.object(
|
|
2660
|
+
e.object(d.storage),
|
|
2227
2661
|
// Protocol storage
|
|
2228
2662
|
e.object(T),
|
|
2229
2663
|
// Reward fund
|
|
@@ -2238,74 +2672,86 @@ async function St(e, t, r) {
|
|
|
2238
2672
|
return a;
|
|
2239
2673
|
}
|
|
2240
2674
|
export {
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2675
|
+
ne as Address,
|
|
2676
|
+
v as DEFAULT_CACHE_TIME,
|
|
2677
|
+
R as DEFAULT_MARKET_IDENTITY,
|
|
2678
|
+
zt as FlashLoanAssetConfig,
|
|
2679
|
+
Rt as IncentiveAPYInfo,
|
|
2680
|
+
Ne as IncentivePoolInfo,
|
|
2681
|
+
Lt as IncentivePoolInfoByPhase,
|
|
2682
|
+
F as MARKETS,
|
|
2683
|
+
wt as Market,
|
|
2684
|
+
He as NaviMissingGraphQLClientError,
|
|
2685
|
+
qt as OracleInfo,
|
|
2686
|
+
z as PoolOperator,
|
|
2687
|
+
Re as ReserveDataInfo,
|
|
2688
|
+
he as SuiPriceServiceConnection,
|
|
2689
|
+
ct as SuiPythClient,
|
|
2690
|
+
L as UserPositions,
|
|
2691
|
+
Le as UserStateInfo,
|
|
2692
|
+
Xt as borrowCoinPTB,
|
|
2693
|
+
M as buildNaviOpenApiUrl,
|
|
2694
|
+
jr as claimLendingRewardsPTB,
|
|
2695
|
+
Kt as configureNaviSdk,
|
|
2696
|
+
vt as createAccountCapPTB,
|
|
2697
|
+
nr as createEModeCapPTB,
|
|
2698
|
+
ge as createNaviLegacyJsonRpcClient,
|
|
2699
|
+
xe as createNaviSuiClient,
|
|
2700
|
+
Ze as createNaviSuiClientBundle,
|
|
2701
|
+
ht as depositCoinPTB,
|
|
2702
|
+
or as emodeIdentityId,
|
|
2703
|
+
jt as enterEModePTB,
|
|
2704
|
+
rr as exitEModePTB,
|
|
2705
|
+
St as filterPriceFeeds,
|
|
2706
|
+
yr as flashloanPTB,
|
|
2707
|
+
Ct as getAccountCapOwnerPTB,
|
|
2708
|
+
Wt as getAddressBalance,
|
|
2709
|
+
re as getAllFlashLoanAssets,
|
|
2710
|
+
er as getBorrowFee,
|
|
2711
|
+
Gt as getCoinObjectOnlyBalance,
|
|
2712
|
+
ur as getCoins,
|
|
2713
|
+
j as getConfig,
|
|
2714
|
+
Yt as getFees,
|
|
2715
|
+
fr as getFlashLoanAsset,
|
|
2716
|
+
cr as getHealthFactor,
|
|
2717
|
+
It as getHealthFactorPTB,
|
|
2718
|
+
_t as getLendingPositions,
|
|
2719
|
+
ir as getLendingState,
|
|
2720
|
+
tr as getMarket,
|
|
2721
|
+
_ as getMarketConfig,
|
|
2722
|
+
bt as getMarkets,
|
|
2723
|
+
S as getPool,
|
|
2724
|
+
G as getPools,
|
|
2725
|
+
Be as getPriceFeeds,
|
|
2726
|
+
pr as getPythStalePriceFeedId,
|
|
2727
|
+
Bt as getPythStalePriceFeedIdV2,
|
|
2728
|
+
sr as getSimulatedHealthFactor,
|
|
2729
|
+
Ie as getSimulatedHealthFactorPTB,
|
|
2730
|
+
Qt as getStats,
|
|
2731
|
+
lr as getTransactions,
|
|
2732
|
+
wr as getUserAvailableLendingRewards,
|
|
2733
|
+
Cr as getUserClaimedRewardHistory,
|
|
2734
|
+
ke as getUserEModeCaps,
|
|
2735
|
+
vr as getUserTotalClaimedReward,
|
|
2736
|
+
hr as liquidatePTB,
|
|
2737
|
+
Ht as listAddressBalances,
|
|
2738
|
+
ar as mergeCoinsPTB,
|
|
2739
|
+
D as mergeServiceHeaders,
|
|
2740
|
+
ye as normalizeAddressBalance,
|
|
2741
|
+
C as normalizeCoinType,
|
|
2742
|
+
gt as parsePoolUID,
|
|
2743
|
+
h as parseTxValue,
|
|
2744
|
+
xt as repayCoinPTB,
|
|
2745
|
+
gr as repayFlashLoanPTB,
|
|
2746
|
+
Jt as requireNaviGraphQLClient,
|
|
2747
|
+
E as resolveNaviOpenApiEndpoint,
|
|
2748
|
+
br as summaryLendingRewards,
|
|
2749
|
+
mr as updateOraclePriceBeforeUserOperationPTB,
|
|
2750
|
+
At as updateOraclePricesPTB,
|
|
2751
|
+
Pt as updatePythPriceFeeds,
|
|
2752
|
+
dr as verifyHealthFactorPTB,
|
|
2753
|
+
$ as withCache,
|
|
2308
2754
|
A as withSingleton,
|
|
2309
|
-
|
|
2755
|
+
Zt as withdrawCoinPTB
|
|
2310
2756
|
};
|
|
2311
2757
|
//# sourceMappingURL=index.esm.js.map
|