From f32ac702ecf9e11c3dcdfed7587e4379ea70ec4c Mon Sep 17 00:00:00 2001 From: eboado Date: Thu, 12 Nov 2020 13:54:23 +0100 Subject: [PATCH] - Refactoring on some Errors --- contracts/libraries/helpers/Errors.sol | 19 +++++++++++-------- contracts/tokenization/AToken.sol | 6 +++--- contracts/tokenization/StableDebtToken.sol | 4 ++-- contracts/tokenization/VariableDebtToken.sol | 4 ++-- contracts/tokenization/base/DebtTokenBase.sol | 2 +- helpers/types.ts | 10 +++++----- test/atoken-modifiers.spec.ts | 12 ++++++------ test/stable-token.spec.ts | 10 ++++------ test/variable-debt-token.spec.ts | 6 +++--- 9 files changed, 37 insertions(+), 36 deletions(-) diff --git a/contracts/libraries/helpers/Errors.sol b/contracts/libraries/helpers/Errors.sol index 61f5aaf6..bf468fd3 100644 --- a/contracts/libraries/helpers/Errors.sol +++ b/contracts/libraries/helpers/Errors.sol @@ -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,8 +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 AT_STABLE_DEBT_OVERFLOW = '79'; - string public constant AT_BURN_EXCEEDS_BALANCE = '80'; + string public constant SDT_STABLE_DEBT_OVERFLOW = '79'; + string public constant SDT_BURN_EXCEEDS_BALANCE = '80'; enum CollateralManagerErrors { NO_ERROR, diff --git a/contracts/tokenization/AToken.sol b/contracts/tokenization/AToken.sol index 2f2be6cb..5138ddeb 100644 --- a/contracts/tokenization/AToken.sol +++ b/contracts/tokenization/AToken.sol @@ -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 diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index 1184be79..cb53afdc 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -123,7 +123,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { .add(vars.amountInRay.rayMul(rate)) .rayDiv(currentBalance.add(amount).wadToRay()); - require(vars.newStableRate < type(uint128).max, Errors.AT_STABLE_DEBT_OVERFLOW); + require(vars.newStableRate < type(uint128).max, Errors.SDT_STABLE_DEBT_OVERFLOW); _usersStableRate[onBehalfOf] = vars.newStableRate; //updating the user and supply timestamp @@ -343,7 +343,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { uint256 oldTotalSupply ) internal { uint256 oldAccountBalance = _balances[account]; - _balances[account] = oldAccountBalance.sub(amount, Errors.AT_BURN_EXCEEDS_BALANCE); + _balances[account] = oldAccountBalance.sub(amount, Errors.SDT_BURN_EXCEEDS_BALANCE); if (address(_incentivesController) != address(0)) { _incentivesController.handleAction(account, oldTotalSupply, oldAccountBalance); diff --git a/contracts/tokenization/VariableDebtToken.sol b/contracts/tokenization/VariableDebtToken.sol index ef429b53..4d45831f 100644 --- a/contracts/tokenization/VariableDebtToken.sol +++ b/contracts/tokenization/VariableDebtToken.sol @@ -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); diff --git a/contracts/tokenization/base/DebtTokenBase.sol b/contracts/tokenization/base/DebtTokenBase.sol index b1b9963c..3cf38019 100644 --- a/contracts/tokenization/base/DebtTokenBase.sol +++ b/contracts/tokenization/base/DebtTokenBase.sol @@ -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); _; } diff --git a/helpers/types.ts b/helpers/types.ts index c9aac797..6b2f156d 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -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', diff --git a/test/atoken-modifiers.spec.ts b/test/atoken-modifiers.spec.ts index e1b00203..4649dc21 100644 --- a/test/atoken-modifiers.spec.ts +++ b/test/atoken-modifiers.spec.ts @@ -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 ); }); }); diff --git a/test/stable-token.spec.ts b/test/stable-token.spec.ts index fecc3e78..1f58965f 100644 --- a/test/stable-token.spec.ts +++ b/test/stable-token.spec.ts @@ -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 ); }); }); diff --git a/test/variable-debt-token.spec.ts b/test/variable-debt-token.spec.ts index 6c177096..71dbecd2 100644 --- a/test/variable-debt-token.spec.ts +++ b/test/variable-debt-token.spec.ts @@ -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 ); }); });