This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First steps * Implemented timeLock * Add param to Core * Complete coreTimeLock upgrade specs * Add timelock modifiers * Update compile error * Add core internal to mock * Remove from internal * Finish rebase * Add timelock upgrade to module * Move TimeLock to its own library and state
- Loading branch information
1 parent
15af3fd
commit 87c594c
Showing
8 changed files
with
398 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
Copyright 2018 Set Labs Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity 0.4.25; | ||
|
||
import { Ownable } from "openzeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol"; | ||
|
||
|
||
/** | ||
* @title TimeLock Upgrade | ||
* @author Set Protocol | ||
* | ||
* The TimeLockUpgrade contract contains a modifier for handling minimum time period updates | ||
*/ | ||
contract TimeLockUpgrade is | ||
Ownable | ||
{ | ||
using SafeMath for uint256; | ||
|
||
/* ============ State Variables ============ */ | ||
|
||
// Timelock Upgrade Period in seconds | ||
uint256 public timeLockPeriod; | ||
|
||
// Mapping of upgradable units and initialized timelock | ||
mapping(bytes32 => uint256) public timeLockedUpgrades; | ||
|
||
/* ============ Events ============ */ | ||
|
||
event UpgradeRegistered( | ||
bytes32 _upgradeHash, | ||
uint256 _timestamp | ||
); | ||
|
||
/* ============ Modifiers ============ */ | ||
|
||
modifier timeLockUpgrade() { | ||
// If the time lock period is 0, then allow non-timebound upgrades. | ||
// This is useful for initialization of the protocol and for testing. | ||
if (timeLockPeriod == 0) { | ||
_; | ||
|
||
return; | ||
} | ||
|
||
// The upgrade hash is defined by the hash of the transaction call data, | ||
// which uniquely identifies the function as well as the passed in arguments. | ||
bytes32 upgradeHash = keccak256( | ||
abi.encodePacked( | ||
msg.data | ||
) | ||
); | ||
|
||
uint256 registrationTime = timeLockedUpgrades[upgradeHash]; | ||
|
||
// If the upgrade hasn't been registered, register with the current time. | ||
if (registrationTime == 0) { | ||
timeLockedUpgrades[upgradeHash] = block.timestamp; | ||
|
||
emit UpgradeRegistered( | ||
upgradeHash, | ||
block.timestamp | ||
); | ||
|
||
return; | ||
} | ||
|
||
require( | ||
block.timestamp >= registrationTime.add(timeLockPeriod), | ||
"TimeLockUpgrade.timeLockUpgrade: Upgrade requires time lock period to have elapsed." | ||
); | ||
|
||
// Reset the timestamp to 0 | ||
timeLockedUpgrades[upgradeHash] = 0; | ||
|
||
// Run the rest of the upgrades | ||
_; | ||
} | ||
|
||
/* ============ Function ============ */ | ||
|
||
/** | ||
* Change timeLockPeriod period. Generally called after initially settings have been set up. | ||
* | ||
* @param _timeLockPeriod Time in seconds that upgrades need to be evaluated before execution | ||
*/ | ||
function setTimeLockPeriod( | ||
uint256 _timeLockPeriod | ||
) | ||
external | ||
onlyOwner | ||
{ | ||
// Only allow setting of the timeLockPeriod the first time | ||
if (timeLockPeriod == 0) { | ||
timeLockPeriod = _timeLockPeriod; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
pragma solidity 0.4.25; | ||
pragma experimental "ABIEncoderV2"; | ||
|
||
import { TimeLockUpgrade } from "../../lib/TimeLockUpgrade.sol"; | ||
|
||
// Mock contract implementation of TimeLockUpgrade functions | ||
contract TimeLockUpgradeMock is | ||
TimeLockUpgrade | ||
{ | ||
uint256 public testUint; | ||
|
||
function testTimeLockUpgrade( | ||
uint256 _testUint | ||
) | ||
public | ||
timeLockUpgrade | ||
{ | ||
testUint = _testUint; | ||
} | ||
} | ||
|
Oops, something went wrong.