lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 * @dev distributes eth based on fees to gen and pot
 */
function distributeInternal(uint256 _rID, uint256 _pID, uint256 _eth, uint256 _team, uint256 _keys, F3Ddatasets.EventReturns memory _eventData_)
    private
    returns(F3Ddatasets.EventReturns)
    {
        // calculate gen share
        uint256 _gen = (_eth.mul(fees_[_team].gen)) / 100;

        // toss 1% into airdrop pot
        uint256 _air = (_eth / 100);
        airDropPot_ = airDropPot_.add(_air);

        uint256 cut = (fees_[_team].marketing).add(13);
        _eth = _eth.sub(_eth.mul(cut) / 100);

        // calculate pot
        uint256 _pot = _eth.sub(_gen);

        // distribute gen share (thats what updateMasks() does) and adjust
        // balances for dust.
        uint256 _dust = updateMasks(_rID, _pID, _gen, _keys);
        if (_dust > 0) {
            _gen = _gen.sub(_dust);
        }

        // add eth to pot
        round_[_rID].pot = _pot.add(_dust).add(round_[_rID].pot);

        // set up event data
        _eventData_.genAmount = _gen.add(_eventData_.genAmount);
        _eventData_.potAmount = _pot;

        return(_eventData_);
    }
// Solidity 0.4.24
/**
 * @dev adds up unmasked earnings, & vault earnings, sets them all to 0
 * @return earnings in wei format
 */
function withdrawEarnings(uint256 _pID)
    private
    returns(uint256)
    {
        // update gen vault
        updateGenVault(_pID, plyr_[_pID].lrnd);

        // from vaults
        uint256 _earnings = (plyr_[_pID].win).add(plyr_[_pID].gen).add(plyr_[_pID].aff);
        if (_earnings > 0)
        {
            plyr_[_pID].win = 0;
            plyr_[_pID].gen = 0;
            plyr_[_pID].aff = 0;
        }

        return(_earnings);
    }
// Solidity 0.4.24
/**
 * @dev prepares compression data and fires event for buy or reload tx's
 */
function endTx(uint256 _pID, uint256 _team, uint256 _eth, uint256 _keys, F3Ddatasets.EventReturns memory _eventData_)
    private
    {
        _eventData_.compressedData = _eventData_.compressedData + (now * 1000000000000000000) + (_team * 100000000000000000000000000000);
        _eventData_.compressedIDs = _eventData_.compressedIDs + _pID + (rID_ * 10000000000000000000000000000000000000000000000000000);

        emit F3Devents.onEndTx
        (
            _eventData_.compressedData,
            _eventData_.compressedIDs,
            plyr_[_pID].name,
            msg.sender,
            _eth,
            _keys,
            _eventData_.winnerAddr,
            _eventData_.winnerName,
            _eventData_.amountWon,
            _eventData_.newPot,
            _eventData_.mktAmount,
//            _eventData_.comAmount,
            _eventData_.genAmount,
            _eventData_.potAmount,
            airDropPot_
        );
    }
// Solidity 0.5.0
/**
 * @dev Escrow finalization task, called when finalize() is called.
 */
function _finalization() internal {
        if (goalReached()) {
            //escrow used to get transferred here, but that allows people to withdraw tokens before LP is created
        } else {
            _escrow.enableRefunds();
        }

        super._finalization();
    }
// Solidity 0.4.24
/**
 * @dev Transfer token for a specified address
 * @param _token erc20 The address of the ERC20 contract
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the _value of tokens to be transferred
 */
function safeTransfer(IERC20 _token, address _to, uint256 _value) internal returns (bool) {
        uint256 prevBalance = _token.balanceOf(address(this));

        require(prevBalance >= _value, "Insufficient funds");

        _token.transfer(_to, _value);

        require(prevBalance - _value == _token.balanceOf(address(this)), "Transfer failed");

        return true;
    }
// Solidity 0.8.9
/**
 * @dev Allow contract owner to withdraw ERC-20 balance from contract
 * while still splitting royalty payments to all other team members.
 * in the event ERC-20 tokens are paid to the contract.
 * @param _tokenContract contract of ERC-20 token to withdraw
 * @param _amount balance to withdraw according to balanceOf of ERC-20 token
 */
function withdrawAllERC20(address _tokenContract, uint256 _amount) public onlyOwner {
    require(_amount > 0);
    IERC20 tokenContract = IERC20(_tokenContract);
    require(tokenContract.balanceOf(address(this)) >= _amount, 'Contract does not own enough tokens');

    for(uint i=0; i < payableAddressCount; i++ ) {
        tokenContract.transfer(payableAddresses[i], (_amount * payableFees[i]) / 100);
    }
 }
// Solidity 0.5.0
/**
 * @dev Withdraw tokens only after crowdsale ends.
 * @param beneficiary Whose tokens will be withdrawn.
 */
function withdrawTokens(address beneficiary) public {
       require(goalReached(), "RefundableCrowdsale: goal not reached");
       //require(hasClosed(), "PostDeliveryCrowdsale: not closed");
       require(finalized(), "Withdraw Tokens: crowdsale not finalized");
        uint256 amount = _balances[beneficiary];
        require(amount > 0, "PostDeliveryCrowdsale: beneficiary is not due any tokens");

        _balances[beneficiary] = 0;
        //_vault.transfer(token(), beneficiary, amount); //so taxes are avoided
        _deliverTokens(address(beneficiary), amount);
    }
// Solidity 0.5.0
/**
 * @dev Extend crowdsale.
 * @param newClosingTime Crowdsale closing time
 */
function _extendTime(uint256 newClosingTime) internal {
        require(!hasClosed(), "TimedCrowdsale: already closed");
        // solhint-disable-next-line max-line-length
        require(newClosingTime > _closingTime, "TimedCrowdsale: new closing time is before current closing time");

        emit TimedCrowdsaleExtended(_closingTime, newClosingTime);
        _closingTime = newClosingTime;
    }
// Solidity 0.6.12
/**
 	 * @notice Performs the minting of gcToken shares upon the deposit of the
 	 *         cToken underlying asset. The funds will be pulled in by this
 	 *         contract, therefore they must be previously approved. This
 	 *         function builds upon the GTokenBase deposit function. See
 	 *         GTokenBase.sol for further documentation.
 	 * @param _underlyingCost The amount of the underlying asset being
 	 *                        deposited in the operation.
 	 */
function depositUnderlying(uint256 _underlyingCost) public override nonReentrant
	{
		address _from = msg.sender;
		require(_underlyingCost > 0, "underlying cost must be greater than 0");
		uint256 _cost = GCFormulae._calcCostFromUnderlyingCost(_underlyingCost, exchangeRate());
		(uint256 _netShares, uint256 _feeShares) = GFormulae._calcDepositSharesFromCost(_cost, totalReserve(), totalSupply(), depositFee());
		require(_netShares > 0, "shares must be greater than 0");
		G.pullFunds(underlyingToken, _from, _underlyingCost);
		GC.safeLend(reserveToken, _underlyingCost);
		require(_prepareDeposit(_cost), "not available at the moment");
		_mint(_from, _netShares);
		_mint(address(this), _feeShares.div(2));
	}
// Solidity 0.6.12
/**
 	 * @notice Performs the burning of gcToken shares upon the withdrawal of
 	 *         the underlying asset. This function builds upon the
 	 *         GTokenBase withdrawal function. See GTokenBase.sol for
 	 *         further documentation.
 	 * @param _grossShares The gross amount of this gcToken shares being
 	 *                     redeemed in the operation.
 	 */
function withdrawUnderlying(uint256 _grossShares) public override nonReentrant
	{
		address _from = msg.sender;
		require(_grossShares > 0, "shares must be greater than 0");
		(uint256 _cost, uint256 _feeShares) = GFormulae._calcWithdrawalCostFromShares(_grossShares, totalReserve(), totalSupply(), withdrawalFee());
		uint256 _underlyingCost = GCFormulae._calcUnderlyingCostFromCost(_cost, exchangeRate());
		require(_underlyingCost > 0, "underlying cost must be greater than 0");
		require(_prepareWithdrawal(_cost), "not available at the moment");
		_underlyingCost = G.min(_underlyingCost, GC.getLendAmount(reserveToken));
		GC.safeRedeem(reserveToken, _underlyingCost);
		G.pushFunds(underlyingToken, _from, _underlyingCost);
		_burn(_from, _grossShares);
		_mint(address(this), _feeShares.div(2));
	}
// Solidity 0.4.25
// @notice Multiplies two numbers, throws on overflow.
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
    if (a == 0) {
      return 0;
    }
    uint256 c = a * b;
    assert(c / a == b);
    return c;
  }
// Solidity 0.4.25
// @notice Integer division of two numbers, truncating the quotient.
function div(uint256 a, uint256 b) internal pure returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    // uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return a / b;
  }
// Solidity 0.8.1
/**
 * @notice Deposits funds in the current mint batch
 * @param _amount Amount of 3cr3CRV to use for minting
 * @param _depositFor User that gets the shares attributed to (for use in zapper contract)
 */
function depositForMint(uint256 _amount, address _depositFor)
    external
    nonReentrant
    whenNotPaused
    onlyApprovedContractOrEOA
  {
    require(
      _hasRole(keccak256("ButterZapper"), msg.sender) || msg.sender == _depositFor,
      "you cant transfer other funds"
    );
    require(threeCrv.balanceOf(msg.sender) >= _amount, "insufficent balance");
    threeCrv.transferFrom(msg.sender, address(this), _amount);
    _deposit(_amount, currentMintBatchId, _depositFor);
  }
// Solidity 0.8.1
/**
 * @notice This function allows a user to withdraw their funds from a batch before that batch has been processed
 * @param _batchId From which batch should funds be withdrawn from
 * @param _amountToWithdraw Amount of Butter or 3CRV to be withdrawn from the queue (depending on mintBatch / redeemBatch)
 * @param _withdrawFor User that gets the shares attributed to (for use in zapper contract)
 */
function withdrawFromBatch(
    bytes32 _batchId,
    uint256 _amountToWithdraw,
    address _withdrawFor
  ) external {
    address recipient = _getRecipient(_withdrawFor);

    Batch storage batch = batches[_batchId];
    uint256 accountBalance = accountBalances[_batchId][_withdrawFor];
    require(batch.claimable == false, "already processed");
    require(accountBalance >= _amountToWithdraw, "account has insufficient funds");

    //At this point the account balance is equal to the supplied token and can be used interchangeably
    accountBalances[_batchId][_withdrawFor] = accountBalance - _amountToWithdraw;
    batch.suppliedTokenBalance = batch.suppliedTokenBalance - _amountToWithdraw;
    batch.unclaimedShares = batch.unclaimedShares - _amountToWithdraw;

    if (batch.batchType == BatchType.Mint) {
      threeCrv.safeTransfer(recipient, _amountToWithdraw);
    } else {
      setToken.safeTransfer(recipient, _amountToWithdraw);
    }
    emit WithdrawnFromBatch(_batchId, _amountToWithdraw, _withdrawFor);
  }
// Solidity 0.8.1
/**
 * @notice Claims funds after the batch has been processed (get Butter from a mint batch and 3CRV from a redeem batch)
 * @param _batchId Id of batch to claim from
 * @param _claimFor User that gets the shares attributed to (for use in zapper contract)
 */
function claim(bytes32 _batchId, address _claimFor) external returns (uint256) {
    (address recipient, BatchType batchType, uint256 accountBalance, uint256 tokenAmountToClaim) = _prepareClaim(
      _batchId,
      _claimFor
    );
    //Transfer token
    if (batchType == BatchType.Mint) {
      setToken.safeTransfer(recipient, tokenAmountToClaim);
    } else {
      //We only want to apply a fee on redemption of Butter
      //Sweethearts are partner addresses that we want to exclude from this fee
      if (!sweethearts[_claimFor]) {
        //Fee is deducted from threeCrv -- This allows it to work with the Zapper
        //Fes are denominated in BasisPoints
        uint256 fee = (tokenAmountToClaim * redemptionFee.rate) / 10_000;
        redemptionFee.accumulated += fee;
        tokenAmountToClaim = tokenAmountToClaim - fee;
      }
      threeCrv.safeTransfer(recipient, tokenAmountToClaim);
    }
    emit Claimed(recipient, batchType, accountBalance, tokenAmountToClaim);

    return tokenAmountToClaim;
  }
// Solidity 0.8.1
/**
 * @notice Claims BTR after batch has been processed and stakes it in Staking.sol
 * @param _batchId Id of batch to claim from
 * @param _claimFor User that gets the shares attributed to (for use in zapper contract)
 */
function claimAndStake(bytes32 _batchId, address _claimFor) external {
    (address recipient, BatchType batchType, uint256 accountBalance, uint256 tokenAmountToClaim) = _prepareClaim(
      _batchId,
      _claimFor
    );
    emit Claimed(recipient, batchType, accountBalance, tokenAmountToClaim);

    //Transfer token
    require(batchType == BatchType.Mint, "Can only stake BTR");
    staking.stakeFor(tokenAmountToClaim, recipient);
  }
// Solidity 0.8.1
/**
 * @notice sets approval for contracts that require access to assets held by this contract
 */
function setApprovals() external {
    (address[] memory tokenAddresses, ) = setBasicIssuanceModule.getRequiredComponentUnitsForIssue(setToken, 1e18);

    for (uint256 i; i < tokenAddresses.length; i++) {
      IERC20 curveLpToken = curvePoolTokenPairs[tokenAddresses[i]].crvLPToken;
      CurveMetapool curveMetapool = curvePoolTokenPairs[tokenAddresses[i]].curveMetaPool;
      YearnVault yearnVault = YearnVault(tokenAddresses[i]);

      _maxApprove(curveLpToken, address(curveMetapool));
      _maxApprove(curveLpToken, address(yearnVault));
      _maxApprove(threeCrv, address(curveMetapool));
    }
    _maxApprove(IERC20(address(setToken)), address(staking));
  }
// Solidity 0.8.1
/**
 * @notice returns the min amount of butter that should be minted given an amount of 3crv
 * @dev this controls slippage in the minting process
 */
function getMinAmountToMint(
    uint256 _valueOfBatch,
    uint256 _valueOfComponentsPerUnit,
    uint256 _slippage
  ) public pure returns (uint256) {
    uint256 _mintAmount = (_valueOfBatch * 1e18) / _valueOfComponentsPerUnit;
    uint256 _delta = (_mintAmount * _slippage) / 10_000;
    return _mintAmount - _delta;
  }
// Solidity 0.4.25
// ACTIONS WITH OWN TOKEN
function sendToNest(
        address _sender,
        uint256 _eggId
    ) external onlyController returns (bool, uint256, uint256, address) {
        require(!getter.isEggOnSale(_eggId), "egg is on sale");
        require(core.isEggOwner(_sender, _eggId), "not an egg owner");

        uint256 _hatchingPrice = treasury.hatchingPrice();
        treasury.takeGold(_hatchingPrice);
        if (getter.getDragonsAmount() > 2997) { // 2997 + 2 (in the nest) + 1 (just sent) = 3000 dragons without gold burning
            treasury.burnGold(_hatchingPrice.div(2));
        }

        return core.sendToNest(_eggId);
    }
// Solidity 0.8.1
/**
 * @notice returns the value of butter in virtualPrice
 */
function valueOfComponents(address[] memory _tokenAddresses, uint256[] memory _quantities)
    public
    view
    returns (uint256)
  {
    uint256 value;
    for (uint256 i = 0; i < _tokenAddresses.length; i++) {
      value +=
        (((YearnVault(_tokenAddresses[i]).pricePerShare() *
          curvePoolTokenPairs[_tokenAddresses[i]].curveMetaPool.get_virtual_price()) / 1e18) * _quantities[i]) /
        1e18;
    }
    return value;
  }
// Solidity 0.8.1
/**
 * @notice makes sure only zapper or user can withdraw from accout_ and returns the recipient of the withdrawn token
 * @param _account is the address which gets withdrawn from
 * @dev returns recipient of the withdrawn funds
 * @dev By default a user should set _account to their address
 * @dev If zapper is used to withdraw and swap for a user the msg.sender will be zapper and _account is the user which we withdraw from. The zapper than sends the swapped funds afterwards to the user
 */
function _getRecipient(address _account) internal view returns (address) {
    //Make sure that only zapper can withdraw from someone else
    require(_hasRole(keccak256("ButterZapper"), msg.sender) || msg.sender == _account, "you cant transfer other funds");

    //Set recipient per default to _account
    address recipient = _account;

    //set the recipient to zapper if its called by the zapper
    if (_hasRole(keccak256("ButterZapper"), msg.sender)) {
      recipient = msg.sender;
    }
    return recipient;
  }
// Solidity 0.8.1
/**
 * @notice Generates the next batch id for new deposits
 * @param _currentBatchId takes the current mint or redeem batch id
 * @param _batchType BatchType of the newly created id
 */
function _generateNextBatch(bytes32 _currentBatchId, BatchType _batchType) internal returns (bytes32) {
    bytes32 id = _generateNextBatchId(_currentBatchId);
    batchIds.push(id);
    Batch storage batch = batches[id];
    batch.batchType = _batchType;
    batch.batchId = id;

    if (BatchType.Mint == _batchType) {
      currentMintBatchId = id;
      batch.suppliedTokenAddress = address(threeCrv);
      batch.claimableTokenAddress = address(setToken);
    }
    if (BatchType.Redeem == _batchType) {
      currentRedeemBatchId = id;
      batch.suppliedTokenAddress = address(setToken);
      batch.claimableTokenAddress = address(threeCrv);
    }
    return id;
  }
// Solidity 0.8.1
/**
 * @notice Deposit either Butter or 3CRV in their respective batches
 * @param _amount The amount of 3CRV or Butter a user is depositing
 * @param _currentBatchId The current reedem or mint batch id to place the funds in the next batch to be processed
 * @param _depositFor User that gets the shares attributed to (for use in zapper contract)
 * @dev This function will be called by depositForMint or depositForRedeem and simply reduces code duplication
 */
function _deposit(
    uint256 _amount,
    bytes32 _currentBatchId,
    address _depositFor
  ) internal {
    Batch storage batch = batches[_currentBatchId];

    //Add the new funds to the batch
    batch.suppliedTokenBalance = batch.suppliedTokenBalance + _amount;
    batch.unclaimedShares = batch.unclaimedShares + _amount;
    accountBalances[_currentBatchId][_depositFor] = accountBalances[_currentBatchId][_depositFor] + _amount;

    //Save the batchId for the user so they can be retrieved to claim the batch
    if (
      accountBatches[_depositFor].length == 0 ||
      accountBatches[_depositFor][accountBatches[_depositFor].length - 1] != _currentBatchId
    ) {
      accountBatches[_depositFor].push(_currentBatchId);
    }

    emit Deposit(_depositFor, _amount);
  }
// Solidity 0.8.1
/**
 * @notice This function checks all requirements for claiming, updates batches and balances and returns the values needed for the final transfer of tokens
 * @param _batchId Id of batch to claim from
 * @param _claimFor User that gets the shares attributed to (for use in zapper contract)
 */
function _prepareClaim(bytes32 _batchId, address _claimFor)
    internal
    returns (
      address,
      BatchType,
      uint256,
      uint256
    )
  {
    Batch storage batch = batches[_batchId];
    require(batch.claimable, "not yet claimable");

    address recipient = _getRecipient(_claimFor);
    uint256 accountBalance = accountBalances[_batchId][_claimFor];
    require(accountBalance <= batch.unclaimedShares, "claiming too many shares");

    //Calculate how many token will be claimed
    uint256 tokenAmountToClaim = (batch.claimableTokenBalance * accountBalance) / batch.unclaimedShares;

    //Subtract the claimed token from the batch
    batch.claimableTokenBalance = batch.claimableTokenBalance - tokenAmountToClaim;
    batch.unclaimedShares = batch.unclaimedShares - accountBalance;
    accountBalances[_batchId][_claimFor] = 0;

    return (recipient, batch.batchType, accountBalance, tokenAmountToClaim);
  }
// Solidity 0.8.1
/**
 * @notice Deposit 3CRV in a curve metapool for its LP-Token
 * @param _amount The amount of 3CRV that gets deposited
 * @param _curveMetapool The metapool where we want to provide liquidity
 */
function _sendToCurve(uint256 _amount, CurveMetapool _curveMetapool) internal {
    //Takes 3CRV and sends lpToken to this contract
    //Metapools take an array of amounts with the exoctic stablecoin at the first spot and 3CRV at the second.
    //The second variable determines the min amount of LP-Token we want to receive (slippage control)
    _curveMetapool.add_liquidity([0, _amount], 0);
  }
// Solidity 0.8.1
/**
 * @notice Withdraws 3CRV for deposited crvLPToken
 * @param _amount The amount of crvLPToken that get deposited
 * @param _curveMetapool The metapool where we want to provide liquidity
 */
function _withdrawFromCurve(uint256 _amount, CurveMetapool _curveMetapool) internal {
    //Takes lp Token and sends 3CRV to this contract
    //The second variable is the index for the token we want to receive (0 = exotic stablecoin, 1 = 3CRV)
    //The third variable determines min amount of token we want to receive (slippage control)
    _curveMetapool.remove_liquidity_one_coin(_amount, 1, 0);
  }
// Solidity 0.8.1
/**
 * @notice Changes the the ProcessingThreshold
 * @param _cooldown Cooldown in seconds
 * @param _mintThreshold Amount of MIM necessary to mint immediately
 * @param _redeemThreshold Amount of Butter necessary to mint immediately
 * @dev The cooldown is the same for redeem and mint batches
 */
function setProcessingThreshold(
    uint256 _cooldown,
    uint256 _mintThreshold,
    uint256 _redeemThreshold
  ) public onlyRole(DAO_ROLE) {
    ProcessingThreshold memory newProcessingThreshold = ProcessingThreshold({
      batchCooldown: _cooldown,
      mintThreshold: _mintThreshold,
      redeemThreshold: _redeemThreshold
    });
    emit ProcessingThresholdUpdated(processingThreshold, newProcessingThreshold);
    processingThreshold = newProcessingThreshold;
  }
// Solidity 0.8.1
/**
 * @notice sets slippage for mint and redeem
 * @param _mintSlippage amount in bps (e.g. 50 = 0.5%)
 * @param _redeemSlippage amount in bps (e.g. 50 = 0.5%)
 */
function setSlippage(uint256 _mintSlippage, uint256 _redeemSlippage) external onlyRole(DAO_ROLE) {
    require(_mintSlippage <= 200 && _redeemSlippage <= 200, "slippage too high");
    Slippage memory newSlippage = Slippage({ mintBps: _mintSlippage, redeemBps: _redeemSlippage });
    emit SlippageUpdated(slippage, newSlippage);
    slippage = newSlippage;
  }
// Solidity 0.4.24
// Assign tokens to investor with locking period
function assignToken(address _investor,uint256 _tokens) external {
        // Tokens assigned by only Angel Sales,PE Sales,Founding Investor and Initiator Team wallets
        require(msg.sender == walletAddresses[0] || msg.sender == walletAddresses[1] || msg.sender == walletAddresses[2] || msg.sender == walletAddresses[3]);

        // Check investor address and tokens.Not allow 0 value
        require(_investor != address(0) && _tokens > 0);
        // Check wallet have enough token balance to assign
        require(_tokens <= balances[msg.sender]);
        
        // Debit the tokens from the wallet
        balances[msg.sender] = safeSub(balances[msg.sender],_tokens);

        // Assign tokens to the investor
        if(msg.sender == walletAddresses[0] || msg.sender == walletAddresses[1]){
            walletAngelPESales[_investor] = safeAdd(walletAngelPESales[_investor],_tokens);
        }
        else if(msg.sender == walletAddresses[2] || msg.sender == walletAddresses[3]){
            walletFoundingInitiatorSales[_investor] = safeAdd(walletFoundingInitiatorSales[_investor],_tokens);
        }
        else{
            revert();
        }
    }