DPP factory and init
This commit is contained in:
@@ -10,6 +10,7 @@ pragma experimental ABIEncoderV2;
|
||||
|
||||
interface ICloneFactory {
|
||||
function clone(address prototype) external returns (address proxy);
|
||||
function clone2(address prototype,bytes32 salt) external returns (address proxy);
|
||||
}
|
||||
|
||||
// introduction of proxy mode design: https://docs.openzeppelin.com/upgrades/2.8/
|
||||
@@ -30,4 +31,20 @@ contract CloneFactory is ICloneFactory {
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
function clone2(address prototype, bytes32 salt) 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 := create2(0, clone, 0x37, salt)
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,17 +8,15 @@
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {IFeeRateModel} from "../intf/IFeeRateModel.sol";
|
||||
import {Ownable} from "../lib/Ownable.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
|
||||
interface IConstFeeRateModel is IFeeRateModel {
|
||||
interface IConstFeeRateModel {
|
||||
function init(address owner, uint256 feeRate) external;
|
||||
|
||||
function setFeeRate(uint256 newFeeRate) external;
|
||||
function getFeeRate(address trader) external view returns (uint256);
|
||||
}
|
||||
|
||||
contract ConstFeeRateModel is InitializableOwnable, IFeeRateModel {
|
||||
contract ConstFeeRateModel is InitializableOwnable {
|
||||
uint256 public _FEE_RATE_;
|
||||
|
||||
function init(address owner, uint256 feeRate) external {
|
||||
@@ -26,11 +24,11 @@ contract ConstFeeRateModel is InitializableOwnable, IFeeRateModel {
|
||||
_FEE_RATE_ = feeRate;
|
||||
}
|
||||
|
||||
function setFeeRate(uint256 newFeeRate) external {
|
||||
function setFeeRate(uint256 newFeeRate) external onlyOwner {
|
||||
_FEE_RATE_ = newFeeRate;
|
||||
}
|
||||
|
||||
function getFeeRate(address) external override view returns (uint256) {
|
||||
function getFeeRate(address trader) external view returns (uint256) {
|
||||
return _FEE_RATE_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,23 +8,28 @@
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "./Ownable.sol";
|
||||
import {InitializableOwnable} from "./InitializableOwnable.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
|
||||
interface IExternalValue {
|
||||
function set(uint256) external;
|
||||
|
||||
function init(address owner, uint256 value) external;
|
||||
function set(uint256 value) external;
|
||||
function get() external view returns (uint256);
|
||||
}
|
||||
|
||||
contract ExternalValue is IExternalValue, InitializableOwnable {
|
||||
|
||||
contract ExternalValue is InitializableOwnable {
|
||||
uint256 public _VALUE_;
|
||||
|
||||
function set(uint256 value) external override onlyOwner {
|
||||
function init(address owner, uint256 value) external {
|
||||
initOwner(owner);
|
||||
_VALUE_ = value;
|
||||
}
|
||||
|
||||
function get() external override view returns (uint256) {
|
||||
function set(uint256 value) external onlyOwner {
|
||||
_VALUE_ = value;
|
||||
}
|
||||
|
||||
function get() external view returns (uint256) {
|
||||
return _VALUE_;
|
||||
}
|
||||
}
|
||||
|
||||
44
contracts/lib/FeeRateModel.sol
Normal file
44
contracts/lib/FeeRateModel.sol
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
|
||||
interface IFeeRateModel {
|
||||
function getFeeRate(address trader) external view returns (uint256);
|
||||
function init(address owner, uint256 feeRate) external;
|
||||
function setFeeRate(uint256 newFeeRate) external;
|
||||
}
|
||||
|
||||
contract FeeRateModel is InitializableOwnable {
|
||||
//DEFAULT
|
||||
uint256 public _FEE_RATE_;
|
||||
mapping(address => uint256) feeMapping;
|
||||
|
||||
function init(address owner, uint256 feeRate) external {
|
||||
initOwner(owner);
|
||||
_FEE_RATE_ = feeRate;
|
||||
}
|
||||
|
||||
function setSpecificFeeRate(address trader, uint256 feeRate) external onlyOwner {
|
||||
require(trader != address(0), "INVALID ADDRESS!");
|
||||
feeMapping[trader] = feeRate;
|
||||
}
|
||||
|
||||
function setFeeRate(uint256 newFeeRate) external onlyOwner {
|
||||
_FEE_RATE_ = newFeeRate;
|
||||
}
|
||||
|
||||
function getFeeRate(address trader) external view returns (uint256) {
|
||||
uint256 feeRate = feeMapping[trader];
|
||||
if(feeRate == 0)
|
||||
return _FEE_RATE_;
|
||||
return feeRate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user