Skip to content

Commit

Permalink
Merge pull request #48 from Gearbox-protocol/fix-aa-pause
Browse files Browse the repository at this point in the history
fix: abstract adapter no longer inherits acl trait
  • Loading branch information
0xmikko authored Apr 10, 2023
2 parents 473f41c + f8148f2 commit bbfb9e2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
29 changes: 17 additions & 12 deletions contracts/adapters/AbstractAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { ACLTrait } from "../core/ACLTrait.sol";
import { IACL } from "../interfaces/IACL.sol";
import { IAdapter } from "../interfaces/adapters/IAdapter.sol";
import { IAddressProvider } from "../interfaces/IAddressProvider.sol";
import { ICreditManagerV2 } from "../interfaces/ICreditManagerV2.sol";
Expand All @@ -12,7 +12,7 @@ import { ZeroAddressException } from "../interfaces/IErrors.sol";

/// @title Abstract adapter
/// @dev Inheriting adapters MUST use provided internal functions to perform all operations with credit accounts
abstract contract AbstractAdapter is IAdapter, ACLTrait {
abstract contract AbstractAdapter is IAdapter {
/// @notice Credit Manager the adapter is connected to
ICreditManagerV2 public immutable override creditManager;

Expand All @@ -22,18 +22,14 @@ abstract contract AbstractAdapter is IAdapter, ACLTrait {
/// @notice Address of the contract the adapter is interacting with
address public immutable override targetContract;

/// @notice ACL contract to check rights
IACL public immutable override _acl;

/// @notice Constructor
/// @param _creditManager Credit Manager to connect this adapter to
/// @param _targetContract Address of the contract this adapter should interact with
constructor(address _creditManager, address _targetContract)
ACLTrait(
address(
IPoolService(ICreditManagerV2(_creditManager).pool())
.addressProvider()
)
)
{
if (_targetContract == address(0)) {
constructor(address _creditManager, address _targetContract) {
if (_creditManager == address(0) || _targetContract == address(0)) {
revert ZeroAddressException(); // F: [AA-2]
}

Expand All @@ -42,9 +38,18 @@ abstract contract AbstractAdapter is IAdapter, ACLTrait {
IPoolService(creditManager.pool()).addressProvider()
); // F: [AA-1]
targetContract = _targetContract; // F: [AA-1]

_acl = IACL(addressProvider.getACL()); // F: [AA-1]
}

/// @notice Reverts if caller of the function is not configurator
modifier configuratorOnly() {
if (!_acl.isConfigurator(msg.sender))
revert CallerNotConfiguratorException(); // F: [AA-16]
_;
}

/// @dev Reverts if the caller of the function is not the Credit Facade
/// @notice Reverts if caller of the function is not the Credit Facade
/// @dev Adapter functions are only allowed to be called from within the multicall
/// Since at this point Credit Account is owned by the Credit Facade, all functions
/// of inheriting adapters that perform actions on account MUST have this modifier
Expand Down
7 changes: 7 additions & 0 deletions contracts/interfaces/adapters/IAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// (c) Gearbox Holdings, 2022
pragma solidity ^0.8.10;

import { IACL } from "../IACL.sol";
import { IAddressProvider } from "../IAddressProvider.sol";
import { ICreditManagerV2 } from "../ICreditManagerV2.sol";

Expand Down Expand Up @@ -38,6 +39,9 @@ interface IAdapterExceptions {

/// @notice Thrown when caller of a `creditFacadeOnly` function is not the Credit Facade
error CreditFacadeOnlyException();

/// @notice Thrown when caller of a `configuratorOnly` function is not configurator
error CallerNotConfiguratorException();
}

interface IAdapter is IAdapterExceptions {
Expand All @@ -50,6 +54,9 @@ interface IAdapter is IAdapterExceptions {
/// @notice Address provider
function addressProvider() external view returns (IAddressProvider);

/// @notice ACL contract to check rights
function _acl() external view returns (IACL);

/// @notice Adapter type
function _gearboxAdapterType() external pure returns (AdapterType);

Expand Down
28 changes: 25 additions & 3 deletions contracts/test/adapters/AbstractAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ contract AbstractAdapterTest is

/// @dev [AA-1]: AbstractAdapter constructor sets correct values
function test_AA_01_constructor_sets_correct_values() public {
IAddressProvider addressProvider = IPoolService(creditManager.pool())
.addressProvider();

assertEq(
address(adapterMock.creditManager()),
address(creditManager),
Expand All @@ -111,7 +114,7 @@ contract AbstractAdapterTest is

assertEq(
address(adapterMock.addressProvider()),
address(IPoolService(creditManager.pool()).addressProvider()),
address(addressProvider),
"Incorrect address provider"
);

Expand All @@ -120,11 +123,17 @@ contract AbstractAdapterTest is
address(targetMock),
"Incorrect target contract"
);

assertEq(
address(adapterMock._acl()),
addressProvider.getACL(),
"Incorrect ACL"
);
}

/// @dev [AA-2]: AbstractAdapter constructor reverts when passed zero-address as target contract
function test_AA_02_constructor_reverts_on_zero_address() public {
evm.expectRevert();
evm.expectRevert(ZeroAddressException.selector);
new AdapterMock(address(0), address(0));

evm.expectRevert(ZeroAddressException.selector);
Expand Down Expand Up @@ -665,7 +674,9 @@ contract AbstractAdapterTest is
}

evm.prank(USER);
evm.expectRevert(TokenNotAllowedException.selector);
evm.expectRevert(
IAdapterExceptions.TokenNotAllowedException.selector
);
creditFacade.multicall(
multicallBuilder(
MultiCall({
Expand All @@ -677,4 +688,15 @@ contract AbstractAdapterTest is
}
}
}

/// @dev [AA-16]: `configuratorOnly` function reverts if called not by configurator
function test_AA_16_configuratorOnly_function_reverts_if_called_not_by_configurator()
public
{
evm.expectRevert(
IAdapterExceptions.CallerNotConfiguratorException.selector
);
evm.prank(USER);
adapterMock.configure();
}
}
2 changes: 2 additions & 0 deletions contracts/test/mocks/adapters/AdapterMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ contract AdapterMock is AbstractAdapter {
AbstractAdapter(_creditManager, _targetContract)
{}

function configure() external view configuratorOnly {}

function creditFacade() external view returns (address) {
return _creditFacade();
}
Expand Down

0 comments on commit bbfb9e2

Please sign in to comment.