Skip to content

Commit

Permalink
Temp: User local variable safeAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-ap committed Jul 4, 2023
1 parent 7172d5d commit 6a0c4ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
29 changes: 16 additions & 13 deletions contracts/SafeProtocolMediator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,21 @@ contract SafeProtocolMediator is ISafeProtocolMediator {
/**
* @notice This function executes non-delegate call(s) on a safe if the module is enabled on the Safe.
* If any one of the actions fail, the transaction reverts.
* @param safe Address of the Safe instance
* @param safe A Safe instance
* @param transaction A struct of type SafeTransaction containing information of about the action(s) to be executed.
* Users can add logic to validate metahash through a transaction guard.
* @return data bytes types containing the result of the executed action.
*/
function executeTransaction(
address safe,
ISafe safe,
SafeTransaction calldata transaction
) external override onlyEnabledModule(safe) returns (bytes[] memory data) {
) external override onlyEnabledModule(address(safe)) returns (bytes[] memory data) {
address safeAddress = address(safe);
data = new bytes[](transaction.actions.length);
uint256 length = transaction.actions.length;
for (uint256 i = 0; i < length; ++i) {
SafeProtocolAction calldata safeProtocolAction = transaction.actions[i];
(bool isActionSuccessful, bytes memory resultData) = ISafe(safe).execTransactionFromModuleReturnData(
(bool isActionSuccessful, bytes memory resultData) = safe.execTransactionFromModuleReturnData(
safeProtocolAction.to,
safeProtocolAction.value,
safeProtocolAction.data,
Expand All @@ -80,44 +81,46 @@ contract SafeProtocolMediator is ISafeProtocolMediator {

// Even if one action fails, revert the transaction.
if (!isActionSuccessful) {
revert ActionExecutionFailed(safe, transaction.metaHash, i);
revert ActionExecutionFailed(safeAddress, transaction.metaHash, i);
} else {
data[i] = resultData;
}
}

emit ActionsExecuted(safe, transaction.metaHash, transaction.nonce);
emit ActionsExecuted(safeAddress, transaction.metaHash, transaction.nonce);
}

/**
* @notice This function executes a delegate call on a safe if the module is enabled and
* root access it granted.
* @param safe Address of the Safe instance
* @param safe A Safe instance
* @param rootAccess A struct of type SafeRootAccess containing information of about the action to be executed.
* Users can add logic to validate metahash through a transaction guard.
* @return data bytes types containing the result of the executed action.
*/
function executeRootAccess(
address safe,
ISafe safe,
SafeRootAccess calldata rootAccess
) external override onlyEnabledModule(safe) returns (bytes memory data) {
) external override onlyEnabledModule(address(safe)) returns (bytes memory data) {
address safeAddress = address(safe);

SafeProtocolAction calldata safeProtocolAction = rootAccess.action;

if (!ISafeProtocolModule(msg.sender).requiresRootAccess() || !enabledModules[safe][msg.sender].rootAddressGranted) {
if (!ISafeProtocolModule(msg.sender).requiresRootAccess() || !enabledModules[safeAddress][msg.sender].rootAddressGranted) {
revert ModuleRequiresRootAccess(msg.sender);
}

bool success;
(success, data) = ISafe(safe).execTransactionFromModuleReturnData(
(success, data) = safe.execTransactionFromModuleReturnData(
safeProtocolAction.to,
safeProtocolAction.value,
safeProtocolAction.data,
1
);
if (success) {
emit RootAccessActionExecuted(safe, rootAccess.metaHash);
emit RootAccessActionExecuted(safeAddress, rootAccess.metaHash);
} else {
revert RootAccessActionExecutionFailed(safe, rootAccess.metaHash);
revert RootAccessActionExecutionFailed(safeAddress, rootAccess.metaHash);
}
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/Mediator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ISafeProtocolMediator {
* @return data Array of bytes types returned upon the successful execution of all the actions. The size of the array will be the same as the size of the actions
* in case of succcessful execution. Empty if the call failed.
*/
function executeTransaction(address safe, SafeTransaction calldata transaction) external returns (bytes[] memory data);
function executeTransaction(ISafe safe, SafeTransaction calldata transaction) external returns (bytes[] memory data);

/**
* @notice This function allows enabled modules to execute delegate call transactions thorugh a Safe.
Expand All @@ -28,5 +28,5 @@ interface ISafeProtocolMediator {
* @return data Arbitrary length bytes data returned upon the successful execution. The size of the array will be the same as the size of the actions
* in case of succcessful execution. Empty if the call failed.
*/
function executeRootAccess(address safe, SafeRootAccess calldata rootAccess) external returns (bytes memory data);
function executeRootAccess(ISafe safe, SafeRootAccess calldata rootAccess) external returns (bytes memory data);
}
4 changes: 2 additions & 2 deletions contracts/test/TestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract TestModule is BaseTestModule {
ISafe safe,
SafeTransaction calldata safetx
) external returns (bytes[] memory data) {
(data) = mediator.executeTransaction(address(safe), safetx);
(data) = mediator.executeTransaction(safe, safetx);
}
}

Expand All @@ -38,6 +38,6 @@ contract TestModuleWithRootAccess is BaseTestModule {
ISafe safe,
SafeRootAccess calldata safeRootAccesstx
) external returns (bytes memory data) {
(data) = mediator.executeRootAccess(address(safe), safeRootAccesstx);
(data) = mediator.executeRootAccess(safe, safeRootAccesstx);
}
}

0 comments on commit 6a0c4ba

Please sign in to comment.