restruct contract repo

This commit is contained in:
mingda
2020-10-23 01:16:52 +08:00
parent 5f10f065e4
commit e8182dd1a1
53 changed files with 775 additions and 2575 deletions

View File

@@ -0,0 +1,33 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
interface ICloneFactory {
function clone(address prototype) external returns (address proxy);
}
// introduction of proxy mode design: https://docs.openzeppelin.com/upgrades/2.8/
// minimum implementation of transparent proxy: https://eips.ethereum.org/EIPS/eip-1167
contract CloneFactory is ICloneFactory {
function clone(address prototype) external override returns (address proxy) {
bytes20 targetBytes = bytes20(prototype);
assembly {
let clone := mload(0x40)
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(clone, 0x14), targetBytes)
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
proxy := create(0, clone, 0x37)
}
return proxy;
}
}

View File

@@ -26,6 +26,10 @@ library DecimalMath {
return target.mul(d) / ONE;
}
function mulFloor(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(d) / ONE;
}
function mulCeil(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(d).divCeil(ONE);
}

View File

@@ -17,6 +17,7 @@ pragma experimental ABIEncoderV2;
contract InitializableOwnable {
address public _OWNER_;
address public _NEW_OWNER_;
bool internal _INITIALIZED_;
// ============ Events ============
@@ -26,6 +27,11 @@ contract InitializableOwnable {
// ============ Modifiers ============
modifier notInitialized() {
require(!_INITIALIZED_, "DODO_INITIALIZED");
_;
}
modifier onlyOwner() {
require(msg.sender == _OWNER_, "NOT_OWNER");
_;
@@ -33,13 +39,18 @@ contract InitializableOwnable {
// ============ Functions ============
function transferOwnership(address newOwner) external onlyOwner {
function initOwner(address newOwner) public notInitialized{
_INITIALIZED_ = true;
_OWNER_ = newOwner;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "INVALID_OWNER");
emit OwnershipTransferPrepared(_OWNER_, newOwner);
_NEW_OWNER_ = newOwner;
}
function claimOwnership() external {
function claimOwnership() public {
require(msg.sender == _NEW_OWNER_, "INVALID_CLAIM");
emit OwnershipTransferred(_OWNER_, _NEW_OWNER_);
_OWNER_ = _NEW_OWNER_;

View File

@@ -0,0 +1,53 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {InitializableOwnable} from "./InitializableOwnable.sol";
contract PermissionManager is InitializableOwnable {
bool public _BLACKLIST_MODE_ON_;
mapping(address => bool) internal _whitelist_;
mapping(address => bool) internal _blacklist_;
function isAllowed(address account) external view returns(bool){
if (_BLACKLIST_MODE_ON_) {
return !_blacklist_[account];
} else {
return _whitelist_[account];
}
}
function openBlacklist() external onlyOwner {
_BLACKLIST_MODE_ON_ = true;
}
function openWhitelist() external onlyOwner {
_BLACKLIST_MODE_ON_ = true;
}
function addToWhitelist(address account) external onlyOwner{
_whitelist_[account] = true;
}
function removeFromWhitelist(address account) external onlyOwner{
_whitelist_[account] = false;
}
function addToBlacklist(address account) external onlyOwner{
_blacklist_[account] = true;
}
function removeFromBlacklist(address account) external onlyOwner{
_blacklist_[account] = false;
}
}

View File

@@ -1,13 +0,0 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
library Types {
enum RStatus {ONE, ABOVE_ONE, BELOW_ONE}
}