lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.20
/**
 * @dev gets freezing end date and freezing balance for the freezing portion specified by index.
 * @param _addr Address of freeze tokens owner.
 * @param _index Freezing portion index. It ordered by release date descending.
 */
function getFreezing(address _addr, uint _index) public view returns (uint64 _release, uint _balance) {
        for (uint i = 0; i < _index + 1; i ++) {
            _release = chains[toKey(_addr, _release)];
            if (_release == 0) {
                return;
            }
        }
        _balance = freezings[toKey(_addr, _release)];
    }
// Solidity 0.4.20
/**
 * @dev freeze your tokens to the specified address.
 *      Be careful, gas usage is not deterministic,
 *      and depends on how many freezes _to address already has.
 * @param _to Address to which token will be freeze.
 * @param _amount Amount of token to freeze.
 * @param _until Release date, must be in future.
 */
function freezeTo(address _to, uint _amount, uint64 _until) public {
        require(_to != address(0));
        require(_amount <= balances[msg.sender]);

        balances[msg.sender] = balances[msg.sender].sub(_amount);

        bytes32 currentKey = toKey(_to, _until);
        freezings[currentKey] = freezings[currentKey].add(_amount);
        freezingBalance[_to] = freezingBalance[_to].add(_amount);

        freeze(_to, _until);
        Transfer(msg.sender, _to, _amount);
        Freezed(_to, _until, _amount);
    }
// Solidity 0.4.20
/**
 * @dev release first available freezing tokens.
 */
function releaseOnce() public {
        bytes32 headKey = toKey(msg.sender, 0);
        uint64 head = chains[headKey];
        require(head != 0);
        require(uint64(block.timestamp) > head);
        bytes32 currentKey = toKey(msg.sender, head);

        uint64 next = chains[currentKey];

        uint amount = freezings[currentKey];
        delete freezings[currentKey];

        balances[msg.sender] = balances[msg.sender].add(amount);
        freezingBalance[msg.sender] = freezingBalance[msg.sender].sub(amount);

        if (next == 0) {
            delete chains[headKey];
        }
        else {
            chains[headKey] = next;
            delete chains[currentKey];
        }
        Released(msg.sender, amount);
    }
// Solidity 0.4.20
/**
 * @dev release all available for release freezing tokens. Gas usage is not deterministic!
 * @return how many tokens was released
 */
function releaseAll() public returns (uint tokens) {
        uint release;
        uint balance;
        (release, balance) = getFreezing(msg.sender, 0);
        while (release != 0 && block.timestamp > release) {
            releaseOnce();
            tokens += balance;
            (release, balance) = getFreezing(msg.sender, 0);
        }
    }
// Solidity 0.4.20
/**
 * @dev Mint the specified amount of token to the specified address and freeze it until the specified date.
 *      Be careful, gas usage is not deterministic,
 *      and depends on how many freezes _to address already has.
 * @param _to Address to which token will be freeze.
 * @param _amount Amount of token to mint and freeze.
 * @param _until Release date, must be in future.
 * @return A boolean that indicates if the operation was successful.
 */
function mintAndFreeze(address _to, uint _amount, uint64 _until) onlyOwner canMint public returns (bool) {
        totalSupply = totalSupply.add(_amount);

        bytes32 currentKey = toKey(_to, _until);
        freezings[currentKey] = freezings[currentKey].add(_amount);
        freezingBalance[_to] = freezingBalance[_to].add(_amount);

        freeze(_to, _until);
        Mint(_to, _amount);
        Freezed(_to, _until, _amount);
        Transfer(msg.sender, _to, _amount);
        return true;
    }
// Solidity 0.4.18
/* Admin function for transfer coins */
function transferFromAdmin(address _from, address _to, uint256 _value) public onlyOwner returns(bool success) {
        if (_to == 0x0) revert();
        if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
        if ((balanceOf[_to] + _value) < balanceOf[_to]) revert(); // Check for overflows        

        // Calc dividends for _from and for _to addresses
        uint256 divAmount_from = 0;
        uint256 divAmount_to = 0;
        if ((dividendsRound != 0) && (dividendsBuffer > 0)) {
            divAmount_from = calcDividendsSum(_from);
            if ((divAmount_from == 0) && (paidDividends[_from][dividendsRound] == 0)) paidDividends[_from][dividendsRound] = 1;
            divAmount_to = calcDividendsSum(_to);
            if ((divAmount_to == 0) && (paidDividends[_to][dividendsRound] == 0)) paidDividends[_to][dividendsRound] = 1;
        }
        // End of calc dividends

        balanceOf[_from] -= _value; // Subtract from the sender
        balanceOf[_to] += _value; // Add the same to the recipient

        if (divAmount_from > 0) {
            if (!_from.send(divAmount_from)) revert();
        }
        if (divAmount_to > 0) {
            if (!_to.send(divAmount_to)) revert();
        }

        Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.4.18
/* 
 	Set params of ICO
 	
 	_auctionsStartBlock, _auctionsStopBlock - block number of start and stop of Ico
 	_auctionsMinTran - minimum transaction amount for Ico in wei
 */
function setICOParams(uint256 _gracePeriodPrice, uint32 _gracePeriodStartBlock, uint32 _gracePeriodStopBlock, uint256 _gracePeriodMaxTarget, uint256 _gracePeriodMinTran, bool _resetAmount) public onlyOwner {
    	gracePeriodStartBlock = _gracePeriodStartBlock;
        gracePeriodStopBlock = _gracePeriodStopBlock;
        gracePeriodMaxTarget = _gracePeriodMaxTarget;
        gracePeriodMinTran = _gracePeriodMinTran;
        
        buyPrice = _gracePeriodPrice;    	
    	
        icoFinished = false;        

        if (_resetAmount) icoRaisedETH = 0;
    }
// Solidity 0.4.18
// Initiate dividends round ( owner can transfer ETH to contract and initiate dividends round )
// aDividendsRound - is integer value of dividends period such as YYYYMM example 201712 (year 2017, month 12)
function setDividends(uint32 _dividendsRound) public payable onlyOwner {
        if (_dividendsRound > 0) {
            if (msg.value < 1000000000000000) revert();
            dividendsSum = msg.value;
            dividendsBuffer = msg.value;
        } else {
            dividendsSum = 0;
            dividendsBuffer = 0;
        }
        dividendsRound = _dividendsRound;
    }
// Solidity 0.4.18
// Get dividends
function getDividends() public {
        if (dividendsBuffer == 0) revert();
        if (balanceOf[msg.sender] == 0) revert();
        if (paidDividends[msg.sender][dividendsRound] != 0) revert();
        uint256 divAmount = calcDividendsSum(msg.sender);
        if (divAmount >= 100000000000000) {
            if (!msg.sender.send(divAmount)) revert();
        }
    }
// Solidity 0.4.18
// Stop ICO
function stopICO() public onlyOwner {
        if ( gracePeriodStopBlock > block.number ) gracePeriodStopBlock = block.number;
        
        icoFinished = true;

        weiToPresalersFromICO = icoRaisedETH * percentToPresalersFromICO / 10000;

        if (soldedSupply >= (burnAfterSoldAmount * 100000000)) {

            uint256 companyCost = soldedSupply * 1000000 * 10000;
            companyCost = companyCost / (10000 - percentToFoundersAfterICO) / 1000000;
            
            uint256 amountToFounders = companyCost - soldedSupply;

            // Burn extra coins if current balance of token greater than amountToFounders 
            if (balanceOf[this] > amountToFounders) {
                Burn(this, (balanceOf[this]-amountToFounders));
                balanceOf[this] = 0;
                totalSupply = companyCost;
            } else {
                totalSupply += amountToFounders - balanceOf[this];
            }

            balanceOf[owner] += amountToFounders;
            balanceOf[this] = 0;
            Transfer(this, owner, amountToFounders);
        }

        buyPrice = 0;
        sellPrice = 0;
    }
// Solidity 0.4.18
// Withdraw ETH to founders 
function withdrawToFounders(uint256 amount) public onlyOwner {
    	uint256 amount_to_withdraw = amount * 1000000000000000; // 0.001 ETH
        if ((this.balance - weiToPresalersFromICO) < amount_to_withdraw) revert();
        amount_to_withdraw = amount_to_withdraw / foundersAddresses.length;
        uint8 i = 0;
        uint8 errors = 0;
        
        for (i = 0; i < foundersAddresses.length; i++) {
			if (!foundersAddresses[i].send(amount_to_withdraw)) {
				errors++;
			}
		}
    }
// Solidity 0.5.16
/**
 * @dev Swaps funds to another token.
 * @param outputToken The output ERC20SwappableOutput token contract address.
 * @param payee The address to which the output funds will be sent.
 * @param inputAmount The amount of input tokens to be burned.
 */
function swap(address outputToken, address payee, uint256 inputAmount) external returns (bool) {
        require(_outputSwapTokens[outputToken] != 0, "Output token is not a registered output swap token.");
        require(inputAmount > 0, "No funds inputted to swap.");
        require(inputAmount <= this.balanceOf(payee), "Input amount cannot be greater than input token balance.");
        require(_outputSwapTokens[outputToken] < 0 || inputAmount <= uint256(_outputSwapTokens[outputToken]), "Input amount is greater than the limit for this output token.");
        ERC20SwappableOutput outputContract = ERC20SwappableOutput(outputToken);
        uint256 outputTotalSupply = outputContract.totalSupply();
        require(outputTotalSupply > 0, "Cannot reference zero total supply of output tokens when calculating output token amount.");
        uint256 outputAmount = inputAmount.mul(outputTotalSupply).div(this.totalSupply());
        _burn(msg.sender, inputAmount);
        require(outputContract.finishSwap(msg.sender, inputAmount, outputAmount), "Failed to finish swap with output token.");
        emit SwapInput(msg.sender, payee, inputAmount, outputAmount);
        return true;
    }
// Solidity 0.7.6
// GET Membership OF A WALLET AS STRING. 
function manokengNameOfOwner(address _owner) external view returns(string[] memory ) {
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount == 0) {
            // Return an empty array
            return new string[](0);
        } else {
            string[] memory result = new string[](tokenCount);
            uint256 index;
            for (index = 0; index < tokenCount; index++) {
                result[index] = manokengName[ tokenOfOwnerByIndex(_owner, index) ] ;
            }
            return result;
        }
    }
// Solidity 0.5.17
// Note: 
// This method should have been called issue(address _receiver), but will remain this for meme value
function squanderMyEthForWorthlessBeans(address _receiver)
        payable
        public
    { 
        // Goals:
        // 1. deposit eth into the vault 
        // 2. give the holder a claim on the vault for later withdrawal to the address they choose 
        // 3. pay the protocol

        require(getExcessCollateral() < riskLimit.add(msg.value), "risk limit exceeded");

        (uint protocolFee, 
        uint automationFee, 
        uint collateralToLock, 
        uint accreditedCollateral, 
        uint tokensToIssue)  = calculateIssuanceAmount(msg.value);

        bytes memory lockETHproxyCall = abi.encodeWithSignature(
            "lockETH(address,address,uint256)", 
            makerManager, 
            ethGemJoin,
            cdpId);
        IDSProxy(address(this)).execute.value(collateralToLock)(saverProxyActions, lockETHproxyCall);
        
        (bool protocolFeePaymentSuccess,) = gulper.call.value(protocolFee)("");
        require(protocolFeePaymentSuccess, "protocol fee transfer to gulper failed");

        // Note: 
        // The automationFee is left in the CDP to cover the gas implications of leaving or joining dEth
        // This is why it is not explicitly used in this method. 

        _mint(_receiver, tokensToIssue);
        
        emit Issued(
            _receiver, 
            msg.value, 
            protocolFee,
            automationFee, 
            collateralToLock, 
            accreditedCollateral,
            tokensToIssue);
    }
// Solidity 0.5.17
// note: all values used by defisaver are in WAD format
// we do not need that level of precision on this method
// so for simplicity and readability they are all set in discrete percentages here
function automate(
            uint _repaymentRatio,
            uint _targetRatio,
            uint _boostRatio,
            uint _minRedemptionRatio,
            uint _automationFeePerc,
            uint _riskLimit)
        public
        auth
    {
        // for reference - this function is called on the subscriptionsProxyV2: 
        // function subscribe(
        //     uint _cdpId, 
        //     uint128 _minRatio, 
        //     uint128 _maxRatio, 
        //     uint128 _optimalRatioBoost, 
        //     uint128 _optimalRatioRepay, 
        //     bool _boostEnabled, 
        //     bool _nextPriceEnabled, 
        //     address _subscriptions) 

        // since it's unclear if there's an official version of this on Kovan, this is hardcoded for mainnet
        address subscriptionsProxyV2 = 0xd6f2125bF7FE2bc793dE7685EA7DEd8bff3917DD;
        address subscriptions = 0xC45d4f6B6bf41b6EdAA58B01c4298B8d9078269a; 

        minRedemptionRatioPerc = _minRedemptionRatio * ONE_PERC;
        automationFeePerc = _automationFeePerc;
        riskLimit = _riskLimit;

        bytes memory subscribeProxyCall = abi.encodeWithSignature(
            "subscribe(uint256,uint128,uint128,uint128,uint128,bool,bool,address)",
            cdpId, 
            _repaymentRatio * 10**16, 
            _boostRatio * 10**16,
            _targetRatio * 10**16,
            _targetRatio * 10**16,
            true,
            true,
            subscriptions);
        IDSProxy(address(this)).execute(subscriptionsProxyV2, subscribeProxyCall);
        
        emit AutomationSettingsChanged(
            _repaymentRatio,
            _targetRatio,
            _boostRatio,
            minRedemptionRatioPerc,
            automationFeePerc,
            riskLimit);
    }
// Solidity 0.7.6
/**
 * @notice Stake tokens to earn rewards
 * @param tokenAddress Staking token address
 * @param amount Amount of tokens to be staked
 */
function stake(
        address referrerAddress,
        address tokenAddress,
        uint256 amount
    ) external whenNotPaused {
        // checks
        require(
            _msgSender() != referrerAddress,
            "STAKE: invalid referrer address"
        );
        require(
            tokenDetails[tokenAddress].isExist,
            "STAKE : Token is not Exist"
        );
        require(
            userTotalStaking[_msgSender()][tokenAddress].add(amount) >=
                tokenDetails[tokenAddress].userMinStake,
            "STAKE : Min Amount should be within permit"
        );
        require(
            userTotalStaking[_msgSender()][tokenAddress].add(amount) <=
                tokenDetails[tokenAddress].userMaxStake,
            "STAKE : Max Amount should be within permit"
        );
        require(
            totalStaking[tokenAddress].add(amount) <=
                tokenDetails[tokenAddress].totalMaxStake,
            "STAKE : Maxlimit exceeds"
        );

        require(
            poolStartTime.add(stakeDuration) > block.timestamp,
            "STAKE: Staking Time Completed"
        );

        // Storing stake details
        stakingDetails[_msgSender()].stakeId.push(
            stakingDetails[_msgSender()].stakeId.length
        );
        stakingDetails[_msgSender()].isActive.push(true);
        stakingDetails[_msgSender()].user = _msgSender();
        stakingDetails[_msgSender()].referrer.push(referrerAddress);
        stakingDetails[_msgSender()].tokenAddress.push(tokenAddress);
        stakingDetails[_msgSender()].startTime.push(block.timestamp);

        // Update total staking amount
        stakingDetails[_msgSender()].stakedAmount.push(amount);
        totalStaking[tokenAddress] = totalStaking[tokenAddress].add(amount);
        userTotalStaking[_msgSender()][tokenAddress] = userTotalStaking[
            _msgSender()
        ][tokenAddress].add(amount);

        // Transfer tokens from user to contract
        require(
            IERC20(tokenAddress).transferFrom(
                _msgSender(),
                address(this),
                amount
            ),
            "Transfer Failed"
        );

        // Emit state changes
        emit Stake(
            _msgSender(),
            (stakingDetails[_msgSender()].stakeId.length.sub(1)),
            referrerAddress,
            tokenAddress,
            amount,
            block.timestamp
        );
    }
// Solidity 0.7.6
/**
 * @notice Claim accumulated rewards
 * @param stakeId Stake ID of the user
 * @param stakedAmount Staked amount of the user
 */
function claimRewards(
        address userAddress,
        uint256 stakeId,
        uint256 stakedAmount,
        uint256 totalStake
    ) internal {
        // Local variables
        uint256 interval;
        uint256 endOfProfit;

        interval = poolStartTime.add(stakeDuration);

        // Interval calculation
        if (interval > block.timestamp) endOfProfit = block.timestamp;
        else endOfProfit = poolStartTime.add(stakeDuration);

        interval = endOfProfit.sub(
            stakingDetails[userAddress].startTime[stakeId]
        );
        uint256[2] memory stakeData;
        stakeData[0] = (stakedAmount);
        stakeData[1] = (totalStake);

        // Reward calculation
        if (interval >= HOURS)
            _rewardCalculation(userAddress, stakeId, stakeData, interval);
    }
// Solidity 0.7.6
/**
 * @notice Get rewards for one day
 * @param stakedAmount Stake amount of the user
 * @param stakedToken Staked token address of the user
 * @param rewardToken Reward token address
 * @return reward One dayh reward for the user
 */
function getOneDayReward(
        uint256 stakedAmount,
        address stakedToken,
        address rewardToken,
        uint256 totalStake
    ) public view returns (uint256 reward) {
        uint256 lockBenefit;

        if (tokenDetails[stakedToken].optionableStatus) {
            stakedAmount = stakedAmount.mul(optionableBenefit);
            lockBenefit = stakedAmount.mul(optionableBenefit.sub(1));
            reward = (
                stakedAmount.mul(
                    tokenDailyDistribution[stakedToken][rewardToken]
                )
            ).div(totalStake.add(lockBenefit));
        } else {
            reward = (
                stakedAmount.mul(
                    tokenDailyDistribution[stakedToken][rewardToken]
                )
            ).div(totalStake);
        }
    }
// Solidity 0.7.6
/**
 * @notice Get rewards for one day
 * @param stakedToken Stake amount of the user
 * @param tokenAddress Reward token address
 * @param amount Amount to be transferred as reward
 */
function sendToken(
        address userAddress,
        address stakedToken,
        address tokenAddress,
        uint256 amount
    ) internal {
        // Checks
        if (tokenAddress != address(0)) {
            require(
                rewardCap[tokenAddress] >= amount,
                "SEND : Insufficient Reward Balance"
            );
            // Transfer of rewards
            rewardCap[tokenAddress] = rewardCap[tokenAddress].sub(amount);

            require(
                IERC20(tokenAddress).transfer(userAddress, amount),
                "Transfer failed"
            );

            // Emit state changes
            emit Claim(
                userAddress,
                stakedToken,
                tokenAddress,
                amount,
                block.timestamp
            );
        }
    }
// Solidity 0.7.6
/**
 * @notice Unstake and claim rewards
 * @param stakeId Stake ID of the user
 */
function unStake(address userAddress, uint256 stakeId)
        external
        whenNotPaused
        returns (bool)
    {
        require(
            _msgSender() == userAddress || _msgSender() == _owner,
            "UNSTAKE: Invalid User Entry"
        );

        address stakedToken = stakingDetails[userAddress].tokenAddress[stakeId];

        // lockableDays check
        require(
            tokenDetails[stakedToken].lockableDays <= block.timestamp,
            "UNSTAKE: Token Locked"
        );

        // optional lock check
        if (tokenDetails[stakedToken].optionableStatus)
            require(
                stakingDetails[userAddress].startTime[stakeId].add(
                    stakeDuration
                ) <= block.timestamp,
                "UNSTAKE: Locked in optional lock"
            );

        // Checks
        require(
            stakingDetails[userAddress].stakedAmount[stakeId] > 0 ||
                stakingDetails[userAddress].isActive[stakeId] == true,
            "UNSTAKE : Already Claimed (or) Insufficient Staked"
        );

        // State updation
        uint256 stakedAmount = stakingDetails[userAddress].stakedAmount[
            stakeId
        ];
        uint256 totalStaking1 = totalStaking[stakedToken];

        stakingDetails[userAddress].stakedAmount[stakeId] = 0;
        stakingDetails[userAddress].isActive[stakeId] = false;

        // Balance check
        require(
            IERC20(stakingDetails[userAddress].tokenAddress[stakeId]).balanceOf(
                address(this)
            ) >= stakedAmount,
            "UNSTAKE : Insufficient Balance"
        );

        // Transfer staked token back to user
        IERC20(stakingDetails[userAddress].tokenAddress[stakeId]).transfer(
            userAddress,
            stakedAmount
        );

        claimRewards(userAddress, stakeId, stakedAmount, totalStaking1);

        // Emit state changes
        emit UnStake(
            userAddress,
            stakingDetails[userAddress].tokenAddress[stakeId],
            stakedAmount,
            block.timestamp,
            stakeId
        );

        return true;
    }
// Solidity 0.7.6
/**
 * @notice View staking details
 * @param _user User address
 */
function viewStakingDetails(address _user)
        public
        view
        returns (
            address[] memory,
            address[] memory,
            bool[] memory,
            uint256[] memory,
            uint256[] memory,
            uint256[] memory
        )
    {
        return (
            stakingDetails[_user].referrer,
            stakingDetails[_user].tokenAddress,
            stakingDetails[_user].isActive,
            stakingDetails[_user].stakeId,
            stakingDetails[_user].stakedAmount,
            stakingDetails[_user].startTime
        );
    }