Files
dodo-contractV2/contracts/Factory/FragmentFactory.sol

89 lines
2.6 KiB
Solidity
Raw Normal View History

2021-03-18 19:54:58 +08:00
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
import {ICloneFactory} from "../lib/CloneFactory.sol";
import {IDVM} from "../DODOVendingMachine/intf/IDVM.sol";
interface IFragmentFactory {
2021-03-18 23:43:54 +08:00
function createFragment() external returns (address newVendingMachine);
2021-03-18 19:54:58 +08:00
}
contract FragmentFactory is InitializableOwnable {
// ============ Templates ============
address public immutable _CLONE_FACTORY_;
2021-03-18 23:43:54 +08:00
address public immutable _MT_FEE_RATE_MODEL_;
2021-03-18 19:54:58 +08:00
address public _DVM_TEMPLATE_;
2021-03-18 23:43:54 +08:00
address public _FEE_DISTRIBUTOR_TEMPLATE_;
address public _FRAGMENT_TEMPLATE_;
2021-03-18 19:54:58 +08:00
// ============ Registry ============
// base -> quote -> DVM address list
mapping(address => mapping(address => address[])) public _REGISTRY_;
// creator -> DVM address list
mapping(address => address[]) public _USER_REGISTRY_;
// ============ Functions ============
constructor(
address cloneFactory,
address dvmTemplate,
2021-03-18 23:43:54 +08:00
address feeDistributorTemplate,
address fragmentTemplate,
address mtFeeRateModel
2021-03-18 19:54:58 +08:00
) public {
_CLONE_FACTORY_ = cloneFactory;
_DVM_TEMPLATE_ = dvmTemplate;
2021-03-18 23:43:54 +08:00
_FEE_DISTRIBUTOR_TEMPLATE_ = feeDistributorTemplate;
_FRAGMENT_TEMPLATE_ = fragmentTemplate;
_MT_FEE_RATE_MODEL_ = mtFeeRateModel;
2021-03-18 19:54:58 +08:00
}
2021-03-18 23:43:54 +08:00
function createFragment(
address owner,
address vault,
2021-03-18 19:54:58 +08:00
address quoteToken,
2021-03-18 23:43:54 +08:00
uint256 mtFeeRate,
2021-03-18 19:54:58 +08:00
uint256 i,
uint256 k,
2021-03-18 23:43:54 +08:00
uint256 totalSupply,
uint256 ownerRatio,
uint256 buyoutTimestamp
) external returns (address newFragment) {
newFragment = ICloneFactory(_CLONE_FACTORY_).clone(_FRAGMENT_TEMPLATE_);
2021-03-18 19:54:58 +08:00
newVendingMachine = ICloneFactory(_CLONE_FACTORY_).clone(_DVM_TEMPLATE_);
2021-03-18 23:43:54 +08:00
newFeeDistributor = ICloneFactory(_CLONE_FACTORY_).clone(_FEE_DISTRIBUTOR_TEMPLATE_);
{
IFeeDistributor(newFeeDistributor).init(newFragment, quoteToken, newFragment);
}
2021-03-18 19:54:58 +08:00
{
IDVM(newVendingMachine).init(
2021-03-18 23:43:54 +08:00
newFeeDistributor,
newFragment,
2021-03-18 19:54:58 +08:00
quoteToken,
2021-03-18 23:43:54 +08:00
0,
mtFeeRateModel,
2021-03-18 19:54:58 +08:00
i,
k,
2021-03-18 23:43:54 +08:00
false
2021-03-18 19:54:58 +08:00
);
2021-03-18 23:43:54 +08:00
IFeeRateRegistry(mtFeeRateModel).set(newVendingMachine, mtFeeRate)
2021-03-18 19:54:58 +08:00
}
2021-03-18 23:43:54 +08:00
{
IFragment(newFragment).init(owner, newVendingMachine, vault, totalSupply, ownerRatio, buyoutTimestamp);
2021-03-18 19:54:58 +08:00
}
}
}