lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.7.4
/**
 * @dev funtion to forcibly remove a users position.  This is required due to the fact that
 * the basis points and scales used to calculate user DPY will be constantly changing.  We 
 * will need to forceibly remove positions of lazy (or malicious) users who will try to take 
 * advantage of DPY being lowered instead of raised and maintining thier current return levels.
 */
function forcePositionRemoval(uint256 _pid, address _account) public {
        require(hasRole(_REMOVAL, msg.sender));
        LiquidityProviders storage p = provider[_pid][_account];
        PoolInfo storage pool = poolInfo[_pid];
        uint256 _lpTokenAmount = p.LockedAmount;
        pool.ContractAddress.safeTransfer(_account, _lpTokenAmount);
        uint256 _newLpTokenAmount = p.LockedAmount.sub(_lpTokenAmount);
        uint yield = calculateUserDailyYield(_pid);
        fundamenta.mintTo(msg.sender, yield);
        provider[_pid][_account] = LiquidityProviders (
            _account, 
            0, 
            _newLpTokenAmount, 
            0, 
            0,
            p.TotalRewardsPaid.add(yield)
        );
        pool.TotalRewardsPaidByPool = pool.TotalRewardsPaidByPool.add(yield);
        pool.TotalLPTokensLocked = pool.TotalLPTokensLocked.sub(_lpTokenAmount);
    
    }
// Solidity 0.5.17
/**
 * @notice Create a new role.
 * @param _roleDescription The description of the role created.
 * @param _admin The role that is allowed to add and remove
 * bearers from the role being created.
 * @return The role id.
 */
function addRole(string memory _roleDescription, uint256 _admin)
    public
    returns(uint256)
  {
    require(_admin <= roles.length, "Admin role doesn't exist.");
    uint256 role = roles.push(
      Role({
        description: _roleDescription,
        admin: _admin
      })
    ) - 1;
    emit RoleCreated(role);
    return role;
  }
// Solidity 0.5.11
// Used by Blockbid admin to calculate amount of BIDL to deposit in the contract.
function admin_getBidlAmountToDeposit() public view returns (uint256) {
        uint256 weiBalance = address(this).balance;
        uint256 bidlAmountSupposedToLock = weiBalance / _weiPerBidl;
        uint256 bidlBalance = _bidlToken.balanceOf(address(this));
        if (bidlAmountSupposedToLock < bidlBalance) {
            return 0;
        }
        return bidlAmountSupposedToLock - bidlBalance;
    }
// Solidity 0.5.11
// Process ETH coming from the pool participant address.
function () external payable {
        // Do not allow changing participant address after it has been set.
        if (_poolParticipant != address(0) && _poolParticipant != msg.sender) {
            revert();
        }

        // Do not allow top-ups if the contract had been activated.
        if (_activated) {
            revert();
        }
		
		uint256 weiBalance = address(this).balance;
		
		// Refund excessive ETH.
		if (weiBalance > _maxBalanceWei) {
		    uint256 excessiveWei = weiBalance.sub(_maxBalanceWei);
		    msg.sender.transfer(excessiveWei);
		    weiBalance = _maxBalanceWei;
		}
		
		if (_poolParticipant != msg.sender) 
		    _poolParticipant = msg.sender;
    }
// Solidity 0.5.17
/**
 * @notice A method to remove a bearer from a role
 * @param _account The account to remove as a bearer.
 * @param _role The role to remove the bearer from.
 */
function removeBearer(address _account, uint256 _role)
    external
  {
    require(
      _role < roles.length,
      "Role doesn't exist."
    );
    require(
      hasRole(msg.sender, roles[_role].admin),
      "User can't remove bearers."
    );
    require(
      hasRole(_account, _role),
      "Account is not bearer of role."
    );

    delete roles[_role].bearers[_account];
    emit BearerRemoved(_account, _role);
  }
// Solidity 0.5.10
/**
 * @notice Create a new escrow
 * @param _offerId Offer
 * @param _tokenAmount Amount buyer is willing to trade
 * @param _fiatAmount Indicates how much FIAT will the user pay for the tokenAmount
 * @param _contactData Contact Data   ContactType:UserId
 * @param _location The location on earth
 * @param _username The username of the user
 */
function createEscrow(
    uint _offerId,
    uint _tokenAmount,
    uint _fiatAmount,
    string memory _contactData,
    string memory _location,
    string memory _username
  ) public returns (uint escrowId) {
    address sender = getSender();
    lastActivity[sender] = block.timestamp;
    escrowId = escrow.createEscrow_relayed(
         address(uint160(sender)),
         _offerId,
         _tokenAmount,
         _fiatAmount,
         _contactData,
         _location,
         _username
    );
  }
// Solidity 0.5.10
/**
 * @notice Function returning if we accept or not the relayed call (do we pay or not for the gas)
 * @param from Address of the buyer getting a free transaction
 * @param encodedFunction Function that will be called on the Escrow contract
 * @param gasPrice Gas price
 * @dev relay and transaction_fee are useless in our relay workflow
 */
function acceptRelayedCall(
    address /* relay */,
    address from,
    bytes calldata encodedFunction,
    uint256 /* transactionFee */,
    uint256 gasPrice,
    uint256 /* gasLimit */,
    uint256 /* nonce */,
    bytes calldata /* approvalData */,
    uint256 /* maxPossibleCharge */
  ) external view returns (uint256, bytes memory)
  {
    bytes memory abiEncodedFunc = encodedFunction; // Call data elements cannot be accessed directly
    bytes4 fSign;
    uint dataValue;

    assembly {
      fSign := mload(add(abiEncodedFunc, add(0x20, 0)))
      dataValue := mload(add(abiEncodedFunc, 36))
    }

    return (_evaluateConditionsToRelay(from, gasPrice, fSign, dataValue), "");
  }
// Solidity 0.5.10
/**
 * @dev Evaluates if the sender conditions are valid for relaying a escrow transaction
 * @param from Sender
 * @param gasPrice Gas Price
 * @param functionSignature Function Signature
 * @param dataValue Represents the escrowId or offerId depending on the function being called
 */
function _evaluateConditionsToRelay(address from, uint gasPrice, bytes4 functionSignature, uint dataValue) internal view returns (uint256) {
    address token;

    if(functionSignature == RATE_SIGNATURE && gasPrice < 20000000000){
      return OK;
    }

    if(from.balance > 600000 * gasPrice) return ERROR_ENOUGH_BALANCE;

    if(gasPrice > 20000000000) return ERROR_GAS_PRICE; // 20Gwei

    if(functionSignature == PAY_SIGNATURE || functionSignature == CANCEL_SIGNATURE || functionSignature == OPEN_CASE_SIGNATURE){
      address payable buyer;
      
      (buyer, , token, ) = escrow.getBasicTradeData(dataValue);

      if(buyer != from) return ERROR_INVALID_BUYER;
      if(token != snt && token != address(0)) return ERROR_INVALID_ASSET;

      if(functionSignature == CANCEL_SIGNATURE){ // Allow activity after 15min have passed
        if((lastActivity[from] + 15 minutes) > block.timestamp) return ERROR_TRX_TOO_SOON;
      }

      return OK;
    } else if(functionSignature == CREATE_SIGNATURE) {
      token = metadataStore.getAsset(dataValue);

      if(token != snt && token != address(0)) return ERROR_INVALID_ASSET;

      // Allow activity after 15 min have passed
      if((lastActivity[from] + 15 minutes) > block.timestamp) return ERROR_TRX_TOO_SOON;

      return OK;
    }

    return ERROR;
  }
// Solidity 0.8.7
// Write (n - 1) as 2^s * d
function getValues(uint256 n) public  pure returns (uint256[2] memory) {
        uint256 s = 0;
        uint256 d = n - 1;
        while (d % 2 == 0) {
            d = d / 2;
            s++;
        }
        uint256[2] memory ret;
        ret[0] = s;
        ret[1] = d;
        return ret;
    }
// Solidity 0.4.21
/**
 * @dev Approves another address to transfer the given token ID
 * @dev The zero address indicates there is no approved address.
 * @dev There can only be one approved address per token at a given time.
 * @dev Can only be called by the token owner or an approved operator.
 * @param _to address to be approved for the given token ID
 * @param _tokenId uint256 ID of the token to be approved
 */
function approve(address _to, uint256 _tokenId) public {
        address owner = ownerOf(_tokenId);
        require(_to != owner);
        require(msg.sender == owner || isApprovedForAll(owner, msg.sender));

        if (getApproved(_tokenId) != address(0) || _to != address(0)) {
            tokenApprovals[_tokenId] = _to;
            emit Approval(owner, _to, _tokenId);
        }
    }
// Solidity 0.4.21
/**
 * @dev Appends uint (in decimal) to a string
 * @param _str The prefix string
 * @param _value The uint to append
 * @return resulting string
 */
function _appendUintToString(string _str, uint _value) internal pure returns (string) {
        uint maxLength = 100;
        bytes memory reversed = new bytes(maxLength);
        uint i = 0;
        while (_value != 0) {
            uint remainder = _value % 10;
            _value = _value / 10;
            reversed[i++] = byte(48 + remainder);
        }
        i--;

        bytes memory inStrB = bytes(_str);
        bytes memory s = new bytes(inStrB.length + i + 1);
        uint j;
        for (j = 0; j < inStrB.length; j++) {
            s[j] = inStrB[j];
        }
        for (j = 0; j <= i; j++) {
            s[j + inStrB.length] = reversed[i - j];
        }
        return string(s);
    }
// Solidity 0.4.21
/**
 * @dev Internal function to remove a token ID from the list of a given address
 * @param _from address representing the previous owner of the given token ID
 * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
 */
function removeTokenFrom(address _from, uint256 _tokenId) internal {
        super.removeTokenFrom(_from, _tokenId);

        uint256 tokenIndex = ownedTokensIndex[_tokenId];
        uint256 lastTokenIndex = ownedTokens[_from].length.sub(1);
        uint256 lastToken = ownedTokens[_from][lastTokenIndex];

        ownedTokens[_from][tokenIndex] = lastToken;
        ownedTokens[_from][lastTokenIndex] = 0;
        // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
        // be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
        // the lastToken to the first position, and then dropping the element placed in the last position of the list

        ownedTokens[_from].length--;
        ownedTokensIndex[_tokenId] = 0;
        ownedTokensIndex[lastToken] = tokenIndex;

        // If a hero is removed from its owner, it no longer can be their active hero
        if (activeHero[_from] == _tokenId) {
            activeHero[_from] = 0;
            emit ActiveHeroChanged(_from, 0);
        }
    }
// Solidity 0.4.21
/**
 * @dev Internal function to burn a specific token
 * @dev Reverts if the token does not exist
 * @param _owner owner of the token to burn
 * @param _tokenId uint256 ID of the token being burned by the msg.sender
 */
function _burn(address _owner, uint256 _tokenId) internal {
        clearApproval(_owner, _tokenId);
        removeTokenFrom(_owner, _tokenId);
        emit Transfer(_owner, address(0), _tokenId);

        // Reorg all tokens array
        uint256 tokenIndex = allTokensIndex[_tokenId];
        uint256 lastTokenIndex = allTokens.length.sub(1);
        uint256 lastToken = allTokens[lastTokenIndex];

        allTokens[tokenIndex] = lastToken;
        allTokens[lastTokenIndex] = 0;

        allTokens.length--;
        allTokensIndex[_tokenId] = 0;
        allTokensIndex[lastToken] = tokenIndex;

        // Clear genome data
        if (genome[_tokenId] != 0) {
            genome[_tokenId] = 0;
        }
    }
// Solidity 0.4.21
/**
 * @dev Allows setting hero data for a hero
 * @param _tokenId hero to set data for
 * @param _fieldA data to set
 * @param _fieldB data to set
 * @param _fieldC data to set
 * @param _fieldD data to set
 * @param _fieldE data to set
 * @param _fieldF data to set
 * @param _fieldG data to set
 */
function setHeroData(
        uint256 _tokenId,
        uint16 _fieldA,
        uint16 _fieldB,
        uint32 _fieldC,
        uint32 _fieldD,
        uint32 _fieldE,
        uint64 _fieldF,
        uint64 _fieldG
    ) external onlyLogicContract {
        heroData[_tokenId] = HeroData(
            _fieldA,
            _fieldB,
            _fieldC,
            _fieldD,
            _fieldE,
            _fieldF,
            _fieldG
        );
    }
// Solidity 0.4.24
/**
 * @dev Release one of the payee's proportional payment.
 * @param account Whose payments will be released.
 */
function release(address account) public {
    require(_shares[account] > 0);

    uint256 totalReceived = address(this).balance.add(_totalReleased);
    uint256 payment = totalReceived.mul(
      _shares[account]).div(
        _totalShares).sub(
          _released[account]
    );

    require(payment != 0);

    _released[account] = _released[account].add(payment);
    _totalReleased = _totalReleased.add(payment);

    account.transfer(payment);
    emit PaymentReleased(account, payment);
  }
// Solidity 0.4.23
// transfer _value tokens to _to from msg.sender
function transfer(address _to, uint256 _value) public returns (bool) {
	    // if you want to destroy tokens, use burn replace transfer to address 0
		require(_to != address(0));
		// can not transfer to self
		require(_to != msg.sender);
		require(_value <= balances[msg.sender]);

		// SafeMath.sub will throw if there is not enough balance.
		balances[msg.sender] = balances[msg.sender].sub(_value);
		balances[_to] = balances[_to].add(_value);
		emit Transfer(msg.sender, _to, _value);
		return true;
	}
// Solidity 0.4.23
// decrease approval to _spender
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
		uint oldValue = allowed[msg.sender][_spender];
		if (_subtractedValue > oldValue) {
			allowed[msg.sender][_spender] = 0;
		} else {
			allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
		}
		emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
		return true;
	}
// Solidity 0.4.24
/**
 * @dev Mints a new NFT.
 * @notice This is an internal function which should be called from user-implemented external
 * mint function. Its purpose is to show and properly initialize data structures when using this
 * implementation.
 * @param _to The address that will own the minted NFT.
 */
function _mint(address _to, uint seed) internal returns (string) {
        require(_to != address(0));
        require(numTokens < TOKEN_LIMIT);
        uint amount = 0;
        if (numTokens >= ARTIST_PRINTS) {
            amount = PRICE;
            require(msg.value >= amount);
        }
        require(seedToId[seed] == 0);
        uint id = numTokens + 1;

        idToCreator[id] = _to;
        idToSeed[id] = seed;
        seedToId[seed] = id;
        uint a = uint(uint160(keccak256(abi.encodePacked(seed))));
        idToSymbolScheme[id] = getScheme(a);
        string memory uri = draw(id);
        emit Generated(id, _to, uri);

        numTokens = numTokens + 1;
        _addNFToken(_to, id);

        if (msg.value > amount) {
            msg.sender.transfer(msg.value - amount);
        }
        if (amount > 0) {
            BENEFICIARY.transfer(amount);
        }

        emit Transfer(address(0), _to, id);
        return uri;
    }
// Solidity 0.6.4
// Internal transfer function which includes the Fee
function _transfer(address _from, address _to, uint _value) private {
        require(_balances[_from] >= _value, 'Must not send more than balance');
        require(_balances[_to] + _value >= _balances[_to], 'Balance overflow');
        if(!mapHolder[_to]){holderArray.push(_to); holders+=1; mapHolder[_to]=true;}
        _balances[_from] =_balances[_from].sub(_value);
        uint _fee = _getFee(_from, _to, _value);                                            // Get fee amount
        _balances[_to] += (_value.sub(_fee));                                               // Add to receiver
        _balances[address(this)] += _fee;                                                   // Add fee to self
        totalFees += _fee;                                                                  // Track fees collected
        emit Transfer(_from, _to, (_value.sub(_fee)));                                      // Transfer event
        if (!mapAddress_Excluded[_from] && !mapAddress_Excluded[_to]) {
            emit Transfer(_from, address(this), _fee);                                      // Fee Transfer event
        }
    }
// Solidity 0.6.4
// Calculate Fee amount
function _getFee(address _from, address _to, uint _value) private view returns (uint) {
        if (mapAddress_Excluded[_from] || mapAddress_Excluded[_to]) {
           return 0;                                                                        // No fee if excluded
        } else {
            return (_value / 1000);                                                         // Fee amount = 0.1%
        }
    }
// Solidity 0.6.12
/**
 * @dev Same as {_get}, with a custom error message when `key` is not in the map.
 */
function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) {
        uint256 keyIndex = map._indexes[key];
        require(keyIndex != 0, errorMessage); // Equivalent to contains(map, key)
        return map._entries[keyIndex - 1]._value; // All indexes are 1-based
    }
// Solidity 0.6.4
// Allow to query for remaining upgrade amount
function getRemainingAmount() public view returns (uint amount){
        uint maxEmissions = (upgradeHeight-1) * mapEra_Emission[1];                         // Max Emission on Old Contract
        uint maxUpgradeAmount = (maxEmissions).sub(VETH(vether2).totalFees());              // Minus any collected fees
        if(maxUpgradeAmount >= upgradedAmount){
            return maxUpgradeAmount.sub(upgradedAmount);                                    // Return remaining
        } else {
            return 0;                                                                       // Return 0
        }
    }
// Solidity 0.6.4
// V1 upgrades by calling V2 snapshot
function upgradeV1() public {
        uint amount = ERC20(vether1).balanceOf(msg.sender);                                 // Get Balance Vether1
        if(amount > 0){
            if(VETH(vether2).mapPreviousOwnership(msg.sender) < amount){
                amount = VETH(vether2).mapPreviousOwnership(msg.sender);                    // Upgrade as much as possible
            } 
            uint remainingAmount = getRemainingAmount();
            if(remainingAmount < amount){amount = remainingAmount;}                         // Handle final amount
            upgradedAmount += amount; 
            mapPreviousOwnership[msg.sender] = mapPreviousOwnership[msg.sender].sub(amount);    // Update mappings
            ERC20(vether1).transferFrom(msg.sender, burnAddress, amount);                   // Must collect & burn tokens
            _transfer(address(this), msg.sender, amount);                                   // Send to owner
        }
    }
// Solidity 0.6.4
// V2 upgrades by calling V3 internal snapshot
function upgradeV2() public {
        uint amount = ERC20(vether2).balanceOf(msg.sender);                                 // Get Balance Vether2
        if(amount > 0){
            if(mapPreviousOwnership[msg.sender] < amount){
                amount = mapPreviousOwnership[msg.sender];                                  // Upgrade as much as possible
            } 
            uint remainingAmount = getRemainingAmount();
            if(remainingAmount < amount){amount = remainingAmount;}                         // Handle final amount
            upgradedAmount += amount; 
            mapPreviousOwnership[msg.sender] = mapPreviousOwnership[msg.sender].sub(amount);    // Update mappings
            ERC20(vether2).transferFrom(msg.sender, burnAddress, amount);                   // Must collect & burn tokens
            _transfer(address(this), msg.sender, amount);                                   // Send to owner
        }
    }
// Solidity 0.6.4
// Internal - Records burn
function _recordBurn(address _payer, address _member, uint _era, uint _day, uint _eth) private {
        require(VETH(vether1).currentDay() >= upgradeHeight || VETH(vether1).currentEra() > 1); // Prohibit until upgrade height
        if (mapEraDay_MemberUnits[_era][_day][_member] == 0){                               // If hasn't contributed to this Day yet
            mapMemberEra_Days[_member][_era].push(_day);                                    // Add it
            mapEraDay_MemberCount[_era][_day] += 1;                                         // Count member
            mapEraDay_Members[_era][_day].push(_member);                                    // Add member
        }
        mapEraDay_MemberUnits[_era][_day][_member] += _eth;                                 // Add member's share
        mapEraDay_UnitsRemaining[_era][_day] += _eth;                                       // Add to total historicals
        mapEraDay_Units[_era][_day] += _eth;                                                // Add to total outstanding
        totalBurnt += _eth;                                                                 // Add to total burnt
        emit Burn(_payer, _member, _era, _day, _eth, mapEraDay_Units[_era][_day]);          // Burn event
        _updateEmission();                                                                  // Update emission Schedule
    }
// Solidity 0.6.4
// Allows changing an excluded address
function changeExcluded(address excluded) external {    
        if(!mapAddress_Excluded[excluded]){
            _transfer(msg.sender, address(this), mapEra_Emission[1]/16);                    // Pay fee of 128 Vether
            mapAddress_Excluded[excluded] = true;                                           // Add desired address
            totalFees += mapEra_Emission[1]/16;
        } else {
            _transfer(msg.sender, address(this), mapEra_Emission[1]/32);                    // Pay fee of 64 Vether
            mapAddress_Excluded[excluded] = false;                                          // Change desired address
            totalFees += mapEra_Emission[1]/32;
        }               
    }
// Solidity 0.6.4
// Internal - withdraw function
function _withdrawShare (uint _era, uint _day, address _member) private returns (uint value) {
        _updateEmission(); 
        if (_era < currentEra) {                                                            // Allow if in previous Era
            value = _processWithdrawal(_era, _day, _member);                                // Process Withdrawal
        } else if (_era == currentEra) {                                                    // Handle if in current Era
            if (_day < currentDay) {                                                        // Allow only if in previous Day
                value = _processWithdrawal(_era, _day, _member);                            // Process Withdrawal
            }
        }  
        return value;
    }