Skip to content

Commit a9ee50a

Browse files
committed
updated InterestRates flag validation, tests
1 parent d309f3e commit a9ee50a

16 files changed

Lines changed: 114 additions & 71 deletions

File tree

src/contracts/extensions/paraswap-adapters/ParaSwapRepayAdapter.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ contract ParaSwapRepayAdapter is BaseParaSwapBuyAdapter, ReentrancyGuard {
207207
address initiator
208208
) private view returns (uint256) {
209209
require(
210-
DataTypes.InterestRateMode(rateMode) != DataTypes.InterestRateMode.NONE,
210+
DataTypes.InterestRateMode(rateMode) == DataTypes.InterestRateMode.VARIABLE,
211211
'INVALID_RATE_MODE'
212212
);
213213
DataTypes.ReserveDataLegacy memory debtReserveData = _getReserveData(address(debtAsset));

src/contracts/helpers/L2Encoder.sol

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ contract L2Encoder {
118118
* @dev Without an onBehalfOf parameter as the compact calls to L2Pool will use msg.sender as onBehalfOf
119119
* @param asset The address of the underlying asset to borrow
120120
* @param amount The amount to be borrowed
121-
* @param interestRateMode The interest rate mode at which the user wants to borrow: 1 and 2 for Variable (changed on v3.2.0)
121+
* @param interestRateMode The interest rate mode at which the user wants to borrow: 2 for Variable, 1 is deprecated (changed on v3.2.0)
122122
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
123123
* 0 if the action is executed directly by the user, without any middle-man
124124
* @return compact representation of withdraw parameters
@@ -153,7 +153,7 @@ contract L2Encoder {
153153
* @param asset The address of the borrowed underlying asset previously borrowed
154154
* @param amount The amount to repay
155155
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `interestRateMode`
156-
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 and 2 for Variable (changed on v3.2.0)
156+
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 2 for Variable, 1 is deprecated (changed on v3.2.0)
157157
* @return compact representation of repay parameters
158158
*/
159159
function encodeRepayParams(
@@ -180,7 +180,7 @@ contract L2Encoder {
180180
* @param asset The address of the borrowed underlying asset previously borrowed
181181
* @param amount The amount to repay
182182
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
183-
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 and 2 for Variable (changed on v3.2.0)
183+
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 2 for Variable, 1 is deprecated (changed on v3.2.0)
184184
* @param deadline The deadline timestamp that the permit is valid
185185
* @param permitV The V parameter of ERC712 permit sig
186186
* @param permitR The R parameter of ERC712 permit sig
@@ -226,7 +226,7 @@ contract L2Encoder {
226226
* @param asset The address of the borrowed underlying asset previously borrowed
227227
* @param amount The amount to repay
228228
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
229-
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 1 and 2 for Variable (changed on v3.2.0)
229+
* @param interestRateMode The interest rate mode at of the debt the user wants to repay: 2 for Variable, 1 is deprecated (changed on v3.2.0)
230230
* @return compact representation of repay with aToken parameters
231231
*/
232232
function encodeRepayWithATokensParams(
@@ -237,26 +237,6 @@ contract L2Encoder {
237237
return encodeRepayParams(asset, amount, interestRateMode);
238238
}
239239

240-
/**
241-
* @notice Encodes swap borrow rate mode parameters from standard input to compact representation of 1 bytes32
242-
* @param asset The address of the underlying asset borrowed
243-
* @param interestRateMode The current interest rate mode of the position being swapped: 1 and 2 for Variable (changed on v3.2.0)
244-
* @return compact representation of swap borrow rate mode parameters
245-
*/
246-
function encodeSwapBorrowRateMode(
247-
address asset,
248-
uint256 interestRateMode
249-
) external view returns (bytes32) {
250-
DataTypes.ReserveDataLegacy memory data = POOL.getReserveData(asset);
251-
uint16 assetId = data.id;
252-
uint8 shortenedInterestRateMode = interestRateMode.toUint8();
253-
bytes32 res;
254-
assembly {
255-
res := add(assetId, shl(16, shortenedInterestRateMode))
256-
}
257-
return res;
258-
}
259-
260240
/**
261241
* @notice Encodes set user use reserve as collateral parameters from standard input to compact representation of 1 bytes32
262242
* @param asset The address of the underlying asset borrowed

src/contracts/helpers/WrappedTokenGatewayV3.sol

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ contract WrappedTokenGatewayV3 is IWrappedTokenGatewayV3, Ownable {
7676
function repayETH(
7777
address,
7878
uint256 amount,
79-
uint256,
79+
uint256 rateMode,
8080
address onBehalfOf
8181
) external payable override {
82+
require(
83+
rateMode == uint256(DataTypes.InterestRateMode.VARIABLE),
84+
'DEPRECATED_BORROW_RATE_MODE'
85+
);
8286
uint256 paybackAmount = DataTypesHelper.getUserCurrentDebt(
8387
onBehalfOf,
8488
POOL.getReserveData(address(WETH))
@@ -105,7 +109,16 @@ contract WrappedTokenGatewayV3 is IWrappedTokenGatewayV3, Ownable {
105109
* @param amount the amount of ETH to borrow
106110
* @param referralCode integrators are assigned a referral code and can potentially receive rewards
107111
*/
108-
function borrowETH(address, uint256 amount, uint256, uint16 referralCode) external override {
112+
function borrowETH(
113+
address,
114+
uint256 amount,
115+
uint256 rateMode,
116+
uint16 referralCode
117+
) external override {
118+
require(
119+
rateMode == uint256(DataTypes.InterestRateMode.VARIABLE),
120+
'DEPRECATED_BORROW_RATE_MODE'
121+
);
109122
POOL.borrow(
110123
address(WETH),
111124
amount,

src/contracts/interfaces/IPool.sol

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ interface IPool {
6767
* initiator of the transaction on flashLoan()
6868
* @param onBehalfOf The address that will be getting the debt
6969
* @param amount The amount borrowed out
70-
* @param interestRateMode The rate mode: 1 and 2 for Variable (changed on v3.2.0)
70+
* @param interestRateMode The rate mode: 2 for Variable, 1 is deprecated (changed on v3.2.0)
7171
* @param borrowRate The numeric rate at which the user has borrowed, expressed in ray
7272
* @param referralCode The referral code used
7373
*/
@@ -101,7 +101,8 @@ interface IPool {
101101
* @dev Emitted on swapBorrowRateMode(), DEPRECATED on v3.2.0
102102
* @param reserve The address of the underlying asset of the reserve
103103
* @param user The address of the user swapping his rate mode
104-
* @param interestRateMode The current interest rate mode of the position being swapped: 1 for Stable, 2 for Variable
104+
* @param interestRateMode The current interest rate mode of the position being swapped:
105+
* 1 for Stable (Deprecated on v3.2.0), 2 for Variable
105106
*/
106107
event SwapBorrowRateMode(
107108
address indexed reserve,
@@ -150,7 +151,8 @@ interface IPool {
150151
* @param initiator The address initiating the flash loan
151152
* @param asset The address of the asset being flash borrowed
152153
* @param amount The amount flash borrowed
153-
* @param interestRateMode The flashloan mode: 0 for regular flashloan, 1 and 2 for Variable debt (changed on v3.2.0)
154+
* @param interestRateMode The flashloan mode: 0 for regular flashloan,
155+
* 1 for Stable (Deprecated on v3.2.0), 2 for Variable
154156
* @param premium The fee flash borrowed
155157
* @param referralCode The referral code used
156158
*/
@@ -293,7 +295,7 @@ interface IPool {
293295
* and 100 variable debt tokens
294296
* @param asset The address of the underlying asset to borrow
295297
* @param amount The amount to be borrowed
296-
* @param interestRateMode DEPRECATED in v3.2.0
298+
* @param interestRateMode 2 for Variable, 1 is deprecated on v3.2.0
297299
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
298300
* 0 if the action is executed directly by the user, without any middle-man
299301
* @param onBehalfOf The address of the user who will receive the debt. Should be the address of the borrower itself
@@ -314,7 +316,7 @@ interface IPool {
314316
* @param asset The address of the borrowed underlying asset previously borrowed
315317
* @param amount The amount to repay
316318
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
317-
* @param interestRateMode DEPRECATED in v3.2.0
319+
* @param interestRateMode 2 for Variable, 1 is deprecated on v3.2.0
318320
* @param onBehalfOf The address of the user who will get his debt reduced/removed. Should be the address of the
319321
* user calling the function if he wants to reduce/remove his own debt, or the address of any other
320322
* other borrower whose debt should be removed
@@ -333,7 +335,7 @@ interface IPool {
333335
* @param asset The address of the borrowed underlying asset previously borrowed
334336
* @param amount The amount to repay
335337
* - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
336-
* @param interestRateMode DEPRECATED in v3.2.0
338+
* @param interestRateMode 2 for Variable, 1 is deprecated on v3.2.0
337339
* @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the
338340
* user calling the function if he wants to reduce/remove his own debt, or the address of any other
339341
* other borrower whose debt should be removed
@@ -408,8 +410,9 @@ interface IPool {
408410
* @param amounts The amounts of the assets being flash-borrowed
409411
* @param interestRateModes Types of the debt to open if the flash loan is not returned:
410412
* 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver
411-
* 1 or 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
412-
* @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2
413+
* 1 -> Deprecated on v3.2.0
414+
* 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
415+
* @param onBehalfOf The address that will receive the debt in the case of using 2 on `modes`
413416
* @param params Variadic packed params to pass to the receiver as extra information
414417
* @param referralCode The code used to register the integrator originating the operation, for potential rewards.
415418
* 0 if the action is executed directly by the user, without any middle-man

src/contracts/mocks/testnet-helpers/TestnetERC20.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ contract TestnetERC20 is IERC20WithPermit, ERC20, Ownable {
7474
* @param value The amount of tokens to mint.
7575
* @return A boolean that indicates if the operation was successful.
7676
*/
77-
function mint(uint256 value) public virtual onlyOwner returns (bool) {
77+
// TODO: check
78+
function mint(uint256 value) public virtual returns (bool) {
7879
_mint(_msgSender(), value);
7980
return true;
8081
}

src/contracts/protocol/libraries/helpers/Errors.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ library Errors {
100100
string public constant LIQUIDATION_GRACE_SENTINEL_CHECK_FAILED = '97'; // 'Liquidation grace sentinel validation failed'
101101
string public constant INVALID_GRACE_PERIOD = '98'; // Grace period above a valid range
102102
string public constant INVALID_FREEZE_STATE = '99'; // Reserve is already in the passed freeze state
103+
string public constant DEPRECATED_BORROW_RATE_MODE = '100'; // User trying to borrow stable, but it's deprecated
103104
}

src/contracts/protocol/libraries/logic/BorrowLogic.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ library BorrowLogic {
8686
asset: params.asset,
8787
userAddress: params.onBehalfOf,
8888
amount: params.amount,
89+
interestRateMode: params.interestRateMode,
8990
reservesCount: params.reservesCount,
9091
oracle: params.oracle,
9192
userEModeCategory: params.userEModeCategory,
@@ -163,7 +164,13 @@ library BorrowLogic {
163164

164165
uint256 variableDebt = Helpers.getUserCurrentDebt(params.onBehalfOf, reserveCache);
165166

166-
ValidationLogic.validateRepay(reserveCache, params.amount, params.onBehalfOf, variableDebt);
167+
ValidationLogic.validateRepay(
168+
reserveCache,
169+
params.amount,
170+
params.interestRateMode,
171+
params.onBehalfOf,
172+
variableDebt
173+
);
167174

168175
uint256 paybackAmount = variableDebt;
169176

src/contracts/protocol/libraries/logic/CalldataLogic.sol

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ library CalldataLogic {
114114
* @param args The packed repay params
115115
* @return The address of the underlying reserve
116116
* @return The amount to repay
117-
* @return The interestRateMode, 1 and 2 for variable debt (changed on v3.2.0)
117+
* @return The interestRateMode, 2 for variable debt, 1 is deprecated (changed on v3.2.0)
118118
*/
119119
function decodeRepayParams(
120120
mapping(uint256 => address) storage reservesList,
@@ -167,28 +167,6 @@ library CalldataLogic {
167167
return (asset, amount, interestRateMode, deadline, permitV);
168168
}
169169

170-
/**
171-
* @notice Decodes compressed swap borrow rate mode params to standard params
172-
* @param reservesList The addresses of all the active reserves
173-
* @param args The packed swap borrow rate mode params
174-
* @return The address of the underlying reserve
175-
* @return The interest rate mode, 1 and 2 for variable debt (changed on v3.2.0)
176-
*/
177-
function decodeSwapBorrowRateModeParams(
178-
mapping(uint256 => address) storage reservesList,
179-
bytes32 args
180-
) internal view returns (address, uint256) {
181-
uint16 assetId;
182-
uint256 interestRateMode;
183-
184-
assembly {
185-
assetId := and(args, 0xFFFF)
186-
interestRateMode := and(shr(16, args), 0xFF)
187-
}
188-
189-
return (reservesList[assetId], interestRateMode);
190-
}
191-
192170
/**
193171
* @notice Decodes compressed set user use reserve as collateral params to standard params
194172
* @param reservesList The addresses of all the active reserves

src/contracts/protocol/libraries/logic/FlashLoanLogic.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ library FlashLoanLogic {
147147
user: msg.sender,
148148
onBehalfOf: params.onBehalfOf,
149149
amount: vars.currentAmount,
150+
interestRateMode: DataTypes.InterestRateMode(params.interestRateModes[i]),
150151
referralCode: params.referralCode,
151152
releaseUnderlying: false,
152153
reservesCount: IPool(params.pool).getReservesCount(),
@@ -268,7 +269,7 @@ library FlashLoanLogic {
268269
msg.sender,
269270
params.asset,
270271
params.amount,
271-
DataTypes.InterestRateMode(0),
272+
DataTypes.InterestRateMode.NONE,
272273
params.totalPremium,
273274
params.referralCode
274275
);

src/contracts/protocol/libraries/logic/ValidationLogic.sol

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ library ValidationLogic {
141141
DataTypes.ValidateBorrowParams memory params
142142
) internal view {
143143
require(params.amount != 0, Errors.INVALID_AMOUNT);
144+
require(
145+
params.interestRateMode == DataTypes.InterestRateMode.VARIABLE,
146+
Errors.DEPRECATED_BORROW_RATE_MODE
147+
);
144148

145149
ValidateBorrowLocalVars memory vars;
146150

@@ -281,10 +285,15 @@ library ValidationLogic {
281285
function validateRepay(
282286
DataTypes.ReserveCache memory reserveCache,
283287
uint256 amountSent,
288+
DataTypes.InterestRateMode interestRateMode,
284289
address onBehalfOf,
285290
uint256 debt
286291
) internal view {
287292
require(amountSent != 0, Errors.INVALID_AMOUNT);
293+
require(
294+
interestRateMode == DataTypes.InterestRateMode.VARIABLE,
295+
Errors.DEPRECATED_BORROW_RATE_MODE
296+
);
288297
require(
289298
amountSent != type(uint256).max || msg.sender == onBehalfOf,
290299
Errors.NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF

0 commit comments

Comments
 (0)