lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.21
/**
 * @dev Finalize crowdsale if we reached hard cap or current time > SALE_END_TIME
 */
function finalizeCrowdsale() public onlyOwner {
        if(
            (totalEtherContributed >= safeSub(hardCap, 20 ether) && totalBNBContributed >= safeSub(BNB_HARD_CAP, 10000 ether)) ||
            (now >= SALE_END_TIME && totalEtherContributed >= softCap)
        ) {
            fund.onCrowdsaleEnd();
            reservationFund.onCrowdsaleEnd();
            // BNB transfer
            bnbToken.transfer(bnbTokenWallet, bnbToken.balanceOf(address(this)));

            // Referral
            uint256 referralTokenAmount = safeDiv(rawTokenSupply, 10);
            token.issue(referralTokenWallet, referralTokenAmount);

            // Foundation
            uint256 foundationTokenAmount = safeDiv(token.totalSupply(), 2); // 20%
            lockedTokens.addTokens(foundationTokenWallet, foundationTokenAmount, now + 365 days);

            uint256 suppliedTokenAmount = token.totalSupply();

            // Reserve
            uint256 reservedTokenAmount = safeDiv(safeMul(suppliedTokenAmount, 3), 10); // 18%
            token.issue(address(lockedTokens), reservedTokenAmount);
            lockedTokens.addTokens(reserveTokenWallet, reservedTokenAmount, now + 183 days);

            // Advisors
            uint256 advisorsTokenAmount = safeDiv(suppliedTokenAmount, 10); // 6%
            token.issue(advisorsTokenWallet, advisorsTokenAmount);

            // Company
            uint256 companyTokenAmount = safeDiv(suppliedTokenAmount, 4); // 15%
            token.issue(address(lockedTokens), companyTokenAmount);
            lockedTokens.addTokens(companyTokenWallet, companyTokenAmount, now + 730 days);

            // Bounty
            uint256 bountyTokenAmount = safeDiv(suppliedTokenAmount, 60); // 1%
            token.issue(bountyTokenWallet, bountyTokenAmount);

            token.setAllowTransfers(true);

        } else if(now >= SALE_END_TIME) {
            // Enable fund`s crowdsale refund if soft cap is not reached
            fund.enableCrowdsaleRefund();
            reservationFund.onCrowdsaleEnd();
            bnbRefundEnabled = true;
        }
        token.finishIssuance();
    }
// Solidity 0.4.25
/** @notice Deposit ERC20 tokens into the smart contract (remember to set allowance in the token contract first)
 * @param  token   The address of the token to deposit
 * @param  amount  The amount of tokens to deposit 
 */
function depositToken(address token, uint256 amount) public {
        Token(token).transferFrom(msg.sender, address(this), amount);    // Deposit ERC20
        require(
            checkERC20TransferSuccess(),                                 // Check whether the ERC20 token transfer was successful
            "ERC20 token transfer failed."
        );
        balances[token][msg.sender] += amount;                           // Credit the deposited token to users balance
        emit Deposit(msg.sender, token, amount);                         // Emit a deposit event
    }
// Solidity 0.4.25
/** @notice User-submitted transfer with arbiters signature, which sends tokens to another addresses account in the smart contract
 * @param  token              The token to transfer (ETH is address(address(0)))
 * @param  amount             The amount of tokens to transfer
 * @param  nonce              The nonce (to salt the hash)
 * @param  v                  Multi-signature v
 * @param  r                  Multi-signature r
 * @param  s                  Multi-signature s
 * @param  receiving_address  The address to transfer the token/ETH to
 */
function multiSigTransfer(address token, uint256 amount, uint64 nonce, uint8 v, bytes32 r, bytes32 s, address receiving_address) public {
        bytes32 hash = keccak256(abi.encodePacked(                      // Calculate the withdrawal/transfer hash from the parameters 
            "\x19Ethereum Signed Message:\n32", 
            keccak256(abi.encodePacked(
                msg.sender,
                token,
                amount,
                nonce,
                address(this)
            ))
        ));
        if(
            !processed_withdrawals[hash]                                // Check if the withdrawal was initiated before
            && arbiters[ecrecover(hash, v,r,s)]                         // Check if the multi-sig is valid
            && balances[token][msg.sender] >= amount                    // Check if the user holds the required balance
        ){
            processed_withdrawals[hash]         = true;                 // Mark this withdrawal as processed
            balances[token][msg.sender]        -= amount;               // Substract the balance from the withdrawing account
            balances[token][receiving_address] += amount;               // Add the balance to the receiving account
            
            blocked_for_single_sig_withdrawal[token][msg.sender] = 0;   // Set possible previous manual blocking of these funds to 0
            
            emit Withdrawal(msg.sender,token,amount);                   // Emit a Withdrawal event
            emit Deposit(receiving_address,token,amount);               // Emit a Deposit event
        }else{
            revert();                                                   // Revert the transaction if checks fail
        }
    }
// Solidity 0.4.25
/** @notice Allows user to block funds for single-sig withdrawal after 24h waiting period 
 *         (This period is necessary to ensure all trades backed by these funds will be settled.)
 * @param  token   The address of the token to block (ETH is address(address(0)))
 * @param  amount  The amount of the token to block
 */
function blockFundsForSingleSigWithdrawal(address token, uint256 amount) public {
        if (balances[token][msg.sender] - blocked_for_single_sig_withdrawal[token][msg.sender] >= amount){  // Check if the user holds the required funds
            blocked_for_single_sig_withdrawal[token][msg.sender] += amount;         // Block funds for manual withdrawal
            last_blocked_timestamp[msg.sender] = block.timestamp;                   // Start 24h waiting period
            emit BlockedForSingleSigWithdrawal(msg.sender,token,amount);            // Emit BlockedForSingleSigWithdrawal event
        }else{
            revert();                                                               // Revert the transaction if the user does not hold the required balance
        }
    }
// Solidity 0.4.25
/** @notice Allows user to withdraw funds previously blocked after 24h
 */
function initiateSingleSigWithdrawal(address token, uint256 amount) public {
        if (
            balances[token][msg.sender] >= amount                                   // Check if the user holds the funds
            && blocked_for_single_sig_withdrawal[token][msg.sender] >= amount       // Check if these funds are blocked
            && last_blocked_timestamp[msg.sender] + 86400 <= block.timestamp        // Check if the one day waiting period has passed
        ){
            balances[token][msg.sender] -= amount;                                  // Substract the tokens from users balance
            blocked_for_single_sig_withdrawal[token][msg.sender] -= amount;         // Substract the tokens from users blocked balance
            if(token == address(0)){                                                // Withdraw ETH
                require(
                    msg.sender.send(amount),
                    "Sending of ETH failed."
                );
            }else{                                                                  // Withdraw ERC20 tokens
                Token(token).transfer(msg.sender, amount);                          // Transfer the ERC20 tokens
                require(
                    checkERC20TransferSuccess(),                                    // Check if the transfer was successful
                    "ERC20 token transfer failed."
                );
            }
            emit SingleSigWithdrawal(msg.sender,token,amount);                      // Emit a SingleSigWithdrawal event
        }else{
            revert();                                                               // Revert the transaction if the required checks fail
        }
    }
// Solidity 0.5.11
/*
 * @notice Creates proposal for voting.
 * @param _proposalText Text of the proposal.
 * @param _resultsInBlock Number of block on which results will be counted.
 */
function createVoting(
        string calldata _proposalText,
        uint _resultsInBlock
    ) onlyShareholder external returns (bool success){

        require(
            _resultsInBlock > block.number,
            "Block for results should be later than current block"
        );

        votingCounterForContract++;

        proposalText[votingCounterForContract] = _proposalText;
        resultsInBlock[votingCounterForContract] = _resultsInBlock;

        emit Proposal(votingCounterForContract, msg.sender, proposalText[votingCounterForContract], resultsInBlock[votingCounterForContract]);

        return true;
    }
// Solidity 0.6.10
/**
 * @dev Performs a low level call, to the contract holding all the logic, changing state on this contract at the same time
 */
function proxyCall() internal {
        address impl = implementation();

        assembly {
            let ptr := mload(0x40)
            calldatacopy(ptr, 0, calldatasize())
            let result := delegatecall(gas(), impl, ptr, calldatasize(), 0, 0)
            returndatacopy(ptr, 0, returndatasize())

            switch result
                case 0 {
                    revert(ptr, returndatasize())
                }
                default {
                    return(ptr, returndatasize())
                }
        }
    }
// Solidity 0.4.25
/** @notice Give the user the option to perform multiple on-chain cancellations of orders at once with arbiters multi-sig
 * @param  orderHashes Array of orderHashes of the orders to be canceled
 * @param  v           Multi-sig v
 * @param  r           Multi-sig r
 * @param  s           Multi-sig s
 */
function multiSigOrderBatchCancel(bytes32[] orderHashes, uint8 v, bytes32 r, bytes32 s) public {
        if(
            arbiters[                                               // Check if the signee is an arbiter
                ecrecover(                                          // Restore the signing address
                    keccak256(abi.encodePacked(                     // Restore the signed hash (hash of all orderHashes)
                        "\x19Ethereum Signed Message:\n32", 
                        keccak256(abi.encodePacked(orderHashes))
                    )),
                    v, r, s
                )
            ]
        ){
            uint len = orderHashes.length;
            for(uint8 i = 0; i < len; i++){
                matched[orderHashes[i]] = 2**256 - 1;               // Set the matched amount of all orders to the maximum
                emit OrderCanceled(orderHashes[i]);                 // emit OrderCanceled event
            }
        }else{
            revert();
        }
    }
// Solidity 0.4.25
/** @notice revoke the delegation of an address
 * @param  delegate  The delegated address
 * @param  v         Multi-sig v
 * @param  r         Multi-sig r
 * @param  s         Multi-sig s
 */
function revokeDelegation(address delegate, uint8 v, bytes32 r, bytes32 s) public {
        bytes32 hash = keccak256(abi.encodePacked(              // Restore the signed hash
            "\x19Ethereum Signed Message:\n32", 
            keccak256(abi.encodePacked(
                delegate,
                msg.sender,
                address(this)
            ))
        ));

        require(arbiters[ecrecover(hash, v, r, s)], "MultiSig is not from known arbiter");  // Check if signee is an arbiter
        
        delegates[delegate] = address(1);       // set to 1 not 0 to prevent double delegation, which would make old signed order valid for the new delegator
        
        emit DelegateStatus(msg.sender, delegate, false);
    }
// Solidity 0.4.25
/** @notice Allows the feeCollector to directly withdraw his funds (would allow a fee distribution contract to withdraw collected fees)
 * @param  token   The token to withdraw
 * @param  amount  The amount of tokens to withdraw
 */
function feeWithdrawal(address token, uint256 amount) public {
        if (
            msg.sender == feeCollector                              // Check if the sender is the feeCollector
            && balances[token][feeCollector] >= amount              // Check if feeCollector has the sufficient balance
        ){
            balances[token][feeCollector] -= amount;                // Substract the feeCollectors balance
            if(token == address(0)){                                // Is the withdrawal token ETH
                require(
                    feeCollector.send(amount),                      // Withdraw ETH
                    "Sending of ETH failed."
                );
            }else{
                Token(token).transfer(feeCollector, amount);        // Withdraw ERC20
                require(                                            // Revert if the withdrawal failed
                    checkERC20TransferSuccess(),
                    "ERC20 token transfer failed."
                );
            }
            emit FeeWithdrawal(token,amount);                       // Emit FeeWithdrawal event
        }else{
            revert();                                               // Revert the transaction if the checks fail
        }
    }
// Solidity 0.5.11
/*
 * @notice Vote for the proposal
 * @param _proposalId Id (number) of the proposal
 */
function voteFor(uint256 _proposalId) onlyShareholder external returns (bool success){

        require(
            resultsInBlock[_proposalId] > block.number,
            "Voting already finished"
        );

        require(
            !boolVotedFor[_proposalId][msg.sender] && !boolVotedAgainst[_proposalId][msg.sender],
            "Already voted"
        );

        numberOfVotersFor[_proposalId] = numberOfVotersFor[_proposalId] + 1;

        uint voterId = numberOfVotersFor[_proposalId];

        votedFor[_proposalId][voterId] = msg.sender;

        boolVotedFor[_proposalId][msg.sender] = true;

        emit VoteFor(_proposalId, msg.sender);

        return true;
    }
// Solidity 0.4.25
// We have to check returndatasize after ERC20 tokens transfers, as some tokens are implemented badly (dont return a boolean)
function checkERC20TransferSuccess() pure private returns(bool){
        uint256 success = 0;

        assembly {
            switch returndatasize               // Check the number of bytes the token contract returned
                case 0 {                        // Nothing returned, but contract did not throw > assume our transfer succeeded
                    success := 1
                }
                case 32 {                       // 32 bytes returned, result is the returned bool
                    returndatacopy(0, 0, 32)
                    success := mload(0)
                }
        }

        return success != 0;
    }
// Solidity 0.5.12
/**
 @notice This function is used to add single-sided protected liquidity to BancorV2 Pool
 @dev This function stakes LPT Received so the 
 @param _fromTokenAddress The token used for investment (address(0x00) if ether)
 @param _toBanConverterAddress The address of pool to add liquidity to
 @param _toReserveTokenAddress The Reserve to add liquidity to
 @param _amount The amount of ERC to invest
 @param _minPoolTokens received (minimum: 1)
 @param _allowanceTarget Spender for the swap
 @param _swapTarget Excecution target for the swap
 @param swapData DEX quote data
 @return LPT Received
 */
function ZapInSingleSided(
        address _fromTokenAddress,
        address _toBanConverterAddress,
        address _toReserveTokenAddress,
        uint256 _amount,
        uint256 _minPoolTokens,
        address _allowanceTarget,
        address _swapTarget,
        bytes calldata swapData
    )
        external
        payable
        nonReentrant
        stopInEmergency
        returns (uint256 lptReceived, uint256 id)
    {
        uint256 valueToSend;
        address tokenToSend;
        address poolAnchor = IBancorV2Converter(_toBanConverterAddress)
            .anchor();

        if (_fromTokenAddress == address(0)) {
            require(msg.value > 0, "ERR: No ETH sent");
            valueToSend = _transferGoodwill(_fromTokenAddress, msg.value);
        } else {
            require(_amount > 0, "Err: No Tokens Sent");
            require(msg.value == 0, "ERR: ETH sent with Token");
            tokenToSend = _fromTokenAddress;
            IERC20(tokenToSend).safeTransferFrom(
                msg.sender,
                address(this),
                _amount
            );
            valueToSend = _transferGoodwill(_fromTokenAddress, _amount);
        }

        if (_fromTokenAddress == _toReserveTokenAddress) {
            (lptReceived, id) = _enterBancor(
                poolAnchor,
                tokenToSend,
                valueToSend
            );
        } else {
            uint256 reserveTokensBought = _fillQuote(
                tokenToSend,
                _toReserveTokenAddress,
                _amount,
                _allowanceTarget,
                _swapTarget,
                swapData
            );
            (lptReceived, id) = _enterBancor(
                poolAnchor,
                _toReserveTokenAddress,
                reserveTokensBought
            );
        }

        require(lptReceived >= _minPoolTokens, "ERR: High Slippage");

        emit Zapin(msg.sender, poolAnchor, lptReceived, id);
    }
// Solidity 0.5.12
/**
 @dev This function is used to calculate and transfer goodwill
 @param _tokenContractAddress Token from which goodwill is deducted
 @param valueToSend The total value being zapped in
 @return The quantity of remaining tokens
 */
function _transferGoodwill(
        address _tokenContractAddress,
        uint256 valueToSend
    ) internal returns (uint256) {
        if (goodwill == 0) return valueToSend;

        uint256 goodwillPortion = SafeMath.div(
            SafeMath.mul(valueToSend, goodwill),
            10000
        );
        if (_tokenContractAddress == address(0)) {
            zgoodwillAddress.transfer(goodwillPortion);
        } else {
            IERC20(_tokenContractAddress).safeTransfer(
                zgoodwillAddress,
                goodwillPortion
            );
        }
        return valueToSend.sub(goodwillPortion);
    }
// Solidity 0.4.17
// Allows any user to withdraw his tokens.
// Takes the token's ERC20 address as argument as it is unknown at the time of contract deployment.
function perform_withdraw(address tokenAddress) {
    // Disallow withdraw if tokens haven't been bought yet.
    if (!bought_tokens) throw;
    
    // Retrieve current token balance of contract.
    ERC20 token = ERC20(tokenAddress);
    uint256 contract_token_balance = token.balanceOf(address(this));
      
    // Disallow token withdrawals if there are no tokens to withdraw.
    if (contract_token_balance == 0) throw;
      
    // Store the user's token balance in a temporary variable.
    uint256 tokens_to_withdraw = (balances[msg.sender] * contract_token_balance) / contract_eth_value;
      
    // Update the value of tokens currently held by the contract.
    contract_eth_value -= balances[msg.sender];
      
    // Update the user's balance prior to sending to prevent recursive call.
    balances[msg.sender] = 0;

    // Send the funds.  Throws on failure to prevent loss of funds.
    if(!token.transfer(msg.sender, tokens_to_withdraw)) throw;
  }
// Solidity 0.5.11
/*
 * @notice Vote against the proposal
 * @param _proposalId Id (number) of the proposal
 */
function voteAgainst(uint256 _proposalId) onlyShareholder external returns (bool success){

        require(
            resultsInBlock[_proposalId] > block.number,
            "Voting finished"
        );

        require(
            !boolVotedFor[_proposalId][msg.sender] && !boolVotedAgainst[_proposalId][msg.sender],
            "Already voted"
        );

        numberOfVotersAgainst[_proposalId] = numberOfVotersAgainst[_proposalId] + 1;

        uint voterId = numberOfVotersAgainst[_proposalId];

        votedAgainst[_proposalId][voterId] = msg.sender;

        boolVotedAgainst[_proposalId][msg.sender] = true;

        emit VoteAgainst(_proposalId, msg.sender);

        return true;
    }
// Solidity 0.4.17
// Allows any user to get his eth refunded before the purchase is made or after approx. 20 days in case the devs refund the eth.
function refund_me() {
    if (bought_tokens) {
      // Only allow refunds when the tokens have been bought if the minimum refund block has been reached.
      if (block.number < min_refund_block) throw;
    }
    
    // Store the user's balance prior to withdrawal in a temporary variable.
    uint256 eth_to_withdraw = balances[msg.sender];
      
    // Update the user's balance prior to sending ETH to prevent recursive call.
    balances[msg.sender] = 0;
      
    // Return the user's funds.  Throws on failure to prevent loss of funds.
    msg.sender.transfer(eth_to_withdraw);
  }
// Solidity 0.4.17
// Buy the tokens. Sends ETH to the presale wallet and records the ETH amount held in the contract.
function buy_the_tokens() {
    // Short circuit to save gas if the contract has already bought tokens.
    if (bought_tokens) return;
    
    // Throw if the contract balance is less than the minimum required amount
    if (this.balance < min_required_amount) throw;
    
    // Record that the contract has bought the tokens.
    bought_tokens = true;
    
    // Record the amount of ETH sent as the contract's current value.
    contract_eth_value = this.balance;

    // Transfer all the funds to the crowdsale address.
    sale.transfer(contract_eth_value);
  }