nftPoolProxy

This commit is contained in:
owen05
2021-09-09 16:18:27 +08:00
parent aff42e7108
commit 3d1e543f65
4 changed files with 68 additions and 24 deletions

View File

@@ -64,30 +64,30 @@ contract ControllerModel is InitializableOwnable {
//===================== View ========================
function getNFTInFee(address filterAdminAddr, address) external view returns(uint256) {
FilterAdminFeeInfo memory FilterAdminFeeInfo = filterAdminFees[filterAdminAddr];
FilterAdminFeeInfo memory filterAdminFeeInfo = filterAdminFees[filterAdminAddr];
if(FilterAdminFeeInfo.isSet) {
return FilterAdminFeeInfo.nftInFee;
if(filterAdminFeeInfo.isSet) {
return filterAdminFeeInfo.nftInFee;
}else {
return _GLOBAL_NFT_IN_FEE_;
}
}
function getNFTRandomOutFee(address filterAdminAddr, address) external view returns(uint256) {
FilterAdminFeeInfo memory FilterAdminFeeInfo = filterAdminFees[filterAdminAddr];
FilterAdminFeeInfo memory filterAdminFeeInfo = filterAdminFees[filterAdminAddr];
if(FilterAdminFeeInfo.isSet) {
return FilterAdminFeeInfo.nftRandomOutFee;
if(filterAdminFeeInfo.isSet) {
return filterAdminFeeInfo.nftRandomOutFee;
}else {
return _GLOBAL_NFT_RANDOM_OUT_FEE_;
}
}
function getNFTTargetOutFee(address filterAdminAddr, address) external view returns(uint256) {
FilterAdminFeeInfo memory FilterAdminFeeInfo = filterAdminFees[filterAdminAddr];
FilterAdminFeeInfo memory filterAdminFeeInfo = filterAdminFees[filterAdminAddr];
if(FilterAdminFeeInfo.isSet) {
return FilterAdminFeeInfo.nftTargetOutFee;
if(filterAdminFeeInfo.isSet) {
return filterAdminFeeInfo.nftTargetOutFee;
}else {
return _GLOBAL_NFT_TARGET_OUT_FEE_;
}

View File

@@ -48,6 +48,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
)
external
preventReentrant
returns (uint256 actualMintAmount)
{
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
require(IFilterModel(filter)._NFT_IN_SWITCH_(), "NFT_IN_CLOSED");
@@ -63,7 +64,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
uint256 actualMintAmount = totalPrice.sub(mtFeeAmount).sub(poolFeeAmount);
actualMintAmount = totalPrice.sub(mtFeeAmount).sub(poolFeeAmount);
require(actualMintAmount >= minMintAmount, "MINT_AMOUNT_NOT_ENOUGH");
_mint(msg.sender, actualMintAmount);
}
@@ -77,6 +78,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
)
external
preventReentrant
returns (uint256 actualMintAmount)
{
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
@@ -92,7 +94,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
uint256 actualMintAmount = totalPrice.sub(mtFeeAmount).sub(poolFeeAmount);
actualMintAmount = totalPrice.sub(mtFeeAmount).sub(poolFeeAmount);
require(actualMintAmount >= minMintAmount, "MINT_AMOUNT_NOT_ENOUGH");
_mint(msg.sender, actualMintAmount);
@@ -105,7 +107,8 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
uint256 maxBurnAmount
)
external
preventReentrant
preventReentrant
returns (uint256 actualBurnAmount)
{
require(msg.sender == tx.origin, "ONLY_ALLOW_EOA");
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
@@ -121,9 +124,9 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
(uint256 poolFeeAmount, uint256 mtFeeAmount) = _nftRandomOutFeeTransfer(totalPrice);
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, totalPrice);
actualBurnAmount = totalPrice;
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, actualBurnAmount);
}
@@ -134,6 +137,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
)
external
preventReentrant
returns (uint256 actualBurnAmount)
{
require(msg.sender == tx.origin, "ONLY_ALLOW_EOA");
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
@@ -151,8 +155,9 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, totalPrice);
actualBurnAmount = totalPrice;
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, actualBurnAmount);
}
function ERC721TargetOut(
@@ -163,6 +168,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
)
external
preventReentrant
returns(uint256 actualBurnAmount)
{
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
require(IFilterModel(filter)._NFT_TARGET_SWITCH_(), "NFT_TARGET_OUT_CLOSED");
@@ -177,8 +183,9 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, totalPrice);
actualBurnAmount = totalPrice;
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, actualBurnAmount);
}
function ERC1155TargetOut(
@@ -190,6 +197,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
)
external
preventReentrant
returns(uint256 actualBurnAmount)
{
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
@@ -203,8 +211,9 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, totalPrice);
actualBurnAmount = totalPrice;
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
_burn(msg.sender, actualBurnAmount);
IFilterModel(filter).transferBatchOutERC1155(nftContract, msg.sender, tokenIds, amounts);
}

View File

@@ -27,5 +27,5 @@ interface IFilterAdmin {
address nftContract,
uint256[] memory tokenIds,
uint256 minMintAmount
) external;
) external returns(uint256 actualMintAmount);
}

View File

@@ -11,6 +11,8 @@ import {ICloneFactory} from "../../lib/CloneFactory.sol";
import {ReentrancyGuard} from "../../lib/ReentrancyGuard.sol";
import {IFilterAdmin} from "../../NFTPool/intf/IFilterAdmin.sol";
import {IERC721} from "../../intf/IERC721.sol";
import {IERC20} from "../../intf/IERC20.sol";
import {SafeERC20} from "../../lib/SafeERC20.sol";
interface IFilter01 {
function init(
@@ -26,8 +28,10 @@ interface IFilter01 {
contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// ============ Storage ============
address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
mapping(uint256 => address) public _FILTER_TEMPLATES_;
address public _FILTER_ADMIN_TEMPLATE_;
address public _DEFAULT_MAINTAINER_;
@@ -116,12 +120,18 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
IERC721(nftContract).safeTransferFrom(msg.sender, address(this), tokenId);
IERC721(nftContract).approve(filter, tokenId);
uint256[] memory tokenIds = new uint256[1];
uint256[] memory tokenIds = new uint256[](1);
tokenIds[0] = tokenId;
IFilterAdmin(filterAdmin).ERC721In(filter, nftContract, tokenIds, 0);
uint256 mintAmount = IFilterAdmin(filterAdmin).ERC721In(filter, nftContract, tokenIds, 0);
_generalApproveMax(filterAdmin, dodoApprove, mintAmount);
(bool success, ) = dodoProxy.call(dodoSwapData);
require(success, "API_SWAP_FAILED");
uint256 returnAmount = _generalBalanceOf(toToken, address(this));
_generalTransfer(toToken, msg.sender, returnAmount);
}
@@ -158,4 +168,29 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
IERC20(token).safeApprove(to, uint256(-1));
}
}
function _generalBalanceOf(
address token,
address who
) internal view returns (uint256) {
if (token == _ETH_ADDRESS_) {
return who.balance;
} else {
return IERC20(token).balanceOf(who);
}
}
function _generalTransfer(
address token,
address payable to,
uint256 amount
) internal {
if (amount > 0) {
if (token == _ETH_ADDRESS_) {
to.transfer(amount);
} else {
IERC20(token).safeTransfer(to, amount);
}
}
}
}