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