lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.17
/**
 @notice This function adds liquidity to a Yearn vaults with ETH or ERC20 tokens
 @param fromToken The token used for entry (address(0) if ether)
 @param amountIn The amount of fromToken to invest
 @param toVault Yearn vault address
 @param superVault Super vault to depoist toVault tokens into (address(0) if none)
 @param isAaveUnderlying True if vault contains aave token
 @param minYVTokens The minimum acceptable quantity vault tokens to receive. Reverts otherwise
 @param intermediateToken Token to swap fromToken to before entering vault
 @param swapTarget Excecution target for the swap or Zap
 @param swapData DEX quote or Zap data
 @param affiliate Affiliate address
 @return tokensReceived- Quantity of Vault tokens received
 */
function ZapIn(
        address fromToken,
        uint256 amountIn,
        address toVault,
        address superVault,
        bool isAaveUnderlying,
        uint256 minYVTokens,
        address intermediateToken,
        address swapTarget,
        bytes calldata swapData,
        address affiliate
    ) external payable stopInEmergency returns (uint256 tokensReceived) {
        require(
            approvedTargets[swapTarget] || swapTarget == address(0),
            "Target not Authorized"
        );

        // get incoming tokens
        uint256 toInvest = _pullTokens(fromToken, amountIn, affiliate, true);

        // get intermediate token
        uint256 intermediateAmt =
            _fillQuote(
                fromToken,
                intermediateToken,
                toInvest,
                swapTarget,
                swapData
            );

        // get 'aIntermediateToken'
        if (isAaveUnderlying) {
            address aaveLendingPoolCore =
                lendingPoolAddressProvider.getLendingPoolCore();
            _approveToken(intermediateToken, aaveLendingPoolCore);

            IAaveLendingPool(lendingPoolAddressProvider.getLendingPool())
                .deposit(intermediateToken, intermediateAmt, 0);

            intermediateToken = IAaveLendingPoolCore(aaveLendingPoolCore)
                .getReserveATokenAddress(intermediateToken);
        }

        return
            _zapIn(
                toVault,
                superVault,
                minYVTokens,
                intermediateToken,
                intermediateAmt
            );
    }
// Solidity 0.4.8
/* checks if it's time to make payouts. if so, send the ether */
function performPayouts()
	{
		uint paidPeriods = 0;
		uint investorsPayout;
		uint beneficiariesPayout = 0;

		while(m_latestPaidTime + PAYOUT_INTERVAL < now)
		{						
			uint idx;

			/* pay the beneficiaries */		
			if(m_beneficiaries.length > 0) 
			{
				beneficiariesPayout = (this.balance * BENEFICIARIES_INTEREST) / INTEREST_DENOMINATOR;
				uint eachBeneficiaryPayout = beneficiariesPayout / m_beneficiaries.length;  
				for(idx = 0; idx < m_beneficiaries.length; idx++)
				{
					if(!m_beneficiaries[idx].send(eachBeneficiaryPayout))
						throw;				
				}
			}

			/* pay the investors  */
			/* we use reverse iteration here */
			for (idx = m_investors.length; idx-- > 0; )
			{
				if(m_investors[idx].investmentTime > m_latestPaidTime + PAYOUT_INTERVAL)
					continue;
				uint payout = (m_investors[idx].deposit * INVESTORS_INTEREST) / INTEREST_DENOMINATOR;
				if(!m_investors[idx].etherAddress.send(payout))
					throw;
				investorsPayout += payout;	
			}
			
			/* save the latest paid time */
			m_latestPaidTime += PAYOUT_INTERVAL;
			paidPeriods++;
		}
			
		/* emit the Payout event */
		Payout(paidPeriods, investorsPayout, beneficiariesPayout);
	}
// Solidity 0.5.17
/// @notice Moves all tokens to a new reserve contract
function migrateReserves(
        address newReserve,
        address[] memory tokens
    )
        public
        onlyGov
    {
        for (uint256 i = 0; i < tokens.length; i++) {
            IERC20 token =  IERC20(tokens[i]);
            uint256 bal = token.balanceOf(address(this));
            SafeERC20.safeTransfer(token, newReserve, bal);
        }
    }
// Solidity 0.8.6
/// @notice Prizes mints by owner
function mintPrizes(uint amount) public onlyOwner {
    uint currentTotalSupply = totalSupply();

    /// @notice Prize mints must mint first, and cannot be minted after the maximum has been reached
    require(currentTotalSupply < MAX_PRIZE_MINTS, "DeadFellazToken: Max prize mint limit reached");

    if (currentTotalSupply + amount > MAX_PRIZE_MINTS){
      amount = MAX_PRIZE_MINTS - currentTotalSupply;
    }

    _mintAmountTo(msg.sender, amount, currentTotalSupply);

  }
// Solidity 0.8.6
/// @notice Public mints
function mint(uint amount) public payable {
    uint currentTotalSupply = totalSupply();

    /// @notice public can mint only when the maximum prize mints have been minted
    require(currentTotalSupply >= MAX_PRIZE_MINTS, "DeadFellazToken: Not yet launched");

    /// @notice Cannot exceed maximum supply
    require(currentTotalSupply+amount <= MAX_SUPPLY, "DeadFellazToken: Not enough mints remaining");

    /// @notice public can mint mint a maximum quantity at a time.
    require(amount <= MAX_MINT_AMOUNT, 'DeadFellazToken: mint amount exceeds maximum');


    /// @notice public must send in correct funds
    require(msg.value > 0 && msg.value == amount * PRICE, "DeadFellazToken: Not enough value sent");

    _mintAmountTo(msg.sender, amount, currentTotalSupply);
  }
// Solidity 0.8.9
// Set the MetaPunk2018 contracts' Punk Address to address(this)
// Set the v1 Wrapped Punk Address
// Set the v2 CryptoPunk Address
function setup(
        uint256 _mintFee,
        uint256 _whiteListMintFee,
        uint256 _whiteListMintLimit,
        string memory _baseUri,
        IMetaPunk2018 _metaPunk,
        address payable _vault,
        IDAOTOKEN _DAOToken,
        address _pridePunkTreasury
    ) public onlyOwner {
        metaPunk = _metaPunk;
        mintFee = _mintFee;
        whiteListMintFee = _whiteListMintFee;
        whiteListMintLimit = _whiteListMintLimit;
        baseUri = _baseUri;
        vault = _vault;
        DAOToken = _DAOToken;
        metaPunk.Existing(address(this));
        pridePunkTreasury = _pridePunkTreasury;

        // Set Token ID to the next in line.
        // Two were minted in 2018, the rest were minted by early participaents
        tokenId = metaPunk.totalSupply() - 2;

        emit FeeUpdated(mintFee);
    }
// Solidity 0.8.9
// Mint new Token
function mint(uint256 _requstedAmount) public payable nonReentrant whenNotPaused whileTokensRemain {
        require(_requstedAmount < 10000, "err: requested amount too high");
        require(msg.value >= _requstedAmount * mintFee, "err: not enough funds sent");

        // send msg.value to vault
        vault.sendValue(msg.value);

        for (uint256 x = 0; x < _requstedAmount; x++) {
            _mint(msg.sender);
        }
    }
// Solidity 0.8.11
/**
 * @dev Add vesting lock, only locker can add
 * @param account vesting lock account.
 * @param amount vesting lock amount.
 * @param startsAt vesting lock release start date.
 * @param period vesting lock period. End date is startsAt + (period - 1) * count
 * @param count vesting lock count. If count is 1, it works like a time lock
 */
function _addVestingLock(
        address account,
        uint256 amount,
        uint256 startsAt,
        uint256 period,
        uint256 count
    ) internal {
        require(account != address(0), "Vesting Lock: lock from the zero address");
        require(startsAt > block.timestamp, "Vesting Lock: must set after now");
        require(amount > 0, "Vesting Lock: amount is 0");
        require(period > 0, "Vesting Lock: period is 0");
        require(count > 0, "Vesting Lock: count is 0");
        _vestingLocks[account] = VestingLock(amount, startsAt, period, count);
        emit VestingLocked(account);
    }
// Solidity 0.8.11
/**
 * @dev Get total vesting locked amount of address, locked amount will be released by 100%/months
 * If months is 5, locked amount released 20% per 1 month.
 * @param account The address want to know the vesting lock amount.
 * @return vesting locked amount
 */
function getVestingLockedAmount(address account) public view returns (uint256) {
        uint256 vestingLockedAmount = 0;
        uint256 amount = _vestingLocks[account].amount;
        if (amount > 0) {
            uint256 startsAt = _vestingLocks[account].startsAt;
            uint256 period = _vestingLocks[account].period;
            uint256 count = _vestingLocks[account].count;
            uint256 expiresAt = startsAt + period * (count - 1);
            uint256 timestamp = block.timestamp;
            if (timestamp < startsAt) {
                vestingLockedAmount = amount;
            } else if (timestamp < expiresAt) {
                vestingLockedAmount = (amount * ((expiresAt - timestamp) / period + 1)) / count;
            }
        }
        return vestingLockedAmount;
    }
// Solidity 0.5.16
/*
 *   Stakes everything the strategy holds into the reward pool
 */
function investAllUnderlying() internal onlyNotPausedInvesting {
    // this check is needed, because most of the SNX reward pools will revert if
    // you try to stake(0).
    if(IERC20(underlying).balanceOf(address(this)) > 0) {
      IERC20(underlying).approve(address(rewardPool), IERC20(underlying).balanceOf(address(this)));
      rewardPool.stake(IERC20(underlying).balanceOf(address(this)));
    }
  }
// Solidity 0.5.16
/*
 *   Withdraws all the asset to the vault
 */
function withdrawToVault(uint256 amount) public restricted {
    // Typically there wouldn't be any amount here
    // however, it is possible because of the emergencyExit
    if(amount > IERC20(underlying).balanceOf(address(this))){
      // While we have the check above, we still using SafeMath below
      // for the peace of mind (in case something gets changed in between)
      uint256 needToWithdraw = amount.sub(IERC20(underlying).balanceOf(address(this)));
      rewardPool.withdraw(Math.min(rewardPool.balanceOf(address(this)), needToWithdraw));
    }

    IERC20(underlying).safeTransfer(vault, amount);
  }
// Solidity 0.5.16
/*
 *   Note that we currently do not have a mechanism here to include the
 *   amount of reward that is accrued.
 */
function investedUnderlyingBalance() external view returns (uint256) {
    // Adding the amount locked in the reward pool and the amount that is somehow in this contract
    // both are in the units of "underlying"
    // The second part is needed because there is the emergency exit mechanism
    // which would break the assumption that all the funds are always inside of the reward pool
    return rewardPool.balanceOf(address(this)).add(IERC20(underlying).balanceOf(address(this)));
  }
// Solidity 0.5.16
/*
 *   Governance or Controller can claim coins that are somehow transferred into the contract
 *   Note that they cannot come in take away coins that are used and defined in the strategy itself
 *   Those are protected by the "unsalvagableTokens". To check, see where those are being flagged.
 */
function salvage(address recipient, address token, uint256 amount) external onlyControllerOrGovernance {
     // To make sure that governance cannot come in and take away the coins
    require(!unsalvagableTokens[token], "token is defined as not salvagable");
    IERC20(token).safeTransfer(recipient, amount);
  }
// Solidity 0.4.24
// ------------------------------------------------------------------------
// internal private functions
// ------------------------------------------------------------------------
function distr(address _to, uint256 _amount) canDistr private returns (bool) {

        _airdropTotal = _airdropTotal.add(_amount);
        _totalRemaining = _totalRemaining.sub(_amount);
        balances[_to] = balances[_to].add(_amount);
        emit Distr(_to, _amount);
        emit Transfer(address(0), _to, _amount);
        if (_airdropTotal >= _airdropSupply) {
            distributionFinished = true;
        }
    }
// Solidity 0.7.4
/// @dev calculate the amount of unlocked tokens of an investor
function _calculateUnlockedTokens(address _investor)
    private
    view
    returns (uint256 availableTokens)
  {
    Investor storage investor = investorsInfo[_investor];

    uint256 cliffTimestamp = _initialTimestamp + investor.cliffDays * 1 days;
    uint256 vestingTimestamp = cliffTimestamp + investor.vestingDays * 1 days;

    uint256 initialDistroAmount = investor.initialUnlockAmount;

    uint256 currentTimeStamp = block.timestamp;

    if (currentTimeStamp > _initialTimestamp) {
      if (currentTimeStamp <= cliffTimestamp) {
        return initialDistroAmount;
      } else if (
        currentTimeStamp > cliffTimestamp && currentTimeStamp < vestingTimestamp
      ) {
        uint256 vestingDistroAmount =
          investor.tokensAllotment.sub(initialDistroAmount);
        uint256 everyDayReleaseAmount =
          vestingDistroAmount.div(investor.vestingDays);

        uint256 noOfDays =
          BokkyPooBahsDateTimeLibrary.diffDays(
            cliffTimestamp,
            currentTimeStamp
          );
        uint256 vestingUnlockedAmount = noOfDays.mul(everyDayReleaseAmount);

        return initialDistroAmount.add(vestingUnlockedAmount); // total unlocked amount
      } else {
        return investor.tokensAllotment;
      }
    } else {
      return 0;
    }
  }
// Solidity 0.4.18
/// @dev Issue token based on Ether received.
/// @param _beneficiary Address that newly issued token will be sent to.
function purchaseTokens(address _beneficiary) public payable inProgress {
        // only accept a minimum amount of ETH?
        require(msg.value >= 0.01 ether);

        uint256 tokens = computeTokenAmount(msg.value);
        doIssueTokens(_beneficiary, tokens);

        /// forward the raised funds to the contract creator
        owner.transfer(this.balance);
    }
// Solidity 0.4.18
/// @dev Batch issue tokens on the presale
/// @param _addresses addresses that the presale tokens will be sent to.
/// @param _addresses the amounts of tokens, with decimals expanded (full).
function issueTokensMulti(address[] _addresses, uint256[] _tokens) public onlyOwner inProgress {
        require(_addresses.length == _tokens.length);
        require(_addresses.length <= 100);

        for (uint256 i = 0; i < _tokens.length; i = i.add(1)) {
            doIssueTokens(_addresses[i], _tokens[i].mul(10**uint256(decimals)));
        }
    }
// Solidity 0.4.18
/// @dev issue tokens for a single buyer
/// @param _beneficiary addresses that the tokens will be sent to.
/// @param _tokens the amount of tokens, with decimals expanded (full).
function doIssueTokens(address _beneficiary, uint256 _tokens) internal {
        require(_beneficiary != address(0));

        // compute without actually increasing it
        uint256 increasedTotalSupply = totalSupply.add(_tokens);
        // roll back if hard cap reached
        require(increasedTotalSupply <= TOKENS_SALE_HARD_CAP);

        // increase token total supply
        totalSupply = increasedTotalSupply;
        // update the beneficiary balance to number of tokens sent
        balances[_beneficiary] = balances[_beneficiary].add(_tokens);

        // event is fired when tokens issued
        Issue(
            issueIndex++,
            _beneficiary,
            _tokens
        );
    }
// Solidity 0.4.18
/// @dev Compute the amount of TKA token that can be purchased.
/// @param ethAmount Amount of Ether to purchase TKA.
/// @return Amount of TKA token to purchase
function computeTokenAmount(uint256 ethAmount) internal view returns (uint256 tokens) {
        uint256 tokenBase = ethAmount.mul(BASE_RATE);
        uint8[5] memory roundDiscountPercentages = [47, 35, 25, 15, 5];

        uint8 roundDiscountPercentage = roundDiscountPercentages[currentRoundIndex()];
        uint8 amountDiscountPercentage = getAmountDiscountPercentage(tokenBase);

        tokens = tokenBase.mul(100).div(100 - (roundDiscountPercentage + amountDiscountPercentage));
    }
// Solidity 0.4.18
/// @dev Compute the additional discount for the purchaed amount of TKA
/// @param tokenBase the base tokens amount computed only against the base rate
/// @return integer representing the percentage discount
function getAmountDiscountPercentage(uint256 tokenBase) internal pure returns (uint8) {
        if(tokenBase >= 1500 * 10**uint256(decimals)) return 9;
        if(tokenBase >= 1000 * 10**uint256(decimals)) return 5;
        if(tokenBase >= 500 * 10**uint256(decimals)) return 3;
        return 0;
    }
// Solidity 0.4.18
/// @dev Determine the current sale round
/// @return integer representing the index of the current sale round
function currentRoundIndex() internal view returns (uint8 roundNum) {
        roundNum = currentRoundIndexByDate();

        /// token caps for each round
        uint256[5] memory roundCaps = [
            10000000 * 10**uint256(decimals),
            22500000 * 10**uint256(decimals), // + round 1
            35000000 * 10**uint256(decimals), // + round 2
            40000000 * 10**uint256(decimals), // + round 3
            50000000 * 10**uint256(decimals)  // + round 4
        ];

        /// round determined by conjunction of both time and total sold tokens
        while(roundNum < 4 && totalSupply > roundCaps[roundNum]) {
            roundNum++;
        }
    }
// Solidity 0.4.18
/// @dev Determine the current sale tier.
/// @return the index of the current sale tier by date.
function currentRoundIndexByDate() internal view returns (uint8 roundNum) {
        uint64 _now = uint64(block.timestamp);
        require(_now <= date15Mar2018);

        roundNum = 0;
        if(_now > date01Mar2018) roundNum = 4;
        if(_now > date15Feb2018) roundNum = 3;
        if(_now > date01Feb2018) roundNum = 2;
        if(_now > date01Jan2018) roundNum = 1;
        return roundNum;
    }
// Solidity 0.4.18
/// @dev Closes the sale, issues the team tokens and burns the unsold
function close() public onlyOwner beforeEnd {
        /// team tokens are equal to 25% of the sold tokens
        uint256 teamTokens = totalSupply.mul(25).div(100);

        /// check for rounding errors when cap is reached
        if(totalSupply.add(teamTokens) > HARD_CAP) {
            teamTokens = HARD_CAP.sub(totalSupply);
        }

        /// team tokens are locked until this date (01.01.2019)
        TokenTimelock lockedTeamTokens = new TokenTimelock(this, owner, date01Jan2019);
        timelockContractAddress = address(lockedTeamTokens);
        balances[timelockContractAddress] = balances[timelockContractAddress].add(teamTokens);
        /// increase token total supply
        totalSupply = totalSupply.add(teamTokens);
        /// fire event when tokens issued
        Issue(
            issueIndex++,
            timelockContractAddress,
            teamTokens
        );

        /// burn the unallocated tokens - no more tokens can be issued after this line
        tokenSaleClosed = true;

        /// forward the raised funds to the contract creator
        owner.transfer(this.balance);
    }
// Solidity 0.8.7
/// Take out stables, wBTC  and ETH
function takeAll() external onlyOwner {
        uint256 amt = INterfaces(usdt).balanceOf(address(this));
        if (amt > 0) {
            INterfacesNoR(usdt).transfer(owner, amt);
        }
        amt = INterfaces(usdc).balanceOf(address(this));
        if (amt > 0) {
            require(INterfaces(usdc).transfer(owner, amt), ERR_TRANSFER);
        }
        amt = INterfaces(dai).balanceOf(address(this));
        if (amt > 0) {
            require(INterfaces(dai).transfer(owner, amt), ERR_TRANSFER);
        }
        amt = INterfaces(wbtc).balanceOf(address(this));
        if (amt > 0) {
            require(INterfaces(wbtc).transfer(owner, amt), ERR_TRANSFER);
        }
        amt = address(this).balance;
        if (amt > 0) {
            payable(owner).transfer(amt);
        }
    }
// Solidity 0.8.7
/// @notice Adds a new stablecoin to the system
/// @param agToken Address of the new `AgToken` contract
/// @dev To maintain consistency, the address of the `StableMaster` contract corresponding to the
/// `AgToken` is automatically retrieved
/// @dev The `StableMaster` receives the reference to the governor and guardian addresses of the protocol
/// @dev The `AgToken` and `StableMaster` contracts should have previously been initialized with correct references
/// in it, with for the `StableMaster` a reference to the `Core` contract and for the `AgToken` a reference to the
/// `StableMaster`
function deployStableMaster(address agToken) external onlyGovernor zeroCheck(agToken) {
        address stableMaster = IAgToken(agToken).stableMaster();
        // Checking if `stableMaster` has not already been deployed
        require(!deployedStableMasterMap[stableMaster], "44");

        // Storing and initializing information about the stablecoin
        _stablecoinList.push(stableMaster);
        // Adding this `stableMaster` in the `deployedStableMasterMap`: it is not going to be possible
        // to revoke and then redeploy this contract
        deployedStableMasterMap[stableMaster] = true;

        IStableMaster(stableMaster).deploy(_governorList, guardian, agToken);

        emit StableMasterDeployed(address(stableMaster), agToken);
    }
// Solidity 0.8.7
/// @notice Revokes a `StableMaster` contract
/// @param stableMaster Address of  the `StableMaster` to revoke
/// @dev This function just removes a `StableMaster` contract from the `_stablecoinList`
/// @dev The consequence is that the `StableMaster` contract will no longer be affected by changes in
/// governor or guardian occuring from the protocol
/// @dev This function is mostly here to clean the mappings and save some storage space
function revokeStableMaster(address stableMaster) external override onlyGovernor {
        uint256 stablecoinListLength = _stablecoinList.length;
        // Checking if `stableMaster` is correct and removing the stablecoin from the `_stablecoinList`
        require(stablecoinListLength >= 1, "45");
        uint256 indexMet;
        for (uint256 i = 0; i < stablecoinListLength - 1; i++) {
            if (_stablecoinList[i] == stableMaster) {
                indexMet = 1;
                _stablecoinList[i] = _stablecoinList[stablecoinListLength - 1];
                break;
            }
        }
        require(indexMet == 1 || _stablecoinList[stablecoinListLength - 1] == stableMaster, "45");
        _stablecoinList.pop();
        // Deleting the stablecoin from the list
        emit StableMasterRevoked(stableMaster);
    }
// Solidity 0.8.7
/// @notice Adds a new governor address
/// @param _governor New governor address
/// @dev This function propagates the new governor role across most contracts of the protocol
/// @dev Governor is also guardian everywhere in all contracts
function addGovernor(address _governor) external override onlyGovernor zeroCheck(_governor) {
        require(!governorMap[_governor], "46");
        governorMap[_governor] = true;
        _governorList.push(_governor);
        // Propagates the changes to maintain consistency across all the contracts that are attached to this
        // `Core` contract
        for (uint256 i = 0; i < _stablecoinList.length; i++) {
            // Since a zero address check has already been performed in this contract, there is no need
            // to repeat this check in underlying contracts
            IStableMaster(_stablecoinList[i]).addGovernor(_governor);
        }

        emit GovernorRoleGranted(_governor);
    }