Skip to content

Instantly share code, notes, and snippets.

@auryn-macmillan
Last active December 30, 2023 22:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auryn-macmillan/105ae8f09c34406997d217ee4dc0f63a to your computer and use it in GitHub Desktop.
Save auryn-macmillan/105ae8f09c34406997d217ee4dc0f63a to your computer and use it in GitHub Desktop.
Zodiac Tutorial: Build your own module
pragma solidity ^0.8.6;
import "@openzeppelin/contracts/access/Ownable.sol";
contract Button is Ownable {
event ButtonPushed(address pusher, uint256 pushes);
uint256 public pushes;
function pushButton() public onlyOwner {
pushes++;
emit ButtonPushed(msg.sender, pushes);
}
}
// 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);
}
}
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