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