mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'fix/147-148-uint128max' into 'master'
- Changed `1 << 128` to `type(uint128).max` Closes #148 and #147 See merge request aave-tech/protocol-v2!169
This commit is contained in:
commit
cfc002dcd1
|
@ -8,7 +8,10 @@ pragma solidity ^0.6.8;
|
|||
* @dev Error messages prefix glossary:
|
||||
* - VL = ValidationLogic
|
||||
* - MATH = Math libraries
|
||||
* - AT = aToken or DebtTokens
|
||||
* - CT = Common errors between tokens (AToken, VariableDebtToken and StableDebtToken)
|
||||
* - AT = AToken
|
||||
* - SDT = StableDebtToken
|
||||
* - VDT = VariableDebtToken
|
||||
* - LP = LendingPool
|
||||
* - LPAPR = LendingPoolAddressesProviderRegistry
|
||||
* - LPC = LendingPoolConfiguration
|
||||
|
@ -50,9 +53,9 @@ library Errors {
|
|||
string public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent'
|
||||
string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The caller of the function is not the lending pool configurator'
|
||||
string public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = '28';
|
||||
string public constant AT_CALLER_MUST_BE_LENDING_POOL = '29'; // 'The caller of this function must be a lending pool'
|
||||
string public constant AT_CANNOT_GIVE_ALLVWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
|
||||
string public constant AT_TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
|
||||
string public constant CT_CALLER_MUST_BE_LENDING_POOL = '29'; // 'The caller of this function must be a lending pool'
|
||||
string public constant CT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'
|
||||
string public constant CT_TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'
|
||||
string public constant RL_RESERVE_ALREADY_INITIALIZED = '32'; // 'Reserve has already been initialized'
|
||||
string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '34'; // 'The liquidity of the reserve needs to be 0'
|
||||
string public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = '35'; // 'The liquidity of the reserve needs to be 0'
|
||||
|
@ -78,9 +81,9 @@ library Errors {
|
|||
string public constant RL_LIQUIDITY_RATE_OVERFLOW = '53'; // Liquidity rate overflows uint128
|
||||
string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '54'; // Variable borrow rate overflows uint128
|
||||
string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '55'; // Stable borrow rate overflows uint128
|
||||
string public constant AT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint
|
||||
string public constant CT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint
|
||||
string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '57';
|
||||
string public constant AT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn
|
||||
string public constant CT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn
|
||||
string public constant LP_FAILED_COLLATERAL_SWAP = '60';
|
||||
string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61';
|
||||
string public constant LP_REENTRANCY_NOT_ALLOWED = '62';
|
||||
|
@ -98,6 +101,8 @@ library Errors {
|
|||
string public constant LP_INCONSISTENT_PARAMS_LENGTH = '74';
|
||||
string public constant UL_INVALID_INDEX = '77';
|
||||
string public constant LP_NOT_CONTRACT = '78';
|
||||
string public constant SDT_STABLE_DEBT_OVERFLOW = '79';
|
||||
string public constant SDT_BURN_EXCEEDS_BALANCE = '80';
|
||||
|
||||
enum CollateralManagerErrors {
|
||||
NO_ERROR,
|
||||
|
|
|
@ -166,7 +166,7 @@ library ReserveLogic {
|
|||
uint256 result = amountToLiquidityRatio.add(WadRayMath.ray());
|
||||
|
||||
result = result.rayMul(reserve.liquidityIndex);
|
||||
require(result < (1 << 128), Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
|
||||
require(result < type(uint128).max, Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
|
||||
|
||||
reserve.liquidityIndex = uint128(result);
|
||||
}
|
||||
|
@ -247,9 +247,9 @@ library ReserveLogic {
|
|||
vars.avgStableRate,
|
||||
reserve.configuration.getReserveFactor()
|
||||
);
|
||||
require(vars.newLiquidityRate < (1 << 128), 'ReserveLogic: Liquidity rate overflow');
|
||||
require(vars.newStableRate < (1 << 128), 'ReserveLogic: Stable borrow rate overflow');
|
||||
require(vars.newVariableRate < (1 << 128), 'ReserveLogic: Variable borrow rate overflow');
|
||||
require(vars.newLiquidityRate < type(uint128).max, Errors.RL_LIQUIDITY_RATE_OVERFLOW);
|
||||
require(vars.newStableRate < type(uint128).max, Errors.RL_STABLE_BORROW_RATE_OVERFLOW);
|
||||
require(vars.newVariableRate < type(uint128).max, Errors.RL_VARIABLE_BORROW_RATE_OVERFLOW);
|
||||
|
||||
reserve.currentLiquidityRate = uint128(vars.newLiquidityRate);
|
||||
reserve.currentStableBorrowRate = uint128(vars.newStableRate);
|
||||
|
@ -367,7 +367,7 @@ library ReserveLogic {
|
|||
timestamp
|
||||
);
|
||||
newLiquidityIndex = cumulatedLiquidityInterest.rayMul(liquidityIndex);
|
||||
require(newLiquidityIndex < (1 << 128), Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
|
||||
require(newLiquidityIndex < type(uint128).max, Errors.RL_LIQUIDITY_INDEX_OVERFLOW);
|
||||
|
||||
reserve.liquidityIndex = uint128(newLiquidityIndex);
|
||||
|
||||
|
@ -379,7 +379,7 @@ library ReserveLogic {
|
|||
timestamp
|
||||
);
|
||||
newVariableBorrowIndex = cumulatedVariableBorrowInterest.rayMul(variableBorrowIndex);
|
||||
require(newVariableBorrowIndex < (1 << 128), Errors.RL_VARIABLE_BORROW_INDEX_OVERFLOW);
|
||||
require(newVariableBorrowIndex < type(uint128).max, Errors.RL_VARIABLE_BORROW_INDEX_OVERFLOW);
|
||||
reserve.variableBorrowIndex = uint128(newVariableBorrowIndex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
|
|||
bytes32 public DOMAIN_SEPARATOR;
|
||||
|
||||
modifier onlyLendingPool {
|
||||
require(_msgSender() == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL);
|
||||
require(_msgSender() == address(POOL), Errors.CT_CALLER_MUST_BE_LENDING_POOL);
|
||||
_;
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
|
|||
uint256 index
|
||||
) external override onlyLendingPool {
|
||||
uint256 amountScaled = amount.rayDiv(index);
|
||||
require(amountScaled != 0, Errors.AT_INVALID_BURN_AMOUNT);
|
||||
require(amountScaled != 0, Errors.CT_INVALID_BURN_AMOUNT);
|
||||
_burn(user, amountScaled);
|
||||
|
||||
//transfers the underlying to the target
|
||||
|
@ -127,7 +127,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
|
|||
uint256 previousBalance = super.balanceOf(user);
|
||||
|
||||
uint256 amountScaled = amount.rayDiv(index);
|
||||
require(amountScaled != 0, Errors.AT_INVALID_MINT_AMOUNT);
|
||||
require(amountScaled != 0, Errors.CT_INVALID_MINT_AMOUNT);
|
||||
_mint(user, amountScaled);
|
||||
|
||||
//transfer event to track balances
|
||||
|
|
|
@ -5,6 +5,7 @@ import {DebtTokenBase} from './base/DebtTokenBase.sol';
|
|||
import {MathUtils} from '../libraries/math/MathUtils.sol';
|
||||
import {WadRayMath} from '../libraries/math/WadRayMath.sol';
|
||||
import {IStableDebtToken} from './interfaces/IStableDebtToken.sol';
|
||||
import {Errors} from '../libraries/helpers/Errors.sol';
|
||||
|
||||
/**
|
||||
* @title contract StableDebtToken
|
||||
|
@ -122,7 +123,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
.add(vars.amountInRay.rayMul(rate))
|
||||
.rayDiv(currentBalance.add(amount).wadToRay());
|
||||
|
||||
require(vars.newStableRate < (1 << 128), 'Debt token: stable rate overflow');
|
||||
require(vars.newStableRate < type(uint128).max, Errors.SDT_STABLE_DEBT_OVERFLOW);
|
||||
_usersStableRate[onBehalfOf] = vars.newStableRate;
|
||||
|
||||
//updating the user and supply timestamp
|
||||
|
@ -342,7 +343,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {
|
|||
uint256 oldTotalSupply
|
||||
) internal {
|
||||
uint256 oldAccountBalance = _balances[account];
|
||||
_balances[account] = oldAccountBalance.sub(amount, 'ERC20: burn amount exceeds balance');
|
||||
_balances[account] = oldAccountBalance.sub(amount, Errors.SDT_BURN_EXCEEDS_BALANCE);
|
||||
|
||||
if (address(_incentivesController) != address(0)) {
|
||||
_incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance);
|
||||
|
|
|
@ -65,7 +65,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
|
|||
|
||||
uint256 previousBalance = super.balanceOf(onBehalfOf);
|
||||
uint256 amountScaled = amount.rayDiv(index);
|
||||
require(amountScaled != 0, Errors.AT_INVALID_MINT_AMOUNT);
|
||||
require(amountScaled != 0, Errors.CT_INVALID_MINT_AMOUNT);
|
||||
|
||||
_mint(onBehalfOf, amountScaled);
|
||||
|
||||
|
@ -86,7 +86,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
|
|||
uint256 index
|
||||
) external override onlyLendingPool {
|
||||
uint256 amountScaled = amount.rayDiv(index);
|
||||
require(amountScaled != 0, Errors.AT_INVALID_BURN_AMOUNT);
|
||||
require(amountScaled != 0, Errors.CT_INVALID_BURN_AMOUNT);
|
||||
|
||||
_burn(user, amountScaled);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable {
|
|||
* @dev Only lending pool can call functions marked by this modifier
|
||||
**/
|
||||
modifier onlyLendingPool {
|
||||
require(_msgSender() == address(POOL), Errors.AT_CALLER_MUST_BE_LENDING_POOL);
|
||||
require(_msgSender() == address(POOL), Errors.CT_CALLER_MUST_BE_LENDING_POOL);
|
||||
_;
|
||||
}
|
||||
|
||||
|
|
|
@ -114,9 +114,9 @@ export enum ProtocolErrors {
|
|||
LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26', // 'The actual balance of the protocol is inconsistent'
|
||||
LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27', // 'The caller is not the lending pool configurator'
|
||||
LP_INCONSISTENT_FLASHLOAN_PARAMS = '28',
|
||||
AT_CALLER_MUST_BE_LENDING_POOL = '29', // 'The caller of this function must be a lending pool'
|
||||
AT_CANNOT_GIVE_ALLVWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
|
||||
AT_TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
|
||||
CT_CALLER_MUST_BE_LENDING_POOL = '29', // 'The caller of this function must be a lending pool'
|
||||
CT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30', // 'User cannot give allowance to himself'
|
||||
CT_TRANSFER_AMOUNT_NOT_GT_0 = '31', // 'Transferred amount needs to be greater than zero'
|
||||
RL_RESERVE_ALREADY_INITIALIZED = '32', // 'Reserve has already been initialized'
|
||||
LPC_RESERVE_LIQUIDITY_NOT_0 = '34', // 'The liquidity of the reserve needs to be 0'
|
||||
LPC_INVALID_ATOKEN_POOL_ADDRESS = '35', // 'The liquidity of the reserve needs to be 0'
|
||||
|
@ -141,9 +141,9 @@ export enum ProtocolErrors {
|
|||
RL_LIQUIDITY_RATE_OVERFLOW = '53', // Liquidity rate overflows uint128
|
||||
RL_VARIABLE_BORROW_RATE_OVERFLOW = '54', // Variable borrow rate overflows uint128
|
||||
RL_STABLE_BORROW_RATE_OVERFLOW = '55', // Stable borrow rate overflows uint128
|
||||
AT_INVALID_MINT_AMOUNT = '56', //invalid amount to mint
|
||||
CT_INVALID_MINT_AMOUNT = '56', //invalid amount to mint
|
||||
LP_FAILED_REPAY_WITH_COLLATERAL = '57',
|
||||
AT_INVALID_BURN_AMOUNT = '58', //invalid amount to burn
|
||||
CT_INVALID_BURN_AMOUNT = '58', //invalid amount to burn
|
||||
LP_BORROW_ALLOWANCE_NOT_ENOUGH = '59', // User borrows on behalf, but allowance are too small
|
||||
LP_FAILED_COLLATERAL_SWAP = '60',
|
||||
LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61',
|
||||
|
|
|
@ -3,19 +3,19 @@ import {makeSuite, TestEnv} from './helpers/make-suite';
|
|||
import {ProtocolErrors} from '../helpers/types';
|
||||
|
||||
makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
|
||||
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||
const {CT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||
|
||||
it('Tries to invoke mint not being the LendingPool', async () => {
|
||||
const {deployer, aDai} = testEnv;
|
||||
await expect(aDai.mint(deployer.address, '1', '1')).to.be.revertedWith(
|
||||
AT_CALLER_MUST_BE_LENDING_POOL
|
||||
CT_CALLER_MUST_BE_LENDING_POOL
|
||||
);
|
||||
});
|
||||
|
||||
it('Tries to invoke burn not being the LendingPool', async () => {
|
||||
const {deployer, aDai} = testEnv;
|
||||
await expect(aDai.burn(deployer.address, deployer.address, '1', '1')).to.be.revertedWith(
|
||||
AT_CALLER_MUST_BE_LENDING_POOL
|
||||
CT_CALLER_MUST_BE_LENDING_POOL
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -23,13 +23,13 @@ makeSuite('AToken: Modifiers', (testEnv: TestEnv) => {
|
|||
const {deployer, users, aDai} = testEnv;
|
||||
await expect(
|
||||
aDai.transferOnLiquidation(deployer.address, users[0].address, '1')
|
||||
).to.be.revertedWith(AT_CALLER_MUST_BE_LENDING_POOL);
|
||||
).to.be.revertedWith(CT_CALLER_MUST_BE_LENDING_POOL);
|
||||
});
|
||||
|
||||
it('Tries to invoke transferUnderlyingTo not being the LendingPool', async () => {
|
||||
const {deployer, users, aDai} = testEnv;
|
||||
const {deployer, aDai} = testEnv;
|
||||
await expect(aDai.transferUnderlyingTo(deployer.address, '1')).to.be.revertedWith(
|
||||
AT_CALLER_MUST_BE_LENDING_POOL
|
||||
CT_CALLER_MUST_BE_LENDING_POOL
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
import {expect} from 'chai';
|
||||
import {makeSuite, TestEnv} from './helpers/make-suite';
|
||||
import {ProtocolErrors, eContractid} from '../helpers/types';
|
||||
import {getContract} from '../helpers/contracts-helpers';
|
||||
import {StableDebtToken} from '../types/StableDebtToken';
|
||||
import {ProtocolErrors} from '../helpers/types';
|
||||
import {getStableDebtToken} from '../helpers/contracts-getters';
|
||||
|
||||
makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
|
||||
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||
const {CT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||
|
||||
it('Tries to invoke mint not being the LendingPool', async () => {
|
||||
const {deployer, pool, dai, helpersContract} = testEnv;
|
||||
|
@ -18,7 +16,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
|
|||
|
||||
await expect(
|
||||
stableDebtContract.mint(deployer.address, deployer.address, '1', '1')
|
||||
).to.be.revertedWith(AT_CALLER_MUST_BE_LENDING_POOL);
|
||||
).to.be.revertedWith(CT_CALLER_MUST_BE_LENDING_POOL);
|
||||
});
|
||||
|
||||
it('Tries to invoke burn not being the LendingPool', async () => {
|
||||
|
@ -33,7 +31,7 @@ makeSuite('Stable debt token tests', (testEnv: TestEnv) => {
|
|||
|
||||
expect(name).to.be.equal('Aave stable debt bearing DAI');
|
||||
await expect(stableDebtContract.burn(deployer.address, '1')).to.be.revertedWith(
|
||||
AT_CALLER_MUST_BE_LENDING_POOL
|
||||
CT_CALLER_MUST_BE_LENDING_POOL
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -4,7 +4,7 @@ import {ProtocolErrors, TokenContractId, eContractid} from '../helpers/types';
|
|||
import {getVariableDebtToken} from '../helpers/contracts-getters';
|
||||
|
||||
makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
|
||||
const {AT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||
const {CT_CALLER_MUST_BE_LENDING_POOL} = ProtocolErrors;
|
||||
|
||||
it('Tries to invoke mint not being the LendingPool', async () => {
|
||||
const {deployer, pool, dai, helpersContract} = testEnv;
|
||||
|
@ -17,7 +17,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
|
|||
|
||||
await expect(
|
||||
variableDebtContract.mint(deployer.address, deployer.address, '1', '1')
|
||||
).to.be.revertedWith(AT_CALLER_MUST_BE_LENDING_POOL);
|
||||
).to.be.revertedWith(CT_CALLER_MUST_BE_LENDING_POOL);
|
||||
});
|
||||
|
||||
it('Tries to invoke burn not being the LendingPool', async () => {
|
||||
|
@ -30,7 +30,7 @@ makeSuite('Variable debt token tests', (testEnv: TestEnv) => {
|
|||
const variableDebtContract = await getVariableDebtToken(daiVariableDebtTokenAddress);
|
||||
|
||||
await expect(variableDebtContract.burn(deployer.address, '1', '1')).to.be.revertedWith(
|
||||
AT_CALLER_MUST_BE_LENDING_POOL
|
||||
CT_CALLER_MUST_BE_LENDING_POOL
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user