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