lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.0
/**
 * @dev Allow AMFEIX to transfer AMF to claiming users
 * 
 * @param tokenAmount Amount of tokens to be sent
 * @param userAddress BTC address on which users willing to receive payment
 * @param btcTxId ID of the AMF buying transaction on Bitcoin network
 */
function payAMF(uint256 tokenAmount, address userAddress, string memory btcTxId) public virtual returns (bool) {
        require(_msgSender() == _tokenPool, "Only AMFEIX can use this method");
        _transfer(_msgSender(), userAddress, tokenAmount);
        emit AmfPaid(userAddress, btcTxId, tokenAmount);
        return true;
    }
// Solidity 0.6.12
/**
 * @dev Get the royalty fee percentage for a specific ERC1155 contract.
 * @param _tokenId uint256 token ID.
 * @return uint8 wei royalty fee.
 */
function getTokenRoyaltyPercentage(
        uint256 _tokenId
    ) public view override returns (uint8) {
        if (tokenRoyaltyPercentage[_tokenId] > 0) {
            return tokenRoyaltyPercentage[_tokenId];
        }
        address creator =
        iERC1155TokenCreator.tokenCreator(_tokenId);
        if (creatorRoyaltyPercentage[creator] > 0) {
            return creatorRoyaltyPercentage[creator];
        }
        return contractRoyaltyPercentage;
    }
// Solidity 0.6.12
/**
 * @dev Sets the royalty percentage set for an Nafter token
 * Requirements:
 
 * - `_percentage` must be <= 100.
 * - only the owner of this contract or the creator can call this method.
 * @param _tokenId uint256 token ID.
 * @param _percentage uint8 wei royalty fee.
 */
function setPercentageForTokenRoyalty(
        uint256 _tokenId,
        uint8 _percentage
    ) external override returns (uint8) {
        require(
            msg.sender == iERC1155TokenCreator.tokenCreator(_tokenId) ||
            msg.sender == owner() ||
            msg.sender == nafter,
            "setPercentageForTokenRoyalty::Must be contract owner or creator or nafter"
        );
        require(
            _percentage <= 100,
            "setPercentageForTokenRoyalty::_percentage must be <= 100"
        );
        tokenRoyaltyPercentage[_tokenId] = _percentage;
    }
// Solidity 0.6.12
/**
 * @dev restore data from old contract, only call by owner
 * @param _oldAddress address of old contract.
 * @param _oldNafterAddress get the token ids from the old nafter contract.
 * @param _startIndex start index of array
 * @param _endIndex end index of array
 */
function restore(address _oldAddress, address _oldNafterAddress, uint256 _startIndex, uint256 _endIndex) external onlyOwner {
        NafterRoyaltyRegistry oldContract = NafterRoyaltyRegistry(_oldAddress);
        INafter oldNafterContract = INafter(_oldNafterAddress);

        uint256 length = oldNafterContract.getTokenIdsLength();
        require(_startIndex < length, "wrong start index");
        require(_endIndex <= length, "wrong end index");

        for (uint i = _startIndex; i < _endIndex; i++) {
            uint256 tokenId = oldNafterContract.getTokenId(i);
            uint8 percentage = oldContract.getPercentageForTokenRoyalty(tokenId);
            if (percentage != 0) {
                tokenRoyaltyPercentage[tokenId] = percentage;
            }
        }

        for (uint i; i < oldContract.creatorsLength(); i++) {
            address creator = oldContract.creators(i);
            creators.push(creator);
            creatorRigistered[creator] = true;
            creatorRoyaltyPercentage[creator] = oldContract.creatorRoyaltyPercentage(creator);
        }
    }
// Solidity 0.8.4
/**
 * Lazily mint some reserved tokens
 */
function mintReserved(uint numberOfTokens) public onlyOwner {
        require(
            _reservedTokenIdCounter.current().add(numberOfTokens) <= RESERVED_TOTAL,
            "Minting would exceed max reserved supply"
        );

       for (uint i = 0; i < numberOfTokens; i++) {
            _safeMintGeneric(msg.sender, _reservedTokenIdCounter);
        }
    }
// Solidity 0.8.7
/**
 * @dev Throttle minting to once a block and reset the reclamation threshold
 * whenever a new token is minted or transferred.
 */
function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal override(ERC721, ERC721Enumerable) {
        super._beforeTokenTransfer(from, to, tokenId);

        // If minting: ensure it's the only one from this tx origin in the block.
        if (from == address(0)) {
            require(
                block.number > _lastTokenMinted[tx.origin],
                "discreet: cannot mint multiple tokens per block from a single origin"
            );

            _lastTokenMinted[tx.origin] = block.number;
        }

        // If not burning: reset tokenId's reclaimable threshold block number.
        if (to != address(0)) {
            _reclaimableThreshold[tokenId] = block.number + 0x400000;
        }
    }
// Solidity 0.8.7
/**
 * @dev Wrap an original or extra discreet NFT when transferred to this
 * contract via `safeTransferFrom` during the migration period.
 */
function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external override returns (bytes4) {
        require(
            block.number < migrationEnds,
            "discreet: token migration is complete."
        );

        require(
            msg.sender == address(originalSet) || msg.sender == address(extraSet),
            "discreet: only accepts original or extra set discreet tokens."
        );

        if (msg.sender == address(originalSet)) {
            require(
                tokenId < 0x240,
                "discreet: only accepts original set discreet tokens with metadata"
            );
            _safeMint(from, tokenId);
        } else {
            require(
                tokenId < 0x120,
                "discreet: only accepts extra set discreet tokens with metadata"
            );
            _safeMint(from, tokenId + 0x240);
        }

        return this.onERC721Received.selector;
    }
// Solidity 0.8.7
/**
 * @dev Mint a given discreet NFT if it is currently available.
 */
function mint(uint256 tokenId) external override {
        require(
            tokenId < 0x510,
            "discreet: cannot mint out-of-range token"
        );

        if (tokenId < 0x360) {
            require(
                block.number >= migrationEnds,
                "discreet: cannot mint tokens from original or extra set until migration is complete."
            );
        }

        _safeMint(msg.sender, tokenId);
    }
// Solidity 0.8.7
/**
 * @dev Mint a given NFT if it is currently available to a given address.
 */
function mint(address to, uint256 tokenId) external override {
        require(
            tokenId < 0x510,
            "discreet: cannot mint out-of-range token"
        );

        if (tokenId < 0x360) {
            require(
                block.number >= migrationEnds,
                "discreet: cannot mint tokens from original or extra set until migration is complete."
            );
        }

        _safeMint(to, tokenId);
    }
// Solidity 0.8.7
/**
 * @dev Burn a given discreet NFT if it is owned, approved or reclaimable.
 * Tokens become reclaimable after ~4 million blocks without a transfer.
 */
function burn(uint256 tokenId) external override {
        require(
            tokenId < 0x510,
            "discreet: cannot burn out-of-range token"
        );

        // Only enforce check if tokenId has not reached reclaimable threshold.
        if (!isReclaimable(tokenId)) {
            require(
                _isApprovedOrOwner(msg.sender, tokenId),
                "discreet: caller is not owner nor approved"
            );
        }

        _burn(tokenId);
    }
// Solidity 0.8.7
/**
 * @dev Derive and return a tokenURI json payload formatted as a
 * data URI.
 */
function tokenURI(uint256 tokenId) external view virtual override returns (string memory) {
        string memory json = Base64.encode(
            bytes(
                string(
                    abi.encodePacked(
                        '{"name": "discreet #',
                        _toString(tokenId),
                        '", "description": "One of 1296 distinct images, stored and derived ',
                        'entirely on-chain, that comprise the discreet.eth collection. It ',
                        'will become reclaimable if 4,194,304 blocks elapse without this ',
                        'token being minted or transferred.", "image": "',
                        tokenImageURI(tokenId),
                        '"}'
                    )
                )
            )
        );

        return string(abi.encodePacked('data:application/json;base64,', json));
    }
// Solidity 0.8.0
// @notice sets current round goal amount
// @dev the current deposit must be less than or equal to goal
// @dev only issuance manager role can call this function
// @param _newGoal the new goal amount to set the current round to
function setCurrentRoundGoal(uint256 _newGoal)
        external
        nonReentrant
        onlyRole(ISSUANCE_MANAGER)
        onlyStage(Stages.Started, currentRoundId)
    {
        uint256 totalDeposit = roundData[currentRoundId].totalDeposit;
        require(
            totalDeposit <= _newGoal,
            "issuance: total deposit must be <= goal"
        );
        roundData[currentRoundId].goal = _newGoal;
        if (totalDeposit == _newGoal) {
            _setCurrentRoundStage(Stages.GoalMet);
        }
    }
// Solidity 0.8.0
// @notice purchase a ticket of an amount in denominated asset into current round
// @dev user should only have one ticket per round
// @dev the contract must not be paused
// @dev only once round has started and goal has not been met
function purchaseTicket(uint256 _amount)
        external
        nonReentrant
        whenNotPaused
        onlyStage(Stages.Started, currentRoundId)
    {
        require(_amount > 0, "issuance: amount can't be zero");
        denomAsset.safeTransferFrom(msg.sender, address(this), _amount);
        uint256 _totalDeposit = roundData[currentRoundId].totalDeposit +
            _amount;
        uint256 goal = roundData[currentRoundId].goal;
        uint256 realAmount = _amount;
        if (_totalDeposit > goal) {
            uint256 change = _totalDeposit - goal;
            realAmount -= change;
            roundData[currentRoundId].totalDeposit += realAmount;
            _setCurrentRoundStage(Stages.GoalMet);
            // send the excess amount back to caller
            denomAsset.transfer(msg.sender, change);
        }
        if (_totalDeposit == goal) {
            roundData[currentRoundId].totalDeposit += realAmount;
            _setCurrentRoundStage(Stages.GoalMet);
        }
        if (_totalDeposit < goal) {
            roundData[currentRoundId].totalDeposit += realAmount;
        }
        // create user ticket
        if (!userTicket[currentRoundId][msg.sender].exists) {
            userTicket[currentRoundId][msg.sender] = Ticket({
                amount: realAmount,
                redeemed: false,
                exists: true
            });
        } else {
            // or increment user ticket's amount
            userTicket[currentRoundId][msg.sender].amount += realAmount;
        }
        emit PurchaseTicket(msg.sender, realAmount);
    }
// Solidity 0.8.0
// @notice use the round's deposited assets to issue new vault tokens
// @dev only callable from issuance manager
// @dev can only issue for current round and after the goal is met
function issue()
        external
        nonReentrant
        onlyRole(ISSUANCE_MANAGER)
        onlyStage(Stages.GoalMet, currentRoundId)
    {
        // approve vault and deposit
        uint256 amount = roundData[currentRoundId].totalDeposit;
        denomAsset.safeApprove(vault, amount);
        uint256 mintedVaultTokens = IXPN(vault).deposit(amount);
        // update the round with the current totalShares returned from deposit
        roundData[currentRoundId].totalShares = mintedVaultTokens;
        // ensure the new shares balance has been incremented correctly
        _setCurrentRoundStage(Stages.End);
        _toNextRound();
    }
// Solidity 0.8.0
// @notice redeem the round ticket for vault tokens
// @param _roundId the identifier of the round
// @dev the round must have ended and vault tokens are issued
function redeemTicket(uint256 _roundId)
        external
        nonReentrant
        onlyStage(Stages.End, _roundId)
    {
        // ensure the user ticket exists in the round specified
        Ticket memory ticket = userTicket[_roundId][msg.sender];
        RoundData memory round = roundData[_roundId];
        require(ticket.exists, "issuance: user ticket does not exist");
        require(
            !ticket.redeemed,
            "issuance: user vault tokens have been redeemed"
        );
        // calculate the shares of user to the current round shares using the proportion of their deposit
        uint256 claimable = ((round.totalShares * ticket.amount) /
            round.totalDeposit);
        // transfer the share of vault tokens to end user.
        userTicket[_roundId][msg.sender].redeemed = true;
        vaultToken.safeTransfer(msg.sender, claimable);
        emit RedeemTicket(msg.sender, claimable);
    }
// Solidity 0.7.6
/// @notice Pause recipient vesting
/// @dev This freezes the vesting schedule for the paused recipient.
///      Recipient will NOT be able to claim until unpaused.
///      Only owner of the vesting escrow can invoke this function.
///      Can only be invoked if the escrow is NOT terminated.
/// @param recipient The recipient address for which vesting will be paused.
function pauseRecipient(address recipient) external onlyOwner escrowNotTerminated isNonZeroAddress(recipient) {
        // current recipient status should be UnPaused
        require(recipients[recipient].recipientVestingStatus == Status.UnPaused, "pauseRecipient: cannot pause");
        // set vesting status of the recipient as Paused
        recipients[recipient].recipientVestingStatus = Status.Paused;
        // set lastPausedAt timestamp
        recipients[recipient].lastPausedAt = block.timestamp;
    }
// Solidity 0.7.6
/// @notice UnPause recipient vesting
/// @dev This unfreezes the vesting schedule for the paused recipient. Recipient will be able to claim.
///      In order to keep vestingPerSec for the recipient a constant, cliffDuration and endTime for the
///      recipient are shifted by the pause duration so that the recipient resumes with the same state
///      at the time it was paused.
///      Only owner of the vesting escrow can invoke this function.
///      Can only be invoked if the escrow is NOT terminated.
/// @param recipient The recipient address for which vesting will be unpaused.
function unPauseRecipient(address recipient) external onlyOwner escrowNotTerminated isNonZeroAddress(recipient) {
        // current recipient status should be Paused
        require(recipients[recipient].recipientVestingStatus == Status.Paused, "unPauseRecipient: cannot unpause");
        // set vesting status of the recipient as "UnPaused"
        recipients[recipient].recipientVestingStatus = Status.UnPaused;
        // calculate the time for which the recipient was paused for
        uint256 pausedFor = block.timestamp.sub(recipients[recipient].lastPausedAt);
        // extend the cliffDuration by the pause duration
        recipients[recipient].cliffDuration = recipients[recipient].cliffDuration.add(pausedFor);
        // extend the endTime by the pause duration
        recipients[recipient].endTime = recipients[recipient].endTime.add(pausedFor);
    }
// Solidity 0.7.6
/// @notice Terminate recipient vesting
/// @dev This terminates the vesting schedule for the recipient forever.
///      Recipient will NOT be able to claim.
///      Only owner of the vesting escrow can invoke this function.
///      Can only be invoked if the escrow is NOT terminated.
/// @param recipient The recipient address for which vesting will be terminated.
function terminateRecipient(address recipient) external onlyOwner escrowNotTerminated isNonZeroAddress(recipient) {
        // current recipient status should NOT be Terminated
        require(recipients[recipient].recipientVestingStatus != Status.Terminated, "terminateRecipient: cannot terminate");
        // claim for the user if possible
        if (canClaim(recipient)) {
            // transfer unclaimed tokens to the recipient
            _claimFor(claimableAmountFor(recipient), recipient);
            // transfer locked tokens to the SAFE_ADDRESS
        }
        uint256 _bal = recipients[recipient].totalVestingAmount.sub(recipients[recipient].totalClaimed);
        IERC20(token).safeTransfer(SAFE_ADDRESS, _bal);
        // set vesting status of the recipient as "Terminated"
        recipients[recipient].recipientVestingStatus = Status.Terminated;
    }
// Solidity 0.7.6
// claim tokens for a specific recipient
function _claimFor(uint256 _amount, address _recipient) internal {
        // get recipient
        Recipient storage recipient = recipients[_recipient];

        // recipient should be able to claim
        require(canClaim(_recipient), "_claimFor: recipient cannot claim");

        // max amount the user can claim right now
        uint256 claimableAmount = claimableAmountFor(_recipient);

        // amount parameter should be less or equal to than claimable amount
        require(_amount <= claimableAmount, "_claimFor: cannot claim passed amount");

        // increase user specific totalClaimed
        recipient.totalClaimed = recipient.totalClaimed.add(_amount);

        // user's totalClaimed should NOT be greater than user's totalVestingAmount
        require(recipient.totalClaimed <= recipient.totalVestingAmount, "_claimFor: cannot claim more than you deserve");

        // increase global totalClaimed
        totalClaimed = totalClaimed.add(_amount);

        // totalClaimed should NOT be greater than total totalAllocatedSupply
        require(totalClaimed <= totalAllocatedSupply, "_claimFor: cannot claim more than allocated to escrow");

        // transfer the amount to the _recipient
        IERC20(token).safeTransfer(_recipient, _amount);
    }
// Solidity 0.7.6
/// @notice Check if a recipient address can successfully invoke claim.
/// @dev Reverts if the recipient is a zero address.
/// @param recipient A zero address recipient address.
/// @return bool representing if the recipient can successfully invoke claim.
function canClaim(address recipient) public view isNonZeroAddress(recipient) returns (bool) {
        Recipient memory _recipient = recipients[recipient];

        // terminated recipients cannot claim
        if (_recipient.recipientVestingStatus == Status.Terminated) {
            return false;
        }

        // In case of a paused recipient
        if (_recipient.recipientVestingStatus == Status.Paused) {
            return _recipient.lastPausedAt >= _recipient.startTime.add(_recipient.cliffDuration);
        }

        // In case of a unpaused recipient, recipient can claim if the cliff duration (inclusive) has passed.
        return block.timestamp >= _recipient.startTime.add(_recipient.cliffDuration);
    }
// Solidity 0.7.6
/// @notice Get total locked tokens of a specific recipient.
/// @dev Reverts if any of the recipients is terminated.
/// @param recipient A non-terminated recipient address.
/// @return Total locked tokens of a specific recipient.
function totalLockedOf(address recipient) public view recipientIsNotTerminated(recipient) returns (uint256) {
        // get recipient
        Recipient memory _recipient = recipients[recipient];

        // We know that vestingPerSec is constant for a recipient for entirety of their vesting period
        // locked = vestingPerSec*(endTime-max(lastPausedAt, startTime+cliffDuration))
        if (_recipient.recipientVestingStatus == Status.Paused) {
            if (_recipient.lastPausedAt >= _recipient.endTime) {
                return 0;
            }
            return
                _recipient.vestingPerSec.mul(
                    _recipient.endTime.sub(
                        Math.max(_recipient.lastPausedAt, _recipient.startTime.add(_recipient.cliffDuration))
                    )
                );
        }

        // Nothing is locked if the recipient passed the endTime
        if (block.timestamp >= _recipient.endTime) {
            return 0;
        }

        // in case escrow is terminated, locked amount stays the constant
        if (ESCROW_TERMINATED) {
            return
                _recipient.vestingPerSec.mul(
                    _recipient.endTime.sub(
                        Math.max(ESCROW_TERMINATED_AT, _recipient.startTime.add(_recipient.cliffDuration))
                    )
                );
        }

        // We know that vestingPerSec is constant for a recipient for entirety of their vesting period
        // locked = vestingPerSec*(endTime-max(block.timestamp, startTime+cliffDuration))
        if (_recipient.recipientVestingStatus == Status.UnPaused) {
            return
                _recipient.vestingPerSec.mul(
                    _recipient.endTime.sub(Math.max(block.timestamp, _recipient.startTime.add(_recipient.cliffDuration)))
                );
        }
    }
// Solidity 0.7.6
/// @notice Allows owner to transfer the ERC20 assets (other than token) to the "to" address in case of any emergency
/// @dev It is assumed that the "to" address is NOT malicious
///      Only owner of the vesting escrow can invoke this function.
///      Reverts if the asset address is a zero address or the token address.
///      Reverts if the to address is a zero address.
/// @param asset Address of the ERC20 asset to be rescued
/// @param to Address to which all ERC20 asset amount will be transferred
/// @return rescued Total amount of asset transferred to the SAFE_ADDRESS.
function inCaseAssetGetStuck(address asset, address to) external onlyOwner returns (uint256 rescued) {
        // asset address should NOT be a 0 address
        require(asset != address(0), "inCaseAssetGetStuck: asset cannot be 0 address");
        // asset address should NOT be the token address
        require(asset != token, "inCaseAssetGetStuck: cannot withdraw token");
        // to address should NOT a 0 address
        require(to != address(0), "inCaseAssetGetStuck: to cannot be 0 address");
        // transfer all the balance of the asset this contract hold to the "to" address
        rescued = IERC20(asset).balanceOf(address(this));
        IERC20(asset).safeTransfer(to, rescued);
    }
// Solidity 0.7.6
/// @notice Transfers the dust to the SAFE_ADDRESS.
/// @dev It is assumed that the SAFE_ADDRESS is NOT malicious.
///      Only owner of the vesting escrow can invoke this function.
/// @return Amount of dust to the SAFE_ADDRESS.
function transferDust() external onlyOwner returns (uint256) {
        // precaution for reentrancy attack
        if (dust > 0) {
            uint256 _dust = dust;
            dust = 0;
            IERC20(token).safeTransfer(SAFE_ADDRESS, _dust);
            return _dust;
        }
        return 0;
    }