-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathIPoolCore.sol
More file actions
605 lines (563 loc) · 25 KB
/
Copy pathIPoolCore.sol
File metadata and controls
605 lines (563 loc) · 25 KB
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.10;
import {IPoolAddressesProvider} from "./IPoolAddressesProvider.sol";
import {DataTypes} from "../protocol/libraries/types/DataTypes.sol";
/**
* @title IPool
*
* @notice Defines the basic interface for an ParaSpace Pool.
**/
interface IPoolCore {
/**
* @dev Emitted on supply()
* @param reserve The address of the underlying asset of the reserve
* @param user The address initiating the supply
* @param onBehalfOf The beneficiary of the supply, receiving the xTokens
* @param amount The amount supplied
* @param referralCode The referral code used
**/
event Supply(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
uint16 indexed referralCode
);
event SupplyERC721(
address indexed reserve,
address user,
address indexed onBehalfOf,
DataTypes.ERC721SupplyParams[] tokenData,
uint16 indexed referralCode,
bool fromNToken
);
/**
* @dev Emitted on withdraw()
* @param reserve The address of the underlying asset being withdrawn
* @param user The address initiating the withdrawal, owner of xTokens
* @param to The address that will receive the underlying asset
* @param amount The amount to be withdrawn
**/
event Withdraw(
address indexed reserve,
address indexed user,
address indexed to,
uint256 amount
);
/**
* @dev Emitted on withdrawERC721()
* @param reserve The address of the underlying asset being withdrawn
* @param user The address initiating the withdrawal, owner of xTokens
* @param to The address that will receive the underlying asset
* @param tokenIds The tokenIds to be withdrawn
**/
event WithdrawERC721(
address indexed reserve,
address indexed user,
address indexed to,
uint256[] tokenIds
);
/**
* @dev Emitted on borrow() and flashLoan() when debt needs to be opened
* @param reserve The address of the underlying asset being borrowed
* @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just
* initiator of the transaction on flashLoan()
* @param onBehalfOf The address that will be getting the debt
* @param amount The amount borrowed out
* @param borrowRate The numeric rate at which the user has borrowed, expressed in ray
* @param referralCode The referral code used
**/
event Borrow(
address indexed reserve,
address user,
address indexed onBehalfOf,
uint256 amount,
uint256 borrowRate,
uint16 indexed referralCode
);
/**
* @dev Emitted on repay()
* @param reserve The address of the underlying asset of the reserve
* @param user The beneficiary of the repayment, getting his debt reduced
* @param repayer The address of the user initiating the repay(), providing the funds
* @param amount The amount repaid
* @param usePTokens True if the repayment is done using xTokens, `false` if done with underlying asset directly
**/
event Repay(
address indexed reserve,
address indexed user,
address indexed repayer,
uint256 amount,
bool usePTokens
);
/**
* @dev Emitted on setUserUseERC20AsCollateral()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user enabling the usage as collateral
**/
event ReserveUsedAsCollateralEnabled(
address indexed reserve,
address indexed user
);
/**
* @dev Emitted on setUserUseERC20AsCollateral()
* @param reserve The address of the underlying asset of the reserve
* @param user The address of the user enabling the usage as collateral
**/
event ReserveUsedAsCollateralDisabled(
address indexed reserve,
address indexed user
);
/**
* @dev Emitted when a borrower is liquidated.
* @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
* @param liquidationAsset The address of the underlying borrowed asset to be repaid with the liquidation
* @param borrower The address of the borrower getting liquidated
* @param liquidationAmount The debt amount of borrowed `asset` the liquidator wants to cover
* @param liquidatedCollateralAmount The amount of collateral received by the liquidator
* @param liquidator The address of the liquidator
* @param receivePToken True if the liquidators wants to receive the collateral xTokens, `false` if he wants
* to receive the underlying collateral asset directly
**/
event LiquidateERC20(
address indexed collateralAsset,
address indexed liquidationAsset,
address indexed borrower,
uint256 liquidationAmount,
uint256 liquidatedCollateralAmount,
address liquidator,
bool receivePToken
);
/**
* @dev Emitted when a borrower's ERC721 asset is liquidated.
* @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
* @param liquidationAsset The address of the underlying borrowed asset to be repaid with the liquidation
* @param borrower The address of the borrower getting liquidated
* @param liquidationAmount The debt amount of borrowed `asset` the liquidator wants to cover
* @param liquidatedCollateralTokenId The token id of ERC721 asset received by the liquidator
* @param liquidator The address of the liquidator
* @param receiveNToken True if the liquidators wants to receive the collateral NTokens, `false` if he wants
* to receive the underlying collateral asset directly
**/
event LiquidateERC721(
address indexed collateralAsset,
address indexed liquidationAsset,
address indexed borrower,
uint256 liquidationAmount,
uint256 liquidatedCollateralTokenId,
address liquidator,
bool receiveNToken
);
/**
* @dev Emitted on flashClaim
* @param target The address of the flash loan receiver contract
* @param initiator The address initiating the flash claim
* @param nftAsset address of the underlying asset of NFT
* @param tokenId The token id of the asset being flash borrowed
**/
event FlashClaim(
address indexed target,
address indexed initiator,
address indexed nftAsset,
uint256 tokenId
);
/**
* @dev Allows smart contracts to access the tokens within one transaction, as long as the tokens taken is returned.
*
* Requirements:
* - `nftTokenIds` must exist.
*
* @param receiverAddress The address of the contract receiving the tokens, implementing the IFlashClaimReceiver interface
* @param nftAsset address of the underlying asset of NFT
* @param nftTokenIds token ids of the underlying asset
* @param params Variadic packed params to pass to the receiver as extra information
*/
function flashClaim(
address receiverAddress,
address nftAsset,
uint256[] calldata nftTokenIds,
bytes calldata params
) external;
/**
* @notice Supplies an `amount` of underlying asset into the reserve, receiving in return overlying xTokens.
* - E.g. User supplies 100 USDC and gets in return 100 pUSDC
* @param asset The address of the underlying asset to supply
* @param amount The amount to be supplied
* @param onBehalfOf The address that will receive the xTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of xTokens
* is a different wallet
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
**/
function supply(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
/**
* @notice Supplies multiple `tokenIds` of underlying ERC721 asset into the reserve, receiving in return overlying nTokens.
* - E.g. User supplies 2 BAYC and gets in return 2 nBAYC
* @param asset The address of the underlying asset to supply
* @param tokenData The list of tokenIds and their collateral configs to be supplied
* @param onBehalfOf The address that will receive the xTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of xTokens
* is a different wallet
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
**/
function supplyERC721(
address asset,
DataTypes.ERC721SupplyParams[] calldata tokenData,
address onBehalfOf,
uint16 referralCode
) external;
/**
* @notice Same as `supplyERC721` but this can only be called by NToken contract and doesn't require sending the underlying asset.
* @param asset The address of the underlying asset to supply
* @param tokenData The list of tokenIds and their collateral configs to be supplied
* @param onBehalfOf The address that will receive the xTokens
**/
function supplyERC721FromNToken(
address asset,
DataTypes.ERC721SupplyParams[] calldata tokenData,
address onBehalfOf
) external;
/**
* @notice Supply with transfer approval of asset to be supplied done via permit function
* see: https://eips.ethereum.org/EIPS/eip-2612 and https://eips.ethereum.org/EIPS/eip-713
* @param asset The address of the underlying asset to supply
* @param amount The amount to be supplied
* @param onBehalfOf The address that will receive the xTokens, same as msg.sender if the user
* wants to receive them on his own wallet, or a different address if the beneficiary of xTokens
* is a different wallet
* @param deadline The deadline timestamp that the permit is valid
* @param referralCode Code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param permitV The V parameter of ERC712 permit sig
* @param permitR The R parameter of ERC712 permit sig
* @param permitS The S parameter of ERC712 permit sig
**/
function supplyWithPermit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode,
uint256 deadline,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) external;
/**
* @notice Withdraws an `amount` of underlying asset from the reserve, burning the equivalent xTokens owned
* E.g. User has 100 pUSDC, calls withdraw() and receives 100 USDC, burning the 100 pUSDC
* @param asset The address of the underlying asset to withdraw
* @param amount The underlying amount to be withdrawn
* - Send the value type(uint256).max in order to withdraw the whole xToken balance
* @param to The address that will receive the underlying, same as msg.sender if the user
* wants to receive it on his own wallet, or a different address if the beneficiary is a
* different wallet
* @return The final amount withdrawn
**/
function withdraw(
address asset,
uint256 amount,
address to
) external returns (uint256);
/**
* @notice Withdraws multiple `tokenIds` of underlying ERC721 asset from the reserve, burning the equivalent nTokens owned
* E.g. User has 2 nBAYC, calls withdraw() and receives 2 BAYC, burning the 2 nBAYC
* @param asset The address of the underlying asset to withdraw
* @param tokenIds The underlying tokenIds to be withdrawn
* - Send the value type(uint256).max in order to withdraw the whole xToken balance
* @param to The address that will receive the underlying, same as msg.sender if the user
* wants to receive it on his own wallet, or a different address if the beneficiary is a
* different wallet
* @return The final amount withdrawn
**/
function withdrawERC721(
address asset,
uint256[] calldata tokenIds,
address to
) external returns (uint256);
/**
* @notice Decreases liquidity for underlying Uniswap V3 NFT LP and validates
* that the user respects liquidation checks.
* @param asset The asset address of uniswapV3
* @param tokenId The id of the erc721 token
* @param liquidityDecrease The amount of liquidity to remove of LP
* @param amount0Min The minimum amount to remove of token0
* @param amount1Min The minimum amount to remove of token1
* @param receiveEthAsWeth If convert weth to ETH
*/
function decreaseUniswapV3Liquidity(
address asset,
uint256 tokenId,
uint128 liquidityDecrease,
uint256 amount0Min,
uint256 amount1Min,
bool receiveEthAsWeth,
uint256 deadline
) external;
/**
* @notice Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
* already supplied enough collateral, or he was given enough allowance by a credit delegator on the
* corresponding debt token (VariableDebtToken)
* - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet
* and 100 stable/variable debt tokens
* @param asset The address of the underlying asset to borrow
* @param amount The amount to be borrowed
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
* 0 if the action is executed directly by the user, without any middle-man
* @param onBehalfOf The address of the user who will receive the debt. Should be the address of the borrower itself
* calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
* if he has been given credit delegation allowance
**/
function borrow(
address asset,
uint256 amount,
uint16 referralCode,
address onBehalfOf
) external;
/**
* @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned
* - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address
* @param asset The address of the borrowed underlying asset previously borrowed
* @param amount The amount to repay
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
* @param onBehalfOf The address of the user who will get his debt reduced/removed. Should be the address of the
* user calling the function if he wants to reduce/remove his own debt, or the address of any other
* other borrower whose debt should be removed
* @return The final amount repaid
**/
function repay(
address asset,
uint256 amount,
address onBehalfOf
) external returns (uint256);
/**
* @notice Repays a borrowed `amount` on a specific reserve using the reserve xTokens, burning the
* equivalent debt tokens
* - E.g. User repays 100 USDC using 100 pUSDC, burning 100 variable/stable debt tokens
* @dev Passing uint256.max as amount will clean up any residual xToken dust balance, if the user xToken
* balance is not enough to cover the whole debt
* @param asset The address of the borrowed underlying asset previously borrowed
* @param amount The amount to repay
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
* @return The final amount repaid
**/
function repayWithPTokens(address asset, uint256 amount)
external
returns (uint256);
/**
* @notice Repay with transfer approval of asset to be repaid done via permit function
* see: https://eips.ethereum.org/EIPS/eip-2612 and https://eips.ethereum.org/EIPS/eip-713
* @param asset The address of the borrowed underlying asset previously borrowed
* @param amount The amount to repay
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
* @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the
* user calling the function if he wants to reduce/remove his own debt, or the address of any other
* other borrower whose debt should be removed
* @param deadline The deadline timestamp that the permit is valid
* @param permitV The V parameter of ERC712 permit sig
* @param permitR The R parameter of ERC712 permit sig
* @param permitS The S parameter of ERC712 permit sig
* @return The final amount repaid
**/
function repayWithPermit(
address asset,
uint256 amount,
address onBehalfOf,
uint256 deadline,
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) external returns (uint256);
/**
* @notice Allows suppliers to enable/disable a specific supplied asset as collateral
* @param asset The address of the underlying asset supplied
* @param useAsCollateral True if the user wants to use the supply as collateral, false otherwise
**/
function setUserUseERC20AsCollateral(address asset, bool useAsCollateral)
external;
/**
* @notice Allows suppliers to enable/disable a specific supplied ERC721 asset with a tokenID as collateral
* @param asset The address of the underlying asset supplied
* @param tokenIds the ids of the supplied ERC721 token
* @param useAsCollateral True if the user wants to use the supply as collateral, false otherwise
**/
function setUserUseERC721AsCollateral(
address asset,
uint256[] calldata tokenIds,
bool useAsCollateral
) external;
/**
* @notice Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1
* - The caller (liquidator) covers `liquidationAmount` amount of debt of the user getting liquidated, and receives
* a proportionally amount of the `collateralAsset` plus a bonus to cover market risk
* @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
* @param liquidationAsset The address of the underlying borrowed asset to be repaid with the liquidation
* @param user The address of the borrower getting liquidated
* @param liquidationAmount The debt amount of borrowed `asset` the liquidator wants to cover
* @param receivePToken True if the liquidators wants to receive the collateral xTokens, `false` if he wants
* to receive the underlying collateral asset directly
**/
function liquidateERC20(
address collateralAsset,
address liquidationAsset,
address user,
uint256 liquidationAmount,
bool receivePToken
) external payable;
function liquidateERC721(
address collateralAsset,
address user,
uint256 collateralTokenId,
uint256 liquidationAmount,
bool receiveNToken
) external payable;
/**
* @notice Start the auction on user's specific NFT collateral
* @param user The address of the user
* @param collateralAsset The address of the NFT collateral
* @param collateralTokenId The tokenId of the NFT collateral
**/
function startAuction(
address user,
address collateralAsset,
uint256 collateralTokenId
) external;
/**
* @notice End specific user's auction
* @param user The address of the user
* @param collateralAsset The address of the NFT collateral
* @param collateralTokenId The tokenId of the NFT collateral
**/
function endAuction(
address user,
address collateralAsset,
uint256 collateralTokenId
) external;
/**
* @notice Returns the configuration of the user across all the reserves
* @param user The user address
* @return The configuration of the user
**/
function getUserConfiguration(address user)
external
view
returns (DataTypes.UserConfigurationMap memory);
/**
* @notice Returns the configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The configuration of the reserve
**/
function getConfiguration(address asset)
external
view
returns (DataTypes.ReserveConfigurationMap memory);
/**
* @notice Returns the normalized income normalized income of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The reserve's normalized income
*/
function getReserveNormalizedIncome(address asset)
external
view
returns (uint256);
/**
* @notice Returns the normalized variable debt per unit of asset
* @param asset The address of the underlying asset of the reserve
* @return The reserve normalized variable debt
*/
function getReserveNormalizedVariableDebt(address asset)
external
view
returns (uint256);
/**
* @notice Returns the state and configuration of the reserve
* @param asset The address of the underlying asset of the reserve
* @return The state and configuration data of the reserve
**/
function getReserveData(address asset)
external
view
returns (DataTypes.ReserveData memory);
/**
* @notice Validates and finalizes an PToken transfer
* @dev Only callable by the overlying xToken of the `asset`
* @param asset The address of the underlying asset of the xToken
* @param from The user from which the xTokens are transferred
* @param to The user receiving the xTokens
* @param amount The amount being transferred/withdrawn
* @param balanceFromBefore The xToken balance of the `from` user before the transfer
* @param balanceToBefore The xToken balance of the `to` user before the transfer
*/
function finalizeTransfer(
address asset,
address from,
address to,
bool usedAsCollateral,
uint256 amount,
uint256 balanceFromBefore,
uint256 balanceToBefore
) external;
/**
* @notice Validates and finalizes an NToken transfer
* @dev Only callable by the overlying xToken of the `asset`
* @param asset The address of the underlying asset of the xToken
* @param tokenId The tokenId of the ERC721 asset
* @param from The user from which the xTokens are transferred
* @param to The user receiving the xTokens
* @param balanceFromBefore The xToken balance of the `from` user before the transfer
*/
function finalizeTransferERC721(
address asset,
uint256 tokenId,
address from,
address to,
bool usedAsCollateral,
uint256 balanceFromBefore
) external;
/**
* @notice Returns the list of the underlying assets of all the initialized reserves
* @dev It does not include dropped reserves
* @return The addresses of the underlying assets of the initialized reserves
**/
function getReservesList() external view returns (address[] memory);
/**
* @notice Returns the address of the underlying asset of a reserve by the reserve id as stored in the DataTypes.ReserveData struct
* @param id The id of the reserve as stored in the DataTypes.ReserveData struct
* @return The address of the reserve associated with id
**/
function getReserveAddressById(uint16 id) external view returns (address);
/**
* @notice Returns the auction related data of specific asset collection and token id.
* @param ntokenAsset The address of ntoken
* @param tokenId The token id which is currently auctioned for liquidation
* @return The auction related data of the corresponding (ntokenAsset, tokenId)
*/
function getAuctionData(address ntokenAsset, uint256 tokenId)
external
view
returns (DataTypes.AuctionData memory);
// function getAuctionData(address user, address) external view returns (DataTypes.AuctionData memory);
/**
* @notice Returns the PoolAddressesProvider connected to this contract
* @return The address of the PoolAddressesProvider
**/
function ADDRESSES_PROVIDER()
external
view
returns (IPoolAddressesProvider);
/**
* @notice Returns the maximum number of reserves supported to be listed in this Pool
* @return The maximum number of reserves supported
*/
function MAX_NUMBER_RESERVES() external view returns (uint16);
/**
* @notice Returns the auction recovery health factor
* @return The auction recovery health factor
*/
function AUCTION_RECOVERY_HEALTH_FACTOR() external view returns (uint64);
}