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