@naviprotocol/lending 1.4.6 → 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 -1008
- 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,435 +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
|
|
523
|
+
}), a = await $(t, n), c = n?.market || O, i = n?.env || "prod";
|
|
313
524
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
314
525
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
315
|
-
|
|
316
|
-
if (k(a.suiCoinType) === k("0x2::sui::SUI") && c) {
|
|
526
|
+
if (k(a.suiCoinType) === k("0x2::sui::SUI") && typeof r == "object" && r?.$kind === "GasCoin") {
|
|
317
527
|
if (!n?.amount)
|
|
318
528
|
throw new Error("Amount is required for sui coin");
|
|
319
|
-
|
|
529
|
+
r = e.splitCoins(r, [n.amount]);
|
|
320
530
|
}
|
|
321
|
-
let
|
|
322
|
-
return typeof n?.amount < "u" ?
|
|
531
|
+
let s;
|
|
532
|
+
return typeof n?.amount < "u" ? s = g(n.amount, e.pure.u64) : s = e.moveCall({
|
|
323
533
|
target: "0x2::coin::value",
|
|
324
|
-
arguments: [g(
|
|
534
|
+
arguments: [g(r, e.object)],
|
|
325
535
|
typeArguments: [a.suiCoinType]
|
|
326
536
|
}), n?.accountCap ? e.moveCall({
|
|
327
|
-
target: `${
|
|
537
|
+
target: `${o.package}::incentive_v3::deposit_with_account_cap`,
|
|
328
538
|
arguments: [
|
|
329
539
|
e.object("0x06"),
|
|
330
|
-
e.object(
|
|
540
|
+
e.object(o.storage),
|
|
331
541
|
e.object(a.contract.pool),
|
|
332
542
|
e.pure.u8(a.id),
|
|
333
|
-
g(
|
|
334
|
-
e.object(
|
|
335
|
-
e.object(
|
|
543
|
+
g(r, e.object),
|
|
544
|
+
e.object(o.incentiveV2),
|
|
545
|
+
e.object(o.incentiveV3),
|
|
336
546
|
g(n.accountCap, e.object)
|
|
337
547
|
],
|
|
338
548
|
typeArguments: [a.suiCoinType]
|
|
339
549
|
}) : e.moveCall({
|
|
340
|
-
target: `${
|
|
550
|
+
target: `${o.package}::incentive_v3::entry_deposit`,
|
|
341
551
|
arguments: [
|
|
342
552
|
e.object("0x06"),
|
|
343
|
-
e.object(
|
|
553
|
+
e.object(o.storage),
|
|
344
554
|
e.object(a.contract.pool),
|
|
345
555
|
e.pure.u8(a.id),
|
|
346
|
-
g(
|
|
347
|
-
|
|
348
|
-
e.object(
|
|
349
|
-
e.object(
|
|
556
|
+
g(r, e.object),
|
|
557
|
+
s,
|
|
558
|
+
e.object(o.incentiveV2),
|
|
559
|
+
e.object(o.incentiveV3)
|
|
350
560
|
],
|
|
351
561
|
typeArguments: [a.suiCoinType]
|
|
352
|
-
}),
|
|
353
|
-
target: `${
|
|
562
|
+
}), o.version === 2 && a.token.symbol === "SUI" && i === "prod" && c === "main" && e.moveCall({
|
|
563
|
+
target: `${o.package}::pool::refresh_stake`,
|
|
354
564
|
arguments: [e.object(a.contract.pool), e.object("0x05")]
|
|
355
565
|
}), e;
|
|
356
566
|
}
|
|
357
|
-
async function
|
|
358
|
-
const
|
|
567
|
+
async function it(e, t, r, n) {
|
|
568
|
+
const o = await _({
|
|
359
569
|
...n,
|
|
360
570
|
cacheTime: b
|
|
361
|
-
}), a = await
|
|
571
|
+
}), a = await $(t, n), c = g(r, e.pure.u64);
|
|
362
572
|
let i;
|
|
363
|
-
if (
|
|
573
|
+
if (o.version === 1)
|
|
364
574
|
if (n?.accountCap) {
|
|
365
|
-
const [
|
|
366
|
-
target: `${
|
|
575
|
+
const [p] = e.moveCall({
|
|
576
|
+
target: `${o.package}::incentive_v3::withdraw_with_account_cap`,
|
|
367
577
|
arguments: [
|
|
368
578
|
e.object("0x06"),
|
|
369
|
-
e.object(
|
|
370
|
-
e.object(
|
|
579
|
+
e.object(o.priceOracle),
|
|
580
|
+
e.object(o.storage),
|
|
371
581
|
e.object(a.contract.pool),
|
|
372
582
|
e.pure.u8(a.id),
|
|
373
|
-
|
|
374
|
-
e.object(
|
|
375
|
-
e.object(
|
|
583
|
+
c,
|
|
584
|
+
e.object(o.incentiveV2),
|
|
585
|
+
e.object(o.incentiveV3),
|
|
376
586
|
g(n.accountCap, e.object)
|
|
377
587
|
],
|
|
378
588
|
typeArguments: [a.suiCoinType]
|
|
379
589
|
});
|
|
380
|
-
i =
|
|
590
|
+
i = p;
|
|
381
591
|
} else {
|
|
382
|
-
const [
|
|
383
|
-
target: `${
|
|
592
|
+
const [p] = e.moveCall({
|
|
593
|
+
target: `${o.package}::incentive_v3::withdraw`,
|
|
384
594
|
arguments: [
|
|
385
595
|
e.object("0x06"),
|
|
386
|
-
e.object(
|
|
387
|
-
e.object(
|
|
596
|
+
e.object(o.priceOracle),
|
|
597
|
+
e.object(o.storage),
|
|
388
598
|
e.object(a.contract.pool),
|
|
389
599
|
e.pure.u8(a.id),
|
|
390
|
-
|
|
391
|
-
e.object(
|
|
392
|
-
e.object(
|
|
600
|
+
c,
|
|
601
|
+
e.object(o.incentiveV2),
|
|
602
|
+
e.object(o.incentiveV3)
|
|
393
603
|
],
|
|
394
604
|
typeArguments: [a.suiCoinType]
|
|
395
605
|
});
|
|
396
|
-
i =
|
|
606
|
+
i = p;
|
|
397
607
|
}
|
|
398
608
|
else if (n?.accountCap) {
|
|
399
|
-
const [
|
|
400
|
-
target: `${
|
|
609
|
+
const [p] = e.moveCall({
|
|
610
|
+
target: `${o.package}::incentive_v3::withdraw_with_account_cap_v2`,
|
|
401
611
|
arguments: [
|
|
402
612
|
e.object("0x06"),
|
|
403
|
-
e.object(
|
|
404
|
-
e.object(
|
|
613
|
+
e.object(o.priceOracle),
|
|
614
|
+
e.object(o.storage),
|
|
405
615
|
e.object(a.contract.pool),
|
|
406
616
|
e.pure.u8(a.id),
|
|
407
|
-
|
|
408
|
-
e.object(
|
|
409
|
-
e.object(
|
|
617
|
+
c,
|
|
618
|
+
e.object(o.incentiveV2),
|
|
619
|
+
e.object(o.incentiveV3),
|
|
410
620
|
g(n.accountCap, e.object),
|
|
411
621
|
e.object("0x05")
|
|
412
622
|
],
|
|
413
623
|
typeArguments: [a.suiCoinType]
|
|
414
624
|
});
|
|
415
|
-
i =
|
|
625
|
+
i = p;
|
|
416
626
|
} else {
|
|
417
|
-
const [
|
|
418
|
-
target: `${
|
|
627
|
+
const [p] = e.moveCall({
|
|
628
|
+
target: `${o.package}::incentive_v3::withdraw_v2`,
|
|
419
629
|
arguments: [
|
|
420
630
|
e.object("0x06"),
|
|
421
|
-
e.object(
|
|
422
|
-
e.object(
|
|
631
|
+
e.object(o.priceOracle),
|
|
632
|
+
e.object(o.storage),
|
|
423
633
|
e.object(a.contract.pool),
|
|
424
634
|
e.pure.u8(a.id),
|
|
425
|
-
|
|
426
|
-
e.object(
|
|
427
|
-
e.object(
|
|
635
|
+
c,
|
|
636
|
+
e.object(o.incentiveV2),
|
|
637
|
+
e.object(o.incentiveV3),
|
|
428
638
|
e.object("0x05")
|
|
429
639
|
],
|
|
430
640
|
typeArguments: [a.suiCoinType]
|
|
431
641
|
});
|
|
432
|
-
i =
|
|
642
|
+
i = p;
|
|
433
643
|
}
|
|
434
644
|
return e.moveCall({
|
|
435
645
|
target: "0x2::coin::from_balance",
|
|
@@ -437,85 +647,85 @@ async function tt(e, r, o, n) {
|
|
|
437
647
|
typeArguments: [a.suiCoinType]
|
|
438
648
|
});
|
|
439
649
|
}
|
|
440
|
-
async function
|
|
441
|
-
const
|
|
650
|
+
async function ct(e, t, r, n) {
|
|
651
|
+
const o = await _({
|
|
442
652
|
...n,
|
|
443
653
|
cacheTime: b
|
|
444
|
-
}), a = await
|
|
654
|
+
}), a = await $(t, n);
|
|
445
655
|
if (a?.deprecatedAt && Date.now() > a.deprecatedAt)
|
|
446
656
|
throw new Error(`The lending pool for coinType ${a.suiCoinType} has been deprecated.`);
|
|
447
|
-
const
|
|
657
|
+
const c = g(r, e.pure.u64);
|
|
448
658
|
let i;
|
|
449
|
-
if (
|
|
659
|
+
if (o.version === 1)
|
|
450
660
|
if (n?.accountCap) {
|
|
451
|
-
const [
|
|
452
|
-
target: `${
|
|
661
|
+
const [p] = e.moveCall({
|
|
662
|
+
target: `${o.package}::incentive_v3::borrow_with_account_cap`,
|
|
453
663
|
arguments: [
|
|
454
664
|
e.object("0x06"),
|
|
455
|
-
e.object(
|
|
456
|
-
e.object(
|
|
665
|
+
e.object(o.priceOracle),
|
|
666
|
+
e.object(o.storage),
|
|
457
667
|
e.object(a.contract.pool),
|
|
458
668
|
e.pure.u8(a.id),
|
|
459
|
-
|
|
460
|
-
e.object(
|
|
461
|
-
e.object(
|
|
669
|
+
c,
|
|
670
|
+
e.object(o.incentiveV2),
|
|
671
|
+
e.object(o.incentiveV3),
|
|
462
672
|
g(n.accountCap, e.object)
|
|
463
673
|
],
|
|
464
674
|
typeArguments: [a.suiCoinType]
|
|
465
675
|
});
|
|
466
|
-
i =
|
|
676
|
+
i = p;
|
|
467
677
|
} else {
|
|
468
|
-
const [
|
|
469
|
-
target: `${
|
|
678
|
+
const [p] = e.moveCall({
|
|
679
|
+
target: `${o.package}::incentive_v3::borrow`,
|
|
470
680
|
arguments: [
|
|
471
681
|
e.object("0x06"),
|
|
472
|
-
e.object(
|
|
473
|
-
e.object(
|
|
682
|
+
e.object(o.priceOracle),
|
|
683
|
+
e.object(o.storage),
|
|
474
684
|
e.object(a.contract.pool),
|
|
475
685
|
e.pure.u8(a.id),
|
|
476
|
-
|
|
477
|
-
e.object(
|
|
478
|
-
e.object(
|
|
686
|
+
c,
|
|
687
|
+
e.object(o.incentiveV2),
|
|
688
|
+
e.object(o.incentiveV3)
|
|
479
689
|
],
|
|
480
690
|
typeArguments: [a.suiCoinType]
|
|
481
691
|
});
|
|
482
|
-
i =
|
|
692
|
+
i = p;
|
|
483
693
|
}
|
|
484
694
|
else if (n?.accountCap) {
|
|
485
|
-
const [
|
|
486
|
-
target: `${
|
|
695
|
+
const [p] = e.moveCall({
|
|
696
|
+
target: `${o.package}::incentive_v3::borrow_with_account_cap_v2`,
|
|
487
697
|
arguments: [
|
|
488
698
|
e.object("0x06"),
|
|
489
|
-
e.object(
|
|
490
|
-
e.object(
|
|
699
|
+
e.object(o.priceOracle),
|
|
700
|
+
e.object(o.storage),
|
|
491
701
|
e.object(a.contract.pool),
|
|
492
702
|
e.pure.u8(a.id),
|
|
493
|
-
|
|
494
|
-
e.object(
|
|
495
|
-
e.object(
|
|
703
|
+
c,
|
|
704
|
+
e.object(o.incentiveV2),
|
|
705
|
+
e.object(o.incentiveV3),
|
|
496
706
|
g(n.accountCap, e.object),
|
|
497
707
|
e.object("0x05")
|
|
498
708
|
],
|
|
499
709
|
typeArguments: [a.suiCoinType]
|
|
500
710
|
});
|
|
501
|
-
i =
|
|
711
|
+
i = p;
|
|
502
712
|
} else {
|
|
503
|
-
const [
|
|
504
|
-
target: `${
|
|
713
|
+
const [p] = e.moveCall({
|
|
714
|
+
target: `${o.package}::incentive_v3::borrow_v2`,
|
|
505
715
|
arguments: [
|
|
506
716
|
e.object("0x06"),
|
|
507
|
-
e.object(
|
|
508
|
-
e.object(
|
|
717
|
+
e.object(o.priceOracle),
|
|
718
|
+
e.object(o.storage),
|
|
509
719
|
e.object(a.contract.pool),
|
|
510
720
|
e.pure.u8(a.id),
|
|
511
|
-
|
|
512
|
-
e.object(
|
|
513
|
-
e.object(
|
|
721
|
+
c,
|
|
722
|
+
e.object(o.incentiveV2),
|
|
723
|
+
e.object(o.incentiveV3),
|
|
514
724
|
e.object("0x05")
|
|
515
725
|
],
|
|
516
726
|
typeArguments: [a.suiCoinType]
|
|
517
727
|
});
|
|
518
|
-
i =
|
|
728
|
+
i = p;
|
|
519
729
|
}
|
|
520
730
|
return e.moveCall({
|
|
521
731
|
target: "0x2::coin::from_balance",
|
|
@@ -523,88 +733,88 @@ async function ot(e, r, o, n) {
|
|
|
523
733
|
typeArguments: [a.suiCoinType]
|
|
524
734
|
});
|
|
525
735
|
}
|
|
526
|
-
async function
|
|
527
|
-
const
|
|
736
|
+
async function st(e, t, r, n) {
|
|
737
|
+
const o = await _({
|
|
528
738
|
...n,
|
|
529
739
|
cacheTime: b
|
|
530
|
-
}), a = await
|
|
531
|
-
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") {
|
|
532
742
|
if (!n?.amount)
|
|
533
743
|
throw new Error("Amount is required for sui coin");
|
|
534
|
-
|
|
744
|
+
r = e.splitCoins(r, [n.amount]);
|
|
535
745
|
}
|
|
536
|
-
let
|
|
537
|
-
if (typeof n?.amount < "u" ?
|
|
746
|
+
let c;
|
|
747
|
+
if (typeof n?.amount < "u" ? c = g(n.amount, e.pure.u64) : c = e.moveCall({
|
|
538
748
|
target: "0x2::coin::value",
|
|
539
|
-
arguments: [g(
|
|
749
|
+
arguments: [g(r, e.object)],
|
|
540
750
|
typeArguments: [a.suiCoinType]
|
|
541
751
|
}), n?.accountCap) {
|
|
542
|
-
const [
|
|
543
|
-
target: `${
|
|
752
|
+
const [i] = e.moveCall({
|
|
753
|
+
target: `${o.package}::incentive_v3::repay_with_account_cap`,
|
|
544
754
|
arguments: [
|
|
545
755
|
e.object("0x06"),
|
|
546
|
-
e.object(
|
|
547
|
-
e.object(
|
|
756
|
+
e.object(o.priceOracle),
|
|
757
|
+
e.object(o.storage),
|
|
548
758
|
e.object(a.contract.pool),
|
|
549
759
|
e.pure.u8(a.id),
|
|
550
|
-
g(
|
|
551
|
-
e.object(
|
|
552
|
-
e.object(
|
|
760
|
+
g(r, e.object),
|
|
761
|
+
e.object(o.incentiveV2),
|
|
762
|
+
e.object(o.incentiveV3),
|
|
553
763
|
g(n.accountCap, e.object)
|
|
554
764
|
],
|
|
555
765
|
typeArguments: [a.suiCoinType]
|
|
556
766
|
});
|
|
557
767
|
return e.moveCall({
|
|
558
768
|
target: "0x2::coin::from_balance",
|
|
559
|
-
arguments: [
|
|
769
|
+
arguments: [i],
|
|
560
770
|
typeArguments: [a.suiCoinType]
|
|
561
771
|
});
|
|
562
772
|
} else
|
|
563
773
|
return e.moveCall({
|
|
564
|
-
target: `${
|
|
774
|
+
target: `${o.package}::incentive_v3::entry_repay`,
|
|
565
775
|
arguments: [
|
|
566
776
|
e.object("0x06"),
|
|
567
|
-
e.object(
|
|
568
|
-
e.object(
|
|
777
|
+
e.object(o.priceOracle),
|
|
778
|
+
e.object(o.storage),
|
|
569
779
|
e.object(a.contract.pool),
|
|
570
780
|
e.pure.u8(a.id),
|
|
571
|
-
g(
|
|
572
|
-
|
|
573
|
-
e.object(
|
|
574
|
-
e.object(
|
|
781
|
+
g(r, e.object),
|
|
782
|
+
c,
|
|
783
|
+
e.object(o.incentiveV2),
|
|
784
|
+
e.object(o.incentiveV3)
|
|
575
785
|
],
|
|
576
786
|
typeArguments: [a.suiCoinType]
|
|
577
787
|
}), e;
|
|
578
788
|
}
|
|
579
|
-
const
|
|
580
|
-
|
|
789
|
+
const lt = S(
|
|
790
|
+
A(
|
|
581
791
|
async (e) => {
|
|
582
|
-
const
|
|
792
|
+
const t = await _({
|
|
583
793
|
...e
|
|
584
794
|
});
|
|
585
795
|
if (e?.address && typeof e?.asset < "u")
|
|
586
796
|
try {
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
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`,
|
|
590
800
|
arguments: [
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
801
|
+
c.object(t.incentiveV3),
|
|
802
|
+
c.pure.address(e.address),
|
|
803
|
+
c.pure.u8(o.id),
|
|
804
|
+
c.pure.u64(1e4)
|
|
595
805
|
],
|
|
596
806
|
typeArguments: []
|
|
597
807
|
});
|
|
598
808
|
const i = await a.devInspectTransactionBlock({
|
|
599
|
-
transactionBlock:
|
|
809
|
+
transactionBlock: c,
|
|
600
810
|
sender: e.address
|
|
601
|
-
}),
|
|
602
|
-
return (Number(
|
|
603
|
-
} catch (
|
|
604
|
-
console.error(
|
|
811
|
+
}), s = H(i, [l.u64()]);
|
|
812
|
+
return (Number(s[0]) || 0) / 100;
|
|
813
|
+
} catch (o) {
|
|
814
|
+
console.error(o);
|
|
605
815
|
}
|
|
606
816
|
const n = (await V.getObject({
|
|
607
|
-
id:
|
|
817
|
+
id: t.incentiveV3,
|
|
608
818
|
options: { showType: !0, showOwner: !0, showContent: !0 }
|
|
609
819
|
})).data.content.fields.borrow_fee_rate;
|
|
610
820
|
return Number(n) / 100;
|
|
@@ -632,383 +842,383 @@ const nt = M(
|
|
|
632
842
|
name: "Sui Eco Market"
|
|
633
843
|
}
|
|
634
844
|
};
|
|
635
|
-
class
|
|
636
|
-
constructor(
|
|
845
|
+
class Ue {
|
|
846
|
+
constructor(t, r) {
|
|
637
847
|
this.poolMap = {}, this.emodeMap = {}, this.pools = [], this.emodes = [], this.emodePools = [], this.emodeBorrowablePools = [], this.emodeSupplyablePools = [], this._overview = {
|
|
638
848
|
marketTotalSupplyValue: "0",
|
|
639
849
|
marketTotalBorrowValue: "0"
|
|
640
|
-
}, this.config =
|
|
850
|
+
}, this.config = C(t), this.initPools(r);
|
|
641
851
|
}
|
|
642
852
|
get overview() {
|
|
643
853
|
return this._overview;
|
|
644
854
|
}
|
|
645
|
-
initPools(
|
|
646
|
-
const
|
|
647
|
-
let
|
|
648
|
-
|
|
649
|
-
if (!this.checkMarket(
|
|
650
|
-
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);
|
|
651
861
|
return;
|
|
652
862
|
}
|
|
653
|
-
|
|
863
|
+
r[s.uniqueId] || this.pools.push(s), s?.emodes?.forEach((m) => {
|
|
654
864
|
n[m.uniqueId] || this.emodes.push(m), m.assets.forEach((h) => {
|
|
655
865
|
h.isDebt && m.assets.find(
|
|
656
|
-
(y) => y.isCollateral && y.ltv > 0 && y.assetId !==
|
|
657
|
-
) &&
|
|
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);
|
|
658
868
|
});
|
|
659
|
-
}), i = i.plus(
|
|
660
|
-
}), this.poolMap =
|
|
661
|
-
const
|
|
662
|
-
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);
|
|
663
873
|
}), this._overview = {
|
|
664
|
-
marketTotalSupplyValue:
|
|
874
|
+
marketTotalSupplyValue: c.toString(),
|
|
665
875
|
marketTotalBorrowValue: i.toString()
|
|
666
|
-
}, 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));
|
|
667
877
|
}
|
|
668
|
-
getEMode(
|
|
669
|
-
return this.emodeMap[
|
|
878
|
+
getEMode(t) {
|
|
879
|
+
return this.emodeMap[t] || null;
|
|
670
880
|
}
|
|
671
|
-
getEModeRelatePools(
|
|
672
|
-
const { collateral: n, debt:
|
|
673
|
-
return
|
|
674
|
-
typeof a == "number" && a !== i.emodeId || i.assets.forEach((
|
|
675
|
-
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]);
|
|
676
886
|
});
|
|
677
|
-
}),
|
|
887
|
+
}), c;
|
|
678
888
|
}
|
|
679
|
-
getEModePools(
|
|
680
|
-
const
|
|
681
|
-
return
|
|
682
|
-
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);
|
|
683
893
|
return {
|
|
684
|
-
...
|
|
894
|
+
...o,
|
|
685
895
|
emode: {
|
|
686
896
|
...a,
|
|
687
|
-
emodeId:
|
|
897
|
+
emodeId: r.emodeId
|
|
688
898
|
},
|
|
689
899
|
isEMode: !0
|
|
690
900
|
};
|
|
691
901
|
}) : [];
|
|
692
902
|
}
|
|
693
|
-
checkMarket(
|
|
694
|
-
let
|
|
695
|
-
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;
|
|
696
906
|
}
|
|
697
907
|
}
|
|
698
|
-
const
|
|
699
|
-
const
|
|
700
|
-
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)
|
|
701
911
|
throw new Error("Market not found");
|
|
702
|
-
return
|
|
703
|
-
},
|
|
704
|
-
|
|
705
|
-
async (e,
|
|
706
|
-
const
|
|
912
|
+
return r;
|
|
913
|
+
}, Oe = S(
|
|
914
|
+
A(
|
|
915
|
+
async (e, t) => {
|
|
916
|
+
const r = await R({
|
|
707
917
|
cacheTime: 6e4,
|
|
708
|
-
...
|
|
918
|
+
...t,
|
|
709
919
|
markets: e
|
|
710
920
|
});
|
|
711
921
|
return e.map((n) => {
|
|
712
|
-
const
|
|
713
|
-
return new
|
|
922
|
+
const o = C(n), a = r.filter((c) => c.market === o.key);
|
|
923
|
+
return new Ue(n, a);
|
|
714
924
|
});
|
|
715
925
|
}
|
|
716
926
|
)
|
|
717
|
-
),
|
|
718
|
-
|
|
719
|
-
async (e,
|
|
927
|
+
), ut = S(
|
|
928
|
+
A(
|
|
929
|
+
async (e, t) => (await Oe([e], t))[0]
|
|
720
930
|
)
|
|
721
|
-
), _ =
|
|
722
|
-
|
|
931
|
+
), _ = S(
|
|
932
|
+
A(
|
|
723
933
|
async (e) => {
|
|
724
|
-
const
|
|
725
|
-
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;
|
|
726
936
|
}
|
|
727
937
|
)
|
|
728
938
|
), b = 1e3 * 60 * 5;
|
|
729
|
-
async function
|
|
730
|
-
const
|
|
939
|
+
async function De(e, t) {
|
|
940
|
+
const r = await _({
|
|
731
941
|
cacheTime: b,
|
|
732
|
-
...
|
|
942
|
+
...t
|
|
733
943
|
});
|
|
734
944
|
return e.moveCall({
|
|
735
|
-
target: `${
|
|
945
|
+
target: `${r.package}::lending::create_account`,
|
|
736
946
|
arguments: []
|
|
737
947
|
});
|
|
738
948
|
}
|
|
739
|
-
async function
|
|
949
|
+
async function Fe(e, t, r) {
|
|
740
950
|
const n = await _({
|
|
741
951
|
cacheTime: b,
|
|
742
|
-
...
|
|
952
|
+
...r
|
|
743
953
|
});
|
|
744
954
|
return e.moveCall({
|
|
745
955
|
target: `${n.package}::account::account_owner`,
|
|
746
|
-
arguments: [
|
|
956
|
+
arguments: [t]
|
|
747
957
|
});
|
|
748
958
|
}
|
|
749
|
-
async function
|
|
959
|
+
async function Ne(e, t, r) {
|
|
750
960
|
const n = await _({
|
|
751
|
-
...
|
|
961
|
+
...r,
|
|
752
962
|
cacheTime: b
|
|
753
963
|
});
|
|
754
|
-
return
|
|
964
|
+
return r?.accountCap ? e.moveCall({
|
|
755
965
|
target: `${n.package}::lending::enter_emode_with_account_cap`,
|
|
756
966
|
arguments: [
|
|
757
967
|
e.object(n.storage),
|
|
758
|
-
g(
|
|
759
|
-
g(
|
|
968
|
+
g(t, e.pure.u64),
|
|
969
|
+
g(r.accountCap, e.object)
|
|
760
970
|
]
|
|
761
971
|
}) : e.moveCall({
|
|
762
972
|
target: `${n.package}::lending::enter_emode`,
|
|
763
|
-
arguments: [e.object(n.storage), g(
|
|
973
|
+
arguments: [e.object(n.storage), g(t, e.pure.u64)]
|
|
764
974
|
}), e;
|
|
765
975
|
}
|
|
766
|
-
async function
|
|
767
|
-
const
|
|
768
|
-
...
|
|
976
|
+
async function pt(e, t) {
|
|
977
|
+
const r = await _({
|
|
978
|
+
...t,
|
|
769
979
|
cacheTime: b
|
|
770
980
|
});
|
|
771
|
-
return
|
|
772
|
-
target: `${
|
|
773
|
-
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)]
|
|
774
984
|
}) : e.moveCall({
|
|
775
|
-
target: `${
|
|
776
|
-
arguments: [e.object(
|
|
985
|
+
target: `${r.package}::lending::exit_emode`,
|
|
986
|
+
arguments: [e.object(r.storage)]
|
|
777
987
|
}), e;
|
|
778
988
|
}
|
|
779
|
-
async function
|
|
989
|
+
async function dt(e, t, r) {
|
|
780
990
|
const n = await _({
|
|
781
991
|
cacheTime: b,
|
|
782
|
-
...
|
|
783
|
-
}),
|
|
784
|
-
await
|
|
785
|
-
...
|
|
786
|
-
accountCap:
|
|
992
|
+
...r
|
|
993
|
+
}), o = await De(e, r);
|
|
994
|
+
await Ne(e, t, {
|
|
995
|
+
...r,
|
|
996
|
+
accountCap: o
|
|
787
997
|
});
|
|
788
|
-
const a = await
|
|
998
|
+
const a = await C(r?.market || O), c = await Fe(e, o, r);
|
|
789
999
|
return e.moveCall({
|
|
790
1000
|
target: `${n.emode.contract.registryPackage}::registry::register_emode_for_account_cap`,
|
|
791
1001
|
arguments: [
|
|
792
1002
|
e.object(n.emode.contract.registryObject),
|
|
793
|
-
|
|
1003
|
+
c,
|
|
794
1004
|
g(a.id, e.pure.u64),
|
|
795
|
-
g(
|
|
1005
|
+
g(t, e.pure.u64)
|
|
796
1006
|
]
|
|
797
|
-
}),
|
|
1007
|
+
}), o;
|
|
798
1008
|
}
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
async (e,
|
|
802
|
-
const
|
|
1009
|
+
const ne = S(
|
|
1010
|
+
A(
|
|
1011
|
+
async (e, t) => {
|
|
1012
|
+
const r = await _({
|
|
803
1013
|
cacheTime: b,
|
|
804
|
-
...
|
|
805
|
-
}), n = new F(),
|
|
1014
|
+
...t
|
|
1015
|
+
}), n = new F(), o = t?.client ?? V;
|
|
806
1016
|
n.moveCall({
|
|
807
|
-
target: `${
|
|
808
|
-
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)]
|
|
809
1019
|
});
|
|
810
|
-
const
|
|
1020
|
+
const c = (await o.devInspectTransactionBlock({
|
|
811
1021
|
transactionBlock: n,
|
|
812
1022
|
sender: e
|
|
813
|
-
})).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]));
|
|
814
1024
|
return i.map((m, h) => ({
|
|
815
1025
|
marketId: Number(m),
|
|
816
|
-
emodeId: Number(
|
|
817
|
-
accountCap:
|
|
1026
|
+
emodeId: Number(s[h]),
|
|
1027
|
+
accountCap: p[h].toString()
|
|
818
1028
|
}));
|
|
819
1029
|
}
|
|
820
1030
|
)
|
|
821
1031
|
);
|
|
822
|
-
function
|
|
823
|
-
return `${
|
|
1032
|
+
function mt(e) {
|
|
1033
|
+
return `${C(e.marketId).key}-${e.emodeId}`;
|
|
824
1034
|
}
|
|
825
|
-
function
|
|
826
|
-
const n = typeof
|
|
1035
|
+
function ft(e, t, r) {
|
|
1036
|
+
const n = typeof r?.balance == "number", o = n ? r.balance : 0;
|
|
827
1037
|
let a = 0;
|
|
828
|
-
const
|
|
1038
|
+
const c = [];
|
|
829
1039
|
let i = "";
|
|
830
|
-
if (
|
|
831
|
-
if (!(n && a >=
|
|
832
|
-
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)
|
|
833
1043
|
throw new Error("All coins must be of the same type");
|
|
834
|
-
a += Number(
|
|
1044
|
+
a += Number(s.balance), c.push(s.coinObjectId);
|
|
835
1045
|
}
|
|
836
|
-
}),
|
|
1046
|
+
}), c.length === 0)
|
|
837
1047
|
throw new Error("No coins to merge");
|
|
838
|
-
if (n && a <
|
|
1048
|
+
if (n && a < o)
|
|
839
1049
|
throw new Error(
|
|
840
|
-
`Balance is less than the specified balance: ${a} < ${
|
|
1050
|
+
`Balance is less than the specified balance: ${a} < ${o}`
|
|
841
1051
|
);
|
|
842
|
-
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]);
|
|
843
1053
|
}
|
|
844
|
-
async function
|
|
1054
|
+
async function ae(e, t, r, n, o, a, c) {
|
|
845
1055
|
const i = await _({
|
|
846
|
-
...
|
|
1056
|
+
...c,
|
|
847
1057
|
cacheTime: b
|
|
848
|
-
}),
|
|
1058
|
+
}), s = await $(r, c);
|
|
849
1059
|
return e.moveCall({
|
|
850
1060
|
target: `${i.uiGetter}::calculator_unchecked::dynamic_health_factor`,
|
|
851
1061
|
arguments: [
|
|
852
1062
|
e.object("0x06"),
|
|
853
1063
|
e.object(i.storage),
|
|
854
1064
|
e.object(i.oracle.priceOracle),
|
|
855
|
-
|
|
856
|
-
g(
|
|
857
|
-
g(
|
|
1065
|
+
Se(e, s),
|
|
1066
|
+
g(t, e.pure.address),
|
|
1067
|
+
g(s.id, e.pure.u8),
|
|
858
1068
|
g(n, e.pure.u64),
|
|
859
|
-
g(
|
|
1069
|
+
g(o, e.pure.u64),
|
|
860
1070
|
g(a, e.pure.bool)
|
|
861
1071
|
],
|
|
862
|
-
typeArguments: [
|
|
1072
|
+
typeArguments: [s.suiCoinType]
|
|
863
1073
|
});
|
|
864
1074
|
}
|
|
865
|
-
async function
|
|
866
|
-
return
|
|
1075
|
+
async function Re(e, t, r) {
|
|
1076
|
+
return ae(e, t, 0, 0, 0, !1, r);
|
|
867
1077
|
}
|
|
868
|
-
async function
|
|
869
|
-
const n = new F(),
|
|
870
|
-
...
|
|
1078
|
+
async function ie(e, t, r) {
|
|
1079
|
+
const n = new F(), o = r?.client ?? V, a = await R({
|
|
1080
|
+
...r,
|
|
871
1081
|
markets: Object.values(U)
|
|
872
|
-
}),
|
|
873
|
-
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) {
|
|
874
1084
|
const f = await _({
|
|
875
|
-
...
|
|
1085
|
+
...r,
|
|
876
1086
|
cacheTime: b,
|
|
877
|
-
market:
|
|
1087
|
+
market: u.key
|
|
878
1088
|
});
|
|
879
1089
|
n.moveCall({
|
|
880
1090
|
target: `${f.uiGetter}::getter::get_reserve_data`,
|
|
881
1091
|
arguments: [n.object(f.storage)]
|
|
882
1092
|
});
|
|
883
1093
|
}
|
|
884
|
-
for (let
|
|
1094
|
+
for (let u of t) {
|
|
885
1095
|
const f = await _({
|
|
886
|
-
...
|
|
1096
|
+
...r,
|
|
887
1097
|
cacheTime: b,
|
|
888
|
-
market:
|
|
1098
|
+
market: u.market
|
|
889
1099
|
});
|
|
890
1100
|
n.moveCall({
|
|
891
1101
|
target: `${f.uiGetter}::getter_unchecked::get_user_state`,
|
|
892
|
-
arguments: [n.object(f.storage), n.pure.address(
|
|
1102
|
+
arguments: [n.object(f.storage), n.pure.address(u.address)]
|
|
893
1103
|
});
|
|
894
1104
|
}
|
|
895
|
-
const m = (await
|
|
1105
|
+
const m = (await o.devInspectTransactionBlock({
|
|
896
1106
|
transactionBlock: n,
|
|
897
1107
|
sender: e
|
|
898
1108
|
})).results || [], h = {};
|
|
899
|
-
|
|
1109
|
+
s.forEach((u, f) => {
|
|
900
1110
|
try {
|
|
901
|
-
const
|
|
902
|
-
for (const
|
|
903
|
-
I[
|
|
904
|
-
supplyIndex:
|
|
905
|
-
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
|
|
906
1116
|
};
|
|
907
|
-
h[
|
|
908
|
-
} catch (
|
|
1117
|
+
h[u.key] = I;
|
|
1118
|
+
} catch (v) {
|
|
909
1119
|
console.warn(
|
|
910
|
-
`[@naviprotocol/lending] Failed to decode reserve data for market "${
|
|
911
|
-
|
|
1120
|
+
`[@naviprotocol/lending] Failed to decode reserve data for market "${u.key}", falling back to open-api pool indices`,
|
|
1121
|
+
v
|
|
912
1122
|
);
|
|
913
1123
|
}
|
|
914
1124
|
});
|
|
915
|
-
const
|
|
916
|
-
return
|
|
917
|
-
const
|
|
918
|
-
|
|
919
|
-
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))
|
|
920
1130
|
return;
|
|
921
|
-
const
|
|
922
|
-
if (!
|
|
1131
|
+
const P = c[`${I.key}-${j.asset_id}`];
|
|
1132
|
+
if (!P)
|
|
923
1133
|
return;
|
|
924
|
-
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();
|
|
925
1135
|
y.push({
|
|
926
|
-
supplyBalance:
|
|
927
|
-
borrowBalance:
|
|
1136
|
+
supplyBalance: ue,
|
|
1137
|
+
borrowBalance: pe,
|
|
928
1138
|
assetId: j.asset_id,
|
|
929
1139
|
market: I.key,
|
|
930
|
-
pool:
|
|
931
|
-
emodeId:
|
|
1140
|
+
pool: P,
|
|
1141
|
+
emodeId: v.emodeId
|
|
932
1142
|
});
|
|
933
1143
|
});
|
|
934
1144
|
}), y;
|
|
935
1145
|
}
|
|
936
|
-
const
|
|
937
|
-
async (e,
|
|
938
|
-
const n = (
|
|
1146
|
+
const yt = S(
|
|
1147
|
+
async (e, t) => {
|
|
1148
|
+
const n = (t?.markets || Object.keys(U)).map((o) => C(o)).map((o) => ({
|
|
939
1149
|
address: e,
|
|
940
|
-
market:
|
|
1150
|
+
market: o.key
|
|
941
1151
|
}));
|
|
942
|
-
return await
|
|
1152
|
+
return await ie(e, n, t);
|
|
943
1153
|
}
|
|
944
1154
|
);
|
|
945
|
-
async function
|
|
946
|
-
const
|
|
947
|
-
await
|
|
948
|
-
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({
|
|
949
1159
|
transactionBlock: n,
|
|
950
1160
|
sender: e
|
|
951
|
-
}), a = H(
|
|
952
|
-
return
|
|
1161
|
+
}), a = H(o, [l.u256()]);
|
|
1162
|
+
return re(Number(a[0]) || 0);
|
|
953
1163
|
}
|
|
954
|
-
async function
|
|
955
|
-
const
|
|
956
|
-
let
|
|
957
|
-
const
|
|
958
|
-
if (
|
|
959
|
-
|
|
960
|
-
}),
|
|
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)
|
|
961
1171
|
throw new Error("Invalid operations");
|
|
962
|
-
const
|
|
963
|
-
await
|
|
1172
|
+
const p = c > 0 || i > 0;
|
|
1173
|
+
await ae(
|
|
964
1174
|
a,
|
|
965
1175
|
e,
|
|
966
|
-
|
|
967
|
-
Math.abs(
|
|
1176
|
+
s,
|
|
1177
|
+
Math.abs(c),
|
|
968
1178
|
Math.abs(i),
|
|
969
|
-
|
|
1179
|
+
p,
|
|
970
1180
|
n
|
|
971
1181
|
);
|
|
972
|
-
const m = await
|
|
1182
|
+
const m = await o.devInspectTransactionBlock({
|
|
973
1183
|
transactionBlock: a,
|
|
974
1184
|
sender: e
|
|
975
|
-
}), h = H(m, [
|
|
976
|
-
return
|
|
1185
|
+
}), h = H(m, [l.u256()]);
|
|
1186
|
+
return re(Number(h[0]) || 0);
|
|
977
1187
|
}
|
|
978
|
-
const
|
|
979
|
-
async (e,
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
const n = `https://open-api.naviprotocol.io/api/navi/user/transactions?${
|
|
983
|
-
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;
|
|
984
1194
|
}
|
|
985
1195
|
);
|
|
986
|
-
async function
|
|
987
|
-
let
|
|
988
|
-
const n = [],
|
|
1196
|
+
async function vt(e, t) {
|
|
1197
|
+
let r = null;
|
|
1198
|
+
const n = [], o = t?.client ?? V;
|
|
989
1199
|
do {
|
|
990
1200
|
let a;
|
|
991
|
-
if (
|
|
1201
|
+
if (t?.coinType ? a = await o.getCoins({
|
|
992
1202
|
owner: e,
|
|
993
|
-
coinType:
|
|
994
|
-
cursor:
|
|
1203
|
+
coinType: t?.coinType,
|
|
1204
|
+
cursor: r,
|
|
995
1205
|
limit: 100
|
|
996
|
-
}) : a = await
|
|
1206
|
+
}) : a = await o.getAllCoins({
|
|
997
1207
|
owner: e,
|
|
998
|
-
cursor:
|
|
1208
|
+
cursor: r,
|
|
999
1209
|
limit: 100
|
|
1000
1210
|
}), !a.data || !a.data.length)
|
|
1001
1211
|
break;
|
|
1002
|
-
n.push(...a.data),
|
|
1003
|
-
} while (
|
|
1212
|
+
n.push(...a.data), r = a.nextCursor;
|
|
1213
|
+
} while (r);
|
|
1004
1214
|
return n;
|
|
1005
1215
|
}
|
|
1006
|
-
const
|
|
1007
|
-
async (e,
|
|
1008
|
-
const
|
|
1009
|
-
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 = [];
|
|
1010
1220
|
try {
|
|
1011
|
-
|
|
1221
|
+
o = await ne(e, t);
|
|
1012
1222
|
} catch (i) {
|
|
1013
1223
|
console.error(i);
|
|
1014
1224
|
}
|
|
@@ -1016,103 +1226,103 @@ const Ee = M(
|
|
|
1016
1226
|
address: e,
|
|
1017
1227
|
market: i.key
|
|
1018
1228
|
})).concat(
|
|
1019
|
-
|
|
1229
|
+
o.filter((i) => !!n.find((s) => s.id === i.marketId)).map((i) => ({
|
|
1020
1230
|
address: i.accountCap,
|
|
1021
|
-
market:
|
|
1231
|
+
market: C(i.marketId).key,
|
|
1022
1232
|
emodeId: i.emodeId
|
|
1023
1233
|
}))
|
|
1024
1234
|
);
|
|
1025
|
-
return (await
|
|
1026
|
-
const
|
|
1027
|
-
const m =
|
|
1028
|
-
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;
|
|
1029
1239
|
}) : void 0;
|
|
1030
|
-
if (
|
|
1031
|
-
if (!i.pool.emodes.find((m) => m.emodeId ===
|
|
1240
|
+
if (s) {
|
|
1241
|
+
if (!i.pool.emodes.find((m) => m.emodeId === s.emodeId))
|
|
1032
1242
|
return;
|
|
1033
|
-
if (
|
|
1034
|
-
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);
|
|
1035
1245
|
if (m.gt(0) || h.emode.isCollateral)
|
|
1036
1246
|
try {
|
|
1037
|
-
|
|
1038
|
-
id: `${i.pool.uniqueId}_${
|
|
1247
|
+
r.push({
|
|
1248
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-supply-${B()}`,
|
|
1039
1249
|
wallet: e,
|
|
1040
1250
|
protocol: "navi",
|
|
1041
1251
|
market: i.market,
|
|
1042
1252
|
type: "navi-lending-emode-supply",
|
|
1043
1253
|
"navi-lending-emode-supply": {
|
|
1044
1254
|
amount: m.toString(),
|
|
1045
|
-
pool:
|
|
1255
|
+
pool: L(i.pool, s),
|
|
1046
1256
|
token: i.pool.token,
|
|
1047
1257
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1048
|
-
emodeCap:
|
|
1258
|
+
emodeCap: s
|
|
1049
1259
|
}
|
|
1050
1260
|
});
|
|
1051
|
-
} catch (
|
|
1052
|
-
console.error(
|
|
1261
|
+
} catch (w) {
|
|
1262
|
+
console.error(w);
|
|
1053
1263
|
}
|
|
1054
1264
|
}
|
|
1055
|
-
if (
|
|
1056
|
-
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);
|
|
1057
1267
|
if (m.gt(0) || h.emode.isDebt)
|
|
1058
1268
|
try {
|
|
1059
|
-
|
|
1060
|
-
id: `${i.pool.uniqueId}_${
|
|
1269
|
+
r.push({
|
|
1270
|
+
id: `${i.pool.uniqueId}_${s.emodeId}_navi-lending-emode-borrow-${B()}`,
|
|
1061
1271
|
wallet: e,
|
|
1062
1272
|
protocol: "navi",
|
|
1063
1273
|
market: i.market,
|
|
1064
1274
|
type: "navi-lending-emode-borrow",
|
|
1065
1275
|
"navi-lending-emode-borrow": {
|
|
1066
1276
|
amount: m.toString(),
|
|
1067
|
-
pool:
|
|
1277
|
+
pool: L(i.pool, s),
|
|
1068
1278
|
token: i.pool.token,
|
|
1069
1279
|
valueUSD: m.multipliedBy(i.pool.oracle.price).toString(),
|
|
1070
|
-
emodeCap:
|
|
1280
|
+
emodeCap: s
|
|
1071
1281
|
}
|
|
1072
1282
|
});
|
|
1073
|
-
} catch (
|
|
1074
|
-
console.error(
|
|
1283
|
+
} catch (w) {
|
|
1284
|
+
console.error(w);
|
|
1075
1285
|
}
|
|
1076
1286
|
}
|
|
1077
1287
|
} else {
|
|
1078
|
-
if (
|
|
1079
|
-
const
|
|
1080
|
-
|
|
1081
|
-
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()}`,
|
|
1082
1292
|
wallet: e,
|
|
1083
1293
|
protocol: "navi",
|
|
1084
1294
|
type: "navi-lending-supply",
|
|
1085
1295
|
market: i.market,
|
|
1086
1296
|
"navi-lending-supply": {
|
|
1087
|
-
amount:
|
|
1297
|
+
amount: p.toString(),
|
|
1088
1298
|
pool: i.pool,
|
|
1089
1299
|
token: i.pool.token,
|
|
1090
|
-
valueUSD:
|
|
1300
|
+
valueUSD: p.multipliedBy(i.pool.oracle.price).toString()
|
|
1091
1301
|
}
|
|
1092
1302
|
});
|
|
1093
1303
|
}
|
|
1094
|
-
if (
|
|
1095
|
-
const
|
|
1096
|
-
|
|
1097
|
-
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()}`,
|
|
1098
1308
|
wallet: e,
|
|
1099
1309
|
protocol: "navi",
|
|
1100
1310
|
market: i.market,
|
|
1101
1311
|
type: "navi-lending-borrow",
|
|
1102
1312
|
"navi-lending-borrow": {
|
|
1103
|
-
amount:
|
|
1313
|
+
amount: p.toString(),
|
|
1104
1314
|
pool: i.pool,
|
|
1105
1315
|
token: i.pool.token,
|
|
1106
|
-
valueUSD:
|
|
1316
|
+
valueUSD: p.multipliedBy(i.pool.oracle.price).toString()
|
|
1107
1317
|
}
|
|
1108
1318
|
});
|
|
1109
1319
|
}
|
|
1110
1320
|
}
|
|
1111
|
-
}),
|
|
1321
|
+
}), r;
|
|
1112
1322
|
}
|
|
1113
1323
|
);
|
|
1114
|
-
class
|
|
1115
|
-
constructor(
|
|
1324
|
+
class D {
|
|
1325
|
+
constructor(t, r) {
|
|
1116
1326
|
this._positions = [], this._priceMap = {}, this._overview = {
|
|
1117
1327
|
hf: 1 / 0,
|
|
1118
1328
|
netVaule: "0",
|
|
@@ -1125,7 +1335,7 @@ class N {
|
|
|
1125
1335
|
maxLoanToVaule: "0",
|
|
1126
1336
|
supply: {},
|
|
1127
1337
|
borrow: {}
|
|
1128
|
-
}, this._priceMap =
|
|
1338
|
+
}, this._priceMap = r || {}, this.positions = t;
|
|
1129
1339
|
}
|
|
1130
1340
|
get positions() {
|
|
1131
1341
|
return this._positions;
|
|
@@ -1136,350 +1346,350 @@ class N {
|
|
|
1136
1346
|
get priceMap() {
|
|
1137
1347
|
return this._priceMap;
|
|
1138
1348
|
}
|
|
1139
|
-
set positions(
|
|
1140
|
-
this._positions =
|
|
1141
|
-
}
|
|
1142
|
-
updatePriceMap(
|
|
1143
|
-
return this._priceMap =
|
|
1144
|
-
}
|
|
1145
|
-
getPrice(
|
|
1146
|
-
const
|
|
1147
|
-
if (this._priceMap[
|
|
1148
|
-
return this._priceMap[
|
|
1149
|
-
const n =
|
|
1150
|
-
return this._priceMap[n] !== void 0 ? this._priceMap[n].toString() :
|
|
1151
|
-
}
|
|
1152
|
-
filterPositionsByPool(
|
|
1153
|
-
const n = !!
|
|
1154
|
-
return new
|
|
1155
|
-
this.positions.filter((
|
|
1156
|
-
const a =
|
|
1157
|
-
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;
|
|
1158
1368
|
}),
|
|
1159
1369
|
this._priceMap
|
|
1160
1370
|
);
|
|
1161
1371
|
}
|
|
1162
|
-
deposit(
|
|
1163
|
-
const n = !!
|
|
1372
|
+
deposit(t, r) {
|
|
1373
|
+
const n = !!t.isEMode, o = this.getPrice(t);
|
|
1164
1374
|
let a;
|
|
1165
1375
|
return n ? a = {
|
|
1166
|
-
id:
|
|
1376
|
+
id: B(),
|
|
1167
1377
|
wallet: "",
|
|
1168
1378
|
protocol: "navi",
|
|
1169
1379
|
market: "",
|
|
1170
1380
|
type: "navi-lending-emode-supply",
|
|
1171
1381
|
"navi-lending-emode-supply": {
|
|
1172
|
-
amount:
|
|
1173
|
-
valueUSD:
|
|
1174
|
-
token:
|
|
1175
|
-
pool:
|
|
1382
|
+
amount: r.toString(),
|
|
1383
|
+
valueUSD: d(r).multipliedBy(o).toString(),
|
|
1384
|
+
token: t.token,
|
|
1385
|
+
pool: t,
|
|
1176
1386
|
emodeCap: {}
|
|
1177
1387
|
}
|
|
1178
1388
|
} : a = {
|
|
1179
|
-
id:
|
|
1389
|
+
id: B(),
|
|
1180
1390
|
wallet: "",
|
|
1181
1391
|
protocol: "navi",
|
|
1182
1392
|
market: "",
|
|
1183
1393
|
type: "navi-lending-supply",
|
|
1184
1394
|
"navi-lending-supply": {
|
|
1185
|
-
amount:
|
|
1186
|
-
valueUSD:
|
|
1187
|
-
token:
|
|
1188
|
-
pool:
|
|
1395
|
+
amount: r.toString(),
|
|
1396
|
+
valueUSD: d(r).multipliedBy(o).toString(),
|
|
1397
|
+
token: t.token,
|
|
1398
|
+
pool: t
|
|
1189
1399
|
}
|
|
1190
|
-
}, new
|
|
1400
|
+
}, new D([...this.positions, a], this._priceMap);
|
|
1191
1401
|
}
|
|
1192
|
-
withdraw(
|
|
1193
|
-
const n = !!
|
|
1402
|
+
withdraw(t, r) {
|
|
1403
|
+
const n = !!t.isEMode, o = this.getPrice(t);
|
|
1194
1404
|
let a;
|
|
1195
1405
|
return n ? a = {
|
|
1196
|
-
id:
|
|
1406
|
+
id: B(),
|
|
1197
1407
|
wallet: "",
|
|
1198
1408
|
protocol: "navi",
|
|
1199
1409
|
market: "",
|
|
1200
1410
|
type: "navi-lending-emode-supply",
|
|
1201
1411
|
"navi-lending-emode-supply": {
|
|
1202
|
-
amount: (-
|
|
1203
|
-
valueUSD:
|
|
1204
|
-
token:
|
|
1205
|
-
pool:
|
|
1412
|
+
amount: (-r).toString(),
|
|
1413
|
+
valueUSD: d(-r).multipliedBy(o).toString(),
|
|
1414
|
+
token: t.token,
|
|
1415
|
+
pool: t,
|
|
1206
1416
|
emodeCap: {}
|
|
1207
1417
|
}
|
|
1208
1418
|
} : a = {
|
|
1209
|
-
id:
|
|
1419
|
+
id: B(),
|
|
1210
1420
|
wallet: "",
|
|
1211
1421
|
protocol: "navi",
|
|
1212
1422
|
market: "",
|
|
1213
1423
|
type: "navi-lending-supply",
|
|
1214
1424
|
"navi-lending-supply": {
|
|
1215
|
-
amount: (-
|
|
1216
|
-
valueUSD:
|
|
1217
|
-
token:
|
|
1218
|
-
pool:
|
|
1425
|
+
amount: (-r).toString(),
|
|
1426
|
+
valueUSD: d(-r).multipliedBy(o).toString(),
|
|
1427
|
+
token: t.token,
|
|
1428
|
+
pool: t
|
|
1219
1429
|
}
|
|
1220
|
-
}, new
|
|
1430
|
+
}, new D([...this.positions, a], this._priceMap);
|
|
1221
1431
|
}
|
|
1222
|
-
borrow(
|
|
1223
|
-
const n = !!
|
|
1432
|
+
borrow(t, r) {
|
|
1433
|
+
const n = !!t.isEMode, o = this.getPrice(t);
|
|
1224
1434
|
let a;
|
|
1225
1435
|
return n ? a = {
|
|
1226
|
-
id:
|
|
1436
|
+
id: B(),
|
|
1227
1437
|
wallet: "",
|
|
1228
1438
|
protocol: "navi",
|
|
1229
1439
|
market: "",
|
|
1230
1440
|
type: "navi-lending-emode-borrow",
|
|
1231
1441
|
"navi-lending-emode-borrow": {
|
|
1232
|
-
amount:
|
|
1233
|
-
valueUSD:
|
|
1234
|
-
token:
|
|
1235
|
-
pool:
|
|
1442
|
+
amount: r.toString(),
|
|
1443
|
+
valueUSD: d(r).multipliedBy(o).toString(),
|
|
1444
|
+
token: t.token,
|
|
1445
|
+
pool: t,
|
|
1236
1446
|
emodeCap: {}
|
|
1237
1447
|
}
|
|
1238
1448
|
} : a = {
|
|
1239
|
-
id:
|
|
1449
|
+
id: B(),
|
|
1240
1450
|
wallet: "",
|
|
1241
1451
|
protocol: "navi",
|
|
1242
1452
|
market: "",
|
|
1243
1453
|
type: "navi-lending-borrow",
|
|
1244
1454
|
"navi-lending-borrow": {
|
|
1245
|
-
amount:
|
|
1246
|
-
valueUSD:
|
|
1247
|
-
token:
|
|
1248
|
-
pool:
|
|
1455
|
+
amount: r.toString(),
|
|
1456
|
+
valueUSD: d(r).multipliedBy(o).toString(),
|
|
1457
|
+
token: t.token,
|
|
1458
|
+
pool: t
|
|
1249
1459
|
}
|
|
1250
|
-
}, new
|
|
1460
|
+
}, new D([...this.positions, a], this._priceMap);
|
|
1251
1461
|
}
|
|
1252
|
-
repay(
|
|
1253
|
-
const n = !!
|
|
1462
|
+
repay(t, r) {
|
|
1463
|
+
const n = !!t.isEMode, o = this.getPrice(t);
|
|
1254
1464
|
let a;
|
|
1255
1465
|
return n ? a = {
|
|
1256
|
-
id:
|
|
1466
|
+
id: B(),
|
|
1257
1467
|
wallet: "",
|
|
1258
1468
|
protocol: "navi",
|
|
1259
1469
|
market: "",
|
|
1260
1470
|
type: "navi-lending-emode-borrow",
|
|
1261
1471
|
"navi-lending-emode-borrow": {
|
|
1262
|
-
amount: (-
|
|
1263
|
-
valueUSD:
|
|
1264
|
-
token:
|
|
1265
|
-
pool:
|
|
1472
|
+
amount: (-r).toString(),
|
|
1473
|
+
valueUSD: d(-r).multipliedBy(o).toString(),
|
|
1474
|
+
token: t.token,
|
|
1475
|
+
pool: t,
|
|
1266
1476
|
emodeCap: {}
|
|
1267
1477
|
}
|
|
1268
1478
|
} : a = {
|
|
1269
|
-
id:
|
|
1479
|
+
id: B(),
|
|
1270
1480
|
wallet: "",
|
|
1271
1481
|
protocol: "navi",
|
|
1272
1482
|
market: "",
|
|
1273
1483
|
type: "navi-lending-borrow",
|
|
1274
1484
|
"navi-lending-borrow": {
|
|
1275
|
-
amount: (-
|
|
1276
|
-
valueUSD:
|
|
1277
|
-
token:
|
|
1278
|
-
pool:
|
|
1485
|
+
amount: (-r).toString(),
|
|
1486
|
+
valueUSD: d(-r).multipliedBy(o).toString(),
|
|
1487
|
+
token: t.token,
|
|
1488
|
+
pool: t
|
|
1279
1489
|
}
|
|
1280
|
-
}, new
|
|
1490
|
+
}, new D([...this.positions, a], this._priceMap);
|
|
1281
1491
|
}
|
|
1282
|
-
resolveValueUSD(
|
|
1283
|
-
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;
|
|
1284
1494
|
}
|
|
1285
|
-
getPositionsOverview(
|
|
1286
|
-
const
|
|
1287
|
-
let
|
|
1288
|
-
|
|
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) => {
|
|
1289
1499
|
if (y.type === "navi-lending-supply") {
|
|
1290
|
-
const
|
|
1291
|
-
|
|
1292
|
-
new
|
|
1293
|
-
),
|
|
1294
|
-
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)
|
|
1295
1505
|
);
|
|
1296
1506
|
} else if (y.type === "navi-lending-borrow") {
|
|
1297
|
-
const
|
|
1298
|
-
a = a.plus(this.resolveValueUSD(
|
|
1507
|
+
const u = y["navi-lending-borrow"];
|
|
1508
|
+
a = a.plus(this.resolveValueUSD(u));
|
|
1299
1509
|
} else if (y.type === "navi-lending-emode-supply") {
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1302
|
-
const
|
|
1303
|
-
|
|
1304
|
-
new
|
|
1305
|
-
),
|
|
1306
|
-
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)
|
|
1307
1517
|
);
|
|
1308
1518
|
} else if (y.type === "navi-lending-emode-borrow") {
|
|
1309
|
-
const
|
|
1310
|
-
a = a.plus(this.resolveValueUSD(
|
|
1519
|
+
const u = y["navi-lending-emode-borrow"];
|
|
1520
|
+
a = a.plus(this.resolveValueUSD(u));
|
|
1311
1521
|
}
|
|
1312
|
-
}), 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) => {
|
|
1313
1523
|
if (y.type === "navi-lending-supply") {
|
|
1314
|
-
const
|
|
1315
|
-
|
|
1316
|
-
new
|
|
1317
|
-
)),
|
|
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();
|
|
1318
1528
|
} else if (y.type === "navi-lending-borrow") {
|
|
1319
|
-
const
|
|
1529
|
+
const u = y["navi-lending-borrow"], f = this.resolveValueUSD(u), v = u.pool.borrowIncentiveApyInfo.apy;
|
|
1320
1530
|
a.gt(0) && (i = i.plus(
|
|
1321
|
-
new
|
|
1322
|
-
)), 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();
|
|
1323
1533
|
} else if (y.type === "navi-lending-emode-supply") {
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1326
|
-
new
|
|
1327
|
-
)),
|
|
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();
|
|
1328
1538
|
} else if (y.type === "navi-lending-emode-borrow") {
|
|
1329
|
-
const
|
|
1539
|
+
const u = y["navi-lending-emode-borrow"], f = this.resolveValueUSD(u), v = u.pool.borrowIncentiveApyInfo.apy;
|
|
1330
1540
|
a.gt(0) && (i = i.plus(
|
|
1331
|
-
new
|
|
1332
|
-
)), 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();
|
|
1333
1543
|
}
|
|
1334
1544
|
});
|
|
1335
|
-
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));
|
|
1336
1546
|
return {
|
|
1337
|
-
hf: a.toNumber() !== 0 ?
|
|
1547
|
+
hf: a.toNumber() !== 0 ? s.dividedBy(a).toNumber() : 1 / 0,
|
|
1338
1548
|
netVaule: m.toString(),
|
|
1339
1549
|
netWorthApr: h.toString(),
|
|
1340
|
-
totalSupplyValue:
|
|
1550
|
+
totalSupplyValue: o.toString(),
|
|
1341
1551
|
totalBorrowValue: a.toString(),
|
|
1342
|
-
totalsupplyApy:
|
|
1552
|
+
totalsupplyApy: c.toString(),
|
|
1343
1553
|
totalBorrowApy: i.toString(),
|
|
1344
|
-
maxLiquidationValue:
|
|
1345
|
-
maxLoanToVaule:
|
|
1346
|
-
supply:
|
|
1554
|
+
maxLiquidationValue: s.toString(),
|
|
1555
|
+
maxLoanToVaule: p.toString(),
|
|
1556
|
+
supply: r,
|
|
1347
1557
|
borrow: n
|
|
1348
1558
|
};
|
|
1349
1559
|
}
|
|
1350
1560
|
}
|
|
1351
|
-
async function
|
|
1352
|
-
const
|
|
1561
|
+
async function bt(e, t, r, n) {
|
|
1562
|
+
const o = await _({
|
|
1353
1563
|
...n,
|
|
1354
1564
|
cacheTime: b
|
|
1355
1565
|
});
|
|
1356
|
-
|
|
1357
|
-
target: `${
|
|
1566
|
+
o.limter && e.moveCall({
|
|
1567
|
+
target: `${o.limter}::navi_adaptor::verify_navi_position_healthy`,
|
|
1358
1568
|
arguments: [
|
|
1359
1569
|
e.object("0x06"),
|
|
1360
|
-
e.object(
|
|
1361
|
-
e.object(
|
|
1362
|
-
g(
|
|
1363
|
-
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())
|
|
1364
1574
|
]
|
|
1365
1575
|
});
|
|
1366
1576
|
}
|
|
1367
|
-
const
|
|
1577
|
+
const ce = new te("https://hermes.pyth.network", {
|
|
1368
1578
|
timeout: 1e4
|
|
1369
1579
|
});
|
|
1370
|
-
async function
|
|
1580
|
+
async function kt(e) {
|
|
1371
1581
|
try {
|
|
1372
|
-
const
|
|
1373
|
-
if (!
|
|
1582
|
+
const t = [], r = await ce.getLatestPriceFeeds(e);
|
|
1583
|
+
if (!r) return t;
|
|
1374
1584
|
const n = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1375
|
-
for (const
|
|
1376
|
-
const a =
|
|
1585
|
+
for (const o of r) {
|
|
1586
|
+
const a = o.getPriceUnchecked();
|
|
1377
1587
|
if (a.publishTime > n) {
|
|
1378
1588
|
console.warn(
|
|
1379
|
-
`pyth price feed is invalid, id: ${
|
|
1589
|
+
`pyth price feed is invalid, id: ${o.id}, publish time: ${a.publishTime}, current timestamp: ${n}`
|
|
1380
1590
|
);
|
|
1381
1591
|
continue;
|
|
1382
1592
|
}
|
|
1383
|
-
n -
|
|
1384
|
-
`stale price feed, id: ${
|
|
1385
|
-
),
|
|
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));
|
|
1386
1596
|
}
|
|
1387
|
-
return
|
|
1388
|
-
} catch (
|
|
1389
|
-
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}`);
|
|
1390
1600
|
}
|
|
1391
1601
|
}
|
|
1392
|
-
async function
|
|
1602
|
+
async function Le(e, t) {
|
|
1393
1603
|
try {
|
|
1394
|
-
const
|
|
1395
|
-
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)),
|
|
1396
1606
|
options: { showContent: !0 }
|
|
1397
1607
|
});
|
|
1398
|
-
for (const
|
|
1399
|
-
const i =
|
|
1608
|
+
for (const c of a) {
|
|
1609
|
+
const i = c.data;
|
|
1400
1610
|
if (!i || !i.content || i.content.dataType !== "moveObject") {
|
|
1401
1611
|
console.warn(`fetched object ${i?.objectId} datatype should be moveObject`);
|
|
1402
1612
|
continue;
|
|
1403
1613
|
}
|
|
1404
|
-
const
|
|
1405
|
-
if (!
|
|
1614
|
+
const s = e.find((u) => u.priceInfoObject == i.objectId);
|
|
1615
|
+
if (!s) {
|
|
1406
1616
|
console.warn(`unable to find pyth info from array, priceInfoObject: ${i.objectId}`);
|
|
1407
1617
|
continue;
|
|
1408
1618
|
}
|
|
1409
|
-
const
|
|
1410
|
-
|
|
1411
|
-
priceFeedId:
|
|
1412
|
-
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,
|
|
1413
1623
|
price: h ? "-" + m : m,
|
|
1414
|
-
conf:
|
|
1624
|
+
conf: w,
|
|
1415
1625
|
publishTime: Number(y),
|
|
1416
|
-
expiration:
|
|
1626
|
+
expiration: s.expiration
|
|
1417
1627
|
});
|
|
1418
1628
|
}
|
|
1419
|
-
return
|
|
1420
|
-
} catch (
|
|
1421
|
-
console.error(
|
|
1629
|
+
return r;
|
|
1630
|
+
} catch (r) {
|
|
1631
|
+
console.error(r, `Polling Sui on-chain price for ${e} failed.`);
|
|
1422
1632
|
return;
|
|
1423
1633
|
}
|
|
1424
1634
|
}
|
|
1425
|
-
async function
|
|
1635
|
+
async function He(e, t) {
|
|
1426
1636
|
try {
|
|
1427
|
-
const
|
|
1428
|
-
if (!n) return
|
|
1429
|
-
const
|
|
1637
|
+
const r = [], n = await Le(e, t);
|
|
1638
|
+
if (!n) return r;
|
|
1639
|
+
const o = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1430
1640
|
for (const a of n) {
|
|
1431
|
-
if (a.publishTime >
|
|
1641
|
+
if (a.publishTime > o) {
|
|
1432
1642
|
console.warn(
|
|
1433
|
-
`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}`
|
|
1434
1644
|
);
|
|
1435
1645
|
continue;
|
|
1436
1646
|
}
|
|
1437
|
-
const
|
|
1438
|
-
|
|
1439
|
-
`stale price feed, id: ${a.priceFeedId}, publish time: ${a.publishTime}, current timestamp: ${
|
|
1440
|
-
),
|
|
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));
|
|
1441
1651
|
}
|
|
1442
|
-
return
|
|
1443
|
-
} catch (
|
|
1444
|
-
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}`);
|
|
1445
1655
|
}
|
|
1446
1656
|
}
|
|
1447
|
-
async function
|
|
1448
|
-
const n =
|
|
1449
|
-
...
|
|
1657
|
+
async function We(e, t, r) {
|
|
1658
|
+
const n = r?.client ?? V, o = await _({
|
|
1659
|
+
...r,
|
|
1450
1660
|
cacheTime: b
|
|
1451
1661
|
});
|
|
1452
1662
|
try {
|
|
1453
|
-
const a = await
|
|
1454
|
-
return await new
|
|
1663
|
+
const a = await ce.getPriceFeedsUpdateData(t);
|
|
1664
|
+
return await new $e(
|
|
1455
1665
|
n,
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
).updatePriceFeeds(e, a,
|
|
1666
|
+
o.oracle.pythStateId,
|
|
1667
|
+
o.oracle.wormholeStateId
|
|
1668
|
+
).updatePriceFeeds(e, a, t);
|
|
1459
1669
|
} catch (a) {
|
|
1460
1670
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
1461
1671
|
}
|
|
1462
1672
|
}
|
|
1463
|
-
async function
|
|
1673
|
+
async function ze(e, t, r) {
|
|
1464
1674
|
const n = await _({
|
|
1465
|
-
...
|
|
1675
|
+
...r,
|
|
1466
1676
|
cacheTime: b
|
|
1467
1677
|
});
|
|
1468
|
-
if (
|
|
1469
|
-
const
|
|
1678
|
+
if (r?.updatePythPriceFeeds) {
|
|
1679
|
+
const o = t.filter((a) => !!a.pythPriceFeedId && !!a.pythPriceInfoObject).map((a) => ({
|
|
1470
1680
|
priceFeedId: a.pythPriceFeedId,
|
|
1471
1681
|
priceInfoObject: a.pythPriceInfoObject,
|
|
1472
1682
|
expiration: 30
|
|
1473
1683
|
}));
|
|
1474
1684
|
try {
|
|
1475
|
-
const a = await
|
|
1476
|
-
a.length > 0 && await
|
|
1685
|
+
const a = await He(o, r);
|
|
1686
|
+
a.length > 0 && await We(e, a, r);
|
|
1477
1687
|
} catch {
|
|
1478
1688
|
console.error("Failed to update Pyth price feeds");
|
|
1479
1689
|
}
|
|
1480
1690
|
}
|
|
1481
|
-
for (const
|
|
1482
|
-
|
|
1691
|
+
for (const o of t)
|
|
1692
|
+
r?.env === "dev" ? e.moveCall({
|
|
1483
1693
|
target: `${n.oracle.packageId}::oracle_pro::update_single_price`,
|
|
1484
1694
|
arguments: [
|
|
1485
1695
|
e.object("0x6"),
|
|
@@ -1490,9 +1700,9 @@ async function Ne(e, r, o) {
|
|
|
1490
1700
|
// Price oracle contract
|
|
1491
1701
|
e.object(n.oracle.supraOracleHolder),
|
|
1492
1702
|
// Supra oracle holder
|
|
1493
|
-
e.object(
|
|
1703
|
+
e.object(o.pythPriceInfoObject),
|
|
1494
1704
|
// Pyth price info object
|
|
1495
|
-
e.pure.address(
|
|
1705
|
+
e.pure.address(o.feedId)
|
|
1496
1706
|
// Price feed ID
|
|
1497
1707
|
]
|
|
1498
1708
|
}) : e.moveCall({
|
|
@@ -1506,140 +1716,140 @@ async function Ne(e, r, o) {
|
|
|
1506
1716
|
// Price oracle contract
|
|
1507
1717
|
e.object(n.oracle.supraOracleHolder),
|
|
1508
1718
|
// Supra oracle holder
|
|
1509
|
-
e.object(
|
|
1719
|
+
e.object(o.pythPriceInfoObject),
|
|
1510
1720
|
// Pyth price info object
|
|
1511
1721
|
e.object(n.oracle.switchboardAggregator),
|
|
1512
|
-
e.pure.address(
|
|
1722
|
+
e.pure.address(o.feedId)
|
|
1513
1723
|
// Price feed ID
|
|
1514
1724
|
]
|
|
1515
1725
|
});
|
|
1516
1726
|
return e;
|
|
1517
1727
|
}
|
|
1518
|
-
async function
|
|
1728
|
+
async function se(e) {
|
|
1519
1729
|
return (await _({
|
|
1520
1730
|
...e,
|
|
1521
1731
|
cacheTime: b
|
|
1522
1732
|
})).oracle.feeds;
|
|
1523
1733
|
}
|
|
1524
|
-
function
|
|
1525
|
-
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) => {
|
|
1526
1736
|
if (![
|
|
1527
1737
|
"navi-lending-supply",
|
|
1528
1738
|
"navi-lending-borrow",
|
|
1529
1739
|
"navi-lending-emode-supply",
|
|
1530
1740
|
"navi-lending-emode-borrow"
|
|
1531
|
-
].includes(
|
|
1741
|
+
].includes(o.type))
|
|
1532
1742
|
return !1;
|
|
1533
|
-
const
|
|
1534
|
-
return
|
|
1535
|
-
}) ||
|
|
1743
|
+
const c = o[o.type]?.pool;
|
|
1744
|
+
return r.oracleId === c?.oracleId;
|
|
1745
|
+
}) || t?.pools && t.pools.find((o) => r.oracleId === o.oracleId)));
|
|
1536
1746
|
}
|
|
1537
|
-
async function
|
|
1747
|
+
async function _t(e, t, r, n) {
|
|
1538
1748
|
try {
|
|
1539
|
-
const
|
|
1749
|
+
const o = await se({
|
|
1540
1750
|
...n
|
|
1541
1751
|
}), a = [];
|
|
1542
|
-
|
|
1543
|
-
a.includes(
|
|
1752
|
+
r.forEach((p) => {
|
|
1753
|
+
a.includes(p.market) || a.push(p.market);
|
|
1544
1754
|
});
|
|
1545
|
-
const
|
|
1755
|
+
const c = await qe(t, {
|
|
1546
1756
|
...n,
|
|
1547
1757
|
markets: a
|
|
1548
|
-
}), i =
|
|
1549
|
-
lendingPositions:
|
|
1550
|
-
pools:
|
|
1758
|
+
}), i = Ge(o, {
|
|
1759
|
+
lendingPositions: c,
|
|
1760
|
+
pools: r
|
|
1551
1761
|
});
|
|
1552
|
-
return await
|
|
1762
|
+
return await ze(e, i, {
|
|
1553
1763
|
updatePythPriceFeeds: !0,
|
|
1554
1764
|
...n
|
|
1555
1765
|
});
|
|
1556
|
-
} catch (
|
|
1766
|
+
} catch (o) {
|
|
1557
1767
|
if (n?.throws)
|
|
1558
|
-
throw
|
|
1559
|
-
return console.error(
|
|
1768
|
+
throw o;
|
|
1769
|
+
return console.error(o), e;
|
|
1560
1770
|
}
|
|
1561
1771
|
}
|
|
1562
|
-
const Y =
|
|
1563
|
-
|
|
1772
|
+
const Y = S(
|
|
1773
|
+
A(
|
|
1564
1774
|
async (e) => {
|
|
1565
|
-
const
|
|
1566
|
-
return Object.keys(
|
|
1567
|
-
...
|
|
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],
|
|
1568
1778
|
coinType: n
|
|
1569
1779
|
}));
|
|
1570
1780
|
}
|
|
1571
1781
|
)
|
|
1572
1782
|
);
|
|
1573
|
-
async function
|
|
1574
|
-
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;
|
|
1575
1785
|
}
|
|
1576
|
-
async function
|
|
1577
|
-
const
|
|
1786
|
+
async function It(e, t, r, n) {
|
|
1787
|
+
const o = await _({
|
|
1578
1788
|
...n,
|
|
1579
1789
|
cacheTime: b
|
|
1580
|
-
}), a = await
|
|
1790
|
+
}), a = await $(t, n);
|
|
1581
1791
|
if (!(await Y({
|
|
1582
1792
|
...n,
|
|
1583
1793
|
cacheTime: b
|
|
1584
1794
|
})).some(
|
|
1585
|
-
(
|
|
1795
|
+
(s) => k(s.coinType) === k(a.suiCoinType)
|
|
1586
1796
|
))
|
|
1587
1797
|
throw new Error("Pool does not support flashloan");
|
|
1588
|
-
if (
|
|
1589
|
-
const [
|
|
1590
|
-
target: `${
|
|
1798
|
+
if (o.version === 1) {
|
|
1799
|
+
const [s, p] = e.moveCall({
|
|
1800
|
+
target: `${o.package}::lending::flash_loan_with_ctx`,
|
|
1591
1801
|
arguments: [
|
|
1592
|
-
e.object(
|
|
1802
|
+
e.object(o.flashloanConfig),
|
|
1593
1803
|
e.object(a.contract.pool),
|
|
1594
|
-
g(
|
|
1804
|
+
g(r, e.pure.u64)
|
|
1595
1805
|
],
|
|
1596
1806
|
typeArguments: [a.suiCoinType]
|
|
1597
1807
|
});
|
|
1598
|
-
return [
|
|
1808
|
+
return [s, p];
|
|
1599
1809
|
} else {
|
|
1600
|
-
const [
|
|
1601
|
-
target: `${
|
|
1810
|
+
const [s, p] = e.moveCall({
|
|
1811
|
+
target: `${o.package}::lending::flash_loan_with_ctx_v2`,
|
|
1602
1812
|
arguments: [
|
|
1603
|
-
e.object(
|
|
1813
|
+
e.object(o.flashloanConfig),
|
|
1604
1814
|
e.object(a.contract.pool),
|
|
1605
|
-
g(
|
|
1815
|
+
g(r, e.pure.u64),
|
|
1606
1816
|
e.object("0x05")
|
|
1607
1817
|
],
|
|
1608
1818
|
typeArguments: [a.suiCoinType]
|
|
1609
1819
|
});
|
|
1610
|
-
return [
|
|
1820
|
+
return [s, p];
|
|
1611
1821
|
}
|
|
1612
1822
|
}
|
|
1613
|
-
async function
|
|
1823
|
+
async function Ct(e, t, r, n, o) {
|
|
1614
1824
|
const a = await _({
|
|
1615
|
-
...
|
|
1825
|
+
...o,
|
|
1616
1826
|
cacheTime: b
|
|
1617
|
-
}),
|
|
1827
|
+
}), c = await $(t, o);
|
|
1618
1828
|
if (!(await Y({
|
|
1619
|
-
...
|
|
1829
|
+
...o,
|
|
1620
1830
|
cacheTime: b
|
|
1621
1831
|
})).some(
|
|
1622
|
-
(m) => k(m.coinType) === k(
|
|
1832
|
+
(m) => k(m.coinType) === k(c.suiCoinType)
|
|
1623
1833
|
))
|
|
1624
1834
|
throw new Error("Pool does not support flashloan");
|
|
1625
|
-
const [
|
|
1835
|
+
const [p] = e.moveCall({
|
|
1626
1836
|
target: `${a.package}::lending::flash_repay_with_ctx`,
|
|
1627
1837
|
arguments: [
|
|
1628
1838
|
e.object("0x06"),
|
|
1629
1839
|
e.object(a.storage),
|
|
1630
|
-
e.object(
|
|
1631
|
-
g(
|
|
1840
|
+
e.object(c.contract.pool),
|
|
1841
|
+
g(r, e.object),
|
|
1632
1842
|
g(n, e.object)
|
|
1633
1843
|
],
|
|
1634
|
-
typeArguments: [
|
|
1844
|
+
typeArguments: [c.suiCoinType]
|
|
1635
1845
|
});
|
|
1636
|
-
return [
|
|
1846
|
+
return [p];
|
|
1637
1847
|
}
|
|
1638
|
-
async function
|
|
1639
|
-
const
|
|
1848
|
+
async function Tt(e, t, r, n, o, a) {
|
|
1849
|
+
const c = {
|
|
1640
1850
|
...a,
|
|
1641
1851
|
cacheTime: b
|
|
1642
|
-
}, i = await _(
|
|
1852
|
+
}, i = await _(c), s = await $(t, c), p = await $(n, c);
|
|
1643
1853
|
if (i.version === 1) {
|
|
1644
1854
|
const [m, h] = e.moveCall({
|
|
1645
1855
|
target: `${i.package}::incentive_v3::liquidation`,
|
|
@@ -1650,24 +1860,24 @@ async function kt(e, r, o, n, t, a) {
|
|
|
1650
1860
|
// Price oracle for asset pricing
|
|
1651
1861
|
e.object(i.storage),
|
|
1652
1862
|
// Protocol storage
|
|
1653
|
-
e.pure.u8(
|
|
1863
|
+
e.pure.u8(s.id),
|
|
1654
1864
|
// Pay asset ID
|
|
1655
|
-
e.object(
|
|
1865
|
+
e.object(s.contract.pool),
|
|
1656
1866
|
// Pay asset pool contract
|
|
1657
|
-
g(
|
|
1867
|
+
g(r, e.object),
|
|
1658
1868
|
// Debt repayment amount
|
|
1659
|
-
e.pure.u8(
|
|
1869
|
+
e.pure.u8(p.id),
|
|
1660
1870
|
// Collateral asset ID
|
|
1661
|
-
e.object(
|
|
1871
|
+
e.object(p.contract.pool),
|
|
1662
1872
|
// Collateral asset pool contract
|
|
1663
|
-
g(
|
|
1873
|
+
g(o, e.pure.address),
|
|
1664
1874
|
// Borrower address
|
|
1665
1875
|
e.object(i.incentiveV2),
|
|
1666
1876
|
// Incentive V2 contract
|
|
1667
1877
|
e.object(i.incentiveV3)
|
|
1668
1878
|
// Incentive V3 contract
|
|
1669
1879
|
],
|
|
1670
|
-
typeArguments: [
|
|
1880
|
+
typeArguments: [s.suiCoinType, p.suiCoinType]
|
|
1671
1881
|
});
|
|
1672
1882
|
return [m, h];
|
|
1673
1883
|
} else {
|
|
@@ -1680,17 +1890,17 @@ async function kt(e, r, o, n, t, a) {
|
|
|
1680
1890
|
// Price oracle for asset pricing
|
|
1681
1891
|
e.object(i.storage),
|
|
1682
1892
|
// Protocol storage
|
|
1683
|
-
e.pure.u8(
|
|
1893
|
+
e.pure.u8(s.id),
|
|
1684
1894
|
// Pay asset ID
|
|
1685
|
-
e.object(
|
|
1895
|
+
e.object(s.contract.pool),
|
|
1686
1896
|
// Pay asset pool contract
|
|
1687
|
-
g(
|
|
1897
|
+
g(r, e.object),
|
|
1688
1898
|
// Debt repayment amount
|
|
1689
|
-
e.pure.u8(
|
|
1899
|
+
e.pure.u8(p.id),
|
|
1690
1900
|
// Collateral asset ID
|
|
1691
|
-
e.object(
|
|
1901
|
+
e.object(p.contract.pool),
|
|
1692
1902
|
// Collateral asset pool contract
|
|
1693
|
-
g(
|
|
1903
|
+
g(o, e.pure.address),
|
|
1694
1904
|
// Borrower address
|
|
1695
1905
|
e.object(i.incentiveV2),
|
|
1696
1906
|
// Incentive V2 contract
|
|
@@ -1699,327 +1909,327 @@ async function kt(e, r, o, n, t, a) {
|
|
|
1699
1909
|
e.object("0x05")
|
|
1700
1910
|
// SuiSystemState object
|
|
1701
1911
|
],
|
|
1702
|
-
typeArguments: [
|
|
1912
|
+
typeArguments: [s.suiCoinType, p.suiCoinType]
|
|
1703
1913
|
});
|
|
1704
1914
|
return [m, h];
|
|
1705
1915
|
}
|
|
1706
1916
|
}
|
|
1707
|
-
async function
|
|
1708
|
-
const n =
|
|
1709
|
-
...
|
|
1917
|
+
async function Ke(e, t, r) {
|
|
1918
|
+
const n = r?.client ?? V, o = new F(), a = await R({
|
|
1919
|
+
...r,
|
|
1710
1920
|
markets: Object.values(U),
|
|
1711
1921
|
cacheTime: b
|
|
1712
|
-
}),
|
|
1713
|
-
for (let m of
|
|
1922
|
+
}), c = await se(r);
|
|
1923
|
+
for (let m of t) {
|
|
1714
1924
|
const h = await _({
|
|
1715
|
-
...
|
|
1925
|
+
...r,
|
|
1716
1926
|
cacheTime: b,
|
|
1717
1927
|
market: m.market
|
|
1718
1928
|
});
|
|
1719
|
-
|
|
1929
|
+
o.moveCall({
|
|
1720
1930
|
target: `${h.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
1721
1931
|
arguments: [
|
|
1722
|
-
|
|
1932
|
+
o.object("0x06"),
|
|
1723
1933
|
// Clock object
|
|
1724
|
-
|
|
1934
|
+
o.object(h.storage),
|
|
1725
1935
|
// Protocol storage
|
|
1726
|
-
|
|
1936
|
+
o.object(h.incentiveV3),
|
|
1727
1937
|
// Incentive V3 contract
|
|
1728
|
-
|
|
1938
|
+
o.pure.address(m.address)
|
|
1729
1939
|
// User address
|
|
1730
1940
|
]
|
|
1731
1941
|
});
|
|
1732
1942
|
}
|
|
1733
1943
|
const i = await n.devInspectTransactionBlock({
|
|
1734
|
-
transactionBlock:
|
|
1944
|
+
transactionBlock: o,
|
|
1735
1945
|
sender: e
|
|
1736
|
-
}),
|
|
1946
|
+
}), s = [];
|
|
1737
1947
|
i?.results?.forEach((m) => {
|
|
1738
|
-
|
|
1948
|
+
s.push(
|
|
1739
1949
|
H(
|
|
1740
1950
|
{
|
|
1741
1951
|
results: [m]
|
|
1742
1952
|
},
|
|
1743
1953
|
[
|
|
1744
|
-
|
|
1954
|
+
l.vector(l.string()),
|
|
1745
1955
|
// Asset coin types
|
|
1746
|
-
|
|
1956
|
+
l.vector(l.string()),
|
|
1747
1957
|
// Reward coin types
|
|
1748
|
-
|
|
1958
|
+
l.vector(l.u8()),
|
|
1749
1959
|
// Reward options
|
|
1750
|
-
|
|
1960
|
+
l.vector(l.Address),
|
|
1751
1961
|
// Rule IDs
|
|
1752
|
-
|
|
1962
|
+
l.vector(l.u256())
|
|
1753
1963
|
// Claimable amounts
|
|
1754
1964
|
]
|
|
1755
1965
|
)
|
|
1756
1966
|
);
|
|
1757
1967
|
});
|
|
1758
|
-
const
|
|
1759
|
-
return
|
|
1760
|
-
const
|
|
1968
|
+
const p = [];
|
|
1969
|
+
return s.forEach((m, h) => {
|
|
1970
|
+
const w = t[h];
|
|
1761
1971
|
if (m.length === 5 && Array.isArray(m[0])) {
|
|
1762
1972
|
const y = m[0].length;
|
|
1763
|
-
for (let
|
|
1764
|
-
const f =
|
|
1765
|
-
(I) => k(I.coinType) === k(m[1][
|
|
1766
|
-
),
|
|
1767
|
-
(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
|
|
1768
1978
|
);
|
|
1769
|
-
!f || !
|
|
1770
|
-
assetId:
|
|
1771
|
-
assetCoinType: k(m[0][
|
|
1772
|
-
rewardCoinType: k(m[1][
|
|
1773
|
-
option: Number(m[2][
|
|
1774
|
-
userClaimableReward: Number(m[4][
|
|
1775
|
-
ruleIds: Array.isArray(m[3][
|
|
1776
|
-
market:
|
|
1777
|
-
owner:
|
|
1778
|
-
address:
|
|
1779
|
-
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
|
|
1780
1990
|
});
|
|
1781
1991
|
}
|
|
1782
1992
|
}
|
|
1783
|
-
}),
|
|
1993
|
+
}), p;
|
|
1784
1994
|
}
|
|
1785
|
-
async function
|
|
1786
|
-
const
|
|
1995
|
+
async function Pt(e, t) {
|
|
1996
|
+
const r = (t?.markets || [U.main]).map((a) => C(a));
|
|
1787
1997
|
let n = [];
|
|
1788
1998
|
try {
|
|
1789
|
-
n = await
|
|
1999
|
+
n = await ne(e, t);
|
|
1790
2000
|
} catch (a) {
|
|
1791
2001
|
console.error(a);
|
|
1792
2002
|
}
|
|
1793
|
-
const
|
|
2003
|
+
const o = r.map((a) => ({
|
|
1794
2004
|
address: e,
|
|
1795
2005
|
owner: e,
|
|
1796
2006
|
market: a.key
|
|
1797
2007
|
})).concat(
|
|
1798
|
-
n.filter((a) => !!
|
|
1799
|
-
const
|
|
2008
|
+
n.filter((a) => !!r.find((c) => c.id === a.marketId)).map((a) => {
|
|
2009
|
+
const c = C(a.marketId);
|
|
1800
2010
|
return {
|
|
1801
2011
|
address: a.accountCap,
|
|
1802
2012
|
owner: e,
|
|
1803
|
-
market:
|
|
2013
|
+
market: c.key,
|
|
1804
2014
|
emodeId: a.emodeId
|
|
1805
2015
|
};
|
|
1806
2016
|
})
|
|
1807
2017
|
);
|
|
1808
|
-
return await
|
|
2018
|
+
return await Ke(e, o, t);
|
|
1809
2019
|
}
|
|
1810
|
-
function
|
|
1811
|
-
const
|
|
2020
|
+
function Bt(e) {
|
|
2021
|
+
const t = /* @__PURE__ */ new Map();
|
|
1812
2022
|
e.forEach((n) => {
|
|
1813
|
-
const
|
|
1814
|
-
|
|
1815
|
-
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,
|
|
1816
2026
|
rewardType: a,
|
|
1817
2027
|
coinType: n.rewardCoinType,
|
|
1818
2028
|
total: Number(n.userClaimableReward),
|
|
1819
2029
|
market: n.market
|
|
1820
2030
|
});
|
|
1821
2031
|
});
|
|
1822
|
-
const
|
|
1823
|
-
for (const { assetId: n, rewardType:
|
|
1824
|
-
const
|
|
1825
|
-
|
|
1826
|
-
const
|
|
1827
|
-
|
|
1828
|
-
}
|
|
1829
|
-
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) => ({
|
|
1830
2040
|
assetId: n.assetId,
|
|
1831
2041
|
rewardType: n.rewardType,
|
|
1832
2042
|
market: n.market,
|
|
1833
|
-
rewards: Array.from(n.rewards.entries()).map(([
|
|
1834
|
-
coinType:
|
|
2043
|
+
rewards: Array.from(n.rewards.entries()).map(([o, a]) => ({
|
|
2044
|
+
coinType: o,
|
|
1835
2045
|
available: a.toFixed(6)
|
|
1836
2046
|
}))
|
|
1837
2047
|
}));
|
|
1838
2048
|
}
|
|
1839
|
-
const
|
|
1840
|
-
async (e,
|
|
1841
|
-
const
|
|
1842
|
-
return (await fetch(
|
|
1843
|
-
}
|
|
1844
|
-
),
|
|
1845
|
-
async (e,
|
|
1846
|
-
const
|
|
1847
|
-
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({
|
|
1848
2058
|
data: n.data.rewards
|
|
1849
2059
|
});
|
|
1850
2060
|
}
|
|
1851
2061
|
);
|
|
1852
|
-
async function
|
|
1853
|
-
const n = await
|
|
1854
|
-
...
|
|
2062
|
+
async function St(e, t, r) {
|
|
2063
|
+
const n = await R({
|
|
2064
|
+
...r,
|
|
1855
2065
|
markets: Object.values(U),
|
|
1856
2066
|
cacheTime: b
|
|
1857
|
-
}),
|
|
1858
|
-
for (const
|
|
1859
|
-
const { rewardCoinType: i, ruleIds:
|
|
1860
|
-
for (const
|
|
1861
|
-
|
|
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, {
|
|
1862
2072
|
assetIds: [],
|
|
1863
2073
|
ruleIds: [],
|
|
1864
2074
|
amount: 0,
|
|
1865
|
-
market:
|
|
2075
|
+
market: p,
|
|
1866
2076
|
owner: m,
|
|
1867
2077
|
address: h,
|
|
1868
|
-
isEMode: typeof
|
|
2078
|
+
isEMode: typeof w < "u"
|
|
1869
2079
|
});
|
|
1870
|
-
const f =
|
|
1871
|
-
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;
|
|
1872
2082
|
}
|
|
1873
2083
|
}
|
|
1874
2084
|
const a = [];
|
|
1875
2085
|
for (const [
|
|
1876
|
-
|
|
1877
|
-
{ assetIds: i, ruleIds:
|
|
1878
|
-
] of
|
|
1879
|
-
const
|
|
1880
|
-
...
|
|
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,
|
|
1881
2091
|
cacheTime: b,
|
|
1882
2092
|
market: m
|
|
1883
|
-
}), f =
|
|
2093
|
+
}), f = c.split("___")[0], v = n.filter(
|
|
1884
2094
|
(j) => k(j.suiCoinType) === k(f)
|
|
1885
2095
|
);
|
|
1886
|
-
|
|
1887
|
-
const I =
|
|
1888
|
-
if (!
|
|
2096
|
+
v.sort((j, P) => j.market === m ? -1 : 1);
|
|
2097
|
+
const I = v[0], T = u.rewardFunds[k(f)];
|
|
2098
|
+
if (!T)
|
|
1889
2099
|
throw new Error(`No matching rewardFund found for reward coin: ${f} ${m}`);
|
|
1890
|
-
if (
|
|
2100
|
+
if (r?.accountCap && !r.customCoinReceive)
|
|
1891
2101
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
1892
|
-
if (
|
|
2102
|
+
if (r?.customCoinReceive) {
|
|
1893
2103
|
let j;
|
|
1894
|
-
|
|
1895
|
-
target: `${
|
|
2104
|
+
r.accountCap ? j = e.moveCall({
|
|
2105
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1896
2106
|
arguments: [
|
|
1897
2107
|
e.object("0x06"),
|
|
1898
2108
|
// Clock object
|
|
1899
|
-
e.object(
|
|
2109
|
+
e.object(u.incentiveV3),
|
|
1900
2110
|
// Incentive V3 contract
|
|
1901
|
-
e.object(
|
|
2111
|
+
e.object(u.storage),
|
|
1902
2112
|
// Protocol storage
|
|
1903
|
-
e.object(
|
|
2113
|
+
e.object(T),
|
|
1904
2114
|
// Reward fund
|
|
1905
2115
|
e.pure.vector("string", i),
|
|
1906
2116
|
// Asset IDs
|
|
1907
|
-
e.pure.vector("address",
|
|
2117
|
+
e.pure.vector("address", s),
|
|
1908
2118
|
// Rule IDs
|
|
1909
|
-
g(
|
|
2119
|
+
g(r.accountCap, e.object)
|
|
1910
2120
|
// Account capability
|
|
1911
2121
|
],
|
|
1912
2122
|
typeArguments: [f]
|
|
1913
2123
|
}) : y ? j = e.moveCall({
|
|
1914
|
-
target: `${
|
|
2124
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1915
2125
|
arguments: [
|
|
1916
2126
|
e.object("0x06"),
|
|
1917
2127
|
// Clock object
|
|
1918
|
-
e.object(
|
|
2128
|
+
e.object(u.incentiveV3),
|
|
1919
2129
|
// Incentive V3 contract
|
|
1920
|
-
e.object(
|
|
2130
|
+
e.object(u.storage),
|
|
1921
2131
|
// Protocol storage
|
|
1922
|
-
e.object(
|
|
2132
|
+
e.object(T),
|
|
1923
2133
|
// Reward fund
|
|
1924
2134
|
e.pure.vector("string", i),
|
|
1925
2135
|
// Asset IDs
|
|
1926
|
-
e.pure.vector("address",
|
|
2136
|
+
e.pure.vector("address", s),
|
|
1927
2137
|
// Rule IDs
|
|
1928
|
-
g(
|
|
2138
|
+
g(w, e.object)
|
|
1929
2139
|
// Account capability
|
|
1930
2140
|
],
|
|
1931
2141
|
typeArguments: [f]
|
|
1932
2142
|
}) : j = e.moveCall({
|
|
1933
|
-
target: `${
|
|
2143
|
+
target: `${u.package}::incentive_v3::claim_reward`,
|
|
1934
2144
|
arguments: [
|
|
1935
2145
|
e.object("0x06"),
|
|
1936
2146
|
// Clock object
|
|
1937
|
-
e.object(
|
|
2147
|
+
e.object(u.incentiveV3),
|
|
1938
2148
|
// Incentive V3 contract
|
|
1939
|
-
e.object(
|
|
2149
|
+
e.object(u.storage),
|
|
1940
2150
|
// Protocol storage
|
|
1941
|
-
e.object(
|
|
2151
|
+
e.object(T),
|
|
1942
2152
|
// Reward fund
|
|
1943
2153
|
e.pure.vector("string", i),
|
|
1944
2154
|
// Asset IDs
|
|
1945
|
-
e.pure.vector("address",
|
|
2155
|
+
e.pure.vector("address", s)
|
|
1946
2156
|
// Rule IDs
|
|
1947
2157
|
],
|
|
1948
2158
|
typeArguments: [f]
|
|
1949
2159
|
});
|
|
1950
|
-
const [
|
|
2160
|
+
const [P] = e.moveCall({
|
|
1951
2161
|
target: "0x2::coin::from_balance",
|
|
1952
2162
|
arguments: [j],
|
|
1953
2163
|
typeArguments: [f]
|
|
1954
2164
|
});
|
|
1955
|
-
if (
|
|
1956
|
-
if (!
|
|
2165
|
+
if (r?.customCoinReceive.type === "transfer") {
|
|
2166
|
+
if (!r.customCoinReceive.transfer)
|
|
1957
2167
|
throw new Error("customCoinReceive.transfer is required");
|
|
1958
2168
|
e.transferObjects(
|
|
1959
|
-
[
|
|
1960
|
-
g(
|
|
2169
|
+
[P],
|
|
2170
|
+
g(r.customCoinReceive.transfer, e.pure.address)
|
|
1961
2171
|
);
|
|
1962
2172
|
}
|
|
1963
|
-
if (
|
|
1964
|
-
const
|
|
1965
|
-
|
|
1966
|
-
[
|
|
1967
|
-
e.pure.address(
|
|
1968
|
-
) : await
|
|
1969
|
-
...
|
|
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,
|
|
1970
2180
|
market: I.market
|
|
1971
2181
|
});
|
|
1972
2182
|
} else
|
|
1973
2183
|
a.push({
|
|
1974
|
-
coin:
|
|
2184
|
+
coin: P,
|
|
1975
2185
|
identifier: I,
|
|
1976
2186
|
owner: h,
|
|
1977
2187
|
isEMode: y
|
|
1978
2188
|
});
|
|
1979
|
-
} else if (
|
|
2189
|
+
} else if (r?.accountCap || y) {
|
|
1980
2190
|
const j = e.moveCall({
|
|
1981
|
-
target: `${
|
|
2191
|
+
target: `${u.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1982
2192
|
arguments: [
|
|
1983
2193
|
e.object("0x06"),
|
|
1984
2194
|
// Clock object
|
|
1985
|
-
e.object(
|
|
2195
|
+
e.object(u.incentiveV3),
|
|
1986
2196
|
// Incentive V3 contract
|
|
1987
|
-
e.object(
|
|
2197
|
+
e.object(u.storage),
|
|
1988
2198
|
// Protocol storage
|
|
1989
|
-
e.object(
|
|
2199
|
+
e.object(T),
|
|
1990
2200
|
// Reward fund
|
|
1991
2201
|
e.pure.vector("string", i),
|
|
1992
2202
|
// Asset IDs
|
|
1993
|
-
e.pure.vector("address",
|
|
2203
|
+
e.pure.vector("address", s),
|
|
1994
2204
|
// Rule IDs
|
|
1995
|
-
g(
|
|
2205
|
+
g(r?.accountCap || w, e.object)
|
|
1996
2206
|
// Account capability
|
|
1997
2207
|
],
|
|
1998
2208
|
typeArguments: [f]
|
|
1999
|
-
}), [
|
|
2209
|
+
}), [P] = e.moveCall({
|
|
2000
2210
|
target: "0x2::coin::from_balance",
|
|
2001
2211
|
arguments: [j],
|
|
2002
2212
|
typeArguments: [f]
|
|
2003
2213
|
});
|
|
2004
2214
|
e.transferObjects(
|
|
2005
|
-
[
|
|
2006
|
-
g(
|
|
2215
|
+
[P],
|
|
2216
|
+
g(r?.accountCap || h, e.pure.address)
|
|
2007
2217
|
);
|
|
2008
2218
|
} else
|
|
2009
2219
|
e.moveCall({
|
|
2010
|
-
target: `${
|
|
2220
|
+
target: `${u.package}::incentive_v3::claim_reward_entry`,
|
|
2011
2221
|
arguments: [
|
|
2012
2222
|
e.object("0x06"),
|
|
2013
2223
|
// Clock object
|
|
2014
|
-
e.object(
|
|
2224
|
+
e.object(u.incentiveV3),
|
|
2015
2225
|
// Incentive V3 contract
|
|
2016
|
-
e.object(
|
|
2226
|
+
e.object(u.storage),
|
|
2017
2227
|
// Protocol storage
|
|
2018
|
-
e.object(
|
|
2228
|
+
e.object(T),
|
|
2019
2229
|
// Reward fund
|
|
2020
2230
|
e.pure.vector("string", i),
|
|
2021
2231
|
// Asset IDs
|
|
2022
|
-
e.pure.vector("address",
|
|
2232
|
+
e.pure.vector("address", s)
|
|
2023
2233
|
// Rule IDs
|
|
2024
2234
|
],
|
|
2025
2235
|
typeArguments: [f]
|
|
@@ -2028,71 +2238,74 @@ async function Tt(e, r, o) {
|
|
|
2028
2238
|
return a;
|
|
2029
2239
|
}
|
|
2030
2240
|
export {
|
|
2031
|
-
|
|
2241
|
+
Z as Address,
|
|
2032
2242
|
b as DEFAULT_CACHE_TIME,
|
|
2033
2243
|
O as DEFAULT_MARKET_IDENTITY,
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2244
|
+
rt as FlashLoanAssetConfig,
|
|
2245
|
+
et as IncentiveAPYInfo,
|
|
2246
|
+
we as IncentivePoolInfo,
|
|
2247
|
+
tt as IncentivePoolInfoByPhase,
|
|
2038
2248
|
U as MARKETS,
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2249
|
+
Ue as Market,
|
|
2250
|
+
ot as OracleInfo,
|
|
2251
|
+
N as PoolOperator,
|
|
2042
2252
|
ve as ReserveDataInfo,
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
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,
|
|
2056
2269
|
Y as getAllFlashLoanAssets,
|
|
2057
|
-
|
|
2058
|
-
|
|
2270
|
+
lt as getBorrowFee,
|
|
2271
|
+
vt as getCoins,
|
|
2059
2272
|
_ as getConfig,
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
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,
|
|
2084
2297
|
k as normalizeCoinType,
|
|
2085
|
-
|
|
2298
|
+
Me as parsePoolUID,
|
|
2086
2299
|
g as parseTxValue,
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
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
|
|
2097
2310
|
};
|
|
2098
2311
|
//# sourceMappingURL=index.esm.js.map
|