lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.4
/**
 * @dev Creates a new token for `to`. Its token ID will be automatically
 * assigned (and available on the emitted {IERC721-Transfer} event), and the token
 * URI autogenerated based on the base URI passed at construction.
 *
 */
function mint() public {
    require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "Must be admin to be able to mint");
    require(_mintingEnabled, "Minting is not enabled yet");
    require(_tokenIdTracker.current() < _max, "all NFTs have been minted");
    address owner = address(this);
    _mint(owner, _tokenIdTracker.current());
    tokenToOwner[_tokenIdTracker.current()] = owner;
    ownerTokenCount[owner] = ownerTokenCount[owner].add(1);
    _tokenIdTracker.increment();
    emit Minted(_tokenIdTracker.current(),owner,1);
    
  }
// Solidity 0.4.11
// TODO: update tests to expect throw
function transfer(address _to, uint256 _value) onlyPayloadSize(2) returns (bool success) {
        require(_to != address(0));
        require(balances[msg.sender] >= _value && _value > 0);
        balances[msg.sender] = safeSub(balances[msg.sender], _value);
        balances[_to] = safeAdd(balances[_to], _value);
        Transfer(msg.sender, _to, _value);

        return true;
    }
// Solidity 0.7.5
/**
 * Taken from Hypersonic https://github.com/M2629/HyperSonic/blob/main/Math.sol
 * @dev Returns the average of two numbers. The result is rounded towards
 * zero.
 */
function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
// Solidity 0.7.5
// Migrates terms from old redemption contract
function migrate( address[] calldata _addresses ) external returns ( bool ) {
        require( msg.sender == owner, "Sender is not owner" );
        require( !hasMigrated, "Already migrated" );

        for( uint i = 0; i < _addresses.length; i++ ) {
            percentCanVest[ _addresses[i] ] = IOldClaimContract( previousClaimContract ).percentCanVest( _addresses[i] );
            amountClaimed[ _addresses[i] ] = IOldClaimContract( previousClaimContract ).amountClaimed( _addresses[i] );
            maxAllowedToClaim[ _addresses[i] ] = IOldClaimContract( previousClaimContract ).maxAllowedToClaim( _addresses[i] );
        }
        
        hasMigrated = true;

        return true;
    }
// Solidity 0.7.5
// Sets terms for a new wallet
function setTerms(address _vester, uint _amountCanClaim, uint _rate ) external returns ( bool ) {
        require( msg.sender == owner, "Sender is not owner" );
        require( _amountCanClaim >= maxAllowedToClaim[ _vester ], "cannot lower amount claimable" );
        require( _rate >= percentCanVest[ _vester ], "cannot lower vesting rate" );

        if( maxAllowedToClaim[ _vester ] == 0 ) {
            amountClaimed[ _vester ] = IOldClaimContract( previousClaimContract ).amountClaimed( _vester );
        } 

        maxAllowedToClaim[ _vester ] = _amountCanClaim;
        percentCanVest[ _vester ] = _rate;

        return true;
    }
// Solidity 0.7.5
// Allows wallet to exercise pOLY to claim OHM
function exercisePOLY( uint _amountToExercise ) external returns ( bool ) {
        require( getPOLYAbleToClaim( msg.sender ).sub( _amountToExercise ) >= 0, 'Not enough OHM vested' );
        require( maxAllowedToClaim[ msg.sender ].sub( amountClaimed[ msg.sender ] ).sub( _amountToExercise ) >= 0, 'Claimed over max' );

        IERC20( DAI ).safeTransferFrom( msg.sender, address( this ), _amountToExercise );
        IERC20( DAI ).approve( treasury, _amountToExercise );

        if( !usingNewVault ) {
            IVaultOld( treasury ).depositReserves( _amountToExercise );
        } else {
            IVaultNew( newTreasury ).depositReserves( _amountToExercise, DAI );
        }

        IPOLY( pOLY ).burnFrom( msg.sender, _amountToExercise );

        amountClaimed[ msg.sender ] = amountClaimed[ msg.sender ].add( _amountToExercise );

        uint _amountOHMToSend = _amountToExercise.div( 1e9 );

        IERC20( OHM ).safeTransfer( msg.sender, _amountOHMToSend );

        return true;
    }
// Solidity 0.7.5
// Allows wallet owner to transfer rights to a new address
function changeWallets( address _oldWallet, address _newWallet ) external returns ( bool ) {
        require( msg.sender == _oldWallet, "Only the wallet owner can change wallets" );
        
        maxAllowedToClaim[ _newWallet ] = maxAllowedToClaim[ _oldWallet ];
        maxAllowedToClaim[ _oldWallet ] = 0;
        
        amountClaimed[ _newWallet ] = amountClaimed[ _oldWallet ];
        amountClaimed[ _oldWallet ] = 0;
        
        percentCanVest[ _newWallet ] = percentCanVest[ _oldWallet ];
        percentCanVest[ _oldWallet ] = 0;
        
        return true;
    }
// Solidity 0.7.5
// For single use after migration
function setNewVault( address _newVault ) external returns ( bool ) {
        require( msg.sender == owner, "Sender is not owner" );
        require( !usingNewVault, "New vault already set" );

        newTreasury = _newVault;
        usingNewVault = true;

        return true;
    }
// Solidity 0.6.0
// swap currencies
function swap(
        string calldata buy,
        string calldata sell,
        uint256 amount,
        uint256 rate,
        uint32 expireTime,
        bytes calldata signature
    ) external payable whenNotPaused returns (bool) {
        if (
            keccak256(bytes(buy)) == keccak256(bytes(baseCurrency)) &&
            keccak256(bytes(sell)) == keccak256(bytes("ETH"))
        ) {
            require(
                _beforeSwap(buy, sell, msg.value, rate, expireTime, signature)
            );
            return swapETHForGSU(rate);
        }

        require(msg.value == 0, "[Dex] ethers are not accepted");
        require(_beforeSwap(buy, sell, amount, rate, expireTime, signature));

        if (
            keccak256(bytes(buy)) == keccak256(bytes("ETH")) &&
            keccak256(bytes(sell)) == keccak256(bytes(baseCurrency))
        ) {
            return swapGSUForETH(amount, rate);
        } else {
            return swapTokens(buy, sell, amount, rate);
        }
    }
// Solidity 0.4.24
// Payable method, payouts for message sender
function () public payable{
 	require(now >= lastBlockTime && msg.value >= minWei); // last block time < block.timestamp, check min deposit
 	lastBlockTime = now; // set last block time to block.timestamp
 	uint256 com = msg.value/100*inCommission; // 3% commission
 	uint256 amount = msg.value - com; // deposit amount is amount - commission
 	if (deposits[msg.sender] > 0){
 		// repeating payment
 		uint256 daysGone = (now - paydates[msg.sender]) / secInDay;	// days gone before this payment, and not included in next payout
 		notToPay[msg.sender] += amount/100*daysGone; // keep amount that does not have to be paid 
 	}else{
 		// new payment 
 		paydates[msg.sender] = now; // set paydate to block.timestamp
 	}
    deposits[msg.sender] += amount; // update deposit amount
    emit DepositIn(msg.sender, msg.value, now); // emit deposit in event
    owner.transfer(com); // transfer commission to contract owner
}
// Solidity 0.4.24
// Payable method, payout will be paid to specific address
function  depositForRecipent(address payoutAddress) public  payable{
 	require(now >= lastBlockTime && msg.value >= minWei); // last block time < block.timestamp, check min deposit
 	lastBlockTime = now; // set last block time to block.timestamp
 	uint256 com = msg.value/100*inCommission; // 3% commission
 	uint256 amount = msg.value - com; // deposit amount is amount - commission
 	if (deposits[payoutAddress] > 0){
 		// repeating payment
 		uint256 daysGone = (now - paydates[payoutAddress]) / secInDay;	// days gone before this payment, and not included in next payout
 		notToPay[payoutAddress] += amount/100*daysGone; // keep amount that does not have to be paid 
 	}else{
 		// new payment
 		paydates[payoutAddress] = now; // set paydate to block.timestamp
 	}
    deposits[payoutAddress] += amount; // update deposit amount
    emit DepositIn(payoutAddress, msg.value, now); // emit deposit in event
    owner.transfer(com); // transfer commission to contract owner
}
// Solidity 0.4.24
// function used by client direct calls, for direct contract interaction, gas paid by function caller in this case
function payOut() public {
		require(deposits[msg.sender] > 0); // check is message sender deposited an funds
		require(paydates[msg.sender] < now); // check is lastPayDate < block.timestamp 
		uint256 payForDays = (now - paydates[msg.sender]) / secInDay; // days from last payment
        require(payForDays >= 30);
		pay(msg.sender,false,payForDays); // don't withdraw tx gass fee, because fee paid by function caller
}
// Solidity 0.4.24
// function used by contrcat owner for automatic payouts from representative site
// gas price paid by contract owner and because of that gasPrice will be withdrawn from payout amount
function payOutFor(address _recipient) public {
		require(msg.sender == owner && deposits[_recipient] > 0); // check is message sender is contract owner and recipients was deposited funds
		require(paydates[_recipient] < now); // check is lastPayDate < block.timestamp
		uint256 payForDays = (now - paydates[_recipient]) / secInDay; // days from last payment
        require(payForDays >= 30); 
		pay(_recipient, true,payForDays); // pay with withdraw tx gas fee because fee paid by contract owner
}
// Solidity 0.6.12
// Deposit LP tokens to pool for RLY allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 pending = user.amount.mul(pool.accRallyPerShare).div(1e12).sub(user.rewardDebt);
            if(pending > 0) {
                safeRallyTransfer(msg.sender, pending);
            }
        }
        if(_amount > 0) {
            pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
            user.amount = user.amount.add(_amount);
        }
        user.rewardDebt = user.amount.mul(pool.accRallyPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.4.19
//Check if team wallet is unlocked
function unlockTokens(address _address) external {
        if (_address == OUTINGRESERVE) {
            require(UNLOCK_OUTINGRESERVE <= now);
            require (outingreserveBalance > 0);
            balances[OUTINGRESERVE] = outingreserveBalance;
            outingreserveBalance = 0;
            Transfer (this, OUTINGRESERVE, balances[OUTINGRESERVE]);
        } else if (_address == TEAM) {
            require(UNLOCK_TEAM <= now);
            require (teamBalance > 0);
            balances[TEAM] = teamBalance;
            teamBalance = 0;
            Transfer (this, TEAM, balances[TEAM]);
        }
    }
// Solidity 0.8.7
/**
 * @dev returns the transaction fee taken if sender sends a payout with a creatorAddress.
 * If senderAddress has a custom fee set it will prioritize that over the creatorAddress.
 */
function _getEaselyBPS(address senderAddress, address creatorAddress) internal view returns (uint256) {
        uint256 bps = _addressToBPS[senderAddress];

        // If the sender BPS is never set, default to creatorAddress fee.
        if (bps == 0) {
            bps = _addressToBPS[creatorAddress];
        }

        // If the creatorAddress BPS is also not set, the fee is the default fee
        if (bps == 0) {
            bps = DEFAULT_FEE_BPS;
        }

        // Since BPS map is initialized to 0, we will treat any BPS greater than the max
        // to be a bps of 0;
        if (bps > MAX_EASELY_FEE_BPS) {
            bps = 0;
        }

        return bps;
    }
// Solidity 0.8.7
/**
 * @dev See {IEaselyPayout-splitPayable}.
 */
function splitPayable(address primaryPayout, address[] memory royalties, uint256[] memory bps) external payable override {
        require(royalties.length == bps.length, "invalid royalties");
        // Divide first to prevent overflow. 
        uint256 payinBasis = msg.value / BASIS_POINT_CONVERSION;
        uint256 primaryBPS = BASIS_POINT_CONVERSION - _getEaselyBPS(_msgSender(), primaryPayout);

        for (uint256 i = 0; i < royalties.length; i++) {
            if (royalties[i] == address(0)) {
                continue;
            }

            require(primaryBPS >= bps[i], "Invalid BPS");
            payable(royalties[i]).transfer(payinBasis * bps[i]);
            primaryBPS -= bps[i]; 
        }

        payable(primaryPayout).transfer(payinBasis * primaryBPS);
    }
// Solidity 0.4.24
/**
 * @dev players use this to change back to one of your old names.  
 * -functionhash- 0xb9291296
 * @param _nameString the name you want to use 
 */
function useMyOldName(string _nameString)
        isHuman()
        public 
    {
        // filter name, and get pID
        bytes32 _name = _nameString.nameFilter();
        uint256 _pID = pIDxAddr_[msg.sender];
        
        // make sure they own the name 
        require(plyrNames_[_pID][_name] == true);
        
        // update their current name 
        plyr_[_pID].name = _name;
    }
// Solidity 0.7.5
/**
 * @notice Tx sender must have a sufficient USDP balance to pay the debt
 * @dev Withdraws collateral
 * @dev Repays specified amount of debt
 * @param asset The address of token using as main collateral
 * @param mainAmount The amount of main collateral token to withdraw
 * @param colAmount The amount of COL token to withdraw
 * @param usdpAmount The amount of USDP token to repay
 **/
function withdrawAndRepay(
        address asset,
        uint mainAmount,
        uint colAmount,
        uint usdpAmount
    )
    public
    spawned(asset, msg.sender)
    nonReentrant
    {
        // check usefulness of tx
        require(mainAmount != 0 || colAmount != 0, "Unit Protocol: USELESS_TX");

        uint debt = vault.debts(asset, msg.sender);
        require(debt != 0 && usdpAmount != debt, "Unit Protocol: USE_REPAY_ALL_INSTEAD");

        if (mainAmount != 0) {
            // withdraw main collateral to the user address
            vault.withdrawMain(asset, msg.sender, mainAmount);
        }

        if (colAmount != 0) {
            // withdraw COL tokens to the user's address
            vault.withdrawCol(asset, msg.sender, colAmount);
        }

        if (usdpAmount != 0) {
            uint fee = vault.calculateFee(asset, msg.sender, usdpAmount);
            vault.chargeFee(vault.usdp(), msg.sender, fee);
            vault.repay(asset, msg.sender, usdpAmount);
        }

        vault.update(asset, msg.sender);

        _ensureCollateralizationTroughProofs(asset, msg.sender);

        // fire an event
        emit Exit(asset, msg.sender, mainAmount, colAmount, usdpAmount);
    }
// Solidity 0.7.5
/**
 * @notice Tx sender must have a sufficient USDP and COL balances and allowances to pay the debt
 * @dev Repays specified amount of debt paying fee in COL
 * @param asset The address of token using as main collateral
 * @param usdpAmount The amount of USDP token to repay
 **/
function repayUsingCol(
        address asset,
        uint usdpAmount
    )
    public
    spawned(asset, msg.sender)
    nonReentrant
    {
        // check usefulness of tx
        require(usdpAmount != 0, "Unit Protocol: USELESS_TX");

        // COL token price in USD
        uint colUsdValue_q112 = keep3rOraclePoolToken.oracleMainAsset().assetToUsd(vault.col(), 1);

        uint fee = vault.calculateFee(asset, msg.sender, usdpAmount);
        uint feeInCol = fee.mul(Q112).div(colUsdValue_q112);
        vault.chargeFee(vault.col(), msg.sender, feeInCol);
        vault.repay(asset, msg.sender, usdpAmount);

        // fire an event
        emit Exit(asset, msg.sender, 0, 0, usdpAmount);
    }
// Solidity 0.4.19
/**
 * NectarCrowdsale constructor
 * @param _startTime start timestamp when purchases are allowed, inclusive
 * @param _endTime end timestamp when purchases are allowed, inclusive
 * @param _initialWeiUsdExchangeRate initial rate of wei/usd used in cap and minimum purchase calculation
 * @param _wallet wallet in which to collect the funds
 * @param _purchaseAuthorizer address to verify purchase authorizations from
 */
function NectarCrowdsale(
        uint256 _startTime,
        uint256 _endTime,
        uint256 _initialWeiUsdExchangeRate,
        address _wallet,
        address _purchaseAuthorizer
    )
        public
    {
        require(_startTime >= now);
        require(_endTime >= _startTime);
        require(_initialWeiUsdExchangeRate > 0);
        require(_wallet != address(0));
        require(_purchaseAuthorizer != address(0));

        token = createTokenContract();
        startTime = _startTime;
        endTime = _endTime;
        weiUsdExchangeRate = _initialWeiUsdExchangeRate;
        wallet = _wallet;
        purchaseAuthorizer = _purchaseAuthorizer;

        capUsd = maxCapUsd;

        // Updates cap and minimumPurchase based on capUsd and weiUsdExchangeRate
        updateCapAndExchangeRate();

        isCanceled = false;
        isFinalized = false;
    }
// Solidity 0.4.19
/**
 * Buy tokens once authorized by the frontend
 * @param nonce nonce parameter generated by the frontend
 * @param authorizedAmount maximum purchase amount authorized for this transaction
 * @param sig the signature generated by the frontned
 */
function buyTokens(uint256 authorizedAmount, uint256 nonce, bytes sig) public payable whenNotPaused {
        require(msg.sender != address(0));
        require(validPurchase(authorizedAmount, nonce, sig));

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        uint256 rate = currentTranche();
        uint256 tokens = weiAmount.mul(rate);

        // update state
        weiRaised = weiRaised.add(weiAmount);
        purchases[nonce] = true;

        token.mint(msg.sender, tokens);
        TokenPurchase(msg.sender, weiAmount, tokens);

        forwardFunds();
    }
// Solidity 0.4.19
/**
 * Get the rate of tokens/wei in the current tranche
 * @return the current tokens/wei rate
 */
function currentTranche() public view returns (uint256) {
        uint256 currentFundingUsd = weiRaised.div(weiUsdExchangeRate);
        if (currentFundingUsd <= tranche1ThresholdUsd) {
            return tranche1Rate;
        } else if (currentFundingUsd <= tranche2ThresholdUsd) {
            return tranche2Rate;
        } else if (currentFundingUsd <= tranche3ThresholdUsd) {
            return tranche3Rate;
        } else if (currentFundingUsd <= tranche4ThresholdUsd) {
            return tranche4Rate;
        } else {
            return standardTrancheRate;
        }
    }
// Solidity 0.4.19
/**
 * Is a purchase transaction valid?
 * @return true if the transaction can buy tokens
 */
function validPurchase(uint256 authorizedAmount, uint256 nonce, bytes sig) internal view returns (bool) {
        // 84 = 20 byte address + 32 byte authorized amount + 32 byte nonce
        bytes memory prefix = "\x19Ethereum Signed Message:\n84";
        bytes32 hash = keccak256(prefix, msg.sender, authorizedAmount, nonce);
        bool validAuthorization = ECRecovery.recover(hash, sig) == purchaseAuthorizer;

        bool validNonce = !purchases[nonce];
        bool withinPeriod = now >= startTime && now <= endTime;
        bool aboveMinimum = msg.value >= minimumPurchase;
        bool belowAuthorized = msg.value <= authorizedAmount;
        bool belowCap = weiRaised.add(msg.value) <= cap;
        return validAuthorization && validNonce && withinPeriod && aboveMinimum && belowAuthorized && belowCap;
    }
// Solidity 0.5.16
// Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders
function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner {
        // If it's SNX we have to query the token symbol to ensure its not a proxy or underlying
        bool isSNX = (keccak256(bytes("SNX")) == keccak256(bytes(ERC20Detailed(tokenAddress).symbol())));
        // Cannot recover the staking token or the rewards token
        require(
            tokenAddress != address(stakingToken) && tokenAddress != address(rewardsToken) && !isSNX,
            "Cannot withdraw the staking or rewards tokens"
        );
        IERC20(tokenAddress).safeTransfer(owner, tokenAmount);
        emit Recovered(tokenAddress, tokenAmount);
    }
// Solidity 0.5.12
/**
 @notice This function is used swap tokens using multiple exchanges
 @param toWhomToIssue address to which tokens should be sent after swap
 	@param path token addresses indicating the conversion path
 	@param amountIn amount of tokens to swap
 @param minTokenOut min amount of expected tokens
 @param withPool indicates the exchange and its sequence we want to swap from
 @param poolData pool or token addresses needed for swapping tokens according to the exchange
 	@param starts indicates the index of path array for each swap
 @return amount of tokens received after swap
 */
function MultiExchangeSwap(
        address payable toWhomToIssue,
        address[] calldata path,
        uint256 amountIn,
        uint256 minTokenOut,
        uint8[] calldata starts,
        uint8[] calldata withPool,
        address[] calldata poolData
    ) external payable nonReentrant returns (uint256 tokensBought) {
        require(toWhomToIssue != address(0), "Invalid receiver address");
        require(path[0] != path[path.length - 1], "Cannot swap same tokens");

        tokensBought = _swap(
            path,
            _getTokens(path[0], amountIn),
            starts,
            withPool,
            poolData
        );

        require(tokensBought >= minTokenOut, "High Slippage");
        _sendTokens(toWhomToIssue, path[path.length - 1], tokensBought);
    }
// Solidity 0.5.12
//swap function
function _swap(
        address[] memory path,
        uint256 tokensToSwap,
        uint8[] memory starts,
        uint8[] memory withPool,
        address[] memory poolData
    ) internal returns (uint256) {
        address _to;
        uint8 poolIndex = 0;
        address[] memory _poolData;
        address _from = path[starts[0]];

        for (uint256 index = 0; index < withPool.length; index++) {
            uint256 endIndex = index == withPool.length.sub(1)
                ? path.length - 1
                : starts[index + 1];

            _to = path[endIndex];

            {
                if (withPool[index] == 2) {
                    _poolData = _getPath(path, starts[index], endIndex + 1);
                } else {
                    _poolData = new address[](1);
                    _poolData[0] = poolData[poolIndex++];
                }
            }

            tokensToSwap = _swapFromPool(
                _from,
                _to,
                tokensToSwap,
                withPool[index],
                _poolData
            );

            _from = _to;
        }
        return tokensToSwap;
    }