/
user.ts
447 lines (385 loc) 路 9.86 KB
/
user.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
import { BigNumber } from "ethers";
import { Address } from "./common";
/** All the aggregated user data, should be updated after each user interaction */
export interface UserData {
/** The address of the user */
readonly address: Address;
/** The ETH balance of the user
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly ethBalance: BigNumber;
/**
* Whether the user has approved the bulker as manager or not
*/
readonly isBulkerManaging: boolean;
stEthData: StEthData;
/** Liquidation value of the user
*
* Number of decimals:
* `8` _(USD)_
*/
readonly liquidationValue: BigNumber;
/** Borrow capacity of the user
*
* Number of decimals:
* `8` _(USD)_
*/
readonly borrowCapacity: BigNumber;
/** Percentage of the borrow capacity used by the user
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly borrowCapacityUsedPercentage: BigNumber;
/** Percentage of the liquidation value used by the user
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly liquidationValueUsedPercentage: BigNumber;
/** Health factor of the user
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly healthFactor: BigNumber;
/** Proportion of the user positon that's matched
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly matchingRatio: BigNumber;
/** Proportion of the user supply positon that's matched
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly supplyMatchingRatio: BigNumber;
/** Proportion of the user borrow positon that's matched
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly borrowMatchingRatio: BigNumber;
/** Total collateral deposited by the user (in USD)
*
* Number of decimals:
* `8` _(USD)_
*/
readonly totalCollateral: BigNumber;
/** Total supply position **on pool** of the user (in USD)
*
* Number of decimals:
* `8` _(USD)_
*/
readonly totalSupplyOnPool: BigNumber;
/** Total borrow position **on pool** of the user (in USD)
*
* Number of decimals:
* `8` _(USD)_
*/
readonly totalBorrowOnPool: BigNumber;
/** Total **matched** supply position of the user (in USD)
*
* Number of decimals:
* `8` _(USD)_
*/
readonly totalSupplyInP2P: BigNumber;
/** Total **matched** borrow position of the user (in USD)
*
* Number of decimals:
* `8` _(USD)_
*/
readonly totalBorrowInP2P: BigNumber;
/** Total supply position of the user (in USD)
*
* Number of decimals:
* `8` _(USD)_
*/
readonly totalSupply: BigNumber;
/** Total borrow position of the user (in USD)
*
* Number of decimals:
* `8` _(USD)_
*/
readonly totalBorrow: BigNumber;
/** Number of morpho tokens received by the user after one year
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly experiencedMorphoEmission: BigNumber;
readonly netAPY: {
/** Expected resulting APY for all user positions
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
totalAPY: BigNumber;
/** Expected resulting APY for the user's collateral positions
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
collateralAPY: BigNumber;
/** APY that the user could expect if all his supply position was on pool
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
virtualPoolSupplyAPY: BigNumber;
/** APY that the user could expect if all his borrow position was on pool
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
virtualPoolBorrowAPY: BigNumber;
/** Expected APY improvement considering matched user positions
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
apyImprovementFromP2P: BigNumber;
};
readonly morphoRewards: {
/** Accumulated morpho Token available to claim
*
* Number of decimals:
* `18` _(WEI)_
*/
claimable: BigNumber;
/** Morpho Token accumulated during the current epoch
*
* Number of decimals:
* `18` _(WEI)_
*/
current: BigNumber;
} | null;
readonly nonce: BigNumber;
}
/** Scaled user data on the market, should be updated after each user interaction.
*
* Scaled balances, should be multiplied by the current index to get the value in underlying.
*/
export interface ScaledUserMarketData {
/** Address of the underlying */
readonly underlyingAddress: Address;
/** Collateral position (on pool) of the user
*
* _Should be multiplied by the pool supply index_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly scaledCollateral: BigNumber;
/** Supply position on pool of the user
*
* _Should be multiplied by the index_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly scaledSupplyOnPool: BigNumber;
/** Borrow position on pool of the user
*
* _Should be multiplied by the index_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly scaledBorrowOnPool: BigNumber;
/** Matched supply position of the user
*
* _Should be multiplied by the index_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly scaledSupplyInP2P: BigNumber;
/** Matched borrow position of the user
*
* _Should be multiplied by the index_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly scaledBorrowInP2P: BigNumber;
/** Balance of the underlying token in the user's wallet
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly walletBalance: BigNumber;
/** Underlying approval to the contract
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly approval: BigNumber;
/** Underlying approval to the bulker
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly bulkerApproval: BigNumber;
/** Underlying approval to the Permit2 contract
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly permit2Approval: BigNumber;
/** The permit2 nonce of the user */
readonly nonce: BigNumber;
/** The permit2 nonce of the user for the bulker contract */
readonly bulkerNonce: BigNumber;
}
/** Exploitable user data for the given market, computed using the current indexes.
*
* Balances given in underlying.
*/
export interface UserMarketData
extends Omit<
ScaledUserMarketData,
| "scaledSupplyOnPool"
| "scaledSupplyInP2P"
| "scaledBorrowOnPool"
| "scaledBorrowInP2P"
| "scaledCollateral"
> {
/** User total supply position on the market (in underlying)
*
* _`supplyOnPool` + `supplyInP2P`_
*
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly totalSupply: BigNumber;
/** User total collateral deposited in this asset (in underlying)
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly totalCollateral: BigNumber;
/** User total borrow position on the market (in underlying)
*
* _`borrowOnPool` + `borrowInP2P`_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly totalBorrow: BigNumber;
/** APY experienced by the user on the market for his collateral position (pool APY)
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
readonly experiencedCollateralAPY: BigNumber;
/** Borrow APY experienced by the user on the market
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
readonly experiencedBorrowAPY: BigNumber;
/** Supply APY experienced by the user on the market
*
* Number of decimals:
* `4` _(BASE_UNITS)_
*/
readonly experiencedSupplyAPY: BigNumber;
/** Number of morpho tokens received by the user after one year with his borrow position
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly experiencedBorrowMorphoEmission: BigNumber;
/** Number of morpho tokens received by the user after one year with his supply position
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly experiencedSupplyMorphoEmission: BigNumber;
/** Proportion of the user position on this market that's matched (supply + borrow)
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly matchingRatio: BigNumber;
/** Proportion of the user supply position on this market that's matched
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly supplyMatchingRatio: BigNumber;
/** Proportion of the user borrow position on this market that's matched
*
* Number of decimals:
* `4` _(BASE_UNIT)_
*/
readonly borrowMatchingRatio: BigNumber;
/** Supply position on pool of the user
*
* _in underlying_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly supplyOnPool: BigNumber;
/** Borrow position on pool of the user
*
* _in underlying_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly borrowOnPool: BigNumber;
/** Matched supply position of the user
*
* _in underlying_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly supplyInP2P: BigNumber;
/** Matched borrow position of the user
*
* _in underlying_
*
* Number of decimals:
* `MarketConfig.decimals`
*/
readonly borrowInP2P: BigNumber;
}
export interface StEthData {
/**
* The amount of stETH for a one wstETH
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly stethPerWsteth: BigNumber;
/** StEth balance of the user
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly balance: BigNumber;
/** The amount of stETH that the user has approved to the permit2
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly permit2Approval: BigNumber;
/** The amount of stETH that the user has approved to the bulker
*
* Number of decimals:
* `18` _(WEI)_
*/
readonly bulkerApproval: BigNumber;
/** The permit2 nonce of the user for the bulker contract */
readonly bulkerNonce: BigNumber;
/** Approval of the wstEth contract for stEth tokens */
readonly wstEthApproval: BigNumber;
}