nftPoolProxy
This commit is contained in:
@@ -64,30 +64,30 @@ contract ControllerModel is InitializableOwnable {
|
|||||||
|
|
||||||
//===================== View ========================
|
//===================== View ========================
|
||||||
function getNFTInFee(address filterAdminAddr, address) external view returns(uint256) {
|
function getNFTInFee(address filterAdminAddr, address) external view returns(uint256) {
|
||||||
FilterAdminFeeInfo memory FilterAdminFeeInfo = filterAdminFees[filterAdminAddr];
|
FilterAdminFeeInfo memory filterAdminFeeInfo = filterAdminFees[filterAdminAddr];
|
||||||
|
|
||||||
if(FilterAdminFeeInfo.isSet) {
|
if(filterAdminFeeInfo.isSet) {
|
||||||
return FilterAdminFeeInfo.nftInFee;
|
return filterAdminFeeInfo.nftInFee;
|
||||||
}else {
|
}else {
|
||||||
return _GLOBAL_NFT_IN_FEE_;
|
return _GLOBAL_NFT_IN_FEE_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNFTRandomOutFee(address filterAdminAddr, address) external view returns(uint256) {
|
function getNFTRandomOutFee(address filterAdminAddr, address) external view returns(uint256) {
|
||||||
FilterAdminFeeInfo memory FilterAdminFeeInfo = filterAdminFees[filterAdminAddr];
|
FilterAdminFeeInfo memory filterAdminFeeInfo = filterAdminFees[filterAdminAddr];
|
||||||
|
|
||||||
if(FilterAdminFeeInfo.isSet) {
|
if(filterAdminFeeInfo.isSet) {
|
||||||
return FilterAdminFeeInfo.nftRandomOutFee;
|
return filterAdminFeeInfo.nftRandomOutFee;
|
||||||
}else {
|
}else {
|
||||||
return _GLOBAL_NFT_RANDOM_OUT_FEE_;
|
return _GLOBAL_NFT_RANDOM_OUT_FEE_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNFTTargetOutFee(address filterAdminAddr, address) external view returns(uint256) {
|
function getNFTTargetOutFee(address filterAdminAddr, address) external view returns(uint256) {
|
||||||
FilterAdminFeeInfo memory FilterAdminFeeInfo = filterAdminFees[filterAdminAddr];
|
FilterAdminFeeInfo memory filterAdminFeeInfo = filterAdminFees[filterAdminAddr];
|
||||||
|
|
||||||
if(FilterAdminFeeInfo.isSet) {
|
if(filterAdminFeeInfo.isSet) {
|
||||||
return FilterAdminFeeInfo.nftTargetOutFee;
|
return filterAdminFeeInfo.nftTargetOutFee;
|
||||||
}else {
|
}else {
|
||||||
return _GLOBAL_NFT_TARGET_OUT_FEE_;
|
return _GLOBAL_NFT_TARGET_OUT_FEE_;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
)
|
)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
|
returns (uint256 actualMintAmount)
|
||||||
{
|
{
|
||||||
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
||||||
require(IFilterModel(filter)._NFT_IN_SWITCH_(), "NFT_IN_CLOSED");
|
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(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
||||||
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
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");
|
require(actualMintAmount >= minMintAmount, "MINT_AMOUNT_NOT_ENOUGH");
|
||||||
_mint(msg.sender, actualMintAmount);
|
_mint(msg.sender, actualMintAmount);
|
||||||
}
|
}
|
||||||
@@ -77,6 +78,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
)
|
)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
|
returns (uint256 actualMintAmount)
|
||||||
{
|
{
|
||||||
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
|
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
|
||||||
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
||||||
@@ -92,7 +94,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
||||||
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
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");
|
require(actualMintAmount >= minMintAmount, "MINT_AMOUNT_NOT_ENOUGH");
|
||||||
_mint(msg.sender, actualMintAmount);
|
_mint(msg.sender, actualMintAmount);
|
||||||
|
|
||||||
@@ -106,6 +108,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
)
|
)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
|
returns (uint256 actualBurnAmount)
|
||||||
{
|
{
|
||||||
require(msg.sender == tx.origin, "ONLY_ALLOW_EOA");
|
require(msg.sender == tx.origin, "ONLY_ALLOW_EOA");
|
||||||
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
||||||
@@ -121,9 +124,9 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
(uint256 poolFeeAmount, uint256 mtFeeAmount) = _nftRandomOutFeeTransfer(totalPrice);
|
(uint256 poolFeeAmount, uint256 mtFeeAmount) = _nftRandomOutFeeTransfer(totalPrice);
|
||||||
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
||||||
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
||||||
|
actualBurnAmount = totalPrice;
|
||||||
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
||||||
_burn(msg.sender, totalPrice);
|
_burn(msg.sender, actualBurnAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -134,6 +137,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
)
|
)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
|
returns (uint256 actualBurnAmount)
|
||||||
{
|
{
|
||||||
require(msg.sender == tx.origin, "ONLY_ALLOW_EOA");
|
require(msg.sender == tx.origin, "ONLY_ALLOW_EOA");
|
||||||
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
||||||
@@ -151,8 +155,9 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
||||||
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
||||||
|
|
||||||
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
actualBurnAmount = totalPrice;
|
||||||
_burn(msg.sender, totalPrice);
|
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
||||||
|
_burn(msg.sender, actualBurnAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ERC721TargetOut(
|
function ERC721TargetOut(
|
||||||
@@ -163,6 +168,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
)
|
)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
|
returns(uint256 actualBurnAmount)
|
||||||
{
|
{
|
||||||
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
||||||
require(IFilterModel(filter)._NFT_TARGET_SWITCH_(), "NFT_TARGET_OUT_CLOSED");
|
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(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
||||||
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
||||||
|
|
||||||
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
actualBurnAmount = totalPrice;
|
||||||
_burn(msg.sender, totalPrice);
|
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
||||||
|
_burn(msg.sender, actualBurnAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ERC1155TargetOut(
|
function ERC1155TargetOut(
|
||||||
@@ -190,6 +197,7 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
)
|
)
|
||||||
external
|
external
|
||||||
preventReentrant
|
preventReentrant
|
||||||
|
returns(uint256 actualBurnAmount)
|
||||||
{
|
{
|
||||||
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
|
require(tokenIds.length == amounts.length, "PARAMS_NOT_MATCH");
|
||||||
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
require(isIncludeFilter(filter), "FILTER_NOT_INCLUDE");
|
||||||
@@ -203,8 +211,9 @@ contract FilterAdmin is InitializableInternalMintableERC20, ReentrancyGuard {
|
|||||||
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
if(poolFeeAmount > 0) _mint(_OWNER_, poolFeeAmount);
|
||||||
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
if(mtFeeAmount > 0) _mint(_DEFAULT_MAINTAINER_, mtFeeAmount);
|
||||||
|
|
||||||
require(totalPrice <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
actualBurnAmount = totalPrice;
|
||||||
_burn(msg.sender, totalPrice);
|
require(actualBurnAmount <= maxBurnAmount, "EXTRA_BURN_AMOUNT");
|
||||||
|
_burn(msg.sender, actualBurnAmount);
|
||||||
|
|
||||||
IFilterModel(filter).transferBatchOutERC1155(nftContract, msg.sender, tokenIds, amounts);
|
IFilterModel(filter).transferBatchOutERC1155(nftContract, msg.sender, tokenIds, amounts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ interface IFilterAdmin {
|
|||||||
address nftContract,
|
address nftContract,
|
||||||
uint256[] memory tokenIds,
|
uint256[] memory tokenIds,
|
||||||
uint256 minMintAmount
|
uint256 minMintAmount
|
||||||
) external;
|
) external returns(uint256 actualMintAmount);
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,8 @@ 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";
|
import {IFilterAdmin} from "../../NFTPool/intf/IFilterAdmin.sol";
|
||||||
import {IERC721} from "../../intf/IERC721.sol";
|
import {IERC721} from "../../intf/IERC721.sol";
|
||||||
|
import {IERC20} from "../../intf/IERC20.sol";
|
||||||
|
import {SafeERC20} from "../../lib/SafeERC20.sol";
|
||||||
|
|
||||||
interface IFilter01 {
|
interface IFilter01 {
|
||||||
function init(
|
function init(
|
||||||
@@ -26,8 +28,10 @@ interface IFilter01 {
|
|||||||
|
|
||||||
contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
|
contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
// ============ Storage ============
|
// ============ Storage ============
|
||||||
|
address constant _ETH_ADDRESS_ = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||||
mapping(uint256 => address) public _FILTER_TEMPLATES_;
|
mapping(uint256 => address) public _FILTER_TEMPLATES_;
|
||||||
address public _FILTER_ADMIN_TEMPLATE_;
|
address public _FILTER_ADMIN_TEMPLATE_;
|
||||||
address public _DEFAULT_MAINTAINER_;
|
address public _DEFAULT_MAINTAINER_;
|
||||||
@@ -116,12 +120,18 @@ contract DODONFTPoolProxy is ReentrancyGuard, InitializableOwnable {
|
|||||||
IERC721(nftContract).safeTransferFrom(msg.sender, address(this), tokenId);
|
IERC721(nftContract).safeTransferFrom(msg.sender, address(this), tokenId);
|
||||||
IERC721(nftContract).approve(filter, tokenId);
|
IERC721(nftContract).approve(filter, tokenId);
|
||||||
|
|
||||||
uint256[] memory tokenIds = new uint256[1];
|
uint256[] memory tokenIds = new uint256[](1);
|
||||||
tokenIds[0] = tokenId;
|
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));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user