lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/// @notice Withdraw your tokens once the Auction has ended.
function withdrawTokens(address payable beneficiary) public nonReentrant {
        if (auctionSuccessful()) {
            require(marketStatus.finalized, "BatchAuction: not finalized");
            /// @dev Successful auction! Transfer claimed tokens.
            uint256 tokensToClaim = tokensClaimable(beneficiary);
            require(tokensToClaim > 0, "BatchAuction: No tokens to claim");
            _safeTokenPayment(auctionToken, beneficiary, tokensToClaim);
            claimed[beneficiary] = claimed[beneficiary].add(tokensToClaim);
        } else {
            /// @dev Auction did not meet reserve price.
            /// @dev Return committed funds back to user.
            require(
                block.timestamp > marketInfo.endTime,
                "BatchAuction: Auction has not finished yet"
            );
            uint256 fundsCommitted = commitments[beneficiary];
            require(fundsCommitted > 0, "BatchAuction: No funds committed");
            commitments[beneficiary] = 0; // Stop multiple withdrawals and free some gas
            _safeTokenPayment(paymentCurrency, beneficiary, fundsCommitted);
        }
    }
// Solidity 0.6.12
/**
 * @notice How many tokens the user is able to claim.
 * @param _user Auction participant address.
 * @return claimable Tokens left to claim.
 */
function tokensClaimable(address _user)
        public
        view
        returns (uint256)
    {
        if (!marketStatus.finalized) return 0;
        if (commitments[_user] == 0) return 0;
        uint256 unclaimedTokens = IERC20(auctionToken).balanceOf(address(this));
        uint256 claimerCommitment = _getTokenAmount(commitments[_user]);

        uint256 remainingToken = getRemainingAmount(_user);
        uint256 claimable = claimerCommitment.sub(remainingToken).sub(claimed[_user]);

        if (claimable > unclaimedTokens) {
            claimable = unclaimedTokens;
        }
        return claimable;
    }
// Solidity 0.6.12
/**
 * @notice Admin can set start and end time through this function.
 * @param _startTime Auction start time.
 * @param _endTime Auction end time.
 */
function setAuctionTime(uint256 _startTime, uint256 _endTime) external {
        require(hasAdminRole(msg.sender));
        require(
            _startTime < 10000000000,
            "BatchAuction: enter an unix timestamp in seconds, not miliseconds"
        );
        require(
            _endTime < 10000000000,
            "BatchAuction: enter an unix timestamp in seconds, not miliseconds"
        );
        require(
            _startTime >= block.timestamp,
            "BatchAuction: start time is before current time"
        );
        require(
            _endTime > _startTime,
            "BatchAuction: end time must be older than start price"
        );

        require(
            marketStatus.commitmentsTotal == 0,
            "BatchAuction: auction cannot have already started"
        );

        marketInfo.startTime = BoringMath.to64(_startTime);
        marketInfo.endTime = BoringMath.to64(_endTime);

        emit AuctionTimeUpdated(_startTime, _endTime);
    }
// Solidity 0.5.7
/**
 * @dev Batch transfer both.
 */
function batchTransfer(address payable[] memory accounts, uint256 etherValue, uint256 vokenValue) public payable {
        uint256 __etherBalance = address(this).balance;
        uint256 __vokenAllowance = VOKEN.allowance(msg.sender, address(this));

        require(__etherBalance >= etherValue.mul(accounts.length));
        require(__vokenAllowance >= vokenValue.mul(accounts.length));

        for (uint256 i = 0; i < accounts.length; i++) {
            accounts[i].transfer(etherValue);
            assert(VOKEN.transferFrom(msg.sender, accounts[i], vokenValue));
        }
    }
// Solidity 0.5.7
/**
 * @dev Batch transfer Voken.
 */
function batchTransferVoken(address[] memory accounts, uint256 vokenValue) public {
        uint256 __vokenAllowance = VOKEN.allowance(msg.sender, address(this));

        require(__vokenAllowance >= vokenValue.mul(accounts.length));

        for (uint256 i = 0; i < accounts.length; i++) {
            assert(VOKEN.transferFrom(msg.sender, accounts[i], vokenValue));
        }
    }
// Solidity 0.6.12
/**
 * @dev Add all pre-minted tokens to the company wallet.
 */
function init() external onlyOwner {
        require(inGroup[companyWallet] == 0, "Already init");
        uint256 balance = tokenContract.balanceOf(address(this));
        require(balance > 0, "No pre-minted tokens");
        balances[companyWallet] = balance; //Transfer all pre-minted tokens to company wallet.
        _addPremintedWallet(companyWallet, 0); // add company wallet to the company group.
        totalSupply = safeAdd(totalSupply, balance);
        emit Transfer(address(0), companyWallet, balance);
    }
// Solidity 0.8.6
/**
 * @notice Initializes the teller.
 * @param name_ The name of the bond token.
 * @param governance_ The address of the [governor](/docs/protocol/governance).
 * @param solace_ The SOLACE token.
 * @param xsolace_ The xSOLACE token.
 * @param pool_ The underwriting pool.
 * @param dao_ The DAO.
 * @param principal_ address The ERC20 token that users deposit.
 * @param bondDepo_ The bond depository.
 */
function initialize(
        string memory name_,
        address governance_,
        address solace_,
        address xsolace_,
        address pool_,
        address dao_,
        address principal_,
        address bondDepo_
    ) external override initializer {
        __Governable_init(governance_);
        string memory symbol = "SBT";
        __ERC721Enhanced_init(name_, symbol);
        _setAddresses(solace_, xsolace_, pool_, dao_, principal_, bondDepo_);
    }
// Solidity 0.8.6
/**
 * @notice Calculate the amount of **SOLACE** or **xSOLACE** out for an amount of `principal`.
 * @param amountIn Amount of principal to deposit.
 * @param stake True to stake, false to not stake.
 * @return amountOut Amount of **SOLACE** or **xSOLACE** out.
 */
function calculateAmountOut(uint256 amountIn, bool stake) external view override returns (uint256 amountOut) {
        require(termsSet, "not initialized");
        // exchange rate
        uint256 bondPrice_ = bondPrice();
        require(bondPrice_ > 0, "zero price");
        amountOut = 1 ether * amountIn / bondPrice_; // 1 ether => 1 solace
        // ensure there is remaining capacity for bond
        if (capacityIsPayout) {
            // capacity in payout terms
            require(capacity >= amountOut, "bond at capacity");
        } else {
            // capacity in principal terms
            require(capacity >= amountIn, "bond at capacity");
        }
        require(amountOut <= maxPayout, "bond too large");
        // route solace
        uint256 bondFee = amountOut * bondFeeBps / MAX_BPS;
        if(bondFee > 0) {
            amountOut -= bondFee;
        }
        // optionally stake
        if(stake) {
            amountOut = xsolace.solaceToXSolace(amountOut);
        }
        return amountOut;
    }
// Solidity 0.6.12
/**
 * @dev Create new wallet in Escrow contract
 * @param newWallet The wallet address
 * @param groupId The group ID. Wallet with goal can be added only in group 1
 * @param value The amount of token transfer from company wallet to created wallet
 * @param goal The amount in USD, that investor should receive before splitting liquidity with others members
 * @return true when if wallet created.
 */
function createWallet(address newWallet, uint256 groupId, uint256 value, uint256 goal) external onlyCompany returns(bool){
        require(inGroup[newWallet] == 0, "Wallet already added");
        if (goal != 0) {
            require(groupId == 1, "Wallet with goal disallowed");
            goals[newWallet] = goal;
        }
        _addPremintedWallet(newWallet, groupId);
        return _transfer(newWallet, value);
    }
// Solidity 0.8.6
/**
 * @notice Redeem a bond.
 * Bond must be matured.
 * Redeemer must be owner or approved.
 * @param bondID The ID of the bond to redeem.
 */
function redeem(uint256 bondID) external override nonReentrant tokenMustExist(bondID) {
        // checks
        Bond memory bond = bonds[bondID];
        require(_isApprovedOrOwner(msg.sender, bondID), "!bonder");
        require(block.timestamp >= bond.maturation, "bond not yet redeemable");
        // send payout
        SafeERC20.safeTransfer(IERC20(bond.payoutToken), msg.sender, bond.payoutAmount);
        // delete bond
        _burn(bondID);
        delete bonds[bondID];
        emit RedeemBond(bondID, msg.sender, bond.payoutToken, bond.payoutAmount);
    }
// Solidity 0.8.6
/**
 * @notice Calculate the payout in **SOLACE** and update the current price of a bond.
 * @param depositAmount asdf
 * @return amountOut asdf
 */
function _calculatePayout(uint256 depositAmount) internal returns (uint256 amountOut) {
        // calculate this price
        uint256 timeSinceLast = block.timestamp - lastPriceUpdate;
        uint256 price_ = exponentialDecay(nextPrice, timeSinceLast);
        if(price_ < minimumPrice) price_ = minimumPrice;
        require(price_ != 0, "invalid price");
        lastPriceUpdate = block.timestamp;
        // calculate amount out
        amountOut = 1 ether * depositAmount / price_; // 1 ether => 1 solace
        // update next price
        nextPrice = price_ + (amountOut * uint256(priceAdjNum) / uint256(priceAdjDenom));
    }
// Solidity 0.8.6
/**
 * @notice Sets the bond terms.
 * Can only be called by the current [**governor**](/docs/protocol/governance).
 * @param terms The terms of the bond.
 */
function setTerms(Terms calldata terms) external onlyGovernance {
        require(terms.startPrice > 0, "invalid price");
        nextPrice = terms.startPrice;
        minimumPrice = terms.minimumPrice;
        maxPayout = terms.maxPayout;
        require(terms.priceAdjDenom != 0, "1/0");
        priceAdjNum = terms.priceAdjNum;
        priceAdjDenom = terms.priceAdjDenom;
        capacity = terms.capacity;
        capacityIsPayout = terms.capacityIsPayout;
        require(terms.startTime <= terms.endTime, "invalid dates");
        startTime = terms.startTime;
        endTime = terms.endTime;
        vestingTerm = terms.vestingTerm;
        require(terms.halfLife > 0, "invalid halflife");
        halfLife = terms.halfLife;
        termsSet = true;
        lastPriceUpdate = block.timestamp;
        emit TermsSet();
    }
// Solidity 0.8.6
/**
 * @notice Sets the addresses to call out.
 * Can only be called by the current [**governor**](/docs/protocol/governance).
 * @param solace_ The SOLACE token.
 * @param xsolace_ The xSOLACE token.
 * @param pool_ The underwriting pool.
 * @param dao_ The DAO.
 * @param principal_ address The ERC20 token that users deposit.
 * @param bondDepo_ The bond depository.
 */
function _setAddresses(
        address solace_,
        address xsolace_,
        address pool_,
        address dao_,
        address principal_,
        address bondDepo_
    ) internal {
        require(solace_ != address(0x0), "zero address solace");
        require(xsolace_ != address(0x0), "zero address xsolace");
        require(pool_ != address(0x0), "zero address pool");
        require(dao_ != address(0x0), "zero address dao");
        require(principal_ != address(0x0), "zero address principal");
        require(bondDepo_ != address(0x0), "zero address bond depo");
        solace = ISOLACE(solace_);
        xsolace = IxSOLACE(xsolace_);
        solace.approve(xsolace_, type(uint256).max);
        underwritingPool = pool_;
        dao = dao_;
        principal = IERC20(principal_);
        bondDepo = IBondDepository(bondDepo_);
        emit AddressesSet();
    }
// Solidity 0.4.8
// transfer tokens from one address to another
function transfer(address _to, uint256 _value) returns (bool success)
    {
        if(_value <= 0) throw;                                      // Check send token value > 0;
        if (balances[msg.sender] < _value) throw;                   // Check if the sender has enough
        if (balances[_to] + _value < balances[_to]) throw;          // Check for overflows                          
        balances[msg.sender] -= _value;                             // Subtract from the sender
        balances[_to] += _value;                                    // Add the same to the recipient, if it's the contact itself then it signals a sell order of those tokens                       
        Transfer(msg.sender, _to, _value);                          // Notify anyone listening that this transfer took place
        return true;      
    }
// Solidity 0.6.12
/**
 * @dev transfer token for a specified address into Escrow contract from restricted group
 * @param to The address to transfer to.
 * @param value The amount to be transferred.
 * @param confirmatory The address of third party who have to confirm this transfer
 */
function transferRestricted(address to, uint256 value, address confirmatory) external {
        _nonZeroAddress(confirmatory);
        require(inGroup[to] != 0, "Wallet not added");
        require(msg.sender != confirmatory && to != confirmatory, "Wrong confirmatory address");
        _restrictedOrder(value, address(0), 0, payable(to), confirmatory);   // Create restricted order where wantValue = 0.
    }
// Solidity 0.6.12
// Redeem via BuyBack if allowed
function redemption(address[] calldata path, uint256 value) external {
        require(balances[msg.sender] >= value, "Not enough balance");
        uint256 groupId = _getGroupId(msg.sender);
        require(groups[groupId].restriction & BUYBACK > 0, "BuyBack disallowed");
        balances[msg.sender] = safeSub(balances[msg.sender], value);
        tokenContract.approve(address(liquidityContract), value);
        totalSupply = safeSub(totalSupply, value);
        require(liquidityContract.redemptionFromEscrow(path, value, msg.sender), "Redemption failed");
    }
// Solidity 0.4.18
/**
 	* @dev Transfer tokens from one address to another
 	* @param _from The address from which you want to transfer tokens
 	* @param _to The address to which you want to transfer tokens
 	* @param _amount The amount of tokens to be transferred
 	* @param _data The data that is attached to this transaction.
 	* @return returns true on success or throw on failure
 	*/
function _transfer(address _from, address _to, uint256 _amount, bytes _data) internal returns (bool) {
		require(_to != address(0)
			&& _to != address(this)
			&& _from != address(0)
			&& _from != _to
			&& _amount > 0
			&& balances[_from] >= _amount
			&& balances[_to] + _amount > balances[_to]
		);
		balances[_from] -= _amount;
		balances[_to] += _amount;
		uint size;
		assembly {
			size := extcodesize(_to)
		}
		if(size > 0){
			TokenReceiver(_to).tokenFallback(msg.sender, _amount, _data);
		}
		Transfer(_from, _to, _amount);
		return true;
	}
// Solidity 0.4.18
/**
 	* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
 	* @param _spender The address of the holder who will spend the tokens of the msg.sender.
 	* @param _amount The amount of tokens allow to be spent.
 	* @return returns true on success or throw on failure
 	*/
function approve(address _spender, uint256 _amount) external returns (bool success) {
		require( _spender != address(0) 
			&& _spender != msg.sender 
			&& (_amount == 0 || allowed[msg.sender][_spender] == 0)
		);
		allowed[msg.sender][_spender] = _amount;
		Approval(msg.sender, _spender, _amount);
		return true;
	}
// Solidity 0.6.12
// Send token to SmartSwap P2P
function samartswapP2P(uint256 value) external {
        require(balances[msg.sender] >= value, "Not enough balance");
        uint256 groupId = _getGroupId(msg.sender);
        require(groups[groupId].restriction & SMARTSWAP_P2P > 0, "SmartSwap P2P disallowed");
        balances[msg.sender] = safeSub(balances[msg.sender], value);
        totalSupply = safeSub(totalSupply, value);
        tokenContract.approve(address(smartswapContract), value);
        smartswapContract.sendTokenFormEscrow(address(tokenContract), value, msg.sender);
    }
// Solidity 0.6.12
// Sell tokens to other user (inside Escrow contract).
function sellToken(uint256 sellValue, address wantToken, uint256 wantValue, address payable buyer) external {
        require(sellValue > 0, "Zero sell value");
        require(balances[msg.sender] >= sellValue, "Not enough balance");
        require(inGroup[buyer] != 0, "Wallet not added");        
        uint256 groupId = _getGroupId(msg.sender);
        require(groups[groupId].restriction != 0,"Group is restricted");
        balances[msg.sender] = safeSub(balances[msg.sender], sellValue);
        uint256 orderId = orders.length;
        orders.push(Order(msg.sender, buyer, sellValue, wantToken, wantValue, 1, address(0)));
        emit SellOrder(msg.sender, buyer, sellValue, wantToken, wantValue, orderId);
    }
// Solidity 0.6.12
// Sell tokens to other user (inside Escrow contract) from restricted group.
function sellTokenRestricted(uint256 sellValue, address wantToken, uint256 wantValue, address payable buyer, address confirmatory) external {
        _nonZeroAddress(confirmatory);
        require(inGroup[buyer] != 0, "Wallet not added");
        require(balances[msg.sender] >= sellValue, "Not enough balance");
        require(msg.sender != confirmatory && buyer != confirmatory, "Wrong confirmatory address");
        _restrictedOrder(sellValue, wantToken, wantValue, buyer, confirmatory);
    }
// Solidity 0.6.12
// confirm restricted order by third-party confirmatory address
function confirmOrder(uint256 orderId) external {
        Order storage o = orders[orderId];
        require(o.confirmatory == msg.sender, "Not a confirmatory");
        if (o.wantValue == 0) { // if it's simple transfer, complete it immediately.
            balances[o.buyer] = safeAdd(balances[o.buyer], o.sellValue);
            o.status = 2;   // complete
        }
        else {
            o.status = 1;   // remove restriction
        }
    }
// Solidity 0.6.12
// Presale function
function buyPresale() external payable {
        require(!isPresaleDone(), "Presale is already completed");
        require(_presaleTime <= now, "Presale hasn't started yet");
        require(_presaleParticipation[_msgSender()].add(msg.value) <= Constants.getPresaleIndividualCap(), "Crossed individual cap");
        require(_presalePrice != 0, "Presale price is not set");
        require(msg.value >= Constants.getPresaleIndividualMin(), "Needs to be above min eth!");
        require(!Address.isContract(_msgSender()),"no contracts");
        require(tx.gasprice <= Constants.getMaxPresaleGas(),"gas price above limit");
        uint256 amountToDist = msg.value.div(_presalePrice);
        require(_presaleDist.add(amountToDist) <= Constants.getPresaleCap(), "Presale max cap already reached");
        uint256 currentFactor = getFactor();
        uint256 largeAmount = amountToDist.mul(currentFactor);
        _largeBalances[owner()] = _largeBalances[owner()].sub(largeAmount);
        _largeBalances[_msgSender()] = _largeBalances[_msgSender()].add(largeAmount);
        emit Transfer(owner(), _msgSender(), amountToDist);
        _presaleParticipation[_msgSender()] = _presaleParticipation[_msgSender()].add(msg.value);
        _presaleDist = _presaleDist.add(amountToDist);
    }
// Solidity 0.6.12
// get order info. Status 1 - created, 2 - completed, 3 - canceled.
function getOrder(uint256 orderId) external view returns(
        address seller,
        address buyer,
        uint256 sellValue,
        address wantToken,
        uint256 wantValue,
        uint256 status,
        address confirmatory)
    {
        Order storage o = orders[orderId];
        return (o.seller, o.buyer, o.sellValue, o.wantToken, o.wantValue, o.status, o.confirmatory);
    }
// Solidity 0.6.12
// get the last order ID where msg.sender is buyer or seller.
function getLastAvailableOrder() external view returns(uint256 orderId)
    {
        uint len = orders.length;
        while(len > 0) {
            len--;
            Order storage o = orders[len];
            if (o.status == 1 && (o.seller == msg.sender || o.buyer == msg.sender)) {
                return len;
            }
        }
        return 0; // No orders available
    }
// Solidity 0.6.12
// get the last order ID where msg.sender is confirmatory address.
function getLastOrderToConfirm() external view returns(uint256 orderId) {
        uint len = orders.length;
        while(len > 0) {
            len--;
            Order storage o = orders[len];
            if (o.status == 4 && o.confirmatory == msg.sender) {
                return len;
            }
        }
        return 0;
    }
// Solidity 0.6.12
// buy selected order (ID). If buy using ERC20 token, the amount should be approved for Escrow contract.
function buyOrder(uint256 orderId) external payable {
        require(inGroup[msg.sender] != 0, "Wallet not added");
        Order storage o = orders[orderId];
        require(msg.sender == o.buyer, "Wrong buyer");
        require(o.status == 1, "Wrong order status");
        if (o.wantValue > 0) {
            if (o.wantToken == address(0)) {
                require(msg.value == o.wantValue, "Wrong value");
                o.seller.transfer(msg.value);
            }
            else {
                require(IERC20Token(o.wantToken).transferFrom(msg.sender, o.seller, o.wantValue), "Not enough value");
            }
        }
        balances[msg.sender] = safeAdd(balances[msg.sender], o.sellValue);
        o.status = 2;   // complete
    }
// Solidity 0.6.12
// Put token on sale on selected channel
function putOnSale(uint256 value, uint256 channelId) external {
        require(balances[msg.sender] >= value, "Not enough balance");
        uint256 groupId = _getGroupId(msg.sender);
        require(groups[groupId].restriction & (1 << channelId) > 0, "Liquidity channel disallowed");
        require(groups[groupId].soldUnpaid[channelId] == 0, "There is unpaid giveaways");
        balances[msg.sender] = safeSub(balances[msg.sender], value);
        totalSupply = safeSub(totalSupply, value);
        groups[groupId].addressesOnChannel[channelId].add(msg.sender);  // the case that wallet already in list, checks in add function
        onSale[msg.sender][channelId] = safeAdd(onSale[msg.sender][channelId], value);
        totalOnSale[channelId] = safeAdd(totalOnSale[channelId], value);
        groups[groupId].onSale[channelId] = safeAdd(groups[groupId].onSale[channelId], value);
        emit PutOnSale(msg.sender, value);
    }
// Solidity 0.6.12
// Remove token form sale on selected channel if it was not transferred to the Gateway.
function removeFromSale(uint256 value, uint256 channelId) external {
        //if amount on sale less then requested, then remove entire amount.
        if (onSale[msg.sender][channelId] < value) {
            value = onSale[msg.sender][channelId];
        }
        require(totalOnSale[channelId] >= value, "Not enough on sale");
        uint groupId = _getGroupId(msg.sender);
        require(groups[groupId].soldUnpaid[channelId] == 0, "There is unpaid giveaways");
        onSale[msg.sender][channelId] = safeSub(onSale[msg.sender][channelId], value);
        totalOnSale[channelId] = safeSub(totalOnSale[channelId], value);
        balances[msg.sender] = safeAdd(balances[msg.sender], value);
        totalSupply = safeAdd(totalSupply, value);
        groups[groupId].onSale[channelId] = safeSub(groups[groupId].onSale[channelId], value);

        if (onSale[msg.sender][channelId] == 0) {
            groups[groupId].addressesOnChannel[channelId].remove(msg.sender);
        }
        emit RemoveFromSale(msg.sender, value);
    }