Skip to content

Commit

Permalink
fix OwnerModule compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
mjlescano committed Aug 16, 2023
1 parent 7c92934 commit f46162e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
60 changes: 50 additions & 10 deletions protocol/governance/contracts/modules/core/OwnerModule.sol
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.11 <0.9.0;

import {AccessError} from "@synthetixio/core-contracts/contracts/errors/AccessError.sol";
import {AddressError} from "@synthetixio/core-contracts/contracts/errors/AddressError.sol";
import {ChangeError} from "@synthetixio/core-contracts/contracts/errors/ChangeError.sol";
import {SafeCastU256} from "@synthetixio/core-contracts/contracts/utils/SafeCast.sol";
import {OwnerModule as BaseOwnerModule} from "@synthetixio/core-modules/contracts/modules/OwnerModule.sol";
import {IOwnable} from "@synthetixio/core-contracts/contracts/interfaces/IOwnable.sol";
import {OwnableStorage} from "@synthetixio/core-contracts/contracts/ownership/OwnableStorage.sol";
import {Guardian} from "../../storage/Guardian.sol";

contract OwnerModule is BaseOwnerModule {
contract OwnerModule is IOwnable {
using SafeCastU256 for uint256;

/**
* @notice Thrown when an the ownership is accepted before the nomination delay
*/
error OwnershipAcceptanceTooEarly();

/**
* @notice Accept ownership nomination an become the new owner, checks that nomination window have passed.
*/
function acceptOwnership() public override {
super.acceptOwnership();
OwnableStorage.Data storage ownableStore = OwnableStorage.load();
Guardian.Data storage guardianStore = Guardian.load();

Guardian.Data storage store = Guardian.load();
address currentNominatedOwner = ownableStore.nominatedOwner;
if (msg.sender != currentNominatedOwner) {
revert NotNominated(msg.sender);
}

if (block.timestamp.to64() - store.ownershipRequestedAt < Guardian.RESCUE_DELAY) {
if (
block.timestamp.to64() - guardianStore.ownershipRequestedAt <
Guardian.ACCEPT_OWNERSHIP_DELAY
) {
revert OwnershipAcceptanceTooEarly();
}

store.ownershipRequestedAt = 0;
emit OwnerChanged(ownableStore.owner, currentNominatedOwner);

ownableStore.owner = currentNominatedOwner;
ownableStore.nominatedOwner = address(0);
guardianStore.ownershipRequestedAt = 0;
}

/**
* @notice Allows the current guardian to nominate a new owner.
* @dev The nominated owner will have to call `acceptOwnership` in a separate transaction in order to finalize the action and become the new contract owner.
* @param newNominatedOwner The address that is to become nominated.
*/
function nominateNewOwner(address newNominatedOwner) public override {
Guardian.onlyGuardian();

Expand All @@ -52,10 +70,32 @@ contract OwnerModule is BaseOwnerModule {
emit OwnerNominated(newNominatedOwner);
}

/**
* @inheritdoc IOwnable
*/
function renounceNomination() external override {
super.renounceNomination();
OwnableStorage.Data storage ownableStore = OwnableStorage.load();
Guardian.Data storage guardianStore = Guardian.load();

if (ownableStore.nominatedOwner != msg.sender) {
revert NotNominated(msg.sender);
}

ownableStore.nominatedOwner = address(0);
guardianStore.ownershipRequestedAt = 0;
}

Guardian.Data storage store = Guardian.load();
store.ownershipRequestedAt = 0;
/**
* @inheritdoc IOwnable
*/
function owner() external view override returns (address) {
return OwnableStorage.load().owner;
}

/**
* @inheritdoc IOwnable
*/
function nominatedOwner() external view override returns (address) {
return OwnableStorage.load().nominatedOwner;
}
}
2 changes: 1 addition & 1 deletion protocol/governance/contracts/storage/Guardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ library Guardian {
bytes32 private constant _STORAGE_SLOT =
keccak256(abi.encode("io.synthetix.governance.Guardian"));

uint64 public constant RESCUE_DELAY = 7 days;
uint64 public constant ACCEPT_OWNERSHIP_DELAY = 7 days;

struct Data {
address guardian;
Expand Down
17 changes: 17 additions & 0 deletions protocol/governance/storage.dump.sol
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ library Epoch {
}
}

// @custom:artifact contracts/storage/Guardian.sol:Guardian
library Guardian {
bytes32 private constant _STORAGE_SLOT = keccak256(abi.encode("io.synthetix.governance.Guardian"));
uint64 public constant ACCEPT_OWNERSHIP_DELAY = 7;
struct Data {
address guardian;
address nominatedGuardian;
uint64 ownershipRequestedAt;
}
function load() internal pure returns (Data storage store) {
bytes32 s = _STORAGE_SLOT;
assembly {
store.slot := s
}
}
}

// @custom:artifact contracts/storage/SnapshotVotePower.sol:SnapshotVotePower
library SnapshotVotePower {
struct Data {
Expand Down

0 comments on commit f46162e

Please sign in to comment.