lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.8
//  get total count tokens (to calculate profit for one token)
function get_CountProfitsToken() constant returns(uint256){
		uint256 countProfitsTokens = 0;

		mapping(address => bool) uniqueHolders;

		uint256 countHolders = smartToken.getCountHolders();
		for(uint256 i=0; i<countHolders; i++)
		{
			address holder = smartToken.getItemHolders(i);
			if(holder!=address(0x0) && !uniqueHolders[holder])
			{
				uint256 holdersTokens = smartToken.balanceOf(holder);
				if(holdersTokens>0)
				{
					uint256 tempTokens = smartToken.tempTokensBalanceOf(holder);
					if((holdersTokens+tempTokens)/decimal >= tokensNeededToGetPayment)
					{
						uniqueHolders[holder]=true;
						countProfitsTokens += (holdersTokens+tempTokens);
					}
				}
			}
		}

		uint256 countTempHolders = smartToken.getCountTempHolders();
		for(uint256 j=0; j<countTempHolders; j++)
		{
			address temp_holder = smartToken.getItemTempHolders(j);
			if(temp_holder!=address(0x0) && !uniqueHolders[temp_holder])
			{
				uint256 token_balance = smartToken.balanceOf(temp_holder);
				if(token_balance==0)
				{
					uint256 count_tempTokens = smartToken.tempTokensBalanceOf(temp_holder);
					if(count_tempTokens>0 && count_tempTokens/decimal >= tokensNeededToGetPayment)
					{
						uniqueHolders[temp_holder]=true;
						countProfitsTokens += count_tempTokens;
					}
				}
			}
		}
		
		return countProfitsTokens;
	}
// Solidity 0.4.8
// get holders addresses to make payment each of them
function get_Holders(uint256 position) constant returns(address[64] listHolders, uint256 nextPosition) 
	{
		uint8 n = 0;		
		uint256 countHolders = smartToken.getCountHolders();
		for(; position < countHolders; position++){			
			address holder = smartToken.getItemHolders(position);
			if(holder!=address(0x0)){
				uint256 holdersTokens = smartToken.balanceOf(holder);
				if(holdersTokens>0){
					uint256 tempTokens = smartToken.tempTokensBalanceOf(holder);
					if((holdersTokens+tempTokens)/decimal >= tokensNeededToGetPayment){
						//
						listHolders[n++] = holder;
						if (n == 64) 
						{
							nextPosition = position + 1;
							return;
						}
					}
				}
			}
		}

		
		if (position >= countHolders)
		{			
			uint256 countTempHolders = smartToken.getCountTempHolders();			
			for(uint256 j=position-countHolders; j<countTempHolders; j++) 
			{							
				address temp_holder = smartToken.getItemTempHolders(j);
				if(temp_holder!=address(0x0)){
					uint256 token_balance = smartToken.balanceOf(temp_holder);
					if(token_balance==0){
						uint256 count_tempTokens = smartToken.tempTokensBalanceOf(temp_holder);
						if(count_tempTokens>0 && count_tempTokens/decimal >= tokensNeededToGetPayment){
							listHolders[n++] = temp_holder;
							if (n == 64) 
							{
								nextPosition = position + 1;
								return;
							}
						}
					}
				}

				position = position + 1;
			}
		}

		nextPosition = 0;
	}
// Solidity 0.4.8
// Get profit for specified token holder
// Function should be executed in blockDividend ! (see struct DividendInfo)
// Don't call this function via etherescan.io
// Example how to call via JavaScript and web3
// var abiDividend = [...];
// var holderAddress = "0xdd94ddf50485f41491c415e7133100e670cd4ef3";
// var dividendIndex = 1;       // starts from zero
// var blockDividend = 3527958; // see function getDividendInfo
// web3.eth.contract(abiDividend).at("0x600e18779b6aC789b95a12C30b5863E842F4ae1d").get_HoldersProfit(dividendIndex, holderAddress, blockDividend, function(err, profit){
//    alert("Your profit " + web3.fromWei(profit).toString(10) + "ETH");
// });
function get_HoldersProfit(uint256 dividendPaymentNum, address holder) constant returns(uint256){
		uint256 profit = 0;
		if(holder != address(0x0) && dividendHistory.length > 0 && dividendPaymentNum < dividendHistory.length){
			uint256 count_tokens = smartToken.balanceOf(holder) + smartToken.tempTokensBalanceOf(holder);
			if(count_tokens/decimal >= tokensNeededToGetPayment){
				profit = (count_tokens*dividendHistory[dividendPaymentNum].amountDividend)/get_CountProfitsToken();
			}
		}
		return profit;
	}
// Solidity 0.4.19
//CONSTANT HELPER FUNCTIONS
function getBankroll()
        constant
        returns(uint) {

        if ((invested < investorsProfit) ||
            (invested + investorsProfit < invested) ||
            (invested + investorsProfit < investorsLosses)) {
            return 0;
        }
        else {
            return invested + investorsProfit - investorsLosses;
        }
    }
// Solidity 0.4.25
/* Allocate Tokens for MAR */
function allocateMARTokens() public {
        require(msg.sender==tokenIssuer);
        uint tokens = 0;
     
        if(block.timestamp > month6Unlock && !month6Allocated)
        {
            month6Allocated = true;
            tokens = safeDiv(totalTokensMAR, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
            
        }
        else if(block.timestamp > month12Unlock && !month12Allocated)
        {
            month12Allocated = true;
            tokens = safeDiv(totalTokensMAR, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
            
        }
        else if(block.timestamp > month24Unlock && !month24Allocated)
        {
            month24Allocated = true;
            tokens = safeDiv(totalTokensMAR, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
            
        }
        else if(block.timestamp > month36Unlock && !month36Allocated)
        {
            month36Allocated = true;
            tokens = safeDiv(totalTokensMAR, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
        }
        else if(block.timestamp > month48Unlock && !month48Allocated)
        {
            month48Allocated = true;
            tokens = safeDiv(totalTokensMAR, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
        }
        else revert();

        AllocateMARTokens(msg.sender);
    }
// Solidity 0.4.25
/* Allocate Tokens for DAPP */
function allocateDAPPTokens() public {
        require(msg.sender==tokenIssuer);
        uint tokens = 0;
     
        if(block.timestamp > month9Unlock && !month9Allocated)
        {
            month9Allocated = true;
            tokens = safeDiv(totalTokensDAPP, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
        }
        else if(block.timestamp > month18Unlock && !month18Allocated)
        {
            month18Allocated = true;
            tokens = safeDiv(totalTokensDAPP, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
            
        }
        else if(block.timestamp > month27Unlock && !month27Allocated)
        {
            month27Allocated = true;
            tokens = safeDiv(totalTokensDAPP, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
            
        }
        else if(block.timestamp > month36Unlock && !month36AllocatedDAPP)
        {
            month36AllocatedDAPP = true;
            tokens = safeDiv(totalTokensDAPP, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
        }
        else if(block.timestamp > month45Unlock && !month45Allocated)
        {
            month45Allocated = true;
            tokens = safeDiv(totalTokensDAPP, 5);
            balances[tokenIssuer] = safeAdd(balances[tokenIssuer], tokens);
            totalSupply = safeAdd(totalSupply, tokens);
        }
        else revert();

        AllocateDAPPTokens(msg.sender);
    }
// Solidity 0.4.25
/* Mint Token */
function mintTokens(address tokenHolder, uint256 amountToken) public
    returns (bool success)
    {
        require(msg.sender==tokenIssuer);
        
        if(totalTokenSaled + amountToken <= totalTokensCrowdSale + totalTokensReward)
        {
            balances[tokenHolder] = safeAdd(balances[tokenHolder], amountToken);
            totalTokenSaled = safeAdd(totalTokenSaled, amountToken);
            totalSupply = safeAdd(totalSupply, amountToken);
            TokenMint(tokenHolder, amountToken);
            return true;
        }
        else
        {
            return false;
        }
    }
// Solidity 0.8.4
/**
 * @dev Approves the token to the spender address with allowance amount.
 * @notice Approves the token to the spender address with allowance amount.
 * @param token_ token for which allowance is to be given.
 * @param spender_ the address to which the allowance is to be given.
 * @param amount_ amount of token.
 */
function approve(
        address token_,
        address spender_,
        uint256 amount_
    ) internal {
        TokenInterface tokenContract_ = TokenInterface(token_);
        try tokenContract_.approve(spender_, amount_) {} catch {
            IERC20 token = IERC20(token_);
            token.safeApprove(spender_, 0);
            token.safeApprove(spender_, amount_);
        }
    }
// Solidity 0.8.4
/**
 * @dev Approves the tokens to the receiver address with allowance (amount + fee).
 * @notice Approves the tokens to the receiver address with allowance (amount + fee).
 * @param _instaLoanVariables struct which includes list of token addresses and amounts.
 * @param _fees list of premiums/fees for the corresponding addresses for flashloan.
 * @param _receiver address to which tokens have to be approved.
 */
function safeApprove(
        FlashloanVariables memory _instaLoanVariables,
        uint256[] memory _fees,
        address _receiver
    ) internal {
        uint256 length_ = _instaLoanVariables._tokens.length;
        require(
            length_ == _instaLoanVariables._amounts.length,
            "Lengths of parameters not same"
        );
        require(length_ == _fees.length, "Lengths of parameters not same");
        for (uint256 i = 0; i < length_; i++) {
            approve(
                _instaLoanVariables._tokens[i],
                _receiver,
                _instaLoanVariables._amounts[i] + _fees[i]
            );
        }
    }
// Solidity 0.8.4
/**
 * @dev Transfers the tokens to the receiver address.
 * @notice Transfers the tokens to the receiver address.
 * @param _instaLoanVariables struct which includes list of token addresses and amounts.
 * @param _receiver address to which tokens have to be transferred.
 */
function safeTransfer(
        FlashloanVariables memory _instaLoanVariables,
        address _receiver
    ) internal {
        uint256 length_ = _instaLoanVariables._tokens.length;
        require(
            length_ == _instaLoanVariables._amounts.length,
            "Lengths of parameters not same"
        );
        for (uint256 i = 0; i < length_; i++) {
            IERC20 token = IERC20(_instaLoanVariables._tokens[i]);
            token.safeTransfer(_receiver, _instaLoanVariables._amounts[i]);
        }
    }
// Solidity 0.8.4
/**
 * @dev Calculates the balances..
 * @notice Calculates the balances of the account passed for the tokens.
 * @param _tokens list of token addresses to calculate balance for.
 * @param _account account to calculate balance for.
 */
function calculateBalances(address[] memory _tokens, address _account)
        internal
        view
        returns (uint256[] memory)
    {
        uint256 _length = _tokens.length;
        uint256[] memory balances_ = new uint256[](_length);
        for (uint256 i = 0; i < _length; i++) {
            IERC20 token = IERC20(_tokens[i]);
            balances_[i] = token.balanceOf(_account);
        }
        return balances_;
    }
// Solidity 0.8.4
/**
 * @dev Supply tokens for the amounts to compound.
 * @notice Supply tokens for the amounts to compound.
 * @param _tokens token addresses.
 * @param _amounts amounts of tokens.
 */
function compoundSupply(address[] memory _tokens, uint256[] memory _amounts)
        internal
    {
        uint256 length_ = _tokens.length;
        require(_amounts.length == length_, "array-lengths-not-same");
        address[] memory cTokens_ = new address[](length_);
        for (uint256 i = 0; i < length_; i++) {
            if (_tokens[i] == address(wethToken)) {
                wethToken.withdraw(_amounts[i]);
                CEthInterface cEth_ = CEthInterface(cethTokenAddr);
                cEth_.mint{value: _amounts[i]}();
                cTokens_[i] = cethTokenAddr;
            } else {
                CTokenInterface cToken_ = CTokenInterface(
                    tokenToCToken[_tokens[i]]
                );
                // Approved already in addTokenToctoken function
                require(cToken_.mint(_amounts[i]) == 0, "mint failed");
                cTokens_[i] = tokenToCToken[_tokens[i]];
            }
        }
    }
// Solidity 0.8.4
/**
 * @dev Withdraw tokens from compound.
 * @notice Withdraw tokens from compound.
 * @param _tokens token addresses.
 * @param _amounts amounts of tokens.
 */
function compoundWithdraw(
        address[] memory _tokens,
        uint256[] memory _amounts
    ) internal {
        uint256 length_ = _tokens.length;
        require(_amounts.length == length_, "array-lengths-not-same");
        for (uint256 i = 0; i < length_; i++) {
            if (_tokens[i] == address(wethToken)) {
                CEthInterface cEth_ = CEthInterface(cethTokenAddr);
                require(
                    cEth_.redeemUnderlying(_amounts[i]) == 0,
                    "redeem failed"
                );
                wethToken.deposit{value: _amounts[i]}();
            } else {
                CTokenInterface cToken_ = CTokenInterface(
                    tokenToCToken[_tokens[i]]
                );
                require(
                    cToken_.redeemUnderlying(_amounts[i]) == 0,
                    "redeem failed"
                );
            }
        }
    }
// Solidity 0.8.4
/**
 * @dev Supply tokens to aave.
 * @notice Supply tokens to aave.
 * @param _tokens token addresses.
 * @param _amounts amounts of tokens.
 */
function aaveSupply(address[] memory _tokens, uint256[] memory _amounts)
        internal
    {
        uint256 length_ = _tokens.length;
        require(_amounts.length == length_, "array-lengths-not-same");
        for (uint256 i = 0; i < length_; i++) {
            approve(_tokens[i], address(aaveLending), _amounts[i]);
            aaveLending.deposit(_tokens[i], _amounts[i], address(this), 3228);
            aaveLending.setUserUseReserveAsCollateral(_tokens[i], true);
        }
    }
// Solidity 0.8.4
/**
 * @dev Borrow tokens from aave.
 * @notice Borrow tokens from aave.
 * @param _tokens list of token addresses.
 * @param _amounts list of amounts for respective tokens.
 */
function aaveBorrow(address[] memory _tokens, uint256[] memory _amounts)
        internal
    {
        uint256 length_ = _tokens.length;
        require(_amounts.length == length_, "array-lengths-not-same");
        for (uint256 i = 0; i < length_; i++) {
            aaveLending.borrow(_tokens[i], _amounts[i], 2, 3228, address(this));
        }
    }
// Solidity 0.8.4
/**
 * @dev Payback tokens to aave.
 * @notice Payback tokens to aave.
 * @param _tokens list of token addresses.
 * @param _amounts list of amounts for respective tokens.
 */
function aavePayback(address[] memory _tokens, uint256[] memory _amounts)
        internal
    {
        uint256 length_ = _tokens.length;
        require(_amounts.length == length_, "array-lengths-not-same");
        for (uint256 i = 0; i < length_; i++) {
            approve(_tokens[i], address(aaveLending), _amounts[i]);
            aaveLending.repay(_tokens[i], _amounts[i], 2, address(this));
        }
    }
// Solidity 0.8.4
/**
 * @dev Withdraw tokens from aave.
 * @notice Withdraw tokens from aave.
 * @param _tokens token addresses.
 * @param _amounts amounts of tokens.
 */
function aaveWithdraw(address[] memory _tokens, uint256[] memory _amounts)
        internal
    {
        uint256 length_ = _tokens.length;
        require(_amounts.length == length_, "array-lengths-not-same");
        for (uint256 i = 0; i < length_; i++) {
            aaveLending.withdraw(_tokens[i], _amounts[i], address(this));
        }
    }
// Solidity 0.8.4
/**
 * @dev Returns fee for the passed route in BPS.
 * @notice Returns fee for the passed route in BPS. 1 BPS == 0.01%.
 * @param _route route number for flashloan.
 */
function calculateFeeBPS(uint256 _route, address account_)
        public
        view
        returns (uint256 BPS_)
    {
        if (_route == 1) {
            BPS_ = aaveLending.FLASHLOAN_PREMIUM_TOTAL();
        } else if (_route == 2 || _route == 3 || _route == 4) {
            BPS_ = (makerLending.toll()) / (10**14);
        } else if (_route == 5 || _route == 6 || _route == 7) {
            BPS_ =
                (
                    balancerLending
                        .getProtocolFeesCollector()
                        .getFlashLoanFeePercentage()
                ) *
                100;
        } else {
            revert("Invalid source");
        }

        if (!isWhitelisted[account_] && BPS_ < InstaFeeBPS) {
            BPS_ = InstaFeeBPS;
        }
    }
// Solidity 0.8.4
/**
 * @dev Calculate fees for the respective amounts and fee in BPS passed.
 * @notice Calculate fees for the respective amounts and fee in BPS passed. 1 BPS == 0.01%.
 * @param _amounts list of amounts.
 * @param _BPS fee in BPS.
 */
function calculateFees(uint256[] memory _amounts, uint256 _BPS)
        internal
        pure
        returns (uint256[] memory)
    {
        uint256 length_ = _amounts.length;
        uint256[] memory InstaFees = new uint256[](length_);
        for (uint256 i = 0; i < length_; i++) {
            InstaFees[i] = (_amounts[i] * _BPS) / (10**4);
        }
        return InstaFees;
    }
// Solidity 0.8.4
/**
 * @dev Sort the tokens and amounts arrays according to token addresses.
 * @notice Sort the tokens and amounts arrays according to token addresses.
 * @param _tokens list of token addresses.
 * @param _amounts list of respective amounts.
 */
function bubbleSort(address[] memory _tokens, uint256[] memory _amounts)
        internal
        pure
        returns (address[] memory, uint256[] memory)
    {
        for (uint256 i = 0; i < _tokens.length - 1; i++) {
            for (uint256 j = 0; j < _tokens.length - i - 1; j++) {
                if (_tokens[j] > _tokens[j + 1]) {
                    (
                        _tokens[j],
                        _tokens[j + 1],
                        _amounts[j],
                        _amounts[j + 1]
                    ) = (
                        _tokens[j + 1],
                        _tokens[j],
                        _amounts[j + 1],
                        _amounts[j]
                    );
                }
            }
        }
        return (_tokens, _amounts);
    }
// Solidity 0.4.18
/**
 * Constructor - instantiates token supply and allocates balanace of
 * to the owner (msg.sender).
 */
function QuantstampToken(address _admin) {
        // the owner is a custodian of tokens that can
        // give an allowance of tokens for crowdsales
        // or to the admin, but cannot itself transfer
        // tokens; hence, this requirement
        require(msg.sender != _admin);

        totalSupply = INITIAL_SUPPLY;
        crowdSaleAllowance = CROWDSALE_ALLOWANCE;
        adminAllowance = ADMIN_ALLOWANCE;

        // mint all tokens
        balances[msg.sender] = totalSupply;
        Transfer(address(0x0), msg.sender, totalSupply);

        adminAddr = _admin;
        approve(adminAddr, adminAllowance);
    }
// Solidity 0.4.18
/**
 * Associates this token with a current crowdsale, giving the crowdsale
 * an allowance of tokens from the crowdsale supply. This gives the
 * crowdsale the ability to call transferFrom to transfer tokens to
 * whomever has purchased them.
 *
 * Note that if _amountForSale is 0, then it is assumed that the full
 * remaining crowdsale supply is made available to the crowdsale.
 *
 * @param _crowdSaleAddr The address of a crowdsale contract that will sell this token
 * @param _amountForSale The supply of tokens provided to the crowdsale
 */
function setCrowdsale(address _crowdSaleAddr, uint256 _amountForSale) external onlyOwner {
        require(!transferEnabled);
        require(_amountForSale <= crowdSaleAllowance);

        // if 0, then full available crowdsale supply is assumed
        uint amount = (_amountForSale == 0) ? crowdSaleAllowance : _amountForSale;

        // Clear allowance of old, and set allowance of new
        approve(crowdSaleAddr, 0);
        approve(_crowdSaleAddr, amount);

        crowdSaleAddr = _crowdSaleAddr;
    }
// Solidity 0.4.18
/**
 * Overrides ERC20 transferFrom function with modifier that prevents the
 * ability to transfer tokens until after transfers have been enabled.
 */
function transferFrom(address _from, address _to, uint256 _value) public onlyWhenTransferEnabled validDestination(_to) returns (bool) {
        bool result = super.transferFrom(_from, _to, _value);
        if (result) {
            if (msg.sender == crowdSaleAddr)
                crowdSaleAllowance = crowdSaleAllowance.sub(_value);
            if (msg.sender == adminAddr)
                adminAllowance = adminAllowance.sub(_value);
        }
        return result;
    }
// Solidity 0.8.4
/**
 * @dev Overload of {ECDSA-recover} that receives the `r` and `vs` short-signature fields separately.
 *
 * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
 *
 * _Available since v4.2._
 */
function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        bytes32 s;
        uint8 v;
        assembly {
            s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
            v := add(shr(255, vs), 27)
        }
        return recover(hash, v, r, s);
    }
// Solidity 0.5.8
// via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol MIT licence
function Concatenate(string memory a, string memory b) public pure returns (string memory concatenatedString) {
    bytes memory bytesA = bytes(a);
    bytes memory bytesB = bytes(b);
    string memory concatenatedAB = new string(bytesA.length + bytesB.length);
    bytes memory bytesAB = bytes(concatenatedAB);
    uint concatendatedIndex = 0;
    uint index = 0;
    for (index = 0; index < bytesA.length; index++) {
      bytesAB[concatendatedIndex++] = bytesA[index];
    }
    for (index = 0; index < bytesB.length; index++) {
      bytesAB[concatendatedIndex++] = bytesB[index];
    }

    return string(bytesAB);
  }
// Solidity 0.8.4
/**
 * @dev Add to token to cToken mapping.
 * @notice Add to token to cToken mapping.
 * @param _cTokens list of cToken addresses to be added to the mapping.
 */
function addTokenToCToken(address[] memory _cTokens) public {
        for (uint256 i = 0; i < _cTokens.length; i++) {
            (bool isMarket_, , ) = troller.markets(_cTokens[i]);
            require(isMarket_, "unvalid-ctoken");
            address token_ = CTokenInterface(_cTokens[i]).underlying();
            require(tokenToCToken[token_] == address((0)), "already-added");
            tokenToCToken[token_] = _cTokens[i];
            IERC20(token_).safeApprove(_cTokens[i], type(uint256).max);
        }
    }