generated from NomicFoundation/hardhat-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 9
/
SafeMigration.sol
46 lines (38 loc) · 1.37 KB
/
SafeMigration.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//SPDX-License-Identifier: LGPL-3.0
pragma solidity ^0.8.12;
import "../interfaces/SafeStorage.sol";
/**
* Migrates a Safe proxy instance to a ZodiacMech
*/
contract SafeMigration is SafeStorage {
address internal constant SENTINEL_MODULES = address(0x1);
address public immutable migrationSingleton;
address public immutable zodiacMechMastercopy;
constructor(address _zodiacMechMastercopy) {
// Singleton address cannot be zero address.
require(
_zodiacMechMastercopy != address(0),
"Invalid mastercopy address provided"
);
zodiacMechMastercopy = _zodiacMechMastercopy;
migrationSingleton = address(this);
}
event ChangedMasterCopy(address singleton);
/**
* @notice Migrates the Safe to the Singleton contract at `migrationSingleton`.
* @dev This can only be called via a delegatecall.
*/
function migrate() public {
require(
address(this) != migrationSingleton,
"Migration should only be called via delegatecall"
);
// Check that the Safe has at least one module enabled so it won't be bricked after the migration
require(
modules[address(SENTINEL_MODULES)] != address(0),
"No modules enabled"
);
singleton = zodiacMechMastercopy;
emit ChangedMasterCopy(singleton);
}
}