Skip to content

Commit

Permalink
fix: rename _checkToken -> _getMaskOrRevert
Browse files Browse the repository at this point in the history
  • Loading branch information
lekhovitsky committed Mar 19, 2023
1 parent a01083f commit 2576b6b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
9 changes: 5 additions & 4 deletions contracts/adapters/AbstractAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ abstract contract AbstractAdapter is IAdapter, ACLNonReentrantTrait {
return creditManager.getCreditAccountOrRevert(_creditFacade()); // F: [AA-4]
}

/// @dev Checks if token is registered as collateral token in the Credit Manager
/// @param token Token to check
/// @dev Returns collateral token mask of given token in the Credit Manager
/// @param token Token to get the mask for
/// @return tokenMask Collateral token mask
function _checkToken(address token) internal view returns (uint256 tokenMask) {
/// @dev Reverts if token is not registered as collateral token in the Credit Manager
function _getMaskOrRevert(address token) internal view returns (uint256 tokenMask) {
tokenMask = creditManager.tokenMasksMap(token); // F: [AA-6]
if (tokenMask == 0) {
revert TokenIsNotInAllowedList(token); // F: [AA-6]
Expand Down Expand Up @@ -120,7 +121,7 @@ abstract contract AbstractAdapter is IAdapter, ACLNonReentrantTrait {
internal
returns (bytes memory result)
{
_checkToken(tokenIn); // F: [AA-15]
_getMaskOrRevert(tokenIn); // F: [AA-15]
result = _executeSwap(tokenIn, tokenOut, callData, disableTokenIn); // F: [AA-7, AA-13]
}

Expand Down
4 changes: 1 addition & 3 deletions contracts/adapters/UniversalAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ contract UniversalAdapter is AbstractAdapter, IUniversalAdapter {
// /// @param to Token recipient
// /// @param amount Amount to withdraw
// function withdrawTo(address token, address to, uint256 amount) external creditFacadeOnly {
// if (creditManager.tokenMasksMap(token) == 0) {
// revert("Token is not allowed");
// }
// _getMaskOrRevert(token);
// creditManager.executeOrder(token, abi.encodeCall(IERC20.transfer, (to, amount)));
// }
}
8 changes: 4 additions & 4 deletions contracts/test/adapters/AbstractAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ contract AbstractAdapterTest is
adapterMock.execute(DUMB_CALLDATA);
}

/// @dev [AA-6]: AbstractAdapter _checkToken works correctly
function test_AA_06_checkToken_works_correctly() public {
/// @dev [AA-6]: AbstractAdapter _getMaskOrRevert works correctly
function test_AA_06_getMaskOrRevert_works_correctly() public {
assertEq(
adapterMock.checkToken(tokenTestSuite.addressOf(Tokens.DAI)),
adapterMock.getMaskOrRevert(tokenTestSuite.addressOf(Tokens.DAI)),
creditManager.tokenMasksMap(tokenTestSuite.addressOf(Tokens.DAI))
);

address token = address(0xdead);
evm.expectRevert(abi.encodeWithSelector(IAdapterExceptions.TokenIsNotInAllowedList.selector, token));
adapterMock.checkToken(address(0xdead));
adapterMock.getMaskOrRevert(address(0xdead));
}

/// @dev [AA-7]: AbstractAdapter functions revert if user has no credit account
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/mocks/adapters/AdapterMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ contract AdapterMock is AbstractAdapter {
return _creditAccount();
}

function checkToken(address token) external view returns (uint256 tokenMask) {
return _checkToken(token);
function getMaskOrRevert(address token) external view returns (uint256 tokenMask) {
return _getMaskOrRevert(token);
}

function approveToken(address token, uint256 amount) external creditFacadeOnly {
Expand Down

0 comments on commit 2576b6b

Please sign in to comment.