lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.25
/**
 * @dev Withdraw pledge behavior.
 * @param _maker borrower address.
 */
function withdrawToken(address _maker) public onlyOwner {
    require(status != StatusChoices.PLEDGE_REFUND);
    uint256 pledgeSum = 0;
    // there are two types of retractions.
    if (status == StatusChoices.NO_PLEDGE_INFO) {
      pledgeSum = classifySquareUp(_maker);
    } else {
      status = StatusChoices.PLEDGE_REFUND;
      require(PledgePoolBase(tokenPoolAddress).withdrawToken(pledgeId, maker, pledgeAccountSum));
      pledgeSum = pledgeAccountSum;
    }
    emit WithdrawToken(_maker, pledgeTokenName, pledgeSum);
  }
// Solidity 0.4.25
/**
 * @dev Executed in some extreme unforsee cases, to avoid eth locked.
 * @param _tokenName recycle token type.
 * @param _amount Number of eth to recycle.
 */
function recycle(string _tokenName, uint256 _amount) public onlyOwner {
    require(status != StatusChoices.NO_PLEDGE_INFO && _amount>0);
    if (_tokenName.stringCompare(TOKEN_ETH)) {
      require(address(this).balance >= _amount);
      owner.transfer(_amount);
    } else {
      address token = checkedToken(_tokenName);
      require(ERC20(token).balanceOf(address(this)) >= _amount);
      require(safeErc20Transfer(token,owner, _amount));
    }
  }
// Solidity 0.4.25
/**
 * @dev Create an order process management contract for the match and repayment business.
 * @param _loanTokenName expect loan token type.
 */
function createOrderContract(string _loanTokenName) internal {
    require(bytes(_loanTokenName).length > 0);
    status = StatusChoices.PLEDGE_CREATE_MATCHING;
    address loanToken20 = checkedToken(_loanTokenName);
    OrderManageContract newOrder = new OrderManageContract(_loanTokenName, loanToken20, maker);
    setPartner(address(newOrder));
    newOrder.setPartner(owner);
    // update contract public data.
    orderContract = newOrder;
    loanTokenName = _loanTokenName;
    emit CreateOrderContract(address(newOrder));
  }
// Solidity 0.4.25
/**
 * @dev classification withdraw.
 * @dev Execute without changing the current contract data state.
 * @param _maker borrower address.
 */
function classifySquareUp(address _maker) internal returns(uint256 sum) {
    if (pledgeTokenName.stringCompare(TOKEN_ETH)) {
      uint256 pledgeSum = verifyEthAccount[_maker];
      require(pledgeSum > 0 && address(this).balance >= pledgeSum);
      _maker.transfer(pledgeSum);
      verifyEthAccount[_maker] = 0;
      sum = pledgeSum;
    } else {
      uint256 balance = ERC20(token20).balanceOf(address(this));
      require(balance > 0);
      require(safeErc20Transfer(token20,_maker, balance));
      sum = balance;
    }
  }
// Solidity 0.4.25
/**
 * @dev Get current contract order status.
 * @return pledgeStatus state indicate.
 */
function getPledgeStatus() public view returns(string pledgeStatus) {
    if (status == StatusChoices.NO_PLEDGE_INFO) {
      pledgeStatus = "NO_PLEDGE_INFO";
    } else if (status == StatusChoices.PLEDGE_CREATE_MATCHING) {
      pledgeStatus = "PLEDGE_CREATE_MATCHING";
    } else {
      pledgeStatus = "PLEDGE_REFUND";
    }
  }
// Solidity 0.4.25
/**
 * @dev _preValidateAddRecord, Validation of an incoming AddRecord. Use require statemens to revert state when conditions are not met.
 * @param _payerAddress Address performing the pleadge.
 * @param _pledgeSum the value to pleadge.
 * @param _pledgeId pledge contract index number.
 * @param _tokenName pledge token name.
 */
function _preValidateAddRecord(address _payerAddress, uint256 _pledgeSum, uint256 _pledgeId, string _tokenName) view internal {
    require(_pledgeSum > 0 && _pledgeId > 0
      && _payerAddress != address(0)
      && bytes(_tokenName).length > 0
      && address(msg.sender).isContract()
      && PledgeContract(msg.sender).getPledgeId()==_pledgeId
    );
  }
// Solidity 0.4.25
/**
 * @dev _preValidateRefund, Validation of an incoming refund. Use require statemens to revert state when conditions are not met.
 * @param _pledgeId pledge contract index number.
 * @param _targetAddress transfer target address.
 * @param _returnSum return token sum.
 */
function _preValidateRefund(uint256 _returnSum, address _targetAddress, uint256 _pledgeId) view internal {
    require(_returnSum > 0 && _pledgeId > 0
      && _targetAddress != address(0)
      && address(msg.sender).isContract()
      && _returnSum <= escrows[_pledgeId].pledgeSum
      && PledgeContract(msg.sender).getPledgeId()==_pledgeId
    );
  }
// Solidity 0.4.25
/**
 * @dev _preValidateWithdraw, Withdraw initiated parameter validation.
 * @param _pledgeId pledge contract index number.
 * @param _maker borrower address.
 * @param _num withdraw token sum.
 */
function _preValidateWithdraw(address _maker, uint256 _num, uint256 _pledgeId) view internal {
    require(_num > 0 && _pledgeId > 0
       && _maker != address(0)
       && address(msg.sender).isContract()
       && _num <= escrows[_pledgeId].pledgeSum
       && PledgeContract(msg.sender).getPledgeId()==_pledgeId
    );
  }
// Solidity 0.8.0
/**
 * @dev Returns the sum of claimable AC from multiple gauges.
 */
function claimable(address _account, address[] memory _gauges) external view returns (uint256) {
        uint256 _total = 0;
        for (uint256 i = 0; i < _gauges.length; i++) {
            _total = _total.add(IGauge(_gauges[i]).claimable(_account));
        }

        return _total;
    }
// Solidity 0.4.24
/**
 * @dev Constructor for CurrentCrowdsale contract.
 * @dev Set the owner who can manage whitelist and token.
 * @param _maxcap The maxcap value.
 * @param _startPhase1 The phase1 ICO start time.
 * @param _startPhase2 The phase2 ICO start time.
 * @param _startPhase3 The phase3 ICO start time.
 * @param _endOfPhase3 The end time of ICO.
 * @param _withdrawalWallet The address to which raised funds will be withdrawn.
 * @param _rate exchange rate for ico.
 * @param _token address of token used for ico.
 * @param _whitelist address of whitelist contract used for ico.
 */
function CurrentCrowdsale(
        uint256 _maxcap,
        uint256 _startPhase1,
        uint256 _startPhase2,
        uint256 _startPhase3,
        uint256 _endOfPhase3,
        address _withdrawalWallet,
        uint256 _rate,
        CurrentToken _token,
        Whitelist _whitelist
    )  TokenRate(_rate) public
    {
        require(_withdrawalWallet != address(0));
        require(_token != address(0) && _whitelist != address(0));
        require(_startPhase1 >= now);
        require(_endOfPhase3 > _startPhase3);
        require(_maxcap > 0);

        token = _token;
        whitelist = _whitelist;

        startPhase1 = _startPhase1;
        startPhase2 = _startPhase2;
        startPhase3 = _startPhase3;
        endOfPhase3 = _endOfPhase3;

        withdrawalWallet = _withdrawalWallet;

        maxcap = _maxcap;
        tokensSoldTotal = HARDCAP_TOKENS_PRE_ICO;
        weiRaisedTotal = tokensSoldTotal.div(_rate.mul(2));

        pushModifier(RateModifier(200, startPhase1));
        pushModifier(RateModifier(150, startPhase2));
        pushModifier(RateModifier(100, startPhase3));
    }
// Solidity 0.4.24
/**
 * @dev Sell tokens during ICO with referral.
 */
function sellTokens(address referral) beforeReachingHardCap whenWhitelisted(msg.sender) whenNotPaused internal {
        require(isIco());
        require(msg.value > 0);

        uint256 weiAmount = msg.value;
        uint256 excessiveFunds = 0;

        uint256 plannedWeiTotal = weiRaisedIco.add(weiAmount);

        if (plannedWeiTotal > maxcap) {
            excessiveFunds = plannedWeiTotal.sub(maxcap);
            weiAmount = maxcap.sub(weiRaisedIco);
        }
        bool isReferred = referral != address(0);
        uint256 tokensForUser = _getTokenAmountForBuyer(weiAmount, isReferred);
        uint256 tokensForReferral = _getTokenAmountForReferral(weiAmount, isReferred);
        uint256 tokensAmount = tokensForUser.add(tokensForReferral);

        if (tokensAmount > tokensRemainingIco) {
            uint256 weiToAccept = _getWeiValueOfTokens(tokensRemainingIco, isReferred);
            tokensForReferral = _getTokenAmountForReferral(weiToAccept, isReferred);
            tokensForUser = tokensRemainingIco.sub(tokensForReferral);
            excessiveFunds = excessiveFunds.add(weiAmount.sub(weiToAccept));

            tokensAmount = tokensRemainingIco;
            weiAmount = weiToAccept;
        }

        tokensSoldIco = tokensSoldIco.add(tokensAmount);
        tokensSoldTotal = tokensSoldTotal.add(tokensAmount);
        tokensRemainingIco = tokensRemainingIco.sub(tokensAmount);

        weiRaisedIco = weiRaisedIco.add(weiAmount);
        weiRaisedTotal = weiRaisedTotal.add(weiAmount);

        token.transfer(msg.sender, tokensForUser);
        if (isReferred) {
            token.transfer(referral, tokensForReferral);
        }

        if (excessiveFunds > 0) {
            msg.sender.transfer(excessiveFunds);
        }

        withdrawalWallet.transfer(this.balance);
    }
// Solidity 0.4.18
/**
 * Receives Eth and issue tokens to the sender
 */
function () payable atStage(Stages.InProgress) {
        hasEnded();
        require(purchasingAllowed);
        if (msg.value == 0) { return; }
        uint256 weiAmount = msg.value;
        address investor = msg.sender;
        uint256 received = weiAmount.div(10e7);
        uint256 tokens = (received).mul(rate);

        if (msg.value >= 10 finney) {
            if (now <= startTimestamp.add(firstTimer)){
                uint256 firstBonusToken = (tokens.div(100)).mul(firstBonus);
                tokens = tokens.add(firstBonusToken);
            }
            
            if (startTimestamp.add(firstTimer) < now && 
            now <= startTimestamp.add(secondTimer)){
                uint256 secondBonusToken = (tokens.div(100)).mul(secondBonus);
                tokens = tokens.add(secondBonusToken);
            }
        }
        
        sendTokens(msg.sender, tokens);
        fuddToken.transfer(investor, tokens);
        totalSupplied = (totalSupplied).add(tokens);
            
        if (totalSupplied >= maxSupply) {
            purchasingAllowed = false;
            stage = Stages.Ended;
        }
    }
// Solidity 0.4.11
// helper function to input bytes via remix
// from https://ethereum.stackexchange.com/a/13658/16
function hexStrToBytes(string _hexString) constant returns (bytes) {
        //Check hex string is valid
        if (bytes(_hexString)[0]!='0' ||
            bytes(_hexString)[1]!='x' ||
            bytes(_hexString).length%2!=0 ||
            bytes(_hexString).length<4) {
                throw;
            }

        bytes memory bytes_array = new bytes((bytes(_hexString).length-2)/2);
        uint len = bytes(_hexString).length;
        
        for (uint i=2; i<len; i+=2) {
            uint tetrad1=16;
            uint tetrad2=16;

            //left digit
            if (uint(bytes(_hexString)[i])>=48 &&uint(bytes(_hexString)[i])<=57)
                tetrad1=uint(bytes(_hexString)[i])-48;

            //right digit
            if (uint(bytes(_hexString)[i+1])>=48 &&uint(bytes(_hexString)[i+1])<=57)
                tetrad2=uint(bytes(_hexString)[i+1])-48;

            //left A->F
            if (uint(bytes(_hexString)[i])>=65 &&uint(bytes(_hexString)[i])<=70)
                tetrad1=uint(bytes(_hexString)[i])-65+10;

            //right A->F
            if (uint(bytes(_hexString)[i+1])>=65 &&uint(bytes(_hexString)[i+1])<=70)
                tetrad2=uint(bytes(_hexString)[i+1])-65+10;

            //left a->f
            if (uint(bytes(_hexString)[i])>=97 &&uint(bytes(_hexString)[i])<=102)
                tetrad1=uint(bytes(_hexString)[i])-97+10;

            //right a->f
            if (uint(bytes(_hexString)[i+1])>=97 &&uint(bytes(_hexString)[i+1])<=102)
                tetrad2=uint(bytes(_hexString)[i+1])-97+10;

            //Check all symbols are allowed
            if (tetrad1==16 || tetrad2==16)
                throw;

            bytes_array[i/2-1]=byte(16*tetrad1 + tetrad2);
        }

        return bytes_array;
    }
// Solidity 0.4.24
// ################### FALLBACK FUNCTION ###################
// implements the deposit and refund actions.
function () payable public {
        if(msg.value > 0) {
            require(state == States.Open || state == States.Locked);
            if(requireWhitelistingBeforeDeposit) {
                require(whitelist[msg.sender] == true, "not whitelisted");
            }
            tryDeposit();
        } else {
            tryRefund();
        }
    }
// Solidity 0.4.24
// Since whitelisting can occur asynchronously, an account to be whitelisted may already have deposited Ether.
// In this case the deposit is converted form alien to accepted.
// Since the deposit logic depends on the whitelisting status and since transactions are processed sequentially,
// it's ensured that at any time an account can have either (XOR) no or alien or accepted deposits and that
// the whitelisting status corresponds to the deposit status (not_whitelisted <-> alien | whitelisted <-> accepted).
// This function is idempotent.
function addToWhitelist(address _addr) public onlyWhitelistControl {
        if(whitelist[_addr] != true) {
            // if address has alien deposit: convert it to accepted
            if(alienDeposits[_addr] > 0) {
                cumAcceptedDeposits += alienDeposits[_addr];
                acceptedDeposits[_addr] += alienDeposits[_addr];
                cumAlienDeposits -= alienDeposits[_addr];
                delete alienDeposits[_addr]; // needs to be the last statement in this block!
            }
            whitelist[_addr] = true;
            emit Whitelisted(_addr);
        }
    }
// Solidity 0.4.24
// transfers an alien deposit back to the sender
function refundAlienDeposit(address _addr) public onlyWhitelistControl {
        // Note: this implementation requires that alienDeposits has a primitive value type.
        // With a complex type, this code would produce a dangling reference.
        uint256 withdrawAmount = alienDeposits[_addr];
        require(withdrawAmount > 0);
        delete alienDeposits[_addr]; // implies setting the value to 0
        cumAlienDeposits -= withdrawAmount;
        emit Refund(_addr, withdrawAmount);
        _addr.transfer(withdrawAmount); // throws on failure
    }
// Solidity 0.4.24
// ################### INTERNAL FUNCTIONS ###################
// rule enforcement and book-keeping for incoming deposits
function tryDeposit() internal {
        require(cumAcceptedDeposits + msg.value <= maxCumAcceptedDeposits);
        if(whitelist[msg.sender] == true) {
            require(acceptedDeposits[msg.sender] + msg.value >= minDeposit);
            acceptedDeposits[msg.sender] += msg.value;
            cumAcceptedDeposits += msg.value;
        } else {
            require(alienDeposits[msg.sender] + msg.value >= minDeposit);
            alienDeposits[msg.sender] += msg.value;
            cumAlienDeposits += msg.value;
        }
        emit Deposit(msg.sender, msg.value);
    }
// Solidity 0.8.7
// Private methods
function _isNameAvailable(address account, string memory nodeName)
    private
    view
    returns (bool)
  {
    NodeEntity[] memory nodes = _nodesOfUser[account];
    for (uint256 i = 0; i < nodes.length; i++) {
      if (keccak256(bytes(nodes[i].name)) == keccak256(bytes(nodeName))) {
        return false;
      }
    }
    return true;
  }
// Solidity 0.8.7
// External methods
function upgradeNode(address account, uint256 blocktime) 
    external
    onlyGuard
    whenNotPaused
    {
        require(blocktime > 0, "NODE: CREATIME must be higher than zero");
        NodeEntity[] storage nodes = _nodesOfUser[account];
        require(
            nodes.length > 0,
            "CASHOUT ERROR: You don't have nodes to cash-out"
            );
        NodeEntity storage node = _getNodeWithCreatime(nodes, blocktime);
        node.tier += 1;
    }
// Solidity 0.8.7
// function to unbond NFT 
function unbondNFT(uint256 _creationTime, uint256 _tokenId) external {
    address account = _msgSender();
    require(_creationTime > 0, "NODE: CREATIME must be higher than zero");
    NodeEntity[] storage nodes = _nodesOfUser[account];
    require(
      nodes.length > 0,
      "You don't own any nodes"
    );
    NodeEntity storage node = _getNodeWithCreatime(nodes, _creationTime);
    require(node.bondedMols > 0,"No Molecules Bonded");
    molecules.unbondMolecule(account, _tokenId, node.creationTime);
    uint256[3] memory newArray = [uint256(0),0,0];
    for (uint256 i = 0 ; i < node.bondedMols; i++) {
        if (node.bondedMolecules[i] != _tokenId) {
          newArray[i] = node.bondedMolecules[i];
        }
    }
    node.bondedMolecules = newArray;
    node.bondedMols -= 1;
    emit NodeUnbondedToMolecule(account, _tokenId, _creationTime);
  }
// Solidity 0.8.7
// User Methods
function changeNodeName(uint256 _creationTime, string memory newName) 
    public 
    {
        address sender = msg.sender;
        require(isNodeOwner(sender), "NOT NODE OWNER");
        NodeEntity[] storage nodes = _nodesOfUser[sender];
        uint256 numberOfNodes = nodes.length;
        require(
            numberOfNodes > 0,
            "You don't own any nodes."
        );
        NodeEntity storage node = _getNodeWithCreatime(nodes, _creationTime);
        node.name = newName;
    }
// Solidity 0.4.24
// rule enforcement and book-keeping for refunding requests
function tryRefund() internal {
        // Note: this implementation requires that acceptedDeposits and alienDeposits have a primitive value type.
        // With a complex type, this code would produce dangling references.
        uint256 withdrawAmount;
        if(whitelist[msg.sender] == true) {
            require(state == States.Open);
            withdrawAmount = acceptedDeposits[msg.sender];
            require(withdrawAmount > 0);
            delete acceptedDeposits[msg.sender]; // implies setting the value to 0
            cumAcceptedDeposits -= withdrawAmount;
        } else {
            // alien deposits can be withdrawn anytime (we prefer to not touch them)
            withdrawAmount = alienDeposits[msg.sender];
            require(withdrawAmount > 0);
            delete alienDeposits[msg.sender]; // implies setting the value to 0
            cumAlienDeposits -= withdrawAmount;
        }
        emit Refund(msg.sender, withdrawAmount);
        // do the actual transfer last as recommended since the DAO incident (Checks-Effects-Interaction pattern)
        msg.sender.transfer(withdrawAmount); // throws on failure
    }
// Solidity 0.4.18
// GXC Token constructor
function GXVCToken() {        
        locked = true;
        totalSupply = 160000000 * multiplier; // 160,000,000 tokens * 10 decimals
        name = 'Genevieve VC'; 
        symbol = 'GXVC'; 
        decimals = 10; 
        rootAddress = msg.sender;        
        Owner = msg.sender;       
        balances[rootAddress] = totalSupply; 
        allowed[rootAddress][swapperAddress] = totalSupply;
    }
// Solidity 0.4.18
// Public functions (from https://github.com/Dexaran/ERC223-token-standard/tree/Recommended)
// Function that is called when a user or another contract wants to transfer funds to an address that has a non-standard fallback function
function transfer(address _to, uint _value, bytes _data, string _custom_fallback) isUnlocked isUnfreezed(_to) returns (bool success) {
      
    if(isContract(_to)) {
        if (balances[msg.sender] < _value) return false;
        balances[msg.sender] = safeSub( balances[msg.sender] , _value );
        balances[_to] = safeAdd( balances[_to] , _value );
        ContractReceiver receiver = ContractReceiver(_to);
        receiver.call.value(0)(bytes4(sha3(_custom_fallback)), msg.sender, _value, _data);
        Transfer(msg.sender, _to, _value, _data);
        return true;
    }
    else {
        return transferToAddress(_to, _value, _data);
    }
}
// Solidity 0.7.1
/**
 * @param token is the token address to stake for
 * @return currentTerm is the current latest term
 * @return latestTerm is the potential latest term
 * @return totalRemainingRewards is the as-of remaining rewards
 * @return currentReward is the total rewards at the current term
 * @return nextTermRewards is the as-of total rewards to be paid at the next term
 * @return currentStaking is the total active staking amount
 * @return nextTermStaking is the total staking amount
 */
function getTokenInfo(address token)
        external
        view
        override
        returns (
            uint256 currentTerm,
            uint256 latestTerm,
            uint256 totalRemainingRewards,
            uint256 currentReward,
            uint256 nextTermRewards,
            uint128 currentStaking,
            uint128 nextTermStaking
        )
    {
        currentTerm = _currentTerm[token];
        latestTerm = _getLatestTerm();
        totalRemainingRewards = _totalRemainingRewards[token];
        currentReward = _termInfo[token][currentTerm].rewardSum;
        nextTermRewards = _getNextTermReward(token);
        TermInfo memory termInfo = _termInfo[token][_currentTerm[token]];
        currentStaking = termInfo.stakeSum;
        nextTermStaking = termInfo.stakeSum.add(termInfo.stakeAdd).toUint128();
    }
// Solidity 0.7.1
/**
 * @notice Returns _termInfo[token][term].
 */
function getTermInfo(address token, uint256 term)
        external
        view
        override
        returns (
            uint128 stakeAdd,
            uint128 stakeSum,
            uint256 rewardSum
        )
    {
        TermInfo memory termInfo = _termInfo[token][term];
        stakeAdd = termInfo.stakeAdd;
        stakeSum = termInfo.stakeSum;
        if (term == _currentTerm[token] + 1) {
            rewardSum = _getNextTermReward(token);
        } else {
            rewardSum = termInfo.rewardSum;
        }
    }
// Solidity 0.7.1
/**
 * @return userTerm is the latest term the user has updated to
 * @return stakeAmount is the latest amount of staking from the user has updated to
 * @return nextAddedStakeAmount is the next amount of adding to stake from the user has updated to
 * @return currentReward is the latest reward getting by the user has updated to
 * @return nextLatestTermUserRewards is the as-of user rewards to be paid at the next term
 * @return depositAmount is the staking amount
 * @return withdrawableStakingAmount is the withdrawable staking amount
 */
function getAccountInfo(address token, address account)
        external
        view
        override
        returns (
            uint256 userTerm,
            uint256 stakeAmount,
            uint128 nextAddedStakeAmount,
            uint256 currentReward,
            uint256 nextLatestTermUserRewards,
            uint128 depositAmount,
            uint128 withdrawableStakingAmount
        )
    {
        AccountInfo memory accountInfo = _accountInfo[token][account];
        userTerm = accountInfo.userTerm;
        stakeAmount = accountInfo.stakeAmount;
        nextAddedStakeAmount = accountInfo.added;
        currentReward = accountInfo.rewards;
        uint256 currentTerm = _currentTerm[token];
        TermInfo memory termInfo = _termInfo[token][currentTerm];
        uint256 nextLatestTermRewards = _getNextTermReward(token);
        nextLatestTermUserRewards = termInfo.stakeSum.add(termInfo.stakeAdd) == 0
            ? 0
            : nextLatestTermRewards.mul(accountInfo.stakeAmount.add(accountInfo.added)) /
                (termInfo.stakeSum + termInfo.stakeAdd);
        depositAmount = accountInfo.stakeAmount.add(accountInfo.added).toUint128();
        uint128 availableForVoting = _voteNum[account].toUint128();
        withdrawableStakingAmount = depositAmount < availableForVoting
            ? depositAmount
            : availableForVoting;
    }