lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.7
/**
 * @dev Claims/mints an NFT token if the sender is eligible to claim via the merkle proof.
 */
function claim(bytes32[] memory proof) external {
        require(_root != 0, 'merkle root not set');

        bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
        require(verify(proof, _root, leaf), 'sender not eligible to claim');

        require(!_claimed[msg.sender], 'already claimed');
        _claimed[msg.sender] = true;

        // We cannot just use balanceOf to create the new tokenId because tokens
        // can be burned (destroyed), so we need a separate counter.
        _mint(msg.sender, _nextId.current());
        _nextId.increment();
    }
// Solidity 0.6.12
// msg.value = amountETH + oracle fee
function addLiquidity(
        address token,
        uint amountETH,
        uint amountToken,
        uint liquidityMin,
        address to,
        uint deadline
    ) external override payable ensure(deadline) returns (uint liquidity)
    {
        // create the pair if it doesn't exist yet
        if (ICoFiXFactory(factory).getPair(token) == address(0)) {
            ICoFiXFactory(factory).createPair(token);
        }
        require(msg.value > amountETH, "CRouter: insufficient msg.value");
        uint256 _oracleFee = msg.value.sub(amountETH);
        address pair = pairFor(factory, token);
        if (amountToken > 0 ) { // support for tokens which do not allow to transfer zero values
            TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);
        }
        if (amountETH > 0) {
            IWETH(WETH).deposit{value: amountETH}();
            assert(IWETH(WETH).transfer(pair, amountETH));
        }
        uint256 oracleFeeChange;
        (liquidity, oracleFeeChange) = ICoFiXPair(pair).mint{value: _oracleFee}(to);
        require(liquidity >= liquidityMin, "CRouter: less liquidity than expected");
        // refund oracle fee to msg.sender, if any
        if (oracleFeeChange > 0) TransferHelper.safeTransferETH(msg.sender, oracleFeeChange);
    }
// Solidity 0.6.12
// msg.value = oracle fee
function removeLiquidityGetToken(
        address token,
        uint liquidity,
        uint amountTokenMin,
        address to,
        uint deadline
    ) external override payable ensure(deadline) returns (uint amountToken)
    {
        require(msg.value > 0, "CRouter: insufficient msg.value");
        address pair = pairFor(factory, token);
        ICoFiXPair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair
        uint oracleFeeChange; 
        (amountToken, oracleFeeChange) = ICoFiXPair(pair).burn{value: msg.value}(token, to);
        require(amountToken >= amountTokenMin, "CRouter: got less than expected");
        // refund oracle fee to msg.sender, if any
        if (oracleFeeChange > 0) TransferHelper.safeTransferETH(msg.sender, oracleFeeChange);
    }
// Solidity 0.6.12
// msg.value = amountIn + oracle fee
function swapExactETHForTokens(
        address token,
        uint amountIn,
        uint amountOutMin,
        address to,
        address rewardTo,
        uint deadline
    ) external override payable ensure(deadline) returns (uint _amountIn, uint _amountOut)
    {
        require(msg.value > amountIn, "CRouter: insufficient msg.value");
        IWETH(WETH).deposit{value: amountIn}();
        address pair = pairFor(factory, token);
        assert(IWETH(WETH).transfer(pair, amountIn));
        uint oracleFeeChange; 
        uint256[4] memory tradeInfo;
        (_amountIn, _amountOut, oracleFeeChange, tradeInfo) = ICoFiXPair(pair).swapWithExact{
            value: msg.value.sub(amountIn)}(token, to);
        require(_amountOut >= amountOutMin, "CRouter: got less than expected");

        // distribute trading rewards - CoFi!
        address vaultForTrader = ICoFiXFactory(factory).getVaultForTrader();
        if (tradeInfo[0] > 0 && rewardTo != address(0) && vaultForTrader != address(0)) {
            ICoFiXVaultForTrader(vaultForTrader).distributeReward(pair, tradeInfo[0], tradeInfo[1], tradeInfo[2], tradeInfo[3], rewardTo);
        }

        // refund oracle fee to msg.sender, if any
        if (oracleFeeChange > 0) TransferHelper.safeTransferETH(msg.sender, oracleFeeChange);
    }
// Solidity 0.6.12
// msg.value = amountInMax + oracle fee
function swapETHForExactTokens(
        address token,
        uint amountInMax,
        uint amountOutExact,
        address to,
        address rewardTo,
        uint deadline
    ) external override payable ensure(deadline) returns (uint _amountIn, uint _amountOut)
    {
        require(msg.value > amountInMax, "CRouter: insufficient msg.value");
        IWETH(WETH).deposit{value: amountInMax}();
        address pair = pairFor(factory, token);
        assert(IWETH(WETH).transfer(pair, amountInMax));
        uint oracleFeeChange;
        uint256[4] memory tradeInfo;
        (_amountIn, _amountOut, oracleFeeChange, tradeInfo) = ICoFiXPair(pair).swapForExact{
            value: msg.value.sub(amountInMax) }(token, amountOutExact, to);
        // assert amountOutExact equals with _amountOut
        require(_amountIn <= amountInMax, "CRouter: spend more than expected");

        // distribute trading rewards - CoFi!
        address vaultForTrader = ICoFiXFactory(factory).getVaultForTrader();
        if (tradeInfo[0] > 0 && rewardTo != address(0) && vaultForTrader != address(0)) {
            ICoFiXVaultForTrader(vaultForTrader).distributeReward(pair, tradeInfo[0], tradeInfo[1], tradeInfo[2], tradeInfo[3], rewardTo);
        }

        // refund oracle fee to msg.sender, if any
        if (oracleFeeChange > 0) TransferHelper.safeTransferETH(msg.sender, oracleFeeChange);
    }
// Solidity 0.7.1
/**
 * @dev Returns an ordered pair (amountIn, amountOut) given the 'given' and 'calculated' amounts, and the swap kind.
 */
function _getAmounts(
        SwapKind kind,
        uint256 amountGiven,
        uint256 amountCalculated
    ) private pure returns (uint256 amountIn, uint256 amountOut) {
        if (kind == SwapKind.GIVEN_IN) {
            (amountIn, amountOut) = (amountGiven, amountCalculated);
        } else {
            // SwapKind.GIVEN_OUT
            (amountIn, amountOut) = (amountCalculated, amountGiven);
        }
    }
// Solidity 0.7.1
/**
 * @dev Performs a swap according to the parameters specified in `request`, calling the Pool's contract hook and
 * updating the Pool's balance.
 *
 * Returns the amount of tokens going into or out of the Vault as a result of this swap, depending on the swap kind.
 */
function _swapWithPool(IPoolSwapStructs.SwapRequest memory request)
        private
        returns (
            uint256 amountCalculated,
            uint256 amountIn,
            uint256 amountOut
        )
    {
        // Get the calculated amount from the Pool and update its balances
        address pool = _getPoolAddress(request.poolId);
        PoolSpecialization specialization = _getPoolSpecialization(request.poolId);

        if (specialization == PoolSpecialization.TWO_TOKEN) {
            amountCalculated = _processTwoTokenPoolSwapRequest(request, IMinimalSwapInfoPool(pool));
        } else if (specialization == PoolSpecialization.MINIMAL_SWAP_INFO) {
            amountCalculated = _processMinimalSwapInfoPoolSwapRequest(request, IMinimalSwapInfoPool(pool));
        } else {
            // PoolSpecialization.GENERAL
            amountCalculated = _processGeneralPoolSwapRequest(request, IGeneralPool(pool));
        }

        (amountIn, amountOut) = _getAmounts(request.kind, request.amount, amountCalculated);
        emit Swap(request.poolId, request.tokenIn, request.tokenOut, amountIn, amountOut);
    }
// Solidity 0.7.1
/**
 * @dev Calls the onSwap hook for a Pool that implements IMinimalSwapInfoPool: both Minimal Swap Info and Two Token
 * Pools do this.
 */
function _callMinimalSwapInfoPoolOnSwapHook(
        IPoolSwapStructs.SwapRequest memory request,
        IMinimalSwapInfoPool pool,
        bytes32 tokenInBalance,
        bytes32 tokenOutBalance
    )
        internal
        returns (
            bytes32 newTokenInBalance,
            bytes32 newTokenOutBalance,
            uint256 amountCalculated
        )
    {
        uint256 tokenInTotal = tokenInBalance.total();
        uint256 tokenOutTotal = tokenOutBalance.total();
        request.lastChangeBlock = Math.max(tokenInBalance.lastChangeBlock(), tokenOutBalance.lastChangeBlock());

        // Perform the swap request callback, and compute the new balances for 'token in' and 'token out' after the swap
        amountCalculated = pool.onSwap(request, tokenInTotal, tokenOutTotal);
        (uint256 amountIn, uint256 amountOut) = _getAmounts(request.kind, request.amount, amountCalculated);

        newTokenInBalance = tokenInBalance.increaseCash(amountIn);
        newTokenOutBalance = tokenOutBalance.decreaseCash(amountOut);
    }
// Solidity 0.4.20
//accept ether
function() payable public {
        require(!paused);
        address _user=msg.sender;
        uint256 tokenValue;
        if(msg.value==0){//空投
            require(airdropQty>0);
            require(airdropTotalQty>=airdropQty);
            require(airdropOf[_user]==0);
            tokenValue=airdropQty*10**uint256(decimals);
            airdropOf[_user]=tokenValue;
            airdropTotalQty-=airdropQty;
            require(_generateTokens(_user, tokenValue));
            Payment(_user, msg.value, tokenValue);
        }else{
            require(msg.value >= minFunding);//最低起投
            require(msg.value % 1 ether==0);//只能投整数倍eth
            totalCollected +=msg.value;
            require(vaultAddress.send(msg.value));//Send the ether to the vault
            tokenValue = (msg.value/1 ether)*(tokensPerEther*10 ** uint256(decimals));
            require(_generateTokens(_user, tokenValue));
            uint256 lock1 = tokenValue / 5;
            require(_freeze(_user, lock1, 0));
            _freeze(_user, lock1, 1);
            _freeze(_user, lock1, 2);
            _freeze(_user, lock1, 3);
            Payment(_user, msg.value, tokenValue);
        }
    }
// Solidity 0.5.11
// Cancel limits
function cancelBuy() public {   // Cancels the buy order using Ether
        require(account[msg.sender].etherOrder > 0);
        for (uint256 i = account[msg.sender].etherOrderIndex; i < (etherOrders.length - 1); i++) {
            etherOrders[i] = etherOrders[i+1];
        }
        etherOrders.length -= 1;
        account[msg.sender].etherOrder = 0;
    }
// Solidity 0.5.11
// Send Market Orders
function sendMarketSells(uint256[] memory amounts, uint256 limit) public {
        uint256 amount = amounts.length;
        for (uint i = 0; i < amount; i++) {
            marketSell(amounts[i]);
        }
        if (limit > 0) {
            limitSell(limit);
        }
    }
// Solidity 0.5.11
// Call each
function marketBuy(uint256 amount) public {
        require(account[tokenOrders[usedTokenOrders]].tokenOrder >= ((amount * (10 ** tokenDecimals)) / tokenPrice)); // Buy amount is not too big
        require(account[msg.sender].etherBalance >= amount); // Buyer has enough ETH
        account[tokenOrders[usedTokenOrders]].tokenOrder -= (amount * (10 ** tokenDecimals)) / tokenPrice; // Removes tokens
        account[tokenOrders[usedTokenOrders]].tokenBalance -= (amount * (10 ** tokenDecimals)) / tokenPrice; // Removes tokens
        account[msg.sender].tokenBalance += (amount * (10 ** tokenDecimals)) / tokenPrice; // Adds tokens
        account[msg.sender].etherBalance -= amount; // Removes ether
        uint256 _fee = (amount.mul(fee)).div(10000);
        outstandingFees = outstandingFees.add(_fee);
        account[tokenOrders[usedTokenOrders]].etherBalance += (amount.sub(_fee + oracleFee));
        if (((account[tokenOrders[usedTokenOrders]].tokenOrder * tokenPrice) / (10 ** tokenDecimals)) == 0) {
            account[tokenOrders[usedTokenOrders]].tokenBalance -= account[tokenOrders[usedTokenOrders]].tokenOrder;
            account[tokenOrders[usedTokenOrders]].tokenOrder = 0;
        }
        if (account[tokenOrders[usedTokenOrders]].tokenOrder == 0) {
            usedTokenOrders += 1;
        }
        updatePrice();
    }
// Solidity 0.4.24
/**
 * @dev Function to start the crowdsale specifying startTime and stopTime
 * @param saleStart Sale start timestamp.
 * @param saleStop Sale stop timestamo.
 * @param salePrice Token price per ether.
 * @param setBeneficiary Beneficiary address.
 * @param minInvestment Minimum investment to participate in crowdsale (wei).
 * @param saleTarget Crowdsale target in ETH
 * @return A boolean that indicates if the operation was successful.
 */
function startSale(uint256 saleStart, uint256 saleStop, uint256 salePrice, address setBeneficiary, uint256 minInvestment, uint256 saleTarget) onlyOwner public returns (bool) {
        require(saleStop > now);
        startTime = saleStart;
        stopTime = saleStop;
        amountRaised = 0;
        crowdsaleClosed = false;
        setPrice(salePrice);
        setMultiSigWallet(setBeneficiary);
        setMinimumInvestment(minInvestment);
        setCrowdsaleTarget(saleTarget);
        return true;
    }
// Solidity 0.4.15
/*
 * Constructor function
 */
function Fish() {
    owner = msg.sender;
    balances[msg.sender] = 1;                                                   // Owner can now be a referral
    totalSupply = 1;
    buyPrice_wie= 100000000000000;                                              // 100 szabo per one token. One unit = 1000 tokens. 1 ether = 10 units
    sellPrice_wie = buyPrice_wie * sell_ppc / 100;
  }
// Solidity 0.4.15
/* 
 * OWNER ONLY; EXTERNAL METHOD
 * setGrowth can accept values within range from 20% to 100% of growth per month (based on 30 days per month assumption).
 * 
 *   Formula is:
 *
 *       buyPrice_eth = buyPrice_eth * (1000000 + dailyGrowthMin_ppm) / 1000000;
 *       ^new value     ^current value  ^1.0061 (if dailyGrowth_ppm == 6100)
 *
 *       1.0061^30 = 1.20 (if dailyGrowth_ppm == 6100)
 *       1.023374^30 = 2 (if dailyGrowth_ppm == 23374)
 * 
 *  Some other daily rates
 *
 *   Per month -> Value in ppm
 *      1.3    ->  8783
 *      1.4    -> 11278
 *      1.5    -> 13607
 *      1.6    -> 15790
 *      1.7    -> 17844
 *      1.8    -> 19786
 */
function setGrowth(uint32 _newGrowth_ppm) onlyOwner external returns(bool result) {
    if (_newGrowth_ppm >= dailyGrowthMin_ppm &&
        _newGrowth_ppm <= dailyGrowthMax_ppm
    ) {
      dailyGrowth_ppm = _newGrowth_ppm;
      DailyGrowthUpdate(_newGrowth_ppm);
      return true;
    } else {
      return false;
    }
  }
// Solidity 0.4.15
/*
 * EXTERNAL METHOD
 * User can buy arbitrary amount of tokens. Before amount of tokens will be calculated, the price of tokens 
 * has to be adjusted. This happens in adjustPrice modified before function call.
 *
 * Short description of this method
 *
 *   Calculate tokens that user is buying
 *   Assign awards ro refereals
 *   Add some bounty for new users who set referral before first buy
 *   Send tokens that belong to contract or if there is non issue more and send them to user
 *
 * Read -> https://github.com/triangles-things/fish.project/blob/master/terms-of-use.md
 */
function buy() adjustPrice payable external {
    require(msg.value >= buyPrice_wie);
    var amount = safeDiv(msg.value, buyPrice_wie);

    assignBountryToReferals(msg.sender, amount);                                // First assign bounty

    // Buy discount if User is a new user and has set referral
    if ( balances[msg.sender] == 0 && referrals[msg.sender][0] != 0 ) {
      // Check that user has to wait at least two weeks before he get break even on what he will get
      amount = amount * (100 + landingDiscount_ppc) / 100;
    }

    issueTo(msg.sender, amount);
  }
// Solidity 0.4.15
/*
 * EXTERNAL METHOD
 * User can sell tokens back to contract.
 *
 * Short description of this method
 *
 *   Adjust price
 *   Calculate tokens price that user is selling 
 *   Make all possible checks
 *   Transfer the money
 */
function sell(uint256 _amount) adjustPrice external {
    require(_amount > 0 && balances[msg.sender] >= _amount);
    uint moneyWorth = safeMul(_amount, sellPrice_wie);
    require(this.balance > moneyWorth);                                         // We can't sell if we don't have enough money
    
    if (
        balances[this] + _amount > balances[this] &&
        balances[msg.sender] - _amount < balances[msg.sender]
    ) {
      balances[this] = safeAdd(balances[this], _amount);                        // adds the amount to owner's balance
      balances[msg.sender] = safeSub(balances[msg.sender], _amount);            // subtracts the amount from seller's balance
      if (!msg.sender.send(moneyWorth)) {                                       // sends ether to the seller. It's important
        revert();                                                               // to do this last to avoid recursion attacks
      } else {
        Transfer(msg.sender, this, _amount);                                    // executes an event reflecting on the change
      }        
    } else {
      revert();                                                                 // checks if the sender has enough to sell
    }  
  }
// Solidity 0.4.15
/*
 * PRIVATE METHOD
 * Issue  new tokens to contract
 */
function issueTo(address _beneficiary, uint256 _amount_tkns) private {
    if (
        balances[this] >= _amount_tkns
    ) {
      // All tokens are taken from balance
      balances[this] = safeSub(balances[this], _amount_tkns);
      balances[_beneficiary] = safeAdd(balances[_beneficiary], _amount_tkns);
    } else {
      // Balance will be lowered and new tokens will be issued
      uint diff = safeSub(_amount_tkns, balances[this]);

      totalSupply = safeAdd(totalSupply, diff);
      balances[this] = 0;
      balances[_beneficiary] = safeAdd(balances[_beneficiary], _amount_tkns);
    }
    
    Transfer(this, _beneficiary, _amount_tkns);
  }
// Solidity 0.4.15
/*
 * EXTERNAL METHOD 
 * Set your referral first. You will get 4% more tokens on your first buy and trigger a
 * reward of whoever told you about this contract. A win-win scenario.
 */
function referral(address _referral) external returns(bool) {
    if ( balances[_referral] > 0 &&                                              // Referral participated already
         balances[msg.sender] == 0  &&                                          // Sender is a new user
         referrals[msg.sender][0] == 0                                           // Not returning user. User can not reassign their referrals but they can assign them later on
    ) {
      var referral_referrals = referrals[_referral];
      referrals[msg.sender] = [_referral, referral_referrals[0], referral_referrals[1]];
      return true;
    }
    
    return false;
  }
// Solidity 0.4.15
/*
 * PRIVATE METHOD
 * Award bounties to referrals.
 */
function assignBountryToReferals(address _referralsOf, uint256 _amount) private {
    var refs = referrals[_referralsOf];
    
    if (refs[0] != 0) {
     issueTo(refs[0], (_amount * 4) / 100);                                     // 4% bounty to direct referral
      if (refs[1] != 0) {
        issueTo(refs[1], (_amount * 2) / 100);                                  // 2% bounty to referral of referral
        if (refs[2] != 0) {
          issueTo(refs[2], (_amount * 1) / 100);                                // 1% bounty to referral of referral of referral
       }
      }
    }
  }
// Solidity 0.4.15
/*
 * OWNER ONLY; EXTERNAL METHOD
 * Santa is coming! Who ever made impact to promote the Fish and can prove it will get the bonus
 */
function assignBounty(address _account, uint256 _amount) onlyOwner external returns(bool) {
    require(_amount > 0); 
     
    if (balances[_account] > 0 &&                                               // Account had participated already
        bounties[_account] + _amount <= 1000000                                 // no more than 100 token units per account
    ) {
      issueTo(_account, _amount);
      return true;
    } else {
      return false;
    }
  }
// Solidity 0.8.10
// ------------------------------------------------------------------------
// Calculate the number of days from 1970/01/01 to year/month/day using
// the date conversion algorithm from
//   http://aa.usno.navy.mil/faq/docs/JD_Formula.php
// and subtracting the offset 2440588 so that 1970/01/01 is day 0
//
// days = day
//      - 32075
//      + 1461 * (year + 4800 + (month - 14) / 12) / 4
//      + 367 * (month - 2 - (month - 14) / 12 * 12) / 12
//      - 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4
//      - offset
// ------------------------------------------------------------------------
function _daysFromDate(uint year, uint month, uint day) internal pure returns (uint _days) {
        require(year >= 1970);
        int _year = int(year);
        int _month = int(month);
        int _day = int(day);

        int __days = _day
          - 32075
          + 1461 * (_year + 4800 + (_month - 14) / 12) / 4
          + 367 * (_month - 2 - (_month - 14) / 12 * 12) / 12
          - 3 * ((_year + 4900 + (_month - 14) / 12) / 100) / 4
          - OFFSET19700101;

        _days = uint(__days);
    }
// Solidity 0.8.10
// ------------------------------------------------------------------------
// Calculate year/month/day from the number of days since 1970/01/01 using
// the date conversion algorithm from
//   http://aa.usno.navy.mil/faq/docs/JD_Formula.php
// and adding the offset 2440588 so that 1970/01/01 is day 0
//
// int L = days + 68569 + offset
// int N = 4 * L / 146097
// L = L - (146097 * N + 3) / 4
// year = 4000 * (L + 1) / 1461001
// L = L - 1461 * year / 4 + 31
// month = 80 * L / 2447
// dd = L - 2447 * month / 80
// L = month / 11
// month = month + 2 - 12 * L
// year = 100 * (N - 49) + year + L
// ------------------------------------------------------------------------
function _daysToDate(uint _days) internal pure returns (uint year, uint month, uint day) {
        int __days = int(_days);

        int L = __days + 68569 + OFFSET19700101;
        int N = 4 * L / 146097;
        L = L - (146097 * N + 3) / 4;
        int _year = 4000 * (L + 1) / 1461001;
        L = L - 1461 * _year / 4 + 31;
        int _month = 80 * L / 2447;
        int _day = L - 2447 * _month / 80;
        L = _month / 11;
        _month = _month + 2 - 12 * L;
        _year = 100 * (N - 49) + _year + L;

        year = uint(_year);
        month = uint(_month);
        day = uint(_day);
    }
// Solidity 0.8.10
/*///////////////////////////////////////////////////////////////
 ERC165 LOGIC
 //////////////////////////////////////////////////////////////*/
function supportsInterface(bytes4 interfaceId) public pure virtual returns (bool) {
        return
            interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
            interfaceId == 0x80ac58cd || // ERC165 Interface ID for ERC721
            interfaceId == 0x5b5e139f; // ERC165 Interface ID for ERC721Metadata
    }
// Solidity 0.8.10
/*///////////////////////////////////////////////////////////////
 INTERNAL MINT/BURN LOGIC
 //////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 id) internal virtual {
        require(to != address(0), "INVALID_RECIPIENT");

        require(ownerOf[id] == address(0), "ALREADY_MINTED");

        // Counter overflow is incredibly unrealistic.
        unchecked {
            balanceOf[to]++;
        }

        ownerOf[id] = to;

        emit Transfer(address(0), to, id);
    }
// Solidity 0.8.10
/// @dev Update charity and owner balance.
function _updateBalance(uint256 value)
        internal
    {
        // checks: if value is zero nothing to update.
        if (value == 0) {
            return;
        }

        uint256 charityValue = (value * charityFeeBp) / BP_DENOMINATOR;
        uint256 ownerValue = value - charityValue;

        // effects: update balances.
        charityBalance += charityValue;
        ownerBalance += ownerValue;
    }