This commit is contained in:
owen05
2021-03-31 14:10:27 +08:00
parent 80744534d5
commit 5d288c047a
5 changed files with 67 additions and 103 deletions

View File

@@ -16,7 +16,7 @@ import {IERC1155Receiver} from "../../intf/IERC1155Receiver.sol";
contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, IERC1155Receiver {
function transferOwnership(address newOwner) public override onlyOwner {
function directTransferOwnership(address newOwner) public onlyOwner {
emit OwnershipTransferred(_OWNER_, newOwner);
_OWNER_ = newOwner;
}
@@ -24,38 +24,40 @@ contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, IERC1155Re
//TODO? assetTo
function withdrawERC721(address nftContract, uint256 tokenId) public onlyOwner {
IERC721(nftContract).safeTransferFrom(msg.sender, _OWNER_, tokenId, "");
// IERC721(nftContract).safeTransferFrom(address(this), _OWNER_, tokenId, "");
}
//TODO? assetTo
function withdrawERC1155(address nftContract, uint256[] memory tokenIds, uint256[] memory amounts) public onlyOwner {
IERC1155(nftContract).safeBatchTransferFrom(msg.sender, _OWNER_, tokenIds, amounts, "");
// IERC1155(nftContract).safeBatchTransferFrom(address(this), _OWNER_, tokenIds, amounts, "");
}
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
address,
address,
uint256,
bytes calldata
) external override returns (bytes4) {
return IERC721Receiver.onERC721Received.selector;
}
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
address,
address,
uint256,
uint256,
bytes calldata
) external override returns (bytes4){
return IERC1155Receiver.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
address,
address,
uint256[] calldata,
uint256[] calldata,
bytes calldata
) external override returns (bytes4){
return IERC1155Receiver.onERC1155BatchReceived.selector;
}

View File

@@ -18,6 +18,8 @@ contract FeeDistributor is InitializableOwnable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// ============ Storage ============
address public _BASE_TOKEN_;
address public _QUOTE_TOKEN_;
uint256 public _BASE_RESERVE_;
@@ -32,6 +34,7 @@ contract FeeDistributor is InitializableOwnable {
mapping(address => uint256) internal _QUOTE_DEBT_;
mapping(address => uint256) internal _SHARES_;
function init(
address baseToken,
address quoteToken,
@@ -45,6 +48,7 @@ contract FeeDistributor is InitializableOwnable {
_STAKE_VAULT_ = address(new StakeVault());
}
//TODO: 用户的手续费base or quote 直接转到该合约中stakeVault保存的是
function stake(address to) external {
_accuReward();
uint256 stakeVault = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_);

View File

@@ -10,23 +10,25 @@ pragma solidity 0.6.9;
import {SafeMath} from "../lib/SafeMath.sol";
import {SafeERC20} from "../lib/SafeERC20.sol";
import {DecimalMath} from "../lib/DecimalMath.sol";
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
import {IDVM} from "../DODOVendingMachine/intf/IDVM.sol";
import {ICloneFactory} from "../lib/CloneFactory.sol";
import {IERC20} from "../intf/IERC20.sol";
import {InitializableMintableERC20} from "../external/ERC20/InitializableMintableERC20.sol";
//TODO?why mintable
contract Fragment is InitializableMintableERC20 {
using SafeMath for uint256;
using SafeERC20 for IERC20;
uint256 _BUYOUT_TIMESTAMP_;
// ============ Storage ============
bool public _IS_BUYOUT_;
uint256 public _BUYOUT_TIMESTAMP_;
uint256 public _BUYOUT_PRICE_;
address _COLLATERAL_VAULT_;
address _QUOTE_;
address _DVM_;
bool _IS_BUYOUT_;
uint256 _BUYOUT_PRICE_;
address public _COLLATERAL_VAULT_;
address public _QUOTE_;
address public _DVM_;
function init(
address owner,
@@ -52,15 +54,15 @@ contract Fragment is InitializableMintableERC20 {
// init FRAG distribution
totalSupply = supply;
balances[owner] = DecimalMath.mulFloor(supply, ownerRatio);
balances[dvm] = supply.sub( balances[owner]);
balances[dvm] = supply.sub(balances[owner]);
emit Transfer(address(0), owner, balances[owner]);
emit Transfer(address(0), dvm, balances[dvm]);
// init DVM liquidity
//TODO?: transfer FRAG to DVM
IDVM(_DVM_).buyShares(address(this));
}
//需要先转入QUOTE
function buyout() external {
require(!_IS_BUYOUT_, "ALREADY BUYOUT");
_IS_BUYOUT_ = true;
@@ -83,10 +85,10 @@ contract Fragment is InitializableMintableERC20 {
IERC20(_QUOTE_).safeTransfer(_OWNER_, ownerQuote);
}
// buyout之后的恒定兑换
// buyout之后的恒定兑换需要先转入FRAG
function redeem(address to) external {
require(_IS_BUYOUT_, "NEED BUYOUT");
//TODO? amount
IERC20(_QUOTE_).safeTransfer(to, DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[address(this)]));
_clearSelfBalance();
}

View File

@@ -44,7 +44,7 @@ contract InitializableOwnable {
_OWNER_ = newOwner;
}
function transferOwnership(address newOwner) public virtual onlyOwner {
function transferOwnership(address newOwner) public onlyOwner {
emit OwnershipTransferPrepared(_OWNER_, newOwner);
_NEW_OWNER_ = newOwner;
}