lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Finalizes a withdrawal via Outbox message; callable only by L2Gateway.outboundTransfer
 * @param _token L1 address of token being withdrawn from
 * @param _from initiator of withdrawal
 * @param _to address the L2 withdrawal call set as the destination.
 * @param _amount Token amount being withdrawn
 * @param _data encoded exitNum (Sequentially increasing exit counter determined by the L2Gateway) and additinal hook data
 */
function finalizeInboundTransfer(
        address _token,
        address _from,
        address _to,
        uint256 _amount,
        bytes calldata _data
    ) external payable override onlyCounterpartGateway {
        (uint256 exitNum, bytes memory callHookData) = GatewayMessageHandler.parseToL1GatewayMsg(
            _data
        );

        if (callHookData.length != 0) {
            // callHookData should always be 0 since inboundEscrowAndCall is disabled
            callHookData = bytes("");
        }

        // we ignore the returned data since the callHook feature is now disabled
        (_to, ) = getExternalCall(exitNum, _to, callHookData);
        inboundEscrowTransfer(_token, _to, _amount);

        emit WithdrawalFinalized(_token, _from, _to, exitNum, _amount);
    }
// Solidity 0.7.1
/**
 * @dev Creates a Pool ID.
 *
 * These are deterministically created by packing the Pool's contract address and its specialization setting into
 * the ID. This saves gas by making this data easily retrievable from a Pool ID with no storage accesses.
 *
 * Since a single contract can register multiple Pools, a unique nonce must be provided to ensure Pool IDs are
 * unique.
 *
 * Pool IDs have the following layout:
 * | 20 bytes pool contract address | 2 bytes specialization setting | 10 bytes nonce |
 * MSB                                                                              LSB
 *
 * 2 bytes for the specialization setting is a bit overkill: there only three of them, which means two bits would
 * suffice. However, there's nothing else of interest to store in this extra space.
 */
function _toPoolId(
        address pool,
        PoolSpecialization specialization,
        uint80 nonce
    ) internal pure returns (bytes32) {
        bytes32 serialized;

        serialized |= bytes32(uint256(nonce));
        serialized |= bytes32(uint256(specialization)) << (10 * 8);
        serialized |= bytes32(uint256(pool)) << (12 * 8);

        return serialized;
    }
// Solidity 0.7.1
/**
 * @dev Returns the address of a Pool's contract.
 *
 * Due to how Pool IDs are created, this is done with no storage accesses and costs little gas.
 */
function _getPoolAddress(bytes32 poolId) internal pure returns (address) {
        // 12 byte logical shift left to remove the nonce and specialization setting. We don't need to mask,
        // since the logical shift already sets the upper bits to zero.
        return address(uint256(poolId) >> (12 * 8));
    }
// Solidity 0.4.18
//low level function to buy tokens
function buyTokens(address beneficiary) internal {
        require(beneficiary != 0x0);
        require(whitelist[beneficiary]);
        require(validPurchase());

        //derive amount in wei to buy 
        uint256 weiAmount = msg.value;

        // check if contribution is in the first 24h hours
        if (getBlockTimestamp() <= firstDay) {
            require((contribution[beneficiary].add(weiAmount)) <= firstDayCap);
        }
        //check if there is enough funds 
        uint256 remainingToFund = cap.sub(weiRaised);
        if (weiAmount > remainingToFund) {
            weiAmount = remainingToFund;
        }
        uint256 weiToReturn = msg.value.sub(weiAmount);
        //Forward funs to the vault 
        forwardFunds(weiAmount);
        //refund if the contribution exceed the cap
        if (weiToReturn > 0) {
            msg.sender.transfer(weiToReturn);
            TokenRefund(beneficiary, weiToReturn);
        }
        //derive how many tokens
        uint256 tokens = getTokens(weiAmount);
        //update the state of weiRaised
        weiRaised = weiRaised.add(weiAmount);
        contribution[beneficiary] = contribution[beneficiary].add(weiAmount);
     
        //Trigger the event of TokenPurchase
        TokenPurchase(
            msg.sender,
            beneficiary,
            weiAmount,
            tokens
        );
        token.transferTokens(beneficiary,tokens);
        
    }
// Solidity 0.4.18
//Only owner can manually finalize the sale
function finalize() onlyOwner {
        require(!isFinalized);
        require(hasEnded());

        if (goalReached()) {
            //Close the vault
            vault.close();
            //Unpause the token 
            token.unpause();
            //give ownership back to deployer
            token.transferOwnership(owner);
        } else {
            //else enable refunds
            vault.enableRefunds();
        }
        //update the sate of isFinalized
        isFinalized = true;
        //trigger and emit the event of finalization
        Finalized();
    }
// Solidity 0.4.18
// @return true if the transaction can buy tokens
function validPurchase() internal constant returns (bool) {
        bool withinPeriod = getBlockTimestamp() >= startTime && getBlockTimestamp() <= endTime;
        bool nonZeroPurchase = msg.value != 0;
        bool capNotReached = weiRaised < cap;
        return withinPeriod && nonZeroPurchase && capNotReached;
    }
// Solidity 0.5.0
//Note: owner (or their advocate) is expected to have audited what they commit to,
// including confidence that the terms are guaranteed not to change. i.e. the smartInvoice is trusted
function commit(SmartInvoice smartInvoice) external isOwner  returns (bool) {
    require(smartInvoice.payer() == address(this), "not smart invoice payer");
    require(smartInvoice.status() == SmartInvoice.Status.UNCOMMITTED, "smart invoice already committed");
    require(smartInvoice.assetToken() == this.assetToken(), "smartInvoice uses different asset token");
    require(smartInvoice.commit(), "could not commit");
    require(smartInvoice.status() == SmartInvoice.Status.COMMITTED, "commit did not update status");
    _smartInvoiceStatus[address(smartInvoice)] = SmartInvoice.Status.COMMITTED;
    return true;
  }
// Solidity 0.8.7
// @dev convinence function for returning the offset token ID
function xhouseID(uint256 _id) public view returns (uint256 houseID) {
        for (uint256 i = 1; i <= SEASON_COUNT; i++) {
            if (_id < seasons[i].unit_count) {
                return (_id + seasons[i].tokenOffset) % seasons[i].unit_count;
            }
        }
    }
// Solidity 0.8.7
// onlyOwner functions
function addSeason(
        uint256 _seasonNum,
        uint256 _price,
        uint256 _count,
        uint256 _walletLimit,
        string memory _provenance,
        string memory _baseURI
    ) external onlyOwner {
        require(seasons[_seasonNum].unit_count == 0, "Season Already exists");
        seasons[_seasonNum] = Season(
            _seasonNum,
            _price,
            _count,
            _walletLimit,
            0, // offset init
            _provenance,
            _baseURI,
            true, // paused
            false, // publicSales
            false // revealed
        );
        SEASON_COUNT += 1;
        // season 1 , 111
        // season 2, 111 + 111
        // season 3 , 222 + 111
        season_offsets[_seasonNum] = season_offsets[_seasonNum - 1] + _count;
        season_minted[_seasonNum] = 0;
    }
// Solidity 0.8.7
// @dev gift a single token to each address passed in through calldata
// @param _season uint256 season number
// @param _recipients Array of addresses to send a single token to
function gift(uint256 _season, address[] calldata _recipients)
        external
        onlyOwner
    {
        require(
            _recipients.length + season_minted[_season] <=
                seasons[_season].unit_count,
            "Number of gifts exceeds season supply"
        );

        for (uint256 i = 0; i < _recipients.length; i++) {
            uint256 tokenID = season_offsets[_season - 1] +
                season_minted[_season] +
                1;
            _safeMint(_recipients[i], tokenID);
            totalPublicMinted += 1;
            season_minted[_season] += 1;
        }
    }
// Solidity 0.7.5
/**
 * Inserts new value by moving existing value at provided index to end of array and setting provided value at provided index
 */
function _insert(Set storage set_, uint256 index_, bytes32 valueToInsert_ ) private returns ( bool ) {
    require(  set_._values.length > index_ );
    require( !_contains( set_, valueToInsert_ ), "Remove value you wish to insert if you wish to reorder array." );
    bytes32 existingValue_ = _at( set_, index_ );
    set_._values[index_] = valueToInsert_;
    return _add( set_, existingValue_);
  }
// Solidity 0.7.5
/**
 * TODO Might require explicit conversion of bytes32[] to address[].
 *  Might require iteration.
 */
function getValues( AddressSet storage set_ ) internal view returns ( address[] memory ) {

    address[] memory addressArray;

    for( uint256 iteration_ = 0; _length(set_._inner) >= iteration_; iteration_++ ){
      addressArray[iteration_] = at( set_, iteration_ );
    }

    return addressArray;
  }
// Solidity 0.6.12
// mine token
function earned(uint256 _tokenId) public view returns (uint256) {
        if(!_exists(_tokenId)) {
            return 0;
        }
        Property memory prop = cardProperties[_tokenId];
        uint256 _startTime = Math.max(prop.lastUpdateTime, mineStartTime);
        uint256 _endTime = Math.min(block.timestamp,mineEndTime);

        if(_startTime >= _endTime) {
            return 0;
        }

        return prop.forceValue.mul(prop.defenderValue)
                .mul(mineFactor).mul(_endTime.sub(_startTime))
                .div(1 days);
    }
// Solidity 0.6.12
// Compose intermediate cards
function composeToIntermediateCards(uint256[] memory _tokenIds) external {
        require(hasComposeToIntermediateStarted, "Compose to intermediate card has not started");
        uint256 count = _tokenIds.length / 2;
        require(_tokenIds.length % 2 == 0 && count > 0 && count <= 5, "Number of cards does not match or exceed maximum cards,maximum is 10");
        CardType cardType = cardProperties[_tokenIds[0]].cardType;
        uint256 nextIntermediateCardId = nextUltramanIntermediateCardId;
        if(cardType == CardType.Monster) {
            nextIntermediateCardId = nextMonsterIntermediateCardId;
        }
        require(nextIntermediateCardId.add((count - 1) * 2) <= intermediateCardIdEnd, "No enough intermediate card");
        uint256 _tokenPrice = getTokenPrice();
        uint256 needToken = composeToIntermediateCardNeedValue.
                            mul(WEI_PRECISION).
                            mul(count).
                            div(_tokenPrice);

        untToken.safeTransferFrom(msg.sender,dev,needToken);
        for(uint256 i = 0 ; i < count ;i++) {
            uint256 first = i * 2 ;
            uint256 second = first + 1;
            compose(_tokenIds[first],_tokenIds[second],CardLevel.Elementary,nextIntermediateCardId,cardType);
            nextIntermediateCardId = nextIntermediateCardId + 2;
        }
        if(cardType == CardType.Ultraman) {
            nextUltramanIntermediateCardId = nextIntermediateCardId;
        }else {
            nextMonsterIntermediateCardId = nextIntermediateCardId;
        }
    }
// Solidity 0.6.12
// Compose advanced cards
function composeToAdvancedCards(uint256[] memory _tokenIds) external {
        require(hasComposeToAdvancedStarted, "Compose to advance card has not started");
        uint256 count = _tokenIds.length / 2;
        require(_tokenIds.length % 2 == 0 && count > 0 && count <= 5, "Number of cards does not match or exceed maximum cards,maximum is 10");
        CardType cardType = cardProperties[_tokenIds[0]].cardType;
        uint256 nextAdvancedCardId = nextUltramanAdvancedCardId;
        if(cardType == CardType.Monster) {
            nextAdvancedCardId = nextMonsterAdvancedCardId;
        }
        require(nextAdvancedCardId.add((count - 1) * 2) <= advancedCardIdEnd, "No enough advance card");

        uint256 _tokenPrice = getTokenPrice();
        uint256 needToken = composeToAdvancedCardNeedValue.
                                mul(WEI_PRECISION).
                                mul(count).
                                div(_tokenPrice);

        untToken.safeTransferFrom(msg.sender,dev,needToken);
        for(uint256 i = 0 ; i < count ;i++) {
            uint256 first = i * 2 ;
            uint256 second = first + 1;
            compose(_tokenIds[first],_tokenIds[second],CardLevel.Intermediate,nextAdvancedCardId,cardType);
            nextAdvancedCardId = nextAdvancedCardId + 2;
        }
        if(cardType == CardType.Ultraman) {
            nextUltramanAdvancedCardId = nextAdvancedCardId;
        }else {
            nextMonsterAdvancedCardId = nextAdvancedCardId;
        }
    }
// Solidity 0.4.24
/**
 * @dev Overrides Crowdsale fund forwarding, sending funds to vault if not finalised, otherwise to wallet
 */
function _forwardFunds() internal {
    // once finalized all contributions got to the wallet
    if (isFinalized) {
      wallet.transfer(msg.value);
    }
    // otherwise send to vault to allow refunds, if required
    else {
      vault.deposit.value(msg.value)(msg.sender);
    }
  }
// Solidity 0.4.24
/**
 * @dev Extend parent behavior requiring contract to not be paused.
 * @param _beneficiary Token beneficiary
 * @param _weiAmount Amount of wei contributed
 */
function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
    super._preValidatePurchase(_beneficiary, _weiAmount);

    require(isCrowdsaleOpen(), "Crowdsale not open");

    require(weiRaised.add(_weiAmount) <= hardCap, "Exceeds maximum cap");

    require(_weiAmount >= minimumContribution, "Beneficiary minimum amount not reached");

    require(whitelist[_beneficiary], "Beneficiary not whitelisted");

    require(whitelist[msg.sender], "Sender not whitelisted");

    require(!paused, "Contract paused");
  }
// Solidity 0.7.1
/**
 * @dev Registers tokens in a Two Token Pool.
 *
 * This function assumes `poolId` exists and corresponds to the Two Token specialization setting.
 *
 * Requirements:
 *
 * - `tokenX` and `tokenY` must not be the same
 * - The tokens must be ordered: tokenX < tokenY
 */
function _registerTwoTokenPoolTokens(
        bytes32 poolId,
        IERC20 tokenX,
        IERC20 tokenY
    ) internal {
        // Not technically true since we didn't register yet, but this is consistent with the error messages of other
        // specialization settings.
        _require(tokenX != tokenY, Errors.TOKEN_ALREADY_REGISTERED);

        _require(tokenX < tokenY, Errors.UNSORTED_TOKENS);

        // A Two Token Pool with no registered tokens is identified by having zero addresses for tokens A and B.
        TwoTokenPoolTokens storage poolTokens = _twoTokenPoolTokens[poolId];
        _require(poolTokens.tokenA == IERC20(0) && poolTokens.tokenB == IERC20(0), Errors.TOKENS_ALREADY_SET);

        // Since tokenX < tokenY, tokenX is A and tokenY is B
        poolTokens.tokenA = tokenX;
        poolTokens.tokenB = tokenY;

        // Note that we don't initialize the balance mapping: the default value of zero corresponds to an empty
        // balance.
    }
// Solidity 0.7.1
/**
 * @dev Deregisters tokens in a Two Token Pool.
 *
 * This function assumes `poolId` exists and corresponds to the Two Token specialization setting.
 *
 * Requirements:
 *
 * - `tokenX` and `tokenY` must be registered in the Pool
 * - both tokens must have zero balance in the Vault
 */
function _deregisterTwoTokenPoolTokens(
        bytes32 poolId,
        IERC20 tokenX,
        IERC20 tokenY
    ) internal {
        (
            bytes32 balanceA,
            bytes32 balanceB,
            TwoTokenPoolBalances storage poolBalances
        ) = _getTwoTokenPoolSharedBalances(poolId, tokenX, tokenY);

        _require(balanceA.isZero() && balanceB.isZero(), Errors.NONZERO_TOKEN_BALANCE);

        delete _twoTokenPoolTokens[poolId];

        // For consistency with other Pool specialization settings, we explicitly reset the packed cash field (which may
        // have a non-zero last change block).
        delete poolBalances.sharedCash;
    }
// Solidity 0.7.1
/**
 * @dev Sets `token`'s balance in a Two Token Pool to the result of the `mutation` function when called with
 * the current balance and `amount`.
 *
 * This function assumes `poolId` exists, corresponds to the Two Token specialization setting, and that `token` is
 * registered for that Pool.
 *
 * Returns the managed balance delta as a result of this call.
 */
function _updateTwoTokenPoolSharedBalance(
        bytes32 poolId,
        IERC20 token,
        function(bytes32, uint256) returns (bytes32) mutation,
        uint256 amount
    ) private returns (int256) {
        (
            TwoTokenPoolBalances storage balances,
            IERC20 tokenA,
            bytes32 balanceA,
            ,
            bytes32 balanceB
        ) = _getTwoTokenPoolBalances(poolId);

        int256 delta;
        if (token == tokenA) {
            bytes32 newBalance = mutation(balanceA, amount);
            delta = newBalance.managedDelta(balanceA);
            balanceA = newBalance;
        } else {
            // token == tokenB
            bytes32 newBalance = mutation(balanceB, amount);
            delta = newBalance.managedDelta(balanceB);
            balanceB = newBalance;
        }

        balances.sharedCash = BalanceAllocation.toSharedCash(balanceA, balanceB);
        balances.sharedManaged = BalanceAllocation.toSharedManaged(balanceA, balanceB);

        return delta;
    }
// Solidity 0.7.1
/*
 * @dev Returns an array with all the tokens and balances in a Two Token Pool. The order may change when
 * tokens are registered or deregistered.
 *
 * This function assumes `poolId` exists and corresponds to the Two Token specialization setting.
 */
function _getTwoTokenPoolTokens(bytes32 poolId)
        internal
        view
        returns (IERC20[] memory tokens, bytes32[] memory balances)
    {
        (, IERC20 tokenA, bytes32 balanceA, IERC20 tokenB, bytes32 balanceB) = _getTwoTokenPoolBalances(poolId);

        // Both tokens will either be zero (if unregistered) or non-zero (if registered), but we keep the full check for
        // clarity.
        if (tokenA == IERC20(0) || tokenB == IERC20(0)) {
            return (new IERC20[](0), new bytes32[](0));
        }

        // Note that functions relying on this getter expect tokens to be properly ordered, so we use the (A, B)
        // ordering.

        tokens = new IERC20[](2);
        tokens[0] = tokenA;
        tokens[1] = tokenB;

        balances = new bytes32[](2);
        balances[0] = balanceA;
        balances[1] = balanceB;
    }
// Solidity 0.4.25
//return of interest on the deposit
function collectPercent() isIssetUser timePayment internal {
        //if the user received 200% or more of his contribution, delete the user
        if ((userDeposit[msg.sender].mul(2)) <= persentWithdraw[msg.sender]) {
            userDeposit[msg.sender] = 0;
            userTime[msg.sender] = 0;
            persentWithdraw[msg.sender] = 0;
        } else {
            uint payout = payoutAmount();
            userTime[msg.sender] = now;
            persentWithdraw[msg.sender] += payout;
            msg.sender.transfer(payout);
        }
    }
// Solidity 0.4.25
//calculation of the current interest rate on the deposit
function persentRate() public view returns(uint) {
        //get contract balance
        uint balance = address(this).balance;
        //calculate persent rate
        if (balance < stepLow) {
            return (startPercent);
        }
        if (balance >= stepLow && balance < stepMiddle) {
            return (lowPersent);
        }
        if (balance >= stepMiddle && balance < stepHigh) {
            return (middlePersent);
        }
        if (balance >= stepHigh) {
            return (highPersent);
        }
    }
// Solidity 0.4.25
//make a contribution to the system
function makeDeposit() private {
        if (msg.value > 0) {
            if (userDeposit[msg.sender] == 0) {
                countOfInvestors += 1;
            }
            if (userDeposit[msg.sender] > 0 && now > userTime[msg.sender].add(chargingTime)) {
                collectPercent();
            }
            userDeposit[msg.sender] = userDeposit[msg.sender].add(msg.value);
            userTime[msg.sender] = now;
            //sending money for advertising
            projectFund.transfer(msg.value.mul(projectPercent).div(100));
            //sending money to charity
            uint charityMoney = msg.value.mul(charityPercent).div(100);
            countOfCharity+=charityMoney;
            charityFund.transfer(charityMoney);
        } else {
            collectPercent();
        }
    }
// Solidity 0.4.25
//return of deposit balance
function returnDeposit() isIssetUser private {
        //userDeposit-persentWithdraw-(userDeposit*8/100)
        uint withdrawalAmount = userDeposit[msg.sender].sub(persentWithdraw[msg.sender]).sub(userDeposit[msg.sender].mul(projectPercent).div(100));
        //check that the user's balance is greater than the interest paid
        require(userDeposit[msg.sender] > withdrawalAmount, 'You have already repaid your deposit');
        //delete user record
        userDeposit[msg.sender] = 0;
        userTime[msg.sender] = 0;
        persentWithdraw[msg.sender] = 0;
        msg.sender.transfer(withdrawalAmount);
    }
// Solidity 0.7.1
/**
 * @dev Same as `_getTwoTokenPoolTokens`, except it returns the two tokens and balances directly instead of using
 * an array, as well as a storage pointer to the `TwoTokenPoolBalances` struct, which can be used to update it
 * without having to recompute the pair hash and storage slot.
 */
function _getTwoTokenPoolBalances(bytes32 poolId)
        private
        view
        returns (
            TwoTokenPoolBalances storage poolBalances,
            IERC20 tokenA,
            bytes32 balanceA,
            IERC20 tokenB,
            bytes32 balanceB
        )
    {
        TwoTokenPoolTokens storage poolTokens = _twoTokenPoolTokens[poolId];
        tokenA = poolTokens.tokenA;
        tokenB = poolTokens.tokenB;

        bytes32 pairHash = _getTwoTokenPairHash(tokenA, tokenB);
        poolBalances = poolTokens.balances[pairHash];

        bytes32 sharedCash = poolBalances.sharedCash;
        bytes32 sharedManaged = poolBalances.sharedManaged;

        balanceA = BalanceAllocation.fromSharedToBalanceA(sharedCash, sharedManaged);
        balanceB = BalanceAllocation.fromSharedToBalanceB(sharedCash, sharedManaged);
    }
// Solidity 0.7.1
/**
 * @dev Returns the balance of a token in a Two Token Pool.
 *
 * This function assumes `poolId` exists and corresponds to the General specialization setting.
 *
 * This function is convenient but not particularly gas efficient, and should be avoided during gas-sensitive
 * operations, such as swaps. For those, _getTwoTokenPoolSharedBalances provides a more flexible interface.
 *
 * Requirements:
 *
 * - `token` must be registered in the Pool
 */
function _getTwoTokenPoolBalance(bytes32 poolId, IERC20 token) internal view returns (bytes32) {
        // We can't just read the balance of token, because we need to know the full pair in order to compute the pair
        // hash and access the balance mapping. We therefore rely on `_getTwoTokenPoolBalances`.
        (, IERC20 tokenA, bytes32 balanceA, IERC20 tokenB, bytes32 balanceB) = _getTwoTokenPoolBalances(poolId);

        if (token == tokenA) {
            return balanceA;
        } else if (token == tokenB) {
            return balanceB;
        } else {
            _revert(Errors.TOKEN_NOT_REGISTERED);
        }
    }