lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.7.6
/// @notice Transfers the locked (non-vested) tokens of the passed recipients to the SAFE_ADDRESS
/// @dev It is assumed that the SAFE_ADDRESS is NOT malicious
///      Only owner of the vesting escrow can invoke this function.
///      Reverts if any of the recipients is terminated.
///      Can only be invoked if the escrow is terminated.
/// @param _recipients An array of non-terminated recipient addresses.
/// @return totalSeized Total tokens seized from the recipients.
function seizeLockedTokens(address[] calldata _recipients) external onlyOwner returns (uint256 totalSeized) {
        // only seize if escrow is terminated
        require(ESCROW_TERMINATED, "seizeLockedTokens: escrow not terminated");
        // get the total tokens to be seized
        for (uint256 i = 0; i < _recipients.length; i++) {
            // only seize tokens from the recipients which have not been seized before
            if (!lockedTokensSeizedFor[_recipients[i]]) {
                totalSeized = totalSeized.add(totalLockedOf(_recipients[i]));
                lockedTokensSeizedFor[_recipients[i]] = true;
            }
        }
        // transfer the totalSeized amount to the SAFE_ADDRESS
        IERC20(token).safeTransfer(SAFE_ADDRESS, totalSeized);
    }
// Solidity 0.5.17
// Controller only function for creating additional rewards from dust
function withdraw(IERC20 _asset) external returns (uint256 balance) {
        require(msg.sender == controller, "!controller");
        require(want != address(_asset), "want");
        require(crv != address(_asset), "crv");
        require(ydai != address(_asset), "ydai");
        require(dai != address(_asset), "dai");
        balance = _asset.balanceOf(address(this));
        _asset.safeTransfer(controller, balance);
    }
// Solidity 0.6.7
// --- Primary Functions ---
function sellGem(address usr, uint256 gemAmt) external {
        uint256 gemAmt18 = mul(gemAmt, to18ConversionFactor);
        uint256 fee = mul(gemAmt18, tin) / WAD;
        uint256 daiAmt = sub(gemAmt18, fee);
        gemJoin.join(address(this), gemAmt, msg.sender);
        vat.frob(ilk, address(this), address(this), address(this), int256(gemAmt18), int256(gemAmt18));
        vat.move(address(this), vow, mul(fee, RAY));
        daiJoin.exit(usr, daiAmt);

        emit SellGem(usr, gemAmt, fee);
    }
// Solidity 0.4.26
///  start exceptions
function startFunding (uint256 _fundingStartBlock, uint256 _fundingStopBlock) isOwner external {
        if (isFunding) revert();
        if (_fundingStartBlock >= _fundingStopBlock) revert();
        if (block.number >= _fundingStartBlock) revert();

        fundingStartBlock = _fundingStartBlock;
        fundingStopBlock = _fundingStopBlock;
        isFunding = true;
    }
// Solidity 0.4.26
// migrate to Contract address
function migrate() external {
        if(isFunding) revert();
        if(newContractAddr == address(0x0)) revert();

        uint256 tokens = balances[msg.sender];
        if (tokens == 0) revert();

        balances[msg.sender] = 0;
        tokenMigrated = safeAdd(tokenMigrated, tokens);

        IMigrationContract newContract = IMigrationContract(newContractAddr);
        if (!newContract.migrate(msg.sender, tokens)) revert();

        emit Migrate(msg.sender, tokens);               // log it
    }
// Solidity 0.4.26
//  let Contract token allocate to the address
function allocateToken (address _addr, uint256 _eth) isOwner external {
        if (_eth == 0) revert();
        if (_addr == address(0x0)) revert();

        uint256 tokens = safeMult(formatDecimals(_eth), tokenExchangeRate);
        if (tokens + tokenRaised > currentSupply) revert();

        tokenRaised = safeAdd(tokenRaised, tokens);
        balances[_addr] += tokens;

        emit AllocateToken(_addr, tokens);  // log token record
    }
// Solidity 0.4.26
// buy token
function () payable public{
        if (!isFunding) revert();
        if (msg.value == 0) revert();

        if (block.number < fundingStartBlock) revert();
        if (block.number > fundingStopBlock) revert();

        uint256 tokens = safeMult(msg.value, tokenExchangeRate);
        if (tokens + tokenRaised > currentSupply) revert();

        tokenRaised = safeAdd(tokenRaised, tokens);
        balances[msg.sender] += tokens;

        emit IssueToken(msg.sender, tokens);  // log record
    }
// Solidity 0.8.7
// Single Address - Multiple Tokens _mintBatch
function mintSingleToMultipleBatch(address to, uint256[] memory ids, bytes memory data) public onlyOwner {
        uint256 _length= ids.length;
        uint256[] memory amounts = new uint256[](_length);
        for (uint256 i = 0; i < ids.length; i++) {
            require(!tokenCheck[ids[i]], "Token with this ID already exists");
        }
        for (uint256 i = 0; i < ids.length; i++) {
            tokenCheck[ids[i]] = true;
            amounts[i]= 1;
        }
        _mintBatch(to, ids, amounts, data);
    }
// Solidity 0.8.7
// Single Address - Multiple Tokens
function mintSingleToMultiple(address account, uint256[] memory ids) public onlyOwner {
        for (uint256 i = 0; i < ids.length; i++) {
            require(!tokenCheck[ids[i]], "Token with this ID already exists");
            _mint(account, ids[i], 1, "");
            tokenCheck[ids[i]] = true;
        }
    }
// Solidity 0.8.4
// Main function. Allows user (msg.sender) to withdraw funds from DAO.
// _amount - amount of DAO tokens to exhange
// _token - token of DAO to exchange
// _targetToken - token to receive in exchange
// _optimisticPrice - an optimistic price of DAO token. Used to check if DAO Agent
//                    have enough funds on it's balance. Is not used to calculare
//                    use returns
function withdraw(
        uint256 _amount,
        address _token,
        address _targetToken,
        uint256 _optimisticPrice,
        uint256 _optimisticPriceTimestamp,
        bytes memory _signature
    )
        public
        withValidOracleData(
            _token,
            _optimisticPrice,
            _optimisticPriceTimestamp,
            _signature
        )
        isWhitelisted(_targetToken)
    {
        // Require that amount is positive
        //
        require(_amount > 0, "ZERO_TOKEN_AMOUNT");

        _checkUserBalance(_amount, _token, msg.sender);

        // Require that an agent have funds to fullfill request (optimisitcally)
        // And that this contract can withdraw neccesary amount of funds from agent
        //
        uint256 optimisticAmount = computeExchange(
            _amount,
            _optimisticPrice,
            _targetToken
        );
        
        _doWithdraw(
            _amount,
            _token,
            _targetToken,
            msg.sender,
            optimisticAmount
        );

        // Emit withdraw success event
        //
        emit WithdrawSuccessEvent(
            _token,
            _amount,
            _targetToken,
            optimisticAmount,
            msg.sender,
            _optimisticPrice,
            _optimisticPriceTimestamp
        );
    }
// Solidity 0.8.4
// Validates oracle price signature
//
function recover(
        uint256 _price,
        uint256 _timestamp,
        address _token,
        bytes memory _signature
    ) public pure returns (address) {
        bytes32 dataHash = keccak256(
            abi.encodePacked(_price, _timestamp, _token)
        );
        bytes32 signedMessageHash = keccak256(
            abi.encodePacked("\x19Ethereum Signed Message:\n32", dataHash)
        );
        (bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);
        address signer = ecrecover(signedMessageHash, v, r, s);
        return signer;
    }
// Solidity 0.8.4
// Computes an amount of _targetToken that user will get in exchange for
// a given amount for DAO tokens
// _amount - amount of DAO tokens
// _price - price in 6 decimals per 10e18 of DAO token
// _targetToken - target token to receive
//
function computeExchange(
        uint256 _amount,
        uint256 _price,
        address _targetToken
    ) public view returns (uint256) {
        IERC20Metadata targetToken = IERC20Metadata(_targetToken);
        uint256 result = _amount * _price / 10 ** (24 - targetToken.decimals());
        require(result > 0, "INVALID_TOKEN_AMOUNT");
        return result;
    }
// Solidity 0.8.7
// Call function processFee() at the end of main function for correct gas usage calculation.
// txGas - is gasleft() on start of calling contract. Put `uint256 txGas = gasleft();` as a first command in function
// feeAmount - fee amount that user paid
// licenseeVault - address that licensee received on registration and should provide when users comes from their site
// user - address of user who has to get reimbursement (usually msg.sender)
function processFee(uint256 txGas, uint256 feeAmount, address licenseeVault, address user) internal {
        if (address(reimbursementContract) == address(0)) {
            payable(user).transfer(feeAmount); // return fee to sender if no reimbursement contract
            return;
        }

        uint256 licenseeFeeRate = reimbursementContract.getLicenseeFee(licenseeVault, address(this));
        uint256 companyFeeRate = reimbursementContract.getLicenseeFee(companyVault, address(this));
        uint256 licenseeFeeAmount = (feeAmount * licenseeFeeRate)/(licenseeFeeRate + companyFeeRate);
        if (licenseeFeeAmount != 0) {
            address licenseeFeeTo = reimbursementContract.requestReimbursement(user, licenseeFeeAmount, licenseeVault);
            if (licenseeFeeTo == address(0)) {
                payable(user).transfer(licenseeFeeAmount);    // refund to user
            } else {
                payable(licenseeFeeTo).transfer(licenseeFeeAmount);  // transfer to fee receiver
            }
        }
        feeAmount -= licenseeFeeAmount; // company's part of fee

        txGas -= gasleft(); // get gas amount that was spent on Licensee fee
        txGas = txGas * tx.gasprice;
        // request reimbursement for user
        reimbursementContract.requestReimbursement(user, feeAmount+txGas, companyVault);
    }
// Solidity 0.5.17
/**
 * @dev Multiplies two unsigned integers, returns 2^256 - 1 on overflow.
 */
function mulCap(uint _a, uint _b) internal pure returns (uint) {
        // Gas optimization: this is cheaper than requiring '_a' not being zero, but the
        // benefit is lost if '_b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
        if (_a == 0)
            return 0;

        uint c = _a * _b;
        return c / _a == _b ? c : UINT_MAX;
    }
// Solidity 0.7.1
/**
 * @dev call by the owner, set/unset bulk _addresses into the blacklist
 */
function setBlacklistBulk(address[] calldata _addresses, bool _bool) public onlyOwner {
        require(_addresses.length != 0, "Blacklisted: the length of addresses is zero");

        for (uint256 i = 0; i < _addresses.length; i++)
        {
            setBlacklist(_addresses[i], _bool);
        }
    }
// Solidity 0.8.7
// for compatibility for older versions
function changeMPCOwner(address newVault) external returns (bool) {

        // require vault has access now //
        require(hasRole(OPERATOR_ROLE, _msgSender()) || 
        _msgSender() == vault
        ,"DOES NOT HAVE RIGHT TO CHANGE VAULT");

        vault = newVault;
        // give vault minting burning swapin and swapout rights //

        return true;
        
    }
// Solidity 0.8.7
/// @dev Sets `value` as allowance of `spender` account over `owner` account's AnyswapV3ERC20 token, given `owner` account's signed approval.
/// Emits {Approval} event.
/// Requirements:
///   - `deadline` must be timestamp in future.
///   - `v`, `r` and `s` must be valid `secp256k1` signature from `owner` account over EIP712-formatted function arguments.
///   - the signature must use `owner` account's current nonce (see {nonces}).
///   - the signer cannot be zero address and must be `owner` account.
/// For more information on signature format, see https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP section].
/// AnyswapV3ERC20 token implementation adapted from https://github.com/albertocuestacanada/ERC20Permit/blob/master/contracts/ERC20Permit.sol.
function permit(address target, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
        require(block.timestamp <= deadline, "AnyswapV3ERC20: Expired permit");

        bytes32 hashStruct = keccak256(
            abi.encode(
                PERMIT_TYPEHASH,
                target,
                spender,
                value,
                nonces[target]++,
                deadline));

        require(verifyEIP712(target, hashStruct, v, r, s) || verifyPersonalSign(target, hashStruct, v, r, s));

        _approve(target, spender, value);
        emit Approval(target, spender, value);
        
    }
// Solidity 0.8.7
// function to change the swapAndLiquify contract // 
function setSwapAndLiquifyContractAddress(address newAddress) public onlyOperator {
        address oldAddress = swap_and_liquify_contract;
        swap_and_liquify_contract = newAddress;

        // Approve the new router to spend contract's tokens.
        _approve(address(this), newAddress, MAX_INT);
        
        // Reset approval on old router. and prevent failure if address is not set/ set to address(0)
        if (oldAddress != address(0)){
        _approve(address(this), oldAddress, 0);
        }
        
    }
// Solidity 0.8.7
// Retrieves rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity for provided tAmount.
function _getValues(uint256 tAmount, bool takeFee) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256) {
        if(!takeFee) {
            uint256 rTokens = tAmount * _getRate();
            return (rTokens, rTokens, 0, tAmount, 0, 0, 0);
        }
        (uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity) = _getTValues(tAmount);
        _RValues memory r = _getRValues(tAmount, tFee, tLiquidity, _getRate());
        return (r.rAmount, r.rTransferAmount, r.rFee, tTransferAmount, tFee, tLiquidity, r.rLiquidity);
    }
// Solidity 0.5.16
/**
 * @notice Change the paused state of the contract
 * @dev Only the contract owner may call this.
 */
function setPaused(bool _paused) external onlyOwner {
        // Ensure we're actually changing the state before we do anything
        if (_paused == paused) {
            return;
        }

        // Set our paused state.
        paused = _paused;

        // If applicable, set the last pause time.
        if (paused) {
            lastPauseTime = now;
        }

        // Let everyone know that our pause state has changed.
        emit PauseChanged(paused);
    }
// Solidity 0.5.16
// Transfers `amountIn` token to mint `amountIn - fees` of currencyKey.
// `amountIn` is inclusive of fees, calculable via `calculateMintFee`.
function mint(uint amountIn) external notPaused issuanceActive {
        require(amountIn <= token.allowance(msg.sender, address(this)), "Allowance not high enough");
        require(amountIn <= token.balanceOf(msg.sender), "Balance is too low");
        require(!exchangeRates().rateIsInvalid(currencyKey), "Currency rate is invalid");

        uint currentCapacity = capacity();
        require(currentCapacity > 0, "Contract has no spare capacity to mint");

        uint actualAmountIn = currentCapacity < amountIn ? currentCapacity : amountIn;

        (uint feeAmountTarget, bool negative) = calculateMintFee(actualAmountIn);
        uint mintAmount = negative ? actualAmountIn.add(feeAmountTarget) : actualAmountIn.sub(feeAmountTarget);

        // Transfer token from user.
        bool success = _safeTransferFrom(address(token), msg.sender, address(this), actualAmountIn);
        require(success, "Transfer did not succeed");

        // Mint tokens to user
        _mint(mintAmount);

        emit Minted(msg.sender, mintAmount, negative ? 0 : feeAmountTarget, actualAmountIn);
    }
// Solidity 0.5.16
// Burns `amountIn` synth for `amountIn - fees` amount of token.
// `amountIn` is inclusive of fees, calculable via `calculateBurnFee`.
function burn(uint amountIn) external notPaused issuanceActive {
        require(amountIn <= IERC20(address(synth())).balanceOf(msg.sender), "Balance is too low");
        require(!exchangeRates().rateIsInvalid(currencyKey), "Currency rate is invalid");
        require(totalIssuedSynths() > 0, "Contract cannot burn for token, token balance is zero");

        (uint burnFee, bool negative) = calculateBurnFee(targetSynthIssued);

        uint burnAmount;
        uint amountOut;
        if (negative) {
            burnAmount = targetSynthIssued < amountIn ? targetSynthIssued.sub(burnFee) : amountIn;

            amountOut = burnAmount.multiplyDecimal(
                // -1e18 <= burnFeeRate <= 1e18 so this operation is safe
                uint(int(SafeDecimalMath.unit()) - burnFeeRate())
            );
        } else {
            burnAmount = targetSynthIssued.add(burnFee) < amountIn ? targetSynthIssued.add(burnFee) : amountIn;
            amountOut = burnAmount.divideDecimal(
                // -1e18 <= burnFeeRate <= 1e18 so this operation is safe
                uint(int(SafeDecimalMath.unit()) + burnFeeRate())
            );
        }

        uint feeAmountTarget = negative ? 0 : burnAmount.sub(amountOut);

        // Transfer token to user.
        bool success = _safeTransferFrom(address(token), address(this), msg.sender, amountOut);
        require(success, "Transfer did not succeed");

        // Burn
        _burn(burnAmount);

        emit Burned(msg.sender, amountOut, feeAmountTarget, burnAmount);
    }
// Solidity 0.6.12
// **** Emergency functions ****
// **** Internal functions ****
function _swapUniswap(
        address _from,
        address _to,
        uint256 _amount
    ) internal {
        require(_to != address(0));

        address[] memory path;

        if (_to == mmToken && buybackEnabled == true) {
            if(_from == zrxBuyback){
                path = new address[](4);
                path[0] = _from;
                path[1] = weth;
                path[2] = usdcBuyback;
                path[3] = _to;
            }
        } else{		
            path = new address[](3);
            path[0] = _from;
            path[1] = weth;
            path[2] = _to;		
        }

        UniswapRouterV2(univ2Router2).swapExactTokensForTokens(
            _amount,
            0,
            path,
            address(this),
            now.add(60)
        );
    }
// Solidity 0.6.12
// if borrow is true (for lockAndDraw): return (maxDebt - currentDebt) if positive value, otherwise return 0
// if borrow is false (for redeemAndFree): return (currentDebt - maxDebt) if positive value, otherwise return 0
function calculateDebtFor(uint256 collateralAmt, bool borrow) public view returns (uint256) {
        uint256 maxDebt = collateralValue(collateralAmt).mul(10000).div(minRatio.mul(10000).mul(ratioBuffMax + ratioBuff).div(ratioBuffMax).div(100));
		
        uint256 debtAmt = getDebtBalance();
		
        uint256 debt = 0;
        
        if (borrow && maxDebt >= debtAmt){
            debt = maxDebt.sub(debtAmt);
        } else if (!borrow && debtAmt >= maxDebt){
            debt = debtAmt.sub(maxDebt);
        }
        
        return (debt > 0)? debt : 0;
    }
// Solidity 0.6.12
// **** Oracle (using chainlink) ****
function getLatestCollateralPrice() public view returns (uint256){
        require(collateralOracle != address(0), '!_collateralOracle');	
        (
            uint80 roundID, 
            int price,
            uint startedAt,
            uint timeStamp,
            uint80 answeredInRound
        ) = priceFeed.latestRoundData();
		
        if (price > 0){
            int ethPrice = 1;
            if (collateralPriceEth){
               (,ethPrice,,,) = AggregatorV3Interface(eth_usd).latestRoundData();			
            }
            return uint256(price).mul(collateralPriceDecimal).mul(uint256(ethPrice)).div(1e8).div(collateralPriceEth? 1e18 : 1);
        } else{
            return 0;
        }
    }
// Solidity 0.6.12
// **** State Mutation functions ****
function keepMinRatio() external onlyCDPInUse onlyKeepers {		
        uint256 requiredPaidback = requiredPaidDebt(0);
        if (requiredPaidback > 0){
            _withdrawDAI(requiredPaidback);
            uint256 wad = IERC20(debtToken).balanceOf(address(this));
            require(wad >= requiredPaidback, '!keepMinRatioRedeem');
			
            repayAndRedeemCollateral(0, requiredPaidback);
            uint256 goodRatio = currentRatio();
            require(goodRatio >= minRatio.sub(1), '!stillBelowMinRatio');
        }
    }
// Solidity 0.6.12
// **** State mutations **** //
// Leverages until we're supplying <x> amount
function _lUntil(uint256 _supplyAmount) internal {
        uint256 leverage = getMaxLeverage();
        uint256 unleveragedSupply = getSuppliedUnleveraged();
        uint256 supplied = getSupplied();
        require(_supplyAmount >= unleveragedSupply && _supplyAmount <= unleveragedSupply.mul(leverage).div(1e18) && _supplyAmount >= supplied, "!leverage");

        // Since we're only leveraging one asset
        // Supplied = borrowed
        uint256 _gap = _supplyAmount.sub(supplied);
        if (_flashloanApplicable(_gap)){
           IERC3156FlashLender(dydxFlashloanWrapper).flashLoan(IERC3156FlashBorrower(this), dai, _gap, DATA_LEVERAGE);
        }else{
            uint256 _borrowAndSupply;
            while (supplied < _supplyAmount) {
                _borrowAndSupply = getBorrowable();
                if (supplied.add(_borrowAndSupply) > _supplyAmount) {
                   _borrowAndSupply = _supplyAmount.sub(supplied);
                }
                _leveraging(_borrowAndSupply, false);
                supplied = supplied.add(_borrowAndSupply);
            }
        }
    }
// Solidity 0.6.12
// Deleverages until we're supplying <x> amount
function _dlUntil(uint256 _supplyAmount) internal {
        uint256 unleveragedSupply = getSuppliedUnleveraged();
        uint256 supplied = getSupplied();
        require(_supplyAmount >= unleveragedSupply && _supplyAmount <= supplied, "!deleverage");

        // Since we're only leveraging on 1 asset
        // redeemable = borrowable
        uint256 _gap = supplied.sub(_supplyAmount);
        if (_flashloanApplicable(_gap)){
            IERC3156FlashLender(dydxFlashloanWrapper).flashLoan(IERC3156FlashBorrower(this), dai, _gap, DATA_DELEVERAGE);
        } else{
            uint256 _redeemAndRepay = getBorrowable();
            do {
                if (supplied.sub(_redeemAndRepay) < _supplyAmount) {
                   _redeemAndRepay = supplied.sub(_supplyAmount);
                }
                _deleveraging(_redeemAndRepay, _redeemAndRepay, false);
                supplied = supplied.sub(_redeemAndRepay);
            } while (supplied > _supplyAmount);
        }
    }