lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.18
/// @param _tulipId - Id of the tulip to auction.
/// @param _startingPrice - Starting price in wei.
/// @param _endingPrice - Ending price in wei.
/// @param _duration - Duration in seconds.
/// @param _seller - Seller address
function _createAuction(
        uint256 _tulipId,
        uint256 _startingPrice,
        uint256 _endingPrice,
        uint256 _duration,
        address _seller
    )
        internal
    {

        Auction memory auction = Auction(
            _seller,
            uint128(_startingPrice),
            uint128(_endingPrice),
            uint64(_duration),
            uint64(now)
        );

        tokenIdToAuction[_tulipId] = auction;

        AuctionCreated(
            uint256(_tulipId),
            uint256(auction.startingPrice),
            uint256(auction.endingPrice),
            uint256(auction.duration)
        );
    }
// Solidity 0.4.18
/*
 * @dev Cancel auction and return tulip to original owner.
 * @param _tulipId - ID of the tulip on auction
 */
function cancelAuction(uint256 _tulipId)
        external
    {
        Auction storage auction = tokenIdToAuction[_tulipId];
        require(auction.startedAt > 0);

        // Only seller can call this function
        address seller = auction.seller;
        require(msg.sender == seller);

        // Return the tulip to the owner
        coreContract.transfer(seller, _tulipId);

        // Remove auction from storage
        delete tokenIdToAuction[_tulipId];

        AuctionCancelled(_tulipId);
    }
// Solidity 0.8.7
/// @dev Moves `value` AnyswapV3ERC20 token from caller's account to account (`to`).
/// A transfer to `address(0)` triggers an ETH withdraw matching the sent AnyswapV3ERC20 token in favor of caller.
/// Emits {Transfer} event.
/// Returns boolean value indicating whether operation succeeded.
/// Requirements:
///   - caller account must have at least `value` AnyswapV3ERC20 token.
function transfer(address to, uint256 value) external override returns (bool) {
        require(to != address(0) || to != address(this));
        uint256 balance = balanceOf[msg.sender];
        require(balance >= value, "AnyswapV3ERC20: transfer amount exceeds balance");

        balanceOf[msg.sender] = balance - value;
        balanceOf[to] += value;
        emit Transfer(msg.sender, to, value);

        return true;
    }
// Solidity 0.8.7
/// @dev Moves `value` AnyswapV3ERC20 token from account (`from`) to account (`to`) using allowance mechanism.
/// `value` is then deducted from caller account's allowance, unless set to `type(uint256).max`.
/// A transfer to `address(0)` triggers an ETH withdraw matching the sent AnyswapV3ERC20 token in favor of caller.
/// Emits {Approval} event to reflect reduced allowance `value` for caller account to spend from account (`from`),
/// unless allowance is set to `type(uint256).max`
/// Emits {Transfer} event.
/// Returns boolean value indicating whether operation succeeded.
/// Requirements:
///   - `from` account must have at least `value` balance of AnyswapV3ERC20 token.
///   - `from` account must have approved caller to spend at least `value` of AnyswapV3ERC20 token, unless `from` and caller are the same account.
function transferFrom(address from, address to, uint256 value) external override returns (bool) {
        require(to != address(0) || to != address(this));
        if (from != msg.sender) {
            // _decreaseAllowance(from, msg.sender, value);
            uint256 allowed = allowance[from][msg.sender];
            if (allowed != type(uint256).max) {
                require(allowed >= value, "AnyswapV3ERC20: request exceeds allowance");
                uint256 reduced = allowed - value;
                allowance[from][msg.sender] = reduced;
                emit Approval(from, msg.sender, reduced);
            }
        }

        uint256 balance = balanceOf[from];
        require(balance >= value, "AnyswapV3ERC20: transfer amount exceeds balance");

        balanceOf[from] = balance - value;
        balanceOf[to] += value;
        emit Transfer(from, to, value);

        return true;
    }
// Solidity 0.8.7
/// @dev Moves `value` AnyswapV3ERC20 token from caller's account to account (`to`),
/// after which a call is executed to an ERC677-compliant contract with the `data` parameter.
/// A transfer to `address(0)` triggers an ETH withdraw matching the sent AnyswapV3ERC20 token in favor of caller.
/// Emits {Transfer} event.
/// Returns boolean value indicating whether operation succeeded.
/// Requirements:
///   - caller account must have at least `value` AnyswapV3ERC20 token.
/// For more information on transferAndCall format, see https://github.com/ethereum/EIPs/issues/677.
function transferAndCall(address to, uint value, bytes calldata data) external override returns (bool) {
        require(to != address(0) || to != address(this));

        uint256 balance = balanceOf[msg.sender];
        require(balance >= value, "AnyswapV3ERC20: transfer amount exceeds balance");

        balanceOf[msg.sender] = balance - value;
        balanceOf[to] += value;
        emit Transfer(msg.sender, to, value);

        return ITransferReceiver(to).onTokenTransfer(msg.sender, value, data);
    }
// Solidity 0.4.19
//human 0.1 standard. Just an arbitrary versioning scheme.
//
//
//function name must match the contract name above
function GhostGold(
        ) {
        balances[msg.sender] = 1000000;               // Give the creator all initial tokens
        totalSupply = 1000000;                        // Update total supply
        name = "GhostGold";                           // Set the name for display purposes
        decimals = 0;                                 // Amount of decimals for display purposes
        symbol = "GXG";                               // Set the symbol for display purposes
    }
// Solidity 0.6.11
/*
 * creates a montage of the given token ids
 */
function createMontage(
        address creator,
        string memory _name,
        string memory _description,
        bool _canBeUnpacked,
        uint256[] memory _tokenIds
    ) external onlyOwner returns (uint256) {
        // create the montage object
        MontageData memory _montage = MontageData(creator, _name, _description, _canBeUnpacked, _tokenIds, "", "");

        // push the montage to the array
        montageDatas.push(_montage);
        uint256 _id = montageDatas.length - 1;
        return _id;
    }
// Solidity 0.8.11
/**
 * @dev Calculates a EIP712 domain separator.
 * @param name The EIP712 domain name.
 * @param version The EIP712 domain version.
 * @param verifyingContract The EIP712 verifying contract.
 * @return result EIP712 domain separator.
 */
function hashDomainSeperator(
        string memory name,
        string memory version,
        address verifyingContract
    ) internal view returns (bytes32 result) {
        bytes32 typehash = EIP712DOMAIN_TYPEHASH;

        // solhint-disable-next-line no-inline-assembly
        assembly {
            let nameHash := keccak256(add(name, 32), mload(name))
            let versionHash := keccak256(add(version, 32), mload(version))
            let chainId := chainid()

            let memPtr := mload(64)

            mstore(memPtr, typehash)
            mstore(add(memPtr, 32), nameHash)
            mstore(add(memPtr, 64), versionHash)
            mstore(add(memPtr, 96), chainId)
            mstore(add(memPtr, 128), verifyingContract)

            result := keccak256(memPtr, 160)
        }
    }
// Solidity 0.8.11
/**
 * @dev Calculates EIP712 encoding for a hash struct with a given domain hash.
 * @param domainHash Hash of the domain domain separator data, computed with getDomainHash().
 * @param hashStruct The EIP712 hash struct.
 * @return result EIP712 hash applied to the given EIP712 Domain.
 */
function hashMessage(bytes32 domainHash, bytes32 hashStruct) internal pure returns (bytes32 result) {
        // solhint-disable-next-line no-inline-assembly
        assembly {
            let memPtr := mload(64)

            mstore(memPtr, 0x1901000000000000000000000000000000000000000000000000000000000000) // EIP191 header
            mstore(add(memPtr, 2), domainHash) // EIP712 domain hash
            mstore(add(memPtr, 34), hashStruct) // Hash of struct

            result := keccak256(memPtr, 66)
        }
    }
// Solidity 0.6.11
/**
 * @notice Get the full contents of the montage (i.e. name and tokeids) for a given token ID.
 * @param tokenId the id of a previously minted montage
 */
function getMontageInformation(uint256 tokenId)
        public
        view
        onlyExistingTokens(tokenId)
        returns (
            address creator,
            string memory name,
            string memory description,
            bool canBeUnpacked,
            uint256[] memory tokenIds
        )
    {
        MontageData memory _montage = montageDatas[tokenId];
        tokenIds = _montage.tokenIds;
        name = _montage.name;
        description = _montage.description;
        canBeUnpacked = _montage.canBeUnpacked;
        creator = _montage.creator;
    }
// Solidity 0.7.0
/**
 * @dev Withdraw User Balance to user account, only Governance call it
 */
function userWithdraw(address withdrawAddress, uint256 amount)
        public
        payable
        onlyGovernance
    {
        require(
            _totalAmount >= amount,
            "User Balance should be more than withdraw amount."
        );

        // Send ETH From Contract to User Address
        (bool sent, ) = withdrawAddress.call{value: amount}("");
        require(sent, "Failed to Withdraw User.");

        // Update Total Balance
        _totalAmount = _totalAmount.sub(amount);
    }
// Solidity 0.7.0
/**
 * @dev EmergencyWithdraw when need to update contract and then will restore it
 */
function emergencyWithdraw() public payable onlyGovernance {
        require(_totalAmount > 0, "Can't send over total ETH amount.");

        uint256 amount = _totalAmount;
        address governanceAddress = governance();

        // Send ETH From Contract to Governance Address
        (bool sent, ) = governanceAddress.call{value: amount}("");
        require(sent, "Failed to Withdraw Governance");

        // Update Total Balance
        _totalAmount = 0;
    }
// Solidity 0.8.11
/**
 * @notice Verify a signed approval permit and execute if valid
 * @param owner     Token owner's address (Authorizer)
 * @param spender   Spender's address
 * @param value     Amount of allowance
 * @param deadline  The time at which this expires (unix time)
 * @param v         v of the signature
 * @param r         r of the signature
 * @param s         s of the signature
 */
function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external virtual {
        require(owner != address(0), "ERC2612/Invalid-address-0");
        require(deadline >= block.timestamp, "ERC2612/Expired-time");

        unchecked {
            bytes32 digest = EIP712.hashMessage(
                DOMAIN_SEPARATOR,
                keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
            );

            address recovered = ecrecover(digest, v, r, s);
            require(recovered != address(0) && recovered == owner, "ERC2612/Invalid-Signature");
        }

        _approve(owner, spender, value);
    }
// Solidity 0.4.13
/// @dev Tranfer tokens from one address to other
/// @param _from source address
/// @param _to dest address
/// @param _value tokens amount
/// @return transfer result
function transferFrom(address _from, address _to, uint _value) onlyPayloadSize(2 * 32) canTransfer checkFrozenAmount(_from, _value) returns (bool success) {
    var _allowance = allowed[_from][msg.sender];

    balances[_to] = safeAdd(balances[_to], _value);
    balances[_from] = safeSub(balances[_from], _value);
    allowed[_from][msg.sender] = safeSub(_allowance, _value);
    Transfer(_from, _to, _value);
    return true;
 }
// Solidity 0.4.13
/// @dev Approve transfer
/// @param _spender holder address
/// @param _value tokens amount
/// @return result
function approve(address _spender, uint _value) returns (bool success) {
   // To change the approve amount you first have to reduce the addresses`
   //  allowance to zero by calling `approve(_spender, 0)` if it is not
   //  already 0 to mitigate the race condition described here:
   //  https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
   require ((_value == 0) || (allowed[msg.sender][_spender] == 0));

   allowed[msg.sender][_spender] = _value;
   Approval(msg.sender, _spender, _value);
   return true;
 }
// Solidity 0.4.13
/// @dev Constructor
/// @param _token Pay Fair token address
/// @param _multisigWallet team wallet
/// @param _start token ICO start date
function PayFairTokenCrowdsale(address _token, address _multisigWallet, uint _start) {
    require(_multisigWallet != 0);
    require(_start != 0);

    token = PayFairToken(_token);

    multisigWallet = _multisigWallet;
    startsAt = _start;

    milestones.push(Milestone(startsAt, startsAt + 1 days, 20));
    milestones.push(Milestone(startsAt + 1 days, startsAt + 5 days, 15));
    milestones.push(Milestone(startsAt + 5 days, startsAt + 10 days, 10));
    milestones.push(Milestone(startsAt + 10 days, startsAt + 20 days, 5));
  }
// Solidity 0.4.13
/// @dev Get the current milestone or bail out if we are not in the milestone periods.
/// @return Milestone current bonus milestone
function getCurrentMilestone() private constant returns (Milestone) {
    for (uint i = 0; i < milestones.length; i++) {
      if (milestones[i].start <= now && milestones[i].end > now) {
        return milestones[i];
      }
   }
 }
// Solidity 0.4.13
/// @dev Make an investment. Crowdsale must be running for one to invest.
/// @param receiver The Ethereum address who receives the tokens
function investInternal(address receiver) stopInEmergency private {
    var state = getState();
    require(state == State.Funding);
    require(msg.value > 0);

    // Add investment record
    var weiAmount = msg.value;
    investments.push(Investment(receiver, weiAmount, getCurrentMilestone().bonus + 100));
    investedAmountOf[receiver] = safeAdd(investedAmountOf[receiver], weiAmount);

    // Update totals
    weiRaised = safeAdd(weiRaised, weiAmount);
    // Transfer funds to the team wallet
    multisigWallet.transfer(weiAmount);
    // Tell us invest was success
    Invested(receiver, weiAmount);
  }
// Solidity 0.4.13
/// @dev Finalize a succcesful crowdsale.
function finalizeCrowdsale() internal {
    // Calculate divisor of the total token count
    uint divisor;
    for (uint i = 0; i < investments.length; i++)
       divisor = safeAdd(divisor, safeMul(investments[i].weiValue, investments[i].weight));

    uint localMultiplier = 10 ** 12;
    // Get unit price
    uint unitPrice = safeDiv(safeMul(token.convertToDecimal(TOTAL_ICO_TOKENS), localMultiplier), divisor);

    // Distribute tokens among investors
    for (i = 0; i < investments.length; i++) {
        var tokenAmount = safeDiv(safeMul(unitPrice, safeMul(investments[i].weiValue, investments[i].weight)), localMultiplier);
        tokenAmountOf[investments[i].source] += tokenAmount;
        assignTokens(investments[i].source, tokenAmount);
    }

    token.releaseTokenTransfer();
  }
// Solidity 0.4.13
/// @dev Crowdfund state machine management.
/// @return State current state
function getState() public constant returns (State) {
    if (finalized)
      return State.Finalized;
    if (address(token) == 0 || address(multisigWallet) == 0)
      return State.Preparing;
    if (preIcoTokensDistributed < token.convertToDecimal(PRE_ICO_MAX_TOKENS))
        return State.PreFunding;
    if (now >= startsAt && now < startsAt + ICO_DURATION && !isCrowdsaleFull())
      return State.Funding;
    if (isMinimumGoalReached())
      return State.Success;
    if (!isMinimumGoalReached() && weiRaised > 0 && loadedRefund >= weiRaised)
      return State.Refunding;
    return State.Failure;
  }
// Solidity 0.8.0
/**
 * @dev Will deploy a balancer LBP. Can only be called by DAO.agent address
 * @notice This function requires that the DAO.agent has approved this address for spending pool tokens (e.g. POP & USDC). It will revert if the DAO.agent has not approved this contract for spending those tokens. The PoolConfiguration.tokenAmounts for the pool tokens will be transferred from the DAO.agent to this contract and forwarded to the LBP
 */
function deployLBP() external {
    require(msg.sender == dao.agent, "Only DAO can call this");
    require(poolConfig.deployed != true, "The pool has already been deployed");
    require(_hasTokensForPool(), "Manager does not have enough pool tokens");

    poolConfig.deployed = true;

    lbp = ILBP(
      balancer.lbpFactory.create(
        poolConfig.name,
        poolConfig.symbol,
        poolConfig.tokens,
        poolConfig.startWeights,
        poolConfig.swapFee,
        poolConfig.owner,
        poolConfig.swapEnabledOnStart
      )
    );

    emit CreatedPool(address(lbp));

    uint256 endtime = poolConfig.startTime + poolConfig.durationInSeconds;

    lbp.updateWeightsGradually(poolConfig.startTime, endtime, poolConfig.endWeights);

    _joinPool();
  }
// Solidity 0.8.0
/**
 * @notice The DAO.agent can call this function to shutdown and unwind the pool. The proceeds will be forwarded to the DAO.treasury
 */
function withdrawFromPool() external {
    require(poolConfig.deployed, "Pool has not been deployed yet");
    require(msg.sender == dao.agent, "not today, buddy");

    bytes32 poolId = lbp.getPoolId();

    uint256[] memory minAmountsOut = new uint256[](poolConfig.tokens.length);
    for (uint256 i; i < poolConfig.tokens.length; i++) {
      minAmountsOut[i] = uint256(0);
    }

    lbp.setSwapEnabled(false);

    ExitPoolRequest memory request = ExitPoolRequest({
      assets: _convertERC20sToAssets(poolConfig.tokens),
      minAmountsOut: minAmountsOut,
      userData: abi.encode(uint256(WeightedPoolExitKind.EXACT_BPT_IN_FOR_TOKENS_OUT), _getLPTokenBalance(poolId)),
      toInternalBalance: false
    });

    balancer.vault.exitPool(poolId, address(this), dao.treasury, request);
    emit ExitedPool(poolId);
  }
// Solidity 0.4.21
/**
 * @dev check contribution amount and time
 */
function isValidContribution() internal view returns(bool) {
        uint256 currentUserContribution = safeAdd(msg.value, userTotalContributed[msg.sender]);
        if(whiteList[msg.sender] && msg.value >= ETHER_MIN_CONTRIB) {
            if(now <= MAX_CONTRIB_CHECK_END_TIME && currentUserContribution > ETHER_MAX_CONTRIB ) {
                    return false;
            }
            return true;

        }
        if(privilegedList[msg.sender] && msg.value >= ETHER_MIN_CONTRIB_PRIVATE) {
            if(now <= MAX_CONTRIB_CHECK_END_TIME && currentUserContribution > ETHER_MAX_CONTRIB_PRIVATE ) {
                    return false;
            }
            return true;
        }

        if(token.limitedWallets(msg.sender) && msg.value >= ETHER_MIN_CONTRIB_USA) {
            if(now <= MAX_CONTRIB_CHECK_END_TIME && currentUserContribution > ETHER_MAX_CONTRIB_USA) {
                    return false;
            }
            return true;
        }

        return false;
    }
// Solidity 0.4.21
/**
 * @dev Check bnb contribution time, amount and hard cap overflow
 */
function isValidBNBContribution() internal view returns(bool) {
        if(token.limitedWallets(msg.sender)) {
            return false;
        }
        if(!whiteList[msg.sender] && !privilegedList[msg.sender]) {
            return false;
        }
        uint256 amount = bnbToken.allowance(msg.sender, address(this));
        if(amount < BNB_MIN_CONTRIB || safeAdd(totalBNBContributed, amount) > BNB_HARD_CAP) {
            return false;
        }
        return true;

    }
// Solidity 0.4.21
/**
 * @dev Calc bonus amount by contribution time
 */
function getBonus() internal constant returns (uint256, uint256) {
        uint256 numerator = 0;
        uint256 denominator = 100;

        if(now < BONUS_WINDOW_1_END_TIME) {
            numerator = 25;
        } else if(now < BONUS_WINDOW_2_END_TIME) {
            numerator = 15;
        } else if(now < BONUS_WINDOW_3_END_TIME) {
            numerator = 10;
        } else if(now < BONUS_WINDOW_4_END_TIME) {
            numerator = 5;
        } else {
            numerator = 0;
        }

        return (numerator, denominator);
    }
// Solidity 0.4.21
/**
 * @dev Process BNB token contribution
 * Transfer all amount of tokens approved by sender. Calc bonuses and issue tokens to contributor.
 */
function processBNBContribution() public whenNotPaused checkTime checkBNBContribution {
        bool additionalBonusApplied = false;
        uint256 bonusNum = 0;
        uint256 bonusDenom = 100;
        (bonusNum, bonusDenom) = getBonus();
        uint256 amountBNB = bnbToken.allowance(msg.sender, address(this));
        bnbToken.transferFrom(msg.sender, address(this), amountBNB);
        bnbContributions[msg.sender] = safeAdd(bnbContributions[msg.sender], amountBNB);

        uint256 tokenBonusAmount = 0;
        uint256 tokenAmount = safeDiv(safeMul(amountBNB, BNB_TOKEN_PRICE_NUM), BNB_TOKEN_PRICE_DENOM);
        rawTokenSupply = safeAdd(rawTokenSupply, tokenAmount);
        if(bonusNum > 0) {
            tokenBonusAmount = safeDiv(safeMul(tokenAmount, bonusNum), bonusDenom);
        }

        if(additionalBonusOwnerState[msg.sender] ==  AdditionalBonusState.Active) {
            additionalBonusOwnerState[msg.sender] = AdditionalBonusState.Applied;
            uint256 additionalBonus = safeDiv(safeMul(tokenAmount, ADDITIONAL_BONUS_NUM), ADDITIONAL_BONUS_DENOM);
            tokenBonusAmount = safeAdd(tokenBonusAmount, additionalBonus);
            additionalBonusApplied = true;
        }

        uint256 tokenTotalAmount = safeAdd(tokenAmount, tokenBonusAmount);
        token.issue(msg.sender, tokenTotalAmount);
        totalBNBContributed = safeAdd(totalBNBContributed, amountBNB);

        LogBNBContribution(msg.sender, amountBNB, tokenAmount, tokenBonusAmount, additionalBonusApplied, now);
    }
// Solidity 0.4.21
/**
 * @dev Process ether contribution. Calc bonuses and issue tokens to contributor.
 */
function processContribution(address contributor, uint256 amount) private checkTime checkContribution checkCap {
        bool additionalBonusApplied = false;
        uint256 bonusNum = 0;
        uint256 bonusDenom = 100;
        (bonusNum, bonusDenom) = getBonus();
        uint256 tokenBonusAmount = 0;

        uint256 tokenAmount = safeDiv(safeMul(amount, tokenPriceNum), tokenPriceDenom);
        rawTokenSupply = safeAdd(rawTokenSupply, tokenAmount);

        if(bonusNum > 0) {
            tokenBonusAmount = safeDiv(safeMul(tokenAmount, bonusNum), bonusDenom);
        }

        if(additionalBonusOwnerState[contributor] ==  AdditionalBonusState.Active) {
            additionalBonusOwnerState[contributor] = AdditionalBonusState.Applied;
            uint256 additionalBonus = safeDiv(safeMul(tokenAmount, ADDITIONAL_BONUS_NUM), ADDITIONAL_BONUS_DENOM);
            tokenBonusAmount = safeAdd(tokenBonusAmount, additionalBonus);
            additionalBonusApplied = true;
        }

        processPayment(contributor, amount, tokenAmount, tokenBonusAmount, additionalBonusApplied);
    }