// SPDX-License-Identifier: MIT pragma solidity 0.8.10; import "@openzeppelin/contracts/access/AccessControlEnumerable.sol"; import "../interfaces/IAsset.sol"; import "../interfaces/IBEERC721.sol"; import "../utils/UInt.sol"; contract AirdropNft is AccessControlEnumerable { using UInt for uint256; bytes32 public constant MANAGE_ROLE = keccak256("MANAGE_ROLE"); event EventDrop( address indexed nftAddress, uint256 indexed serialNum, uint256 firstTokenId, uint256 batchSize ); constructor(address[] memory _manageAddress) { // Set up the ADMIN_ROLE and MANAGE_ROLE _setRoleAdmin(MANAGE_ROLE, DEFAULT_ADMIN_ROLE); // Grant the ADMIN_ROLE to the deployer and to the contract itself _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); // Grant the MANAGE_ROLE to the specified address for (uint256 i = 0; i < _manageAddress.length; ++i) { _setupRole(MANAGE_ROLE, _manageAddress[i]); } } /** * @dev Modifier that checks if the caller has the MANAGE_ROLE. * * The function uses the _checkRole() function from the AccessControl library. * If the check is successful, the code defined by the function that uses this modifier is executed. */ modifier onlyManager() { // Check if the caller has the MANAGE_ROLE _checkRole(MANAGE_ROLE, _msgSender()); // If the check is successful, execute the code in the function that uses this modifier _; } function dropMintNft( address tokenAddr, uint256 serialNum, address[] memory _recipients, uint256[] memory _amounts ) public onlyManager returns (bool) { require(_recipients.length == _amounts.length, "ERC:length mismatch"); uint256 beginToken = 0; uint256 batchSize = 0; for (uint16 i = 0; i < _recipients.length; i++) { uint256[] memory _nftIds = IBEERC721(tokenAddr).batchMint( _recipients[i], _amounts[i] ); batchSize += _amounts[i]; if (i == 0) { beginToken = _nftIds[0]; } } emit EventDrop(tokenAddr, serialNum, beginToken, batchSize); return true; } function dropMintAsset( address tokenAddr, uint256 serialNum, address[] memory _recipients, uint256[] memory _tokenIds ) external onlyManager returns (bool) { require(_recipients.length == _tokenIds.length, "ERC:length mismatch"); uint256 beginToken = _tokenIds[0]; for (uint16 i = 0; i < _recipients.length; i++) { IAsset(tokenAddr).batchMint( _recipients[i], _tokenIds[i].asSingletonArray() ); } emit EventDrop(tokenAddr, serialNum, beginToken, _tokenIds.length); return true; } }