fix: Replace literal erros string with constant number strings

This commit is contained in:
Lasse Herskind 2021-08-23 19:08:11 +02:00
parent 7b20dee0fa
commit 3389b8b806
3 changed files with 52 additions and 24 deletions

View File

@ -0,0 +1,11 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.12;
library StaticATokenErrors {
string public constant INVALID_OWNER = '1';
string public constant INVALID_EXPIRATION = '2';
string public constant INVALID_SIGNATURE = '3';
string public constant INVALID_DEPOSITOR = '4';
string public constant INVALID_RECIPIENT = '5';
string public constant ONLY_ONE_AMOUNT_FORMAT_ALLOWED = '6';
}

View File

@ -7,6 +7,8 @@ import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import {IAToken} from '../../interfaces/IAToken.sol';
import {IAaveIncentivesController} from '../../interfaces/IAaveIncentivesController.sol';
import {StaticATokenErrors} from '../libraries/helpers/StaticATokenErrors.sol';
import {ERC20} from '../../dependencies/openzeppelin/contracts/ERC20.sol';
import {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol';
import {WadRayMath} from '../../protocol/libraries/math/WadRayMath.sol';
@ -161,9 +163,9 @@ contract StaticATokenLM is ERC20 {
bytes32 s,
uint256 chainId
) external {
require(owner != address(0), 'INVALID_OWNER');
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
//solium-disable-next-line
require(block.timestamp <= deadline, 'INVALID_EXPIRATION');
require(block.timestamp <= deadline, StaticATokenErrors.INVALID_EXPIRATION);
uint256 currentValidNonce = _nonces[owner];
bytes32 digest =
keccak256(
@ -173,7 +175,7 @@ contract StaticATokenLM is ERC20 {
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
)
);
require(owner == ecrecover(digest, v, r, s), 'INVALID_SIGNATURE');
require(owner == ecrecover(digest, v, r, s), StaticATokenErrors.INVALID_SIGNATURE);
_nonces[owner] = currentValidNonce.add(1);
_approve(owner, spender, value);
}
@ -204,9 +206,9 @@ contract StaticATokenLM is ERC20 {
SignatureParams calldata sigParams,
uint256 chainId
) external returns (uint256) {
require(depositor != address(0), 'INVALID_DEPOSITOR');
require(depositor != address(0), StaticATokenErrors.INVALID_DEPOSITOR);
//solium-disable-next-line
require(block.timestamp <= deadline, 'INVALID_EXPIRATION');
require(block.timestamp <= deadline, StaticATokenErrors.INVALID_EXPIRATION);
uint256 currentValidNonce = _nonces[depositor];
bytes32 digest =
keccak256(
@ -229,7 +231,7 @@ contract StaticATokenLM is ERC20 {
);
require(
depositor == ecrecover(digest, sigParams.v, sigParams.r, sigParams.s),
'INVALID_SIGNATURE'
StaticATokenErrors.INVALID_SIGNATURE
);
_nonces[depositor] = currentValidNonce.add(1);
_deposit(depositor, recipient, value, referralCode, fromUnderlying);
@ -261,9 +263,9 @@ contract StaticATokenLM is ERC20 {
SignatureParams calldata sigParams,
uint256 chainId
) external returns (uint256, uint256) {
require(owner != address(0), 'INVALID_OWNER');
require(owner != address(0), StaticATokenErrors.INVALID_OWNER);
//solium-disable-next-line
require(block.timestamp <= deadline, 'INVALID_EXPIRATION');
require(block.timestamp <= deadline, StaticATokenErrors.INVALID_EXPIRATION);
uint256 currentValidNonce = _nonces[owner];
bytes32 digest =
keccak256(
@ -285,7 +287,10 @@ contract StaticATokenLM is ERC20 {
)
);
require(owner == ecrecover(digest, sigParams.v, sigParams.r, sigParams.s), 'INVALID_SIGNATURE');
require(
owner == ecrecover(digest, sigParams.v, sigParams.r, sigParams.s),
StaticATokenErrors.INVALID_SIGNATURE
);
_nonces[owner] = currentValidNonce.add(1);
return _withdraw(owner, recipient, staticAmount, dynamicAmount, toUnderlying);
}
@ -361,7 +366,7 @@ contract StaticATokenLM is ERC20 {
uint16 referralCode,
bool fromUnderlying
) internal returns (uint256) {
require(recipient != address(0), 'INVALID_RECIPIENT');
require(recipient != address(0), StaticATokenErrors.INVALID_RECIPIENT);
_updateRewards();
if (fromUnderlying) {
@ -383,8 +388,11 @@ contract StaticATokenLM is ERC20 {
uint256 dynamicAmount,
bool toUnderlying
) internal returns (uint256, uint256) {
require(recipient != address(0), 'INVALID_RECIPIENT');
require(staticAmount == 0 || dynamicAmount == 0, 'ONLY_ONE_AMOUNT_FORMAT_ALLOWED');
require(recipient != address(0), StaticATokenErrors.INVALID_RECIPIENT);
require(
staticAmount == 0 || dynamicAmount == 0,
StaticATokenErrors.ONLY_ONE_AMOUNT_FORMAT_ALLOWED
);
_updateRewards();
uint256 userBalance = balanceOf(owner);

View File

@ -62,6 +62,15 @@ const TEST_USERS = [
'0x8BffC896D42F07776561A5814D6E4240950d6D3a',
];
const LM_ERRORS = {
INVALID_OWNER: '1',
INVALID_EXPIRATION: '2',
INVALID_SIGNATURE: '3',
INVALID_DEPOSITOR: '4',
INVALID_RECIPIENT: '5',
ONLY_ONE_AMOUNT_FORMAT_ALLOWED: '6',
};
type tBalancesInvolved = {
staticATokenATokenBalance: BigNumber;
staticATokenStkAaveBalance: BigNumber;
@ -195,7 +204,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
await expect(
staticAToken.deposit(ZERO_ADDRESS, amountToDeposit, 0, true, defaultTxParams)
).to.be.revertedWith('INVALID_RECIPIENT');
).to.be.revertedWith(LM_ERRORS.INVALID_RECIPIENT);
// Depositing
await waitForTx(
@ -206,7 +215,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
await expect(
staticAToken.withdraw(ZERO_ADDRESS, amountToWithdraw, true, defaultTxParams)
).to.be.revertedWith('INVALID_RECIPIENT');
).to.be.revertedWith(LM_ERRORS.INVALID_RECIPIENT);
// Withdrawing all
await waitForTx(
@ -530,7 +539,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
staticAToken
.connect(spender)
.permit(spender._address, spender._address, permitAmount, expiration, v, r, s, chainId)
).to.be.revertedWith('INVALID_SIGNATURE');
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
await waitForTx(
await staticAToken
@ -608,13 +617,13 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
staticAToken
.connect(spender)
.permit(ZERO_ADDRESS, spender._address, permitAmount, expiration, v, r, s, chainId)
).to.be.revertedWith('INVALID_OWNER');
).to.be.revertedWith(LM_ERRORS.INVALID_OWNER);
await expect(
staticAToken
.connect(spender)
.permit(owner._address, spender._address, permitAmount, expiration, v, r, s, chainId)
).to.be.revertedWith('INVALID_EXPIRATION');
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
expect((await staticAToken.allowance(owner._address, spender._address)).toString()).to.be.equal(
'0',
@ -691,7 +700,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
sigParams,
chainId
)
).to.be.revertedWith('INVALID_DEPOSITOR');
).to.be.revertedWith(LM_ERRORS.INVALID_DEPOSITOR);
await expect(
staticAToken
@ -706,7 +715,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
sigParams,
chainId
)
).to.be.revertedWith('INVALID_EXPIRATION');
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
await expect(
staticAToken
@ -721,7 +730,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
sigParams,
chainId
)
).to.be.revertedWith('INVALID_SIGNATURE');
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
// Deposit
await waitForTx(
@ -865,7 +874,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
sigParams,
chainId
)
).to.be.revertedWith('INVALID_OWNER');
).to.be.revertedWith(LM_ERRORS.INVALID_OWNER);
await expect(
staticAToken
@ -880,7 +889,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
sigParams,
chainId
)
).to.be.revertedWith('INVALID_EXPIRATION');
).to.be.revertedWith(LM_ERRORS.INVALID_EXPIRATION);
await expect(
staticAToken
@ -895,7 +904,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
sigParams,
chainId
)
).to.be.revertedWith('INVALID_SIGNATURE');
).to.be.revertedWith(LM_ERRORS.INVALID_SIGNATURE);
// Deposit
await waitForTx(
@ -997,7 +1006,7 @@ describe('StaticATokenLM: aToken wrapper with static balances and liquidity mini
sigParams,
chainId
)
).to.be.revertedWith('ONLY_ONE_AMOUNT_FORMAT_ALLOWED');
).to.be.revertedWith(LM_ERRORS.ONLY_ONE_AMOUNT_FORMAT_ALLOWED);
const ctxtAfterDeposit = await getContext(ctxtParams);
expect(ctxtInitial.userStaticATokenBalance).to.be.eq(ctxtAfterDeposit.userStaticATokenBalance);