Last active
December 30, 2023 22:27
-
-
Save auryn-macmillan/105ae8f09c34406997d217ee4dc0f63a to your computer and use it in GitHub Desktop.
Zodiac Tutorial: Build your own module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: LGPL-3.0-only | |
pragma solidity >=0.8.0; | |
contract MockSafe { | |
address public module; | |
error NotAuthorized(address unacceptedAddress); | |
receive() external payable {} | |
function enableModule(address _module) external { | |
module = _module; | |
} | |
function exec( | |
address payable to, | |
uint256 value, | |
bytes calldata data | |
) external { | |
bool success; | |
bytes memory response; | |
(success, response) = to.call{value: value}(data); | |
if (!success) { | |
assembly { | |
revert(add(response, 0x20), mload(response)) | |
} | |
} | |
} | |
function execTransactionFromModule( | |
address payable to, | |
uint256 value, | |
bytes calldata data, | |
uint8 operation | |
) external returns (bool success) { | |
if (msg.sender != module) revert NotAuthorized(msg.sender); | |
if (operation == 1) (success, ) = to.delegatecall(data); | |
else (success, ) = to.call{value: value}(data); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.6; | |
import "@gnosis.pm/zodiac/contracts/core/Module.sol"; | |
contract MyModule is Module { | |
/// insert your code here | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment