lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.15
// *
// Buy token by sending ether here
//
// You can also send the ether directly to the contract address
function buy() payable {
        if (msg.value == 0) {
            revert();
        }

        // prevent from buying before starting preico or ico
        if (!isPreICOPrivateOpened && !isPreICOPublicOpened && !isICOOpened) {
            revert();
        }

        if (isICOClosed) {
            revert();
        }

        // Deciding how many tokens can be bought with the ether received
        uint tokens = getSMPTokensAmountPerEthInternal(msg.value);

        // Just in case
        if (tokens > balances[ICO_ADDRESS]) { 
            revert();
        }

        // Transfer from the ICO pool
        balances[ICO_ADDRESS] = balances[ICO_ADDRESS].sub(tokens); // if not enough, will revert()
        balances[msg.sender] = balances[msg.sender].add(tokens);

        // Broadcasting the buying event
        SMPAcquired(msg.sender, msg.value, tokens);
    }
// Solidity 0.4.15
// *
// Some percentage of the tokens is already reserved for marketing
function distributeMarketingShares() onlyOwner {
        // Making it impossible to call this function twice
        if (preMarketingSharesDistributed) {
            revert();
        }

        preMarketingSharesDistributed = true;

        // Values are in WEI tokens
        balances[0xAc5C2414dae4ADB07D82d40dE71B4Bc5E2b417fd] = 100000000 * WEI; // referral
        balances[0x603D3e11E88dD9aDdc4D9AbE205C7C02e9e13483] = 20000000 * WEI; // social marketing
        
        current_supply = (100000000 + 20000000) * WEI;

        // Sending the rest to ICO pool
        balances[ICO_ADDRESS] = INITIAL_SUPPLY.sub(current_supply);

        // Initializing the supply variables
        ico_starting_supply = balances[ICO_ADDRESS];
        current_supply = INITIAL_SUPPLY;
        SupplyChanged(0, current_supply);
    }
// Solidity 0.8.7
/*Function to mint token with 0 ETH price utpo 499*/
function FreeMint() external reentryLock {
        require(mintActive, "Mint is not Active");
        require(freeMinted < 250, "Free Mints Sold Out");
        require(numberMinted < totalTokens, "Collection Sold Out");

        uint256 mintSeedValue = numberMinted;
        numberMinted += 1;
        freeMinted += 1;

        _safeMint(_msgSender(), mintSeedValue );
    }
// Solidity 0.8.7
/* 0.015 for everyone */
function publicMint(uint256 qty) external payable reentryLock {
        require(totalTokens >= qty + numberMinted, "sold out");
        require(qty <= maxPerTxn, "max 50 per txn");
        require(mintActive, "Mint is not Active");
        require(msg.value == qty * price, "Wrong Eth Amount");
        
        uint256 mintSeedValue = numberMinted;
        numberMinted += qty;
        
        for(uint256 i = 0; i < qty; i++) {
            _safeMint(_msgSender(), mintSeedValue + i);
        }
       
    }
// Solidity 0.4.24
/**
 @notice Sets erc20 globals and fee paramters
 @param _name Full token name  'USD by token.io'
 @param _symbol Symbol name 'USDx'
 @param _tla Three letter abbreviation 'USD'
 @param _version Release version 'v0.0.1'
 @param _decimals Decimal precision
 @param _feeContract Address of fee contract
 @return { "success" : "Returns true if successfully called from another contract"}
 */
function setParams(
    string _name,
    string _symbol,
    string _tla,
    string _version,
    uint _decimals,
    address _feeContract,
    uint _fxUSDBPSRate
    ) onlyOwner public returns (bool success) {
      require(lib.setTokenName(_name),
        "Error: Unable to set token name. Please check arguments.");
      require(lib.setTokenSymbol(_symbol),
        "Error: Unable to set token symbol. Please check arguments.");
      require(lib.setTokenTLA(_tla),
        "Error: Unable to set token TLA. Please check arguments.");
      require(lib.setTokenVersion(_version),
        "Error: Unable to set token version. Please check arguments.");
      require(lib.setTokenDecimals(_symbol, _decimals),
        "Error: Unable to set token decimals. Please check arguments.");
      require(lib.setFeeContract(_feeContract),
        "Error: Unable to set fee contract. Please check arguments.");
      require(lib.setFxUSDBPSRate(_symbol, _fxUSDBPSRate),
        "Error: Unable to set fx USD basis points rate. Please check arguments.");
      return true;
    }
// Solidity 0.4.24
/**
 * @notice Gets fee parameters
 * @return {
 "bps":"Fee amount as a mesuare of basis points",
 "min":"Minimum fee amount",
 "max":"Maximum fee amount",
 "flat":"Flat fee amount",
 "contract":"Address of fee contract"
 }
 */
function getFeeParams() public view returns (uint bps, uint min, uint max, uint flat, bytes feeMsg, address feeAccount) {
      address feeContract = lib.getFeeContract(address(this));
      return (
        lib.getFeeBPS(feeContract),
        lib.getFeeMin(feeContract),
        lib.getFeeMax(feeContract),
        lib.getFeeFlat(feeContract),
        lib.getFeeMsg(feeContract),
        feeContract
      );
    }
// Solidity 0.4.24
/**
 * @notice transfers 'amount' from msg.sender to a receiving account 'to'
 * @param to Receiving address
 * @param amount Transfer amount
 * @return {"success" : "Returns true if transfer succeeds"}
 */
function transfer(address to, uint amount) public notDeprecated returns (bool success) {
      address feeContract = lib.getFeeContract(address(this));
      string memory currency = lib.getTokenSymbol(address(this));
      uint fees = calculateFees(amount);

      bytes32 id_a = keccak256(abi.encodePacked('token.balance', currency, lib.getForwardedAccount(msg.sender)));
      bytes32 id_b = keccak256(abi.encodePacked('token.balance', currency, lib.getForwardedAccount(to)));
      bytes32 id_c = keccak256(abi.encodePacked('token.balance', currency, lib.getForwardedAccount(feeContract)));

      require(
        lib.Storage.setUint(id_a, lib.Storage.getUint(id_a).sub(amount.add(fees))),
        "Error: Unable to set storage value. Please ensure contract has allowed permissions with storage contract."
      );

      require(
        lib.Storage.setUint(id_b, lib.Storage.getUint(id_b).add(amount)),
        "Error: Unable to set storage value. Please ensure contract has allowed permissions with storage contract."
      );

      require(
        lib.Storage.setUint(id_c, lib.Storage.getUint(id_c).add(fees)),
        "Error: Unable to set storage value. Please ensure contract has allowed permissions with storage contract."
      );

      emit Transfer(msg.sender, to, amount);

      return true;
    }
// Solidity 0.4.24
/**
 * @notice spender transfers from approvers account to the reciving account
 * @param from Approver's address
 * @param to Receiving address
 * @param amount Transfer amount
 * @return {"success" : "Returns true if transferFrom succeeds"}
 */
function transferFrom(address from, address to, uint amount) public notDeprecated returns (bool success) {
      address feeContract = lib.getFeeContract(address(this));
      string memory currency = lib.getTokenSymbol(address(this));
      uint fees = calculateFees(amount);

      bytes32 id_a = keccak256(abi.encodePacked('token.balance', currency, lib.getForwardedAccount(from)));
      bytes32 id_b = keccak256(abi.encodePacked('token.balance', currency, lib.getForwardedAccount(to)));
      bytes32 id_c = keccak256(abi.encodePacked('token.balance', currency, lib.getForwardedAccount(feeContract)));

      require(
        lib.Storage.setUint(id_a, lib.Storage.getUint(id_a).sub(amount.add(fees))),
        "Error: Unable to set storage value. Please ensure contract has allowed permissions with storage contract."
      );

      require(
        lib.Storage.setUint(id_b, lib.Storage.getUint(id_b).add(amount)),
        "Error: Unable to set storage value. Please ensure contract has allowed permissions with storage contract."
      );

      require(
        lib.Storage.setUint(id_c, lib.Storage.getUint(id_c).add(fees)),
        "Error: Unable to set storage value. Please ensure contract has allowed permissions with storage contract."
      );

      /// @notice This transaction will fail if the msg.sender does not have an approved allowance.
      require(
        lib.updateAllowance(lib.getTokenSymbol(address(this)), from, amount.add(fees)),
        "Error: Unable to update allowance for spender."
      );

      emit Transfer(from, to, amount);
      return true;
    }
// Solidity 0.4.24
/**
 * @notice approves spender a given amount
 * @param spender Spender's address
 * @param amount Allowance amount
 * @return {"success" : "Returns true if approve succeeds"}
 */
function approve(address spender, uint amount) public notDeprecated returns (bool success) {
      /// @notice sends approve through library
      /// @dev !!! mtuates storage states
      require(
        lib.approveAllowance(spender, amount),
        "Error: Unable to approve allowance for spender. Please ensure spender is not null and does not have a frozen balance."
      );
      return true;
    }
// Solidity 0.4.21
// 1 million STO tokens
function StoToken(address _owner, address initialAccount) public {
        require(_owner != address(0) && initialAccount != address(0) && _owner != initialAccount);
        owner = _owner;
        balances[initialAccount] = INITIAL_BALANCE;
        totalSupply_ = INITIAL_BALANCE;
        emit Transfer(address(0), initialAccount, INITIAL_BALANCE);
    }
// Solidity 0.7.0
/// @param f The float value with 5 bits for the exponent
/// @param numBits The total number of bits (numBitsMantissa := numBits - numBitsExponent)
/// @return value The decoded integer value.
function decodeFloat(
        uint f,
        uint numBits
        )
        internal
        pure
        returns (uint96 value)
    {
        uint numBitsMantissa = numBits.sub(5);
        uint exponent = f >> numBitsMantissa;
        // log2(10**77) = 255.79 < 256
        require(exponent <= 77, "EXPONENT_TOO_LARGE");
        uint mantissa = f & ((1 << numBitsMantissa) - 1);
        value = mantissa.mul(10 ** exponent).toUint96();
    }
// Solidity 0.8.2
// *************
// BOT FUNCTIONS
// *************
function fulfillOrder(address _user, uint256 _artBlocksProjectId, uint256 _tokenId, uint256 _expectedPriceInWeiEach, address _profitTo, bool _sendNow) public returns (uint256) {
		// CHECKS
		Order memory order = orders[_user][_artBlocksProjectId];
		require(order.quantity > 0, 'user order DNE');
		require(order.priceInWeiEach >= _expectedPriceInWeiEach, 'user offer insufficient'); // protects bots from users frontrunning them
		require(ARTBLOCKS_FACTORY.tokenIdToProjectId(_tokenId) == _artBlocksProjectId, 'user did not request this NFT');

		// EFFECTS
		Order memory newOrder;
		if (order.quantity > 1) {
			newOrder.priceInWeiEach = order.priceInWeiEach;
			newOrder.quantity = order.quantity - 1;
		}
		orders[_user][_artBlocksProjectId] = newOrder;

		uint256 artBlocksBrokerFee = order.priceInWeiEach * artBlocksBrokerFeeBips / 10_000;
		balances[profitReceiver] += artBlocksBrokerFee;

		// INTERACTIONS
		// transfer NFT to user
		ARTBLOCKS_FACTORY.safeTransferFrom(msg.sender, _user, _tokenId); // reverts on failure

		// pay the fullfiller
		if (_sendNow) {
			sendValue(payable(_profitTo), order.priceInWeiEach - artBlocksBrokerFee);
		} else {
			balances[_profitTo] += order.priceInWeiEach - artBlocksBrokerFee;
		}

		emit Action(_user, _artBlocksProjectId, newOrder.priceInWeiEach, newOrder.quantity, 'order fulfilled', _tokenId);

		return order.priceInWeiEach - artBlocksBrokerFee; // proceeds to order fullfiller
	}
// Solidity 0.8.2
// ****************
// HELPER FUNCTIONS
// ****************
// OpenZeppelin's sendValue function, used for transfering ETH out of this contract
function sendValue(address payable recipient, uint256 amount) internal {
		require(address(this).balance >= amount, "Address: insufficient balance");
		// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
		(bool success, ) = recipient.call{ value: amount }("");
		require(success, "Address: unable to send value, recipient may have reverted");
	}
// Solidity 0.7.6
/* ========== ONLY OPERATOR ========== */
function setCoreParams(
        bool _canDeposit,
        uint256 _withdrawFee,
        uint256 _reinvestMin0,
        uint256 _reinvestMin1
    ) external onlyOperator {
        require(_withdrawFee == 0 || _withdrawFee >= 4, "invalid fee param");
        canDeposit = _canDeposit;
        withdrawFee = _withdrawFee;
        reinvestMin0 = _reinvestMin0;
        reinvestMin1 = _reinvestMin1;
    }
// Solidity 0.5.17
// _time : 0 ~ 24
function teamIssue(address _to, uint _time) onlyOwner public
    {
        require(saleTime == false);
        require( _time < teamVestingTime);
        
        uint nowTime = now;
        require( nowTime > tmVestingTimer[_time] );
        
        uint tokens = teamVestingSupply;

        require(tokens == tmVestingBalances[_time]);
        require(maxTeamSupply >= tokenIssuedTeam.add(tokens));
        
        balances[_to] = balances[_to].add(tokens);
        tmVestingBalances[_time] = 0;
        
        totalTokenSupply = totalTokenSupply.add(tokens);
        tokenIssuedTeam = tokenIssuedTeam.add(tokens);
        
        emit TeamIssue(_to, tokens);
    }
// Solidity 0.5.17
// _time : 0 ~ 4
function advisorIssue(address _to, uint _time) onlyOwner public
    {
        require(saleTime == false);
        require( _time < advisorVestingTime);
        
        uint nowTime = now;
        require( nowTime > advVestingTimer[_time] );
        
        uint tokens = advisorVestingSupply;

        require(tokens == advVestingBalances[_time]);
        require(maxAdvisorSupply >= tokenIssuedAdv.add(tokens));
        
        balances[_to] = balances[_to].add(tokens);
        advVestingBalances[_time] = 0;
        
        totalTokenSupply = totalTokenSupply.add(tokens);
        tokenIssuedAdv = tokenIssuedAdv.add(tokens);
        
        emit AdvIssue(_to, tokens);
    }
// Solidity 0.4.24
/**
 * @notice Tells whether a signature is seen as valid by this contract through ERC-1271
 * @param _hash Arbitrary length data signed on the behalf of address (this)
 * @param _signature Signature byte array associated with _data
 * @return The ERC-1271 magic value if the signature is valid
 */
function isValidSignature(bytes32 _hash, bytes _signature) public view returns (bytes4) {
        // Short-circuit in case the hash was presigned. Optimization as performing calls
        // and ecrecover is more expensive than an SLOAD.
        if (isPresigned[_hash]) {
            return returnIsValidSignatureMagicNumber(true);
        }

        bool isValid;
        if (designatedSigner == address(0)) {
            isValid = false;
        } else {
            isValid = SignatureValidator.isValidSignature(_hash, designatedSigner, _signature);
        }

        return returnIsValidSignatureMagicNumber(isValid);
    }
// Solidity 0.6.11
/**
 * @notice Create a new stake at latest confirmed node
 * @param stakerAddress Address of the new staker
 * @param depositAmount Stake amount of the new staker
 */
function createNewStake(address payable stakerAddress, uint256 depositAmount) internal {
        uint256 stakerIndex = _stakerList.length;
        _stakerList.push(stakerAddress);
        _stakerMap[stakerAddress] = Staker(
            stakerIndex,
            _latestConfirmed,
            depositAmount,
            address(0), // new staker is not in challenge
            true
        );
        _lastStakeBlock = block.number;
        emit UserStakeUpdated(stakerAddress, 0, depositAmount);
    }
// Solidity 0.8.9
/**
 * @dev Returns the time rewards were last claimed
 * @param _tokenId The token to reference
 * @param chainsContract The chains token contract
 */
function __lastClaim(uint256 _tokenId, IChains chainsContract) internal view returns (uint256) {

        require(chainsContract.ownerOf(_tokenId) != address(0),"TOKEN_NOT_MINTED");

        uint256 lastClaimed = _lastClaim[_tokenId];

        if(lastClaimed == 0 || lastClaimed < _emissionStart){

            uint256 mintedAt = chainsContract.getTokenTimestamp(_tokenId);

            if(mintedAt<_emissionStart){
                lastClaimed = _emissionStart;
            }else{
                lastClaimed = mintedAt;
            }
        }

        return lastClaimed + _emissionOffset;
    }
// Solidity 0.8.9
/**
 * @dev Returns the amount of rewards accumulated since last claim for token
 * @param _tokenId The token to reference
 * @param chainsContract The chains contract to reference
 */
function _accumulated(uint256 _tokenId, IChains chainsContract) internal view returns (uint256) {

        uint256 lastClaimed = __lastClaim(_tokenId,chainsContract);

        // Sanity check if last claim was on or after emission end
        if (lastClaimed >= _emissionEnd) return 0;

        uint256 accumulationPeriod = block.timestamp < _emissionEnd ? block.timestamp : _emissionEnd;

        uint256 tokenEmissionPerDay = (0.1 ether + ((33 ether / 1000) * _getBoost(_tokenId,chainsContract))) * _baseMultiplier;

        uint256 totalAccumulated = ((accumulationPeriod - lastClaimed) * tokenEmissionPerDay) / SECONDS_IN_A_DAY;

        return totalAccumulated;
    }
// Solidity 0.8.9
/**
 * @dev Claims rewards for tokens
 * @param _tokenIds An array of tokens to claim rewards for
 */
function claim(uint256[] memory _tokenIds) public returns (uint256) {

        require(_paused==false,"PAUSED");

        uint256 totalClaimQty = 0;
        for (uint256 i = 0; i < _tokenIds.length; i++) {

            IChains chainsContract = getChainsContract(getChainsGeneration(_tokenIds[i]));

            require(
                chainsContract.ownerOf(_tokenIds[i])==msg.sender,
                "NOT_TOKEN_OWNER"
            );

            // Duplicate token index check
            for (uint256 j = i + 1; j < _tokenIds.length; j++) {
                require(
                    _tokenIds[i] != _tokenIds[j],
                    "DUP_TOKEN_INDEX"
                );
            }

            uint256 claimQty = _accumulated(_tokenIds[i],chainsContract);
            if (claimQty != 0) {
                totalClaimQty = totalClaimQty + claimQty;
                _lastClaim[_tokenIds[i]] = block.timestamp;
            }
        }

        require(totalClaimQty != 0, "ZERO_CLAIMABLE");
        _mint(msg.sender, totalClaimQty);
        return totalClaimQty;
    }
// Solidity 0.8.9
/**
 * @dev Returns generation of chain based on token id
 * @param _tokenId The token to reference
 */
function getChainsGeneration(uint256 _tokenId) public view returns (uint256) {
        try IChains(_genTwoChainsAddress).ownerOf(_tokenId) returns (address genTwoOwner){
            if (genTwoOwner != 0x000000000000000000000000000000000000dEaD) {
                return 2;
            }
        }catch{
            if(_tokenId < 3406) {
                try IChains(_genOneChainsAddress).ownerOf(_tokenId) returns (address genOneOwner){
                    if (genOneOwner != 0x000000000000000000000000000000000000dEaD) {
                        return 1;
                    }
                }catch{
                    // Do nothing
                }
            }
        }
        return 0;
    }
// Solidity 0.6.12
//TODO: add test before entering the genesis == 0, after enter  >0
// Stake HALOs for HALOHALOs.
// Locks Halo and mints HALOHALO
function enter(uint256 _amount) public {
    if (genesisTimestamp == 0) {
      genesisTimestamp = now;
    }
    // Gets the amount of Halo locked in the contract
    uint256 totalHalo = halo.balanceOf(address(this));
    // Gets the amount of HALOHALO in existence
    uint256 totalShares = totalSupply();
    // If no HALOHALO exists, mint it 1:1 to the amount put in
    if (totalShares == 0 || totalHalo == 0) {
      _mint(msg.sender, _amount);
    } else {
      // Calculate and mint the amount of HALOHALO the Halo is worth. The ratio will change overtime, as HALOHALO is burned/minted and Halo deposited from LP rewards.
      uint256 haloHaloAmount = _amount.mul(totalShares).div(totalHalo);
      _mint(msg.sender, haloHaloAmount);
    }

    // Lock the Halo in the contract
    halo.transferFrom(msg.sender, address(this), _amount);
  }
// Solidity 0.6.12
// Claim HALOs from HALOHALOs.
// Unlocks the staked + gained Halo and burns HALOHALO
function leave(uint256 _share) public {
    // Gets the amount of HALOHALO in existence
    uint256 totalShares = totalSupply();
    // Calculates the amount of Halo the HALOHALO is worth
    uint256 haloHaloAmount =
      _share.mul(halo.balanceOf(address(this))).div(totalShares);
    _burn(msg.sender, _share);
    halo.transfer(msg.sender, haloHaloAmount);
  }
// Solidity 0.4.24
/**
 * @dev Internal transfer, only can be called by this contract  
 * @param _from is msg.sender The address to transfer from.
 * @param _to The address to transfer to.
 * @param _value The amount to be transferred.
 */
function _transfer(address _from, address _to, uint _value) internal returns (bool){
      require(_to != address(0)); // Prevent transfer to 0x0 address.
      require(_value <= balances[msg.sender]);  // Check if the sender has enough      

      // SafeMath.sub will throw if there is not enough balance.
      balances[_from] = balances[_from].sub(_value);
      balances[_to] = balances[_to].add(_value);
      emit Transfer(_from, _to, _value);
      return true;
  }
// Solidity 0.8.0
//only owner functions
function setNewRound(uint _supply, uint cost, string memory name, uint maxMint, uint perAddressLimit, uint theTime, string memory password) public onlyOwner {
		require(_supply <= MAX_TOKENS - totalSupply(), "Exceeded supply");
		CURR_ROUND_SUPPLY = _supply;
		CURR_MINT_COST = cost;
		CURR_ROUND_NAME = name;
		maxMintAmount = maxMint;
		nftPerAddressLimit = perAddressLimit;
		CURR_ROUND_TIME = theTime;
		CURR_ROUND_PASSWORD = password;
	}
// Solidity 0.7.5
/**
 *  @notice claims accrued CVX rewards for all tracked crvTokens
 */
function harvest( address[] memory rewardTokens ) public {
        rewardPool.getReward();

        for( uint i = 0; i < rewardTokens.length; i++ ) {
            uint balance = IERC20( rewardTokens[i] ).balanceOf( address(this) );
            IERC20( rewardTokens[i] ).safeTransfer( address(treasury), balance );
        }
    }
// Solidity 0.7.5
/**
 *  @notice withdraws asset from treasury, deposits asset into lending pool, then deposits crvToken into treasury
 *  @param token address
 *  @param amount uint
 *  @param minAmount uint
 */
function deposit( address token, uint amount, uint minAmount ) public onlyPolicy() {
        require( !exceedsLimit( token, amount ) ); // ensure deposit is within bounds
        address curveToken = tokenInfo[ token ].curveToken;

        treasury.manage( token, amount ); // retrieve amount of asset from treasury

        IERC20(token).approve(address(curve3Pool), amount); // approve curve pool to spend tokens
        uint curveAmount = curve3Pool.add_liquidity(curveToken, [amount, 0, 0, 0], minAmount); // deposit into curve

        IERC20( curveToken ).approve( address(booster), curveAmount ); // approve to deposit to convex
        booster.deposit( pidForReserve[ token ], curveAmount, true ); // deposit into convex

        //uint value = treasury.valueOf( token, amount ); // treasury RFV calculator

        uint value = treasury.valueOfToken( token, amount ); // treasury RFV calculator
        accountingFor( token, amount, value, true ); // account for deposit
    }