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

View File

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