lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/// @dev Remove liquidity from Sushiswap pool, with no staking rewards (use WERC20 wrapper)
/// @param tokenA Token A for the pair
/// @param tokenB Token B for the pair
/// @param amt Amounts of tokens to take out, withdraw, repay, and get.
function removeLiquidityWERC20(
    address tokenA,
    address tokenB,
    RepayAmounts calldata amt
  ) external {
    address lp = getAndApprovePair(tokenA, tokenB);

    // 1. Take out collateral
    doTakeCollateral(lp, amt.amtLPTake);

    // 2-8. remove liquidity
    removeLiquidityInternal(tokenA, tokenB, amt, lp);
  }
// Solidity 0.6.12
/// @dev Remove liquidity from Sushiswap pool, from masterChef staking
/// @param tokenA Token A for the pair
/// @param tokenB Token B for the pair
/// @param amt Amounts of tokens to take out, withdraw, repay, and get.
function removeLiquidityWMasterChef(
    address tokenA,
    address tokenB,
    RepayAmounts calldata amt
  ) external {
    address lp = getAndApprovePair(tokenA, tokenB);
    (, address collToken, uint collId, ) = bank.getCurrentPositionInfo();
    require(IWMasterChef(collToken).getUnderlyingToken(collId) == lp, 'incorrect underlying');
    require(collToken == address(wmasterchef), 'collateral token & wmasterchef mismatched');

    // 1. Take out collateral
    bank.takeCollateral(address(wmasterchef), collId, amt.amtLPTake);
    wmasterchef.burn(collId, amt.amtLPTake);

    // 2-8. remove liquidity
    removeLiquidityInternal(tokenA, tokenB, amt, lp);

    // 9. Refund sushi
    doRefund(sushi);
  }
// Solidity 0.6.12
/// @dev Harvest SUSHI reward tokens to in-exec position's owner
function harvestWMasterChef() external {
    (, address collToken, uint collId, ) = bank.getCurrentPositionInfo();
    (uint pid, ) = wmasterchef.decodeId(collId);
    address lp = wmasterchef.getUnderlyingToken(collId);
    require(whitelistedLpTokens[lp], 'lp token not whitelisted');
    require(collToken == address(wmasterchef), 'collateral token & wmasterchef mismatched');

    // 1. Take out collateral
    bank.takeCollateral(address(wmasterchef), collId, uint(-1));
    wmasterchef.burn(collId, uint(-1));

    // 2. put collateral
    uint amount = IERC20(lp).balanceOf(address(this));
    ensureApprove(lp, address(wmasterchef));
    uint id = wmasterchef.mint(pid, amount);
    bank.putCollateral(address(wmasterchef), id, amount);

    // 3. Refund sushi
    doRefund(sushi);
  }
// Solidity 0.4.24
/**
 * @dev converts all incoming ethereum to keys.
 * @param _affCode the ID/address/name of the player who gets the affiliate fee
 * @param _team what team is the player playing for?
 */
function buyXid(uint256 _affCode, uint256 _team)
        isActivated()
        isHuman()
        isWithinLimits(msg.value)
        public
        payable
    {
        // set up our tx event data and determine if player is new or not
        CAE4Ddatasets.EventReturns memory _eventData_ = determinePID(_eventData_);
        
        // fetch player id
        uint256 _pID = pIDxAddr_[msg.sender];
        
        // manage affiliate residuals
        // if no affiliate code was given or player tried to use their own, lolz
        if (_affCode == 0 || _affCode == _pID)
        {
            // use last stored affiliate code 
            _affCode = plyr_[_pID].laff;
            
        // if affiliate code was given & its not the same as previously stored 
        } else if (_affCode != plyr_[_pID].laff) {
            // update last affiliate 
            plyr_[_pID].laff = _affCode;
        }
        
        // verify a valid team was selected
        _team = verifyTeam(_team);
        
        // buy core 
        buyCore(_pID, _affCode, _team, _eventData_);
    }
// Solidity 0.4.24
/**
 * @dev returns all current round info needed for front end
 * -functionhash- 0x747dff42
 * @return eth invested during ICO phase
 * @return round id 
 * @return total keys for round 
 * @return time round ends
 * @return time round started
 * @return current pot 
 * @return current team ID & player ID in lead 
 * @return current player in leads address 
 * @return current player in leads name
 * @return elephants eth in for round
 * @return nuts eth in for round
 * @return rock eth in for round
 * @return rivulets eth in for round
 * @return airdrop tracker # & airdrop pot
 */
function getCurrentRoundInfo()
        public
        view
        returns(uint256, uint256, uint256, uint256, uint256, uint256, uint256, address, bytes32, uint256, uint256, uint256, uint256, uint256)
    {
        // setup local rID
        uint256 _rID = rID_;
        
        return
        (
            round_[_rID].eth,               //0
            _rID,                           //1
            round_[_rID].keys,              //2
            round_[_rID].end,               //3
            round_[_rID].strt,              //4
            round_[_rID].pot,               //5
            (round_[_rID].team + (round_[_rID].plyr * 10)),     //6
            plyr_[round_[_rID].plyr].addr,  //7
            plyr_[round_[_rID].plyr].name,  //8
            rndTmEth_[_rID][0],             //9
            rndTmEth_[_rID][1],             //10
            rndTmEth_[_rID][2],             //11
            rndTmEth_[_rID][3],             //12
            airDropTracker_ + (airDropPot_ * 1000)              //13
        );
    }
// Solidity 0.4.19
// WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.  
// This is a constructor function 
// which means the following function name has to match the contract name declared above
function Dubscoin() {
        balances[msg.sender] = 11111111100000000000;               // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS)
        totalSupply = 11111111100000000000;                        // Update total supply (1000 for example) (CHANGE THIS)
        name = "Dubscoin";                                   // Set the name for display purposes (CHANGE THIS)
        decimals = 11;                                               // Amount of decimals for display purposes (CHANGE THIS)
        symbol = "DUBS";                                             // Set the symbol for display purposes (CHANGE THIS)                                 // Set the price of your token for the ICO (CHANGE THIS)
    }
// Solidity 0.6.6
/**
 * @notice If volatility of asset pair is over 200%, spread rate becomes variable
 **/
function calculateSpreadByAssetVolatility(OracleInterface oracle)
        external
        override
        returns (uint128)
    {
        if (address(oracle) == address(0)) {
            return uint128(SPREAD_RATE);
        }
        uint256 volatility = oracle.getVolatility().mul(TEN_DIGITS);
        if ((DECIMAL * 100) > volatility && (DECIMAL * 2) < volatility) {
            return SPREAD_RATE.mulByRate(volatility).div(2).toUint128();
        } else if (DECIMAL * 100 <= volatility) {
            return uint128(SPREAD_RATE * 50);
        }
        return uint128(SPREAD_RATE);
    }
// Solidity 0.6.6
/**
 * @notice Approximate expression of option token volatility
 * @param coef Coefficient of S/K in the linear equation
 * @param coefsig Coefficient of vol * t^0.5 in the linear equation
 * @param intercept Intercept in the linear equation
 * @param ratio S/K
 * @param sigTime vol * t^0.5
 * @dev Spread is difined by volatility of LBT which is approached by linear equation (intercept - coef * S/K - coefsig * vol * t^0.5)
 * @dev Coefficient and intercept of linear equation is determined by S/k(and alpha - beta * vol * t^0.5)
 * @dev spread = 0.3 * v / 2
 **/
function _caluculateZ(
        uint256 coef,
        uint256 coefsig,
        uint256 intercept,
        uint256 ratio,
        uint256 sigTime
    ) private pure returns (uint256) {
        uint256 z = intercept.sub(ratio.mulByRate(coef)).sub(
            sigTime.mulByRate(coefsig)
        );
        if (z <= 2 * DECIMAL) {
            return DECIMAL;
        } else if (z >= DECIMAL.mul(100)) {
            return DECIMAL * 50;
        }
        return z.div(2);
    }
// Solidity 0.6.6
/**
 * @notice Calculate square root of uint
 **/
function _sqrt(uint256 x) private pure returns (uint256 y) {
        uint256 z = (x + 1) / 2;
        y = x;
        while (z < y) {
            y = z;
            z = (x / z + z) / 2;
        }
    }
// Solidity 0.7.4
/**
 * @dev See {IWOWSERC1155-getNextMintableTokenId}.
 */
function getNextMintableTokenId(uint8 level, uint8 cardId)
    external
    view
    override
    returns (bool, uint256)
  {
    uint16 levelCard = ((uint16(level) << 8) | cardId);
    uint256 tokenId = uint32(levelCard) << 16;
    uint256 tokenIdEnd = tokenId + _wowsLevelCap[level];

    for (; tokenId < tokenIdEnd; ++tokenId)
      if (!_tokenInfos[tokenId].minted) return (true, tokenId);
    return (false, uint256(-1));
  }
// Solidity 0.7.4
/**
 * @dev See {IWOWSERC1155-setURI}.
 */
function setURI(uint256 tokenId, string memory _uri) public override {
    require(
      hasRole((tokenId == 0) ? DEFAULT_ADMIN_ROLE : MINTER_ROLE, _msgSender()),
      'Access denied'
    );
    require(tokenId == 0 || tokenId > 0xFFFFFFFF, 'invalid tokenId');

    if (tokenId == 0) _setURI(_uri);
    else _customCards[tokenId].uri = _uri;
  }
// Solidity 0.7.4
/**
 * @dev See {IERC1155-setApprovalForAll}.
 */
function setApprovalForAll(address operator, bool approved)
    public
    virtual
    override
  {
    // Prevent auctions like OpenSea from selling this token. Selling by third
    // parties is only allowed for cryptofolios which are locked in one of our
    // TradeFloor contracts.
    require(hasRole(OPERATOR_ROLE, operator), 'Only Operators');

    super.setApprovalForAll(operator, approved);
  }
// Solidity 0.7.4
/**
 * @dev See {IERC1155MetadataURI-uri}.
 *
 * For custom tokens the URI is thought to be a full URL without
 * placeholders. For our WOWS token a tokenid placeholder is expected, and
 * the id is of the metadata is tokenId >> 16 because 16Bit tken share the
 * same metadata / image.
 */
function uri(uint256 tokenId)
    public
    view
    virtual
    override(ERC1155)
    returns (string memory)
  {
    if (tokenId > 0xFFFFFFFF)
      // Custom token
      return
        bytes(_customCards[tokenId].uri).length == 0
          ? _customDefaultUri
          : _customCards[tokenId].uri;

    // WOWS token
    return
      string(
        abi.encodePacked(
          super.uri(0),
          HEX[(tokenId >> 28) & 0xF],
          HEX[(tokenId >> 24) & 0xF],
          HEX[(tokenId >> 20) & 0xF],
          HEX[(tokenId >> 16) & 0xF],
          '.json'
        )
      );
  }
// Solidity 0.7.4
/**
 * @dev Return information about a wows card
 *
 * @param levels The levels of the card to query
 * @param cardIds A list of card ids to query
 *
 * @return capMintedPair Array of 16 Bit, cap,minted,...
 */
function getCardDataBatch(uint8[] memory levels, uint8[] memory cardIds)
    external
    view
    returns (uint16[] memory capMintedPair)
  {
    require(levels.length == cardIds.length, 'Length mismatch');
    uint16[] memory result = new uint16[](cardIds.length * 2);
    for (uint256 i = 0; i < cardIds.length; ++i) {
      result[i * 2] = _wowsLevelCap[levels[i]];
      result[i * 2 + 1] = _wowsCardsMinted[
        (uint16(levels[i]) << 8) | cardIds[i]
      ];
    }
    return result;
  }
// Solidity 0.7.4
/**
 * @dev Return list of tokenIds owned by `account`
 */
function getTokenIds(address account)
    external
    view
    returns (uint256[] memory)
  {
    Owned storage list = _owned[account];
    uint256[] memory result = new uint256[](list.count);
    ListKey storage key = list.listKey;
    for (uint256 i = 0; i < list.count; ++i) {
      result[i] = key.index;
      key = _tokenInfos[key.index].listKey;
    }
    return result;
  }
// Solidity 0.7.4
/**
 * @dev Set the cap of a specific WOWS level
 *
 * Note that this function can be used to add a new card.
 */
function setWowsLevelCaps(uint8[] memory levels, uint16[] memory newCaps)
    public
  {
    require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'Only admin');
    require(levels.length == newCaps.length, "Lengths don't match");

    for (uint256 i = 0; i < levels.length; ++i) {
      require(_wowsLevelCap[levels[i]] < newCaps[i], 'Decrement forbidden');
      _wowsLevelCap[levels[i]] = newCaps[i];
    }
  }
// Solidity 0.7.4
/**
 * @dev Ownership change -> update linked list owner -> tokenId
 *
 * linkKeys are 1 based where tokenIds are 0-based.
 */
function _relinkOwner(
    address from,
    address to,
    uint256 tokenId
  ) internal {
    TokenInfo storage tokenInfo = _tokenInfos[tokenId];

    // Remove tokenId from List
    if (from != address(0)) {
      Owned storage fromList = _owned[from];
      require(fromList.count > 0, 'Count mismatch');
      ListKey storage key = fromList.listKey;
      uint256 count = fromList.count;

      // Search the token which links to tokenId
      for (; count > 0 && key.index != tokenId; --count)
        key = _tokenInfos[key.index].listKey;
      require(key.index == tokenId, 'Key mismatch');

      // Unlink prev -> tokenId
      key.index = tokenInfo.listKey.index;
      // Unlink tokenId -> next
      tokenInfo.listKey.index = 0;
      // Decrement count
      fromList.count--;
    }

    if (to != address(0)) {
      Owned storage toList = _owned[to];
      tokenInfo.listKey.index = toList.listKey.index;
      toList.listKey.index = tokenId;
      toList.count++;
    }
  }
// Solidity 0.4.24
// transfer locked balance to an address
function transferLockedBalance(uint _category, address _to, uint _value) public onlyOwner returns (bool success) {
        require(balances[msg.sender] >= _value && _value > 0);
        lockedAddresses[_category].push(_to);
        balances[msg.sender] -= _value;
        timeLockedBalances[_category][_to] += _value;
        emit Transfer(msg.sender, _to, _value);
        return true;
    }
// Solidity 0.4.24
// unlock category of locked address
function unlockBalance(uint _category) public onlyOwner returns (bool success) {
        uint _length = lockedAddresses[_category].length;
        address _addr;
        uint _value = 0;
        for(uint i = 0; i< _length; i++) {
            _addr = lockedAddresses[_category][i];
            _value = timeLockedBalances[_category][_addr];
            balances[_addr] += _value;
            timeLockedBalances[_category][_addr] = 0;
        }
        delete lockedAddresses[_category];
        return true;
    }
// Solidity 0.6.5
// solium-disable-next-line security/no-assign-params
function uint2str(uint256 _i) internal pure returns (string memory) {
        if (_i == 0) {
            return "0";
        }
        uint256 j = _i;
        uint256 len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bstr = new bytes(len);
        uint256 k = len - 1;
        while (_i != 0) {
            bstr[k--] = bytes1(uint8(48 + (_i % 10)));
            _i /= 10;
        }
        return string(bstr);
    }
// Solidity 0.4.24
// Defining a constructor 
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
        require(_to != address(0));
        require(_value <= balances[_from]);
        require(_value <= allowed[_from][msg.sender]);
    
        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
        
        emit Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.6.5
/// @notice Check if a purchase message is valid
/// @param buyer The address paying for the purchase & receiving tokens
/// @param catalystIds The catalyst IDs to be purchased
/// @param catalystQuantities The quantities of the catalysts to be purchased
/// @param gemIds The gem IDs to be purchased
/// @param gemQuantities The quantities of the gems to be purchased
/// @param nonce The current nonce for the user. This is represented as a
/// uint256 value, but is actually 2 packed uint128's (queueId + nonce)
/// @param signature A signed message specifying tx details
/// @return True if the purchase is valid
function isPurchaseValid(
        address buyer,
        uint256[] memory catalystIds,
        uint256[] memory catalystQuantities,
        uint256[] memory gemIds,
        uint256[] memory gemQuantities,
        uint256 nonce,
        bytes memory signature
    ) public returns (bool) {
        require(_checkAndUpdateNonce(buyer, nonce), "INVALID_NONCE");
        require(_validateGemAmounts(catalystIds, catalystQuantities, gemQuantities), "INVALID_GEMS");
        bytes32 hashedData = keccak256(abi.encodePacked(catalystIds, catalystQuantities, gemIds, gemQuantities, buyer, nonce));

        address signer = SigUtil.recover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hashedData)), signature);
        return signer == _signingWallet;
    }
// Solidity 0.6.5
/// @dev Function for validating the nonce for a user.
/// @param _buyer The address for which we want to check the nonce
/// @param _packedValue The queueId + nonce, packed together.
/// EG: for queueId=42 nonce=7, pass: "0x0000000000000000000000000000002A00000000000000000000000000000007"
function _checkAndUpdateNonce(address _buyer, uint256 _packedValue) private returns (bool) {
        uint128 queueId = uint128(_packedValue / 2**128);
        uint128 nonce = uint128(_packedValue % 2**128);
        uint128 currentNonce = queuedNonces[_buyer][queueId];
        if (nonce == currentNonce) {
            queuedNonces[_buyer][queueId] = currentNonce + 1;
            return true;
        }
        return false;
    }
// Solidity 0.6.5
/// @dev Function to ensure the gem amounts requested are valid.
/// @param catalystIds An array of Ids. Order cannot be assumed to be consistent.
/// @param catalystQuantities The quantitiy of each catalyst Id
/// @param gemQuantities The quantitiy of each type of gem.
/// @return bool - whether or not gem amounts are valid
function _validateGemAmounts(
        uint256[] memory catalystIds,
        uint256[] memory catalystQuantities,
        uint256[] memory gemQuantities
    ) private returns (bool) {
        uint256 maxGemsAllowed;
        uint256 requestedGems;
        for (uint256 i = 0; i < catalystQuantities.length; i++) {
            require(catalystIds[i] < 4, "ID_OUT_OF_BOUNDS");
            maxGemsAllowed += catalystQuantities[i] * (catalystIds[i] + 1);
        }
        for (uint256 i = 0; i < gemQuantities.length; i++) {
            requestedGems += gemQuantities[i];
        }
        return (requestedGems <= maxGemsAllowed);
    }
// Solidity 0.6.5
/// @notice Transfer `amount` tokens from `from` to `to`.
/// @param from whose token it is transferring from.
/// @param to the recipient address of the tokens transfered.
/// @param amount the number of tokens transfered.
/// @return success true if success.
function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external override returns (bool success) {
        if (msg.sender != from && !_superOperators[msg.sender]) {
            uint256 currentAllowance = _allowances[from][msg.sender];
            if (currentAllowance != ~uint256(0)) {
                // save gas when allowance is maximal by not reducing it (see https://github.com/ethereum/EIPs/issues/717)
                require(currentAllowance >= amount, "NOT_AUTHOIZED_ALLOWANCE");
                _allowances[from][msg.sender] = currentAllowance - amount;
            }
        }
        _transfer(from, to, amount);
        return true;
    }
// Solidity 0.6.5
/// @notice burn `amount` tokens from `owner`.
/// @param from address whose token is to burn.
/// @param amount the number of token to burn.
function burnFor(address from, uint256 amount) external override {
        if (msg.sender != from && !_superOperators[msg.sender]) {
            uint256 currentAllowance = _allowances[from][msg.sender];
            if (currentAllowance != ~uint256(0)) {
                require(currentAllowance >= amount, "NOT_AUTHOIZED_ALLOWANCE");
                _allowances[from][msg.sender] = currentAllowance - amount;
            }
        }
        _burn(from, amount);
    }
// Solidity 0.8.2
// End Getter
// Business Logic
function adminMint() external onlyAdmin {
        uint _amount = accounts[msg.sender].nftsReserved;
        require(accounts[msg.sender].isAdmin == true,"Sorry, Only an admin can mint");
        require(_amount > 0, 'Need to have reserved supply');
        require(totalSupply() + _amount <= MAX_PHC, "You would exceed the mint limit");

        accounts[msg.sender].nftsReserved -= _amount;
        _reserved = _reserved - _amount;


        for (uint i = 0; i < _amount; i++) {
            id++;
            _safeMint(msg.sender, id);
            emit Mint(msg.sender, totalSupply());
        }
    }
// Solidity 0.4.16
// transfer to and lock it
function transferAndLock(address _to, uint256 _value, uint _releaseTime) public returns (bool success) {
        require(_to != 0x0);
        require(_value <= balances[msg.sender]);
        require(_value > 0);
        require(_releaseTime > now && _releaseTime <= now + 60*60*24*365*5);

        // SafeMath.sub will throw if there is not enough balance.
        balances[msg.sender] = balances[msg.sender].sub(_value);
       
        //if preLock can release 
        uint preRelease = timeRelease[_to];
        if (preRelease <= now && preRelease != 0x0) {
            balances[_to] = balances[_to].add(lockedBalance[_to]);
            lockedBalance[_to] = 0;
        }

        lockedBalance[_to] = lockedBalance[_to].add(_value);
        timeRelease[_to] =  _releaseTime >= timeRelease[_to] ? _releaseTime : timeRelease[_to]; 
        Transfer(msg.sender, _to, _value);
        Lock(_to, _value, _releaseTime);
        return true;
    }
// Solidity 0.4.16
/**
 * @notice Transfers tokens held by lock.
 */
function unlock() public constant returns (bool success){
        uint256 amount = lockedBalance[msg.sender];
        require(amount > 0);
        require(now >= timeRelease[msg.sender]);

        balances[msg.sender] = balances[msg.sender].add(amount);
        lockedBalance[msg.sender] = 0;
        timeRelease[msg.sender] = 0;

        Transfer(0x0, msg.sender, amount);
        UnLock(msg.sender, amount);

        return true;

    }
// Solidity 0.4.16
/**
 * reward rate for purchase
 */
function rewardRate() internal constant returns (uint256) {
            
            uint256 rate = baseExchangeRate;

            if (now < startTime) {
                rate = vcExchangeRate;
            } else {
                uint crowdIndex = (now - startTime) / (24 * 60 * 60); 
                if (crowdIndex < DaysForEarlyDay) {
                    rate = earlyExchangeRate;
                } else {
                    rate = baseExchangeRate;
                }

                //vip
                if (msg.value >= vipThrehold) {
                    rate = vipExchangeRate;
                }
            }
            return rate - baseExchangeRate;
        
      }
// Solidity 0.8.4
// Withdraw BEP20 tokens sent to this contract
// NOTE: This function is to be called if and only if BEP20 tokens gets sent into this contract. 
// On no other occurence should this function be called. 
function withdrawTokens(address token, address recipient) external onlyOwner {
        require(token != address(0), 'Invalid Token!');
        require(recipient != address(0), 'Invalid Recipient!');

        uint256 balance = IBEP20(token).balanceOf(address(this));
        if (balance > 0) {
            require(IBEP20(token).transfer(recipient, balance), "Transfer Failed");
        }
    }