lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/// Update odds of a bet
function updateOdds(uint makerBetId, uint odds) external {
        require(odds > (10 ** oddsDecimals) && odds < ((10 ** 8) * (10 ** oddsDecimals)));

        MakerBet storage makerBet = makerBets[makerBetId][msg.sender];
        require(makerBet.makerBetId != 0);

        require(now < makerBet.expiry);

        require(makerBet.status == BetStatus.Open || makerBet.status == BetStatus.Paused);

        require(msg.sender == makerBet.maker);

        require(odds != makerBet.odds);

        uint oldOdds = makerBet.odds;

        makerBet.odds = odds;

        emit LogUpdateOdds(makerBetId, msg.sender, oldOdds, makerBet.odds);
    }
// Solidity 0.4.24
/// Close a bet and withdraw unused fund
function closeBet(uint makerBetId) external {
        MakerBet storage makerBet = makerBets[makerBetId][msg.sender];
        require(makerBet.makerBetId != 0);

        require(makerBet.status == BetStatus.Open || makerBet.status == BetStatus.Paused);

        require(msg.sender == makerBet.maker);

        makerBet.status = BetStatus.Closed;

        // refund unused fund to maker
        uint unusedFund = sub(makerBet.totalFund, makerBet.reservedFund);

        if (unusedFund > 0) {
            makerBet.totalFund = makerBet.reservedFund;

            uint refundAmount = unusedFund;
            if (makerBet.totalStake == 0) {
                refundAmount = add(refundAmount, makerBet.trustedVerifier.baseFee); // Refund base verifier fee too if no taker-bets, because verifier do not need to settle the bet with no takers
                makerBet.makerFundWithdrawn = true;
            }

            if (!makerBet.maker.send(refundAmount)) {
                makerBet.totalFund = add(makerBet.totalFund, unusedFund);
                makerBet.status = BetStatus.Paused;
                makerBet.makerFundWithdrawn = false;
            } else {
                emit LogCloseBet(makerBetId, msg.sender);
            }
        } else {
            emit LogCloseBet(makerBetId, msg.sender);
        }
    }
// Solidity 0.4.24
/// Settle a bet by trusted verifier
function settleBet(uint makerBetId, address maker, uint outcome) external {
        require(outcome == 1 || outcome == 2 || outcome == 3 || outcome == 4);

        MakerBet storage makerBet = makerBets[makerBetId][maker];
        require(makerBet.makerBetId != 0);

        require(msg.sender == makerBet.trustedVerifier.addr);

        require(makerBet.totalStake > 0);

        require(makerBet.status != BetStatus.Settled);

        BetOutcome betOutcome = BetOutcome(outcome);
        makerBet.outcome = betOutcome;
        makerBet.status = BetStatus.Settled;

        payMaker(makerBet);
        payVerifier(makerBet);

        emit LogSettleBet(makerBetId, maker);
    }
// Solidity 0.4.24
/// Manual withdraw fund from a bet after outcome is set
function withdraw(uint makerBetId, address maker) external {
        MakerBet storage makerBet = makerBets[makerBetId][maker];
        require(makerBet.makerBetId != 0);

        require(makerBet.outcome != BetOutcome.NotSettled);

        require(makerBet.status == BetStatus.Settled);

        bool fullyWithdrawn = false;

        if (msg.sender == maker) {
            fullyWithdrawn = payMaker(makerBet);
        } else if (msg.sender == makerBet.trustedVerifier.addr) {
            fullyWithdrawn = payVerifier(makerBet);
        } else {
            fullyWithdrawn = payTaker(makerBet, msg.sender);
        }

        if (fullyWithdrawn) {
            emit LogWithdraw(makerBetId, maker, msg.sender);
        }
    }
// Solidity 0.4.24
/// Payout to maker
function payMaker(MakerBet storage makerBet) private returns (bool fullyWithdrawn) {
        fullyWithdrawn = false;

        if (!makerBet.makerFundWithdrawn) {
            makerBet.makerFundWithdrawn = true;

            uint payout = 0;
            if (makerBet.outcome == BetOutcome.MakerWin) {
                uint trustedVerifierFeeMakerWin = mul(makerBet.totalStake, makerBet.trustedVerifier.feeRate) / ((10 ** feeRateDecimals) * 100);
                payout = sub(add(makerBet.totalFund, makerBet.totalStake), trustedVerifierFeeMakerWin);
            } else if (makerBet.outcome == BetOutcome.TakerWin) {
                payout = sub(makerBet.totalFund, makerBet.reservedFund);
            } else if (makerBet.outcome == BetOutcome.Draw || makerBet.outcome == BetOutcome.Canceled) {
                payout = makerBet.totalFund;
            }

            if (payout > 0) {
                fullyWithdrawn = true;

                if (!makerBet.maker.send(payout)) {
                    makerBet.makerFundWithdrawn = false;
                    fullyWithdrawn = false;
                }
            }
        }

        return fullyWithdrawn;
    }
// Solidity 0.4.24
/// Payout to taker
function payTaker(MakerBet storage makerBet, address taker) private returns (bool fullyWithdrawn) {
        fullyWithdrawn = false;

        uint payout = 0;

        for (uint betIndex = 0; betIndex < makerBet.takerBetsCount; betIndex++) {
            if (makerBet.takerBets[betIndex].taker == taker) {
                if (!makerBet.takerBets[betIndex].settled) {
                    makerBet.takerBets[betIndex].settled = true;

                    if (makerBet.outcome == BetOutcome.MakerWin) {
                        continue;
                    } else if (makerBet.outcome == BetOutcome.TakerWin) {
                        uint netProfit = mul(mul(makerBet.takerBets[betIndex].stake, sub(makerBet.takerBets[betIndex].odds, (10 ** oddsDecimals))), sub(((10 ** feeRateDecimals) * 100), makerBet.trustedVerifier.feeRate)) / (10 ** oddsDecimals) / ((10 ** feeRateDecimals) * 100);
                        payout = add(payout, add(makerBet.takerBets[betIndex].stake, netProfit));
                    } else if (makerBet.outcome == BetOutcome.Draw || makerBet.outcome == BetOutcome.Canceled) {
                        payout = add(payout, makerBet.takerBets[betIndex].stake);
                    }
                }
            }
        }

        if (payout > 0) {
            fullyWithdrawn = true;

            if (!taker.send(payout)) {
                fullyWithdrawn = false;

                for (uint betIndex2 = 0; betIndex2 < makerBet.takerBetsCount; betIndex2++) {
                    if (makerBet.takerBets[betIndex2].taker == taker) {
                        if (makerBet.takerBets[betIndex2].settled) {
                            makerBet.takerBets[betIndex2].settled = false;
                        }
                    }
                }
            }
        }

        return fullyWithdrawn;
    }
// Solidity 0.4.24
/// Payout to verifier
function payVerifier(MakerBet storage makerBet) private returns (bool fullyWithdrawn) {
        fullyWithdrawn = false;

        if (!makerBet.trustedVerifierFeeSent) {
            makerBet.trustedVerifierFeeSent = true;

            uint payout = 0;
            if (makerBet.outcome == BetOutcome.MakerWin) {
                uint trustedVerifierFeeMakerWin = mul(makerBet.totalStake, makerBet.trustedVerifier.feeRate) / ((10 ** feeRateDecimals) * 100);
                payout = add(makerBet.trustedVerifier.baseFee, trustedVerifierFeeMakerWin);
            } else if (makerBet.outcome == BetOutcome.TakerWin) {
                uint trustedVerifierFeeTakerWin = mul(makerBet.reservedFund, makerBet.trustedVerifier.feeRate) / ((10 ** feeRateDecimals) * 100);
                payout = add(makerBet.trustedVerifier.baseFee, trustedVerifierFeeTakerWin);
            } else if (makerBet.outcome == BetOutcome.Draw || makerBet.outcome == BetOutcome.Canceled) {
                payout = makerBet.trustedVerifier.baseFee;
            }

            if (payout > 0) {
                fullyWithdrawn = true;

                if (!makerBet.trustedVerifier.addr.send(payout)) {
                    makerBet.trustedVerifierFeeSent = false;
                    fullyWithdrawn = false;
                }
            }
        }

        return fullyWithdrawn;
    }
// Solidity 0.4.24
/* Math utilities */
function mul(uint256 _a, uint256 _b) private pure returns(uint256 c) {
        if (_a == 0) {
            return 0;
        }

        c = _a * _b;
        assert(c / _a == _b);
        return c;
    }
// Solidity 0.6.12
/**
 * @dev Returns the average of two numbers. The result is rounded towards
 * zero.
 */
function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
// Solidity 0.7.0
/**
 * Mints Bananass
 */
function mintBanana(uint numberOfTokens) public payable {
        require(saleIsActive, "Sale must be active to mint Bananas");
        require(numberOfTokens <= maxBananaPurchase, "Can only mint 20 tokens at a time");
        require(totalSupply().add(numberOfTokens) <= MAX_BANANAS, "Purchase would exceed max supply of Bananas");
        require(BananaPrice.mul(numberOfTokens) <= msg.value, "Ether value sent is not correct");
        
        for(uint i = 0; i < numberOfTokens; i++) {
            uint mintIndex = totalSupply();
            if (totalSupply() < MAX_BANANAS) {
                _safeMint(msg.sender, mintIndex);
            }
        }

        // If we haven't set the starting index and this is either 1) the last saleable token or 2) the first token to be sold after
        // the end of pre-sale, set the starting index block
        if (startingIndexBlock == 0 && (totalSupply() == MAX_BANANAS || block.timestamp >= REVEAL_TIMESTAMP)) {
            startingIndexBlock = block.number;
        } 
    }
// Solidity 0.8.6
/// @notice Deposit LP tokens to Staking contract for Reward token allocation.
/// @param pid The index of the pool. See `poolInfo`.
/// @param amount LP token amount to deposit.
/// @param to The receiver of `amount` deposit benefit.
function deposit(
        uint256 pid,
        uint256 amount,
        address to
    ) public {
        PoolInfo memory pool = updatePool(pid);
        UserInfo storage user = userInfo[pid][to];

        // Effects
        user.amount = user.amount.add(amount);
        user.rewardDebt = user.rewardDebt.add(int256(amount.mul(pool.accRewardPerShare) / ACC_PRECISION));

        // Interactions
        IRewarder _rewarder = rewarder[pid];
        if (address(_rewarder) != address(0)) {
            _rewarder.onTokenReward(pid, to, to, 0, user.amount);
        }

        lpToken[pid].safeTransferFrom(msg.sender, address(this), amount);

        emit Deposit(msg.sender, pid, amount, to);
    }
// Solidity 0.8.6
/// @notice Harvest proceeds for transaction sender to `to`.
/// @param pid The index of the pool. See `poolInfo`.
/// @param to Receiver of Token rewards.
function harvest(uint256 pid, address to) public {
        PoolInfo memory pool = updatePool(pid);
        UserInfo storage user = userInfo[pid][msg.sender];
        int256 accumulatedRewards = int256(user.amount.mul(pool.accRewardPerShare) / ACC_PRECISION);
        uint256 _pendingRewards = accumulatedRewards.sub(user.rewardDebt).toUInt256();

        // Effects
        user.rewardDebt = accumulatedRewards;

        // Interactions
        if (_pendingRewards != 0) {
            rewardToken.safeTransferFrom(rewardOwner, to, _pendingRewards);
        }

        IRewarder _rewarder = rewarder[pid];
        if (address(_rewarder) != address(0)) {
            _rewarder.onTokenReward(pid, msg.sender, to, _pendingRewards, user.amount);
        }

        emit Harvest(msg.sender, pid, _pendingRewards);
    }
// Solidity 0.8.3
/**
 * @dev Swaps ETH for wrapped stETH and deposits the resulting wstETH to the ZkSync bridge.
 * First withdraws ETH from the bridge if there is a pending balance.
 * @param _amountIn The amount of ETH to swap.
 */
function swapEthForStEth(uint256 _amountIn) internal returns (uint256) {
        // swap Eth for stEth on the Lido contract
        ILido(stEth).submit{value: _amountIn}(lidoReferral);
        // approve the wStEth contract to take the stEth
        IERC20(stEth).approve(wStEth, _amountIn);
        // wrap to wStEth and return deposited amount
        return IWstETH(wStEth).wrap(_amountIn);
    }
// Solidity 0.7.6
/**
 * Returns the amount of days passed with vesting
 */
function getDays(uint256 afterDays) public view returns (uint256) {
        uint256 releaseTime = getListingTime();
        uint256 time = releaseTime.add(afterDays);

        if (block.timestamp < time) {
            return 0;
        }

        uint256 diff = block.timestamp.sub(time);
        uint256 ds = diff.div(1 days).add(1);
        
        return ds;
    }
// Solidity 0.7.6
// Returns the amount of tokens unlocked by vesting so far
function getUnlockedVestingAmount(address sender) public view returns (uint256) {
        
        if (!isStarted(0)) {
            return 0;
        }
        
        uint256 dailyTransferableAmount = 0;

        for (uint256 i=0; i<vestingWallets[sender].length; i++) {

            if (vestingWallets[sender][i].totalAmount == 0) {
                continue;
            }

            uint256 trueDays = getDays(vestingWallets[sender][i].afterDays);
            uint256 dailyTransferableAmountCurrent = 0;
            
            // Unlock the first month right away on the first day of vesting;
            // But only start the real vesting after the first month (0, 30, 30, .., 31)
            if (trueDays > 0 && trueDays < 30) {
                trueDays = 30; 
                dailyTransferableAmountCurrent = vestingWallets[sender][i].firstMonthAmount;
            } 

            if (trueDays >= 30) {
                dailyTransferableAmountCurrent = vestingWallets[sender][i].firstMonthAmount.add(vestingWallets[sender][i].dayAmount.mul(trueDays.sub(30)));
            }

            if (dailyTransferableAmountCurrent > vestingWallets[sender][i].totalAmount) {
                dailyTransferableAmountCurrent = vestingWallets[sender][i].totalAmount;
            }

            dailyTransferableAmount = dailyTransferableAmount.add(dailyTransferableAmountCurrent);
        }

        return dailyTransferableAmount;
    }
// Solidity 0.8.9
/// @notice Removes and returns the n-th logical element
/// @param  self   the data structure
/// @param  index  which element (zero indexed) to remove and return
/// @return popped the specified element
function popByIndex(Self storage self, uint256 index) internal returns (uint256 popped) {
        popped = getByIndex(self, index);
        uint256 lastIndex = self.length - 1; // will not underflow b/c prior get
        if (index < lastIndex) {
            uint256 lastElement = getByIndex(self, lastIndex);
            self.elements[index] = lastElement;
        }
        delete self.elements[lastIndex];
        self.length -= 1;
    }
// Solidity 0.8.9
/// @notice Returns the n-th logical element
/// @param  self    the data structure
/// @param  index   which element (zero indexed) to get
/// @return element the specified element
function getByIndex(Self storage self, uint256 index) internal view returns (uint256 element) {
        require(index < self.length, "Out of bounds");
        return self.elements[index] == 0
            ? index + 1 // revert on overflow
            : self.elements[index];
    }
// Solidity 0.8.9
/// @notice Adds a new entry to the end of the queue
/// @param  self        the data structure
/// @param  beneficiary an address associated with the commitment
/// @param  quantity    how many to enqueue
function enqueue(Self storage self, address beneficiary, uint32 quantity) internal {
        require(quantity > 0, "Quantity is missing");
        self.elements[self.endIndex] = Element(
            beneficiary,
            uint64(block.number), // maturityBlock, hash thereof not yet known
            quantity
        );
        self.endIndex += 1;
        self.length += quantity;
    }
// Solidity 0.8.9
/// @notice Removes and returns the first element of the multi-queue; reverts if queue is empty
/// @param  self          the data structure
/// @return beneficiary   an address associated with the commitment
/// @return maturityBlock when this commitment matured
function dequeue(Self storage self) internal returns (address beneficiary, uint64 maturityBlock) {
        require(!_isEmpty(self), "Queue is empty");
        beneficiary = self.elements[self.startIndex].beneficiary;
        maturityBlock = self.elements[self.startIndex].maturityBlock;
        if (self.elements[self.startIndex].quantity == 1) {
            delete self.elements[self.startIndex];
            self.startIndex += 1;
        } else {
            self.elements[self.startIndex].quantity -= 1;
        }
        self.length -= 1;
    }
// Solidity 0.6.12
/**
 * @notice Admin function to add iToken into supported markets
 * Checks if the iToken already exsits
 * Will `revert()` if any check fails
 * @param _iToken The _iToken to add
 * @param _collateralFactor The _collateralFactor of _iToken
 * @param _borrowFactor The _borrowFactor of _iToken
 * @param _supplyCapacity The _supplyCapacity of _iToken
 * @param _distributionFactor The _distributionFactor of _iToken
 */
function _addMarket(
        address _iToken,
        uint256 _collateralFactor,
        uint256 _borrowFactor,
        uint256 _supplyCapacity,
        uint256 _borrowCapacity,
        uint256 _distributionFactor
    ) external override onlyOwner {
        require(IiToken(_iToken).isSupported(), "Token is not supported");

        // Market must not have been listed, EnumerableSet.add() will return false if it exsits
        require(iTokens.add(_iToken), "Token has already been listed");

        require(
            _collateralFactor <= collateralFactorMaxMantissa,
            "Collateral factor invalid"
        );

        require(
            _borrowFactor > 0 && _borrowFactor <= borrowFactorMaxMantissa,
            "Borrow factor invalid"
        );

        // Its value will be taken into account when calculate account equity
        // Check if the price is available for the calculation
        require(
            IPriceOracle(priceOracle).getUnderlyingPrice(_iToken) != 0,
            "Underlying price is unavailable"
        );

        markets[_iToken] = Market({
            collateralFactorMantissa: _collateralFactor,
            borrowFactorMantissa: _borrowFactor,
            borrowCapacity: _borrowCapacity,
            supplyCapacity: _supplyCapacity,
            mintPaused: false,
            redeemPaused: false,
            borrowPaused: false
        });

        IRewardDistributor(rewardDistributor)._addRecipient(
            _iToken,
            _distributionFactor
        );

        emit MarketAdded(
            _iToken,
            _collateralFactor,
            _borrowFactor,
            _supplyCapacity,
            _borrowCapacity,
            _distributionFactor
        );
    }
// Solidity 0.6.12
/**
 * @notice Sets liquidationIncentive
 * @dev Admin function to set liquidationIncentive
 * @param _newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18
 */
function _setLiquidationIncentive(uint256 _newLiquidationIncentiveMantissa)
        external
        override
        onlyOwner
    {
        require(
            _newLiquidationIncentiveMantissa >=
                liquidationIncentiveMinMantissa &&
                _newLiquidationIncentiveMantissa <=
                liquidationIncentiveMaxMantissa,
            "Liquidation incentive invalid"
        );

        uint256 _oldLiquidationIncentiveMantissa = liquidationIncentiveMantissa;
        liquidationIncentiveMantissa = _newLiquidationIncentiveMantissa;

        emit NewLiquidationIncentive(
            _oldLiquidationIncentiveMantissa,
            _newLiquidationIncentiveMantissa
        );
    }
// Solidity 0.6.12
/**
 * @notice Sets the collateralFactor for a iToken
 * @dev Admin function to set collateralFactor for a iToken
 * @param _iToken The token to set the factor on
 * @param _newCollateralFactorMantissa The new collateral factor, scaled by 1e18
 */
function _setCollateralFactor(
        address _iToken,
        uint256 _newCollateralFactorMantissa
    ) external override onlyOwner {
        _checkiTokenListed(_iToken);

        require(
            _newCollateralFactorMantissa <= collateralFactorMaxMantissa,
            "Collateral factor invalid"
        );

        // Its value will be taken into account when calculate account equity
        // Check if the price is available for the calculation
        require(
            IPriceOracle(priceOracle).getUnderlyingPrice(_iToken) != 0,
            "Failed to set collateral factor, underlying price is unavailable"
        );

        Market storage _market = markets[_iToken];
        uint256 _oldCollateralFactorMantissa = _market.collateralFactorMantissa;
        _market.collateralFactorMantissa = _newCollateralFactorMantissa;

        emit NewCollateralFactor(
            _iToken,
            _oldCollateralFactorMantissa,
            _newCollateralFactorMantissa
        );
    }
// Solidity 0.6.12
/**
 * @notice Sets the borrowFactor for a iToken
 * @dev Admin function to set borrowFactor for a iToken
 * @param _iToken The token to set the factor on
 * @param _newBorrowFactorMantissa The new borrow factor, scaled by 1e18
 */
function _setBorrowFactor(address _iToken, uint256 _newBorrowFactorMantissa)
        external
        override
        onlyOwner
    {
        _checkiTokenListed(_iToken);

        require(
            _newBorrowFactorMantissa > 0 &&
                _newBorrowFactorMantissa <= borrowFactorMaxMantissa,
            "Borrow factor invalid"
        );

        // Its value will be taken into account when calculate account equity
        // Check if the price is available for the calculation
        require(
            IPriceOracle(priceOracle).getUnderlyingPrice(_iToken) != 0,
            "Failed to set borrow factor, underlying price is unavailable"
        );

        Market storage _market = markets[_iToken];
        uint256 _oldBorrowFactorMantissa = _market.borrowFactorMantissa;
        _market.borrowFactorMantissa = _newBorrowFactorMantissa;

        emit NewBorrowFactor(
            _iToken,
            _oldBorrowFactorMantissa,
            _newBorrowFactorMantissa
        );
    }
// Solidity 0.6.12
/**
 * @notice Sets the pauseGuardian
 * @dev Admin function to set pauseGuardian
 * @param _newPauseGuardian The new pause guardian
 */
function _setPauseGuardian(address _newPauseGuardian)
        external
        override
        onlyOwner
    {
        address _oldPauseGuardian = pauseGuardian;

        require(
            _newPauseGuardian != address(0) &&
                _newPauseGuardian != _oldPauseGuardian,
            "Pause guardian address invalid"
        );

        pauseGuardian = _newPauseGuardian;

        emit NewPauseGuardian(_oldPauseGuardian, _newPauseGuardian);
    }
// Solidity 0.6.12
/**
 * @notice pause/unpause entire protocol, including mint/redeem/borrow/seize/transfer
 * @dev Admin function, only owner and pauseGuardian can call this
 * @param _paused whether to pause or unpause
 */
function _setProtocolPaused(bool _paused)
        external
        override
        checkPauser(_paused)
    {
        EnumerableSetUpgradeable.AddressSet storage _iTokens = iTokens;
        uint256 _len = _iTokens.length();

        for (uint256 i = 0; i < _len; i++) {
            address _iToken = _iTokens.at(i);

            _setiTokenPausedInternal(_iToken, _paused);
        }

        _setTransferPausedInternal(_paused);
        _setSeizePausedInternal(_paused);
    }