-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathMigration.sol
105 lines (89 loc) · 3.29 KB
/
Migration.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// SPDX-License-Identifier: MIT
pragma solidity 0.8.21;
import {Guardians} from "../abstract/Guardians.sol";
import {IMigration} from "../interfaces/abstract/IMigration.sol";
abstract contract Migration is IMigration, Guardians {
/*//////////////////////////////////////////////////////////////
IMMUTABLES
//////////////////////////////////////////////////////////////*/
/**
* @inheritdoc IMigration
*/
uint24 public immutable gracePeriod;
/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
/**
* @inheritdoc IMigration
*/
address public migrator;
/**
* @inheritdoc IMigration
*/
uint40 public migratedAt;
/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/
/**
* @notice Allow only the migrator to call the protected function.
* Revoke permissions after the migration period.
*/
modifier onlyMigrator() {
if (msg.sender != migrator) revert OnlyMigrator();
if (isMigrated() && block.timestamp > migratedAt + gracePeriod) {
revert PermissionRevoked();
}
_requirePaused();
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/**
* @notice Set the grace period and migrator address.
* Pauses contract at deployment time.
*
* @param _gracePeriod Migration grace period in seconds.
* @param _initialOwner Initial owner address. Set as migrator.
*/
constructor(uint24 _gracePeriod, address _migrator, address _initialOwner) Guardians(_initialOwner) {
gracePeriod = _gracePeriod;
migrator = _migrator;
emit SetMigrator(address(0), _migrator);
_pause();
}
/*//////////////////////////////////////////////////////////////
VIEWS
//////////////////////////////////////////////////////////////*/
/**
* @inheritdoc IMigration
*/
function isMigrated() public view returns (bool) {
return migratedAt != 0;
}
/*//////////////////////////////////////////////////////////////
MIGRATION
//////////////////////////////////////////////////////////////*/
/**
* @inheritdoc IMigration
*/
function migrate() external {
if (msg.sender != migrator) revert OnlyMigrator();
if (isMigrated()) revert AlreadyMigrated();
_requirePaused();
migratedAt = uint40(block.timestamp);
emit Migrated(migratedAt);
}
/*//////////////////////////////////////////////////////////////
SET MIGRATOR
//////////////////////////////////////////////////////////////*/
/**
* @inheritdoc IMigration
*/
function setMigrator(address _migrator) public onlyOwner {
if (isMigrated()) revert AlreadyMigrated();
_requirePaused();
emit SetMigrator(migrator, _migrator);
migrator = _migrator;
}
}