-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,48 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.12; | ||
|
||
import {ZeusScript} from "../utils/ZeusScript.sol"; | ||
import "../utils/ZeusScript.sol"; | ||
|
||
/** | ||
* @title MultisigBuilder | ||
* @dev Abstract contract for building arbitrary multisig scripts. | ||
*/ | ||
abstract contract MultisigBuilder is ZeusScript { | ||
|
||
bool private hasPranked; | ||
|
||
modifier prank(address caller) { | ||
_startPrank(caller); | ||
_; | ||
_stopPrank(); | ||
} | ||
|
||
/** | ||
* @notice Constructs a SafeTx object for a Gnosis Safe to ingest. Emits via `ZeusMultisigExecute` | ||
*/ | ||
function execute() public { | ||
MultisigOptions memory opt = options(); | ||
emit ZeusRequireMultisig(opt.addr, opt.callType); | ||
vm.startPrank(opt.addr, opt.addr); | ||
runAsMultisig(); | ||
vm.stopPrank(); | ||
_runAsMultisig(); | ||
require(hasPranked, "MultisigBuilder.execute: did not use prank helpers"); | ||
} | ||
|
||
/** | ||
* Indicate the multisig address | ||
* @dev Implement the most high-level call performed by the target multisig for this script. | ||
* Note: This function should be written as if the target multisig is performing the call directly. | ||
* Note: This function MUST be written by using the `prank` modifier or `_startPrank`/`_stopPrank` | ||
* helper methods. | ||
*/ | ||
function options() internal virtual returns (MultisigOptions memory); | ||
function _runAsMultisig() internal virtual; | ||
|
||
/** | ||
* @notice To be implemented by inheriting contract. | ||
* | ||
* This function will be pranked from the perspective of the multisig you choose to run with. | ||
* DO NOT USE vm.startPrank()/stopPrank() during your implementation. | ||
*/ | ||
function runAsMultisig() internal virtual; | ||
function _startPrank(address caller) internal { | ||
require(!hasPranked, "MultisigBuilder._startPrank: called twice in txn"); | ||
hasPranked = true; | ||
|
||
emit ZeusRequireMultisig(caller, Encode.Operation.Call); | ||
vm.startPrank(caller); | ||
} | ||
|
||
function _stopPrank() internal { | ||
require(hasPranked, "MultisigBuilder._stopPrank: _startPrank not called"); | ||
vm.stopPrank(); | ||
} | ||
} |
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
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