merge feature/nft
This commit is contained in:
130
contracts/CollateralVault/impl/NFTCollateralVault.sol
Normal file
130
contracts/CollateralVault/impl/NFTCollateralVault.sol
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {IERC721} from "../../intf/IERC721.sol";
|
||||
import {IERC721Receiver} from "../../intf/IERC721Receiver.sol";
|
||||
import {IERC1155} from "../../intf/IERC1155.sol";
|
||||
import {IERC1155Receiver} from "../../intf/IERC1155Receiver.sol";
|
||||
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
|
||||
|
||||
|
||||
contract NFTCollateralVault is InitializableOwnable, IERC721Receiver, IERC1155Receiver, ReentrancyGuard {
|
||||
using SafeMath for uint256;
|
||||
|
||||
// ============ Storage ============
|
||||
string public name;
|
||||
string public baseURI;
|
||||
|
||||
function init(
|
||||
address owner,
|
||||
string memory _name,
|
||||
string memory _baseURI
|
||||
) external {
|
||||
initOwner(owner);
|
||||
name = _name;
|
||||
baseURI = _baseURI;
|
||||
}
|
||||
|
||||
// ============ Event ============
|
||||
event RemoveNftToken(address nftContract, uint256 tokenId, uint256 amount);
|
||||
event AddNftToken(address nftContract, uint256 tokenId, uint256 amount);
|
||||
|
||||
// ============ TransferFrom NFT ============
|
||||
function depositERC721(address nftContract, uint256[] memory tokenIds) public {
|
||||
require(nftContract != address(0), "DODONftVault: ZERO_ADDRESS");
|
||||
for(uint256 i = 0; i < tokenIds.length; i++) {
|
||||
IERC721(nftContract).safeTransferFrom(msg.sender, address(this), tokenIds[i]);
|
||||
emit AddNftToken(nftContract, tokenIds[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
function depoistERC1155(address nftContract, uint256[] memory tokenIds, uint256[] memory amounts) public {
|
||||
require(nftContract != address(0), "DODONftVault: ZERO_ADDRESS");
|
||||
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
|
||||
IERC1155(nftContract).safeBatchTransferFrom(msg.sender, address(this), tokenIds, amounts, "");
|
||||
for(uint256 i = 0; i < tokenIds.length; i++) {
|
||||
emit AddNftToken(nftContract, tokenIds[i], amounts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Ownable ============
|
||||
function directTransferOwnership(address newOwner) external onlyOwner {
|
||||
require(newOwner != address(0), "DODONftVault: ZERO_ADDRESS");
|
||||
emit OwnershipTransferred(_OWNER_, newOwner);
|
||||
_OWNER_ = newOwner;
|
||||
}
|
||||
|
||||
function createFragment(address nftProxy, bytes calldata data) external preventReentrant onlyOwner {
|
||||
require(nftProxy != address(0), "DODONftVault: PROXY_INVALID");
|
||||
_OWNER_ = nftProxy;
|
||||
(bool success,) = nftProxy.call(data);
|
||||
require(success, "DODONftVault: TRANSFER_OWNER_FAILED");
|
||||
emit OwnershipTransferred(_OWNER_, nftProxy);
|
||||
}
|
||||
|
||||
function withdrawERC721(address nftContract, uint256[] memory tokenIds) external onlyOwner {
|
||||
require(nftContract != address(0), "DODONftVault: ZERO_ADDRESS");
|
||||
for(uint256 i = 0; i < tokenIds.length; i++) {
|
||||
IERC721(nftContract).safeTransferFrom(address(this), _OWNER_, tokenIds[i]);
|
||||
emit RemoveNftToken(nftContract, tokenIds[i], 1);
|
||||
}
|
||||
}
|
||||
|
||||
function withdrawERC1155(address nftContract, uint256[] memory tokenIds, uint256[] memory amounts) external onlyOwner {
|
||||
require(nftContract != address(0), "DODONftVault: ZERO_ADDRESS");
|
||||
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
|
||||
IERC1155(nftContract).safeBatchTransferFrom(address(this), _OWNER_, tokenIds, amounts, "");
|
||||
for(uint256 i = 0; i < tokenIds.length; i++) {
|
||||
emit RemoveNftToken(nftContract, tokenIds[i], amounts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function supportsInterface(bytes4 interfaceId) public override view returns (bool) {
|
||||
return interfaceId == type(IERC1155Receiver).interfaceId
|
||||
|| interfaceId == type(IERC721Receiver).interfaceId;
|
||||
}
|
||||
|
||||
// ============ Callback ============
|
||||
function onERC721Received(
|
||||
address,
|
||||
address,
|
||||
uint256 tokenId,
|
||||
bytes calldata
|
||||
) external override returns (bytes4) {
|
||||
emit AddNftToken(msg.sender, tokenId, 1);
|
||||
return IERC721Receiver.onERC721Received.selector;
|
||||
}
|
||||
|
||||
function onERC1155Received(
|
||||
address,
|
||||
address,
|
||||
uint256 id,
|
||||
uint256 value,
|
||||
bytes calldata
|
||||
) external override returns (bytes4){
|
||||
emit AddNftToken(msg.sender, id, value);
|
||||
return IERC1155Receiver.onERC1155Received.selector;
|
||||
}
|
||||
|
||||
function onERC1155BatchReceived(
|
||||
address,
|
||||
address,
|
||||
uint256[] calldata ids,
|
||||
uint256[] calldata values,
|
||||
bytes calldata
|
||||
) external override returns (bytes4){
|
||||
require(ids.length == values.length, "PARAMS_NOT_MATCH");
|
||||
for(uint256 i = 0; i < ids.length; i++) {
|
||||
emit AddNftToken(msg.sender, ids[i], values[i]);
|
||||
}
|
||||
return IERC1155Receiver.onERC1155BatchReceived.selector;
|
||||
}
|
||||
}
|
||||
17
contracts/CollateralVault/intf/ICollateralVault.sol
Normal file
17
contracts/CollateralVault/intf/ICollateralVault.sol
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
|
||||
interface ICollateralVault {
|
||||
function _OWNER_() external returns (address);
|
||||
|
||||
function init(address owner, string memory name, string memory baseURI) external;
|
||||
|
||||
function directTransferOwnership(address newOwner) external;
|
||||
}
|
||||
161
contracts/DODODrops/DODODropsV1.sol
Normal file
161
contracts/DODODrops/DODODropsV1.sol
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {IERC20} from "../intf/IERC20.sol";
|
||||
import {SafeERC20} from "../lib/SafeERC20.sol";
|
||||
import {SafeMath} from "../lib/SafeMath.sol";
|
||||
import {IRandomGenerator} from "../lib/RandomGenerator.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
import {Address} from "../external/utils/Address.sol";
|
||||
import {ERC721URIStorage} from "../external/ERC721/ERC721URIStorage.sol";
|
||||
|
||||
contract DODODropsV1 is ERC721URIStorage, InitializableOwnable {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
using Address for address;
|
||||
|
||||
// ============ Storage ============
|
||||
|
||||
mapping(address => uint256) _USER_TICKETS_;
|
||||
uint256 public _TOTAL_TICKETS_;
|
||||
|
||||
uint256 public _CUR_SELLING_TICKETS_;
|
||||
uint256 public _CUR_PRCIE_;
|
||||
uint256 public _TICKET_UNIT_ = 1; // ticket consumed in a single lottery
|
||||
|
||||
uint256[] public _TOKEN_IDS_;
|
||||
|
||||
address public _RANDOM_GENERATOR_;
|
||||
|
||||
bool public _REDEEM_ALLOWED_ = true;
|
||||
|
||||
|
||||
// ============ Event =============
|
||||
event ChangeRandomGenerator(address randomGenerator);
|
||||
event ChangeTicketUnit(uint256 newTicketUnit);
|
||||
event ChangeSellingInfo(uint256 curSellingTickets, uint256 curPrice);
|
||||
event Withdraw(address account, uint256 amount);
|
||||
event BatchMint(uint256 mintAmount);
|
||||
event BuyTicket(address account, uint256 value, uint256 tickets);
|
||||
event RedeemPrize(address account, uint256 tokenId);
|
||||
event DisableRedeem();
|
||||
event EnableRedeem();
|
||||
|
||||
fallback() external payable {}
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
function init(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory baseUri,
|
||||
address owner,
|
||||
address randomGenerator
|
||||
) external {
|
||||
require(owner != address(0));
|
||||
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_baseUri = baseUri;
|
||||
|
||||
initOwner(owner);
|
||||
_RANDOM_GENERATOR_ = randomGenerator;
|
||||
}
|
||||
|
||||
function buyTicket() payable external {
|
||||
uint256 buyAmount = msg.value;
|
||||
require(buyAmount >= _CUR_PRCIE_, "BNB_NOT_ENOUGH");
|
||||
uint256 tickets = buyAmount.div(_CUR_PRCIE_);
|
||||
require(tickets <= _CUR_SELLING_TICKETS_, "TICKETS_NOT_ENOUGH");
|
||||
_USER_TICKETS_[msg.sender] = _USER_TICKETS_[msg.sender].add(tickets);
|
||||
_TOTAL_TICKETS_ = _TOTAL_TICKETS_.add(tickets);
|
||||
_CUR_SELLING_TICKETS_ = _CUR_SELLING_TICKETS_.sub(tickets);
|
||||
|
||||
uint256 leftOver = msg.value - tickets.mul(_CUR_PRCIE_);
|
||||
if(leftOver > 0)
|
||||
msg.sender.transfer(leftOver);
|
||||
emit BuyTicket(msg.sender, buyAmount - leftOver, tickets);
|
||||
}
|
||||
|
||||
|
||||
function redeemPrize(uint256 ticketNum) external {
|
||||
require(_REDEEM_ALLOWED_, "REDEEM_CLOSED");
|
||||
// require(!address(msg.sender).isContract(), "ONLY_ALLOW_EOA");
|
||||
require(tx.origin == msg.sender, "ONLY_ALLOW_EOA");
|
||||
require(ticketNum >= 1 && ticketNum <= _USER_TICKETS_[msg.sender], "TICKET_NUM_INVALID");
|
||||
_USER_TICKETS_[msg.sender] = _USER_TICKETS_[msg.sender].sub(ticketNum);
|
||||
_TOTAL_TICKETS_ = _TOTAL_TICKETS_.sub(ticketNum);
|
||||
for (uint256 i = 0; i < ticketNum; i++) {
|
||||
_redeemSinglePrize(msg.sender);
|
||||
}
|
||||
}
|
||||
|
||||
// ================= View ===================
|
||||
function getTickets(address account) view external returns(uint256) {
|
||||
return _USER_TICKETS_[account];
|
||||
}
|
||||
|
||||
// =============== Internal ================
|
||||
|
||||
function _redeemSinglePrize(address to) internal {
|
||||
uint256 range = _TOKEN_IDS_.length;
|
||||
uint256 random = IRandomGenerator(_RANDOM_GENERATOR_).random(gasleft()) % range;
|
||||
uint256 prizeId = _TOKEN_IDS_[random];
|
||||
|
||||
if(random != range - 1) {
|
||||
_TOKEN_IDS_[random] = _TOKEN_IDS_[range - 1];
|
||||
}
|
||||
_TOKEN_IDS_.pop();
|
||||
_safeTransfer(address(this), to, prizeId, "");
|
||||
emit RedeemPrize(to, prizeId);
|
||||
}
|
||||
|
||||
// ================= Owner ===================
|
||||
|
||||
function disableRedeemPrize() external onlyOwner {
|
||||
_REDEEM_ALLOWED_ = false;
|
||||
emit DisableRedeem();
|
||||
}
|
||||
|
||||
function enableRedeemPrize() external onlyOwner {
|
||||
_REDEEM_ALLOWED_ = true;
|
||||
emit EnableRedeem();
|
||||
}
|
||||
|
||||
function updateRandomGenerator(address newRandomGenerator) external onlyOwner {
|
||||
require(newRandomGenerator != address(0));
|
||||
_RANDOM_GENERATOR_ = newRandomGenerator;
|
||||
emit ChangeRandomGenerator(newRandomGenerator);
|
||||
}
|
||||
|
||||
function updateSellingInfo(uint256 newSellingTickets, uint256 newPrice) external onlyOwner {
|
||||
_CUR_SELLING_TICKETS_ = newSellingTickets;
|
||||
_CUR_PRCIE_ = newPrice;
|
||||
emit ChangeSellingInfo(newSellingTickets, newPrice);
|
||||
}
|
||||
|
||||
function updateTicketUnit(uint256 newTicketUnit) external onlyOwner {
|
||||
require(newTicketUnit != 0);
|
||||
_TICKET_UNIT_ = newTicketUnit;
|
||||
emit ChangeTicketUnit(newTicketUnit);
|
||||
}
|
||||
|
||||
function withdraw() external onlyOwner {
|
||||
uint256 amount = address(this).balance;
|
||||
msg.sender.transfer(amount);
|
||||
emit Withdraw(msg.sender, amount);
|
||||
}
|
||||
|
||||
function batchMint(uint256[] calldata ids, string[] calldata urls) external onlyOwner {
|
||||
for(uint256 i = 0; i < ids.length; i++) {
|
||||
_mint(address(this), ids[i]);
|
||||
_TOKEN_IDS_.push(ids[i]);
|
||||
_setTokenURI(ids[i], urls[i]);
|
||||
}
|
||||
emit BatchMint(ids.length);
|
||||
}
|
||||
}
|
||||
350
contracts/DODODrops/DODODropsV2/DODODrops.sol
Normal file
350
contracts/DODODrops/DODODropsV2/DODODrops.sol
Normal file
@@ -0,0 +1,350 @@
|
||||
/*
|
||||
Copyright 2021 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {UniversalERC20} from "../../SmartRoute/lib/UniversalERC20.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {Address} from "../../external/utils/Address.sol";
|
||||
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
|
||||
import {IRandomGenerator} from "../../lib/RandomGenerator.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {InitializableMintableERC20} from "../../external/ERC20/InitializableMintableERC20.sol";
|
||||
|
||||
interface IDropsFeeModel {
|
||||
function getPayAmount(address dodoDrops, address user, uint256 originalPrice, uint256 ticketAmount) external view returns (uint256, uint256);
|
||||
}
|
||||
|
||||
interface IDropsNft {
|
||||
function mint(address to, uint256 tokenId) external;
|
||||
function mint(address account, uint256 id, uint256 amount, bytes memory data) external;
|
||||
}
|
||||
|
||||
contract DODODrops is InitializableMintableERC20, ReentrancyGuard {
|
||||
using SafeMath for uint256;
|
||||
using Address for address;
|
||||
using UniversalERC20 for IERC20;
|
||||
|
||||
// ============ Storage ============
|
||||
address constant _BASE_COIN_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
|
||||
address public _BUY_TOKEN_;
|
||||
uint256 public _BUY_TOKEN_RESERVE_;
|
||||
address public _FEE_MODEL_;
|
||||
address payable public _MAINTAINER_;
|
||||
address public _NFT_TOKEN_;
|
||||
|
||||
uint256 public _TICKET_UNIT_ = 1; // ticket consumed in a single lottery
|
||||
|
||||
uint256 [] public _SELLING_TIME_INTERVAL_;
|
||||
uint256 [] public _SELLING_PRICE_SET_;
|
||||
uint256 [] public _SELLING_AMOUNT_SET_;
|
||||
uint256 public _REDEEM_ALLOWED_TIME_;
|
||||
|
||||
uint256[] public _PROB_INTERVAL_; // index => Interval probability (Only For ProbMode)
|
||||
uint256[][] public _TOKEN_ID_MAP_; // Interval index => tokenIds (Only For ProbMode)
|
||||
|
||||
uint256[] public _TOKEN_ID_LIST_; //index => tokenId (Only For FixedAmount mode)
|
||||
|
||||
bool public _IS_PROB_MODE_; // false = FixedAmount mode, true = ProbMode
|
||||
bool public _IS_REVEAL_MODE_;
|
||||
uint256 public _REVEAL_RN_ = 0;
|
||||
address public _RNG_;
|
||||
|
||||
bool public _CAN_TRANSFER_;
|
||||
|
||||
fallback() external payable {}
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
// ============ Modifiers ============
|
||||
|
||||
modifier notStart() {
|
||||
require(block.timestamp < _SELLING_TIME_INTERVAL_[0] || _SELLING_TIME_INTERVAL_[0] == 0, "ALREADY_START");
|
||||
_;
|
||||
}
|
||||
|
||||
modifier buyTicketsFinish() {
|
||||
require(block.timestamp > _SELLING_TIME_INTERVAL_[_SELLING_TIME_INTERVAL_.length - 1] && _SELLING_TIME_INTERVAL_[0] != 0, "BUY_TICKETS_NOT_FINISH");
|
||||
_;
|
||||
}
|
||||
|
||||
modifier canTransfer() {
|
||||
require(_CAN_TRANSFER_, "DropsTickets: not allowed transfer");
|
||||
_;
|
||||
}
|
||||
|
||||
// ============ Event =============
|
||||
event BuyTicket(address account, uint256 payAmount, uint256 feeAmount, uint256 ticketAmount);
|
||||
event RedeemPrize(address account, uint256 tokenId, address referer);
|
||||
|
||||
event ChangeRNG(address rng);
|
||||
event ChangeRedeemTime(uint256 redeemTime);
|
||||
event ChangeTicketUnit(uint256 newTicketUnit);
|
||||
event Withdraw(address account, uint256 amount);
|
||||
event SetReveal();
|
||||
|
||||
event SetSellingInfo();
|
||||
event SetProbInfo(); // only for ProbMode
|
||||
event SetTokenIdMapByIndex(uint256 index); // only for ProbMode
|
||||
event SetFixedAmountInfo(); // only for FixedAmount mode
|
||||
|
||||
event SetCantransfer(bool allowed);
|
||||
|
||||
|
||||
function init(
|
||||
address[] memory addrList, //0 owner, 1 buyToken, 2 feeModel, 3 defaultMaintainer 4 rng 5 nftToken
|
||||
uint256[] memory sellingTimeInterval,
|
||||
uint256[] memory sellingPrice,
|
||||
uint256[] memory sellingAmount,
|
||||
uint256 redeemAllowedTime,
|
||||
bool isRevealMode,
|
||||
bool isProbMode
|
||||
) public {
|
||||
_BUY_TOKEN_ = addrList[1];
|
||||
_FEE_MODEL_ = addrList[2];
|
||||
_MAINTAINER_ = payable(addrList[3]);
|
||||
_RNG_ = addrList[4];
|
||||
_NFT_TOKEN_ = addrList[5];
|
||||
|
||||
_IS_REVEAL_MODE_ = isRevealMode;
|
||||
_IS_PROB_MODE_ = isProbMode;
|
||||
_REDEEM_ALLOWED_TIME_ = redeemAllowedTime;
|
||||
|
||||
if(sellingTimeInterval.length > 0) _setSellingInfo(sellingTimeInterval, sellingPrice, sellingAmount);
|
||||
|
||||
string memory prefix = "DROPS_";
|
||||
name = string(abi.encodePacked(prefix, addressToShortString(address(this))));
|
||||
symbol = name;
|
||||
decimals = 0;
|
||||
|
||||
//init Owner
|
||||
super.init(addrList[0], 0, name, symbol, decimals);
|
||||
}
|
||||
|
||||
function buyTickets(address ticketTo, uint256 ticketAmount) payable external preventReentrant {
|
||||
(uint256 curPrice, uint256 sellAmount, uint256 index) = getSellingInfo();
|
||||
require(curPrice > 0 && sellAmount > 0, "CAN_NOT_BUY");
|
||||
require(ticketAmount <= sellAmount, "TICKETS_NOT_ENOUGH");
|
||||
(uint256 payAmount, uint256 feeAmount) = IDropsFeeModel(_FEE_MODEL_).getPayAmount(address(this), ticketTo, curPrice, ticketAmount);
|
||||
require(payAmount > 0, "UnQualified");
|
||||
|
||||
uint256 baseBalance = IERC20(_BUY_TOKEN_).universalBalanceOf(address(this));
|
||||
uint256 buyInput = baseBalance.sub(_BUY_TOKEN_RESERVE_);
|
||||
|
||||
require(payAmount <= buyInput, "PAY_AMOUNT_NOT_ENOUGH");
|
||||
|
||||
_SELLING_AMOUNT_SET_[index] = sellAmount.sub(ticketAmount);
|
||||
_BUY_TOKEN_RESERVE_ = baseBalance.sub(feeAmount);
|
||||
|
||||
IERC20(_BUY_TOKEN_).universalTransfer(_MAINTAINER_,feeAmount);
|
||||
_mint(ticketTo, ticketAmount);
|
||||
emit BuyTicket(ticketTo, payAmount, feeAmount, ticketAmount);
|
||||
}
|
||||
|
||||
function redeemTicket(uint256 ticketNum, address referer) external {
|
||||
// require(!address(msg.sender).isContract(), "ONLY_ALLOW_EOA");
|
||||
require(tx.origin == msg.sender, "ONLY_ALLOW_EOA");
|
||||
require(ticketNum >= 1 && ticketNum <= balanceOf(msg.sender), "TICKET_NUM_INVALID");
|
||||
_burn(msg.sender,ticketNum);
|
||||
for (uint256 i = 0; i < ticketNum; i++) {
|
||||
_redeemSinglePrize(msg.sender, i, referer);
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Internal ============
|
||||
|
||||
function _redeemSinglePrize(address to, uint256 curNo, address referer) internal {
|
||||
require(block.timestamp >= _REDEEM_ALLOWED_TIME_ && _REDEEM_ALLOWED_TIME_ != 0, "REDEEM_CLOSE");
|
||||
uint256 range;
|
||||
if(_IS_PROB_MODE_) {
|
||||
range = _PROB_INTERVAL_[_PROB_INTERVAL_.length - 1];
|
||||
}else {
|
||||
range = _TOKEN_ID_LIST_.length;
|
||||
}
|
||||
uint256 random;
|
||||
if(_IS_REVEAL_MODE_) {
|
||||
require(_REVEAL_RN_ != 0, "REVEAL_NOT_SET");
|
||||
random = uint256(keccak256(abi.encodePacked(_REVEAL_RN_, msg.sender, balanceOf(msg.sender).add(curNo + 1)))) % range;
|
||||
}else {
|
||||
random = IRandomGenerator(_RNG_).random(gasleft() + block.number) % range;
|
||||
}
|
||||
uint256 tokenId;
|
||||
if(_IS_PROB_MODE_) {
|
||||
uint256 i;
|
||||
for (i = 0; i < _PROB_INTERVAL_.length; i++) {
|
||||
if (random <= _PROB_INTERVAL_[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
require(_TOKEN_ID_MAP_[i].length > 0, "EMPTY_TOKEN_ID_MAP");
|
||||
tokenId = _TOKEN_ID_MAP_[i][random % _TOKEN_ID_MAP_[i].length];
|
||||
IDropsNft(_NFT_TOKEN_).mint(to, tokenId, 1, "");
|
||||
} else {
|
||||
tokenId = _TOKEN_ID_LIST_[random];
|
||||
if(random != range - 1) {
|
||||
_TOKEN_ID_LIST_[random] = _TOKEN_ID_LIST_[range - 1];
|
||||
}
|
||||
_TOKEN_ID_LIST_.pop();
|
||||
IDropsNft(_NFT_TOKEN_).mint(to, tokenId);
|
||||
}
|
||||
emit RedeemPrize(to, tokenId, referer);
|
||||
}
|
||||
|
||||
|
||||
function _setSellingInfo(uint256[] memory sellingTimeIntervals, uint256[] memory sellingPrice, uint256[] memory sellingAmount) internal {
|
||||
require(sellingTimeIntervals.length > 0, "PARAM_NOT_INVALID");
|
||||
require(sellingTimeIntervals.length == sellingPrice.length && sellingPrice.length == sellingAmount.length, "PARAM_NOT_INVALID");
|
||||
for (uint256 i = 0; i < sellingTimeIntervals.length - 1; i++) {
|
||||
require(sellingTimeIntervals[i] < sellingTimeIntervals[i + 1], "INTERVAL_INVALID");
|
||||
require(sellingPrice[i] != 0, "PRICE_INVALID");
|
||||
}
|
||||
if(_IS_REVEAL_MODE_) {
|
||||
require(sellingAmount[sellingTimeIntervals.length - 1] == 0, "AMOUNT_INVALID");
|
||||
require(sellingPrice[sellingTimeIntervals.length - 1] == 0, "PRICE_INVALID");
|
||||
}
|
||||
_SELLING_TIME_INTERVAL_ = sellingTimeIntervals;
|
||||
_SELLING_PRICE_SET_ = sellingPrice;
|
||||
_SELLING_AMOUNT_SET_ = sellingAmount;
|
||||
emit SetSellingInfo();
|
||||
}
|
||||
|
||||
|
||||
function _setProbInfo(uint256[] memory probIntervals,uint256[][] memory tokenIdMap) internal {
|
||||
require(_IS_PROB_MODE_, "ONLY_ALLOW_PROB_MODE");
|
||||
require(probIntervals.length > 0, "PARAM_NOT_INVALID");
|
||||
require(tokenIdMap.length == probIntervals.length, "PARAM_NOT_INVALID");
|
||||
|
||||
require(tokenIdMap[0].length > 0, "INVALID");
|
||||
for (uint256 i = 1; i < probIntervals.length; i++) {
|
||||
require(probIntervals[i] > probIntervals[i - 1], "INTERVAL_INVALID");
|
||||
require(tokenIdMap[i].length > 0, "INVALID");
|
||||
}
|
||||
_PROB_INTERVAL_ = probIntervals;
|
||||
_TOKEN_ID_MAP_ = tokenIdMap;
|
||||
emit SetProbInfo();
|
||||
}
|
||||
|
||||
function _setFixedAmountInfo(uint256[] memory tokenIdList) internal {
|
||||
require(!_IS_PROB_MODE_, "ONLY_ALLOW_FIXED_AMOUNT_MODE");
|
||||
require(tokenIdList.length > 0, "PARAM_NOT_INVALID");
|
||||
_TOKEN_ID_LIST_ = tokenIdList;
|
||||
emit SetFixedAmountInfo();
|
||||
}
|
||||
|
||||
|
||||
function approve(address spender, uint256 amount) canTransfer public override returns (bool) {
|
||||
return super.approve(spender, amount);
|
||||
}
|
||||
|
||||
function transferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
) canTransfer public override returns (bool) {
|
||||
return super.transferFrom(from, to, amount);
|
||||
}
|
||||
|
||||
function transfer(address to, uint256 amount) canTransfer public override returns (bool) {
|
||||
return super.transfer(to, amount);
|
||||
}
|
||||
|
||||
// ================= Owner ===================
|
||||
function setCantransfer(bool allowed) public onlyOwner {
|
||||
_CAN_TRANSFER_ = allowed;
|
||||
emit SetCantransfer(allowed);
|
||||
}
|
||||
|
||||
function withdraw() external onlyOwner {
|
||||
uint256 amount = IERC20(_BUY_TOKEN_).universalBalanceOf(address(this));
|
||||
IERC20(_BUY_TOKEN_).universalTransfer(msg.sender ,amount);
|
||||
emit Withdraw(msg.sender, amount);
|
||||
}
|
||||
|
||||
function setRevealRn() buyTicketsFinish external onlyOwner {
|
||||
require(_REVEAL_RN_ == 0, "ALREADY_SET");
|
||||
require(!_CAN_TRANSFER_, "NEED_CLOSE_TRANSFER");
|
||||
_REVEAL_RN_ = uint256(keccak256(abi.encodePacked(blockhash(block.number - 1))));
|
||||
emit SetReveal();
|
||||
}
|
||||
|
||||
function setSellingInfo(uint256[] memory sellingTimeIntervals, uint256[] memory prices, uint256[] memory amounts) external notStart() onlyOwner {
|
||||
_setSellingInfo(sellingTimeIntervals, prices, amounts);
|
||||
}
|
||||
|
||||
function setProbInfo(uint256[] memory probIntervals,uint256[][] memory tokenIdMaps) external notStart() onlyOwner {
|
||||
_setProbInfo(probIntervals, tokenIdMaps);
|
||||
}
|
||||
|
||||
function setFixedAmountInfo(uint256[] memory tokenIdList) external notStart() onlyOwner {
|
||||
_setFixedAmountInfo(tokenIdList);
|
||||
}
|
||||
|
||||
function addFixedAmountInfo(uint256[] memory addTokenIdList) external notStart() onlyOwner {
|
||||
for (uint256 i = 0; i < addTokenIdList.length; i++) {
|
||||
_TOKEN_ID_LIST_.push(addTokenIdList[i]);
|
||||
}
|
||||
emit SetFixedAmountInfo();
|
||||
}
|
||||
|
||||
function setTokenIdMapByIndex(uint256 index, uint256[] memory tokenIds) external notStart() onlyOwner {
|
||||
require(_IS_PROB_MODE_, "ONLY_ALLOW_PROB_MODE");
|
||||
require(tokenIds.length > 0 && index < _TOKEN_ID_MAP_.length,"PARAM_NOT_INVALID");
|
||||
_TOKEN_ID_MAP_[index] = tokenIds;
|
||||
emit SetTokenIdMapByIndex(index);
|
||||
}
|
||||
|
||||
function updateRNG(address newRNG) external onlyOwner {
|
||||
require(newRNG != address(0));
|
||||
_RNG_ = newRNG;
|
||||
emit ChangeRNG(newRNG);
|
||||
}
|
||||
|
||||
function updateTicketUnit(uint256 newTicketUnit) external onlyOwner {
|
||||
require(newTicketUnit != 0);
|
||||
_TICKET_UNIT_ = newTicketUnit;
|
||||
emit ChangeTicketUnit(newTicketUnit);
|
||||
}
|
||||
|
||||
function updateRedeemTime(uint256 newRedeemTime) external onlyOwner {
|
||||
require(newRedeemTime > block.timestamp || newRedeemTime == 0, "PARAM_NOT_INVALID");
|
||||
_REDEEM_ALLOWED_TIME_ = newRedeemTime;
|
||||
emit ChangeRedeemTime(newRedeemTime);
|
||||
}
|
||||
|
||||
// ================= View ===================
|
||||
|
||||
function getSellingStage() public view returns (uint256 stageLen) {
|
||||
stageLen = _SELLING_TIME_INTERVAL_.length;
|
||||
}
|
||||
|
||||
function getSellingInfo() public view returns (uint256 curPrice, uint256 sellAmount, uint256 index) {
|
||||
uint256 curBlockTime = block.timestamp;
|
||||
if(curBlockTime >= _SELLING_TIME_INTERVAL_[0] && _SELLING_TIME_INTERVAL_[0] != 0) {
|
||||
uint256 i;
|
||||
for (i = 1; i < _SELLING_TIME_INTERVAL_.length; i++) {
|
||||
if (curBlockTime <= _SELLING_TIME_INTERVAL_[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
curPrice = _SELLING_PRICE_SET_[i-1];
|
||||
sellAmount = _SELLING_AMOUNT_SET_[i-1];
|
||||
index = i - 1;
|
||||
}
|
||||
}
|
||||
|
||||
function addressToShortString(address _addr) public pure returns (string memory) {
|
||||
bytes32 value = bytes32(uint256(_addr));
|
||||
bytes memory alphabet = "0123456789abcdef";
|
||||
|
||||
bytes memory str = new bytes(8);
|
||||
for (uint256 i = 0; i < 4; i++) {
|
||||
str[i * 2] = alphabet[uint8(value[i + 12] >> 4)];
|
||||
str[1 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)];
|
||||
}
|
||||
return string(str);
|
||||
}
|
||||
}
|
||||
55
contracts/DODODrops/DODODropsV2/DropsERC1155.sol
Normal file
55
contracts/DODODrops/DODODropsV2/DropsERC1155.sol
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
|
||||
Copyright 2021 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ERC1155} from "../../external/ERC1155/ERC1155.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {Strings} from "../../external/utils/Strings.sol";
|
||||
|
||||
contract DropsERC1155 is ERC1155, InitializableOwnable {
|
||||
using Strings for uint256;
|
||||
|
||||
mapping (address => bool) public _IS_ALLOWED_MINT_;
|
||||
string internal _baseUri = "";
|
||||
|
||||
// ============ Event =============
|
||||
event addMinter(address account);
|
||||
event removeMinter(address account);
|
||||
|
||||
function addMintAccount(address account) public onlyOwner {
|
||||
_IS_ALLOWED_MINT_[account] = true;
|
||||
emit addMinter(account);
|
||||
}
|
||||
|
||||
function removeMintAccount(address account) public onlyOwner {
|
||||
_IS_ALLOWED_MINT_[account] = false;
|
||||
emit removeMinter(account);
|
||||
}
|
||||
|
||||
function init(
|
||||
address owner,
|
||||
string memory uri
|
||||
) public {
|
||||
initOwner(owner);
|
||||
_baseUri = uri;
|
||||
}
|
||||
|
||||
function mint(address account, uint256 id, uint256 amount, bytes memory data) external {
|
||||
require(_IS_ALLOWED_MINT_[msg.sender], "Mint restricted");
|
||||
_mint(account, id, amount, data);
|
||||
}
|
||||
|
||||
function uri(uint256 tokenId) public view override returns (string memory) {
|
||||
string memory baseURI = _baseUri;
|
||||
|
||||
return bytes(baseURI).length > 0
|
||||
? string(abi.encodePacked(baseURI, tokenId.toString()))
|
||||
: '';
|
||||
}
|
||||
}
|
||||
47
contracts/DODODrops/DODODropsV2/DropsERC721.sol
Normal file
47
contracts/DODODrops/DODODropsV2/DropsERC721.sol
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
|
||||
Copyright 2021 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ERC721Enumerable} from "../../external/ERC721/ERC721Enumerable.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
|
||||
contract DropsERC721 is ERC721Enumerable, InitializableOwnable {
|
||||
mapping (address => bool) public _IS_ALLOWED_MINT_;
|
||||
|
||||
// ============ Event =============
|
||||
event addMinter(address account);
|
||||
event removeMinter(address account);
|
||||
|
||||
function addMintAccount(address account) public onlyOwner {
|
||||
_IS_ALLOWED_MINT_[account] = true;
|
||||
emit addMinter(account);
|
||||
}
|
||||
|
||||
function removeMintAccount(address account) public onlyOwner {
|
||||
_IS_ALLOWED_MINT_[account] = false;
|
||||
emit removeMinter(account);
|
||||
}
|
||||
|
||||
function init(
|
||||
address owner,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory uri
|
||||
) public {
|
||||
initOwner(owner);
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_baseUri = uri;
|
||||
}
|
||||
|
||||
function mint(address to, uint256 tokenId) external {
|
||||
require(_IS_ALLOWED_MINT_[msg.sender], "restricted");
|
||||
_mint(to, tokenId);
|
||||
}
|
||||
}
|
||||
78
contracts/DODODrops/DODODropsV2/DropsFeeModel.sol
Normal file
78
contracts/DODODrops/DODODropsV2/DropsFeeModel.sol
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
|
||||
Copyright 2021 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
|
||||
interface IFee {
|
||||
function getUserFee(address user,uint256 ticketAmount) external view returns (uint256);
|
||||
}
|
||||
|
||||
interface IPrice {
|
||||
function getUserPrice(address user, uint256 originalPrice, uint256 ticketAmount) external view returns (uint256);
|
||||
}
|
||||
|
||||
contract DropsFeeModel is InitializableOwnable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
struct DropBoxInfo {
|
||||
bool isSet;
|
||||
uint256 globalFee;
|
||||
address feeAddr;
|
||||
address priceAddr;
|
||||
}
|
||||
|
||||
mapping(address => DropBoxInfo) dropBoxes;
|
||||
|
||||
// ============ Event =============
|
||||
event AddDropBoxInfo(address dropBox, uint256 globalFee, address feeAddr, address priceAddr);
|
||||
event SetDropBoxInfo(address dropBox, uint256 globalFee, address feeAddr, address priceAddr);
|
||||
|
||||
|
||||
function addDropBoxInfo(address dropBox, uint256 globalFee, address feeAddr, address priceAddr) external onlyOwner {
|
||||
DropBoxInfo memory dropBoxInfo = DropBoxInfo({
|
||||
isSet: true,
|
||||
globalFee: globalFee,
|
||||
feeAddr: feeAddr,
|
||||
priceAddr: priceAddr
|
||||
});
|
||||
dropBoxes[dropBox] = dropBoxInfo;
|
||||
emit AddDropBoxInfo(dropBox, globalFee, feeAddr, priceAddr);
|
||||
}
|
||||
|
||||
function setDropBoxInfo(address dropBox, uint256 globalFee, address feeAddr, address priceAddr) external onlyOwner {
|
||||
require(dropBoxes[dropBox].isSet, "NOT_FOUND_BOX");
|
||||
dropBoxes[dropBox].globalFee = globalFee;
|
||||
dropBoxes[dropBox].feeAddr = feeAddr;
|
||||
dropBoxes[dropBox].priceAddr = priceAddr;
|
||||
emit SetDropBoxInfo(dropBox, globalFee, feeAddr, priceAddr);
|
||||
}
|
||||
|
||||
function getPayAmount(address dropBox, address user, uint256 originalPrice, uint256 ticketAmount) external view returns (uint256 payAmount, uint256 feeAmount) {
|
||||
DropBoxInfo memory dropBoxInfo = dropBoxes[dropBox];
|
||||
if(!dropBoxInfo.isSet) {
|
||||
payAmount = originalPrice.mul(ticketAmount);
|
||||
feeAmount = 0;
|
||||
} else {
|
||||
uint256 feeRate = dropBoxInfo.globalFee;
|
||||
address feeAddr = dropBoxInfo.feeAddr;
|
||||
if(feeAddr != address(0))
|
||||
feeRate = IFee(feeAddr).getUserFee(user, ticketAmount);
|
||||
|
||||
uint256 price = originalPrice;
|
||||
address priceAddr = dropBoxInfo.priceAddr;
|
||||
if(priceAddr != address(0))
|
||||
price = IPrice(priceAddr).getUserPrice(user, originalPrice, ticketAmount);
|
||||
|
||||
payAmount = price.mul(ticketAmount);
|
||||
feeAmount = DecimalMath.mulFloor(payAmount, feeRate);
|
||||
}
|
||||
}
|
||||
}
|
||||
192
contracts/DODOFee/FeeDistributer.sol
Normal file
192
contracts/DODOFee/FeeDistributer.sol
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
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 {Ownable} from "../lib/Ownable.sol";
|
||||
|
||||
contract FeeDistributor {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
// ============ Storage ============
|
||||
|
||||
address public _BASE_TOKEN_;
|
||||
address public _QUOTE_TOKEN_;
|
||||
uint256 public _BASE_RESERVE_;
|
||||
uint256 public _QUOTE_RESERVE_;
|
||||
|
||||
address public _STAKE_VAULT_;
|
||||
address public _STAKE_TOKEN_;
|
||||
uint256 public _STAKE_RESERVE_;
|
||||
|
||||
uint256 public _BASE_REWARD_RATIO_;
|
||||
mapping(address => uint256) public _USER_BASE_REWARDS_;
|
||||
mapping(address => uint256) public _USER_BASE_PER_SHARE_;
|
||||
|
||||
uint256 public _QUOTE_REWARD_RATIO_;
|
||||
mapping(address => uint256) public _USER_QUOTE_REWARDS_;
|
||||
mapping(address => uint256) public _USER_QUOTE_PER_SHARE_;
|
||||
|
||||
mapping(address => uint256) public _SHARES_;
|
||||
|
||||
bool internal _FEE_INITIALIZED_;
|
||||
|
||||
// ============ Event ============
|
||||
event Stake(address sender, uint256 amount);
|
||||
event UnStake(address sender, uint256 amount);
|
||||
event Claim(address sender, uint256 baseAmount, uint256 quoteAmount);
|
||||
|
||||
function init(
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address stakeToken
|
||||
) external {
|
||||
require(!_FEE_INITIALIZED_, "ALREADY_INITIALIZED");
|
||||
_FEE_INITIALIZED_ = true;
|
||||
|
||||
_BASE_TOKEN_ = baseToken;
|
||||
_QUOTE_TOKEN_ = quoteToken;
|
||||
_STAKE_TOKEN_ = stakeToken;
|
||||
_STAKE_VAULT_ = address(new StakeVault());
|
||||
}
|
||||
|
||||
function stake(address to) external {
|
||||
_updateGlobalState();
|
||||
_updateUserReward(to);
|
||||
uint256 stakeVault = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_);
|
||||
uint256 stakeInput = stakeVault.sub(_STAKE_RESERVE_);
|
||||
_addShares(stakeInput, to);
|
||||
emit Stake(to, stakeInput);
|
||||
}
|
||||
|
||||
function claim(address to) external {
|
||||
_updateGlobalState();
|
||||
_updateUserReward(msg.sender);
|
||||
_claim(msg.sender, to);
|
||||
}
|
||||
|
||||
function unstake(
|
||||
uint256 amount,
|
||||
address to,
|
||||
bool withClaim
|
||||
) external {
|
||||
require(_SHARES_[msg.sender] >= amount, "STAKE BALANCE ONT ENOUGH");
|
||||
_updateGlobalState();
|
||||
_updateUserReward(msg.sender);
|
||||
|
||||
if (withClaim) {
|
||||
_claim(msg.sender, to);
|
||||
}
|
||||
_removeShares(amount, msg.sender);
|
||||
StakeVault(_STAKE_VAULT_).transferOut(_STAKE_TOKEN_, amount, to);
|
||||
|
||||
emit UnStake(msg.sender, amount);
|
||||
}
|
||||
|
||||
// ============ View ================
|
||||
function getPendingReward(address user)
|
||||
external
|
||||
view
|
||||
returns (uint256 baseReward, uint256 quoteReward)
|
||||
{
|
||||
uint256 baseInput = IERC20(_BASE_TOKEN_).balanceOf(address(this)).sub(_BASE_RESERVE_);
|
||||
uint256 quoteInput = IERC20(_QUOTE_TOKEN_).balanceOf(address(this)).sub(_QUOTE_RESERVE_);
|
||||
uint256 baseRwardRatio = _BASE_REWARD_RATIO_;
|
||||
uint256 quoteRewardRatio = _QUOTE_REWARD_RATIO_;
|
||||
if (_STAKE_RESERVE_ != 0) {
|
||||
baseRwardRatio = _BASE_REWARD_RATIO_.add(
|
||||
DecimalMath.divFloor(baseInput, _STAKE_RESERVE_)
|
||||
);
|
||||
quoteRewardRatio = _QUOTE_REWARD_RATIO_.add(
|
||||
DecimalMath.divFloor(quoteInput, _STAKE_RESERVE_)
|
||||
);
|
||||
}
|
||||
baseReward = DecimalMath
|
||||
.mulFloor(_SHARES_[user], baseRwardRatio.sub(_USER_BASE_PER_SHARE_[user]))
|
||||
.add(_USER_BASE_REWARDS_[user]);
|
||||
quoteReward = DecimalMath
|
||||
.mulFloor(_SHARES_[user], quoteRewardRatio.sub(_USER_QUOTE_PER_SHARE_[user]))
|
||||
.add(_USER_QUOTE_REWARDS_[user]);
|
||||
}
|
||||
|
||||
// ============ Internal ============
|
||||
|
||||
function _claim(address sender, address to) internal {
|
||||
uint256 allBase = _USER_BASE_REWARDS_[sender];
|
||||
uint256 allQuote = _USER_QUOTE_REWARDS_[sender];
|
||||
|
||||
_BASE_RESERVE_ = _BASE_RESERVE_.sub(allBase);
|
||||
_QUOTE_RESERVE_ = _QUOTE_RESERVE_.sub(allQuote);
|
||||
_USER_BASE_REWARDS_[sender] = 0;
|
||||
_USER_QUOTE_REWARDS_[sender] = 0;
|
||||
|
||||
IERC20(_BASE_TOKEN_).safeTransfer(to, allBase);
|
||||
IERC20(_QUOTE_TOKEN_).safeTransfer(to, allQuote);
|
||||
|
||||
emit Claim(sender, allBase, allQuote);
|
||||
}
|
||||
|
||||
function _updateGlobalState() internal {
|
||||
uint256 baseInput = IERC20(_BASE_TOKEN_).balanceOf(address(this)).sub(_BASE_RESERVE_);
|
||||
uint256 quoteInput = IERC20(_QUOTE_TOKEN_).balanceOf(address(this)).sub(_QUOTE_RESERVE_);
|
||||
|
||||
if (_STAKE_RESERVE_ != 0) {
|
||||
_BASE_REWARD_RATIO_ = _BASE_REWARD_RATIO_.add(
|
||||
DecimalMath.divFloor(baseInput, _STAKE_RESERVE_)
|
||||
);
|
||||
_QUOTE_REWARD_RATIO_ = _QUOTE_REWARD_RATIO_.add(
|
||||
DecimalMath.divFloor(quoteInput, _STAKE_RESERVE_)
|
||||
);
|
||||
}
|
||||
|
||||
_BASE_RESERVE_ = _BASE_RESERVE_.add(baseInput);
|
||||
_QUOTE_RESERVE_ = _QUOTE_RESERVE_.add(quoteInput);
|
||||
}
|
||||
|
||||
function _updateUserReward(address user) internal {
|
||||
_USER_BASE_REWARDS_[user] = DecimalMath
|
||||
.mulFloor(_SHARES_[user], _BASE_REWARD_RATIO_.sub(_USER_BASE_PER_SHARE_[user]))
|
||||
.add(_USER_BASE_REWARDS_[user]);
|
||||
|
||||
_USER_BASE_PER_SHARE_[user] = _BASE_REWARD_RATIO_;
|
||||
|
||||
_USER_QUOTE_REWARDS_[user] = DecimalMath
|
||||
.mulFloor(_SHARES_[user], _QUOTE_REWARD_RATIO_.sub(_USER_QUOTE_PER_SHARE_[user]))
|
||||
.add(_USER_QUOTE_REWARDS_[user]);
|
||||
|
||||
_USER_QUOTE_PER_SHARE_[user] = _QUOTE_REWARD_RATIO_;
|
||||
}
|
||||
|
||||
function _addShares(uint256 amount, address to) internal {
|
||||
_SHARES_[to] = _SHARES_[to].add(amount);
|
||||
_STAKE_RESERVE_ = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_);
|
||||
}
|
||||
|
||||
function _removeShares(uint256 amount, address from) internal {
|
||||
_SHARES_[from] = _SHARES_[from].sub(amount);
|
||||
_STAKE_RESERVE_ = IERC20(_STAKE_TOKEN_).balanceOf(_STAKE_VAULT_);
|
||||
}
|
||||
}
|
||||
|
||||
contract StakeVault is Ownable {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
function transferOut(
|
||||
address token,
|
||||
uint256 amount,
|
||||
address to
|
||||
) external onlyOwner {
|
||||
if (amount > 0) {
|
||||
IERC20(token).safeTransfer(to, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,19 @@ interface IQuota {
|
||||
contract UserQuota is Ownable, IQuota {
|
||||
|
||||
mapping(address => uint256) public userQuota;
|
||||
uint256 constant quota = 375 * 10**6; //For example 375u on eth
|
||||
|
||||
event SetQuota(address user, uint256 amount);
|
||||
|
||||
function setUserQuota(address[] memory users) external onlyOwner {
|
||||
function setUserQuota(address[] memory users, uint256[] memory quotas) external onlyOwner {
|
||||
require(users.length == quotas.length, "PARAMS_LENGTH_NOT_MATCH");
|
||||
for(uint256 i = 0; i< users.length; i++) {
|
||||
require(users[i] != address(0), "USER_INVALID");
|
||||
userQuota[users[i]] = quota;
|
||||
userQuota[users[i]] = quotas[i];
|
||||
emit SetQuota(users[i],quotas[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function getUserQuota(address user) override external view returns (int) {
|
||||
return int(userQuota[user]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../../lib/Ownable.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
|
||||
interface IMemSource {
|
||||
function getMemLevel(address user) external returns (uint256);
|
||||
}
|
||||
|
||||
contract MemRegistry is Ownable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
address[] internal _VALID_MEM_SOURCE_LIST_;
|
||||
mapping(address => bool) internal _VALID_MEM_SOURCE_;
|
||||
mapping(address => uint256) internal _MEM_SOURCE_WEIGHT_;
|
||||
|
||||
function getMemLevel(address user) public returns (uint256 memLevel) {
|
||||
for (uint8 i = 0; i < _VALID_MEM_SOURCE_LIST_.length; i++) {
|
||||
address _source = _VALID_MEM_SOURCE_LIST_[i];
|
||||
memLevel = memLevel.add(
|
||||
IMemSource(_source).getMemLevel(user).mul(_MEM_SOURCE_WEIGHT_[_source])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function setMemSourceWeight(address source, uint256 weight) external onlyOwner {
|
||||
_MEM_SOURCE_WEIGHT_[source] = weight;
|
||||
}
|
||||
|
||||
function addMemSource(address source) external onlyOwner {
|
||||
require(!_VALID_MEM_SOURCE_[source], "SOURCE_ALREADY_EXIST");
|
||||
_VALID_MEM_SOURCE_LIST_.push(source);
|
||||
_VALID_MEM_SOURCE_[source] = true;
|
||||
}
|
||||
|
||||
function removeMemSource(address source) external onlyOwner {
|
||||
require(_VALID_MEM_SOURCE_[source], "SOURCE_NOT_EXIST");
|
||||
for (uint8 i = 0; i <= _VALID_MEM_SOURCE_LIST_.length - 1; i++) {
|
||||
if (_VALID_MEM_SOURCE_LIST_[i] == source) {
|
||||
_VALID_MEM_SOURCE_LIST_[i] = _VALID_MEM_SOURCE_LIST_[_VALID_MEM_SOURCE_LIST_
|
||||
.length - 1];
|
||||
_VALID_MEM_SOURCE_LIST_.pop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
_VALID_MEM_SOURCE_[source] = false;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../../lib/Ownable.sol";
|
||||
import {IPermissionManager} from "../../lib/PermissionManager.sol";
|
||||
import {IMemSource} from "./MemSourceStake.sol";
|
||||
|
||||
contract MemPermission is Ownable {
|
||||
uint256 public _MEM_LEVEL_THRESHOLD_;
|
||||
address public _MEM_LEVEL_SOURCE_;
|
||||
|
||||
constructor(address memLevelSource, uint256 memLevelThreshold) public {
|
||||
_MEM_LEVEL_THRESHOLD_ = memLevelThreshold;
|
||||
_MEM_LEVEL_SOURCE_ = memLevelSource;
|
||||
}
|
||||
|
||||
function isAllowed(address account) external returns (bool) {
|
||||
return IMemSource(_MEM_LEVEL_SOURCE_).getMemLevel(account) >= _MEM_LEVEL_THRESHOLD_;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../../lib/Ownable.sol";
|
||||
import {IMemSource} from "./MemAggregator.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
|
||||
contract MemSourceHold is Ownable, IMemSource {
|
||||
address public _DODO_TOKEN_;
|
||||
|
||||
constructor(address dodoToken) public {
|
||||
_DODO_TOKEN_ = dodoToken;
|
||||
}
|
||||
|
||||
// ============ View Function ============
|
||||
|
||||
function getMemLevel(address user) external override returns (uint256) {
|
||||
return IERC20(_DODO_TOKEN_).balanceOf(user);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Ownable} from "../../lib/Ownable.sol";
|
||||
import {IMemSource} from "./MemAggregator.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
|
||||
contract MemSourceStake is Ownable, IMemSource {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
address public _DODO_TOKEN_;
|
||||
uint256 public _DODO_RESERVE_;
|
||||
uint256 public _COLD_DOWN_DURATION_;
|
||||
|
||||
mapping(address => uint256) internal _STAKED_DODO_;
|
||||
mapping(address => uint256) internal _PENDING_DODO_;
|
||||
mapping(address => uint256) internal _EXECUTE_TIME_;
|
||||
|
||||
constructor(address dodoToken) public {
|
||||
_DODO_TOKEN_ = dodoToken;
|
||||
}
|
||||
|
||||
// ============ Owner Function ============
|
||||
|
||||
function setColdDownDuration(uint256 coldDownDuration) external onlyOwner {
|
||||
_COLD_DOWN_DURATION_ = coldDownDuration;
|
||||
}
|
||||
|
||||
// ============ DODO Function ============
|
||||
|
||||
function admitStakedDODO(address to) external {
|
||||
uint256 dodoInput = IERC20(_DODO_TOKEN_).balanceOf(address(this)).sub(_DODO_RESERVE_);
|
||||
_STAKED_DODO_[to] = _STAKED_DODO_[to].add(dodoInput);
|
||||
_sync();
|
||||
}
|
||||
|
||||
function stakeDODO(uint256 amount) external {
|
||||
_transferDODOIn(msg.sender, amount);
|
||||
_STAKED_DODO_[msg.sender] = _STAKED_DODO_[msg.sender].add(amount);
|
||||
_sync();
|
||||
}
|
||||
|
||||
function requestDODOWithdraw(uint256 amount) external {
|
||||
_STAKED_DODO_[msg.sender] = _STAKED_DODO_[msg.sender].sub(amount);
|
||||
_PENDING_DODO_[msg.sender] = _PENDING_DODO_[msg.sender].add(amount);
|
||||
_EXECUTE_TIME_[msg.sender] = block.timestamp.add(_COLD_DOWN_DURATION_);
|
||||
}
|
||||
|
||||
function withdrawDODO() external {
|
||||
require(_EXECUTE_TIME_[msg.sender] <= block.timestamp, "WITHDRAW_COLD_DOWN");
|
||||
_transferDODOOut(msg.sender, _PENDING_DODO_[msg.sender]);
|
||||
_PENDING_DODO_[msg.sender] = 0;
|
||||
}
|
||||
|
||||
// ============ Balance Function ============
|
||||
|
||||
function _transferDODOIn(address from, uint256 amount) internal {
|
||||
IERC20(_DODO_TOKEN_).transferFrom(from, address(this), amount);
|
||||
}
|
||||
|
||||
function _transferDODOOut(address to, uint256 amount) internal {
|
||||
IERC20(_DODO_TOKEN_).transfer(to, amount);
|
||||
}
|
||||
|
||||
function _sync() internal {
|
||||
_DODO_RESERVE_ = IERC20(_DODO_TOKEN_).balanceOf(address(this));
|
||||
}
|
||||
|
||||
// ============ View Function ============
|
||||
|
||||
function getMemLevel(address user) external override returns (uint256) {
|
||||
return _STAKED_DODO_[user];
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
@@ -405,4 +403,4 @@ contract vDODOToken is InitializableOwnable {
|
||||
|
||||
emit Transfer(from, to, vDODOAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
43
contracts/Factory/DODONFT.sol
Normal file
43
contracts/Factory/DODONFT.sol
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
|
||||
Copyright 2021 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {ERC721URIStorage} from "../external/ERC721/ERC721URIStorage.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
|
||||
contract DODONFT is ERC721URIStorage, InitializableOwnable {
|
||||
|
||||
uint256 public _CUR_TOKENID_;
|
||||
|
||||
// ============ Event =============
|
||||
event DODONFTMint(address creator, uint256 tokenId);
|
||||
event DODONFTBurn(uint256 tokenId);
|
||||
|
||||
function init(
|
||||
address owner,
|
||||
string memory name,
|
||||
string memory symbol
|
||||
) public {
|
||||
initOwner(owner);
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
}
|
||||
|
||||
function mint(string calldata uri) external {
|
||||
_safeMint(msg.sender, _CUR_TOKENID_);
|
||||
_setTokenURI(_CUR_TOKENID_, uri);
|
||||
emit DODONFTMint(msg.sender, _CUR_TOKENID_);
|
||||
_CUR_TOKENID_ = _CUR_TOKENID_ + 1;
|
||||
}
|
||||
|
||||
function burn(uint256 tokenId) external onlyOwner {
|
||||
require(tokenId < _CUR_TOKENID_, "TOKENID_INVALID");
|
||||
_burn(tokenId);
|
||||
emit DODONFTBurn(tokenId);
|
||||
}
|
||||
}
|
||||
57
contracts/Factory/DODONFT1155.sol
Normal file
57
contracts/Factory/DODONFT1155.sol
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
|
||||
Copyright 2021 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {ERC1155} from "../external/ERC1155/ERC1155.sol";
|
||||
import {Strings} from "../external/utils/Strings.sol";
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
|
||||
contract DODONFT1155 is ERC1155, InitializableOwnable {
|
||||
using Strings for uint256;
|
||||
|
||||
uint256 public _CUR_TOKENID_;
|
||||
string internal _baseUri = "";
|
||||
mapping (uint256 => string) private _tokenURIs;
|
||||
|
||||
// ============ Event =============
|
||||
event DODONFTMint(address creator, uint256 tokenId, uint256 amount);
|
||||
event DODONFTBurn(address account, uint256 tokenId, uint256 amount);
|
||||
|
||||
|
||||
function mint(string calldata uri, uint256 amount) external {
|
||||
_mint(msg.sender, _CUR_TOKENID_, amount, "");
|
||||
_setTokenURI(_CUR_TOKENID_, uri);
|
||||
emit DODONFTMint(msg.sender, _CUR_TOKENID_, amount);
|
||||
_CUR_TOKENID_ = _CUR_TOKENID_ + 1;
|
||||
}
|
||||
|
||||
function burn(address account, uint256 tokenId, uint256 amount) external onlyOwner {
|
||||
require(tokenId < _CUR_TOKENID_, "TOKENID_INVALID");
|
||||
_burn(account, tokenId, amount);
|
||||
emit DODONFTBurn(account, tokenId, amount);
|
||||
}
|
||||
|
||||
function uri(uint256 tokenId) public view override returns (string memory) {
|
||||
string memory _tokenURI = _tokenURIs[tokenId];
|
||||
string memory base = _baseUri;
|
||||
|
||||
if (bytes(base).length == 0) {
|
||||
return _tokenURI;
|
||||
}
|
||||
|
||||
if (bytes(_tokenURI).length > 0) {
|
||||
return string(abi.encodePacked(base, _tokenURI));
|
||||
}
|
||||
|
||||
return super.uri(tokenId);
|
||||
}
|
||||
|
||||
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal {
|
||||
_tokenURIs[tokenId] = _tokenURI;
|
||||
}
|
||||
}
|
||||
75
contracts/Factory/NFTTokenFactory.sol
Normal file
75
contracts/Factory/NFTTokenFactory.sol
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {ICloneFactory} from "../lib/CloneFactory.sol";
|
||||
import {InitializableERC721} from "../external/ERC721/InitializableERC721.sol";
|
||||
import {InitializableERC1155} from "../external/ERC1155/InitializableERC1155.sol";
|
||||
|
||||
/**
|
||||
* @title DODO NFTTokenFactory
|
||||
* @author DODO Breeder
|
||||
*
|
||||
* @notice Help user to create erc721 && erc1155 token
|
||||
*/
|
||||
contract NFTTokenFactory {
|
||||
// ============ Templates ============
|
||||
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
address public immutable _ERC721_TEMPLATE_;
|
||||
address public immutable _ERC1155_TEMPLATE_;
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event NewERC721(address erc721, address creator);
|
||||
event NewERC1155(address erc1155, address creator);
|
||||
|
||||
// ============ Registry ============
|
||||
mapping(address => address[]) public _USER_ERC721_REGISTRY_;
|
||||
mapping(address => address[]) public _USER_ERC1155_REGISTRY_;
|
||||
|
||||
// ============ Functions ============
|
||||
|
||||
constructor(
|
||||
address cloneFactory,
|
||||
address erc721Template,
|
||||
address erc1155Tempalte
|
||||
) public {
|
||||
_CLONE_FACTORY_ = cloneFactory;
|
||||
_ERC721_TEMPLATE_ = erc721Template;
|
||||
_ERC1155_TEMPLATE_ = erc1155Tempalte;
|
||||
}
|
||||
|
||||
function createERC721(
|
||||
string memory uri
|
||||
) external returns (address newERC721) {
|
||||
newERC721 = ICloneFactory(_CLONE_FACTORY_).clone(_ERC721_TEMPLATE_);
|
||||
InitializableERC721(newERC721).init(msg.sender, "DODONFT", "DODONFT", uri);
|
||||
_USER_ERC721_REGISTRY_[msg.sender].push(newERC721);
|
||||
emit NewERC721(newERC721, msg.sender);
|
||||
}
|
||||
|
||||
function createERC1155(
|
||||
uint256 amount,
|
||||
string memory uri
|
||||
) external returns (address newERC1155) {
|
||||
newERC1155 = ICloneFactory(_CLONE_FACTORY_).clone(_ERC1155_TEMPLATE_);
|
||||
InitializableERC1155(newERC1155).init(msg.sender, amount, uri);
|
||||
_USER_ERC1155_REGISTRY_[msg.sender].push(newERC1155);
|
||||
emit NewERC1155(newERC1155, msg.sender);
|
||||
}
|
||||
|
||||
|
||||
function getERC721TokenByUser(address user)
|
||||
external
|
||||
view
|
||||
returns (address[] memory tokens)
|
||||
{
|
||||
return _USER_ERC721_REGISTRY_[user];
|
||||
}
|
||||
}
|
||||
113
contracts/Factory/Registries/DODONFTRegistry.sol
Normal file
113
contracts/Factory/Registries/DODONFTRegistry.sol
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
|
||||
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 {IDVM} from "../../DODOVendingMachine/intf/IDVM.sol";
|
||||
import {IFragment} from "../../GeneralizedFragment/intf/IFragment.sol";
|
||||
|
||||
interface IDODONFTRegistry {
|
||||
function addRegistry(
|
||||
address vault,
|
||||
address fragment,
|
||||
address quoteToken,
|
||||
address dvm
|
||||
) external;
|
||||
|
||||
function removeRegistry(address fragment) external;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title DODONFT Registry
|
||||
* @author DODO Breeder
|
||||
*
|
||||
* @notice Register DODONFT Pools
|
||||
*/
|
||||
contract DODONFTRegistry is InitializableOwnable, IDODONFTRegistry {
|
||||
|
||||
mapping (address => bool) public isAdminListed;
|
||||
|
||||
// ============ Registry ============
|
||||
// Vault -> Frag
|
||||
mapping(address => address) public _VAULT_FRAG_REGISTRY_;
|
||||
|
||||
// base -> quote -> DVM address list
|
||||
mapping(address => mapping(address => address[])) public _REGISTRY_;
|
||||
|
||||
// ============ Events ============
|
||||
|
||||
event NewRegistry(
|
||||
address vault,
|
||||
address fragment,
|
||||
address dvm
|
||||
);
|
||||
|
||||
event RemoveRegistry(address fragment);
|
||||
|
||||
|
||||
// ============ Admin Operation Functions ============
|
||||
|
||||
function addRegistry(
|
||||
address vault,
|
||||
address fragment,
|
||||
address quoteToken,
|
||||
address dvm
|
||||
) override external {
|
||||
require(isAdminListed[msg.sender], "ACCESS_DENIED");
|
||||
_VAULT_FRAG_REGISTRY_[vault] = fragment;
|
||||
_REGISTRY_[fragment][quoteToken].push(dvm);
|
||||
emit NewRegistry(vault, fragment, dvm);
|
||||
}
|
||||
|
||||
function removeRegistry(address fragment) override external {
|
||||
require(isAdminListed[msg.sender], "ACCESS_DENIED");
|
||||
address vault = IFragment(fragment)._COLLATERAL_VAULT_();
|
||||
address dvm = IFragment(fragment)._DVM_();
|
||||
|
||||
_VAULT_FRAG_REGISTRY_[vault] = address(0);
|
||||
|
||||
address quoteToken = IDVM(dvm)._QUOTE_TOKEN_();
|
||||
address[] memory registryList = _REGISTRY_[fragment][quoteToken];
|
||||
for (uint256 i = 0; i < registryList.length; i++) {
|
||||
if (registryList[i] == dvm) {
|
||||
if(i != registryList.length - 1) {
|
||||
_REGISTRY_[fragment][quoteToken][i] = _REGISTRY_[fragment][quoteToken][registryList.length - 1];
|
||||
}
|
||||
_REGISTRY_[fragment][quoteToken].pop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
emit RemoveRegistry(fragment);
|
||||
}
|
||||
|
||||
function addAdminList (address contractAddr) external onlyOwner {
|
||||
isAdminListed[contractAddr] = true;
|
||||
}
|
||||
|
||||
function removeAdminList (address contractAddr) external onlyOwner {
|
||||
isAdminListed[contractAddr] = false;
|
||||
}
|
||||
|
||||
function getDODOPool(address baseToken, address quoteToken)
|
||||
external
|
||||
view
|
||||
returns (address[] memory pools)
|
||||
{
|
||||
return _REGISTRY_[baseToken][quoteToken];
|
||||
}
|
||||
|
||||
function getDODOPoolBidirection(address token0, address token1)
|
||||
external
|
||||
view
|
||||
returns (address[] memory baseToken0Pool, address[] memory baseToken1Pool)
|
||||
{
|
||||
return (_REGISTRY_[token0][token1], _REGISTRY_[token1][token0]);
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ contract UpCrowdPoolingFactory is InitializableOwnable {
|
||||
|
||||
// ============ Settings =============
|
||||
uint256 public _FREEZE_DURATION_ = 30 days;
|
||||
uint256 public _CALM_DURATION_ = 0;
|
||||
uint256 public _CALM_DURATION_ = 600;
|
||||
uint256 public _VEST_DURATION_ = 0;
|
||||
uint256 public _CLIFF_RATE_ = 10**18;
|
||||
|
||||
|
||||
87
contracts/GeneralizedFragment/impl/BuyoutModel.sol
Normal file
87
contracts/GeneralizedFragment/impl/BuyoutModel.sol
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
|
||||
Copyright 2021 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
|
||||
interface IBuyout {
|
||||
function getBuyoutQualification(address user) external view returns (bool);
|
||||
}
|
||||
|
||||
contract BuyoutModel is InitializableOwnable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
uint256 public _MIN_FRAG_ = 100; //0.1
|
||||
uint256 public _MAX_FRAG_ = 1000; //1
|
||||
int public _BUYOUT_FEE_ = 0;
|
||||
|
||||
struct FragInfo {
|
||||
uint256 minFrag;
|
||||
uint256 maxFrag;
|
||||
address buyoutAddr;
|
||||
bool isSet;
|
||||
}
|
||||
|
||||
mapping(address => FragInfo) frags;
|
||||
|
||||
function addFragInfo(address fragAddr, uint256 minFrag, uint256 maxFrag, address buyoutAddr) external onlyOwner {
|
||||
FragInfo memory fragInfo = FragInfo({
|
||||
minFrag: minFrag,
|
||||
maxFrag: maxFrag,
|
||||
buyoutAddr: buyoutAddr,
|
||||
isSet: true
|
||||
});
|
||||
frags[fragAddr] = fragInfo;
|
||||
}
|
||||
|
||||
function setFragInfo(address fragAddr, uint256 minFrag, uint256 maxFrag, address buyoutAddr) external onlyOwner {
|
||||
frags[fragAddr].minFrag = minFrag;
|
||||
frags[fragAddr].maxFrag = maxFrag;
|
||||
frags[fragAddr].buyoutAddr = buyoutAddr;
|
||||
}
|
||||
|
||||
function setGlobalParam(uint256 minFrag, uint256 maxFrag, uint256 buyoutFee) external onlyOwner {
|
||||
require(minFrag <= 1000 && maxFrag <= 1000, "PARAM_INVALID");
|
||||
_MIN_FRAG_ = minFrag;
|
||||
_MAX_FRAG_ = maxFrag;
|
||||
_BUYOUT_FEE_ = int(buyoutFee);
|
||||
}
|
||||
|
||||
function getBuyoutStatus(address fragAddr, address user) external view returns (int) {
|
||||
FragInfo memory fragInfo = frags[fragAddr];
|
||||
|
||||
uint256 userBalance = IERC20(fragAddr).balanceOf(user);
|
||||
uint256 totalSupply = IERC20(fragAddr).totalSupply();
|
||||
uint256 minFrag = _MIN_FRAG_;
|
||||
uint256 maxFrag = _MAX_FRAG_;
|
||||
|
||||
if(fragInfo.isSet) {
|
||||
address buyoutAddr = fragInfo.buyoutAddr;
|
||||
if(buyoutAddr != address(0)) {
|
||||
bool isQualified = IBuyout(buyoutAddr).getBuyoutQualification(user);
|
||||
if(isQualified) {
|
||||
return _BUYOUT_FEE_;
|
||||
}else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
minFrag = fragInfo.minFrag;
|
||||
maxFrag = fragInfo.maxFrag;
|
||||
}
|
||||
|
||||
if(userBalance >= totalSupply.mul(minFrag).div(1000) && userBalance <= totalSupply.mul(maxFrag).div(1000)) {
|
||||
return _BUYOUT_FEE_;
|
||||
}else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
167
contracts/GeneralizedFragment/impl/Fragment.sol
Normal file
167
contracts/GeneralizedFragment/impl/Fragment.sol
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
import {IDVM} from "../../DODOVendingMachine/intf/IDVM.sol";
|
||||
import {IDODOCallee} from "../../intf/IDODOCallee.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {InitializableFragERC20} from "../../external/ERC20/InitializableFragERC20.sol";
|
||||
import {ICollateralVault} from "../../CollateralVault/intf/ICollateralVault.sol";
|
||||
|
||||
interface IBuyoutModel {
|
||||
function getBuyoutStatus(address fragAddr, address user) external view returns (int);
|
||||
}
|
||||
|
||||
contract Fragment is InitializableFragERC20 {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
// ============ Storage ============
|
||||
|
||||
bool public _IS_BUYOUT_;
|
||||
uint256 public _BUYOUT_TIMESTAMP_;
|
||||
uint256 public _BUYOUT_PRICE_;
|
||||
uint256 public _DISTRIBUTION_RATIO_;
|
||||
|
||||
address public _COLLATERAL_VAULT_;
|
||||
address public _VAULT_PRE_OWNER_;
|
||||
address public _QUOTE_;
|
||||
address public _DVM_;
|
||||
address public _DEFAULT_MAINTAINER_;
|
||||
address public _BUYOUT_MODEL_;
|
||||
|
||||
bool internal _FRAG_INITIALIZED_;
|
||||
|
||||
// ============ Event ============
|
||||
event RemoveNftToken(address nftContract, uint256 tokenId, uint256 amount);
|
||||
event AddNftToken(address nftContract, uint256 tokenId, uint256 amount);
|
||||
event InitInfo(address vault, string name, string baseURI);
|
||||
event CreateFragment();
|
||||
event Buyout(address newOwner);
|
||||
event Redeem(address sender, uint256 baseAmount, uint256 quoteAmount);
|
||||
|
||||
|
||||
function init(
|
||||
address dvm,
|
||||
address vaultPreOwner,
|
||||
address collateralVault,
|
||||
uint256 _totalSupply,
|
||||
uint256 ownerRatio,
|
||||
uint256 buyoutTimestamp,
|
||||
address defaultMaintainer,
|
||||
address buyoutModel,
|
||||
uint256 distributionRatio,
|
||||
string memory _symbol
|
||||
) external {
|
||||
require(!_FRAG_INITIALIZED_, "DODOFragment: ALREADY_INITIALIZED");
|
||||
_FRAG_INITIALIZED_ = true;
|
||||
|
||||
// init local variables
|
||||
_DVM_ = dvm;
|
||||
_QUOTE_ = IDVM(_DVM_)._QUOTE_TOKEN_();
|
||||
_VAULT_PRE_OWNER_ = vaultPreOwner;
|
||||
_COLLATERAL_VAULT_ = collateralVault;
|
||||
_BUYOUT_TIMESTAMP_ = buyoutTimestamp;
|
||||
_DEFAULT_MAINTAINER_ = defaultMaintainer;
|
||||
_BUYOUT_MODEL_ = buyoutModel;
|
||||
_DISTRIBUTION_RATIO_ = distributionRatio;
|
||||
|
||||
// init FRAG meta data
|
||||
name = string(abi.encodePacked("DODO_FRAG_", _symbol));
|
||||
symbol = string(abi.encodePacked("d_", _symbol));
|
||||
super.init(address(this), _totalSupply, name, symbol);
|
||||
|
||||
// init FRAG distribution
|
||||
uint256 vaultPreOwnerBalance = DecimalMath.mulFloor(_totalSupply, ownerRatio);
|
||||
uint256 distributionBalance = DecimalMath.mulFloor(vaultPreOwnerBalance, distributionRatio);
|
||||
|
||||
if(distributionBalance > 0) _transfer(address(this), _DEFAULT_MAINTAINER_, distributionBalance);
|
||||
_transfer(address(this), _VAULT_PRE_OWNER_, vaultPreOwnerBalance.sub(distributionBalance));
|
||||
_transfer(address(this), _DVM_, _totalSupply.sub(vaultPreOwnerBalance));
|
||||
|
||||
// init DVM liquidity
|
||||
IDVM(_DVM_).buyShares(address(this));
|
||||
}
|
||||
|
||||
|
||||
function buyout(address newVaultOwner) external {
|
||||
require(_BUYOUT_TIMESTAMP_ != 0, "DODOFragment: NOT_SUPPORT_BUYOUT");
|
||||
require(block.timestamp > _BUYOUT_TIMESTAMP_, "DODOFragment: BUYOUT_NOT_START");
|
||||
require(!_IS_BUYOUT_, "DODOFragment: ALREADY_BUYOUT");
|
||||
|
||||
int buyoutFee = IBuyoutModel(_BUYOUT_MODEL_).getBuyoutStatus(address(this), newVaultOwner);
|
||||
require(buyoutFee != -1, "DODOFragment: USER_UNABLE_BUYOUT");
|
||||
|
||||
_IS_BUYOUT_ = true;
|
||||
|
||||
_BUYOUT_PRICE_ = IDVM(_DVM_).getMidPrice();
|
||||
uint256 requireQuote = DecimalMath.mulCeil(_BUYOUT_PRICE_, totalSupply);
|
||||
uint256 payQuote = IERC20(_QUOTE_).balanceOf(address(this));
|
||||
require(payQuote >= requireQuote, "DODOFragment: QUOTE_NOT_ENOUGH");
|
||||
|
||||
IDVM(_DVM_).sellShares(
|
||||
IERC20(_DVM_).balanceOf(address(this)),
|
||||
address(this),
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
uint256(-1)
|
||||
);
|
||||
|
||||
uint256 redeemFrag = totalSupply.sub(balances[address(this)]).sub(balances[_VAULT_PRE_OWNER_]);
|
||||
uint256 ownerQuoteWithoutFee = IERC20(_QUOTE_).balanceOf(address(this)).sub(DecimalMath.mulCeil(_BUYOUT_PRICE_, redeemFrag));
|
||||
_clearBalance(address(this));
|
||||
_clearBalance(_VAULT_PRE_OWNER_);
|
||||
|
||||
uint256 buyoutFeeAmount = DecimalMath.mulFloor(ownerQuoteWithoutFee, uint256(buyoutFee));
|
||||
|
||||
IERC20(_QUOTE_).safeTransfer(_DEFAULT_MAINTAINER_, buyoutFeeAmount);
|
||||
IERC20(_QUOTE_).safeTransfer(_VAULT_PRE_OWNER_, ownerQuoteWithoutFee.sub(buyoutFeeAmount));
|
||||
|
||||
ICollateralVault(_COLLATERAL_VAULT_).directTransferOwnership(newVaultOwner);
|
||||
|
||||
emit Buyout(newVaultOwner);
|
||||
}
|
||||
|
||||
|
||||
function redeem(address to, bytes calldata data) external {
|
||||
require(_IS_BUYOUT_, "DODOFragment: NEED_BUYOUT");
|
||||
|
||||
uint256 baseAmount = balances[msg.sender];
|
||||
uint256 quoteAmount = DecimalMath.mulFloor(_BUYOUT_PRICE_, baseAmount);
|
||||
_clearBalance(msg.sender);
|
||||
IERC20(_QUOTE_).safeTransfer(to, quoteAmount);
|
||||
|
||||
if (data.length > 0) {
|
||||
IDODOCallee(to).NFTRedeemCall(
|
||||
msg.sender,
|
||||
quoteAmount,
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
emit Redeem(msg.sender, baseAmount, quoteAmount);
|
||||
}
|
||||
|
||||
function getBuyoutRequirement() external view returns (uint256 requireQuote){
|
||||
require(_BUYOUT_TIMESTAMP_ != 0, "NOT SUPPORT BUYOUT");
|
||||
require(!_IS_BUYOUT_, "ALREADY BUYOUT");
|
||||
uint256 price = IDVM(_DVM_).getMidPrice();
|
||||
requireQuote = DecimalMath.mulCeil(price, totalSupply);
|
||||
}
|
||||
|
||||
function _clearBalance(address account) internal {
|
||||
uint256 clearBalance = balances[account];
|
||||
balances[account] = 0;
|
||||
balances[address(0)] = balances[address(0)].add(clearBalance);
|
||||
emit Transfer(account, address(0), clearBalance);
|
||||
}
|
||||
}
|
||||
37
contracts/GeneralizedFragment/intf/IFragment.sol
Normal file
37
contracts/GeneralizedFragment/intf/IFragment.sol
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
|
||||
interface IFragment {
|
||||
|
||||
function init(
|
||||
address dvm,
|
||||
address vaultPreOwner,
|
||||
address collateralVault,
|
||||
uint256 totalSupply,
|
||||
uint256 ownerRatio,
|
||||
uint256 buyoutTimestamp,
|
||||
address defaultMaintainer,
|
||||
address buyoutModel,
|
||||
uint256 distributionRatio,
|
||||
string memory fragSymbol
|
||||
) external;
|
||||
|
||||
function buyout(address newVaultOwner) external;
|
||||
|
||||
function redeem(address to) external;
|
||||
|
||||
function _QUOTE_() external view returns (address);
|
||||
|
||||
function _COLLATERAL_VAULT_() external view returns (address);
|
||||
|
||||
function _DVM_() external view returns (address);
|
||||
|
||||
function totalSupply() external view returns (uint256);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {IDODOV2} from "../intf/IDODOV2.sol";
|
||||
import {IFragment} from "../../GeneralizedFragment/intf/IFragment.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {IWETH} from "../../intf/IWETH.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
@@ -64,6 +65,15 @@ contract DODOCalleeHelper is ReentrancyGuard {
|
||||
_withdraw(assetTo, _quoteToken, quoteAmount, _quoteToken == _WETH_);
|
||||
}
|
||||
|
||||
function NFTRedeemCall(
|
||||
address payable assetTo,
|
||||
uint256 quoteAmount,
|
||||
bytes calldata
|
||||
) external preventReentrant {
|
||||
address _quoteToken = IFragment(msg.sender)._QUOTE_();
|
||||
_withdraw(assetTo, _quoteToken, quoteAmount, _quoteToken == _WETH_);
|
||||
}
|
||||
|
||||
function _withdraw(
|
||||
address payable to,
|
||||
address token,
|
||||
|
||||
68
contracts/SmartRoute/helper/DODONFTRouteHelper.sol
Normal file
68
contracts/SmartRoute/helper/DODONFTRouteHelper.sol
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {IDODOV2} from "../intf/IDODOV2.sol";
|
||||
|
||||
contract DODONFTRouteHelper {
|
||||
address public immutable _NFT_REGISTER_;
|
||||
|
||||
struct PairDetail {
|
||||
uint256 i;
|
||||
uint256 K;
|
||||
uint256 B;
|
||||
uint256 Q;
|
||||
uint256 B0;
|
||||
uint256 Q0;
|
||||
uint256 R;
|
||||
uint256 lpFeeRate;
|
||||
uint256 mtFeeRate;
|
||||
address baseToken;
|
||||
address quoteToken;
|
||||
address curPair;
|
||||
uint256 pairVersion;
|
||||
}
|
||||
|
||||
constructor(address nftRegistry) public {
|
||||
_NFT_REGISTER_ = nftRegistry;
|
||||
}
|
||||
|
||||
function getPairDetail(address token0,address token1,address userAddr) external view returns (PairDetail[] memory res) {
|
||||
(address[] memory baseToken0DVM, address[] memory baseToken1DVM) = IDODOV2(_NFT_REGISTER_).getDODOPoolBidirection(token0,token1);
|
||||
uint256 len = baseToken0DVM.length + baseToken1DVM.length;
|
||||
res = new PairDetail[](len);
|
||||
for(uint8 i = 0; i < len; i++) {
|
||||
PairDetail memory curRes = PairDetail(0,0,0,0,0,0,0,0,0,address(0),address(0),address(0),2);
|
||||
address cur;
|
||||
if(i < baseToken0DVM.length) {
|
||||
cur = baseToken0DVM[i];
|
||||
curRes.baseToken = token0;
|
||||
curRes.quoteToken = token1;
|
||||
} else {
|
||||
cur = baseToken1DVM[i - baseToken0DVM.length];
|
||||
curRes.baseToken = token1;
|
||||
curRes.quoteToken = token0;
|
||||
}
|
||||
|
||||
(
|
||||
curRes.i,
|
||||
curRes.K,
|
||||
curRes.B,
|
||||
curRes.Q,
|
||||
curRes.B0,
|
||||
curRes.Q0,
|
||||
curRes.R
|
||||
) = IDODOV2(cur).getPMMStateForCall();
|
||||
|
||||
(curRes.lpFeeRate, curRes.mtFeeRate) = IDODOV2(cur).getUserFeeRate(userAddr);
|
||||
curRes.curPair = cur;
|
||||
res[i] = curRes;
|
||||
}
|
||||
}
|
||||
}
|
||||
72
contracts/SmartRoute/proxies/DODODropsProxy.sol
Normal file
72
contracts/SmartRoute/proxies/DODODropsProxy.sol
Normal file
@@ -0,0 +1,72 @@
|
||||
|
||||
/*
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IDODOApproveProxy} from "../DODOApproveProxy.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
|
||||
|
||||
interface IDODODrops {
|
||||
function _BUY_TOKEN_() external view returns (address);
|
||||
function _FEE_MODEL_() external view returns (address);
|
||||
function getSellingInfo() external view returns (uint256, uint256, uint256);
|
||||
function buyTickets(address assetTo, uint256 ticketAmount) external;
|
||||
}
|
||||
|
||||
interface IDropsFeeModel {
|
||||
function getPayAmount(address mysteryBox, address user, uint256 originalPrice, uint256 ticketAmount) external view returns (uint256, uint256);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title DODO DropsProxy
|
||||
* @author DODO Breeder
|
||||
*
|
||||
* @notice Entrance of Drops in DODO platform
|
||||
*/
|
||||
contract DODODropsProxy is ReentrancyGuard {
|
||||
using SafeMath for uint256;
|
||||
|
||||
// ============ Storage ============
|
||||
|
||||
address constant _BASE_COIN_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
address public immutable _DODO_APPROVE_PROXY_;
|
||||
|
||||
// ============ Events ============
|
||||
event BuyTicket(address indexed account, address indexed mysteryBox, uint256 ticketAmount);
|
||||
|
||||
fallback() external payable {}
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
constructor(address dodoApproveProxy) public {
|
||||
_DODO_APPROVE_PROXY_ = dodoApproveProxy;
|
||||
}
|
||||
|
||||
function buyTickets(address payable dodoDrops, uint256 ticketAmount) external payable preventReentrant {
|
||||
(uint256 curPrice, uint256 sellAmount,) = IDODODrops(dodoDrops).getSellingInfo();
|
||||
require(curPrice > 0 && sellAmount > 0, "CAN_NOT_BUY");
|
||||
require(ticketAmount <= sellAmount, "TICKETS_NOT_ENOUGH");
|
||||
|
||||
address feeModel = IDODODrops(dodoDrops)._FEE_MODEL_();
|
||||
(uint256 payAmount,) = IDropsFeeModel(feeModel).getPayAmount(dodoDrops, msg.sender, curPrice, ticketAmount);
|
||||
require(payAmount > 0, "UnQualified");
|
||||
address buyToken = IDODODrops(dodoDrops)._BUY_TOKEN_();
|
||||
|
||||
if(buyToken == _BASE_COIN_) {
|
||||
require(msg.value == payAmount, "PAYAMOUNT_NOT_ENOUGH");
|
||||
dodoDrops.transfer(payAmount);
|
||||
}else {
|
||||
IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens(buyToken, msg.sender, dodoDrops, payAmount);
|
||||
}
|
||||
|
||||
IDODODrops(dodoDrops).buyTickets(msg.sender, ticketAmount);
|
||||
|
||||
emit BuyTicket(msg.sender, dodoDrops, ticketAmount);
|
||||
}
|
||||
}
|
||||
218
contracts/SmartRoute/proxies/DODONFTProxy.sol
Normal file
218
contracts/SmartRoute/proxies/DODONFTProxy.sol
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IDODOApproveProxy} from "../DODOApproveProxy.sol";
|
||||
import {ICloneFactory} from "../../lib/CloneFactory.sol";
|
||||
import {IERC20} from "../../intf/IERC20.sol";
|
||||
import {IWETH} from "../../intf/IWETH.sol";
|
||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||
import {ICollateralVault} from "../../CollateralVault/intf/ICollateralVault.sol";
|
||||
import {IDVM} from "../../DODOVendingMachine/intf/IDVM.sol";
|
||||
import {IFragment} from "../../GeneralizedFragment/intf/IFragment.sol";
|
||||
import {IDODONFTRegistry} from "../../Factory/Registries/DODONFTRegistry.sol";
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||
import {DecimalMath} from "../../lib/DecimalMath.sol";
|
||||
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title DODONFTProxy
|
||||
* @author DODO Breeder
|
||||
*
|
||||
* @notice Entrance of NFT in DODO platform
|
||||
*/
|
||||
contract DODONFTProxy is ReentrancyGuard, InitializableOwnable {
|
||||
using SafeMath for uint256;
|
||||
|
||||
|
||||
// ============ Storage ============
|
||||
|
||||
address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||
address public immutable _WETH_;
|
||||
address public immutable _DODO_APPROVE_PROXY_;
|
||||
address public immutable _CLONE_FACTORY_;
|
||||
address public immutable _NFT_REGISTY_;
|
||||
address public immutable _DEFAULT_MAINTAINER_;
|
||||
|
||||
address public _MT_FEE_RATE_MODEL_;
|
||||
address public _VAULT_TEMPLATE_;
|
||||
address public _FRAG_TEMPLATE_;
|
||||
address public _DVM_TEMPLATE_;
|
||||
address public _BUYOUT_MODEL_;
|
||||
|
||||
// ============ Events ============
|
||||
event ChangeVaultTemplate(address newVaultTemplate);
|
||||
event ChangeFragTemplate(address newFragTemplate);
|
||||
event ChangeDvmTemplate(address newDvmTemplate);
|
||||
event ChangeMtFeeRateTemplate(address newMtFeeRateTemplate);
|
||||
event ChangeBuyoutModel(address newBuyoutModel);
|
||||
event CreateNFTCollateralVault(address creator, address vault, string name, string baseURI);
|
||||
event CreateFragment(address vault, address fragment, address dvm);
|
||||
event Buyout(address from, address fragment, uint256 amount);
|
||||
|
||||
// ============ Modifiers ============
|
||||
|
||||
modifier judgeExpired(uint256 deadLine) {
|
||||
require(deadLine >= block.timestamp, "DODONFTProxy: EXPIRED");
|
||||
_;
|
||||
}
|
||||
|
||||
fallback() external payable {}
|
||||
|
||||
receive() external payable {}
|
||||
|
||||
constructor(
|
||||
address cloneFactory,
|
||||
address payable weth,
|
||||
address dodoApproveProxy,
|
||||
address defaultMaintainer,
|
||||
address buyoutModel,
|
||||
address mtFeeRateModel,
|
||||
address vaultTemplate,
|
||||
address fragTemplate,
|
||||
address dvmTemplate,
|
||||
address nftRegistry
|
||||
) public {
|
||||
_CLONE_FACTORY_ = cloneFactory;
|
||||
_WETH_ = weth;
|
||||
_DODO_APPROVE_PROXY_ = dodoApproveProxy;
|
||||
_DEFAULT_MAINTAINER_ = defaultMaintainer;
|
||||
_MT_FEE_RATE_MODEL_ = mtFeeRateModel;
|
||||
_BUYOUT_MODEL_ = buyoutModel;
|
||||
_VAULT_TEMPLATE_ = vaultTemplate;
|
||||
_FRAG_TEMPLATE_ = fragTemplate;
|
||||
_DVM_TEMPLATE_ = dvmTemplate;
|
||||
_NFT_REGISTY_ = nftRegistry;
|
||||
}
|
||||
|
||||
function createNFTCollateralVault(string memory name, string memory baseURI) external returns (address newVault) {
|
||||
newVault = ICloneFactory(_CLONE_FACTORY_).clone(_VAULT_TEMPLATE_);
|
||||
ICollateralVault(newVault).init(msg.sender, name, baseURI);
|
||||
emit CreateNFTCollateralVault(msg.sender, newVault, name, baseURI);
|
||||
}
|
||||
|
||||
function createFragment(
|
||||
address[] calldata addrList, //0 - quoteToken, 1 - vaultPreOwner
|
||||
uint256[] calldata params, //(DVM: 0 - lpFeeRate 1 - I, 2 - K) , (FRAG: 3 - totalSupply, 4 - ownerRatio, 5 - buyoutTimestamp, 6 - distributionRatio)
|
||||
bool isOpenTwap,
|
||||
string memory fragSymbol
|
||||
) external returns (address newFragment, address newDvm) {
|
||||
newFragment = ICloneFactory(_CLONE_FACTORY_).clone(_FRAG_TEMPLATE_);
|
||||
address _quoteToken = addrList[0] == _ETH_ADDRESS_ ? _WETH_ : addrList[0];
|
||||
|
||||
{
|
||||
uint256[] memory _params = params;
|
||||
|
||||
newDvm = ICloneFactory(_CLONE_FACTORY_).clone(_DVM_TEMPLATE_);
|
||||
IDVM(newDvm).init(
|
||||
_DEFAULT_MAINTAINER_,
|
||||
newFragment,
|
||||
_quoteToken,
|
||||
_params[0],
|
||||
_MT_FEE_RATE_MODEL_,
|
||||
_params[1],
|
||||
_params[2],
|
||||
isOpenTwap
|
||||
);
|
||||
IFragment(newFragment).init(
|
||||
newDvm,
|
||||
addrList[1],
|
||||
msg.sender,
|
||||
_params[3],
|
||||
_params[4],
|
||||
_params[5],
|
||||
_DEFAULT_MAINTAINER_,
|
||||
_BUYOUT_MODEL_,
|
||||
_params[6],
|
||||
fragSymbol
|
||||
);
|
||||
}
|
||||
|
||||
ICollateralVault(msg.sender).directTransferOwnership(newFragment);
|
||||
|
||||
IDODONFTRegistry(_NFT_REGISTY_).addRegistry(msg.sender, newFragment, _quoteToken, newDvm);
|
||||
|
||||
emit CreateFragment(msg.sender, newFragment, newDvm);
|
||||
}
|
||||
|
||||
function buyout(
|
||||
address fragment,
|
||||
uint256 quoteMaxAmount,
|
||||
uint8 flag, // 0 - ERC20, 1 - quoteInETH
|
||||
uint256 deadLine
|
||||
) external payable preventReentrant judgeExpired(deadLine) {
|
||||
if(flag == 0)
|
||||
require(msg.value == 0, "DODONFTProxy: WE_SAVED_YOUR_MONEY");
|
||||
|
||||
address dvm = IFragment(fragment)._DVM_();
|
||||
uint256 fragTotalSupply = IFragment(fragment).totalSupply();
|
||||
uint256 buyPrice = IDVM(dvm).getMidPrice();
|
||||
|
||||
uint256 curRequireQuote = DecimalMath.mulCeil(buyPrice, fragTotalSupply);
|
||||
|
||||
require(curRequireQuote <= quoteMaxAmount, "DODONFTProxy: CURRENT_TOTAL_VAULE_MORE_THAN_QUOTEMAX");
|
||||
|
||||
_deposit(msg.sender, fragment, IFragment(fragment)._QUOTE_(), curRequireQuote, flag == 1);
|
||||
IFragment(fragment).buyout(msg.sender);
|
||||
|
||||
IDODONFTRegistry(_NFT_REGISTY_).removeRegistry(fragment);
|
||||
|
||||
// refund dust eth
|
||||
if (flag == 1 && msg.value > curRequireQuote) msg.sender.transfer(msg.value - curRequireQuote);
|
||||
|
||||
emit Buyout(msg.sender, fragment, curRequireQuote);
|
||||
}
|
||||
|
||||
//============= Owner ===================
|
||||
function updateVaultTemplate(address newVaultTemplate) external onlyOwner {
|
||||
_VAULT_TEMPLATE_ = newVaultTemplate;
|
||||
emit ChangeVaultTemplate(newVaultTemplate);
|
||||
}
|
||||
|
||||
function updateFragTemplate(address newFragTemplate) external onlyOwner {
|
||||
_FRAG_TEMPLATE_ = newFragTemplate;
|
||||
emit ChangeFragTemplate(newFragTemplate);
|
||||
}
|
||||
|
||||
function updateMtFeeRateTemplate(address newMtFeeRateTemplate) external onlyOwner {
|
||||
_MT_FEE_RATE_MODEL_ = newMtFeeRateTemplate;
|
||||
emit ChangeMtFeeRateTemplate(newMtFeeRateTemplate);
|
||||
}
|
||||
|
||||
function updateDvmTemplate(address newDvmTemplate) external onlyOwner {
|
||||
_DVM_TEMPLATE_ = newDvmTemplate;
|
||||
emit ChangeDvmTemplate(newDvmTemplate);
|
||||
}
|
||||
|
||||
function updateBuyoutModel(address newBuyoutModel) external onlyOwner {
|
||||
_BUYOUT_MODEL_ = newBuyoutModel;
|
||||
emit ChangeBuyoutModel(newBuyoutModel);
|
||||
}
|
||||
|
||||
|
||||
//============= Internal ================
|
||||
|
||||
function _deposit(
|
||||
address from,
|
||||
address to,
|
||||
address token,
|
||||
uint256 amount,
|
||||
bool isETH
|
||||
) internal {
|
||||
if (isETH) {
|
||||
if (amount > 0) {
|
||||
IWETH(_WETH_).deposit{value: amount}();
|
||||
if (to != address(this)) SafeERC20.safeTransfer(IERC20(_WETH_), to, amount);
|
||||
}
|
||||
} else {
|
||||
IDODOApproveProxy(_DODO_APPROVE_PROXY_).claimTokens(token, from, to, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
395
contracts/external/ERC1155/ERC1155.sol
vendored
Normal file
395
contracts/external/ERC1155/ERC1155.sol
vendored
Normal file
@@ -0,0 +1,395 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IERC1155} from "../../intf/IERC1155.sol";
|
||||
import {IERC165} from "../../intf/IERC165.sol";
|
||||
import {IERC1155Receiver} from "../../intf/IERC1155Receiver.sol";
|
||||
import {IERC1155MetadataURI} from "../../intf/IERC1155MetadataURI.sol";
|
||||
import {ERC165} from "../utils/ERC165.sol";
|
||||
import {Strings} from "../utils/Strings.sol";
|
||||
import {Address} from "../utils/Address.sol";
|
||||
import {Context} from "../utils/Context.sol";
|
||||
|
||||
/**
|
||||
*
|
||||
* @dev Implementation of the basic standard multi-token.
|
||||
* See https://eips.ethereum.org/EIPS/eip-1155
|
||||
* Originally based on code by Enjin: https://github.com/enjin/erc-1155
|
||||
*
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
|
||||
using Address for address;
|
||||
|
||||
// Mapping from token ID to account balances
|
||||
mapping (uint256 => mapping(address => uint256)) private _balances;
|
||||
|
||||
// Mapping from account to operator approvals
|
||||
mapping (address => mapping(address => bool)) private _operatorApprovals;
|
||||
|
||||
// Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
|
||||
string private _uri;
|
||||
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
||||
return interfaceId == type(IERC1155).interfaceId
|
||||
|| interfaceId == type(IERC1155MetadataURI).interfaceId
|
||||
|| super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC1155MetadataURI-uri}.
|
||||
*
|
||||
* This implementation returns the same URI for *all* token types. It relies
|
||||
* on the token type ID substitution mechanism
|
||||
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
|
||||
*
|
||||
* Clients calling this function must replace the `\{id\}` substring with the
|
||||
* actual token type ID.
|
||||
*/
|
||||
function uri(uint256) public view virtual override returns (string memory) {
|
||||
return _uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC1155-balanceOf}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `account` cannot be the zero address.
|
||||
*/
|
||||
function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
|
||||
require(account != address(0), "ERC1155: balance query for the zero address");
|
||||
return _balances[id][account];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC1155-balanceOfBatch}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `accounts` and `ids` must have the same length.
|
||||
*/
|
||||
function balanceOfBatch(
|
||||
address[] memory accounts,
|
||||
uint256[] memory ids
|
||||
)
|
||||
public
|
||||
view
|
||||
virtual
|
||||
override
|
||||
returns (uint256[] memory)
|
||||
{
|
||||
require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");
|
||||
|
||||
uint256[] memory batchBalances = new uint256[](accounts.length);
|
||||
|
||||
for (uint256 i = 0; i < accounts.length; ++i) {
|
||||
batchBalances[i] = balanceOf(accounts[i], ids[i]);
|
||||
}
|
||||
|
||||
return batchBalances;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC1155-setApprovalForAll}.
|
||||
*/
|
||||
function setApprovalForAll(address operator, bool approved) public virtual override {
|
||||
require(_msgSender() != operator, "ERC1155: setting approval status for self");
|
||||
|
||||
_operatorApprovals[_msgSender()][operator] = approved;
|
||||
emit ApprovalForAll(_msgSender(), operator, approved);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC1155-isApprovedForAll}.
|
||||
*/
|
||||
function isApprovedForAll(address account, address operator) public view virtual override returns (bool) {
|
||||
return _operatorApprovals[account][operator];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC1155-safeTransferFrom}.
|
||||
*/
|
||||
function safeTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 id,
|
||||
uint256 amount,
|
||||
bytes memory data
|
||||
)
|
||||
public
|
||||
virtual
|
||||
override
|
||||
{
|
||||
require(to != address(0), "ERC1155: transfer to the zero address");
|
||||
require(
|
||||
from == _msgSender() || isApprovedForAll(from, _msgSender()),
|
||||
"ERC1155: caller is not owner nor approved"
|
||||
);
|
||||
|
||||
address operator = _msgSender();
|
||||
|
||||
_beforeTokenTransfer(operator, from, to, _asSingletonArray(id), _asSingletonArray(amount), data);
|
||||
|
||||
uint256 fromBalance = _balances[id][from];
|
||||
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
|
||||
_balances[id][from] = fromBalance - amount;
|
||||
_balances[id][to] += amount;
|
||||
|
||||
emit TransferSingle(operator, from, to, id, amount);
|
||||
|
||||
_doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC1155-safeBatchTransferFrom}.
|
||||
*/
|
||||
function safeBatchTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256[] memory ids,
|
||||
uint256[] memory amounts,
|
||||
bytes memory data
|
||||
)
|
||||
public
|
||||
virtual
|
||||
override
|
||||
{
|
||||
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
||||
require(to != address(0), "ERC1155: transfer to the zero address");
|
||||
require(
|
||||
from == _msgSender() || isApprovedForAll(from, _msgSender()),
|
||||
"ERC1155: transfer caller is not owner nor approved"
|
||||
);
|
||||
|
||||
address operator = _msgSender();
|
||||
|
||||
_beforeTokenTransfer(operator, from, to, ids, amounts, data);
|
||||
|
||||
for (uint256 i = 0; i < ids.length; ++i) {
|
||||
uint256 id = ids[i];
|
||||
uint256 amount = amounts[i];
|
||||
|
||||
uint256 fromBalance = _balances[id][from];
|
||||
require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
|
||||
_balances[id][from] = fromBalance - amount;
|
||||
_balances[id][to] += amount;
|
||||
}
|
||||
|
||||
emit TransferBatch(operator, from, to, ids, amounts);
|
||||
|
||||
_doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets a new URI for all token types, by relying on the token type ID
|
||||
* substitution mechanism
|
||||
* https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
|
||||
*
|
||||
* By this mechanism, any occurrence of the `\{id\}` substring in either the
|
||||
* URI or any of the amounts in the JSON file at said URI will be replaced by
|
||||
* clients with the token type ID.
|
||||
*
|
||||
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
|
||||
* interpreted by clients as
|
||||
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
|
||||
* for token type ID 0x4cce0.
|
||||
*
|
||||
* See {uri}.
|
||||
*
|
||||
* Because these URIs cannot be meaningfully represented by the {URI} event,
|
||||
* this function emits no events.
|
||||
*/
|
||||
function _setURI(string memory newuri) internal virtual {
|
||||
_uri = newuri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Creates `amount` tokens of token type `id`, and assigns them to `account`.
|
||||
*
|
||||
* Emits a {TransferSingle} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `account` cannot be the zero address.
|
||||
* - If `account` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
|
||||
* acceptance magic value.
|
||||
*/
|
||||
function _mint(address account, uint256 id, uint256 amount, bytes memory data) internal virtual {
|
||||
require(account != address(0), "ERC1155: mint to the zero address");
|
||||
|
||||
address operator = _msgSender();
|
||||
|
||||
_beforeTokenTransfer(operator, address(0), account, _asSingletonArray(id), _asSingletonArray(amount), data);
|
||||
|
||||
_balances[id][account] += amount;
|
||||
emit TransferSingle(operator, address(0), account, id, amount);
|
||||
|
||||
_doSafeTransferAcceptanceCheck(operator, address(0), account, id, amount, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `ids` and `amounts` must have the same length.
|
||||
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
|
||||
* acceptance magic value.
|
||||
*/
|
||||
function _mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data) internal virtual {
|
||||
require(to != address(0), "ERC1155: mint to the zero address");
|
||||
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
||||
|
||||
address operator = _msgSender();
|
||||
|
||||
_beforeTokenTransfer(operator, address(0), to, ids, amounts, data);
|
||||
|
||||
for (uint i = 0; i < ids.length; i++) {
|
||||
_balances[ids[i]][to] += amounts[i];
|
||||
}
|
||||
|
||||
emit TransferBatch(operator, address(0), to, ids, amounts);
|
||||
|
||||
_doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Destroys `amount` tokens of token type `id` from `account`
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `account` cannot be the zero address.
|
||||
* - `account` must have at least `amount` tokens of token type `id`.
|
||||
*/
|
||||
function _burn(address account, uint256 id, uint256 amount) internal virtual {
|
||||
require(account != address(0), "ERC1155: burn from the zero address");
|
||||
|
||||
address operator = _msgSender();
|
||||
|
||||
_beforeTokenTransfer(operator, account, address(0), _asSingletonArray(id), _asSingletonArray(amount), "");
|
||||
|
||||
uint256 accountBalance = _balances[id][account];
|
||||
require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
|
||||
_balances[id][account] = accountBalance - amount;
|
||||
|
||||
emit TransferSingle(operator, account, address(0), id, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `ids` and `amounts` must have the same length.
|
||||
*/
|
||||
function _burnBatch(address account, uint256[] memory ids, uint256[] memory amounts) internal virtual {
|
||||
require(account != address(0), "ERC1155: burn from the zero address");
|
||||
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
|
||||
|
||||
address operator = _msgSender();
|
||||
|
||||
_beforeTokenTransfer(operator, account, address(0), ids, amounts, "");
|
||||
|
||||
for (uint i = 0; i < ids.length; i++) {
|
||||
uint256 id = ids[i];
|
||||
uint256 amount = amounts[i];
|
||||
|
||||
uint256 accountBalance = _balances[id][account];
|
||||
require(accountBalance >= amount, "ERC1155: burn amount exceeds balance");
|
||||
_balances[id][account] = accountBalance - amount;
|
||||
}
|
||||
|
||||
emit TransferBatch(operator, account, address(0), ids, amounts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Hook that is called before any token transfer. This includes minting
|
||||
* and burning, as well as batched variants.
|
||||
*
|
||||
* The same hook is called on both single and batched variants. For single
|
||||
* transfers, the length of the `id` and `amount` arrays will be 1.
|
||||
*
|
||||
* Calling conditions (for each `id` and `amount` pair):
|
||||
*
|
||||
* - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
|
||||
* of token type `id` will be transferred to `to`.
|
||||
* - When `from` is zero, `amount` tokens of token type `id` will be minted
|
||||
* for `to`.
|
||||
* - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
|
||||
* will be burned.
|
||||
* - `from` and `to` are never both zero.
|
||||
* - `ids` and `amounts` have the same, non-zero length.
|
||||
*
|
||||
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
|
||||
*/
|
||||
function _beforeTokenTransfer(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256[] memory ids,
|
||||
uint256[] memory amounts,
|
||||
bytes memory data
|
||||
)
|
||||
internal
|
||||
virtual
|
||||
{ }
|
||||
|
||||
function _doSafeTransferAcceptanceCheck(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256 id,
|
||||
uint256 amount,
|
||||
bytes memory data
|
||||
)
|
||||
private
|
||||
{
|
||||
if (to.isContract()) {
|
||||
try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
|
||||
if (response != IERC1155Receiver(to).onERC1155Received.selector) {
|
||||
revert("ERC1155: ERC1155Receiver rejected tokens");
|
||||
}
|
||||
} catch Error(string memory reason) {
|
||||
revert(reason);
|
||||
} catch {
|
||||
revert("ERC1155: transfer to non ERC1155Receiver implementer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _doSafeBatchTransferAcceptanceCheck(
|
||||
address operator,
|
||||
address from,
|
||||
address to,
|
||||
uint256[] memory ids,
|
||||
uint256[] memory amounts,
|
||||
bytes memory data
|
||||
)
|
||||
private
|
||||
{
|
||||
if (to.isContract()) {
|
||||
try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (bytes4 response) {
|
||||
if (response != IERC1155Receiver(to).onERC1155BatchReceived.selector) {
|
||||
revert("ERC1155: ERC1155Receiver rejected tokens");
|
||||
}
|
||||
} catch Error(string memory reason) {
|
||||
revert(reason);
|
||||
} catch {
|
||||
revert("ERC1155: transfer to non ERC1155Receiver implementer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
|
||||
uint256[] memory array = new uint256[](1);
|
||||
array[0] = element;
|
||||
|
||||
return array;
|
||||
}
|
||||
}
|
||||
50
contracts/external/ERC1155/InitializableERC1155.sol
vendored
Normal file
50
contracts/external/ERC1155/InitializableERC1155.sol
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {ERC1155} from "./ERC1155.sol";
|
||||
import {Strings} from "../utils/Strings.sol";
|
||||
|
||||
contract InitializableERC1155 is ERC1155 {
|
||||
using Strings for uint256;
|
||||
|
||||
mapping (uint256 => string) private _tokenURIs;
|
||||
string internal _baseUri = "";
|
||||
bool internal _INITIALIZED_;
|
||||
|
||||
function init(
|
||||
address creator,
|
||||
uint256 amount,
|
||||
string memory uri
|
||||
) public {
|
||||
require(!_INITIALIZED_, "INITIALIZED");
|
||||
_INITIALIZED_ = true;
|
||||
_mint(creator, 0, amount ,"");
|
||||
_setTokenURI(0, uri);
|
||||
}
|
||||
|
||||
function uri(uint256 tokenId) public view override returns (string memory) {
|
||||
string memory _tokenURI = _tokenURIs[tokenId];
|
||||
string memory base = _baseUri;
|
||||
|
||||
if (bytes(base).length == 0) {
|
||||
return _tokenURI;
|
||||
}
|
||||
|
||||
if (bytes(_tokenURI).length > 0) {
|
||||
return string(abi.encodePacked(base, _tokenURI));
|
||||
}
|
||||
|
||||
return super.uri(tokenId);
|
||||
}
|
||||
|
||||
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal {
|
||||
_tokenURIs[tokenId] = _tokenURI;
|
||||
}
|
||||
|
||||
}
|
||||
21
contracts/external/ERC20/InitializableERC20.sol
vendored
21
contracts/external/ERC20/InitializableERC20.sol
vendored
@@ -19,7 +19,7 @@ contract InitializableERC20 {
|
||||
|
||||
bool public initialized;
|
||||
|
||||
mapping(address => uint256) balances;
|
||||
mapping(address => uint256) internal balances;
|
||||
mapping(address => mapping(address => uint256)) internal allowed;
|
||||
|
||||
event Transfer(address indexed from, address indexed to, uint256 amount);
|
||||
@@ -43,12 +43,7 @@ contract InitializableERC20 {
|
||||
}
|
||||
|
||||
function transfer(address to, uint256 amount) public returns (bool) {
|
||||
require(to != address(0), "TO_ADDRESS_IS_EMPTY");
|
||||
require(amount <= balances[msg.sender], "BALANCE_NOT_ENOUGH");
|
||||
|
||||
balances[msg.sender] = balances[msg.sender].sub(amount);
|
||||
balances[to] = balances[to].add(amount);
|
||||
emit Transfer(msg.sender, to, amount);
|
||||
_transfer(msg.sender, to, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,4 +76,16 @@ contract InitializableERC20 {
|
||||
function allowance(address owner, address spender) public view returns (uint256) {
|
||||
return allowed[owner][spender];
|
||||
}
|
||||
|
||||
function _transfer(address sender, address recipient, uint256 amount) internal {
|
||||
require(sender != address(0), "FROM_ADDRESS_IS_EMPTY");
|
||||
require(recipient != address(0), "TO_ADDRESS_IS_EMPTY");
|
||||
require(amount <= balances[sender], "BALANCE_NOT_ENOUGH");
|
||||
|
||||
balances[sender] = balances[sender].sub(amount);
|
||||
balances[recipient] = balances[recipient].add(amount);
|
||||
|
||||
emit Transfer(sender, recipient, amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
92
contracts/external/ERC20/InitializableFragERC20.sol
vendored
Normal file
92
contracts/external/ERC20/InitializableFragERC20.sol
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {SafeMath} from "../../lib/SafeMath.sol";
|
||||
|
||||
contract InitializableFragERC20 {
|
||||
using SafeMath for uint256;
|
||||
|
||||
string public name;
|
||||
string public symbol;
|
||||
uint256 public totalSupply;
|
||||
|
||||
bool public initialized;
|
||||
|
||||
mapping(address => uint256) internal balances;
|
||||
mapping(address => mapping(address => uint256)) internal allowed;
|
||||
|
||||
event Transfer(address indexed from, address indexed to, uint256 amount);
|
||||
event Approval(address indexed owner, address indexed spender, uint256 amount);
|
||||
|
||||
function init(
|
||||
address _creator,
|
||||
uint256 _totalSupply,
|
||||
string memory _name,
|
||||
string memory _symbol
|
||||
) public {
|
||||
require(!initialized, "TOKEN_INITIALIZED");
|
||||
initialized = true;
|
||||
totalSupply = _totalSupply;
|
||||
balances[_creator] = _totalSupply;
|
||||
name = _name;
|
||||
symbol = _symbol;
|
||||
emit Transfer(address(0), _creator, _totalSupply);
|
||||
}
|
||||
|
||||
function decimals() public view returns (uint8) {
|
||||
return 18;
|
||||
}
|
||||
|
||||
function transfer(address to, uint256 amount) public returns (bool) {
|
||||
_transfer(msg.sender, to, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
function balanceOf(address owner) public view returns (uint256 balance) {
|
||||
return balances[owner];
|
||||
}
|
||||
|
||||
function transferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
) public returns (bool) {
|
||||
require(to != address(0), "TO_ADDRESS_IS_EMPTY");
|
||||
require(amount <= balances[from], "BALANCE_NOT_ENOUGH");
|
||||
require(amount <= allowed[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
|
||||
|
||||
balances[from] = balances[from].sub(amount);
|
||||
balances[to] = balances[to].add(amount);
|
||||
allowed[from][msg.sender] = allowed[from][msg.sender].sub(amount);
|
||||
emit Transfer(from, to, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
function approve(address spender, uint256 amount) public returns (bool) {
|
||||
allowed[msg.sender][spender] = amount;
|
||||
emit Approval(msg.sender, spender, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
function allowance(address owner, address spender) public view returns (uint256) {
|
||||
return allowed[owner][spender];
|
||||
}
|
||||
|
||||
function _transfer(address sender, address recipient, uint256 amount) internal {
|
||||
require(sender != address(0), "FROM_ADDRESS_IS_EMPTY");
|
||||
require(recipient != address(0), "TO_ADDRESS_IS_EMPTY");
|
||||
require(amount <= balances[sender], "BALANCE_NOT_ENOUGH");
|
||||
|
||||
balances[sender] = balances[sender].sub(amount);
|
||||
balances[recipient] = balances[recipient].add(amount);
|
||||
|
||||
emit Transfer(sender, recipient, amount);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ contract InitializableMintableERC20 is InitializableOwnable {
|
||||
string public symbol;
|
||||
uint256 public totalSupply;
|
||||
|
||||
mapping(address => uint256) balances;
|
||||
mapping(address => uint256) internal balances;
|
||||
mapping(address => mapping(address => uint256)) internal allowed;
|
||||
|
||||
event Transfer(address indexed from, address indexed to, uint256 amount);
|
||||
@@ -42,7 +42,7 @@ contract InitializableMintableERC20 is InitializableOwnable {
|
||||
emit Transfer(address(0), _creator, _initSupply);
|
||||
}
|
||||
|
||||
function transfer(address to, uint256 amount) public returns (bool) {
|
||||
function transfer(address to, uint256 amount) public virtual returns (bool) {
|
||||
require(to != address(0), "TO_ADDRESS_IS_EMPTY");
|
||||
require(amount <= balances[msg.sender], "BALANCE_NOT_ENOUGH");
|
||||
|
||||
@@ -60,7 +60,7 @@ contract InitializableMintableERC20 is InitializableOwnable {
|
||||
address from,
|
||||
address to,
|
||||
uint256 amount
|
||||
) public returns (bool) {
|
||||
) public virtual returns (bool) {
|
||||
require(to != address(0), "TO_ADDRESS_IS_EMPTY");
|
||||
require(amount <= balances[from], "BALANCE_NOT_ENOUGH");
|
||||
require(amount <= allowed[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
|
||||
@@ -72,7 +72,7 @@ contract InitializableMintableERC20 is InitializableOwnable {
|
||||
return true;
|
||||
}
|
||||
|
||||
function approve(address spender, uint256 amount) public returns (bool) {
|
||||
function approve(address spender, uint256 amount) public virtual returns (bool) {
|
||||
allowed[msg.sender][spender] = amount;
|
||||
emit Approval(msg.sender, spender, amount);
|
||||
return true;
|
||||
@@ -83,13 +83,21 @@ contract InitializableMintableERC20 is InitializableOwnable {
|
||||
}
|
||||
|
||||
function mint(address user, uint256 value) external onlyOwner {
|
||||
_mint(user, value);
|
||||
}
|
||||
|
||||
function burn(address user, uint256 value) external onlyOwner {
|
||||
_burn(user, value);
|
||||
}
|
||||
|
||||
function _mint(address user, uint256 value) internal {
|
||||
balances[user] = balances[user].add(value);
|
||||
totalSupply = totalSupply.add(value);
|
||||
emit Mint(user, value);
|
||||
emit Transfer(address(0), user, value);
|
||||
}
|
||||
|
||||
function burn(address user, uint256 value) external onlyOwner {
|
||||
function _burn(address user, uint256 value) internal {
|
||||
balances[user] = balances[user].sub(value);
|
||||
totalSupply = totalSupply.sub(value);
|
||||
emit Burn(user, value);
|
||||
|
||||
372
contracts/external/ERC721/ERC721.sol
vendored
Normal file
372
contracts/external/ERC721/ERC721.sol
vendored
Normal file
@@ -0,0 +1,372 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IERC721} from "../../intf/IERC721.sol";
|
||||
import {IERC165} from "../../intf/IERC165.sol";
|
||||
import {IERC721Receiver} from "../../intf/IERC721Receiver.sol";
|
||||
import {IERC721Metadata} from "../../intf/IERC721Metadata.sol";
|
||||
import {ERC165} from "../utils/ERC165.sol";
|
||||
import {Strings} from "../utils/Strings.sol";
|
||||
import {Address} from "../utils/Address.sol";
|
||||
import {Context} from "../utils/Context.sol";
|
||||
|
||||
/**
|
||||
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
|
||||
* the Metadata extension, but not including the Enumerable extension, which is available separately as
|
||||
* {ERC721Enumerable}.
|
||||
*/
|
||||
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
|
||||
using Address for address;
|
||||
using Strings for uint256;
|
||||
|
||||
// Token name
|
||||
string internal _name;
|
||||
|
||||
// Token symbol
|
||||
string internal _symbol;
|
||||
|
||||
string internal _baseUri = "";
|
||||
|
||||
// Mapping from token ID to owner address
|
||||
mapping (uint256 => address) private _owners;
|
||||
|
||||
// Mapping owner address to token count
|
||||
mapping (address => uint256) private _balances;
|
||||
|
||||
// Mapping from token ID to approved address
|
||||
mapping (uint256 => address) private _tokenApprovals;
|
||||
|
||||
// Mapping from owner to operator approvals
|
||||
mapping (address => mapping (address => bool)) private _operatorApprovals;
|
||||
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
|
||||
return interfaceId == type(IERC721).interfaceId
|
||||
|| interfaceId == type(IERC721Metadata).interfaceId
|
||||
|| super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-balanceOf}.
|
||||
*/
|
||||
function balanceOf(address owner) public view virtual override returns (uint256) {
|
||||
require(owner != address(0), "ERC721: balance query for the zero address");
|
||||
return _balances[owner];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-ownerOf}.
|
||||
*/
|
||||
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
|
||||
address owner = _owners[tokenId];
|
||||
require(owner != address(0), "ERC721: owner query for nonexistent token");
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Metadata-name}.
|
||||
*/
|
||||
function name() public view virtual override returns (string memory) {
|
||||
return _name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Metadata-symbol}.
|
||||
*/
|
||||
function symbol() public view virtual override returns (string memory) {
|
||||
return _symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Metadata-tokenURI}.
|
||||
*/
|
||||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
||||
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
|
||||
|
||||
string memory baseURI = _baseURI();
|
||||
return bytes(baseURI).length > 0
|
||||
? string(abi.encodePacked(baseURI, tokenId.toString()))
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Base URI for computing {tokenURI}. Empty by default, can be overriden
|
||||
* in child contracts.
|
||||
*/
|
||||
function _baseURI() internal view virtual returns (string memory) {
|
||||
return _baseUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-approve}.
|
||||
*/
|
||||
function approve(address to, uint256 tokenId) public virtual override {
|
||||
address owner = ERC721.ownerOf(tokenId);
|
||||
require(to != owner, "ERC721: approval to current owner");
|
||||
|
||||
require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
|
||||
"ERC721: approve caller is not owner nor approved for all"
|
||||
);
|
||||
|
||||
_approve(to, tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-getApproved}.
|
||||
*/
|
||||
function getApproved(uint256 tokenId) public view virtual override returns (address) {
|
||||
require(_exists(tokenId), "ERC721: approved query for nonexistent token");
|
||||
|
||||
return _tokenApprovals[tokenId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-setApprovalForAll}.
|
||||
*/
|
||||
function setApprovalForAll(address operator, bool approved) public virtual override {
|
||||
require(operator != _msgSender(), "ERC721: approve to caller");
|
||||
|
||||
_operatorApprovals[_msgSender()][operator] = approved;
|
||||
emit ApprovalForAll(_msgSender(), operator, approved);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-isApprovedForAll}.
|
||||
*/
|
||||
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
|
||||
return _operatorApprovals[owner][operator];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-transferFrom}.
|
||||
*/
|
||||
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
|
||||
//solhint-disable-next-line max-line-length
|
||||
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
|
||||
|
||||
_transfer(from, to, tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-safeTransferFrom}.
|
||||
*/
|
||||
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
|
||||
safeTransferFrom(from, to, tokenId, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721-safeTransferFrom}.
|
||||
*/
|
||||
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory _data) public virtual override {
|
||||
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
|
||||
_safeTransfer(from, to, tokenId, _data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
|
||||
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
|
||||
*
|
||||
* `_data` is additional data, it has no specified format and it is sent in call to `to`.
|
||||
*
|
||||
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
|
||||
* implement alternative mechanisms to perform token transfer, such as signature-based.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `from` cannot be the zero address.
|
||||
* - `to` cannot be the zero address.
|
||||
* - `tokenId` token must exist and be owned by `from`.
|
||||
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory _data) internal virtual {
|
||||
_transfer(from, to, tokenId);
|
||||
require(_checkOnERC721Received(from, to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns whether `tokenId` exists.
|
||||
*
|
||||
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
|
||||
*
|
||||
* Tokens start existing when they are minted (`_mint`),
|
||||
* and stop existing when they are burned (`_burn`).
|
||||
*/
|
||||
function _exists(uint256 tokenId) internal view virtual returns (bool) {
|
||||
return _owners[tokenId] != address(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns whether `spender` is allowed to manage `tokenId`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*/
|
||||
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
|
||||
require(_exists(tokenId), "ERC721: operator query for nonexistent token");
|
||||
address owner = ERC721.ownerOf(tokenId);
|
||||
return (spender == owner || getApproved(tokenId) == spender || isApprovedForAll(owner, spender));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Safely mints `tokenId` and transfers it to `to`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must not exist.
|
||||
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function _safeMint(address to, uint256 tokenId) internal virtual {
|
||||
_safeMint(to, tokenId, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
|
||||
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
|
||||
*/
|
||||
function _safeMint(address to, uint256 tokenId, bytes memory _data) internal virtual {
|
||||
_mint(to, tokenId);
|
||||
require(_checkOnERC721Received(address(0), to, tokenId, _data), "ERC721: transfer to non ERC721Receiver implementer");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Mints `tokenId` and transfers it to `to`.
|
||||
*
|
||||
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must not exist.
|
||||
* - `to` cannot be the zero address.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function _mint(address to, uint256 tokenId) internal virtual {
|
||||
require(to != address(0), "ERC721: mint to the zero address");
|
||||
require(!_exists(tokenId), "ERC721: token already minted");
|
||||
|
||||
_beforeTokenTransfer(address(0), to, tokenId);
|
||||
|
||||
_balances[to] += 1;
|
||||
_owners[tokenId] = to;
|
||||
|
||||
emit Transfer(address(0), to, tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Destroys `tokenId`.
|
||||
* The approval is cleared when the token is burned.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function _burn(uint256 tokenId) internal virtual {
|
||||
address owner = ERC721.ownerOf(tokenId);
|
||||
|
||||
_beforeTokenTransfer(owner, address(0), tokenId);
|
||||
|
||||
// Clear approvals
|
||||
_approve(address(0), tokenId);
|
||||
|
||||
_balances[owner] -= 1;
|
||||
delete _owners[tokenId];
|
||||
|
||||
emit Transfer(owner, address(0), tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Transfers `tokenId` from `from` to `to`.
|
||||
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `to` cannot be the zero address.
|
||||
* - `tokenId` token must be owned by `from`.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function _transfer(address from, address to, uint256 tokenId) internal virtual {
|
||||
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer of token that is not own");
|
||||
require(to != address(0), "ERC721: transfer to the zero address");
|
||||
|
||||
_beforeTokenTransfer(from, to, tokenId);
|
||||
|
||||
// Clear approvals from the previous owner
|
||||
_approve(address(0), tokenId);
|
||||
|
||||
_balances[from] -= 1;
|
||||
_balances[to] += 1;
|
||||
_owners[tokenId] = to;
|
||||
|
||||
emit Transfer(from, to, tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Approve `to` to operate on `tokenId`
|
||||
*
|
||||
* Emits a {Approval} event.
|
||||
*/
|
||||
function _approve(address to, uint256 tokenId) internal virtual {
|
||||
_tokenApprovals[tokenId] = to;
|
||||
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
|
||||
* The call is not executed if the target address is not a contract.
|
||||
*
|
||||
* @param from address representing the previous owner of the given token ID
|
||||
* @param to target address that will receive the tokens
|
||||
* @param tokenId uint256 ID of the token to be transferred
|
||||
* @param _data bytes optional data to send along with the call
|
||||
* @return bool whether the call correctly returned the expected magic value
|
||||
*/
|
||||
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data)
|
||||
private returns (bool)
|
||||
{
|
||||
if (to.isContract()) {
|
||||
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {
|
||||
return retval == IERC721Receiver(to).onERC721Received.selector;
|
||||
} catch (bytes memory reason) {
|
||||
if (reason.length == 0) {
|
||||
revert("ERC721: transfer to non ERC721Receiver implementer");
|
||||
} else {
|
||||
// solhint-disable-next-line no-inline-assembly
|
||||
assembly {
|
||||
revert(add(32, reason), mload(reason))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Hook that is called before any token transfer. This includes minting
|
||||
* and burning.
|
||||
*
|
||||
* Calling conditions:
|
||||
*
|
||||
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
|
||||
* transferred to `to`.
|
||||
* - When `from` is zero, `tokenId` will be minted for `to`.
|
||||
* - When `to` is zero, ``from``'s `tokenId` will be burned.
|
||||
* - `from` cannot be the zero address.
|
||||
* - `to` cannot be the zero address.
|
||||
*
|
||||
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
|
||||
*/
|
||||
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual { }
|
||||
}
|
||||
160
contracts/external/ERC721/ERC721Enumerable.sol
vendored
Normal file
160
contracts/external/ERC721/ERC721Enumerable.sol
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721Enumerable.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import "./ERC721.sol";
|
||||
import "../../intf/IERC721Enumerable.sol";
|
||||
|
||||
/**
|
||||
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
|
||||
* enumerability of all the token ids in the contract as well as all token ids owned by each
|
||||
* account.
|
||||
*/
|
||||
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
|
||||
// Mapping from owner to list of owned token IDs
|
||||
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
|
||||
|
||||
// Mapping from token ID to index of the owner tokens list
|
||||
mapping(uint256 => uint256) private _ownedTokensIndex;
|
||||
|
||||
// Array with all token ids, used for enumeration
|
||||
uint256[] private _allTokens;
|
||||
|
||||
// Mapping from token id to position in the allTokens array
|
||||
mapping(uint256 => uint256) private _allTokensIndex;
|
||||
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
|
||||
return interfaceId == type(IERC721Enumerable).interfaceId
|
||||
|| super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
|
||||
*/
|
||||
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
|
||||
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
|
||||
return _ownedTokens[owner][index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Enumerable-totalSupply}.
|
||||
*/
|
||||
function totalSupply() public view virtual override returns (uint256) {
|
||||
return _allTokens.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Enumerable-tokenByIndex}.
|
||||
*/
|
||||
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
|
||||
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
|
||||
return _allTokens[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Hook that is called before any token transfer. This includes minting
|
||||
* and burning.
|
||||
*
|
||||
* Calling conditions:
|
||||
*
|
||||
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
|
||||
* transferred to `to`.
|
||||
* - When `from` is zero, `tokenId` will be minted for `to`.
|
||||
* - When `to` is zero, ``from``'s `tokenId` will be burned.
|
||||
* - `from` cannot be the zero address.
|
||||
* - `to` cannot be the zero address.
|
||||
*
|
||||
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
|
||||
*/
|
||||
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override {
|
||||
super._beforeTokenTransfer(from, to, tokenId);
|
||||
|
||||
if (from == address(0)) {
|
||||
_addTokenToAllTokensEnumeration(tokenId);
|
||||
} else if (from != to) {
|
||||
_removeTokenFromOwnerEnumeration(from, tokenId);
|
||||
}
|
||||
if (to == address(0)) {
|
||||
_removeTokenFromAllTokensEnumeration(tokenId);
|
||||
} else if (to != from) {
|
||||
_addTokenToOwnerEnumeration(to, tokenId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Private function to add a token to this extension's ownership-tracking data structures.
|
||||
* @param to address representing the new owner of the given token ID
|
||||
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
|
||||
*/
|
||||
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
|
||||
uint256 length = ERC721.balanceOf(to);
|
||||
_ownedTokens[to][length] = tokenId;
|
||||
_ownedTokensIndex[tokenId] = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Private function to add a token to this extension's token tracking data structures.
|
||||
* @param tokenId uint256 ID of the token to be added to the tokens list
|
||||
*/
|
||||
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
|
||||
_allTokensIndex[tokenId] = _allTokens.length;
|
||||
_allTokens.push(tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
|
||||
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
|
||||
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
|
||||
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
|
||||
* @param from address representing the previous owner of the given token ID
|
||||
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
|
||||
*/
|
||||
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
|
||||
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
|
||||
// then delete the last slot (swap and pop).
|
||||
|
||||
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
|
||||
uint256 tokenIndex = _ownedTokensIndex[tokenId];
|
||||
|
||||
// When the token to delete is the last token, the swap operation is unnecessary
|
||||
if (tokenIndex != lastTokenIndex) {
|
||||
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
|
||||
|
||||
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
|
||||
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
|
||||
}
|
||||
|
||||
// This also deletes the contents at the last position of the array
|
||||
delete _ownedTokensIndex[tokenId];
|
||||
delete _ownedTokens[from][lastTokenIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Private function to remove a token from this extension's token tracking data structures.
|
||||
* This has O(1) time complexity, but alters the order of the _allTokens array.
|
||||
* @param tokenId uint256 ID of the token to be removed from the tokens list
|
||||
*/
|
||||
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
|
||||
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
|
||||
// then delete the last slot (swap and pop).
|
||||
|
||||
uint256 lastTokenIndex = _allTokens.length - 1;
|
||||
uint256 tokenIndex = _allTokensIndex[tokenId];
|
||||
|
||||
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
|
||||
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
|
||||
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
|
||||
uint256 lastTokenId = _allTokens[lastTokenIndex];
|
||||
|
||||
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
|
||||
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
|
||||
|
||||
// This also deletes the contents at the last position of the array
|
||||
delete _allTokensIndex[tokenId];
|
||||
_allTokens.pop();
|
||||
}
|
||||
}
|
||||
67
contracts/external/ERC721/ERC721URIStorage.sol
vendored
Normal file
67
contracts/external/ERC721/ERC721URIStorage.sol
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/ERC721URIStorage.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import "./ERC721Enumerable.sol";
|
||||
|
||||
/**
|
||||
* @dev ERC721 token with storage based token URI management.
|
||||
*/
|
||||
abstract contract ERC721URIStorage is ERC721Enumerable {
|
||||
using Strings for uint256;
|
||||
|
||||
// Optional mapping for token URIs
|
||||
mapping (uint256 => string) private _tokenURIs;
|
||||
|
||||
/**
|
||||
* @dev See {IERC721Metadata-tokenURI}.
|
||||
*/
|
||||
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
|
||||
require(_exists(tokenId), "ERC721URIStorage: URI query for nonexistent token");
|
||||
|
||||
string memory _tokenURI = _tokenURIs[tokenId];
|
||||
string memory base = _baseURI();
|
||||
|
||||
// If there is no base URI, return the token URI.
|
||||
if (bytes(base).length == 0) {
|
||||
return _tokenURI;
|
||||
}
|
||||
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
|
||||
if (bytes(_tokenURI).length > 0) {
|
||||
return string(abi.encodePacked(base, _tokenURI));
|
||||
}
|
||||
|
||||
return super.tokenURI(tokenId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*/
|
||||
function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual {
|
||||
require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token");
|
||||
_tokenURIs[tokenId] = _tokenURI;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Destroys `tokenId`.
|
||||
* The approval is cleared when the token is burned.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function _burn(uint256 tokenId) internal virtual override {
|
||||
super._burn(tokenId);
|
||||
|
||||
if (bytes(_tokenURIs[tokenId]).length != 0) {
|
||||
delete _tokenURIs[tokenId];
|
||||
}
|
||||
}
|
||||
}
|
||||
24
contracts/external/ERC721/InitializableERC721.sol
vendored
Normal file
24
contracts/external/ERC721/InitializableERC721.sol
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {ERC721URIStorage} from "./ERC721URIStorage.sol";
|
||||
|
||||
contract InitializableERC721 is ERC721URIStorage {
|
||||
function init(
|
||||
address creator,
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
string memory uri
|
||||
) public {
|
||||
_name = name;
|
||||
_symbol = symbol;
|
||||
_mint(creator, 0);
|
||||
_setTokenURI(0, uri);
|
||||
}
|
||||
}
|
||||
190
contracts/external/utils/Address.sol
vendored
Normal file
190
contracts/external/utils/Address.sol
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Address.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
/**
|
||||
* @dev Collection of functions related to the address type
|
||||
*/
|
||||
library Address {
|
||||
/**
|
||||
* @dev Returns true if `account` is a contract.
|
||||
*
|
||||
* [IMPORTANT]
|
||||
* ====
|
||||
* It is unsafe to assume that an address for which this function returns
|
||||
* false is an externally-owned account (EOA) and not a contract.
|
||||
*
|
||||
* Among others, `isContract` will return false for the following
|
||||
* types of addresses:
|
||||
*
|
||||
* - an externally-owned account
|
||||
* - a contract in construction
|
||||
* - an address where a contract will be created
|
||||
* - an address where a contract lived, but was destroyed
|
||||
* ====
|
||||
*/
|
||||
function isContract(address account) internal view returns (bool) {
|
||||
// This method relies on extcodesize, which returns 0 for contracts in
|
||||
// construction, since the code is only stored at the end of the
|
||||
// constructor execution.
|
||||
|
||||
uint256 size;
|
||||
// solhint-disable-next-line no-inline-assembly
|
||||
assembly { size := extcodesize(account) }
|
||||
return size > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
|
||||
* `recipient`, forwarding all available gas and reverting on errors.
|
||||
*
|
||||
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
|
||||
* of certain opcodes, possibly making contracts go over the 2300 gas limit
|
||||
* imposed by `transfer`, making them unable to receive funds via
|
||||
* `transfer`. {sendValue} removes this limitation.
|
||||
*
|
||||
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
|
||||
*
|
||||
* IMPORTANT: because control is transferred to `recipient`, care must be
|
||||
* taken to not create reentrancy vulnerabilities. Consider using
|
||||
* {ReentrancyGuard} or the
|
||||
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
|
||||
*/
|
||||
function sendValue(address payable recipient, uint256 amount) internal {
|
||||
require(address(this).balance >= amount, "Address: insufficient balance");
|
||||
|
||||
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
|
||||
(bool success, ) = recipient.call{ value: amount }("");
|
||||
require(success, "Address: unable to send value, recipient may have reverted");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Performs a Solidity function call using a low level `call`. A
|
||||
* plain`call` is an unsafe replacement for a function call: use this
|
||||
* function instead.
|
||||
*
|
||||
* If `target` reverts with a revert reason, it is bubbled up by this
|
||||
* function (like regular Solidity function calls).
|
||||
*
|
||||
* Returns the raw returned data. To convert to the expected return value,
|
||||
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `target` must be a contract.
|
||||
* - calling `target` with `data` must not revert.
|
||||
*
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
|
||||
return functionCall(target, data, "Address: low-level call failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
|
||||
* `errorMessage` as a fallback revert reason when `target` reverts.
|
||||
*
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
|
||||
return functionCallWithValue(target, data, 0, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
||||
* but also transferring `value` wei to `target`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - the calling contract must have an ETH balance of at least `value`.
|
||||
* - the called Solidity function must be `payable`.
|
||||
*
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
|
||||
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
|
||||
* with `errorMessage` as a fallback revert reason when `target` reverts.
|
||||
*
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
|
||||
require(address(this).balance >= value, "Address: insufficient balance for call");
|
||||
require(isContract(target), "Address: call to non-contract");
|
||||
|
||||
// solhint-disable-next-line avoid-low-level-calls
|
||||
(bool success, bytes memory returndata) = target.call{ value: value }(data);
|
||||
return _verifyCallResult(success, returndata, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
||||
* but performing a static call.
|
||||
*
|
||||
* _Available since v3.3._
|
||||
*/
|
||||
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
|
||||
return functionStaticCall(target, data, "Address: low-level static call failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
|
||||
* but performing a static call.
|
||||
*
|
||||
* _Available since v3.3._
|
||||
*/
|
||||
function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
|
||||
require(isContract(target), "Address: static call to non-contract");
|
||||
|
||||
// solhint-disable-next-line avoid-low-level-calls
|
||||
(bool success, bytes memory returndata) = target.staticcall(data);
|
||||
return _verifyCallResult(success, returndata, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
|
||||
* but performing a delegate call.
|
||||
*
|
||||
* _Available since v3.4._
|
||||
*/
|
||||
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
|
||||
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
|
||||
* but performing a delegate call.
|
||||
*
|
||||
* _Available since v3.4._
|
||||
*/
|
||||
function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
|
||||
require(isContract(target), "Address: delegate call to non-contract");
|
||||
|
||||
// solhint-disable-next-line avoid-low-level-calls
|
||||
(bool success, bytes memory returndata) = target.delegatecall(data);
|
||||
return _verifyCallResult(success, returndata, errorMessage);
|
||||
}
|
||||
|
||||
function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
|
||||
if (success) {
|
||||
return returndata;
|
||||
} else {
|
||||
// Look for revert reason and bubble it up if present
|
||||
if (returndata.length > 0) {
|
||||
// The easiest way to bubble the revert reason is using memory via assembly
|
||||
|
||||
// solhint-disable-next-line no-inline-assembly
|
||||
assembly {
|
||||
let returndata_size := mload(returndata)
|
||||
revert(add(32, returndata), returndata_size)
|
||||
}
|
||||
} else {
|
||||
revert(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
contracts/external/utils/Context.sol
vendored
Normal file
25
contracts/external/utils/Context.sol
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Context.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
/*
|
||||
* @dev Provides information about the current execution context, including the
|
||||
* sender of the transaction and its data. While these are generally available
|
||||
* via msg.sender and msg.data, they should not be accessed in such a direct
|
||||
* manner, since when dealing with meta-transactions the account sending and
|
||||
* paying for execution may not be the actual sender (as far as an application
|
||||
* is concerned).
|
||||
*
|
||||
* This contract is only required for intermediate, library-like contracts.
|
||||
*/
|
||||
abstract contract Context {
|
||||
function _msgSender() internal view virtual returns (address) {
|
||||
return msg.sender;
|
||||
}
|
||||
|
||||
function _msgData() internal view virtual returns (bytes calldata) {
|
||||
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
|
||||
return msg.data;
|
||||
}
|
||||
}
|
||||
29
contracts/external/utils/ERC165.sol
vendored
Normal file
29
contracts/external/utils/ERC165.sol
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/introspection/ERC165.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import "../../intf/IERC165.sol";
|
||||
|
||||
/**
|
||||
* @dev Implementation of the {IERC165} interface.
|
||||
*
|
||||
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
|
||||
* for the additional interface id that will be supported. For example:
|
||||
*
|
||||
* ```solidity
|
||||
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
||||
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
|
||||
*/
|
||||
abstract contract ERC165 is IERC165 {
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
|
||||
return interfaceId == type(IERC165).interfaceId;
|
||||
}
|
||||
}
|
||||
68
contracts/external/utils/Strings.sol
vendored
Normal file
68
contracts/external/utils/Strings.sol
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
/**
|
||||
* @dev String operations.
|
||||
*/
|
||||
library Strings {
|
||||
bytes16 private constant alphabet = "0123456789abcdef";
|
||||
|
||||
/**
|
||||
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
|
||||
*/
|
||||
function toString(uint256 value) internal pure returns (string memory) {
|
||||
// Inspired by OraclizeAPI's implementation - MIT licence
|
||||
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
|
||||
|
||||
if (value == 0) {
|
||||
return "0";
|
||||
}
|
||||
uint256 temp = value;
|
||||
uint256 digits;
|
||||
while (temp != 0) {
|
||||
digits++;
|
||||
temp /= 10;
|
||||
}
|
||||
bytes memory buffer = new bytes(digits);
|
||||
while (value != 0) {
|
||||
digits -= 1;
|
||||
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
|
||||
value /= 10;
|
||||
}
|
||||
return string(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
|
||||
*/
|
||||
function toHexString(uint256 value) internal pure returns (string memory) {
|
||||
if (value == 0) {
|
||||
return "0x00";
|
||||
}
|
||||
uint256 temp = value;
|
||||
uint256 length = 0;
|
||||
while (temp != 0) {
|
||||
length++;
|
||||
temp >>= 8;
|
||||
}
|
||||
return toHexString(value, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
|
||||
*/
|
||||
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
|
||||
bytes memory buffer = new bytes(2 * length + 2);
|
||||
buffer[0] = "0";
|
||||
buffer[1] = "x";
|
||||
for (uint256 i = 2 * length + 1; i > 1; --i) {
|
||||
buffer[i] = alphabet[value & 0xf];
|
||||
value >>= 4;
|
||||
}
|
||||
require(value == 0, "Strings: hex length insufficient");
|
||||
return string(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface IDODOApprove {
|
||||
function claimTokens(address token,address who,address dest,uint256 amount) external;
|
||||
|
||||
@@ -50,4 +50,10 @@ interface IDODOCallee {
|
||||
uint256 quoteAmount,
|
||||
bytes calldata data
|
||||
) external;
|
||||
|
||||
function NFTRedeemCall(
|
||||
address payable assetTo,
|
||||
uint256 quoteAmount,
|
||||
bytes calldata
|
||||
) external;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
131
contracts/intf/IERC1155.sol
Normal file
131
contracts/intf/IERC1155.sol
Normal file
@@ -0,0 +1,131 @@
|
||||
// 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.9;
|
||||
|
||||
import "./IERC165.sol";
|
||||
|
||||
/**
|
||||
* @dev Required interface of an ERC1155 compliant contract, as defined in the
|
||||
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
|
||||
*
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
interface IERC1155 is IERC165 {
|
||||
/**
|
||||
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
|
||||
*/
|
||||
event TransferSingle(
|
||||
address indexed operator,
|
||||
address indexed from,
|
||||
address indexed to,
|
||||
uint256 id,
|
||||
uint256 value
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
|
||||
* transfers.
|
||||
*/
|
||||
event TransferBatch(
|
||||
address indexed operator,
|
||||
address indexed from,
|
||||
address indexed to,
|
||||
uint256[] ids,
|
||||
uint256[] values
|
||||
);
|
||||
|
||||
/**
|
||||
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
|
||||
* `approved`.
|
||||
*/
|
||||
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
|
||||
|
||||
/**
|
||||
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
|
||||
*
|
||||
* If an {URI} event was emitted for `id`, the standard
|
||||
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
|
||||
* returned by {IERC1155MetadataURI-uri}.
|
||||
*/
|
||||
event URI(string value, uint256 indexed id);
|
||||
|
||||
/**
|
||||
* @dev Returns the amount of tokens of token type `id` owned by `account`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `account` cannot be the zero address.
|
||||
*/
|
||||
function balanceOf(address account, uint256 id) external view returns (uint256);
|
||||
|
||||
/**
|
||||
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `accounts` and `ids` must have the same length.
|
||||
*/
|
||||
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
|
||||
external
|
||||
view
|
||||
returns (uint256[] memory);
|
||||
|
||||
/**
|
||||
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
|
||||
*
|
||||
* Emits an {ApprovalForAll} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `operator` cannot be the caller.
|
||||
*/
|
||||
function setApprovalForAll(address operator, bool approved) external;
|
||||
|
||||
/**
|
||||
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
|
||||
*
|
||||
* See {setApprovalForAll}.
|
||||
*/
|
||||
function isApprovedForAll(address account, address operator) external view returns (bool);
|
||||
|
||||
/**
|
||||
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
|
||||
*
|
||||
* Emits a {TransferSingle} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `to` cannot be the zero address.
|
||||
* - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.
|
||||
* - `from` must have a balance of tokens of type `id` of at least `amount`.
|
||||
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
|
||||
* acceptance magic value.
|
||||
*/
|
||||
function safeTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 id,
|
||||
uint256 amount,
|
||||
bytes calldata data
|
||||
) external;
|
||||
|
||||
/**
|
||||
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
|
||||
*
|
||||
* Emits a {TransferBatch} event.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `ids` and `amounts` must have the same length.
|
||||
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
|
||||
* acceptance magic value.
|
||||
*/
|
||||
function safeBatchTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256[] calldata ids,
|
||||
uint256[] calldata amounts,
|
||||
bytes calldata data
|
||||
) external;
|
||||
}
|
||||
22
contracts/intf/IERC1155MetadataURI.sol
Normal file
22
contracts/intf/IERC1155MetadataURI.sol
Normal file
@@ -0,0 +1,22 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import "./IERC1155.sol";
|
||||
|
||||
/**
|
||||
* @dev Interface of the optional ERC1155MetadataExtension interface, as defined
|
||||
* in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
|
||||
*
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
interface IERC1155MetadataURI is IERC1155 {
|
||||
/**
|
||||
* @dev Returns the URI for token type `id`.
|
||||
*
|
||||
* If the `\{id\}` substring is present in the URI, it must be replaced by
|
||||
* clients with the actual token type ID.
|
||||
*/
|
||||
function uri(uint256 id) external view returns (string memory);
|
||||
}
|
||||
53
contracts/intf/IERC1155Receiver.sol
Normal file
53
contracts/intf/IERC1155Receiver.sol
Normal file
@@ -0,0 +1,53 @@
|
||||
// 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.9;
|
||||
|
||||
import "./IERC165.sol";
|
||||
|
||||
/**
|
||||
* _Available since v3.1._
|
||||
*/
|
||||
interface IERC1155Receiver is IERC165 {
|
||||
/**
|
||||
@dev Handles the receipt of a single ERC1155 token type. This function is
|
||||
called at the end of a `safeTransferFrom` after the balance has been updated.
|
||||
To accept the transfer, this must return
|
||||
`bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
|
||||
(i.e. 0xf23a6e61, or its own function selector).
|
||||
@param operator The address which initiated the transfer (i.e. msg.sender)
|
||||
@param from The address which previously owned the token
|
||||
@param id The ID of the token being transferred
|
||||
@param value The amount of tokens being transferred
|
||||
@param data Additional data with no specified format
|
||||
@return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
|
||||
*/
|
||||
function onERC1155Received(
|
||||
address operator,
|
||||
address from,
|
||||
uint256 id,
|
||||
uint256 value,
|
||||
bytes calldata data
|
||||
) external returns (bytes4);
|
||||
|
||||
/**
|
||||
@dev Handles the receipt of a multiple ERC1155 token types. This function
|
||||
is called at the end of a `safeBatchTransferFrom` after the balances have
|
||||
been updated. To accept the transfer(s), this must return
|
||||
`bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
|
||||
(i.e. 0xbc197c81, or its own function selector).
|
||||
@param operator The address which initiated the batch transfer (i.e. msg.sender)
|
||||
@param from The address which previously owned the token
|
||||
@param ids An array containing ids of each token being transferred (order and length must match values array)
|
||||
@param values An array containing amounts of each token being transferred (order and length must match ids array)
|
||||
@param data Additional data with no specified format
|
||||
@return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
|
||||
*/
|
||||
function onERC1155BatchReceived(
|
||||
address operator,
|
||||
address from,
|
||||
uint256[] calldata ids,
|
||||
uint256[] calldata values,
|
||||
bytes calldata data
|
||||
) external returns (bytes4);
|
||||
}
|
||||
25
contracts/intf/IERC165.sol
Normal file
25
contracts/intf/IERC165.sol
Normal file
@@ -0,0 +1,25 @@
|
||||
// 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.9;
|
||||
|
||||
/**
|
||||
* @dev Interface of the ERC165 standard, as defined in the
|
||||
* https://eips.ethereum.org/EIPS/eip-165[EIP].
|
||||
*
|
||||
* Implementers can declare support of contract interfaces, which can then be
|
||||
* queried by others ({ERC165Checker}).
|
||||
*
|
||||
* For an implementation, see {ERC165}.
|
||||
*/
|
||||
interface IERC165 {
|
||||
/**
|
||||
* @dev Returns true if this contract implements the interface defined by
|
||||
* `interfaceId`. See the corresponding
|
||||
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
|
||||
* to learn more about how these ids are created.
|
||||
*
|
||||
* This function call must use less than 30 000 gas.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId) external view returns (bool);
|
||||
}
|
||||
@@ -72,4 +72,4 @@ interface IERC20 {
|
||||
address recipient,
|
||||
uint256 amount
|
||||
) external returns (bool);
|
||||
}
|
||||
}
|
||||
143
contracts/intf/IERC721.sol
Normal file
143
contracts/intf/IERC721.sol
Normal file
@@ -0,0 +1,143 @@
|
||||
// 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.9;
|
||||
|
||||
import "./IERC165.sol";
|
||||
|
||||
/**
|
||||
* @dev Required interface of an ERC721 compliant contract.
|
||||
*/
|
||||
interface IERC721 is IERC165 {
|
||||
/**
|
||||
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
|
||||
*/
|
||||
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
|
||||
|
||||
/**
|
||||
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
|
||||
*/
|
||||
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
|
||||
|
||||
/**
|
||||
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
|
||||
*/
|
||||
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
|
||||
|
||||
/**
|
||||
* @dev Returns the number of tokens in ``owner``'s account.
|
||||
*/
|
||||
function balanceOf(address owner) external view returns (uint256 balance);
|
||||
|
||||
/**
|
||||
* @dev Returns the owner of the `tokenId` token.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*/
|
||||
function ownerOf(uint256 tokenId) external view returns (address owner);
|
||||
|
||||
/**
|
||||
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
|
||||
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `from` cannot be the zero address.
|
||||
* - `to` cannot be the zero address.
|
||||
* - `tokenId` token must exist and be owned by `from`.
|
||||
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
|
||||
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function safeTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 tokenId
|
||||
) external;
|
||||
|
||||
/**
|
||||
* @dev Transfers `tokenId` token from `from` to `to`.
|
||||
*
|
||||
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `from` cannot be the zero address.
|
||||
* - `to` cannot be the zero address.
|
||||
* - `tokenId` token must be owned by `from`.
|
||||
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function transferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 tokenId
|
||||
) external;
|
||||
|
||||
/**
|
||||
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
|
||||
* The approval is cleared when the token is transferred.
|
||||
*
|
||||
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The caller must own the token or be an approved operator.
|
||||
* - `tokenId` must exist.
|
||||
*
|
||||
* Emits an {Approval} event.
|
||||
*/
|
||||
function approve(address to, uint256 tokenId) external;
|
||||
|
||||
/**
|
||||
* @dev Returns the account approved for `tokenId` token.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `tokenId` must exist.
|
||||
*/
|
||||
function getApproved(uint256 tokenId) external view returns (address operator);
|
||||
|
||||
/**
|
||||
* @dev Approve or remove `operator` as an operator for the caller.
|
||||
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - The `operator` cannot be the caller.
|
||||
*
|
||||
* Emits an {ApprovalForAll} event.
|
||||
*/
|
||||
function setApprovalForAll(address operator, bool _approved) external;
|
||||
|
||||
/**
|
||||
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
|
||||
*
|
||||
* See {setApprovalForAll}
|
||||
*/
|
||||
function isApprovedForAll(address owner, address operator) external view returns (bool);
|
||||
|
||||
/**
|
||||
* @dev Safely transfers `tokenId` token from `from` to `to`.
|
||||
*
|
||||
* Requirements:
|
||||
*
|
||||
* - `from` cannot be the zero address.
|
||||
* - `to` cannot be the zero address.
|
||||
* - `tokenId` token must exist and be owned by `from`.
|
||||
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
|
||||
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
|
||||
*
|
||||
* Emits a {Transfer} event.
|
||||
*/
|
||||
function safeTransferFrom(
|
||||
address from,
|
||||
address to,
|
||||
uint256 tokenId,
|
||||
bytes calldata data
|
||||
) external;
|
||||
}
|
||||
32
contracts/intf/IERC721Enumerable.sol
Normal file
32
contracts/intf/IERC721Enumerable.sol
Normal file
@@ -0,0 +1,32 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/IERC721Enumerable.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import "./IERC165.sol";
|
||||
import "./IERC721.sol";
|
||||
|
||||
|
||||
/**
|
||||
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
|
||||
* @dev See https://eips.ethereum.org/EIPS/eip-721
|
||||
*/
|
||||
interface IERC721Enumerable is IERC721 {
|
||||
|
||||
/**
|
||||
* @dev Returns the total amount of tokens stored by the contract.
|
||||
*/
|
||||
function totalSupply() external view returns (uint256);
|
||||
|
||||
/**
|
||||
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
|
||||
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
|
||||
*/
|
||||
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
|
||||
|
||||
/**
|
||||
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
|
||||
* Use along with {totalSupply} to enumerate all tokens.
|
||||
*/
|
||||
function tokenByIndex(uint256 index) external view returns (uint256);
|
||||
}
|
||||
28
contracts/intf/IERC721Metadata.sol
Normal file
28
contracts/intf/IERC721Metadata.sol
Normal file
@@ -0,0 +1,28 @@
|
||||
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/extensions/IERC721Metadata.sol
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import "./IERC721.sol";
|
||||
|
||||
/**
|
||||
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
|
||||
* @dev See https://eips.ethereum.org/EIPS/eip-721
|
||||
*/
|
||||
interface IERC721Metadata is IERC721 {
|
||||
|
||||
/**
|
||||
* @dev Returns the token collection name.
|
||||
*/
|
||||
function name() external view returns (string memory);
|
||||
|
||||
/**
|
||||
* @dev Returns the token collection symbol.
|
||||
*/
|
||||
function symbol() external view returns (string memory);
|
||||
|
||||
/**
|
||||
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
|
||||
*/
|
||||
function tokenURI(uint256 tokenId) external view returns (string memory);
|
||||
}
|
||||
27
contracts/intf/IERC721Receiver.sol
Normal file
27
contracts/intf/IERC721Receiver.sol
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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.9;
|
||||
|
||||
/**
|
||||
* @title ERC721 token receiver interface
|
||||
* @dev Interface for any contract that wants to support safeTransfers
|
||||
* from ERC721 asset contracts.
|
||||
*/
|
||||
interface IERC721Receiver {
|
||||
/**
|
||||
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
|
||||
* by `operator` from `from`, this function is called.
|
||||
*
|
||||
* It must return its Solidity selector to confirm the token transfer.
|
||||
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
|
||||
*
|
||||
* The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.
|
||||
*/
|
||||
function onERC721Received(
|
||||
address operator,
|
||||
address from,
|
||||
uint256 tokenId,
|
||||
bytes calldata data
|
||||
) external returns (bytes4);
|
||||
}
|
||||
23
contracts/intf/IFeeDistributor.sol
Normal file
23
contracts/intf/IFeeDistributor.sol
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
interface IFeeDistributor {
|
||||
function init(
|
||||
address baseToken,
|
||||
address quoteToken,
|
||||
address stakeToken
|
||||
) external;
|
||||
|
||||
function stake(address to) external;
|
||||
|
||||
function _STAKE_TOKEN_() external view returns(address);
|
||||
|
||||
function _STAKE_VAULT_() external view returns(address);
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -6,31 +6,21 @@
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||
|
||||
interface IConstFeeRateModel {
|
||||
function init(address owner, uint256 feeRate) external;
|
||||
function init(uint256 feeRate) external;
|
||||
|
||||
function setFeeRate(uint256 newFeeRate) external;
|
||||
|
||||
function getFeeRate(address trader) external view returns (uint256);
|
||||
function getFeeRate(address) external view returns (uint256);
|
||||
}
|
||||
|
||||
contract ConstFeeRateModel is InitializableOwnable {
|
||||
contract ConstFeeRateModel {
|
||||
uint256 public _FEE_RATE_;
|
||||
|
||||
function init(address owner, uint256 feeRate) external {
|
||||
initOwner(owner);
|
||||
function init(uint256 feeRate) external {
|
||||
_FEE_RATE_ = feeRate;
|
||||
}
|
||||
|
||||
function setFeeRate(uint256 newFeeRate) external onlyOwner {
|
||||
_FEE_RATE_ = newFeeRate;
|
||||
}
|
||||
|
||||
function getFeeRate(address trader) external view returns (uint256) {
|
||||
function getFeeRate(address) external view returns (uint256) {
|
||||
return _FEE_RATE_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ contract Ownable {
|
||||
emit OwnershipTransferred(address(0), _OWNER_);
|
||||
}
|
||||
|
||||
function transferOwnership(address newOwner) external onlyOwner {
|
||||
function transferOwnership(address newOwner) external virtual onlyOwner {
|
||||
emit OwnershipTransferPrepared(_OWNER_, newOwner);
|
||||
_NEW_OWNER_ = newOwner;
|
||||
}
|
||||
|
||||
34
contracts/lib/RandomGenerator.sol
Normal file
34
contracts/lib/RandomGenerator.sol
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
interface IRandomGenerator {
|
||||
function random(uint256 seed) external view returns (uint256);
|
||||
}
|
||||
|
||||
interface IDODOMidPrice {
|
||||
function getMidPrice() external view returns (uint256 midPrice);
|
||||
}
|
||||
|
||||
contract RandomGenerator is IRandomGenerator{
|
||||
address[] public pools;
|
||||
|
||||
constructor(address[] memory _pools) public {
|
||||
for (uint256 i = 0; i < _pools.length; i++) {
|
||||
pools.push(_pools[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function random(uint256 seed) external override view returns (uint256) {
|
||||
uint256 priceSum;
|
||||
for (uint256 i = 0; i < pools.length; i++) {
|
||||
priceSum += IDODOMidPrice(pools[i]).getMidPrice();
|
||||
}
|
||||
return uint256(keccak256(abi.encodePacked(blockhash(block.number-1), priceSum, seed)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user