From cd17f1c5acf69c8d4aec08b7264503b97dc346db Mon Sep 17 00:00:00 2001 From: mingda Date: Fri, 24 Jul 2020 01:55:09 +0800 Subject: [PATCH] remove constructor because using proxy mode clone --- contracts/dodo.sol | 6 +++- contracts/impl/Storage.sol | 4 +-- contracts/lib/InitializableOwnable.sol | 48 ++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 contracts/lib/InitializableOwnable.sol diff --git a/contracts/dodo.sol b/contracts/dodo.sol index f902034..5313063 100644 --- a/contracts/dodo.sol +++ b/contracts/dodo.sol @@ -33,10 +33,14 @@ contract DODO is Admin, Trader, LiquidityProvider { uint256 mtFeeRate, uint256 k, uint256 gasPriceLimit - ) external onlyOwner preventReentrant { + ) external { require(!_INITIALIZED_, "DODO_INITIALIZED"); _INITIALIZED_ = true; + // constructor + _OWNER_ = msg.sender; + emit OwnershipTransferred(address(0), _OWNER_); + _SUPERVISOR_ = supervisor; _MAINTAINER_ = maintainer; _BASE_TOKEN_ = baseToken; diff --git a/contracts/impl/Storage.sol b/contracts/impl/Storage.sol index 63f8d1d..3135772 100644 --- a/contracts/impl/Storage.sol +++ b/contracts/impl/Storage.sol @@ -8,7 +8,7 @@ pragma solidity 0.6.9; pragma experimental ABIEncoderV2; -import {Ownable} from "../lib/Ownable.sol"; +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; import {SafeMath} from "../lib/SafeMath.sol"; import {DecimalMath} from "../lib/DecimalMath.sol"; import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol"; @@ -22,7 +22,7 @@ import {Types} from "../lib/Types.sol"; * * @notice Local Variables */ -contract Storage is Ownable, ReentrancyGuard { +contract Storage is InitializableOwnable, ReentrancyGuard { using SafeMath for uint256; // ============ Variables for Control ============ diff --git a/contracts/lib/InitializableOwnable.sol b/contracts/lib/InitializableOwnable.sol new file mode 100644 index 0000000..c90dde0 --- /dev/null +++ b/contracts/lib/InitializableOwnable.sol @@ -0,0 +1,48 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +/** + * @title Ownable + * @author DODO Breeder + * + * @notice Ownership related functions + */ +contract InitializableOwnable { + address public _OWNER_; + address public _NEW_OWNER_; + + // ============ Events ============ + + event OwnershipTransferPrepared(address indexed previousOwner, address indexed newOwner); + + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + // ============ Modifiers ============ + + modifier onlyOwner() { + require(msg.sender == _OWNER_, "NOT_OWNER"); + _; + } + + // ============ Functions ============ + + function transferOwnership(address newOwner) external onlyOwner { + require(newOwner != address(0), "INVALID_OWNER"); + emit OwnershipTransferPrepared(_OWNER_, newOwner); + _NEW_OWNER_ = newOwner; + } + + function claimOwnership() external { + require(msg.sender == _NEW_OWNER_, "INVALID_CLAIM"); + emit OwnershipTransferred(_OWNER_, _NEW_OWNER_); + _OWNER_ = _NEW_OWNER_; + _NEW_OWNER_ = address(0); + } +}