lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
// Notify a reward amount without updating time,
function notifyRewardAmountWithoutUpdateTime(uint256 reward) external onlyOwner {
    rewardToken.safeTransferFrom(msg.sender, address(this), reward);
    updateRewardPerTokenStored();
    if (block.timestamp >= periodFinish) {
      rewardRate = reward.div(DURATION);
    } else {
      uint256 remaining = periodFinish.sub(block.timestamp);
      uint256 leftover = remaining.mul(rewardRate);
      rewardRate = reward.add(leftover).div(DURATION);
    }
    emit RewardAdded(reward);
  }
// Solidity 0.8.12
// MINTING FUNCTIONS
function mint(uint256 amount) external payable {
        require(saleActive, "Public sale not active");
        require(msg.value == amount * mintPrice, "Not enough ETH sent");
        require(amount <= MAX_AMOUNT_PER_MINT, "Minting too many at a time");
        require(amount + totalSupply() <= MAX_TOTAL_SUPPLY, "Would exceed max supply");

        _mint(msg.sender, amount, "", false);
    }
// Solidity 0.8.12
// reserves 'amount' NFTs minted direct to a specified wallet
function reserve(address to, uint256 amount) external onlyOwner {
        require(amount + totalSupply() <= MAX_TOTAL_SUPPLY, "Would exceed max supply");
        require(reserved + amount <= MAX_RESERVED_AMOUNT, "Would exceed max reserved amount");

        _mint(to, amount, "", false);
        reserved += amount;
    }
// Solidity 0.8.12
// UPDATE FUNCTIONS
function plunge(uint256 tokenId) public onlyTokenOwner(tokenId) {
        require(!isLocked[tokenId], "Gator is dead");

        uint256 currentLevel = tokenLevels[tokenId];
        require(currentLevel < MAX_LEVEL, "Gator already max level");

        uint256 pseudoRandomNumber = _genPseudoRandomNumber(tokenId);

        if (currentLevel == 0) {
            // first upgrade, 90% chance of success
            if (pseudoRandomNumber < 9) {
                tokenLevels[tokenId] += 1;
            } else {
                tokenLevels[tokenId] = 0;
                isLocked[tokenId] = true;
            }
        } else {
            // second upgrade, 30% chance of success
            if (pseudoRandomNumber < 3) {
                tokenLevels[tokenId] += 1;
            } else {
                tokenLevels[tokenId] = 0;
                isLocked[tokenId] = true;
            }
        }
    }
// Solidity 0.8.12
// VIEW FUNCTIONS
function walletOfOwner(address wallet) public view returns (uint256[] memory) {
        uint256 tokenCount = balanceOf(wallet);
        uint256[] memory tokenIds = new uint256[](tokenCount);
        for (uint256 i; i < tokenCount; i++) {
            tokenIds[i] = tokenOfOwnerByIndex(wallet, i);
        }
        return tokenIds;
    }
// Solidity 0.7.6
// ------------------------------------------------------------------------
// Stakers can claim their pending rewards using this function
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Stakers can unstake the staked tokens using this function
// @param tokens the number of tokens to withdraw
// ------------------------------------------------------------------------
function WITHDRAW(uint256 tokens) external nonReentrant {

       require(stakers[msg.sender].stakedTokens >= tokens && tokens > 0, "Invalid token amount to withdraw");

       uint256 _unstakingFee = (onePercent(tokens).mul(unstakingFee)).div(10);

       // add pending rewards to remainder to be claimed by user later, if there is any existing stake


       reward.totalreward = (reward.totalreward).add(_unstakingFee);
       require(REWARDTOKEN(rewtkn).transfer(msg.sender, tokens.sub(_unstakingFee)), "Error in un-staking tokens");

       stakers[msg.sender].stakedTokens = stakers[msg.sender].stakedTokens.sub(tokens);

       if (stakers[msg.sender].stakedTokens == 0)
       {
           stakers[msg.sender].creationTime = block.timestamp ;
       }
       totalStakes = totalStakes.sub(tokens);
       emit UNSTAKED(msg.sender, tokens.sub(_unstakingFee), _unstakingFee);


   }
// Solidity 0.6.12
// **** State Mutations ****
function harvest() public restricted override {
        // stablecoin we want to convert to
        (address to, uint256 toIndex) = getMostPremium();

        // Collects crv tokens
        // this also sends KEEP to keep_rewards contract
        ICurveMintr(mintr).mint(gauge);
        uint256 _crv = IERC20(crv).balanceOf(address(this));
        if (_crv > 0) {
            // x% is sent back to the rewards holder
            // to be used to lock up in as veCRV in a future date
            uint256 _keepCRV = _crv.mul(keepCRV).div(keepCRVMax);
            if (_keepCRV > 0) {
                IERC20(crv).safeTransfer(
                    treasury,
                    _keepCRV
                );
            }
            _crv = _crv.sub(_keepCRV);
            _swapUniswap(crv, to, _crv);
        }

        // Adds liquidity to curve.fi's pool
        // to get back underlying (usdncrv)
        uint256 _to = IERC20(to).balanceOf(address(this));
        if (_to > 0) {
            IERC20(to).safeApprove(curve, 0);
            IERC20(to).safeApprove(curve, _to);
            uint256[4] memory liquidity;
            liquidity[toIndex] = _to;
            ICurveUSDN(curve).add_liquidity(liquidity, 0);
        }

        // Distribute the collected funds and deposit underlying
        // Emit harvested event
        _distributeAndDeposit();
        emit Harvested(to, _to);
    }
// Solidity 0.6.12
/**
 * @notice Get the underlying price of a kToken
 * @param kToken The kToken address for price retrieval
 * @return Price denominated in USD
 */
function getUnderlyingPrice(address kToken) public view returns (uint){
        KTokenConfig memory config = getKConfigByKToken(kToken);
        uint price;
        if (config.priceSource == PriceSource.CHAINLINK) {
            price = _calcPrice(_getChainlinkPrice(config), config);
        }else if (config.priceSource == PriceSource.KAPTAIN) {
            price = _calcPrice(_getKaptainPrice(config), config);
        }else if (config.priceSource == PriceSource.LP){
            price = _calcLpPrice(config);
        }else{
            revert("invalid price source");
        }

        require(price != 0, "invalid price 0");

        return price;
    }
// Solidity 0.6.12
/*********************************************************************************************
 *  Pl = lpPrice
 *  p0 = token0_PriceFromPriceSource
 *  p1 = token1_PriceFromPriceSource
 *  r0 = reserve0                                 2 * sqrt(p0 * r0) * sqrt(p1 * r1) * 1e36
 *  r1 = reserve1                          Pl = --------------------------------------------
 *  PM0 = Token0_PriceMantissa                         totalSupply * sqrt(PM0 * PM1)
 *  PM1 = Token1_PriceMantissa
 *  totalSupply = LP totalSupply
 *  PriceMantissa = priceUnit * baseUnit
 *********************************************************************************************/
function _calcLpPrice(KTokenConfig memory config) internal view returns (uint){
        uint numerator;
        uint denominator;
        KTokenConfig memory config0;
        KTokenConfig memory config1;

        {
            address token0 = IUniswapV2Pair(config.underlying).token0();
            address token1 = IUniswapV2Pair(config.underlying).token1();
            config0 = getKConfigByUnderlying(token0);
            config1 = getKConfigByUnderlying(token1);
        }

        {
            (uint r0, uint r1, ) = IUniswapV2Pair(config.underlying).getReserves();
            numerator = (_getSourcePrice(config0).mul(r0).sqrt())
                            .mul(_getSourcePrice(config1).mul(r1).sqrt())
                            .mul(2).mul(priceScale);
        }

        {
            uint totalSupply = IUniswapV2Pair(config.underlying).totalSupply();
            uint pmMultiplier = config0.priceMantissa.mul(config1.priceMantissa);
            denominator = totalSupply.mul(pmMultiplier.sqrt());
        }

        return numerator.div(denominator);
    }
// Solidity 0.6.12
/// @notice Only Kaptain allowed to operate prices
function postPrices(string[] calldata symbolArray, uint[] calldata priceArray) external onlyKaptain {
        require(symbolArray.length == priceArray.length, "length mismatch");
        // iterate and set
        for (uint i = 0; i < symbolArray.length; i++) {
            KTokenConfig memory config = getKConfigBySymbolHash(keccak256(abi.encodePacked(symbolArray[i])));
            require(config.priceSource == PriceSource.KAPTAIN, "can only post kaptain price");
            require(config.symbolHash != mcdHash, "cannot post mcd price here");
            require(priceArray[i] != 0, "price cannot be 0");
            prices[config.symbolHash] = priceArray[i];
        }
    }
// Solidity 0.4.16
/// Initiate a transfer to `_to` with value `_value`?
function transfer(address _to, uint256 _value) 
        public returns (bool success) 
    {
        // sanity check
        require(_to != address(this));

        // // check for overflows
        // require(_value > 0 &&
        //   balances[msg.sender] < _value &&
        //   balances[_to] + _value < balances[_to]);

        // 
        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);
        
        // emit transfer event
        Transfer(msg.sender, _to, _value);
        return true;
    }
// Solidity 0.4.16
/// Initiate a transfer of `_value` from `_from` to `_to`
function transferFrom(address _from, address _to, uint256 _value)         
        public returns (bool success) 
    {    
        // sanity check
        require(_to != 0x0 && _from != 0x0);
        require(_from != _to && _to != address(this));

        // check for overflows
        // require(_value > 0 &&
        //   balances[_from] >= _value &&
        //   allowed[_from][_to] <= _value &&
        //   balances[_to] + _value < balances[_to]);

        // update public balance
        allowed[_from][_to] = allowed[_from][_to].sub(_value);        
        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);

        // emit transfer event
        Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.4.16
/// Approve `_spender` to claim/spend `_value`?
function approve(address _spender, uint256 _value)          
        public returns (bool success) 
    {
        // sanity check
        require(_spender != 0x0 && _spender != address(this));            

        // if the allowance isn't 0, it can only be updated to 0 to prevent 
        // an allowance change immediately after withdrawal
        require(allowed[msg.sender][_spender] == 0);

        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;
    }
// Solidity 0.4.16
/// check allowance approved from `_owner` to `_spender`?
function allowance(address _owner, address _spender)          
        public constant returns (uint remaining) 
    {
        // sanity check
        require(_spender != 0x0 && _owner != 0x0);
        require(_owner != _spender && _spender != address(this));            

        // constant op. Just return the balance.
        return allowed[_owner][_spender];
    }
// Solidity 0.6.12
// @dev must be called after you add chainlink sourced config
function setAggregators(string[] calldata symbols, address[] calldata sources) public onlyOwner {
        require(symbols.length == sources.length, "mismatched input");
        for (uint i = 0; i < symbols.length; i++) {
            KTokenConfig memory config = getKConfigBySymbolHash(keccak256(abi.encodePacked(symbols[i])));
            AggregatorV3Interface agg = AggregatorV3Interface(sources[i]);
            aggregators[config.symbolHash] = agg;
            uint priceDecimals = uint(agg.decimals());
            require(10**priceDecimals == config.priceUnit, "mismatched priceUnit");
            emit AggregatorUpdated(symbols[i], sources[i]);
        }
    }
// Solidity 0.6.12
// @notice set the symbol used to query ExOracle
function setExOracleConfig(address kToken_, string memory symbol_, address source_) public onlyOwner {
        KTokenConfig memory config = getKConfigByKToken(kToken_);
        require(config.priceSource == PriceSource.EXORACLE, "mismatched priceSource");

        ExOracleConfig memory exOracleConfig = ExOracleConfig({
            kToken: kToken_,
            symbol: symbol_,
            source: source_
        });
        exOracleConfigs[kToken_] = exOracleConfig;

        (uint price, ) = exOracleView.get(symbol_, source_);
        require(price != 0, "unable to get price");

        emit ExOracleConfigUpdated(kToken_, symbol_, source_);
    }
// Solidity 0.6.12
// F1: External is ok here because this is the batch function, adding it to a batch makes no sense
// F2: Calls in the batch may be payable, delegatecall operates in the same context, so each call in the batch has access to msg.value
// C3: The length of the loop is fully under user control, so can't be exploited
// C7: Delegatecall is only used on the same contract, so it's safe
function batch(bytes[] calldata calls, bool revertOnFail) external payable returns (bool[] memory successes, bytes[] memory results) {
        successes = new bool[](calls.length);
        results = new bytes[](calls.length);
        for (uint256 i = 0; i < calls.length; i++) {
            (bool success, bytes memory result) = address(this).delegatecall(calls[i]);
            require(success || !revertOnFail, _getRevertMsg(result));
            successes[i] = success;
            results[i] = result;
        }
    }
// Solidity 0.6.12
/// @notice Liquidity zap from BENTO.
function zapFromBento(
        address pair,
        address to,
        uint256 amount
    ) external returns (uint256 amount0, uint256 amount1) {
        bento.withdraw(IERC20(pair), msg.sender, pair, amount, 0); // withdraw `amount` to `pair` from BENTO
        (amount0, amount1) = ISushiLiquidityZap(pair).burn(to); // trigger burn to redeem liquidity for `to`
    }
// Solidity 0.8.7
/**
 * mint Early Access Corgis
 */
function earlyAccessMint(uint256 boneTokenId, uint256 numberOfTokens) public payable {
        uint256 supply = totalSupply();
        uint256 boneCount = approvingBoneContract.balanceOf(msg.sender);
        uint256 corgiPerBoneCount = numberOfCorgisMintedPerBone[boneTokenId];
        bool bonesOfOwner = findBonesOfOwner(msg.sender, boneTokenId, boneCount);

        require(addressBlockBought[msg.sender] < block.timestamp, "Not allowed to Mint on the same Block");
        require(!Address.isContract(msg.sender),"Contracts are not allowed to mint");
        require(bonesOfOwner,"You do not own this bone");
        require(corgiPerBoneCount + numberOfTokens < 6,"You cannot mint more than 5 Corgis per Bone");
        require(earlyAccessIsActive, "Early Access Mint is not active yet");
        require(boneCount > 0, "You don't have a mint pass");
        require(msg.value >= price * numberOfTokens, "Payment is Insufficient");
        require(supply + numberOfTokens <= maxEarlyAccess, "Exceeds maximum Corgis early access supply" );

        addressBlockBought[msg.sender] = block.timestamp;
        for(uint256 i; i < numberOfTokens; i++){
            _safeMint( msg.sender, supply + i );
        }

        numberOfCorgisMintedPerBone[boneTokenId] = numberOfCorgisMintedPerBone[boneTokenId].add(numberOfTokens);
    }
// Solidity 0.8.7
/**
 * mint Corgis
 */
function mintCorgis(uint256 numberOfTokens) public payable {
        uint256 supply = totalSupply();

        require(addressBlockBought[msg.sender] < block.timestamp, "Not allowed to Mint on the same Block");
        require(!Address.isContract(msg.sender),"Contracts are not allowed to mint");
        require(corgiSaleIsActive, "Sale is not active yet");
        require(msg.value >= price * numberOfTokens, "Payment is Insufficient");
        require(numberOfTokens <= maxPublicPurchase, "You can adopt a maximum of 10 Corgis");
        require(supply + numberOfTokens <= maxCorgis, "Exceeds maximum Corgis supply" );

        addressBlockBought[msg.sender] = block.timestamp;

        for(uint256 i; i < numberOfTokens; i++){
            _safeMint( msg.sender, supply + i );

            if (totalSupply() == 6500) {
                // send to charity fund
                sendToCommunityAndCharityWallets(charityFundWallet, donationToCharity);
            } else if (totalSupply() == 9000) {
                // send to community vault
                sendToCommunityAndCharityWallets(communityVault, sendToCommunityVault);
            }
        }
    }
// Solidity 0.8.7
/**
 * reserve Corgis for giveaways
 */
function mintCorgisForGiveaway() public onlyOwner {
        uint256 supply = totalSupply();
        require(giveaway > 0, "Giveaway has been minted!");

        for (uint256 i = 0; i < custom + giveaway; i++) {
            _safeMint(msg.sender, supply + i);
        }

        giveaway -= giveaway;
    }
// Solidity 0.8.7
/**
 * Returns Corgis of the Caller
 */
function corgisOfOwner(address _owner) public view returns(uint256[] memory) {
        uint256 tokenCount = balanceOf(_owner);

        uint256[] memory tokensId = new uint256[](tokenCount);
        for(uint256 i; i < tokenCount; i++){
            tokensId[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokensId;
    }
// Solidity 0.5.0
// This function is responsible for making transactions within the system.
function transferFrom(address from, address to, uint tokens) public returns (bool success) {
		balances[from] = safeSub(balances[from], tokens);
		allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
		balances[to] = safeAdd(balances[to], tokens);
		emit Transfer(from, to, tokens);
		return true;
	}
// Solidity 0.4.24
/**
 * toEthSignedMessageHash
 * @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
 * and hash the result
 */
function toEthSignedMessageHash(bytes32 hash)
    internal
    pure
    returns (bytes32)
  {
    // 32 is the length in bytes of hash,
    // enforced by the type signature above
    return keccak256(
      abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
    );
  }
// Solidity 0.4.24
/**
 * @dev rank - find the rank of a value in the tree,
 *      i.e. its index in the sorted list of elements of the tree
 * @param _tree the tree
 * @param _value the input value to find its rank.
 * @return smaller - the number of elements in the tree which their value is
 * less than the input value.
 */
function rank(Tree storage _tree,uint _value) internal view returns (uint smaller) {
        if (_value != 0) {
            smaller = _tree.nodes[0].dupes;

            uint cur = _tree.nodes[0].children[true];
            Node storage currentNode = _tree.nodes[cur];

            while (true) {
                if (cur <= _value) {
                    if (cur<_value) {
                        smaller = smaller + 1+currentNode.dupes;
                    }
                    uint leftChild = currentNode.children[false];
                    if (leftChild!=0) {
                        smaller = smaller + _tree.nodes[leftChild].count;
                    }
                }
                if (cur == _value) {
                    break;
                }
                cur = currentNode.children[cur<_value];
                if (cur == 0) {
                    break;
                }
                currentNode = _tree.nodes[cur];
            }
        }
    }
// Solidity 0.4.24
/**
 * Round a real to the nearest integral real value.
 */
function round(int256 realValue) internal pure returns (int256) {
        // First, truncate.
        int216 ipart = fromReal(realValue);
        if ((fractionalBits(realValue) & (uint40(1) << (REAL_FBITS - 1))) > 0) {
            // High fractional bit is set. Round up.
            if (realValue < int256(0)) {
                // Rounding up for a negative number is rounding down.
                ipart -= 1;
            } else {
                ipart += 1;
            }
        }
        return toReal(ipart);
    }
// Solidity 0.4.24
/**
 * Get the fractional part of a real, as a real. Respects sign (so fpartSigned(-0.5) is -0.5).
 */
function fpartSigned(int256 realValue) internal pure returns (int256) {
        // This gets the fractional part but strips the sign
        int256 fractional = fpart(realValue);
        if (realValue < 0) {
            // Add the negative sign back in.
            return -fractional;
        } else {
            return fractional;
        }
    }
// Solidity 0.4.24
/**
 * Multiply one real by another. Truncates overflows.
 */
function mul(int256 realA, int256 realB) internal pure returns (int256) {
        // When multiplying fixed point in x.y and z.w formats we get (x+z).(y+w) format.
        // So we just have to clip off the extra REAL_FBITS fractional bits.
        return int256((int256(realA) * int256(realB)) >> REAL_FBITS);
    }
// Solidity 0.4.24
/**
 * Divide one real by another real. Truncates overflows.
 */
function div(int256 realNumerator, int256 realDenominator) internal pure returns (int256) {
        // We use the reverse of the multiplication trick: convert numerator from
        // x.y to (x+z).(y+w) fixed point, then divide by denom in z.w fixed point.
        return int256((int256(realNumerator) * REAL_ONE) / int256(realDenominator));
    }
// Solidity 0.4.24
/**
 * Raise a number to a positive integer power in O(log power) time.
 * See <https://stackoverflow.com/a/101613>
 */
function ipow(int256 realBase, int216 exponent) internal pure returns (int256) {
        if (exponent < 0) {
            // Negative powers are not allowed here.
            revert();
        }

        int256 tempRealBase = realBase;
        int256 tempExponent = exponent;

        // Start with the 0th power
        int256 realResult = REAL_ONE;
        while (tempExponent != 0) {
            // While there are still bits set
            if ((tempExponent & 0x1) == 0x1) {
                // If the low bit is set, multiply in the (many-times-squared) base
                realResult = mul(realResult, tempRealBase);
            }
            // Shift off the low bit
            tempExponent = tempExponent >> 1;
            // Do the squaring
            tempRealBase = mul(tempRealBase, tempRealBase);
        }

        // Return the final result.
        return realResult;
    }
// Solidity 0.4.24
/**
 * Zero all but the highest set bit of a number.
 * See <https://stackoverflow.com/a/53184>
 */
function hibit(uint256 _val) internal pure returns (uint256) {
        // Set all the bits below the highest set bit
        uint256 val = _val;
        val |= (val >> 1);
        val |= (val >> 2);
        val |= (val >> 4);
        val |= (val >> 8);
        val |= (val >> 16);
        val |= (val >> 32);
        val |= (val >> 64);
        val |= (val >> 128);
        return val ^ (val >> 1);
    }