snapshot
This commit is contained in:
@@ -25,13 +25,17 @@ contract FeeDistributor is InitializableOwnable {
|
||||
mapping(address => uint256) internal _BASE_DEBT_;
|
||||
mapping(address => uint256) internal _QUOTE_DEBT_;
|
||||
|
||||
function init() external {
|
||||
function init(
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address stakeToken
|
||||
) external {
|
||||
_BASE_TOKEN_ = baseToken;
|
||||
_QUOTE_TOKEN_ = quoteToken;
|
||||
_STAKE_TOKEN_ = stakeToken;
|
||||
_BASE_REWARD_RATIO_ = DecimalMath.ONE;
|
||||
_QUOTE_REWARD_RATIO_ = DecimalMath.ONE;
|
||||
_STAKE_VAULT_ = new DistributorStakeVault();
|
||||
_STAKE_VAULT_ = new StakeVault();
|
||||
}
|
||||
|
||||
function stake(address to) external {
|
||||
@@ -54,7 +58,7 @@ contract FeeDistributor is InitializableOwnable {
|
||||
}
|
||||
|
||||
_removeShares(amount, msg.sender);
|
||||
DistributorStakeVault(_STAKE_VAULT_).transferOut(_STAKE_TOKEN_, amount, to);
|
||||
StakeVault(_STAKE_VAULT_).transferOut(_STAKE_TOKEN_, amount, to);
|
||||
}
|
||||
|
||||
function _claim(address sender, address to) internal {
|
||||
@@ -91,7 +95,7 @@ contract FeeDistributor is InitializableOwnable {
|
||||
|
||||
}
|
||||
|
||||
contract DistributorStakeVault is Ownable {
|
||||
contract StakeVault is Ownable {
|
||||
function transferOut(
|
||||
address token,
|
||||
uint256 amount,
|
||||
|
||||
@@ -13,20 +13,17 @@ import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {IDVM} from "../DODOVendingMachine/intf/IDVM.sol";
|
||||
|
||||
interface IFragmentFactory {
|
||||
function createFragment(
|
||||
|
||||
) external returns (address newVendingMachine);
|
||||
function createFragment() external returns (address newVendingMachine);
|
||||
}
|
||||
|
||||
|
||||
contract FragmentFactory is InitializableOwnable {
|
||||
// ============ Templates ============
|
||||
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
address public immutable _DEFAULT_MAINTAINER_;
|
||||
address public immutable _DEFAULT_MT_FEE_RATE_MODEL_;
|
||||
address public immutable _MT_FEE_RATE_MODEL_;
|
||||
address public _DVM_TEMPLATE_;
|
||||
address public _FEE_DISTRIBUTOR_TEMPLATE_
|
||||
address public _FEE_DISTRIBUTOR_TEMPLATE_;
|
||||
address public _FRAGMENT_TEMPLATE_;
|
||||
|
||||
// ============ Registry ============
|
||||
|
||||
@@ -35,124 +32,57 @@ contract FragmentFactory is InitializableOwnable {
|
||||
// creator -> DVM address list
|
||||
mapping(address => address[]) public _USER_REGISTRY_;
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event NewDVM(
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address creator,
|
||||
address dvm
|
||||
);
|
||||
|
||||
event RemoveDVM(address dvm);
|
||||
|
||||
// ============ Functions ============
|
||||
|
||||
constructor(
|
||||
address cloneFactory,
|
||||
address dvmTemplate,
|
||||
address defaultMaintainer,
|
||||
address defaultMtFeeRateModel
|
||||
address feeDistributorTemplate,
|
||||
address fragmentTemplate,
|
||||
address mtFeeRateModel
|
||||
) public {
|
||||
_CLONE_FACTORY_ = cloneFactory;
|
||||
_DVM_TEMPLATE_ = dvmTemplate;
|
||||
_DEFAULT_MAINTAINER_ = defaultMaintainer;
|
||||
_DEFAULT_MT_FEE_RATE_MODEL_ = defaultMtFeeRateModel;
|
||||
_FEE_DISTRIBUTOR_TEMPLATE_ = feeDistributorTemplate;
|
||||
_FRAGMENT_TEMPLATE_ = fragmentTemplate;
|
||||
_MT_FEE_RATE_MODEL_ = mtFeeRateModel;
|
||||
}
|
||||
|
||||
function createDODOVendingMachine(
|
||||
address baseToken,
|
||||
function createFragment(
|
||||
address owner,
|
||||
address vault,
|
||||
address quoteToken,
|
||||
uint256 lpFeeRate,
|
||||
uint256 mtFeeRate,
|
||||
uint256 i,
|
||||
uint256 k,
|
||||
bool isOpenTWAP
|
||||
) external returns (address newVendingMachine) {
|
||||
uint256 totalSupply,
|
||||
uint256 ownerRatio,
|
||||
uint256 buyoutTimestamp
|
||||
) external returns (address newFragment) {
|
||||
newFragment = ICloneFactory(_CLONE_FACTORY_).clone(_FRAGMENT_TEMPLATE_);
|
||||
newVendingMachine = ICloneFactory(_CLONE_FACTORY_).clone(_DVM_TEMPLATE_);
|
||||
newFeeDistributor = ICloneFactory(_CLONE_FACTORY_).clone(_FEE_DISTRIBUTOR_TEMPLATE_);
|
||||
|
||||
{
|
||||
IFeeDistributor(newFeeDistributor).init(newFragment, quoteToken, newFragment);
|
||||
}
|
||||
|
||||
{
|
||||
IDVM(newVendingMachine).init(
|
||||
_DEFAULT_MAINTAINER_,
|
||||
baseToken,
|
||||
newFeeDistributor,
|
||||
newFragment,
|
||||
quoteToken,
|
||||
lpFeeRate,
|
||||
_DEFAULT_MT_FEE_RATE_MODEL_,
|
||||
0,
|
||||
mtFeeRateModel,
|
||||
i,
|
||||
k,
|
||||
isOpenTWAP
|
||||
false
|
||||
);
|
||||
IFeeRateRegistry(mtFeeRateModel).set(newVendingMachine, mtFeeRate)
|
||||
}
|
||||
_REGISTRY_[baseToken][quoteToken].push(newVendingMachine);
|
||||
_USER_REGISTRY_[tx.origin].push(newVendingMachine);
|
||||
emit NewDVM(baseToken, quoteToken, tx.origin, newVendingMachine);
|
||||
}
|
||||
|
||||
// ============ Admin Operation Functions ============
|
||||
|
||||
function updateDvmTemplate(address _newDVMTemplate) external onlyOwner {
|
||||
_DVM_TEMPLATE_ = _newDVMTemplate;
|
||||
}
|
||||
|
||||
function addPoolByAdmin(
|
||||
address creator,
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address pool
|
||||
) external onlyOwner {
|
||||
_REGISTRY_[baseToken][quoteToken].push(pool);
|
||||
_USER_REGISTRY_[creator].push(pool);
|
||||
emit NewDVM(baseToken, quoteToken, creator, pool);
|
||||
}
|
||||
|
||||
function removePoolByAdmin(
|
||||
address creator,
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address pool
|
||||
) external onlyOwner {
|
||||
address[] memory registryList = _REGISTRY_[baseToken][quoteToken];
|
||||
for (uint256 i = 0; i < registryList.length; i++) {
|
||||
if (registryList[i] == pool) {
|
||||
registryList[i] = registryList[registryList.length - 1];
|
||||
break;
|
||||
}
|
||||
{
|
||||
IFragment(newFragment).init(owner, newVendingMachine, vault, totalSupply, ownerRatio, buyoutTimestamp);
|
||||
}
|
||||
_REGISTRY_[baseToken][quoteToken] = registryList;
|
||||
_REGISTRY_[baseToken][quoteToken].pop();
|
||||
address[] memory userRegistryList = _USER_REGISTRY_[creator];
|
||||
for (uint256 i = 0; i < userRegistryList.length; i++) {
|
||||
if (userRegistryList[i] == pool) {
|
||||
userRegistryList[i] = userRegistryList[userRegistryList.length - 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
_USER_REGISTRY_[creator] = userRegistryList;
|
||||
_USER_REGISTRY_[creator].pop();
|
||||
emit RemoveDVM(pool);
|
||||
}
|
||||
|
||||
// ============ View Functions ============
|
||||
|
||||
function getDODOPool(address baseToken, address quoteToken)
|
||||
external
|
||||
view
|
||||
returns (address[] memory machines)
|
||||
{
|
||||
return _REGISTRY_[baseToken][quoteToken];
|
||||
}
|
||||
|
||||
function getDODOPoolBidirection(address token0, address token1)
|
||||
external
|
||||
view
|
||||
returns (address[] memory baseToken0Machines, address[] memory baseToken1Machines)
|
||||
{
|
||||
return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
|
||||
}
|
||||
|
||||
function getDODOPoolByUser(address user)
|
||||
external
|
||||
view
|
||||
returns (address[] memory machines)
|
||||
{
|
||||
return _USER_REGISTRY_[user];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,15 +32,17 @@ contract Fragment is InitializableMintableERC20 {
|
||||
address dvm,
|
||||
address collateralVault,
|
||||
uint256 supply,
|
||||
uint256 ownerRatio
|
||||
uint256 ownerRatio,
|
||||
uint256 buyoutTimestamp
|
||||
) external {
|
||||
// init local variables
|
||||
initOwner(owner);
|
||||
_DVM_ = dvm;
|
||||
_COLLATERAL_VAULT_ = collateralVault;
|
||||
_QUOTE_ = IDVM(DVM)._QUOTE_TOKEN_();
|
||||
_BUYOUT_TIMESTAMP_ = buyoutTimestamp;
|
||||
|
||||
// init FRAM meta data
|
||||
// init FRAG meta data
|
||||
string memory suffix = "FRAG_";
|
||||
name = string(abi.encodePacked(suffix, IDVM(_DVM_).addressToShortString(_COLLATERAL_VAULT_));
|
||||
symbol = "FRAG";
|
||||
@@ -58,6 +60,7 @@ contract Fragment is InitializableMintableERC20 {
|
||||
}
|
||||
|
||||
function buyout() external {
|
||||
require(!_IS_BUYOUT_, "ALREADY BUYOUT");
|
||||
_IS_BUYOUT_ = true;
|
||||
_BUYOUT_PRICE_ = IDVM(_DVM_).getMidPrice();
|
||||
uint256 requireQuote = DecimalMath.mulCeil(_BUYOUT_PRICE_, totalSupply);
|
||||
@@ -80,11 +83,13 @@ contract Fragment is InitializableMintableERC20 {
|
||||
|
||||
// buyout之后的恒定兑换
|
||||
function redeem(address to) external {
|
||||
require(_IS_BUYOUT_, "NEED BUYOUT");
|
||||
IERC20(_QUOTE_).safeTransfer(DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[address(this)]), to);
|
||||
_clearSelfBalance();
|
||||
}
|
||||
|
||||
function getBuyoutRequire() view return (uint256 requireQuote){
|
||||
function getBuyoutRequirement() view return (uint256 requireQuote){
|
||||
require(!_IS_BUYOUT_, "ALREADY BUYOUT");
|
||||
uint256 price = IDVM(_DVM_).getMidPrice();
|
||||
requireQuote = DecimalMath.mulCeil(price, totalSupply);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user