lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.10
/**
 * @dev PUBLIC FACING: Open a stake.
 * @param newStakedGuns Number of Guns to stake
 * @param newStakedDays Number of days to stake
 */
function stakeStart(uint256 newStakedGuns, uint256 newStakedDays)
        external
    {
        GlobalsCache memory g;
        GlobalsCache memory gSnapshot;
        _globalsLoad(g, gSnapshot);

        /* Enforce the minimum stake time */
        require(newStakedDays >= MIN_STAKE_DAYS, "NUG: newStakedDays lower than minimum");

        /* Check if log data needs to be updated */
        _dailyDataUpdateAuto(g);

        _stakeStart(g, newStakedGuns, newStakedDays);

        /* Remove staked Guns from balance of staker */
        _burn(msg.sender, newStakedGuns);

        _globalsSync(g, gSnapshot);
    }
// Solidity 0.5.10
/**
 * @dev Calculates total stake payout including rewards for a multi-day range
 * @param g Cache of stored globals
 * @param stakeSharesParam Param from stake to calculate bonuses for
 * @param beginDay First day to calculate bonuses for
 * @param endDay Last day (non-inclusive) of range to calculate bonuses for
 * @return Payout in Guns
 */
function _calcPayoutRewards(
        GlobalsCache memory g,
        uint256 stakeSharesParam,
        uint256 beginDay,
        uint256 endDay
    )
        private
        view
        returns (uint256 payout)
    {
        uint256 counter;

        for (uint256 day = beginDay; day < endDay; day++) {
            uint256 dayPayout;

            dayPayout = dailyData[day].dayPayoutTotal * stakeSharesParam
                / dailyData[day].dayStakeSharesTotal;

            if (counter < 4) {
                counter++;
            } 
            /* Eligible to receive bonus */
            else {
                dayPayout = (dailyData[day].dayPayoutTotal * stakeSharesParam
                / dailyData[day].dayStakeSharesTotal) * BONUS_DAY_SCALE;
                counter = 0;
            }

            payout += dayPayout;
        }

        return payout;
    }
// Solidity 0.5.10
/**
 * @dev Calculates user dividends
 * @param g Cache of stored globals
 * @param stakeSharesParam Param from stake to calculate bonuses for
 * @param beginDay First day to calculate bonuses for
 * @param endDay Last day (non-inclusive) of range to calculate bonuses for
 * @return Payout in Guns
 */
function _calcPayoutDividendsReward(
        GlobalsCache memory g,
        uint256 stakeSharesParam,
        uint256 beginDay,
        uint256 endDay
    )
        private
        view
        returns (uint256 payout)
    {

        for (uint256 day = beginDay; day < endDay; day++) {
            uint256 dayPayout;

            /* user's share of 85% of the day's dividends, 15% total will drip to NUI platform */
            dayPayout += ((dailyData[day].dayDividends * 85) / 100) * stakeSharesParam
            / dailyData[day].dayStakeSharesTotal;

            payout += dayPayout;
        }

        return payout;
    }
// Solidity 0.5.10
/**
 * @dev PUBLIC FACING: Enter the auction lobby for the current round
 * @param referrerAddr TRX address of referring user (optional; 0x0 for no referrer)
 */
function xfLobbyEnter(address referrerAddr)
        external
        payable
    {
        uint256 enterDay = _currentDay();

        uint256 rawAmount = msg.value;
        require(rawAmount != 0, "NUG: Amount required");

        XfLobbyQueueStore storage qRef = xfLobbyMembers[enterDay][msg.sender];

        uint256 entryIndex = qRef.tailIndex++;

        qRef.entries[entryIndex] = XfLobbyEntryStore(uint96(rawAmount), referrerAddr);

        xfLobby[enterDay] += rawAmount;

        emit XfLobbyEnter(
            block.timestamp, 
            enterDay, 
            entryIndex, 
            rawAmount
        );
    }
// Solidity 0.5.10
/**
 * @dev PUBLIC FACING: Release 15% for NUI Drip from daily divs
 */
function xfFlush()
        external
    {
        GlobalsCache memory g;
        GlobalsCache memory gSnapshot;
        _globalsLoad(g, gSnapshot);
        
        require(address(this).balance != 0, "NUG: No value");

        require(LAST_FLUSHED_DAY < _currentDay(), "NUG: Invalid day");

        _dailyDataUpdateAuto(g);

        NUI_SHARE_ADDR.transfer((dailyData[LAST_FLUSHED_DAY].dayDividends * 15) / 100);

        LAST_FLUSHED_DAY++;

        _globalsSync(g, gSnapshot);
    }
// Solidity 0.5.10
/**
 * @dev PUBLIC FACING: Return the lobby days that a user is in with a single call
 * @param memberAddr TRX address of the user
 * @return Bit vector of lobby day numbers
 */
function xfLobbyPendingDays(address memberAddr)
        external
        view
        returns (uint256[XF_LOBBY_DAY_WORDS] memory words)
    {
        uint256 day = _currentDay() + 1;

        while (day-- != 0) {
            if (xfLobbyMembers[day][memberAddr].tailIndex > xfLobbyMembers[day][memberAddr].headIndex) {
                words[day >> 8] |= 1 << (day & 255);
            }
        }

        return words;
    }
// Solidity 0.6.12
/**
 * @dev Burns aTokens from `user` and sends the equivalent amount of underlying to `receiverOfUnderlying`
 * - Only callable by the LendingPool, as extra state updates there need to be managed
 * @param user The owner of the aTokens, getting them burned
 * @param receiverOfUnderlying The address that will receive the underlying
 * @param amount The amount being burned
 * @param index The new liquidity index of the reserve
 **/
function burn(
    address user,
    address receiverOfUnderlying,
    uint256 amount,
    uint256 index
  ) external override onlyLendingPool {
    uint256 amountScaled = amount.rayDiv(index);
    require(amountScaled != 0, Errors.CT_INVALID_BURN_AMOUNT);

    ExtData memory e = _fetchExtData();
    _burnScaled(user, amountScaled, e);
    _totalGonsDeposited = _totalGonsDeposited.sub(
      _amplToGons(e.totalAMPLSupply, amountScaled).toInt256Safe()
    );

    IERC20(UNDERLYING_ASSET_ADDRESS).safeTransfer(receiverOfUnderlying, amount);

    emit Transfer(user, address(0), amount);
    emit Burn(user, receiverOfUnderlying, amount, index);
  }
// Solidity 0.6.12
/**
 * @dev Mints `amount` aTokens to `user`
 * - Only callable by the LendingPool, as extra state updates there need to be managed
 * @param user The address receiving the minted tokens
 * @param amount The amount of tokens getting minted
 * @param index The new liquidity index of the reserve
 * @return `true` if the the previous balance of the user was 0
 */
function mint(
    address user,
    uint256 amount,
    uint256 index
  ) external override onlyLendingPool returns (bool) {
    uint256 previousBalanceInternal = super.balanceOf(user);

    uint256 amountScaled = amount.rayDiv(index);
    require(amountScaled != 0, Errors.CT_INVALID_MINT_AMOUNT);

    ExtData memory e = _fetchExtData();
    _mintScaled(user, amountScaled, e);
    _totalGonsDeposited = _totalGonsDeposited.add(
      _amplToGons(e.totalAMPLSupply, amountScaled).toInt256Safe()
    );

    emit Transfer(address(0), user, amount);
    emit Mint(user, amount, index);

    return previousBalanceInternal == 0;
  }
// Solidity 0.6.12
/**
 * @dev Mints aTokens to the reserve treasury
 * - Only callable by the LendingPool
 * @param amount The amount of tokens getting minted
 * @param index The new liquidity index of the reserve
 */
function mintToTreasury(uint256 amount, uint256 index) external override onlyLendingPool {
    if (amount == 0) {
      return;
    }

    // Compared to the normal mint, we don't check for rounding errors.
    // The amount to mint can easily be very small since it is a fraction of the interest accrued.
    // In that case, the treasury will experience a (very small) loss, but it
    // wont cause potentially valid transactions to fail.
    uint256 amountScaled = amount.rayDiv(index);
    // require(amountScaled != 0, Errors.CT_INVALID_MINT_AMOUNT);

    ExtData memory e = _fetchExtData();
    _mintScaled(RESERVE_TREASURY_ADDRESS, amountScaled, e);
    _totalGonsDeposited = _totalGonsDeposited.add(
      _amplToGons(e.totalAMPLSupply, amountScaled).toInt256Safe()
    );

    emit Transfer(address(0), RESERVE_TREASURY_ADDRESS, amount);
    emit Mint(RESERVE_TREASURY_ADDRESS, amount, index);
  }
// Solidity 0.6.12
/**
 * @dev Transfers aTokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken
 * - Only callable by the LendingPool
 * @param from The address getting liquidated, current owner of the aTokens
 * @param to The recipient
 * @param value The amount of tokens getting transferred
 **/
function transferOnLiquidation(
    address from,
    address to,
    uint256 value
  ) external override onlyLendingPool {
    // Being a normal transfer, the Transfer() and BalanceTransfer() are emitted
    // so no need to emit a specific event here
    _transfer(from, to, value, false);

    emit Transfer(from, to, value);
  }
// Solidity 0.6.12
/**
 * @dev implements the permit function as for
 * https://github.com/ethereum/EIPs/blob/8a34d644aacf0f9f8f00815307fd7dd5da07655f/EIPS/eip-2612.md
 * @param owner The owner of the funds
 * @param spender The spender
 * @param value The amount
 * @param deadline The deadline timestamp, type(uint256).max for max deadline
 * @param v Signature param
 * @param s Signature param
 * @param r Signature param
 */
function permit(
    address owner,
    address spender,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
  ) external {
    require(owner != address(0), 'INVALID_OWNER');
    //solium-disable-next-line
    require(block.timestamp <= deadline, 'INVALID_EXPIRATION');
    uint256 currentValidNonce = _nonces[owner];
    bytes32 digest =
      keccak256(
        abi.encodePacked(
          '\x19\x01',
          DOMAIN_SEPARATOR,
          keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, currentValidNonce, deadline))
        )
      );
    require(owner == ecrecover(digest, v, r, s), 'INVALID_SIGNATURE');
    _nonces[owner] = currentValidNonce.add(1);
    _approve(owner, spender, value);
  }
// Solidity 0.6.12
/**
 * @dev Transfers the aTokens between two users. Validates the transfer
 * (ie checks for valid HF after the transfer) if required
 * @param from The source address
 * @param to The destination address
 * @param amount The amount getting transferred
 * @param validate `true` if the transfer needs to be validated
 **/
function _transfer(
    address from,
    address to,
    uint256 amount,
    bool validate
  ) internal {
    uint256 index = POOL.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS);
    uint256 amountScaled = amount.rayDiv(index);

    ExtData memory e = _fetchExtData();
    uint256 totalSupplyInternal = super.totalSupply();

    uint256 scaledTotalSupply = _scaledTotalSupply(e, _totalGonsDeposited);
    uint256 fromBalanceScaled = _scaledBalanceOf(super.balanceOf(from), totalSupplyInternal, scaledTotalSupply);
    uint256 toBalanceScaled = _scaledBalanceOf(super.balanceOf(to), totalSupplyInternal, scaledTotalSupply);

    uint256 fromBalanceBefore = fromBalanceScaled.rayMul(index);
    uint256 toBalanceBefore = toBalanceScaled.rayMul(index);

    _transferScaled(from, to, amountScaled, e);

    if (validate) {
      POOL.finalizeTransfer(
        UNDERLYING_ASSET_ADDRESS,
        from,
        to,
        amount,
        fromBalanceBefore,
        toBalanceBefore
      );
    }

    emit BalanceTransfer(from, to, amount, index);
  }
// Solidity 0.6.12
/**
 * @dev calculates the total supply of the specific aToken
 * since the balance of every single user increases over time, the total supply
 * does that too.
 * @return the current total supply
 **/
function totalSupply() public view override(IncentivizedERC20, IERC20) returns (uint256) {
    uint256 currentSupplyScaled = _scaledTotalSupply(_fetchExtData(), _totalGonsDeposited);

    if (currentSupplyScaled == 0) {
      // currentSupplyInternal should also be zero in this case (super.totalSupply())
      return 0;
    }

    return currentSupplyScaled.rayMul(POOL.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS));
  }
// Solidity 0.6.12
/**
 * @dev transferAmountInternal = (transferAmountScaled * totalSupplyInternal) / scaledTotalSupply
 **/
function _transferScaled(address from, address to, uint256 transferAmountScaled, ExtData memory e) private returns (uint256) {
    uint256 totalSupplyInternal = super.totalSupply();
    uint256 scaledTotalSupply = _scaledTotalSupply(e, _totalGonsDeposited);
    uint256 transferAmountInternal = transferAmountScaled.mul(totalSupplyInternal).div(scaledTotalSupply);
    super._transfer(from, to, transferAmountInternal);
  }
// Solidity 0.6.12
/**
 * @dev mintAmountInternal is mint such that the following holds true
 *
 * (userBalanceInternalBefore+mintAmountInternal)/(totalSupplyInternalBefore+mintAmountInternal)
 *    = (userBalanceScaledBefore+mintAmountScaled)/(scaledTotalSupplyBefore+mintAmountScaled)
 *
 * scaledTotalSupplyAfter = scaledTotalSupplyBefore+mintAmountScaled
 * userBalanceScaledAfter = userBalanceScaledBefore+mintAmountScaled
 * otherBalanceScaledBefore = scaledTotalSupplyBefore-userBalanceScaledBefore
 *
 * mintAmountInternal = (totalSupplyInternalBefore*userBalanceScaledAfter - scaledTotalSupplyAfter*userBalanceInternalBefore)/otherBalanceScaledBefore
 **/
function _mintScaled(address user, uint256 mintAmountScaled, ExtData memory e) private {
    uint256 totalSupplyInternalBefore = super.totalSupply();
    uint256 userBalanceInternalBefore = super.balanceOf(user);

    // First mint
    if(totalSupplyInternalBefore == 0) {
      uint256 mintAmountInternal = _amplToGons(e.totalAMPLSupply, mintAmountScaled);
      _mint(user, mintAmountInternal);
      return;
    }

    uint256 scaledTotalSupplyBefore = _scaledTotalSupply(e, _totalGonsDeposited);

    uint256 userBalanceScaledBefore = _scaledBalanceOf(userBalanceInternalBefore, totalSupplyInternalBefore, scaledTotalSupplyBefore);
    uint256 otherBalanceScaledBefore = scaledTotalSupplyBefore.sub(userBalanceScaledBefore);

    uint256 scaledTotalSupplyAfter = scaledTotalSupplyBefore.add(mintAmountScaled);
    uint256 userBalanceScaledAfter = userBalanceScaledBefore.add(mintAmountScaled);
    uint256 mintAmountInternal = 0;

    // Lone user
    if(otherBalanceScaledBefore == 0) {
      uint256 mintAmountInternal = mintAmountScaled.mul(totalSupplyInternalBefore).div(scaledTotalSupplyBefore);
      _mint(user, mintAmountInternal);
      return;
    }

    mintAmountInternal = totalSupplyInternalBefore
      .mul(userBalanceScaledAfter)
      .sub(scaledTotalSupplyAfter.mul(userBalanceInternalBefore))
      .div(otherBalanceScaledBefore);

    _mint(user, mintAmountInternal);
  }
// Solidity 0.6.12
/**
 * @dev burnAmountInternal is burnt such that the following holds true
 *
 * (userBalanceInternalBefore-burnAmountInternal)/(totalSupplyInternalBefore-burnAmountInternal)
 *    = (userBalanceScaledBefore-burnAmountScaled)/(scaledTotalSupplyBefore-burnAmountScaled)
 *
 * scaledTotalSupplyAfter = scaledTotalSupplyBefore-burnAmountScaled
 * userBalanceScaledAfter = userBalanceScaledBefore-burnAmountScaled
 * otherBalanceScaledBefore = scaledTotalSupplyBefore-userBalanceScaledBefore
 *
 * burnAmountInternal = (scaledTotalSupplyAfter*userBalanceInternalBefore - totalSupplyInternalBefore*userBalanceScaledAfter)/otherBalanceScaledBefore
 **/
function _burnScaled(address user, uint256 burnAmountScaled, ExtData memory e) private {
    uint256 totalSupplyInternalBefore = super.totalSupply();
    uint256 userBalanceInternalBefore = super.balanceOf(user);

    uint256 scaledTotalSupplyBefore = _scaledTotalSupply(e, _totalGonsDeposited);
    uint256 userBalanceScaledBefore = _scaledBalanceOf(userBalanceInternalBefore, totalSupplyInternalBefore, scaledTotalSupplyBefore);
    uint256 otherBalanceScaledBefore = scaledTotalSupplyBefore.sub(userBalanceScaledBefore);

    uint256 scaledTotalSupplyAfter = scaledTotalSupplyBefore.sub(burnAmountScaled);
    uint256 userBalanceScaledAfter = userBalanceScaledBefore.sub(burnAmountScaled);
    uint256 burnAmountInternal = 0;

    // Lone user
    if(otherBalanceScaledBefore == 0) {
      uint256 burnAmountInternal = burnAmountScaled.mul(totalSupplyInternalBefore).div(scaledTotalSupplyBefore);
      _burn(user, burnAmountInternal);
      return;
    }

    burnAmountInternal = scaledTotalSupplyAfter
      .mul(userBalanceInternalBefore)
      .sub(totalSupplyInternalBefore.mul(userBalanceScaledAfter))
      .div(otherBalanceScaledBefore);
    _burn(user, burnAmountInternal);
  }
// Solidity 0.4.26
/// @dev Update crowdsale parameter
function updateParams(
uint256 _tokenExchangeRate,
uint256 _tokenCrowdsaleCap,
uint256 _fundingStartBlock,
uint256 _fundingEndBlock) external
{
assert(block.number < fundingStartBlock);
assert(!isFinalized);

// update system parameters
tokenExchangeRate = _tokenExchangeRate;
tokenCrowdsaleCap = _tokenCrowdsaleCap;
fundingStartBlock = _fundingStartBlock;
fundingEndBlock = _fundingEndBlock;
}
// Solidity 0.4.25
// ------------------------------------------------------------------------
// Transfer `tokens` from the `from` account to the `to` account
// 
// The calling account must already have sufficient tokens approve(...)-d
// for spending from the `from` account and
// - From account must have sufficient balance to transfer
// - Spender must have sufficient allowance to transfer
// ------------------------------------------------------------------------
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        require(from != address(0));
        require(to != address(0));
        require(tokens > 0);
        require(balances[from] >= tokens);
        require(allowed[from][msg.sender] >= tokens);
        
        balances[from] = balances[from].sub(tokens);
        allowed[from][msg.sender] = allowed[from][msg.sender].sub(tokens);
        balances[to] = balances[to].add(tokens);
        emit Transfer(from, to, tokens);
        return true;
    }
// Solidity 0.5.16
/**
 * Add a new contract. 
 * This function can only be called by the owner of the smart contract.
 *
 * @param _contractId 		Contract Id
 * @param _data		        Contract Data
 */
function addContract(uint _contractId, string memory _data) public checkSenderIsOwner
    returns(uint)
    {
        Contract storage newContract = contracts[_contractId];
        require(newContract.contractId == 0, "Contract already created.");

        newContract.contractId = _contractId;
        newContract.data = _data;

        // emitting the event that a new contract has been registered
        emit newContractRegistered(_contractId);

        return _contractId;
    }
// Solidity 0.5.12
/**
 * @dev Insert node `_node` with a value
 * @param self stored linked list from contract
 * @param _node new node to insert
 * @param _value value of the new `_node` to insert
 * @notice If the `_node` does not exists, it's added to the list
 *   if the `_node` already exists, it updates its value.
 */
function set(List storage self, uint256 _node, uint256 _value) internal {
        // Check if node previusly existed
        if (self.exists[_node]) {

            // Load the new and old position
            (uint256 leftOldPos, uint256 leftNewPos) = self.findOldAndNewLeftPosition(_node, _value);

            // If node position changed, we need to re-do the linking
            if (leftOldPos != leftNewPos && _node != leftNewPos) {
                // Remove prev link
                self.links[leftOldPos] = self.links[_node];

                // Create new link
                uint256 next = self.links[leftNewPos];
                self.links[leftNewPos] = _node;
                self.links[_node] = next;
            }
        } else {
            // Update size of the list
            self.size = self.size + 1;
            // Set node as existing
            self.exists[_node] = true;
            // Find position for the new node and update the links
            uint256 leftPosition = self.findLeftPosition(_value);
            uint256 next = self.links[leftPosition];
            self.links[leftPosition] = _node;
            self.links[_node] = next;
        }

        // Set the value for the node
        self.values[_node] = _value;
    }
// Solidity 0.5.12
/**
 * @dev Returns the previus node of a given `_node`
 *   alongside to the previus node of a hypothetical new `_value`
 * @param self stored linked list from contract
 * @param _node a node to search for its left node
 * @param _value a value to seach for its hypothetical left node
 * @return `leftNodePost` the node previus to the given `_node` and
 *   `leftValPost` the node previus to the hypothetical new `_value`
 * @notice This method performs two seemingly unrelated tasks at the same time
 *   because both of those tasks require a list iteration, thus saving gas.
 */
function findOldAndNewLeftPosition(
        List storage self,
        uint256 _node,
        uint256 _value
    ) internal view returns (
        uint256 leftNodePos,
        uint256 leftValPos
    ) {
        // Find old and new value positions
        bool foundNode;
        bool foundVal;

        // Iterate links
        uint256 c = HEAD;
        while (!foundNode || !foundVal) {
            uint256 next = self.links[c];

            // We should have found the old position
            // the new one must be at the end
            if (next == 0) {
                leftValPos = c;
                break;
            }

            // If the next node is the current node
            // we found the old position
            if (next == _node) {
                leftNodePos = c;
                foundNode = true;
            }

            // If the next value is higher and we didn't found one yet
            // the next value if the position
            if (self.values[next] > _value && !foundVal) {
                leftValPos = c;
                foundVal = true;
            }

            c = next;
        }
    }
// Solidity 0.5.12
/**
 * @dev Get the left node for a given hypothetical `_value`
 * @param self stored linked list from contract
 * @param _value value to seek
 * @return uint256 left node for the given value
 */
function findLeftPosition(List storage self, uint256 _value) internal view returns (uint256) {
        uint256 next = HEAD;
        uint256 c;

        do {
            c = next;
            next = self.links[c];
        } while(self.values[next] < _value && next != 0);

        return c;
    }
// Solidity 0.5.12
/**
 * @dev Get the node on a given `_position`
 * @param self stored linked list from contract
 * @param _position node position to retrieve
 * @return the node key
 */
function nodeAt(List storage self, uint256 _position) internal view returns (uint256) {
        uint256 next = self.links[HEAD];
        for (uint256 i = 0; i < _position; i++) {
            next = self.links[next];
        }

        return next;
    }
// Solidity 0.5.12
/**
 * @dev Removes an entry from the sorted list
 * @param self stored linked list from contract
 * @param _node node to remove from the list
 */
function remove(List storage self, uint256 _node) internal {
        require(self.exists[_node], "the node does not exists");

        uint256 c = self.links[HEAD];
        while (c != 0) {
            uint256 next = self.links[c];
            if (next == _node) {
                break;
            }

            c = next;
        }

        self.size -= 1;
        self.exists[_node] = false;
        self.links[c] = self.links[_node];
        delete self.links[_node];
        delete self.values[_node];
    }