fix syntax

This commit is contained in:
owen05
2021-03-30 18:25:39 +08:00
parent 40b0621127
commit 80744534d5
14 changed files with 101 additions and 107 deletions

View File

@@ -14,18 +14,20 @@ import {IERC721Receiver} from "../../intf/IERC721Receiver.sol";
import {IERC1155} from "../../intf/IERC1155.sol";
import {IERC1155Receiver} from "../../intf/IERC1155Receiver.sol";
contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, ReentrancyGuard {
contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, IERC1155Receiver {
function transferOwnership(address newOwner) external override onlyOwner {
function transferOwnership(address newOwner) public override onlyOwner {
emit OwnershipTransferred(_OWNER_, newOwner);
_OWNER_ = newOwner;
}
function withdrawERC721(address nftContract, uint256 tokenId) onlyOwner {
//TODO? assetTo
function withdrawERC721(address nftContract, uint256 tokenId) public onlyOwner {
IERC721(nftContract).safeTransferFrom(msg.sender, _OWNER_, tokenId, "");
}
function withdrawERC1155(address nftContract, uint256[] tokenIds, uint256[] amounts) onlyOwner {
//TODO? assetTo
function withdrawERC1155(address nftContract, uint256[] memory tokenIds, uint256[] memory amounts) public onlyOwner {
IERC1155(nftContract).safeBatchTransferFrom(msg.sender, _OWNER_, tokenIds, amounts, "");
}
@@ -34,7 +36,7 @@ contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, Reentrancy
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4) {
) external override returns (bytes4) {
return IERC721Receiver.onERC721Received.selector;
}
@@ -44,9 +46,9 @@ contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, Reentrancy
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4){
) external override returns (bytes4){
return IERC1155Receiver.onERC1155Received.selector;
};
}
function onERC1155BatchReceived(
address operator,
@@ -54,7 +56,12 @@ contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, Reentrancy
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4){
return IERC1155BatchReceiver.onERC1155BatchReceived.selector;
};
) external override returns (bytes4){
return IERC1155Receiver.onERC1155BatchReceived.selector;
}
function supportsInterface(bytes4 interfaceId) public override view returns (bool) {
return interfaceId == type(IERC1155).interfaceId
|| interfaceId == type(IERC721).interfaceId;
}
}

View File

@@ -8,10 +8,16 @@
pragma solidity 0.6.9;
import {SafeMath} from "../lib/SafeMath.sol";
import {DecimalMath} from "../lib/DecimalMath.sol";
import {IERC20} from "../intf/IERC20.sol";
import {SafeERC20} from "../lib/SafeERC20.sol";
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
import {Ownable} from "../lib/Ownable.sol";
contract FeeDistributor is InitializableOwnable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
address public _BASE_TOKEN_;
address public _QUOTE_TOKEN_;
uint256 public _BASE_RESERVE_;
@@ -24,6 +30,7 @@ contract FeeDistributor is InitializableOwnable {
uint256 public _STAKE_RESERVE_;
mapping(address => uint256) internal _BASE_DEBT_;
mapping(address => uint256) internal _QUOTE_DEBT_;
mapping(address => uint256) internal _SHARES_;
function init(
address baseToken,
@@ -35,18 +42,19 @@ contract FeeDistributor is InitializableOwnable {
_STAKE_TOKEN_ = stakeToken;
_BASE_REWARD_RATIO_ = DecimalMath.ONE;
_QUOTE_REWARD_RATIO_ = DecimalMath.ONE;
_STAKE_VAULT_ = new StakeVault();
_STAKE_VAULT_ = address(new StakeVault());
}
function stake(address to) external {
_accuReward();
uint256 stakeInput = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_).sub(_STAKE_RESERVE_);
uint256 stakeVault = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_);
uint256 stakeInput = stakeVault.sub(_STAKE_RESERVE_);
_addShares(stakeInput, to);
}
function claim(address to) external {
_accuReward();
_claim();
_claim(msg.sender, to);
}
function unstake(uint256 amount, address to, bool withClaim) external {
@@ -64,21 +72,21 @@ contract FeeDistributor is InitializableOwnable {
function _claim(address sender, address to) internal {
uint256 allBase = DecimalMath.mulFloor(_SHARES_[sender], _BASE_REWARD_RATIO_);
uint256 allQuote = DecimalMath.mulFloor(_SHARES_[sender], _QUOTE_REWARD_RATIO_);
IERC20(_BASE_TOKEN_).safeTransfer(allBase.sub(_BASE_DEBT_[sender]), to);
IERC20(_QUOTE_TOKEN_).safeTransfer(allQuote.sub(_QUOTE_DEBT_[sender]), to);
IERC20(_BASE_TOKEN_).safeTransfer(to, allBase.sub(_BASE_DEBT_[sender]));
IERC20(_QUOTE_TOKEN_).safeTransfer(to, allQuote.sub(_QUOTE_DEBT_[sender]));
_BASE_DEBT_[sender] = allBase;
_QUOTE_DEBT_[sender] = allQuote;
}
function _addShares(uint256 amount, address to) internal {
_SHARES_[to] = _SHARES_[to].add(amount)
_SHARES_[to] = _SHARES_[to].add(amount);
_BASE_DEBT_[to] = _BASE_DEBT_[to].add(DecimalMath.mulCeil(amount, _BASE_REWARD_RATIO_));
_QUOTE_DEBT_[to] = _QUOTE_DEBT_[to].add(DecimalMath.mulCeil(amount, _QUOTE_REWARD_RATIO_));
_STAKE_RESERVE_ = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_);
}
function _removeShares(uint256 amount, address from) internal {
_SHARES_[from] = _SHARES_[from].sub(amount)
_SHARES_[from] = _SHARES_[from].sub(amount);
_BASE_DEBT_[from] = _BASE_DEBT_[from].sub(DecimalMath.mulFloor(amount, _BASE_REWARD_RATIO_));
_QUOTE_DEBT_[from] = _QUOTE_DEBT_[from].sub(DecimalMath.mulFloor(amount, _QUOTE_REWARD_RATIO_));
_STAKE_RESERVE_ = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_);
@@ -96,11 +104,13 @@ contract FeeDistributor is InitializableOwnable {
}
contract StakeVault is Ownable {
using SafeERC20 for IERC20;
function transferOut(
address token,
uint256 amount,
address to
) onlyOwner {
IERC20(token).SafeTransfer(amount, to);
) external onlyOwner {
IERC20(token).safeTransfer(to, amount);
}
}

View File

@@ -34,4 +34,17 @@ interface IDVM {
function buyShares(address to) external returns (uint256,uint256,uint256);
function addressToShortString(address _addr) external pure returns (string memory);
function getMidPrice() external view returns (uint256 midPrice);
function sellShares(
uint256 shareAmount,
address to,
uint256 baseMinAmount,
uint256 quoteMinAmount,
bytes calldata data,
uint256 deadline
) external returns (uint256 baseAmount, uint256 quoteAmount);
}

View File

@@ -68,30 +68,30 @@ contract FragmentFactory is InitializableOwnable {
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_);
// 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);
}
// {
// IFeeDistributor(newFeeDistributor).init(newFragment, quoteToken, newFragment);
// }
{
IDVM(newVendingMachine).init(
newFeeDistributor,
newFragment,
quoteToken,
0,
mtFeeRateModel,
i,
k,
false
);
IFeeRateRegistry(mtFeeRateModel).set(newVendingMachine, mtFeeRate)
}
// {
// IDVM(newVendingMachine).init(
// newFeeDistributor,
// newFragment,
// quoteToken,
// 0,
// mtFeeRateModel,
// i,
// k,
// false
// );
// IFeeRateRegistry(mtFeeRateModel).set(newVendingMachine, mtFeeRate);
// }
{
IFragment(newFragment).init(owner, newVendingMachine, vault, totalSupply, ownerRatio, buyoutTimestamp);
}
// {
// IFragment(newFragment).init(owner, newVendingMachine, vault, totalSupply, ownerRatio, buyoutTimestamp);
// }
}
}

View File

@@ -9,15 +9,16 @@ pragma solidity 0.6.9;
import {SafeMath} from "../lib/SafeMath.sol";
import {SafeERC20} from "../lib/SafeERC20.sol";
import {DecimalMath} from "../../lib/DecimalMath.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";
contract Fragment is InitializableMintableERC20 {
using SafeMath for uint256;
using SafeTransfer for IERC20;
using SafeERC20 for IERC20;
uint256 _BUYOUT_TIMESTAMP_;
@@ -39,12 +40,12 @@ contract Fragment is InitializableMintableERC20 {
initOwner(owner);
_DVM_ = dvm;
_COLLATERAL_VAULT_ = collateralVault;
_QUOTE_ = IDVM(DVM)._QUOTE_TOKEN_();
_QUOTE_ = IDVM(_DVM_)._QUOTE_TOKEN_();
_BUYOUT_TIMESTAMP_ = buyoutTimestamp;
// init FRAG meta data
string memory suffix = "FRAG_";
name = string(abi.encodePacked(suffix, IDVM(_DVM_).addressToShortString(_COLLATERAL_VAULT_));
name = string(abi.encodePacked(suffix, IDVM(_DVM_).addressToShortString(_COLLATERAL_VAULT_)));
symbol = "FRAG";
decimals = 18;
@@ -56,7 +57,8 @@ contract Fragment is InitializableMintableERC20 {
emit Transfer(address(0), dvm, balances[dvm]);
// init DVM liquidity
IDVM(DVM).buyShares(address(this));
//TODO?: transfer FRAG to DVM
IDVM(_DVM_).buyShares(address(this));
}
function buyout() external {
@@ -75,20 +77,21 @@ contract Fragment is InitializableMintableERC20 {
uint256(-1)
);
uint256 ownerQuote = DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[address(this)])
uint256 ownerQuote = DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[address(this)]);
_clearSelfBalance();
IERC20(_QUOTE_).safeTransfer(ownerQuote, _OWNER_);
IERC20(_QUOTE_).safeTransfer(_OWNER_, ownerQuote);
}
// buyout之后的恒定兑换
function redeem(address to) external {
require(_IS_BUYOUT_, "NEED BUYOUT");
IERC20(_QUOTE_).safeTransfer(DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[address(this)]), to);
//TODO? amount
IERC20(_QUOTE_).safeTransfer(to, DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[address(this)]));
_clearSelfBalance();
}
function getBuyoutRequirement() view return (uint256 requireQuote){
function getBuyoutRequirement() external view returns (uint256 requireQuote){
require(!_IS_BUYOUT_, "ALREADY BUYOUT");
uint256 price = IDVM(_DVM_).getMidPrice();
requireQuote = DecimalMath.mulCeil(price, totalSupply);

View File

@@ -1,19 +0,0 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
interface IDODOIncentiveBsc {
function triggerIncentive(
address fromToken,
address toToken,
uint256 fromAmount,
uint256 returnAmount,
address assetTo
) external;
}

View File

@@ -1,7 +1,7 @@
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/solc-0.6/contracts/token/ERC1155/IERC1155.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
pragma solidity 0.6.9;
import "./IERC165.sol";

View File

@@ -1,9 +1,9 @@
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma solidity 0.6.9;
import "./ERC165.sol";
import "./IERC165.sol";
/**
* _Available since v3.1._

View File

@@ -1,7 +1,7 @@
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/solc-0.6/contracts/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma solidity 0.6.9;
/**
* @dev Interface of the ERC165 standard, as defined in the

View File

@@ -1,7 +1,8 @@
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/solc-0.6/contracts/token/ERC20/IERC20.sol
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
@@ -12,6 +13,12 @@ interface IERC20 {
*/
function totalSupply() external view returns (uint256);
function decimals() external view returns (uint8);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
@@ -65,18 +72,4 @@ interface IERC20 {
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
}

View File

@@ -1,7 +1,7 @@
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/solc-0.6/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.8.0;
pragma solidity 0.6.9;
import "./IERC165.sol";

View File

@@ -1,7 +1,7 @@
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/solc-0.6/contracts/token/ERC721/IERC721Receiver.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
pragma solidity 0.6.9;
/**
* @title ERC721 token receiver interface

View File

@@ -1,13 +0,0 @@
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
interface ILockedTokenVault02 {
function tradeIncentive(address trader, uint256 amount) external;
}

View File

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