lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.4
/**
 * @dev Callback function for aave flashloan.
 * @notice Callback function for aave flashloan.
 * @param _assets list of asset addresses for flashloan.
 * @param _amounts list of amounts for the corresponding assets for flashloan.
 * @param _premiums list of premiums/fees for the corresponding addresses for flashloan.
 * @param _initiator initiator address for flashloan.
 * @param _data extra data passed.
 */
function executeOperation(
        address[] memory _assets,
        uint256[] memory _amounts,
        uint256[] memory _premiums,
        address _initiator,
        bytes memory _data
    ) external verifyDataHash(_data) returns (bool) {
        require(_initiator == address(this), "not-same-sender");
        require(msg.sender == address(aaveLending), "not-aave-sender");

        FlashloanVariables memory instaLoanVariables_;

        (address sender_, bytes memory data_) = abi.decode(
            _data,
            (address, bytes)
        );

        instaLoanVariables_._tokens = _assets;
        instaLoanVariables_._amounts = _amounts;
        instaLoanVariables_._instaFees = calculateFees(
            _amounts,
            calculateFeeBPS(1, sender_)
        );
        instaLoanVariables_._iniBals = calculateBalances(
            _assets,
            address(this)
        );

        safeApprove(instaLoanVariables_, _premiums, address(aaveLending));
        safeTransfer(instaLoanVariables_, sender_);

        if (checkIfDsa(sender_)) {
            Address.functionCall(
                sender_,
                data_,
                "DSA-flashloan-fallback-failed"
            );
        } else {
            InstaFlashReceiverInterface(sender_).executeOperation(
                _assets,
                _amounts,
                instaLoanVariables_._instaFees,
                sender_,
                data_
            );
        }

        instaLoanVariables_._finBals = calculateBalances(
            _assets,
            address(this)
        );
        validateFlashloan(instaLoanVariables_);

        return true;
    }
// Solidity 0.8.4
/**
 * @dev Middle function for route 1.
 * @notice Middle function for route 1.
 * @param _tokens list of token addresses for flashloan.
 * @param _amounts list of amounts for the corresponding assets or amount of ether to borrow as collateral for flashloan.
 * @param _data extra data passed.
 */
function routeAave(
        address[] memory _tokens,
        uint256[] memory _amounts,
        bytes memory _data
    ) internal {
        bytes memory data_ = abi.encode(msg.sender, _data);
        uint256 length_ = _tokens.length;
        uint256[] memory _modes = new uint256[](length_);
        for (uint256 i = 0; i < length_; i++) {
            _modes[i] = 0;
        }
        dataHash = bytes32(keccak256(data_));
        aaveLending.flashLoan(
            address(this),
            _tokens,
            _amounts,
            _modes,
            address(0),
            data_,
            3228
        );
    }
// Solidity 0.8.4
/**
 * @dev Middle function for route 2.
 * @notice Middle function for route 2.
 * @param _token token address for flashloan(DAI).
 * @param _amount DAI amount for flashloan.
 * @param _data extra data passed.
 */
function routeMaker(
        address _token,
        uint256 _amount,
        bytes memory _data
    ) internal {
        address[] memory tokens_ = new address[](1);
        uint256[] memory amounts_ = new uint256[](1);
        tokens_[0] = _token;
        amounts_[0] = _amount;
        bytes memory data_ = abi.encode(
            2,
            tokens_,
            amounts_,
            msg.sender,
            _data
        );
        dataHash = bytes32(keccak256(data_));
        makerLending.flashLoan(
            InstaFlashReceiverInterface(address(this)),
            _token,
            _amount,
            data_
        );
    }
// Solidity 0.8.4
/**
 * @dev Middle function for route 3.
 * @notice Middle function for route 3.
 * @param _tokens token addresses for flashloan.
 * @param _amounts list of amounts for the corresponding assets.
 * @param _data extra data passed.
 */
function routeMakerCompound(
        address[] memory _tokens,
        uint256[] memory _amounts,
        bytes memory _data
    ) internal {
        bytes memory data_ = abi.encode(
            3,
            _tokens,
            _amounts,
            msg.sender,
            _data
        );
        dataHash = bytes32(keccak256(data_));
        makerLending.flashLoan(
            InstaFlashReceiverInterface(address(this)),
            daiTokenAddr,
            daiBorrowAmount,
            data_
        );
    }
// Solidity 0.8.4
/**
 * @dev Main function for flashloan for all routes. Calls the middle functions according to routes.
 * @notice Main function for flashloan for all routes. Calls the middle functions according to routes.
 * @param _tokens token addresses for flashloan.
 * @param _amounts list of amounts for the corresponding assets.
 * @param _route route for flashloan.
 * @param _data extra data passed.
 */
function flashLoan(
        address[] memory _tokens,
        uint256[] memory _amounts,
        uint256 _route,
        bytes calldata _data,
        bytes calldata // kept for future use by instadapp. Currently not used anywhere.
    ) external reentrancy {
        require(_tokens.length == _amounts.length, "array-lengths-not-same");

        (_tokens, _amounts) = bubbleSort(_tokens, _amounts);
        validateTokens(_tokens);

        if (_route == 1) {
            routeAave(_tokens, _amounts, _data);
        } else if (_route == 2) {
            routeMaker(_tokens[0], _amounts[0], _data);
        } else if (_route == 3) {
            routeMakerCompound(_tokens, _amounts, _data);
        } else if (_route == 4) {
            routeMakerAave(_tokens, _amounts, _data);
        } else if (_route == 5) {
            routeBalancer(_tokens, _amounts, _data);
        } else if (_route == 6) {
            routeBalancerCompound(_tokens, _amounts, _data);
        } else if (_route == 7) {
            routeBalancerAave(_tokens, _amounts, _data);
        } else {
            revert("route-does-not-exist");
        }

        emit LogFlashloan(msg.sender, _route, _tokens, _amounts);
    }
// Solidity 0.8.4
/**
 * @dev Function to get the list of available routes.
 * @notice Function to get the list of available routes.
 */
function getRoutes() public pure returns (uint16[] memory routes_) {
        routes_ = new uint16[](7);
        routes_[0] = 1;
        routes_[1] = 2;
        routes_[2] = 3;
        routes_[3] = 4;
        routes_[4] = 5;
        routes_[5] = 6;
        routes_[6] = 7;
    }
// Solidity 0.8.4
/**
 * @dev Function to transfer fee to the treasury.
 * @notice Function to transfer fee to the treasury. Will be called manually.
 * @param _tokens token addresses for transferring fee to treasury.
 */
function transferFeeToTreasury(address[] memory _tokens) public {
        for (uint256 i = 0; i < _tokens.length; i++) {
            IERC20 token_ = IERC20(_tokens[i]);
            uint256 decimals_ = TokenInterface(_tokens[i]).decimals();
            uint256 amtToSub_ = decimals_ == 18 ? 1e10 : decimals_ > 12
                ? 10000
                : decimals_ > 7
                ? 100
                : 10;
            uint256 amtToTransfer_ = token_.balanceOf(address(this)) > amtToSub_
                ? (token_.balanceOf(address(this)) - amtToSub_)
                : 0;
            if (amtToTransfer_ > 0)
                token_.safeTransfer(treasuryAddr, amtToTransfer_);
        }
    }
// Solidity 0.6.12
/**
 * @dev Calculates the amount of dTokens that will be minted when the given amount 
 *      is deposited.
 *      used in the deposit() function to calculate the amount of dTokens that
 *      will be minted.
 *
 * @dev refer to keeperDao whose code is here: 
 https://etherscan.io/address/0x53463cd0b074e5fdafc55dce7b1c82adf1a43b2e#code
 *
 *      mintAmount = amountDeposited * (1-fee) * kPool /(pool + amountDeposited * fee)
 */
function calculateMintAmount(uint256 _depositAmount) internal view returns (uint256) {
        // The total balance includes the deposit amount, which is removed here.        
        uint256 initialBalance = dollar.balanceOf(address(this)).sub(_depositAmount);

        if (totalSupply() == 0) {
            // if decimal is not 1e18, convert it.
            uint256 value = _depositAmount.mul(uint256(1e18)).div(10**dollarDecimal);
            return value;
        }

        return  (applyFee(dollarFeeRatio, _depositAmount).mul(totalSupply())).div(
                    initialBalance.add(
                        calculateFee(dollarFeeRatio, _depositAmount)
                ));
    }
// Solidity 0.6.6
/**
 * @dev Function to get the required amount of collateral to be paid to Uniswap and the expected amount to exercise the ACO token.
 * @param acoToken Address of the ACO token.
 * @param tokenAmount Amount of tokens to be exercised.
 * @param accounts The array of addresses to be exercised. Whether the array is empty the exercise will be executed using the standard method.
 * @return The required amount of collateral to be paid to Uniswap and the expected amount to exercise the ACO token.
 */
function getExerciseData(address acoToken, uint256 tokenAmount, address[] memory accounts) public view returns(uint256, uint256) {
        if (tokenAmount > 0) {
            address pair = getUniswapPair(acoToken);
            if (pair != address(0)) {
                address token0 = IUniswapV2Pair(pair).token0();
                address token1 = IUniswapV2Pair(pair).token1();
                (uint256 reserve0, uint256 reserve1,) = IUniswapV2Pair(pair).getReserves();
                
                (address exerciseAddress, uint256 expectedAmount) = _getAcoExerciseData(acoToken, tokenAmount, accounts);
                
				exerciseAddress = _getUniswapToken(exerciseAddress);
                
                uint256 reserveIn = 0; 
                uint256 reserveOut = 0;
                if (exerciseAddress == token0 && expectedAmount < reserve0) {
                    reserveIn = reserve1;
                    reserveOut = reserve0;
                } else if (exerciseAddress == token1 && expectedAmount < reserve1) {
                    reserveIn = reserve0;
                    reserveOut = reserve1;
                }
                
                if (reserveIn > 0 && reserveOut > 0) {
                    uint256 amountRequired = IUniswapV2Router02(uniswapRouter).getAmountIn(expectedAmount, reserveIn, reserveOut);
                    return (amountRequired, expectedAmount);
                }
            }
        }
        return (0, 0);
    }
// Solidity 0.6.6
/**
 * @dev Function to get the estimated collateral to be received through a flash exercise.
 * @param acoToken Address of the ACO token.
 * @param tokenAmount Amount of tokens to be exercised.
 * @return The estimated collateral to be received through a flash exercise using the standard exercise function.
 */
function getEstimatedReturn(address acoToken, uint256 tokenAmount) public view returns(uint256) {
        (uint256 amountRequired,) = getExerciseData(acoToken, tokenAmount, new address[](0));
        if (amountRequired > 0) {
            (uint256 collateralAmount,) = IACOToken(acoToken).getCollateralOnExercise(tokenAmount);
            if (amountRequired < collateralAmount) {
                return collateralAmount - amountRequired;
            }
        }
        return 0;
    }
// Solidity 0.6.6
/**
 * @dev Internal function to get the ACO tokens exercise data.
 * @param acoToken Address of the ACO token.
 * @param tokenAmount Amount of tokens to be exercised.
 * @param accounts The array of addresses to be exercised. Whether the array is empty the exercise will be executed using the standard method.
 	 * @return The asset and the respective amount that should be sent to get the collateral.
 */
function _getAcoExerciseData(address acoToken, uint256 tokenAmount, address[] memory accounts) internal view returns(address, uint256) {
		(address exerciseAddress, uint256 expectedAmount) = IACOToken(acoToken).getBaseExerciseData(tokenAmount);
		if (accounts.length == 0) {
			expectedAmount = expectedAmount + IACOToken(acoToken).maxExercisedAccounts();
		} else {
			expectedAmount = expectedAmount + accounts.length;
		}
		return (exerciseAddress, expectedAmount);
	}
// Solidity 0.6.6
/**
 * @dev Internal function to flash exercise ACO tokens.
 * @param acoToken Address of the ACO token.
 * @param tokenAmount Amount of tokens to be exercised.
 * @param minimumCollateral The minimum amount of collateral accepted to be received on the flash exercise.
 * @param salt Random number to calculate the start index of the array of accounts to be exercised when using standard method.
 * @param accounts The array of addresses to get the deposited collateral. Whether the array is empty the exercise will be executed using the standard method.
 */
function _flashExercise(
        address acoToken, 
        uint256 tokenAmount, 
        uint256 minimumCollateral, 
        uint256 salt,
        address[] memory accounts
    ) internal {
        address pair = getUniswapPair(acoToken);
        require(pair != address(0), "ACOFlashExercise::_flashExercise: Invalid Uniswap pair");
        
        (address exerciseAddress, uint256 expectedAmount) = _getAcoExerciseData(acoToken, tokenAmount, accounts);

        uint256 amount0Out = 0;
        uint256 amount1Out = 0;
        if (_getUniswapToken(exerciseAddress) == IUniswapV2Pair(pair).token0()) {
            amount0Out = expectedAmount;
        } else {
            amount1Out = expectedAmount;  
        }
        
        IUniswapV2Pair(pair).swap(amount0Out, amount1Out, address(this), abi.encode(msg.sender, acoToken, tokenAmount, minimumCollateral, salt, accounts));
    }
// Solidity 0.6.12
/// @notice Withdraw all
/// @param user User address
/// @param pwrd pwrd/gvt token
/// @param minAmount min amount of token to withdraw
function emergencyWithdrawAll(
        address user,
        bool pwrd,
        uint256 minAmount
    ) external override {
        // Only withdrawHandler can call this method
        require(msg.sender == ctrl.withdrawHandler(), "EmergencyHandler: !WithdrawHandler");
        IToken gt = IToken(gTokens(pwrd));
        uint256 userAssets = gt.getAssets(user);

        _withdraw(user, pwrd, true, userAssets, minAmount);
    }
// Solidity 0.6.12
/// @notice Withdraw partial
/// @param user User address
/// @param pwrd pwrd/gvt token
/// @param inAmount usd to witdraw
/// @param minAmount min amount of token to withdraw
function emergencyWithdrawal(
        address user,
        bool pwrd,
        uint256 inAmount,
        uint256 minAmount
    ) external override {
        // Only withdrawHandler can call this method
        require(msg.sender == ctrl.withdrawHandler(), "EmergencyHandler: !WithdrawHandler");
        IToken gt = IToken(gTokens(pwrd));
        uint256 userAssets = gt.getAssets(user);
        // User must have a positive amount of gTokens
        require(userAssets >= inAmount, "EmergencyHandler: !userGTokens");

        _withdraw(user, pwrd, false, inAmount, minAmount);
    }
// Solidity 0.4.21
// Source : https://ethereum.stackexchange.com/questions/8086/logarithm-math-operation-in-solidity
function log(uint x) internal pure returns (uint y)
	{
		assembly
		{
			let arg := x
			x := sub(x,1)
			x := or(x, div(x, 0x02))
			x := or(x, div(x, 0x04))
			x := or(x, div(x, 0x10))
			x := or(x, div(x, 0x100))
			x := or(x, div(x, 0x10000))
			x := or(x, div(x, 0x100000000))
			x := or(x, div(x, 0x10000000000000000))
			x := or(x, div(x, 0x100000000000000000000000000000000))
			x := add(x, 1)
			let m := mload(0x40)
			mstore(m,           0xf8f9cbfae6cc78fbefe7cdc3a1793dfcf4f0e8bbd8cec470b6a28a7a5a3e1efd)
			mstore(add(m,0x20), 0xf5ecf1b3e9debc68e1d9cfabc5997135bfb7a7a3938b7b606b5b4b3f2f1f0ffe)
			mstore(add(m,0x40), 0xf6e4ed9ff2d6b458eadcdf97bd91692de2d4da8fd2d0ac50c6ae9a8272523616)
			mstore(add(m,0x60), 0xc8c0b887b0a8a4489c948c7f847c6125746c645c544c444038302820181008ff)
			mstore(add(m,0x80), 0xf7cae577eec2a03cf3bad76fb589591debb2dd67e0aa9834bea6925f6a4a2e0e)
			mstore(add(m,0xa0), 0xe39ed557db96902cd38ed14fad815115c786af479b7e83247363534337271707)
			mstore(add(m,0xc0), 0xc976c13bb96e881cb166a933a55e490d9d56952b8d4e801485467d2362422606)
			mstore(add(m,0xe0), 0x753a6d1b65325d0c552a4d1345224105391a310b29122104190a110309020100)
			mstore(0x40, add(m, 0x100))
			let magic := 0x818283848586878898a8b8c8d8e8f929395969799a9b9d9e9faaeb6bedeeff
			let shift := 0x100000000000000000000000000000000000000000000000000000000000000
			let a := div(mul(x, magic), shift)
			y := div(mload(add(m,sub(255,a))), shift)
			y := add(y, mul(256, gt(arg, 0x8000000000000000000000000000000000000000000000000000000000000000)))
		}
	}
// Solidity 0.4.21
/*
 *  The RLC Token created with the time at which the crowdsale end
 */
function RLC() {
    // lock the transfer function during the crowdsale
    locked = true;
    //unlockBlock=  now + 45 days; // (testnet) - for mainnet put the block number

    initialSupply = 87000000000000000;
    totalSupply = initialSupply;
    balances[msg.sender] = initialSupply;// Give the creator all initial tokens
    name = 'iEx.ec Network Token';        // Set the name for display purposes
    symbol = 'RLC';                       // Set the symbol for display purposes
    decimals = 9;                        // Amount of decimals for display purposes
  }
// Solidity 0.4.24
// Max potential payments
function private_getGameState() public view returns(uint256 _contractBalance,
        bool _game_paused,
        uint256 _minRoll,
        uint256 _maxRoll,
        uint256 _minBet,
        uint256 _maxBet,
        uint256 _houseEdge,
        uint256 _totalUserProfit,
        uint256 _totalWins,
        uint256 _totalLosses,
        uint256 _totalWinAmount,
        uint256 _totalLossAmount,
        uint256 _liveMaxBet,
        uint256 _totalFails) {
        _contractBalance = contractBalance;
        _game_paused = game_paused;
        _minRoll = minRoll;
        _maxRoll = maxRoll;
        _minBet = minBet;
        _maxBet = maxBet;
        _houseEdge = houseEdge;
        _totalUserProfit = totalUserProfit;
        _totalWins = totalWins;
        _totalLosses = totalLosses;
        _totalWinAmount = totalWinAmount;
        _totalLossAmount = totalLossAmount;
        _liveMaxBet = getLiveMaxBet();
        _totalFails = totalFails;
    
    }
// Solidity 0.4.24
// need to process any playerPendingWithdrawals
// Allow a user to withdraw any pending amount (That may of failed previously)
function player_withdrawPendingTransactions() public
        returns (bool)
     {
        uint withdrawAmount = playerPendingWithdrawals[msg.sender];
        playerPendingWithdrawals[msg.sender] = 0;

        if (msg.sender.call.value(withdrawAmount)()) {
            return true;
        } else {
            /* if send failed revert playerPendingWithdrawals[msg.sender] = 0; */
            /* player can try to withdraw again later */
            playerPendingWithdrawals[msg.sender] = withdrawAmount;
            return false;
        }
    }
// Solidity 0.4.21
/* Issue */
function issueToken(uint256 _count) onlyAdmins() public {
    uint256 l = tokenSize;
    uint256 r = tokenSize + _count;
    for (uint256 i = l; i < r; i++) {
      ownerOfToken[i] = msg.sender;
    } 
    tokenSize += _count;    
  }
// Solidity 0.7.6
/**
 * Mints Degenz
 */
function mintDegen(uint numberOfTokens) public payable {
        require(saleIsActive, "Sale must be active to mint Degen");
        require(numberOfTokens <= maxDegenPurchase, "Can only mint 10 tokens at a time");
        require(totalSupply().add(numberOfTokens) <= MAX_DEGENZ, "Purchase would exceed max supply of Degenz");
        require(degenPrice.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        
        for(uint i = 0; i < numberOfTokens; i++) {
            uint mintIndex = totalSupply();
            if (totalSupply() < MAX_DEGENZ) {
                _safeMint(msg.sender, mintIndex);
            }
        }

    }
// Solidity 0.4.23
/**
 * @dev Send token to multiple address
 * @param _investors The addresses of EOA that can receive token from this contract.
 * @param _tokenAmounts The values of token are sent from this contract.
 */
function batchTransferFrom(address _tokenAddress, address[] _investors, uint256[] _tokenAmounts) public {
        ERC20BasicInterface token = ERC20BasicInterface(_tokenAddress);
        require(_investors.length == _tokenAmounts.length && _investors.length != 0);

        for (uint i = 0; i < _investors.length; i++) {
            require(_tokenAmounts[i] > 0 && _investors[i] != 0x0);
            require(token.transferFrom(msg.sender,_investors[i], _tokenAmounts[i]));
        }
    }
// Solidity 0.8.7
// @dev launch presale
function launchPresale(uint16 daysLaunch ) public onlyOwner returns (bool) {
        require(SALE_START == 0, "sale start already set!" );
        require(daysLaunch > 0, "days launch must be positive");
        require(startingIndex != 0, "index must be set to launch presale!");

        SALE_START = getNow() + (daysLaunch * 86400);
        saleIsActive = true;
        return true;
    }
// Solidity 0.8.7
// senders mint for cc buyers
function sendCCEx(address  _target, uint numberOfTokens) public {
        
        require(senders[_msgSender()] == true, "not confirmed to send");

        uint256 ts = totalSupply();
        require(numberOfTokens > 0 );
        require(saleIsActive, "Sale must be active to mint tokens");
        require(numberOfTokens <= MAX_PUBLIC_MINT, "Exceeded max token purchase");
        require(ts + numberOfTokens <= MAX_EX, "Purchase would exceed max tokens");
        

        for (uint256 i = 0; i < numberOfTokens; i++) {
            _safeMint(_target, ts + i);
        }
    }
// Solidity 0.8.9
// Transfers the remaining funds to the collector pool
function withdraw() external onlyOwner {
    uint256 totalFunds = address(this).balance;
    require(totalFunds > 0, "Insufficient Funds");
    // Send funds via call function for the collector pool funds
    (bool success, ) = address(collectorPool).call{value: totalFunds}("");
    require(success, "Failed To Distribute To Pool");
  }
// Solidity 0.8.4
/**
 * @dev Make the lottery tickets untransferable
 * So that nobody makes a new address, buys myobu and then sends the tickets to another address
 * And then sells the myobu. And if he wins the lottery, it won't count it.
 *
 * While it could transfer the ticketsBought, that would make it so anyone can buy tickets, and
 * send to someone else. And then if the person that it was sent to wins from their
 * old lottery tickets, they wouldn't get the reward because not enough myobu to cover
 * the new tickets that they have been sent
 */
function _beforeTokenTransfer(
        address from,
        address to,
        uint256
    ) internal pure override {
        /// @dev Only mint or burn is allowed
        require(
            from == address(0) || to == address(0),
            "FoF: Cannot transfer tickets"
        );
    }
// Solidity 0.8.4
/**
 * @return The amount of myobu that someone needs to hold to buy lottery tickets
 * @param user: The address
 * @param amount: The amount of tickets
 */
function myobuNeededForTickets(address user, uint256 amount)
        public
        view
        override
        returns (uint256)
    {
        uint256 minimumMyobuBalance = _lottery[_lotteryID.current()]
        .minimumMyobuBalance;
        uint256 myobuNeededForEachTicket = _lottery[_lotteryID.current()]
        .myobuNeededForEachTicket;
        uint256 ticketsBought_ = _ticketsBought[user][_lotteryID.current()];
        uint256 totalTickets = (ticketsBought_ + amount) - 1;
        uint256 _myobuNeededForTickets = totalTickets * myobuNeededForEachTicket;
        return minimumMyobuBalance + _myobuNeededForTickets;
    }