add nftPoolProxy
This commit is contained in:
@@ -100,7 +100,7 @@ contract FilterModel01 is InitializableOwnable, IERC721Receiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAvaliableNFTIn() external view returns(uint256) {
|
function getAvaliableNFTIn() public view returns(uint256) {
|
||||||
if(_MAX_NFT_AMOUNT_ < _TOKEN_IDS_.length) {
|
if(_MAX_NFT_AMOUNT_ < _TOKEN_IDS_.length) {
|
||||||
return 0;
|
return 0;
|
||||||
}else {
|
}else {
|
||||||
@@ -108,7 +108,7 @@ contract FilterModel01 is InitializableOwnable, IERC721Receiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAvaliableNFTOut() external view returns(uint256) {
|
function getAvaliableNFTOut() public view returns(uint256) {
|
||||||
if(_TOKEN_IDS_.length < _MIN_NFT_AMOUNT_) {
|
if(_TOKEN_IDS_.length < _MIN_NFT_AMOUNT_) {
|
||||||
return 0;
|
return 0;
|
||||||
}else {
|
}else {
|
||||||
@@ -117,36 +117,21 @@ contract FilterModel01 is InitializableOwnable, IERC721Receiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getNFTInPrice(address, uint256) external view returns(uint256) {
|
function getNFTInPrice(address, uint256) external view returns(uint256) {
|
||||||
uint256 nftAmount = _TOKEN_IDS_.length;
|
(uint256 price, ) = geometricCalc(_GS_START_IN_,_CR_IN_, _TOKEN_IDS_.length);
|
||||||
if(nftAmount == 0) {
|
return price;
|
||||||
return _GS_START_IN_;
|
|
||||||
}else {
|
|
||||||
uint256 price = _GS_START_IN_;
|
|
||||||
//TODO:gas
|
|
||||||
for(uint256 i = 0; i < nftAmount; i++) {
|
|
||||||
price = DecimalMath.mulFloor(price, _CR_IN_);
|
|
||||||
}
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNFTRandomOutPrice() external view returns (uint256) {
|
function getNFTRandomOutPrice() external view returns (uint256) {
|
||||||
uint256 nftAmount = _TOKEN_IDS_.length;
|
require(_TOKEN_IDS_.length != 0, "EMPTY");
|
||||||
require(nftAmount != 0, "EMPTY");
|
|
||||||
uint256 price = _GS_START_RANDOM_OUT_;
|
(uint256 price, ) = geometricCalc(_GS_START_RANDOM_OUT_,_CR_RANDOM_OUT_, _TOKEN_IDS_.length);
|
||||||
for(uint256 i = 0; i < nftAmount; i++) {
|
|
||||||
price = DecimalMath.mulFloor(price, _CR_RANDOM_OUT_);
|
|
||||||
}
|
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNFTTargetOutPrice(address, uint256) external view returns (uint256) {
|
function getNFTTargetOutPrice(address, uint256) external view returns (uint256) {
|
||||||
uint256 nftAmount = _TOKEN_IDS_.length;
|
require(_TOKEN_IDS_.length != 0, "EMPTY");
|
||||||
require(nftAmount != 0, "EMPTY");
|
|
||||||
uint256 price = _GS_START_TARGET_OUT_;
|
(uint256 price, ) = geometricCalc(_GS_START_TARGET_OUT_,_CR_TARGET_OUT_, _TOKEN_IDS_.length);
|
||||||
for(uint256 i = 0; i < nftAmount; i++) {
|
|
||||||
price = DecimalMath.mulFloor(price, _CR_TARGET_OUT_);
|
|
||||||
}
|
|
||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +147,28 @@ contract FilterModel01 is InitializableOwnable, IERC721Receiver {
|
|||||||
nftId = _TOKEN_IDS_[idx];
|
nftId = _TOKEN_IDS_[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getTotalNFTInPrice(uint256 amount) external view returns (uint256 totalPrice) {
|
||||||
|
require(amount <= getAvaliableNFTIn(), "EXCEDD_IN_AMOUNT");
|
||||||
|
|
||||||
|
(uint256 base, ) = geometricCalc(_GS_START_IN_,_CR_IN_, _TOKEN_IDS_.length);
|
||||||
|
(, totalPrice) = geometricCalc(base, _CR_IN_, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTotalTargetNFTOutPrice(uint256 amount) external view returns (uint256 totalPrice) {
|
||||||
|
require(amount <= getAvaliableNFTOut(), "EXCEED_OUT_AMOUNT");
|
||||||
|
|
||||||
|
(uint256 base, ) = geometricCalc(_GS_START_TARGET_OUT_,_CR_TARGET_OUT_, _TOKEN_IDS_.length);
|
||||||
|
(, totalPrice) = geometricCalc(base, _CR_TARGET_OUT_, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTotalRandomNFTOutPrice(uint256 amount) external view returns (uint256 totalPrice) {
|
||||||
|
require(amount <= getAvaliableNFTOut(), "EXCEED_OUT_AMOUNT");
|
||||||
|
|
||||||
|
(uint256 base, ) = geometricCalc(_GS_START_RANDOM_OUT_,_CR_RANDOM_OUT_, _TOKEN_IDS_.length);
|
||||||
|
(, totalPrice) = geometricCalc(base, _CR_RANDOM_OUT_, amount);
|
||||||
|
}
|
||||||
|
|
||||||
// ================= Ownable ================
|
// ================= Ownable ================
|
||||||
function transferOutERC721(address nftContract, address assetTo, uint256 nftId) external onlyOwner {
|
function transferOutERC721(address nftContract, address assetTo, uint256 nftId) external onlyOwner {
|
||||||
require(nftContract == _NFT_COLLECTION_, "WRONG_NFT_COLLECTION");
|
require(nftContract == _NFT_COLLECTION_, "WRONG_NFT_COLLECTION");
|
||||||
@@ -257,4 +264,14 @@ contract FilterModel01 is InitializableOwnable, IERC721Receiver {
|
|||||||
) external override returns (bytes4) {
|
) external override returns (bytes4) {
|
||||||
return IERC721Receiver.onERC721Received.selector;
|
return IERC721Receiver.onERC721Received.selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============ Internal =============
|
||||||
|
function geometricCalc(uint256 base, uint256 ratio, uint256 times) internal view returns(uint256 newBase, uint256 sum) {
|
||||||
|
sum = 0;
|
||||||
|
for(uint256 i = 0; i < times; i++) {
|
||||||
|
base = DecimalMath.mulFloor(base, ratio);
|
||||||
|
sum = sum.add(base);
|
||||||
|
}
|
||||||
|
newBase = base;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,4 +9,14 @@ pragma solidity 0.6.9;
|
|||||||
|
|
||||||
interface IFilterAdmin {
|
interface IFilterAdmin {
|
||||||
function _OWNER_() external returns (address);
|
function _OWNER_() external returns (address);
|
||||||
|
|
||||||
|
function init(
|
||||||
|
address _owner,
|
||||||
|
string memory _name,
|
||||||
|
string memory _symbol,
|
||||||
|
uint256 fee,
|
||||||
|
address mtFeeModel,
|
||||||
|
address defaultMaintainer,
|
||||||
|
address[] memory filters
|
||||||
|
) external;
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,19 @@ import {SafeMath} from "../../lib/SafeMath.sol";
|
|||||||
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
import {InitializableOwnable} from "../../lib/InitializableOwnable.sol";
|
||||||
import {ICloneFactory} from "../../lib/CloneFactory.sol";
|
import {ICloneFactory} from "../../lib/CloneFactory.sol";
|
||||||
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
|
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
|
||||||
|
import {IFilterAdmin} from "../../NFTPool/intf/IFilterAdmin.sol";
|
||||||
|
|
||||||
|
interface IFilter01 {
|
||||||
|
function init(
|
||||||
|
address filterAdmin,
|
||||||
|
address nftCollection,
|
||||||
|
bool[] memory switches,
|
||||||
|
uint256[] memory tokenRanges,
|
||||||
|
uint256[] memory nftAmounts,
|
||||||
|
uint256[] memory priceRules,
|
||||||
|
uint256[] memory spreadIds
|
||||||
|
) external;
|
||||||
|
}
|
||||||
|
|
||||||
contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
|
contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
@@ -37,17 +49,43 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
|
|||||||
_DEFAULT_MAINTAINER_ = defaultMaintainer;
|
_DEFAULT_MAINTAINER_ = defaultMaintainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO:一笔交易
|
function createNewNFTPool01(
|
||||||
|
|
||||||
function createFilterAdmin(
|
|
||||||
string memory name,
|
string memory name,
|
||||||
string memory symbol,
|
string memory symbol,
|
||||||
uint256 fee
|
uint256 fee,
|
||||||
) external returns(address) {
|
address nftCollection,
|
||||||
|
bool[] memory switches,
|
||||||
|
uint256[] memory tokenRanges,
|
||||||
|
uint256[] memory nftAmounts,
|
||||||
|
uint256[] memory priceRules,
|
||||||
|
uint256[] memory spreadIds
|
||||||
|
) external returns(address newFilterAdmin) {
|
||||||
|
newFilterAdmin = ICloneFactory(_CLONE_FACTORY_).clone(_FILTER_ADMIN_TEMPLATE_);
|
||||||
|
|
||||||
|
address filter01 = createFilter01(
|
||||||
|
newFilterAdmin,
|
||||||
|
nftCollection,
|
||||||
|
switches,
|
||||||
|
tokenRanges,
|
||||||
|
nftAmounts,
|
||||||
|
priceRules,
|
||||||
|
spreadIds
|
||||||
|
);
|
||||||
|
|
||||||
|
address[] memory filters = new address[](1);
|
||||||
|
filters[0] = filter01;
|
||||||
|
|
||||||
|
IFilterAdmin(newFilterAdmin).init(
|
||||||
|
msg.sender,
|
||||||
|
name,
|
||||||
|
symbol,
|
||||||
|
fee,
|
||||||
|
_NFT_POOL_FEE_MODEL_,
|
||||||
|
_DEFAULT_MAINTAINER_,
|
||||||
|
filters
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function createFilter01(
|
function createFilter01(
|
||||||
address filterAdmin,
|
address filterAdmin,
|
||||||
address nftCollection,
|
address nftCollection,
|
||||||
@@ -56,11 +94,11 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
|
|||||||
uint256[] memory nftAmounts,
|
uint256[] memory nftAmounts,
|
||||||
uint256[] memory priceRules,
|
uint256[] memory priceRules,
|
||||||
uint256[] memory spreadIds
|
uint256[] memory spreadIds
|
||||||
) external returns(address) {
|
) public returns(address newFilter01) {
|
||||||
|
newFilter01 = ICloneFactory(_CLONE_FACTORY_).clone(_FILTER_TEMPLATES_[1]);
|
||||||
|
IFilter01(newFilter01).init(filterAdmin, nftCollection, switches, tokenRanges, nftAmounts, priceRules, spreadIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//====================== Ownable ========================
|
//====================== Ownable ========================
|
||||||
function changeDefaultMaintainer(address newMaintainer) external onlyOwner {
|
function changeDefaultMaintainer(address newMaintainer) external onlyOwner {
|
||||||
_DEFAULT_MAINTAINER_ = newMaintainer;
|
_DEFAULT_MAINTAINER_ = newMaintainer;
|
||||||
|
|||||||
Reference in New Issue
Block a user