Skip to content

Commit 56d8f40

Browse files
Pull copy/pasted nonce logic into virtual hook to allow flexibiltiy for explicit nonce-setting (#67)
1 parent 7bda417 commit 56d8f40

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

script/universal/MultisigBase.sol

+13-9
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,25 @@ abstract contract MultisigBase is Simulator {
1919
return keccak256(_encodeTransactionData(_safe, _data));
2020
}
2121

22-
function _encodeTransactionData(address _safe, bytes memory _data) internal view returns (bytes memory) {
23-
// Ensure that the required contracts exist
24-
require(address(multicall).code.length > 0, "multicall3 not deployed");
25-
require(_safe.code.length > 0, "no code at safe address");
26-
27-
IGnosisSafe safe = IGnosisSafe(payable(_safe));
28-
uint256 nonce = safe.nonce();
22+
// Virtual method which can be overwritten
23+
// Default logic here is vestigial for backwards compatibility
24+
function _getNonce(IGnosisSafe safe) internal view virtual returns (uint256 nonce) {
25+
nonce = safe.nonce();
2926
console.log("Safe current nonce:", nonce);
30-
31-
// workaround to check if the SAFE_NONCE env var is present
3227
try vm.envUint("SAFE_NONCE") {
3328
nonce = vm.envUint("SAFE_NONCE");
3429
console.log("Creating transaction with nonce:", nonce);
3530
}
3631
catch {}
32+
}
33+
34+
function _encodeTransactionData(address _safe, bytes memory _data) internal view returns (bytes memory) {
35+
// Ensure that the required contracts exist
36+
require(address(multicall).code.length > 0, "multicall3 not deployed");
37+
require(_safe.code.length > 0, "no code at safe address");
38+
39+
IGnosisSafe safe = IGnosisSafe(payable(_safe));
40+
uint256 nonce = _getNonce(safe);
3741

3842
return safe.encodeTransactionData({
3943
to: address(multicall),

script/universal/MultisigBuilder.sol

+2-20
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,7 @@ abstract contract MultisigBuilder is MultisigBase {
8080
function simulateSigned(bytes memory _signatures) public returns (bool) {
8181
address _safe = _ownerSafe();
8282
IGnosisSafe safe = IGnosisSafe(payable(_safe));
83-
84-
uint256 _nonce = safe.nonce();
85-
console.log("Safe current nonce:", _nonce);
86-
87-
// workaround to check if the SAFE_NONCE env var is present
88-
try vm.envUint("SAFE_NONCE") {
89-
_nonce = vm.envUint("SAFE_NONCE");
90-
console.log("Creating transaction with nonce:", _nonce);
91-
}
92-
catch {}
93-
83+
uint256 _nonce = _getNonce(safe);
9484
vm.store(_safe, bytes32(uint256(5)), bytes32(uint256(_nonce)));
9585
bool success = _executeTransaction(_safe, _buildCalls(), _signatures);
9686
if (success) _postCheck();
@@ -150,15 +140,7 @@ abstract contract MultisigBuilder is MultisigBase {
150140
// default logic is vestigial for backwards compatibility.
151141
function _addOverrides(address _safe) internal virtual view returns (SimulationStateOverride memory) {
152142
IGnosisSafe safe = IGnosisSafe(payable(_safe));
153-
uint256 _nonce = safe.nonce();
154-
console.log("Safe current nonce:", _nonce);
155-
156-
// workaround to check if the SAFE_NONCE env var is present
157-
try vm.envUint("SAFE_NONCE") {
158-
_nonce = vm.envUint("SAFE_NONCE");
159-
console.log("Creating transaction with nonce:", _nonce);
160-
}
161-
catch {}
143+
uint256 _nonce = _getNonce(safe);
162144
return overrideSafeThresholdAndNonce(_safe, _nonce);
163145
}
164146
}

0 commit comments

Comments
 (0)