@naviprotocol/lending 1.4.0-emode.16 → 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 +698 -693
- package/dist/index.esm.js.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,20 +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
|
+
filterPositionsByPool(o) {
|
|
1082
|
+
const r = !!o.isEMode ? ["navi-lending-emode-supply", "navi-lending-emode-borrow"] : ["navi-lending-supply", "navi-lending-borrow"];
|
|
1081
1083
|
return new M(
|
|
1082
1084
|
this.positions.filter((t) => {
|
|
1083
1085
|
const a = t[t.type];
|
|
1084
|
-
return r.includes(t.type) && a.pool.uniqueId ===
|
|
1086
|
+
return r.includes(t.type) && a.pool.uniqueId === o.uniqueId;
|
|
1085
1087
|
})
|
|
1086
1088
|
);
|
|
1087
1089
|
}
|
|
1088
|
-
deposit(
|
|
1089
|
-
const r = !!
|
|
1090
|
+
deposit(o, n) {
|
|
1091
|
+
const r = !!o.isEMode;
|
|
1090
1092
|
let t;
|
|
1091
1093
|
return r ? t = {
|
|
1092
1094
|
id: P(),
|
|
@@ -1095,10 +1097,10 @@ class M {
|
|
|
1095
1097
|
market: "",
|
|
1096
1098
|
type: "navi-lending-emode-supply",
|
|
1097
1099
|
"navi-lending-emode-supply": {
|
|
1098
|
-
amount:
|
|
1099
|
-
valueUSD: l(
|
|
1100
|
-
token:
|
|
1101
|
-
pool:
|
|
1100
|
+
amount: n.toString(),
|
|
1101
|
+
valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
|
|
1102
|
+
token: o.token,
|
|
1103
|
+
pool: o,
|
|
1102
1104
|
emodeCap: {}
|
|
1103
1105
|
}
|
|
1104
1106
|
} : t = {
|
|
@@ -1108,15 +1110,15 @@ class M {
|
|
|
1108
1110
|
market: "",
|
|
1109
1111
|
type: "navi-lending-supply",
|
|
1110
1112
|
"navi-lending-supply": {
|
|
1111
|
-
amount:
|
|
1112
|
-
valueUSD: l(
|
|
1113
|
-
token:
|
|
1114
|
-
pool:
|
|
1113
|
+
amount: n.toString(),
|
|
1114
|
+
valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
|
|
1115
|
+
token: o.token,
|
|
1116
|
+
pool: o
|
|
1115
1117
|
}
|
|
1116
1118
|
}, new M([...this.positions, t]);
|
|
1117
1119
|
}
|
|
1118
|
-
withdraw(
|
|
1119
|
-
const r = !!
|
|
1120
|
+
withdraw(o, n) {
|
|
1121
|
+
const r = !!o.isEMode;
|
|
1120
1122
|
let t;
|
|
1121
1123
|
return r ? t = {
|
|
1122
1124
|
id: P(),
|
|
@@ -1125,10 +1127,10 @@ class M {
|
|
|
1125
1127
|
market: "",
|
|
1126
1128
|
type: "navi-lending-emode-supply",
|
|
1127
1129
|
"navi-lending-emode-supply": {
|
|
1128
|
-
amount: (-
|
|
1129
|
-
valueUSD: l(-
|
|
1130
|
-
token:
|
|
1131
|
-
pool:
|
|
1130
|
+
amount: (-n).toString(),
|
|
1131
|
+
valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
|
|
1132
|
+
token: o.token,
|
|
1133
|
+
pool: o,
|
|
1132
1134
|
emodeCap: {}
|
|
1133
1135
|
}
|
|
1134
1136
|
} : t = {
|
|
@@ -1138,15 +1140,15 @@ class M {
|
|
|
1138
1140
|
market: "",
|
|
1139
1141
|
type: "navi-lending-supply",
|
|
1140
1142
|
"navi-lending-supply": {
|
|
1141
|
-
amount: (-
|
|
1142
|
-
valueUSD: l(-
|
|
1143
|
-
token:
|
|
1144
|
-
pool:
|
|
1143
|
+
amount: (-n).toString(),
|
|
1144
|
+
valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
|
|
1145
|
+
token: o.token,
|
|
1146
|
+
pool: o
|
|
1145
1147
|
}
|
|
1146
1148
|
}, new M([...this.positions, t]);
|
|
1147
1149
|
}
|
|
1148
|
-
borrow(
|
|
1149
|
-
const r = !!
|
|
1150
|
+
borrow(o, n) {
|
|
1151
|
+
const r = !!o.isEMode;
|
|
1150
1152
|
let t;
|
|
1151
1153
|
return r ? t = {
|
|
1152
1154
|
id: P(),
|
|
@@ -1155,10 +1157,10 @@ class M {
|
|
|
1155
1157
|
market: "",
|
|
1156
1158
|
type: "navi-lending-emode-borrow",
|
|
1157
1159
|
"navi-lending-emode-borrow": {
|
|
1158
|
-
amount:
|
|
1159
|
-
valueUSD: l(
|
|
1160
|
-
token:
|
|
1161
|
-
pool:
|
|
1160
|
+
amount: n.toString(),
|
|
1161
|
+
valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
|
|
1162
|
+
token: o.token,
|
|
1163
|
+
pool: o,
|
|
1162
1164
|
emodeCap: {}
|
|
1163
1165
|
}
|
|
1164
1166
|
} : t = {
|
|
@@ -1168,15 +1170,15 @@ class M {
|
|
|
1168
1170
|
market: "",
|
|
1169
1171
|
type: "navi-lending-borrow",
|
|
1170
1172
|
"navi-lending-borrow": {
|
|
1171
|
-
amount:
|
|
1172
|
-
valueUSD: l(
|
|
1173
|
-
token:
|
|
1174
|
-
pool:
|
|
1173
|
+
amount: n.toString(),
|
|
1174
|
+
valueUSD: l(n).multipliedBy(o.oracle.price).toString(),
|
|
1175
|
+
token: o.token,
|
|
1176
|
+
pool: o
|
|
1175
1177
|
}
|
|
1176
1178
|
}, new M([...this.positions, t]);
|
|
1177
1179
|
}
|
|
1178
|
-
repay(
|
|
1179
|
-
const r = !!
|
|
1180
|
+
repay(o, n) {
|
|
1181
|
+
const r = !!o.isEMode;
|
|
1180
1182
|
let t;
|
|
1181
1183
|
return r ? t = {
|
|
1182
1184
|
id: P(),
|
|
@@ -1185,10 +1187,10 @@ class M {
|
|
|
1185
1187
|
market: "",
|
|
1186
1188
|
type: "navi-lending-emode-borrow",
|
|
1187
1189
|
"navi-lending-emode-borrow": {
|
|
1188
|
-
amount: (-
|
|
1189
|
-
valueUSD: l(-
|
|
1190
|
-
token:
|
|
1191
|
-
pool:
|
|
1190
|
+
amount: (-n).toString(),
|
|
1191
|
+
valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
|
|
1192
|
+
token: o.token,
|
|
1193
|
+
pool: o,
|
|
1192
1194
|
emodeCap: {}
|
|
1193
1195
|
}
|
|
1194
1196
|
} : t = {
|
|
@@ -1198,69 +1200,72 @@ class M {
|
|
|
1198
1200
|
market: "",
|
|
1199
1201
|
type: "navi-lending-borrow",
|
|
1200
1202
|
"navi-lending-borrow": {
|
|
1201
|
-
amount: (-
|
|
1202
|
-
valueUSD: l(-
|
|
1203
|
-
token:
|
|
1204
|
-
pool:
|
|
1203
|
+
amount: (-n).toString(),
|
|
1204
|
+
valueUSD: l(-n).multipliedBy(o.oracle.price).toString(),
|
|
1205
|
+
token: o.token,
|
|
1206
|
+
pool: o
|
|
1205
1207
|
}
|
|
1206
1208
|
}, new M([...this.positions, t]);
|
|
1207
1209
|
}
|
|
1208
|
-
getPositionsOverview(
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
} else if (d.type === "navi-lending-borrow")
|
|
1219
|
-
r = r.plus(d["navi-lending-borrow"].valueUSD);
|
|
1220
|
-
else if (d.type === "navi-lending-emode-supply") {
|
|
1221
|
-
const g = d["navi-lending-emode-supply"];
|
|
1222
|
-
o = o.plus(g.valueUSD);
|
|
1223
|
-
const v = g.pool.emode;
|
|
1224
|
-
i = i.plus(
|
|
1225
|
-
new l(g.valueUSD).multipliedBy(v.lt)
|
|
1226
|
-
), c = c.plus(
|
|
1227
|
-
new l(g.valueUSD).multipliedBy(v.ltv)
|
|
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)
|
|
1228
1220
|
);
|
|
1229
|
-
} else
|
|
1230
|
-
|
|
1231
|
-
if (
|
|
1232
|
-
const
|
|
1233
|
-
t = t.plus(
|
|
1234
|
-
|
|
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)
|
|
1235
1231
|
);
|
|
1236
|
-
} else
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
)
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
)
|
|
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();
|
|
1251
1254
|
}
|
|
1252
1255
|
});
|
|
1253
|
-
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));
|
|
1254
1257
|
return {
|
|
1255
|
-
hf:
|
|
1256
|
-
netVaule:
|
|
1257
|
-
netWorthApr:
|
|
1258
|
-
totalSupplyValue:
|
|
1259
|
-
totalBorrowValue:
|
|
1260
|
-
totalsupplyApy:
|
|
1261
|
-
totalBorrowApy:
|
|
1262
|
-
maxLiquidationValue:
|
|
1263
|
-
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
|
|
1264
1269
|
};
|
|
1265
1270
|
}
|
|
1266
1271
|
}
|
|
@@ -1269,10 +1274,10 @@ const ee = new Y("https://hermes.pyth.network", {
|
|
|
1269
1274
|
});
|
|
1270
1275
|
async function Ae(e) {
|
|
1271
1276
|
try {
|
|
1272
|
-
const
|
|
1273
|
-
if (!
|
|
1277
|
+
const o = [], n = await ee.getLatestPriceFeeds(e);
|
|
1278
|
+
if (!n) return o;
|
|
1274
1279
|
const r = Math.floor((/* @__PURE__ */ new Date()).valueOf() / 1e3);
|
|
1275
|
-
for (const t of
|
|
1280
|
+
for (const t of n) {
|
|
1276
1281
|
const a = t.getPriceUnchecked();
|
|
1277
1282
|
if (a.publishTime > r) {
|
|
1278
1283
|
console.warn(
|
|
@@ -1282,43 +1287,43 @@ async function Ae(e) {
|
|
|
1282
1287
|
}
|
|
1283
1288
|
r - t.getPriceUnchecked().publishTime > 30 && (console.info(
|
|
1284
1289
|
`stale price feed, id: ${t.id}, publish time: ${a.publishTime}, current timestamp: ${r}`
|
|
1285
|
-
),
|
|
1290
|
+
), o.push(t.id));
|
|
1286
1291
|
}
|
|
1287
|
-
return
|
|
1288
|
-
} catch (
|
|
1289
|
-
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}`);
|
|
1290
1295
|
}
|
|
1291
1296
|
}
|
|
1292
|
-
async function
|
|
1293
|
-
const r =
|
|
1294
|
-
...
|
|
1295
|
-
cacheTime:
|
|
1297
|
+
async function Se(e, o, n) {
|
|
1298
|
+
const r = n?.client ?? S, t = await k({
|
|
1299
|
+
...n,
|
|
1300
|
+
cacheTime: h
|
|
1296
1301
|
});
|
|
1297
1302
|
try {
|
|
1298
|
-
const a = await ee.getPriceFeedsUpdateData(
|
|
1303
|
+
const a = await ee.getPriceFeedsUpdateData(o);
|
|
1299
1304
|
return await new le(
|
|
1300
1305
|
r,
|
|
1301
1306
|
t.oracle.pythStateId,
|
|
1302
1307
|
t.oracle.wormholeStateId
|
|
1303
|
-
).updatePriceFeeds(e, a,
|
|
1308
|
+
).updatePriceFeeds(e, a, o);
|
|
1304
1309
|
} catch (a) {
|
|
1305
1310
|
throw new Error(`failed to update pyth price feeds, msg: ${a.message}`);
|
|
1306
1311
|
}
|
|
1307
1312
|
}
|
|
1308
|
-
async function
|
|
1313
|
+
async function $e(e, o, n) {
|
|
1309
1314
|
const r = await k({
|
|
1310
|
-
...
|
|
1311
|
-
cacheTime:
|
|
1315
|
+
...n,
|
|
1316
|
+
cacheTime: h
|
|
1312
1317
|
});
|
|
1313
|
-
if (
|
|
1314
|
-
const t =
|
|
1318
|
+
if (n?.updatePythPriceFeeds) {
|
|
1319
|
+
const t = o.filter((a) => !!a.pythPriceFeedId).map((a) => a.pythPriceFeedId);
|
|
1315
1320
|
try {
|
|
1316
1321
|
const a = await Ae(t);
|
|
1317
|
-
a.length > 0 && await
|
|
1322
|
+
a.length > 0 && await Se(e, a, n);
|
|
1318
1323
|
} catch {
|
|
1319
1324
|
}
|
|
1320
1325
|
}
|
|
1321
|
-
for (const t of
|
|
1326
|
+
for (const t of o)
|
|
1322
1327
|
e.moveCall({
|
|
1323
1328
|
target: `${r.oracle.packageId}::oracle_pro::update_single_price`,
|
|
1324
1329
|
arguments: [
|
|
@@ -1341,33 +1346,33 @@ async function Se(e, n, o) {
|
|
|
1341
1346
|
async function te(e) {
|
|
1342
1347
|
return (await k({
|
|
1343
1348
|
...e,
|
|
1344
|
-
cacheTime:
|
|
1349
|
+
cacheTime: h
|
|
1345
1350
|
})).oracle.feeds;
|
|
1346
1351
|
}
|
|
1347
|
-
function Pe(e,
|
|
1348
|
-
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) => [
|
|
1349
1354
|
"navi-lending-supply",
|
|
1350
1355
|
"navi-lending-borrow",
|
|
1351
1356
|
"navi-lending-emode-supply",
|
|
1352
1357
|
"navi-lending-emode-borrow"
|
|
1353
|
-
].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)));
|
|
1354
1359
|
}
|
|
1355
|
-
async function st(e,
|
|
1360
|
+
async function st(e, o, n, r) {
|
|
1356
1361
|
try {
|
|
1357
1362
|
const t = await te({
|
|
1358
1363
|
...r
|
|
1359
1364
|
}), a = [];
|
|
1360
|
-
|
|
1365
|
+
n.forEach((u) => {
|
|
1361
1366
|
a.includes(u.market) || a.push(u.market);
|
|
1362
1367
|
});
|
|
1363
|
-
const
|
|
1368
|
+
const c = await Be(o, {
|
|
1364
1369
|
...r,
|
|
1365
1370
|
markets: a
|
|
1366
|
-
}),
|
|
1367
|
-
lendingPositions:
|
|
1368
|
-
pools:
|
|
1371
|
+
}), i = Pe(t, {
|
|
1372
|
+
lendingPositions: c,
|
|
1373
|
+
pools: n
|
|
1369
1374
|
});
|
|
1370
|
-
return await
|
|
1375
|
+
return await $e(e, i, {
|
|
1371
1376
|
updatePythPriceFeeds: !0,
|
|
1372
1377
|
...r
|
|
1373
1378
|
});
|
|
@@ -1380,25 +1385,25 @@ async function st(e, n, o, r) {
|
|
|
1380
1385
|
const L = A(
|
|
1381
1386
|
I(
|
|
1382
1387
|
async (e) => {
|
|
1383
|
-
const
|
|
1384
|
-
return Object.keys(
|
|
1385
|
-
...
|
|
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],
|
|
1386
1391
|
coinType: r
|
|
1387
1392
|
}));
|
|
1388
1393
|
}
|
|
1389
1394
|
)
|
|
1390
1395
|
);
|
|
1391
|
-
async function ut(e,
|
|
1392
|
-
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;
|
|
1393
1398
|
}
|
|
1394
|
-
async function lt(e,
|
|
1399
|
+
async function lt(e, o, n, r) {
|
|
1395
1400
|
const t = await k({
|
|
1396
1401
|
...r,
|
|
1397
|
-
cacheTime:
|
|
1398
|
-
}), a = await B(
|
|
1402
|
+
cacheTime: h
|
|
1403
|
+
}), a = await B(o, r);
|
|
1399
1404
|
if (!(await L({
|
|
1400
1405
|
...r,
|
|
1401
|
-
cacheTime:
|
|
1406
|
+
cacheTime: h
|
|
1402
1407
|
})).some(
|
|
1403
1408
|
(s) => b(s.coinType) === b(a.suiCoinType)
|
|
1404
1409
|
))
|
|
@@ -1409,7 +1414,7 @@ async function lt(e, n, o, r) {
|
|
|
1409
1414
|
arguments: [
|
|
1410
1415
|
e.object(t.flashloanConfig),
|
|
1411
1416
|
e.object(a.contract.pool),
|
|
1412
|
-
y(
|
|
1417
|
+
y(n, e.pure.u64)
|
|
1413
1418
|
],
|
|
1414
1419
|
typeArguments: [a.suiCoinType]
|
|
1415
1420
|
});
|
|
@@ -1420,7 +1425,7 @@ async function lt(e, n, o, r) {
|
|
|
1420
1425
|
arguments: [
|
|
1421
1426
|
e.object(t.flashloanConfig),
|
|
1422
1427
|
e.object(a.contract.pool),
|
|
1423
|
-
y(
|
|
1428
|
+
y(n, e.pure.u64),
|
|
1424
1429
|
e.object("0x05")
|
|
1425
1430
|
],
|
|
1426
1431
|
typeArguments: [a.suiCoinType]
|
|
@@ -1428,16 +1433,16 @@ async function lt(e, n, o, r) {
|
|
|
1428
1433
|
return [s, u];
|
|
1429
1434
|
}
|
|
1430
1435
|
}
|
|
1431
|
-
async function pt(e,
|
|
1436
|
+
async function pt(e, o, n, r, t) {
|
|
1432
1437
|
const a = await k({
|
|
1433
1438
|
...t,
|
|
1434
|
-
cacheTime:
|
|
1435
|
-
}),
|
|
1439
|
+
cacheTime: h
|
|
1440
|
+
}), c = await B(o, t);
|
|
1436
1441
|
if (!(await L({
|
|
1437
1442
|
...t,
|
|
1438
|
-
cacheTime:
|
|
1443
|
+
cacheTime: h
|
|
1439
1444
|
})).some(
|
|
1440
|
-
(m) => b(m.coinType) === b(
|
|
1445
|
+
(m) => b(m.coinType) === b(c.suiCoinType)
|
|
1441
1446
|
))
|
|
1442
1447
|
throw new Error("Pool does not support flashloan");
|
|
1443
1448
|
const [u] = e.moveCall({
|
|
@@ -1445,34 +1450,34 @@ async function pt(e, n, o, r, t) {
|
|
|
1445
1450
|
arguments: [
|
|
1446
1451
|
e.object("0x06"),
|
|
1447
1452
|
e.object(a.storage),
|
|
1448
|
-
e.object(
|
|
1449
|
-
y(
|
|
1453
|
+
e.object(c.contract.pool),
|
|
1454
|
+
y(n, e.object),
|
|
1450
1455
|
y(r, e.object)
|
|
1451
1456
|
],
|
|
1452
|
-
typeArguments: [
|
|
1457
|
+
typeArguments: [c.suiCoinType]
|
|
1453
1458
|
});
|
|
1454
1459
|
return [u];
|
|
1455
1460
|
}
|
|
1456
|
-
async function dt(e,
|
|
1457
|
-
const
|
|
1461
|
+
async function dt(e, o, n, r, t, a) {
|
|
1462
|
+
const c = {
|
|
1458
1463
|
...a,
|
|
1459
|
-
cacheTime:
|
|
1460
|
-
},
|
|
1461
|
-
if (
|
|
1462
|
-
const [m,
|
|
1463
|
-
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`,
|
|
1464
1469
|
arguments: [
|
|
1465
1470
|
e.object("0x06"),
|
|
1466
1471
|
// Clock object
|
|
1467
|
-
e.object(
|
|
1472
|
+
e.object(i.priceOracle),
|
|
1468
1473
|
// Price oracle for asset pricing
|
|
1469
|
-
e.object(
|
|
1474
|
+
e.object(i.storage),
|
|
1470
1475
|
// Protocol storage
|
|
1471
1476
|
e.pure.u8(s.id),
|
|
1472
1477
|
// Pay asset ID
|
|
1473
1478
|
e.object(s.contract.pool),
|
|
1474
1479
|
// Pay asset pool contract
|
|
1475
|
-
y(
|
|
1480
|
+
y(n, e.object),
|
|
1476
1481
|
// Debt repayment amount
|
|
1477
1482
|
e.pure.u8(u.id),
|
|
1478
1483
|
// Collateral asset ID
|
|
@@ -1480,29 +1485,29 @@ async function dt(e, n, o, r, t, a) {
|
|
|
1480
1485
|
// Collateral asset pool contract
|
|
1481
1486
|
y(t, e.pure.address),
|
|
1482
1487
|
// Borrower address
|
|
1483
|
-
e.object(
|
|
1488
|
+
e.object(i.incentiveV2),
|
|
1484
1489
|
// Incentive V2 contract
|
|
1485
|
-
e.object(
|
|
1490
|
+
e.object(i.incentiveV3)
|
|
1486
1491
|
// Incentive V3 contract
|
|
1487
1492
|
],
|
|
1488
1493
|
typeArguments: [s.suiCoinType, u.suiCoinType]
|
|
1489
1494
|
});
|
|
1490
|
-
return [m,
|
|
1495
|
+
return [m, g];
|
|
1491
1496
|
} else {
|
|
1492
|
-
const [m,
|
|
1493
|
-
target: `${
|
|
1497
|
+
const [m, g] = e.moveCall({
|
|
1498
|
+
target: `${i.package}::incentive_v3::liquidation_v2`,
|
|
1494
1499
|
arguments: [
|
|
1495
1500
|
e.object("0x06"),
|
|
1496
1501
|
// Clock object
|
|
1497
|
-
e.object(
|
|
1502
|
+
e.object(i.priceOracle),
|
|
1498
1503
|
// Price oracle for asset pricing
|
|
1499
|
-
e.object(
|
|
1504
|
+
e.object(i.storage),
|
|
1500
1505
|
// Protocol storage
|
|
1501
1506
|
e.pure.u8(s.id),
|
|
1502
1507
|
// Pay asset ID
|
|
1503
1508
|
e.object(s.contract.pool),
|
|
1504
1509
|
// Pay asset pool contract
|
|
1505
|
-
y(
|
|
1510
|
+
y(n, e.object),
|
|
1506
1511
|
// Debt repayment amount
|
|
1507
1512
|
e.pure.u8(u.id),
|
|
1508
1513
|
// Collateral asset ID
|
|
@@ -1510,49 +1515,49 @@ async function dt(e, n, o, r, t, a) {
|
|
|
1510
1515
|
// Collateral asset pool contract
|
|
1511
1516
|
y(t, e.pure.address),
|
|
1512
1517
|
// Borrower address
|
|
1513
|
-
e.object(
|
|
1518
|
+
e.object(i.incentiveV2),
|
|
1514
1519
|
// Incentive V2 contract
|
|
1515
|
-
e.object(
|
|
1520
|
+
e.object(i.incentiveV3),
|
|
1516
1521
|
// Incentive V3 contract
|
|
1517
1522
|
e.object("0x05")
|
|
1518
1523
|
// SuiSystemState object
|
|
1519
1524
|
],
|
|
1520
1525
|
typeArguments: [s.suiCoinType, u.suiCoinType]
|
|
1521
1526
|
});
|
|
1522
|
-
return [m,
|
|
1527
|
+
return [m, g];
|
|
1523
1528
|
}
|
|
1524
1529
|
}
|
|
1525
|
-
async function Ve(e,
|
|
1526
|
-
const r =
|
|
1527
|
-
...
|
|
1530
|
+
async function Ve(e, o, n) {
|
|
1531
|
+
const r = n?.client ?? S, t = new U(), a = await R({
|
|
1532
|
+
...n,
|
|
1528
1533
|
markets: Object.values(E),
|
|
1529
|
-
cacheTime:
|
|
1530
|
-
}),
|
|
1531
|
-
for (let m of
|
|
1532
|
-
const
|
|
1533
|
-
...
|
|
1534
|
-
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,
|
|
1535
1540
|
market: m.market
|
|
1536
1541
|
});
|
|
1537
1542
|
t.moveCall({
|
|
1538
|
-
target: `${
|
|
1543
|
+
target: `${g.uiGetter}::incentive_v3_getter::get_user_atomic_claimable_rewards`,
|
|
1539
1544
|
arguments: [
|
|
1540
1545
|
t.object("0x06"),
|
|
1541
1546
|
// Clock object
|
|
1542
|
-
t.object(
|
|
1547
|
+
t.object(g.storage),
|
|
1543
1548
|
// Protocol storage
|
|
1544
|
-
t.object(
|
|
1549
|
+
t.object(g.incentiveV3),
|
|
1545
1550
|
// Incentive V3 contract
|
|
1546
1551
|
t.pure.address(m.address)
|
|
1547
1552
|
// User address
|
|
1548
1553
|
]
|
|
1549
1554
|
});
|
|
1550
1555
|
}
|
|
1551
|
-
const
|
|
1556
|
+
const i = await r.devInspectTransactionBlock({
|
|
1552
1557
|
transactionBlock: t,
|
|
1553
1558
|
sender: e
|
|
1554
1559
|
}), s = [];
|
|
1555
|
-
|
|
1560
|
+
i?.results?.forEach((m) => {
|
|
1556
1561
|
s.push(
|
|
1557
1562
|
O(
|
|
1558
1563
|
{
|
|
@@ -1574,52 +1579,52 @@ async function Ve(e, n, o) {
|
|
|
1574
1579
|
);
|
|
1575
1580
|
});
|
|
1576
1581
|
const u = [];
|
|
1577
|
-
return s.forEach((m,
|
|
1578
|
-
const
|
|
1582
|
+
return s.forEach((m, g) => {
|
|
1583
|
+
const v = o[g];
|
|
1579
1584
|
if (m.length === 5 && Array.isArray(m[0])) {
|
|
1580
|
-
const
|
|
1581
|
-
for (let
|
|
1582
|
-
const
|
|
1583
|
-
(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])
|
|
1584
1589
|
), _ = a.find(
|
|
1585
|
-
(T) => b(T.coinType) === b(m[0][
|
|
1590
|
+
(T) => b(T.coinType) === b(m[0][p])
|
|
1586
1591
|
);
|
|
1587
|
-
!
|
|
1592
|
+
!f || !_ || u.push({
|
|
1588
1593
|
assetId: _.id,
|
|
1589
|
-
assetCoinType: b(m[0][
|
|
1590
|
-
rewardCoinType: b(m[1][
|
|
1591
|
-
option: Number(m[2][
|
|
1592
|
-
userClaimableReward: Number(m[4][
|
|
1593
|
-
ruleIds: Array.isArray(m[3][
|
|
1594
|
-
market:
|
|
1595
|
-
owner:
|
|
1596
|
-
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
|
|
1597
1602
|
});
|
|
1598
1603
|
}
|
|
1599
1604
|
}
|
|
1600
1605
|
}), u;
|
|
1601
1606
|
}
|
|
1602
|
-
async function mt(e,
|
|
1603
|
-
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) => ({
|
|
1604
1609
|
address: e,
|
|
1605
1610
|
market: a.key
|
|
1606
1611
|
})).concat(
|
|
1607
|
-
r.filter((a) => !!
|
|
1608
|
-
const
|
|
1612
|
+
r.filter((a) => !!n.find((c) => c.id === a.marketId)).map((a) => {
|
|
1613
|
+
const c = j(a.marketId);
|
|
1609
1614
|
return {
|
|
1610
1615
|
address: e,
|
|
1611
|
-
market:
|
|
1616
|
+
market: c.key,
|
|
1612
1617
|
emodeId: a.emodeId
|
|
1613
1618
|
};
|
|
1614
1619
|
})
|
|
1615
1620
|
);
|
|
1616
|
-
return await Ve(e, t,
|
|
1621
|
+
return await Ve(e, t, o);
|
|
1617
1622
|
}
|
|
1618
|
-
function
|
|
1619
|
-
const
|
|
1623
|
+
function yt(e) {
|
|
1624
|
+
const o = /* @__PURE__ */ new Map();
|
|
1620
1625
|
e.forEach((r) => {
|
|
1621
|
-
const t = r.assetId, a = r.option,
|
|
1622
|
-
|
|
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, {
|
|
1623
1628
|
assetId: t,
|
|
1624
1629
|
rewardType: a,
|
|
1625
1630
|
coinType: r.rewardCoinType,
|
|
@@ -1627,14 +1632,14 @@ function gt(e) {
|
|
|
1627
1632
|
market: r.market
|
|
1628
1633
|
});
|
|
1629
1634
|
});
|
|
1630
|
-
const
|
|
1631
|
-
for (const { assetId: r, rewardType: t, coinType: a, total:
|
|
1632
|
-
const s = `${r}-${t}-${
|
|
1633
|
-
|
|
1634
|
-
const u =
|
|
1635
|
-
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);
|
|
1636
1641
|
}
|
|
1637
|
-
return Array.from(
|
|
1642
|
+
return Array.from(n.values()).map((r) => ({
|
|
1638
1643
|
assetId: r.assetId,
|
|
1639
1644
|
rewardType: r.rewardType,
|
|
1640
1645
|
market: r.market,
|
|
@@ -1644,56 +1649,56 @@ function gt(e) {
|
|
|
1644
1649
|
}))
|
|
1645
1650
|
}));
|
|
1646
1651
|
}
|
|
1647
|
-
const
|
|
1648
|
-
async (e,
|
|
1649
|
-
const
|
|
1650
|
-
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;
|
|
1651
1656
|
}
|
|
1652
1657
|
), ft = I(
|
|
1653
|
-
async (e,
|
|
1654
|
-
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());
|
|
1655
1660
|
return F({
|
|
1656
1661
|
data: r.data.rewards
|
|
1657
1662
|
});
|
|
1658
1663
|
}
|
|
1659
1664
|
);
|
|
1660
|
-
async function
|
|
1665
|
+
async function wt(e, o, n) {
|
|
1661
1666
|
const r = await k({
|
|
1662
|
-
...
|
|
1663
|
-
cacheTime:
|
|
1667
|
+
...n,
|
|
1668
|
+
cacheTime: h
|
|
1664
1669
|
}), t = await R({
|
|
1665
|
-
...
|
|
1670
|
+
...n,
|
|
1666
1671
|
markets: Object.values(E),
|
|
1667
|
-
cacheTime:
|
|
1672
|
+
cacheTime: h
|
|
1668
1673
|
}), a = /* @__PURE__ */ new Map();
|
|
1669
|
-
for (const
|
|
1670
|
-
const { rewardCoinType: s, ruleIds: u, market: m, owner:
|
|
1671
|
-
for (const
|
|
1672
|
-
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, {
|
|
1673
1678
|
assetIds: [],
|
|
1674
1679
|
ruleIds: [],
|
|
1675
1680
|
amount: 0,
|
|
1676
1681
|
market: m,
|
|
1677
|
-
owner:
|
|
1678
|
-
isEMode: typeof
|
|
1682
|
+
owner: g,
|
|
1683
|
+
isEMode: typeof v < "u"
|
|
1679
1684
|
});
|
|
1680
|
-
const
|
|
1681
|
-
|
|
1685
|
+
const f = a.get(w);
|
|
1686
|
+
f.assetIds.push(i.assetCoinType.replace("0x", "")), f.ruleIds.push(p), f.amount += i.userClaimableReward;
|
|
1682
1687
|
}
|
|
1683
1688
|
}
|
|
1684
|
-
const
|
|
1685
|
-
for (const [
|
|
1686
|
-
const
|
|
1687
|
-
(_) => 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
|
|
1688
1693
|
);
|
|
1689
|
-
if (!
|
|
1690
|
-
throw new Error(`No matching rewardFund found for reward coin: ${
|
|
1691
|
-
const
|
|
1692
|
-
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)
|
|
1693
1698
|
throw new Error("customCoinReceive is required when accountCap is provided");
|
|
1694
|
-
if (
|
|
1699
|
+
if (n?.customCoinReceive) {
|
|
1695
1700
|
let _;
|
|
1696
|
-
|
|
1701
|
+
n.accountCap ? _ = e.moveCall({
|
|
1697
1702
|
target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1698
1703
|
arguments: [
|
|
1699
1704
|
e.object("0x06"),
|
|
@@ -1702,17 +1707,17 @@ async function vt(e, n, o) {
|
|
|
1702
1707
|
// Incentive V3 contract
|
|
1703
1708
|
e.object(r.storage),
|
|
1704
1709
|
// Protocol storage
|
|
1705
|
-
e.object(
|
|
1710
|
+
e.object(f),
|
|
1706
1711
|
// Reward fund
|
|
1707
1712
|
e.pure.vector("string", s),
|
|
1708
1713
|
// Asset IDs
|
|
1709
1714
|
e.pure.vector("address", u),
|
|
1710
1715
|
// Rule IDs
|
|
1711
|
-
y(
|
|
1716
|
+
y(n.accountCap, e.object)
|
|
1712
1717
|
// Account capability
|
|
1713
1718
|
],
|
|
1714
|
-
typeArguments: [
|
|
1715
|
-
}) :
|
|
1719
|
+
typeArguments: [i]
|
|
1720
|
+
}) : w ? _ = e.moveCall({
|
|
1716
1721
|
target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1717
1722
|
arguments: [
|
|
1718
1723
|
e.object("0x06"),
|
|
@@ -1721,16 +1726,16 @@ async function vt(e, n, o) {
|
|
|
1721
1726
|
// Incentive V3 contract
|
|
1722
1727
|
e.object(r.storage),
|
|
1723
1728
|
// Protocol storage
|
|
1724
|
-
e.object(
|
|
1729
|
+
e.object(f),
|
|
1725
1730
|
// Reward fund
|
|
1726
1731
|
e.pure.vector("string", s),
|
|
1727
1732
|
// Asset IDs
|
|
1728
1733
|
e.pure.vector("address", u),
|
|
1729
1734
|
// Rule IDs
|
|
1730
|
-
y(
|
|
1735
|
+
y(v, e.object)
|
|
1731
1736
|
// Account capability
|
|
1732
1737
|
],
|
|
1733
|
-
typeArguments: [
|
|
1738
|
+
typeArguments: [i]
|
|
1734
1739
|
}) : _ = e.moveCall({
|
|
1735
1740
|
target: `${r.package}::incentive_v3::claim_reward`,
|
|
1736
1741
|
arguments: [
|
|
@@ -1740,42 +1745,42 @@ async function vt(e, n, o) {
|
|
|
1740
1745
|
// Incentive V3 contract
|
|
1741
1746
|
e.object(r.storage),
|
|
1742
1747
|
// Protocol storage
|
|
1743
|
-
e.object(
|
|
1748
|
+
e.object(f),
|
|
1744
1749
|
// Reward fund
|
|
1745
1750
|
e.pure.vector("string", s),
|
|
1746
1751
|
// Asset IDs
|
|
1747
1752
|
e.pure.vector("address", u)
|
|
1748
1753
|
// Rule IDs
|
|
1749
1754
|
],
|
|
1750
|
-
typeArguments: [
|
|
1755
|
+
typeArguments: [i]
|
|
1751
1756
|
});
|
|
1752
1757
|
const [T] = e.moveCall({
|
|
1753
1758
|
target: "0x2::coin::from_balance",
|
|
1754
1759
|
arguments: [_],
|
|
1755
|
-
typeArguments: [
|
|
1760
|
+
typeArguments: [i]
|
|
1756
1761
|
});
|
|
1757
|
-
if (
|
|
1758
|
-
if (!
|
|
1762
|
+
if (n?.customCoinReceive.type === "transfer") {
|
|
1763
|
+
if (!n.customCoinReceive.transfer)
|
|
1759
1764
|
throw new Error("customCoinReceive.transfer is required");
|
|
1760
1765
|
e.transferObjects(
|
|
1761
1766
|
[T],
|
|
1762
|
-
y(
|
|
1767
|
+
y(n.customCoinReceive.transfer, e.pure.address)
|
|
1763
1768
|
);
|
|
1764
1769
|
}
|
|
1765
|
-
if (
|
|
1766
|
-
const oe = l(
|
|
1767
|
-
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(
|
|
1768
1773
|
[T],
|
|
1769
|
-
e.pure.address(
|
|
1770
|
-
) : await be(e,
|
|
1774
|
+
e.pure.address(n.customCoinReceive.depositNAVI.fallbackReceiveAddress)
|
|
1775
|
+
) : await be(e, p, T, n);
|
|
1771
1776
|
} else
|
|
1772
|
-
|
|
1777
|
+
c.push({
|
|
1773
1778
|
coin: T,
|
|
1774
|
-
identifier:
|
|
1775
|
-
owner:
|
|
1776
|
-
isEMode:
|
|
1779
|
+
identifier: p,
|
|
1780
|
+
owner: v,
|
|
1781
|
+
isEMode: w
|
|
1777
1782
|
});
|
|
1778
|
-
} else if (
|
|
1783
|
+
} else if (n?.accountCap || w) {
|
|
1779
1784
|
const _ = e.moveCall({
|
|
1780
1785
|
target: `${r.package}::incentive_v3::claim_reward_with_account_cap`,
|
|
1781
1786
|
arguments: [
|
|
@@ -1785,24 +1790,24 @@ async function vt(e, n, o) {
|
|
|
1785
1790
|
// Incentive V3 contract
|
|
1786
1791
|
e.object(r.storage),
|
|
1787
1792
|
// Protocol storage
|
|
1788
|
-
e.object(
|
|
1793
|
+
e.object(f),
|
|
1789
1794
|
// Reward fund
|
|
1790
1795
|
e.pure.vector("string", s),
|
|
1791
1796
|
// Asset IDs
|
|
1792
1797
|
e.pure.vector("address", u),
|
|
1793
1798
|
// Rule IDs
|
|
1794
|
-
y(
|
|
1799
|
+
y(n?.accountCap || v, e.object)
|
|
1795
1800
|
// Account capability
|
|
1796
1801
|
],
|
|
1797
|
-
typeArguments: [
|
|
1802
|
+
typeArguments: [i]
|
|
1798
1803
|
}), [T] = e.moveCall({
|
|
1799
1804
|
target: "0x2::coin::from_balance",
|
|
1800
1805
|
arguments: [_],
|
|
1801
|
-
typeArguments: [
|
|
1806
|
+
typeArguments: [i]
|
|
1802
1807
|
});
|
|
1803
1808
|
e.transferObjects(
|
|
1804
1809
|
[T],
|
|
1805
|
-
y(
|
|
1810
|
+
y(n?.accountCap || v, e.pure.address)
|
|
1806
1811
|
);
|
|
1807
1812
|
} else
|
|
1808
1813
|
e.moveCall({
|
|
@@ -1814,21 +1819,21 @@ async function vt(e, n, o) {
|
|
|
1814
1819
|
// Incentive V3 contract
|
|
1815
1820
|
e.object(r.storage),
|
|
1816
1821
|
// Protocol storage
|
|
1817
|
-
e.object(
|
|
1822
|
+
e.object(f),
|
|
1818
1823
|
// Reward fund
|
|
1819
1824
|
e.pure.vector("string", s),
|
|
1820
1825
|
// Asset IDs
|
|
1821
1826
|
e.pure.vector("address", u)
|
|
1822
1827
|
// Rule IDs
|
|
1823
1828
|
],
|
|
1824
|
-
typeArguments: [
|
|
1829
|
+
typeArguments: [i]
|
|
1825
1830
|
});
|
|
1826
1831
|
}
|
|
1827
|
-
return
|
|
1832
|
+
return c;
|
|
1828
1833
|
}
|
|
1829
1834
|
export {
|
|
1830
1835
|
W as Address,
|
|
1831
|
-
|
|
1836
|
+
h as DEFAULT_CACHE_TIME,
|
|
1832
1837
|
D as DEFAULT_MARKET_IDENTITY,
|
|
1833
1838
|
He as FlashLoanAssetConfig,
|
|
1834
1839
|
qe as IncentiveAPYInfo,
|
|
@@ -1842,7 +1847,7 @@ export {
|
|
|
1842
1847
|
M as UserPositions,
|
|
1843
1848
|
de as UserStateInfo,
|
|
1844
1849
|
Je as borrowCoinPTB,
|
|
1845
|
-
|
|
1850
|
+
wt as claimLendingRewardsPTB,
|
|
1846
1851
|
_e as createAccountCapPTB,
|
|
1847
1852
|
et as createEModeCapPTB,
|
|
1848
1853
|
be as depositCoinPTB,
|
|
@@ -1854,7 +1859,7 @@ export {
|
|
|
1854
1859
|
je as getAccountCapOwnerPTB,
|
|
1855
1860
|
L as getAllFlashLoanAssets,
|
|
1856
1861
|
Xe as getBorrowFee,
|
|
1857
|
-
|
|
1862
|
+
ct as getCoins,
|
|
1858
1863
|
k as getConfig,
|
|
1859
1864
|
Ke as getFees,
|
|
1860
1865
|
ut as getFlashLoanAsset,
|
|
@@ -1872,11 +1877,11 @@ export {
|
|
|
1872
1877
|
at as getSimulatedHealthFactor,
|
|
1873
1878
|
Z as getSimulatedHealthFactorPTB,
|
|
1874
1879
|
ze as getStats,
|
|
1875
|
-
|
|
1880
|
+
it as getTransactions,
|
|
1876
1881
|
mt as getUserAvailableLendingRewards,
|
|
1877
1882
|
ft as getUserClaimedRewardHistory,
|
|
1878
1883
|
X as getUserEModeCaps,
|
|
1879
|
-
|
|
1884
|
+
gt as getUserTotalClaimedReward,
|
|
1880
1885
|
dt as liquidatePTB,
|
|
1881
1886
|
ot as mergeCoinsPTB,
|
|
1882
1887
|
b as normalizeCoinType,
|
|
@@ -1884,10 +1889,10 @@ export {
|
|
|
1884
1889
|
y as parseTxValue,
|
|
1885
1890
|
Qe as repayCoinPTB,
|
|
1886
1891
|
pt as repayFlashLoanPTB,
|
|
1887
|
-
|
|
1892
|
+
yt as summaryLendingRewards,
|
|
1888
1893
|
st as updateOraclePriceBeforeUserOperationPTB,
|
|
1889
|
-
|
|
1890
|
-
|
|
1894
|
+
$e as updateOraclePricesPTB,
|
|
1895
|
+
Se as updatePythPriceFeeds,
|
|
1891
1896
|
A as withCache,
|
|
1892
1897
|
I as withSingleton,
|
|
1893
1898
|
Ye as withdrawCoinPTB
|