lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.6
/**
 * @dev From ERC-3156. Loan `amount` fyDai to `receiver`, which needs to return them plus fee to this contract within the same transaction.
 * Note that if the initiator and the borrower are the same address, no approval is needed for this contract to take the principal + fee from the borrower.
 * If the borrower transfers the principal + fee to this contract, they will be burnt here instead of pulled from the borrower.
 * @param receiver The contract receiving the tokens, needs to implement the `onFlashLoan(address user, uint256 amount, uint256 fee, bytes calldata)` interface.
 * @param token The loan currency. Must be a fyDai contract.
 * @param amount The amount of tokens lent.
 * @param data A data parameter to be passed on to the `receiver` for any custom use.
 */
function flashLoan(IERC3156FlashBorrower receiver, address token, uint256 amount, bytes memory data)
        external override
        beforeMaturity
        returns(bool)
    {
        require(token == address(this), "Unsupported currency");
        _mint(address(receiver), amount);
        require(receiver.onFlashLoan(msg.sender, token, amount, 0, data) == FLASH_LOAN_RETURN, "Non-compliant borrower");
        _burn(address(receiver), amount);
        return true;
    }
// Solidity 0.8.7
// public (Early Bird Mint) 150 to mint
function earlyBirdMint() public payable {
        uint256 supply = totalSupply();
        require(
            earlyBirdMinting,
            "Error: Early Bird minting is not active yet."
        );
        require(supply < 250, "Error: Maximum limit surpassed"); // max total mints is 100 marketing, 150 earlybird,

        require(
            earlyBirdList[msg.sender],
            "Error: Sender is not on the Early Bird List!"
        );

        if (mintLimitActive) {
            require(
                !alreadyMinted[msg.sender],
                "Error: Sender already minted one token"
            );
        }

        if (msg.sender != owner()) {
            require(msg.value >= cost, "Error: costs are higher per NFT.");
        }

        _safeMint(msg.sender, supply + 1);
        alreadyMinted[msg.sender] = true;
    }
// Solidity 0.8.7
// public marketing mint 100
function marketingMint() public payable onlyOwnerOrDev {
        uint256 supply = totalSupply();
        require(
            marketingMinting,
            "Error: Marketing minting is not active yet."
        );
        require(supply < 100, "Error you may only mint 100 NFTs"); // max total mints is 100 marketing

        for (uint256 i = 1; i <= 100; i++) {
            _safeMint(msg.sender, supply + i);
        }
    }
// Solidity 0.5.17
/**
 * @dev is used to add initital advisory board members
 * @param abArray is the list of initial advisory board members
 */
function addInitialABMembers(address[] calldata abArray) external onlyOwner {

    //Ensure that NXMaster has initialized.
    require(ms.masterInitialized());

    require(maxABCount >=
      SafeMath.add(numberOfMembers(uint(Role.AdvisoryBoard)), abArray.length)
    );
    //AB count can't exceed maxABCount
    for (uint i = 0; i < abArray.length; i++) {
      require(checkRole(abArray[i], uint(MemberRoles.Role.Member)));
      _updateRole(abArray[i], uint(Role.AdvisoryBoard), true);
    }
  }
// Solidity 0.5.17
/**
 * @dev to add members before launch
 * @param userArray is list of addresses of members
 * @param tokens is list of tokens minted for each array element
 */
function addMembersBeforeLaunch(address[] memory userArray, uint[] memory tokens) public onlyOwner {
    require(!launched);

    for (uint i = 0; i < userArray.length; i++) {
      require(!ms.isMember(userArray[i]));
      dAppToken.addToWhitelist(userArray[i]);
      _updateRole(userArray[i], uint(Role.Member), true);
      dAppToken.mint(userArray[i], tokens[i]);
    }
    launched = true;
    launchedOn = now;

  }
// Solidity 0.5.17
/**
 * @dev Called by user to pay joining membership fee
 */
function payJoiningFee(address _userAddress) public payable {
    require(_userAddress != address(0));
    require(!ms.isPause(), "Emergency Pause Applied");
    if (msg.sender == address(ms.getLatestAddress("QT"))) {
      require(td.walletAddress() != address(0), "No walletAddress present");
      dAppToken.addToWhitelist(_userAddress);
      _updateRole(_userAddress, uint(Role.Member), true);
      td.walletAddress().transfer(msg.value);
    } else {
      require(!qd.refundEligible(_userAddress));
      require(!ms.isMember(_userAddress));
      require(msg.value == td.joiningFee());
      qd.setRefundEligible(_userAddress, true);
    }
  }
// Solidity 0.5.17
/**
 * @dev to perform kyc verdict
 * @param _userAddress whose kyc is being performed
 * @param verdict of kyc process
 */
function kycVerdict(address payable _userAddress, bool verdict) public {

    require(msg.sender == qd.kycAuthAddress());
    require(!ms.isPause());
    require(_userAddress != address(0));
    require(!ms.isMember(_userAddress));
    require(qd.refundEligible(_userAddress));
    if (verdict) {
      qd.setRefundEligible(_userAddress, false);
      uint fee = td.joiningFee();
      dAppToken.addToWhitelist(_userAddress);
      _updateRole(_userAddress, uint(Role.Member), true);
      td.walletAddress().transfer(fee); // solhint-disable-line

    } else {
      qd.setRefundEligible(_userAddress, false);
      _userAddress.transfer(td.joiningFee()); // solhint-disable-line
    }
  }
// Solidity 0.5.17
/**
 * @dev Called by existed member if wish to Withdraw membership.
 */
function withdrawMembership() public {

    require(!ms.isPause() && ms.isMember(msg.sender));
    require(dAppToken.totalLockedBalance(msg.sender, now) == 0); // solhint-disable-line
    require(!tf.isLockedForMemberVote(msg.sender)); // No locked tokens for Member/Governance voting
    require(cr.getAllPendingRewardOfUser(msg.sender) == 0); // No pending reward to be claimed(claim assesment).
    require(dAppToken.tokensUnlockable(msg.sender, "CLA") == 0, "Member should have no CLA unlockable tokens");

    gv.removeDelegation(msg.sender);
    dAppToken.burnFrom(msg.sender, tk.balanceOf(msg.sender));
    _updateRole(msg.sender, uint(Role.Member), false);
    dAppToken.removeFromWhitelist(msg.sender); // need clarification on whitelist

    if (claimPayoutAddress[msg.sender] != address(0)) {
      claimPayoutAddress[msg.sender] = address(0);
      emit ClaimPayoutAddressSet(msg.sender, address(0));
    }
  }
// Solidity 0.5.17
/**
 * @dev Called by existed member if wish to switch membership to other address.
 * @param _add address of user to forward membership.
 */
function switchMembership(address _add) external {

    require(!ms.isPause() && ms.isMember(msg.sender) && !ms.isMember(_add));
    require(dAppToken.totalLockedBalance(msg.sender, now) == 0); // solhint-disable-line
    require(!tf.isLockedForMemberVote(msg.sender)); // No locked tokens for Member/Governance voting
    require(cr.getAllPendingRewardOfUser(msg.sender) == 0); // No pending reward to be claimed(claim assesment).
    require(dAppToken.tokensUnlockable(msg.sender, "CLA") == 0, "Member should have no CLA unlockable tokens");

    gv.removeDelegation(msg.sender);
    dAppToken.addToWhitelist(_add);
    _updateRole(_add, uint(Role.Member), true);
    tk.transferFrom(msg.sender, _add, tk.balanceOf(msg.sender));
    _updateRole(msg.sender, uint(Role.Member), false);
    dAppToken.removeFromWhitelist(msg.sender);

    address payable previousPayoutAddress = claimPayoutAddress[msg.sender];

    if (previousPayoutAddress != address(0)) {

      address payable storedAddress = previousPayoutAddress == _add ? address(0) : previousPayoutAddress;

      claimPayoutAddress[msg.sender] = address(0);
      claimPayoutAddress[_add] = storedAddress;

      // emit event for old address reset
      emit ClaimPayoutAddressSet(msg.sender, address(0));

      if (storedAddress != address(0)) {
        // emit event for setting the payout address on the new member address if it's non zero
        emit ClaimPayoutAddressSet(_add, storedAddress);
      }
    }

    emit switchedMembership(msg.sender, _add, now);
  }
// Solidity 0.5.17
/// @dev Gets the member addresses assigned by a specific role
/// @param _memberRoleId Member role id
/// @return roleId Role id
/// @return allMemberAddress Member addresses of specified role id
function members(uint _memberRoleId) public view returns (uint, address[] memory memberArray) {//solhint-disable-line
    uint length = memberRoleData[_memberRoleId].memberAddress.length;
    uint i;
    uint j = 0;
    memberArray = new address[](memberRoleData[_memberRoleId].memberCounter);
    for (i = 0; i < length; i++) {
      address member = memberRoleData[_memberRoleId].memberAddress[i];
      if (memberRoleData[_memberRoleId].memberActive[member] && !_checkMemberInArray(member, memberArray)) {//solhint-disable-line
        memberArray[j] = member;
        j++;
      }
    }

    return (_memberRoleId, memberArray);
  }
// Solidity 0.5.17
/// @dev Get All role ids array that has been assigned to a member so far.
function roles(address _memberAddress) public view returns (uint[] memory) {//solhint-disable-line
    uint length = memberRoleData.length;
    uint[] memory assignedRoles = new uint[](length);
    uint counter = 0;
    for (uint i = 1; i < length; i++) {
      if (memberRoleData[i].memberActive[_memberAddress]) {
        assignedRoles[counter] = i;
        counter++;
      }
    }
    return assignedRoles;
  }
// Solidity 0.5.17
/**
 * @dev to update the member roles
 * @param _memberAddress in concern
 * @param _roleId the id of role
 * @param _active if active is true, add the member, else remove it
 */
function _updateRole(address _memberAddress,
    uint _roleId,
    bool _active) internal {
    // require(_roleId != uint(Role.TokenHolder), "Membership to Token holder is detected automatically");
    if (_active) {
      require(!memberRoleData[_roleId].memberActive[_memberAddress]);
      memberRoleData[_roleId].memberCounter = SafeMath.add(memberRoleData[_roleId].memberCounter, 1);
      memberRoleData[_roleId].memberActive[_memberAddress] = true;
      memberRoleData[_roleId].memberAddress.push(_memberAddress);
    } else {
      require(memberRoleData[_roleId].memberActive[_memberAddress]);
      memberRoleData[_roleId].memberCounter = SafeMath.sub(memberRoleData[_roleId].memberCounter, 1);
      delete memberRoleData[_roleId].memberActive[_memberAddress];
    }
  }
// Solidity 0.5.17
/**
 * @dev to check if member is in the given member array
 * @param _memberAddress in concern
 * @param memberArray in concern
 * @return boolean to represent the presence
 */
function _checkMemberInArray(
    address _memberAddress,
    address[] memory memberArray
  )
  internal
  pure
  returns (bool memberExists)
  {
    uint i;
    for (i = 0; i < memberArray.length; i++) {
      if (memberArray[i] == _memberAddress) {
        memberExists = true;
        break;
      }
    }
  }
// Solidity 0.5.17
/**
 * @dev to add initial member roles
 * @param _firstAB is the member address to be added
 * @param memberAuthority is the member authority(role) to be added for
 */
function _addInitialMemberRoles(address _firstAB, address memberAuthority) internal {
    maxABCount = 5;
    _addRole("Unassigned", "Unassigned", address(0));
    _addRole(
      "Advisory Board",
      "Selected few members that are deeply entrusted by the dApp. An ideal advisory board should be a mix of skills of domain, governance, research, technology, consulting etc to improve the performance of the dApp.", //solhint-disable-line
      address(0)
    );
    _addRole(
      "Member",
      "Represents all users of Mutual.", //solhint-disable-line
      memberAuthority
    );
    _addRole(
      "Owner",
      "Represents Owner of Mutual.", //solhint-disable-line
      address(0)
    );
    // _updateRole(_firstAB, uint(Role.AdvisoryBoard), true);
    _updateRole(_firstAB, uint(Role.Owner), true);
    // _updateRole(_firstAB, uint(Role.Member), true);
    launchedOn = 0;
  }
// Solidity 0.6.6
/**
 * @dev Stake rPEPE-ETH LP tokens
 *
 * Requirement
 *
 * - In this pool, don't care about 2.5% fee for stake/unstake
 *
 * @param amount: Amount of LP tokens to deposit
 */
function stake(uint256 amount) public {
        require(amount > 0, "Staking amount must be more than zero");
        // Transfer tokens from staker to the contract amount
        require(IUniswapV2Pair(_UniswapV2Pair).transferFrom(_msgSender(), address(this), uint(amount)), "It has failed to transfer tokens from staker to contract.");
        // add staker to array
        if (_stakedAmount[_msgSender()] == 0) {
            _stakers.push(_msgSender());
        }
        // Increase the total staked amount
        _totalStakedAmount = _totalStakedAmount.add(amount);
        // Add new stake amount
        _stakedAmount[_msgSender()] = _stakedAmount[_msgSender()].add(amount);
        emit Staked(_msgSender(), amount);
    }
// Solidity 0.6.6
/**
 * @dev count and return pepe amount from lp token amount in uniswap v2 pool
 *
 * Formula
 *
 * - rPEPE = (staked LP / total LP in uniswap pool) * rPEPE in uniswap pool
 */
function _getStakedPepeAmount(uint256 amount) internal view returns (uint256)  {
        (uint112 pepeAmount,,) = IUniswapV2Pair(_UniswapV2Pair).getReserves();
        // get the total amount of LP token in uniswap v2 pool
        uint totalAmount = IUniswapV2Pair(_UniswapV2Pair).totalSupply();
        return amount.mul(uint256(pepeAmount)).div(uint256(totalAmount));
    }
// Solidity 0.8.7
// Standard mint function
function mint(uint256 _amount) public payable {
        uint256 supply = totalSupply();
        require( saleIsActive,                     "Sale isn't active" );
        require( _amount > 0 && _amount < 16,     "Can only mint between 1 and 15 tokens at once" );
        require( (supply + _amount) <= (MAX_SUPPLY - reserved), "Purchase would exceed maximum supply" );
        require( msg.value == price * _amount,   "Wrong amount of ETH sent" );
        for(uint256 i; i < _amount; i++){
            _safeMint( msg.sender, supply + i );
        }
    }
// Solidity 0.6.8
/**
 * @notice withdraw any Dai accumulated as dividends, and any tokens that might have been erroneously sent to this contract
 * @param token      address of token to withdraw
 * @param amount     amount of token to withdraw
 * @return true if success
 */
function withdrawERC20(address token, uint256 amount) external returns (bool) {
        require(msg.sender == _poolSource, "Only designated source can withdraw any token");
        require(token != address(_wToken), "Cannot withdraw asset token this way");

        IERC20(token).safeTransfer(_poolSource, amount);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice deposit Dai and get back wTokens
 * @param amount      amount of Dai to deposit
 * @return true if success
 */
function swapWithDai(uint256 amount) external returns (bool) {
        require(amount > 0, "Dai amount must be greater than 0");

        uint256 tokenAmount = daiToToken(amount);

        // through not strictly needed, useful to have a clear message for this error case
        require(_wToken.balanceOf(address(this)) >= tokenAmount, "Insufficient token supply in the pool");

        _daiContract.transferFrom(msg.sender, _poolSource, amount);
        _wToken.transfer(msg.sender, tokenAmount);

        emit TokenTransaction(msg.sender, msg.sender, tokenAmount, 1, amount);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice deposit USDT and get back wTokens
 * @param amount      amount of USDT to deposit
 * @return true if success
 */
function swapWithUSDT(uint256 amount) external returns (bool) {
        require(amount > 0, "USDT amount must be greater than 0");

        uint256 tokenAmount = usdtToToken(amount);

        require(_wToken.balanceOf(address(this)) >= tokenAmount, "Insufficient token supply in the pool");

        // safeTransferFrom is necessary for USDT due to argument byte size check in USDT's transferFrom function
        _usdtContract.safeTransferFrom(msg.sender, _poolSource, amount);
        _wToken.transfer(msg.sender, tokenAmount);

        emit TokenTransaction(msg.sender, msg.sender, tokenAmount, 3, amount);
        return true;
    }
// Solidity 0.5.10
/// @notice A public call to increase the peg by 4%. Can only be called once every 12 hours, and only if
///         there is there is <= 2% as much Ether value in the contract as there is Dai value.
///         Example: with a peg of 100, and 10000 total Dai in the vault, the ether balance of the
///         vault must be less than or equal to 2 to execute this function.
function increasePeg() external {
        // check that the total value of eth in contract is <= 2% the total value of dai in the contract
        require (address(this).balance.mul(etherPeg) <= daiContract.balanceOf(address(this)).div(50)); 
        // check that peg hasn't been changed in last 12 hours
        require (now > pegMoveReadyTime);
        // increase peg
        etherPeg = etherPeg.mul(104).div(100);
        // reset cooldown
        pegMoveReadyTime = now+pegMoveCooldown;
    }
// Solidity 0.5.10
/// @notice All units are minimum denomination, ie base unit *10**-18
///         Use this payable function to buy INCH from the contract with Wei. Rates are based on premium
///         and etherPeg. For every Wei deposited, msg.sender recieves etherPeg/(0.000001*premium) INCH.
///         Example: If the peg is 100, and the premium is 2000000, msg.sender will recieve 50 INCH.
/// @dev    Transaction reverts if payment results in 0 INCH returned
function __buyInchWithWei() external payable {
        // Calculate the amount of inch give to msg.sender
        uint _inchToBuy = msg.value.mul(etherPeg).mul(premiumDigits).div(premium);
        // Require that INCH returned is not 0
        require(_inchToBuy > 0);
        // Transfer INCH to Purchaser
        inchWormContract.transfer(msg.sender, _inchToBuy);
        
        emit BuyInchWithWei(_inchToBuy, msg.value);
    }
// Solidity 0.5.10
/// @param  _inchToBuy: amount of INCH (in mininum denomination) msg.sender wishes to purchase
/// @notice All units are in minimum denomination, ie base unit *10**-18
///         Use this payable to buy INCH from the contract using Dai. Rates are based on premium.
///         For every Dai deposited, msg.sender recieves 1/(0.000001*premium) INCH.
///         Example: If the premium is 5000000, calling the function with input 1 will result in 
///         msg.sender paying 5 DaiSats. 
function __buyInchWithDai(uint _inchToBuy) external {
        // Calculate the amount of Dai to extract from the purchaser's wallet based on the premium
        uint _daiOwed = _inchToBuy.mul(premium).div(premiumDigits);
        // Take Dai from the purchaser and transfer to vault contract
        daiContract.transferFrom(msg.sender, address(this), _daiOwed);
        // Send INCH to purchaser
        inchWormContract.transfer(msg.sender, _inchToBuy);
        
        emit BuyInchWithDai(_inchToBuy, _daiOwed);
    }
// Solidity 0.8.2
// join presale - just send ETH to contract,
// remember to check GAS LIMIT > 70000!
receive() external payable {
        // only if not ended
        require(!presaleEnded, "Presale ended");
        // only if within time limit
        require(block.timestamp < presaleEnd, "Presale time's up");

        // record new user balance if possible
        uint256 amount = msg.value + balances[msg.sender];
        require(amount >= minPerUser, "Below buy-in");
        require(amount <= maxPerUser, "Over buy-in");
        balances[msg.sender] = amount;

        // end presale if reached limit
        if (collected() >= presaleLimit) {
            presaleEnded = true;
        }
    }
// Solidity 0.8.2
// withdraw ETH from contract
// can be used by user and owner
// return false if nothing to do
function withdraw() external returns (bool) {
        if (!presaleEnded) {
            // end and fail presale if failsafe time passed
            if (block.timestamp > presaleEnd + failSafeTime) {
                presaleEnded = true;
                presaleFailed = true;
                // don't return true, you can withdraw in this call
            }
        }
        // owner withdraw - presale succeed ?
        else if (msg.sender == owner && !presaleFailed) {
            send(owner, address(this).balance);
            return true;
        }

        // presale failed, withdraw to calling user
        if (presaleFailed) {
            uint256 amount = balances[msg.sender];
            balances[msg.sender] = 0;
            send(msg.sender, amount);
            return true;
        }

        // did nothing
        return false;
    }
// Solidity 0.5.1
// Send {tokens} amount of tokens from address {from} to address {to}
// The transferFrom method is used for a withdraw workflow, allowing contracts to send
// tokens on your behalf
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        require( allowed[from][msg.sender] >= tokens && balances[from] >= tokens && tokens > 0 );
        balances[from] -= tokens;
        allowed[from][msg.sender] -= tokens;
        balances[to] += tokens;
        emit Transfer(from, to, tokens);
        return true;
    }
// Solidity 0.8.11
// automated buyback
function autoBuyBack(uint256 amountInWei) internal {
        
        lastAutoBuyBackTime = block.timestamp;
        
        address[] memory path = new address[](2);
        path[0] = dexRouter.WETH();
        path[1] = address(this);

        // make the swap
        dexRouter.swapExactETHForTokensSupportingFeeOnTransferTokens{value: amountInWei}(
            0, // accept any amount of Ethereum
            path,
            address(0xdead),
            block.timestamp
        );
        
        emit BuyBackTriggered(amountInWei);
    }
// Solidity 0.8.12
/* ------------- Traits ------------- */
function encode(string[] memory strs) internal pure returns (bytes memory) {
        bytes memory a;
        for (uint256 i; i < strs.length; i++) {
            if (i < strs.length - 1) a = abi.encodePacked(a, strs[i], bytes1(0));
            else a = abi.encodePacked(a, strs[i]);
        }
        return a;
    }