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