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