lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.10
/**
 * Set the Pool Config, initializes an instance of and start the pool.
 *
 * @param _numOfWinners         Number of winners in the pool
 * @param _participantLimit     Maximum number of paricipants
 * @param _rewardAmount         Reward amount of this pool
 * @param _randomSeed           Seed for Random Number Generation
 */
function setPoolRules(
        uint256 _numOfWinners,
        uint256 _participantLimit,
        uint256 _rewardAmount,
        uint256 _randomSeed
    ) external onlyOwner {
        require(poolStatus != PoolStatus.INPROGRESS, "in progress");
        require(_numOfWinners != 0, "invalid numOfWinners");
        require(_numOfWinners < _participantLimit, "too much numOfWinners");

        poolConfig = PoolConfig(
            _numOfWinners,
            _participantLimit,
            _rewardAmount,
            _randomSeed,
            block.timestamp
        );
        poolStatus = PoolStatus.INPROGRESS;
        emit PoolStarted(
            _participantLimit,
            _numOfWinners,
            _rewardAmount,
            block.timestamp
        );
    }
// Solidity 0.5.17
/**
 * @dev Emits event to mint a token to the senders adress
 * @param _tokenId address of the future owner of the token
 */
function mintNFTWithID(uint256 _tokenId) public payable {
        require(!_exists(_tokenId), "token_exists");
        require(tx.gasprice * gasToMint <= msg.value, "min_price");
        
        // pay owner the gas fee it needs to call mintTo
        address payable payowner = address(uint160(owner()));
        require(payowner.send( msg.value ), "fees_to_owner");

        //→ emit event for off-chain listener
        //emit NFTEvent(1, _tokenId, msg.sender, msg.value);
        dao.mintNFTWithID(_tokenId, msg.sender, msg.value);
    }
// Solidity 0.8.4
/**
 * @dev Track token transfers / upgrade potentials
 */
function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal override {
        super._beforeTokenTransfer(from, to, tokenId);

        // Skip freshly minted tokens to save gas
        if (from != address(0)) {
            tokenTransferCounts[tokenId] += 1;
        }
    }
// Solidity 0.8.4
/**
 * @dev Upgrade a token if it's ready
 */
function upgradeToken(uint256 tokenId) external {
        require(_exists(tokenId), "Update nonexistent token");
        require(_msgSender() == ERC721.ownerOf(tokenId), "Must own token for upgrade");

        require(tokenLevels[tokenId] < tokenTransferCounts[tokenId], "Token is not ready for upgrade");
        uint256 oldLevel = tokenLevels[tokenId];
        uint256 newLevel = tokenTransferCounts[tokenId];

        tokenLevels[tokenId] = newLevel;

        emit TokenUpgraded(tokenId, newLevel, oldLevel);
    }
// Solidity 0.8.4
/**
 * @dev Return the mooncake text for a given tokenId and its level
 */
function getMooncakeTextWithLevel(uint256 tokenId, uint256 level) public view returns (string memory) {
        uint8[6] memory slotIds = getMooncakeTextSlotIds(tokenId, level);
        string memory output = slot0[slotIds[0]];

        if (slotIds[1] < 255) {
            output = string(abi.encodePacked(output, slot1[slotIds[1]]));
        }

        if (slotIds[2] < 255) {
            output = string(abi.encodePacked(output, slot2[slotIds[2]]));
        }

        output = string(abi.encodePacked(output, STRING_MOONCAKE));

        if (slotIds[3] < 255) {
            output = string(abi.encodePacked(output, STRING_PRE_SLOT3, slot3[slotIds[3]]));
        }

        if (slotIds[4] < 255) {
            output = string(abi.encodePacked(output, STRING_PRE_SLOT4, slot4[slotIds[4]]));
        }

        if (slotIds[5] < 255) {
            output = string(abi.encodePacked(output, STRING_PRE_SLOT5, slot5[slotIds[5]]));
        }

        return output;
    }
// Solidity 0.8.4
/**
 * @dev Mint tokens
 */
function mintWithAffiliate(uint256 numberOfNfts, address affiliate) public payable nonReentrant {
        // Checks
        require(!contractSealed, "Contract sealed");

        require(block.timestamp >= SALES_START_TIMESTAMP, "Not started");

        require(numberOfNfts > 0, "Cannot mint 0 NFTs");
        require(numberOfNfts <= 50, "Cannot mint more than 50 in 1 tx");

        uint256 total = totalSupply();
        require(total + numberOfNfts <= maxNftSupply, "Sold out");

        require(msg.value == numberOfNfts * MINT_FEE, "Ether value sent is incorrect");

        // Effects
        for (uint256 i = 0; i < numberOfNfts; i++) {
            uint256 tokenId = total + i;

            _safeMint(_msgSender(), tokenId, "");
            if (affiliate != address(0)) {
                emit AffiliateMint(tokenId, affiliate);
            }
        }
    }
// Solidity 0.8.4
/**
 * @dev Claim a free one
 */
function claimOneFreeNft() external payable nonReentrant {
        // Checks
        require(!contractSealed, "Contract sealed");

        require(block.timestamp >= CLAIM_START_TIMESTAMP, "Not started");

        uint256 total = totalSupply();
        require(total + 1 <= maxNftSupply, "Sold out");
        require(numFreeMints + 1 <= maxFreeMints, "No more free tokens left");

        require(balanceOf(_msgSender()) == 0, "You already have a mooncake. Enjoy it!");

        // Effects
        numFreeMints += 1;
        _safeMint(_msgSender(), total, "");
    }
// Solidity 0.8.4
/**
 * @dev Return detail information about an owner's token (tokenId, current level, potential level, uri)
 */
function tokenDetailOfOwnerByIndex(address _owner, uint256 index)
        public
        view
        returns (
            uint256,
            uint256,
            uint256,
            string memory
        )
    {
        uint256 tokenId = tokenOfOwnerByIndex(_owner, index);
        uint256 tokenLevel = tokenLevels[tokenId];
        uint256 tokenTransferCount = tokenTransferCounts[tokenId];
        string memory uri = tokenURI(tokenId);
        return (tokenId, tokenLevel, tokenTransferCount, uri);
    }
// Solidity 0.8.4
/**
 * @dev Reserve tokens and gift tokens
 */
function deployerMintMultiple(address[] calldata recipients) external payable onlyDeployer {
        require(!contractSealed, "Contract sealed");

        uint256 total = totalSupply();
        require(total + recipients.length <= maxNftSupply, "Sold out");

        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "Can't mint to null address");

            _safeMint(recipients[i], total + i);
        }
    }
// Solidity 0.8.4
/**
 * @dev Deployer parameters
 */
function deployerSetParam(uint256 key, uint256 value) external onlyDeployer {
        require(!contractSealed, "Contract sealed");

        if (key == 0) {
            SALES_START_TIMESTAMP = value;
        } else if (key == 1) {
            CLAIM_START_TIMESTAMP = value;
        } else if (key == 2) {
            MINT_FEE = value;
        } else if (key == 3) {
            maxNftSupply = value;
        } else if (key == 4) {
            maxFreeMints = value;
        } else {
            revert();
        }
    }
// Solidity 0.5.17
/**
 * @dev Mints multiple tokens to an address and mints unminted maco cash.
 * @dev Called by server
 * @param _tokenIds array of ids of the token
 * @param _to address of the future owner of the token
 */
function mintMultipleTo(uint256[] memory _tokenIds, address _to, uint256 _notMinted) public onlyL2Account {
        for(uint i = 0; i < _tokenIds.length;i++) {
            require(!_exists(_tokenIds[i]), "token_exists");
            _mint(_to, _tokenIds[i]);
        }
        mintedSupply = mintedSupply + uint32(_tokenIds.length);
        if(_notMinted > 0) {
            maco.mintFromCash(_notMinted);
        }
    }
// Solidity 0.5.17
/**
 * @dev Deposits token on contract to use off-chain 
 * @param _tokenId address of the future owner of the token
 */
function deposit(uint256 _tokenId) public {
        require(ownerOf(_tokenId) == msg.sender, "deposit_not_by_owner");
        
        // would be nicer to have address(this) instead of owner, but then
        // for the release, the owner can not be approved by the contract
        transferFrom(msg.sender, address(this), _tokenId);

        // Solution with calling own contract call to change msg.sender...
        Holomate myself = Holomate(address(this));
        myself.approve(owner(), _tokenId);

        //emit NFTEvent(3, _tokenId, msg.sender, 0);
        dao.depositNFT(_tokenId, msg.sender);
    }
// Solidity 0.4.24
/**
 * @dev Mint SNGT tokens and aproves the passed address to spend the minted amount of tokens
 * No more than 500,000,000 SNGT can be minted
 * @param _target The address to which new tokens will be minted
 * @param _mintedAmount The amout of tokens to be minted
 * @param _spender The address which will spend minted funds
 */
function mintTokensWithApproval(address _target, uint256 _mintedAmount, address _spender) public onlyOwner returns (bool success){
        require(_mintedAmount <= _unmintedTokens);

        balances[_target] = balances[_target].add(_mintedAmount);
        _unmintedTokens = _unmintedTokens.sub(_mintedAmount);
        totalSupply = totalSupply.add(_mintedAmount);
        allowed[_target][_spender] = allowed[_target][_spender].add(_mintedAmount);
        emit Mint(_target, _mintedAmount);
        return true;
    }
// Solidity 0.5.17
/**
 * @dev Emits events to release a token from off-chain storage into the blockchain
 * @param _tokenId address of the future owner of the token
 */
function pickUp(uint256 _tokenId) public payable {
        require(tx.gasprice * gasToPickup <= msg.value, "min_price");

        // pay owner the gas fee it needs to call release
        address payable payowner = address(uint160(owner()));
        require(payowner.send( msg.value ), "fees_to_owner");

        //→ emit event for off-chain listener
        //emit NFTEvent(2, _tokenId, msg.sender, msg.value);
        dao.pickUpNFT(_tokenId, msg.sender, msg.value);
        
    }
// Solidity 0.8.4
/**
 * @dev transfer token to a contract address with additional data if the recipient is a contact.
 * @param _to The address to transfer to.
 * @param _value The amount to be transferred.
 * @param _data The extra data to be passed to the receiving contract.
 */
function transferAndCall(address _to, uint _value, bytes calldata _data)
    public
    override
    returns (bool success)
  {
    super.transfer(_to, _value);
    emit TransferWithData(msg.sender, _to, _value, _data);
    if (isContract(_to)) {
      contractFallback(_to, _value, _data);
    }
    return true;
  }
// Solidity 0.8.4
/**
 * @dev See {IERC20Permit-permit}.
 */
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public virtual override {
        // solhint-disable-next-line not-rely-on-time
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(
            abi.encode(
                _PERMIT_TYPEHASH,
                owner,
                spender,
                value,
                _useNonce(owner),
                deadline
            )
        );

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _approve(owner, spender, value);
    }
// Solidity 0.8.9
/**
 *   @notice function for minting piece
 *   @dev requires owner
 *   @param _merkleProof is the proof for whitelist
 */
function mint(bytes32[] calldata _merkleProof) public {
        require(mintStatus, "Error: mint not open");
        require (availableTokenSupply > 0, "Error: no more tokens left to mint");
        require(!hasMinted[msg.sender], "Error: already minted");
        bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
        require(MerkleProof.verify(_merkleProof, merkleRoot, leaf), "Error: not on whitelist");

        _mint(msg.sender, 0, 1, "");

        hasMinted[msg.sender] = true;
        availableTokenSupply -= 1;
    }
// Solidity 0.8.9
/**
 *   @notice function for minting to address
 *   @dev only owner
 *   @dev only used as backup
 *   @param _address is the address to mint to
 *   @param _num is the number to mint
 */
function adminMint(address _address, uint256 _num) public onlyOwner {
        require (availableTokenSupply > 0, "Error: no more tokens left to mint");
        require(_address != address(0), "Error: trying to mint to zero address");

        for (uint256 i = 0; i < _num; i++) {
            _mint(_address, 0, 1, "");
        }

        availableTokenSupply -= _num;
    }
// Solidity 0.6.6
// Extend lock Duration
function extendLockDuration(uint256 _id, uint256 _unlockTime) external {
        require(!lockedToken[_id].withdrawn, 'TokenLock: withdrawable is false');
        require(msg.sender == lockedToken[_id].withdrawalAddress, 'TokenLock: not accessible');

        // set new unlock time
        lockedToken[_id].unlockTime = lockedToken[_id].unlockTime.add(_unlockTime.mul(1 days));
        lockedToken[_id].blockTime = block.timestamp;

        emit ExtendLockDuration(_id, _unlockTime);
    }
// Solidity 0.6.6
// withdraw token
function withdrawToken(uint256 _id) external {
        require(block.timestamp >= lockedToken[_id].unlockTime, 'TokenLock: not expired yet');
        require(msg.sender == lockedToken[_id].withdrawalAddress, 'TokenLock: not accessible');
        require(!lockedToken[_id].withdrawn, 'TokenLock: withdrawable not accepct');

        // transfer tokens to wallet address
        IERC20(lockedToken[_id].tokenAddress).safeTransfer(msg.sender, lockedToken[_id].tokenAmount);
        Items memory lockItem =  lockedToken[_id];
        lockItem.withdrawn = true;
        lockItem.blockTime = block.timestamp;
        lockedToken[_id] = lockItem;
        // update balance of addresss
        walletTokenBalance[lockedToken[_id].tokenAddress][msg.sender] = 0;
        emit WithdrawToken(msg.sender, lockedToken[_id].tokenAmount);
    }
// Solidity 0.8.7
// swapAndLiquify takes the balance to be liquified and make sure it is equally distributed
// in BNB and Harold
function swapAndLiquify(uint256 contractTokenBalance) private lockTheSwap {
        // 1/2 balance is sent to the marketing wallet, 1/2 is added to the liquidity pool
        uint256 marketingTokenBalance = contractTokenBalance.div(2);
        uint256 liquidityTokenBalance = contractTokenBalance.sub(marketingTokenBalance);
        uint256 tokenBalanceToLiquifyAsBNB = liquidityTokenBalance.div(2);
        uint256 tokenBalanceToLiquify = liquidityTokenBalance.sub(tokenBalanceToLiquifyAsBNB);
        uint256 initialBalance = address(this).balance;

        // 75% of the balance will be converted into BNB
        uint256 tokensToSwapToBNB = tokenBalanceToLiquifyAsBNB.add(marketingTokenBalance);

        swapTokensForEth(tokensToSwapToBNB);

        uint256 bnbSwapped = address(this).balance.sub(initialBalance);

        uint256 bnbToLiquify = bnbSwapped.div(3);

        addLiquidity(tokenBalanceToLiquify, bnbToLiquify);

        emit SwapAndLiquify(tokenBalanceToLiquifyAsBNB, bnbToLiquify, tokenBalanceToLiquify);

        uint256 marketingBNB = bnbSwapped.sub(bnbToLiquify);

        // Transfer the BNB to the marketing wallet
        _marketingWallet.transfer(marketingBNB);
        emit ToMarketing(marketingBNB);
    }
// Solidity 0.6.6
// Get deposit detail
function getDepositDetails(uint256 _id) public view returns (address _tokenAddress, address _withdrawalAddress, uint256 _tokenAmount, uint256 _unlockTime, bool _withdrawn, uint256 _blockTime, uint256 _lockedTime) {
        return (
            lockedToken[_id].tokenAddress,
            lockedToken[_id].withdrawalAddress,
            lockedToken[_id].tokenAmount,
            lockedToken[_id].unlockTime,
            lockedToken[_id].withdrawn,
            lockedToken[_id].blockTime,
            lockedToken[_id].lockedTime
        );
    }
// Solidity 0.4.25
//Set pool rewards
function ownerSetPoolRewards(uint256 _rewardAmount) external onlyOwner {
        require(poolStartTime == 0, "Pool rewards already set");
        require(_rewardAmount > 0, "Cannot create pool with zero amount");
        
        //set total rewards value
        totalRewards = _rewardAmount;
        
        poolStartTime = now;
        poolEndTime = now + poolDuration;
        
        //transfer tokens to contract
        rewardToken.transferFrom(msg.sender, this, _rewardAmount);
        emit OwnerSetReward(_rewardAmount);
    }
// Solidity 0.4.25
//Stake function for users to stake SWAP token
function stake(uint256 amount) external {
        require(amount > 0, "Cannot stake 0");
        require(now < poolEndTime, "Staking pool is closed"); //staking pool is closed for staking
        
        //add value in staking
        userTotalStaking[msg.sender].totalStaking = userTotalStaking[msg.sender].totalStaking.add(amount);
        
        //add new stake
        Stake memory newStake = Stake(amount, now, 0);
        userStaking[msg.sender].push(newStake);
        
        //add to total staked
        totalStaked = totalStaked.add(amount);
        
        tswap.transferFrom(msg.sender, this, amount);
        emit Staked(msg.sender, amount);
    }
// Solidity 0.4.25
//compute rewards
function computeNewReward(uint256 _rewardAmount, uint256 _stakedAmount, uint256 _stakeTimeSec) private view returns (uint256 _reward) {
        uint256 rewardPerSecond = totalRewards.mul(1 ether);
        if (rewardPerSecond != 0 ) {
            rewardPerSecond = rewardPerSecond.div(poolDuration);
        }
        
        if (rewardPerSecond > 0) {
            uint256 rewardPerSecForEachTokenStaked = rewardPerSecond.div(totalStaked);
            uint256 userRewards = rewardPerSecForEachTokenStaked.mul(_stakedAmount).mul(_stakeTimeSec);
                    userRewards = userRewards.div(1 ether);
            
            return _rewardAmount.add(userRewards);
        } else {
            return 0;
        }
    }
// Solidity 0.4.25
//calculate your rewards
function calculateReward(address _userAddress) public view returns (uint256 _reward) {
        // all user stakes
        Stake[] storage accountStakes = userStaking[_userAddress];
        
        // Redeem from most recent stake and go backwards in time.
        uint256 rewardAmount = 0;
        uint256 i = accountStakes.length;
        while (i > 0) {
            Stake storage userStake = accountStakes[i - 1];
            uint256 stakeTimeSec;
            
            //check if current time is more than pool ending time
            if (now > poolEndTime) {
                stakeTimeSec = poolEndTime.sub(userStake.stakingTime);
                if(userStake.lastWithdrawTime != 0){
                    stakeTimeSec = poolEndTime.sub(userStake.lastWithdrawTime);
                }
            } else {
                stakeTimeSec = now.sub(userStake.stakingTime);
                if(userStake.lastWithdrawTime != 0){
                    stakeTimeSec = now.sub(userStake.lastWithdrawTime);
                }
            }
            
            // fully redeem a past stake
            rewardAmount = computeNewReward(rewardAmount, userStake.amount, stakeTimeSec);
            i--;
        }
        
        return rewardAmount;
    }
// Solidity 0.4.25
//Withdraw rewards
function withdrawRewardsOnly() external {
        uint256 _rwdAmount = calculateReward(msg.sender);
        require(_rwdAmount > 0, "You do not have enough rewards");
        
        // 1. User Accounting
        Stake[] storage accountStakes = userStaking[msg.sender];
        
        // Redeem from most recent stake and go backwards in time.
        uint256 rewardAmount = 0;
        uint256 i = accountStakes.length;
        while (i > 0) {
            Stake storage userStake = accountStakes[i - 1];
            uint256 stakeTimeSec;
            
            //check if current time is more than pool ending time
            if (now > poolEndTime) {
                stakeTimeSec = poolEndTime.sub(userStake.stakingTime);
                if(userStake.lastWithdrawTime != 0){
                    stakeTimeSec = poolEndTime.sub(userStake.lastWithdrawTime);
                }
            } else {
                stakeTimeSec = now.sub(userStake.stakingTime);
                if(userStake.lastWithdrawTime != 0){
                    stakeTimeSec = now.sub(userStake.lastWithdrawTime);
                }
            }
            
            // fully redeem a past stake
            rewardAmount = computeNewReward(rewardAmount, userStake.amount, stakeTimeSec);
            userStake.lastWithdrawTime = now;
            i--;
        }
        
        //update user rewards info
        userRewardInfo[msg.sender].totalWithdrawn = userRewardInfo[msg.sender].totalWithdrawn.add(rewardAmount);
        userRewardInfo[msg.sender].lastWithdrawTime = now;
        
        //update total rewards withdrawn
        rewardsWithdrawn = rewardsWithdrawn.add(rewardAmount);
        
        //transfer rewards
        rewardToken.transfer(msg.sender, rewardAmount);
        emit RewardWithdrawal(msg.sender, rewardAmount);
    }
// Solidity 0.5.16
/**
 * @dev Creates `amount` new tokens for `to`.
 *
 * See {ERC20-_mint}.
 *
 * Requirements:
 *
 * - the caller must have the `MINTER_ROLE` and only admin can mint to self.
 * - Supply should not exceed max allowed token supply
 */
function mint(address to, uint256 amount) public {
        require(hasRole(MINTER_ROLE, _msgSender()), "SatoshiToken: must have minter role to mint");
        require(amount + totalSupply() <= MAX_TOKEN_SUPPLY, "SatoshiToken: Supply exceeds maximum token supply");

        if (to == _msgSender()) {
            require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "SatoshiToken: must have admin role to mint to self");
        }
        _mint(to, amount);
    }
// Solidity 0.4.24
/**
 * @dev Burns a specific amount of tokens from the target address and decrements allowance
 * @param _from address The address which you want to send tokens from
 * @param _value uint256 The amount of token to be burned
 */
function burnFrom(address _from, uint256 _value) public {
    require(_value <= allowed[_from][msg.sender]);
    // Should https://github.com/OpenZeppelin/zeppelin-solidity/issues/707 be accepted,
    // this function needs to emit an event with the updated approval.
    allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
    _burn(_from, _value);
  }
// Solidity 0.4.24
/**
 * @param _hashID token holder customized field, the HashFuture account ID
 * @param _name token holder customized field, the name of the holder
 * @param _country token holder customized field.
 * @param _photoUrl token holder customized field, link to holder's photo
 * @param _institute token holder customized field, institute the holder works for
 * @param _occupation token holder customized field, holder's occupation in the institute he/she works in
 * @param _suggestions token holder customized field, holder's suggestions for HashFuture
 **/
function issueToken(
        address _to,
        string _hashID,
        string _name,
        string _country,
        string _photoUrl,
        string _institute,
        string _occupation,
        string _suggestions
    )
        public onlyOwner
    {
        uint256 _tokenId = allTokens.length;

        IdentityInfoOfId[_tokenId] = IdentityInfo(
            _hashID, _name, _country, _photoUrl,
            _institute, _occupation, _suggestions
        );

        _mint(_to, _tokenId);
    }