Skip to content

Commit

Permalink
Making inheritance chain more compact
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Oct 3, 2023
1 parent 8932de8 commit fbbf0f4
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 193 deletions.
184 changes: 0 additions & 184 deletions contracts/core/BaseModifier.sol

This file was deleted.

87 changes: 83 additions & 4 deletions contracts/core/GuardableModifier.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,87 @@
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity >=0.7.0 <0.9.0;

import "./BaseModifier.sol";
import "./GuardableModule.sol";
import "../guard/Guardable.sol";
import "./Modifier.sol";

abstract contract GuardableModifier is Module, Guardable, Modifier {
/// @dev Passes a transaction to be executed by the avatar.
/// @notice Can only be called by this contract.
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction: 0 == call, 1 == delegate call.
function exec(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation
) internal override returns (bool success) {
address currentGuard = guard;
if (currentGuard != address(0)) {
IGuard(currentGuard).checkTransaction(
/// Transaction info used by module transactions.
to,
value,
data,
operation,
/// Zero out the redundant transaction information only used for Safe multisig transctions.
0,
0,
0,
address(0),
payable(0),
"",
msg.sender
);
}
success = IAvatar(target).execTransactionFromModule(
to,
value,
data,
operation
);
if (currentGuard != address(0)) {
IGuard(currentGuard).checkAfterExecution("", success);
}
}

/// @dev Passes a transaction to be executed by the target and returns data.
/// @notice Can only be called by this contract.
/// @param to Destination address of module transaction.
/// @param value Ether value of module transaction.
/// @param data Data payload of module transaction.
/// @param operation Operation type of module transaction: 0 == call, 1 == delegate call.
function execAndReturnData(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation
) internal override returns (bool success, bytes memory returnData) {
address currentGuard = guard;
if (currentGuard != address(0)) {
IGuard(currentGuard).checkTransaction(
/// Transaction info used by module transactions.
to,
value,
data,
operation,
/// Zero out the redundant transaction information only used for Safe multisig transctions.
0,
0,
0,
address(0),
payable(0),
"",
msg.sender
);
}

(success, returnData) = IAvatar(target)
.execTransactionFromModuleReturnData(to, value, data, operation);

abstract contract GuardableModifier is GuardableModule, BaseModifier {}
if (currentGuard != address(0)) {
IGuard(currentGuard).checkAfterExecution("", success);
}
}
}
3 changes: 1 addition & 2 deletions contracts/core/GuardableModule.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only

/// @title Module Interface - A contract that can pass messages to a Module Manager contract if enabled by that contract.
pragma solidity >=0.7.0 <0.9.0;

import "../guard/Guardable.sol";
import "./Module.sol";

/// @title GuardableModule - A contract that can pass messages to a Module Manager contract if enabled by that contract.
abstract contract GuardableModule is Module, Guardable {
/// @dev Passes a transaction to be executed by the avatar.
/// @notice Can only be called by this contract.
Expand Down
Loading

0 comments on commit fbbf0f4

Please sign in to comment.