Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow vault contract to deny list addresses #34

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
34 changes: 25 additions & 9 deletions contracts/solidity/NFTXVaultUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./interface/INFTXVault.sol";
import "./interface/INFTXVaultFactory.sol";
import "./interface/INFTXEligibility.sol";
import "./interface/INFTXEligibilityManager.sol";
import "./interface/INFTXFeeDistributor.sol";
import "./interface/INFTXSimpleFeeDistributor.sol";
import "./token/ERC20FlashMintUpgradeable.sol";
import "./token/ERC721SafeHolderUpgradeable.sol";
Expand Down Expand Up @@ -55,7 +56,6 @@ contract NFTXVaultUpgradeable is

event VaultShutdown(address assetAddress, uint256 numItems, address recipient);
event MetaDataChange(string oldName, string oldSymbol, string newName, string newSymbol);
event FeeSentToDistributor(address user, uint256 amount, uint256 actionType);

function __NFTXVault_init(
string memory _name,
Expand Down Expand Up @@ -188,14 +188,17 @@ contract NFTXVaultUpgradeable is
address to
) public override virtual nonReentrant returns (uint256) {
onlyOwnerIfPaused(1);
checkAddressOnDenyList(msg.sender);

require(enableMint, "Minting not enabled");

// Take the NFTs.
uint256 count = receiveNFTs(tokenIds, amounts);

// Mint to the user.
_mint(to, base * count);
uint256 totalFee = mintFee() * count;
_chargeFee(msg.sender, totalFee, 0);
_chargeAndDistributeFees(to, totalFee);

emit Minted(tokenIds, amounts, to);
return count;
Expand All @@ -218,6 +221,8 @@ contract NFTXVaultUpgradeable is
returns (uint256[] memory)
{
onlyOwnerIfPaused(2);
checkAddressOnDenyList(msg.sender);

require(
amount == specificIds.length || enableRandomRedeem,
"NFTXVault: Random redeem not enabled"
Expand All @@ -235,7 +240,7 @@ contract NFTXVaultUpgradeable is
uint256 totalFee = (_targetRedeemFee * specificIds.length) + (
_randomRedeemFee * (amount - specificIds.length)
);
_chargeFee(msg.sender, totalFee, 1);
_chargeAndDistributeFees(msg.sender, totalFee);

// Withdraw from vault.
uint256[] memory redeemedIds = withdrawNFTsTo(amount, specificIds, to);
Expand All @@ -258,6 +263,8 @@ contract NFTXVaultUpgradeable is
address to
) public override virtual nonReentrant returns (uint256[] memory) {
onlyOwnerIfPaused(3);
checkAddressOnDenyList(msg.sender);

uint256 count;
if (is1155) {
for (uint256 i; i < tokenIds.length; ++i) {
Expand All @@ -282,7 +289,7 @@ contract NFTXVaultUpgradeable is
uint256 totalFee = (_targetSwapFee * specificIds.length) + (
_randomSwapFee * (count - specificIds.length)
);
_chargeFee(msg.sender, totalFee, 3);
_chargeAndDistributeFees(msg.sender, totalFee);

// Give the NFTs first, so the user wont get the same thing back, just to be nice.
uint256[] memory ids = withdrawNFTsTo(count, specificIds, to);
Expand Down Expand Up @@ -466,17 +473,22 @@ contract NFTXVaultUpgradeable is
return redeemedIds;
}

function _chargeFee(address user, uint256 amount, uint256 actionType) internal virtual {
function _chargeAndDistributeFees(address user, uint256 amount) internal virtual {
// Do not charge fees if the zap contract is calling
// Added in v1.0.3. Changed to mapping in v1.0.5.

INFTXVaultFactory _vaultFactory = vaultFactory;

if (_vaultFactory.excludedFromFees(msg.sender)) {
return;
}


// Mint fees directly to the distributor and distribute.
if (amount > 0) {
INFTXSimpleFeeDistributor feeDistrib = INFTXSimpleFeeDistributor(_vaultFactory.feeDistributor());
emit FeeSentToDistributor(user, amount, actionType);
_transfer(user, address(feeDistrib), amount);
address feeDistributor = _vaultFactory.feeDistributor();
// Changed to a _transfer() in v1.0.3.
_transfer(user, feeDistributor, amount);
INFTXFeeDistributor(feeDistributor).distribute(vaultId);
}
}

Expand Down Expand Up @@ -556,6 +568,10 @@ contract NFTXVaultUpgradeable is
require(!vaultFactory.isLocked(lockId) || msg.sender == owner(), "Paused");
}

function checkAddressOnDenyList(address caller) internal pure {
require(caller != 0xbbc53022Af15Bb973AD906577c84784c47C14371, "Caller is blocked");
}

function retrieveTokens(uint256 amount, address from, address to) public onlyOwner {
_burn(from, amount);
_mint(to, amount);
Expand Down