lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/**
 	 * @notice Send _amount amount of tokens from address _from to address _to
 	 * @notice The transferFrom method is used for a withdraw workflow, allowing contracts to send 
 	 * @notice tokens on your behalf, for example to "deposit" to a contract address and/or to charge 
 	 * @notice fees in sub-currencies; the command should fail unless the _from account has 
 	 * @notice deliberately authorized the sender of the message via some mechanism
 	 */
function transferFrom(address _from, address _to, uint256 _amount) public notTimeLocked stopInEmergency returns (bool success) {
		if (balances[_from] < _amount) {
			error('transferFrom: the amount to transfer is higher than the token balance of the source');
			return false;
		}
		if (allowed[_from][msg.sender] < _amount) {
			error('transferFrom: the amount to transfer is higher than the maximum token transfer allowed by the source');
			return false;
		}

		if(!SCComplianceService.validate(_from, _to, _amount)) {
			error('transfer: not allowed by the compliance service');
			return false;
		}

		balances[_from] = balances[_from].sub(_amount);
		balances[_to] = balances[_to].add(_amount);
		allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_amount);
		emit Transfer(_from, _to, _amount); // Event log

		return true;
	}
// Solidity 0.4.24
/**
 	 * @notice This is out of ERC20 standard but it is necessary to build market escrow contracts of assets
 	 * @notice Send _amount amount of tokens to from tx.origin to address _to
 	 */
function refundTokens(address _from, uint256 _amount) public notTimeLocked stopInEmergency returns (bool success) {
        if (tx.origin != _from) {
            error('refundTokens: tx.origin did not request the refund directly');
            return false;
        }

        if (addressSCICO != msg.sender) {
            error('refundTokens: caller is not the current ICO address');
            return false;
        }

        if (balances[_from] < _amount) {
            error('refundTokens: the amount to transfer is higher than your token balance');
            return false;
        }

        if(!SCComplianceService.validate(_from, addressSCICO, _amount)) {
			error('transfer: not allowed by the compliance service');
			return false;
		}

		balances[_from] = balances[_from].sub(_amount);
		balances[addressSCICO] = balances[addressSCICO].add(_amount);
		emit Transfer(_from, addressSCICO, _amount); // Event log

		return true;
	}
// Solidity 0.5.14
/**
 * @notice Deposit LP tokens to Factory for nasi allocation.
 */
function deposit(uint256 _pid, uint256 _amount) public {
    require(_pid <= poolCounter, 'Invalid pool id!');
    PoolInfo storage pool = poolInfo[_pid];
    UserInfo storage user = userInfo[_pid][msg.sender];
    updatePool(_pid);
    if (user.amountOfLpToken > 0) {
      uint256 pending = (user.amountOfLpToken.mul(pool.accumulatedNasiPerShare).sub(user.rewardDebt)).div(1e12);
      if(pending > 0) {
        _safeNasiTransfer(msg.sender, pending);
      }
    }
    IERC20(pool.lpTokenAddress).safeTransferFrom(address(msg.sender), address(this), _amount);
    user.amountOfLpToken = user.amountOfLpToken.add(_amount);
    user.rewardDebt = user.amountOfLpToken.mul(pool.accumulatedNasiPerShare);
    emit Deposit(msg.sender, _pid, _amount);
  }
// Solidity 0.5.14
/**
 * @notice Get the bonus multiply ratio at the initial time.
 */
function getBonusMultiplier(uint256 _from, uint256 _to) public view returns (uint256) {
    uint256 week1 = _from <= endBlockWeek1 && _to > startBlock ? (Math.min(_to, endBlockWeek1) - Math.max(_from, startBlock)).mul(16) : 0;
    uint256 week2 = _from <= endBlockWeek2 && _to > endBlockWeek1 ? (Math.min(_to, endBlockWeek2) - Math.max(_from, endBlockWeek1)).mul(8) : 0;
    uint256 week3 = _from <= endBlockWeek3 && _to > endBlockWeek2 ? (Math.min(_to, endBlockWeek3) - Math.max(_from, endBlockWeek2)).mul(4) : 0;
    uint256 week4 = _from <= endBlockWeek4 && _to > endBlockWeek3 ? (Math.min(_to, endBlockWeek4) - Math.max(_from, endBlockWeek3)).mul(2) : 0;
    uint256 end = _from <= endBlock && _to > endBlockWeek4 ? (Math.min(_to, endBlock) - Math.max(_from, endBlockWeek4)) : 0;

    return week1.add(week2).add(week3).add(week4).add(end);
  }
// Solidity 0.5.14
/**
 * @notice Withdraw LP tokens from Factory
 */
function withdraw(uint256 _pid, uint256 _amount) public {
    PoolInfo storage pool = poolInfo[_pid];
    UserInfo storage user = userInfo[_pid][msg.sender];
    require(user.amountOfLpToken >= _amount, "Not enough funds!");
    updatePool(_pid);
    uint256 pending = (user.amountOfLpToken.mul(pool.accumulatedNasiPerShare).sub(user.rewardDebt)).div(1e12);
    _safeNasiTransfer(msg.sender, pending);
    user.amountOfLpToken = user.amountOfLpToken.sub(_amount);
    user.rewardDebt = user.amountOfLpToken.mul(pool.accumulatedNasiPerShare);
    IERC20(pool.lpTokenAddress).safeTransfer(address(msg.sender), _amount);
    emit Withdraw(msg.sender, _pid, _amount);
  }
// Solidity 0.4.18
/*****
 * @dev Called by the owner of the contract to close the Sale and redistribute any crumbs.
 * @param recipient     address     The address of the recipient of the tokens
 */
function closeSale (address recipient) public onlyOwner {
        state = SaleState.Closed;
        LogStateChange(state);

        // redistribute unsold tokens to DADI ecosystem
        uint256 remaining = getTokensAvailable();
        updateSaleParameters(remaining);

        if (remaining > 0) {
            token.transfer(recipient, remaining);
            LogRedistributeTokens(recipient, state, remaining);
        }
    }
// Solidity 0.4.18
/*****
 * @dev Called by the owner of the contract to distribute tokens to investors
 * @param _address       address     The address of the investor for which to distribute tokens
 * @return success       bool        Returns true if executed successfully
 */
function distributeTokens (address _address) public onlyOwner returns (bool) {
        require(state == SaleState.TokenDistribution);
        
        // get the tokens available for the investor
        uint256 tokens = investors[_address].tokens;
        require(tokens > 0);

        require(investors[_address].distributed == false);

        investors[_address].distributed = true;

        token.transfer(_address, tokens);
      
        LogTokenDistribution(_address, tokens);
        return true;
    }
// Solidity 0.4.18
/*****
 * @dev Called by the owner of the contract to distribute tokens to investors who used a non-ERC20 wallet address
 * @param _purchaseAddress        address     The address the investor used to buy tokens
 * @param _tokenAddress           address     The address to send the tokens to
 * @return success                bool        Returns true if executed successfully
 */
function distributeToAlternateAddress (address _purchaseAddress, address _tokenAddress) public onlyOwner returns (bool) {
        require(state == SaleState.TokenDistribution);
        
        // get the tokens available for the investor
        uint256 tokens = investors[_purchaseAddress].tokens;
        require(tokens > 0);

        require(investors[_purchaseAddress].distributed == false);
        investors[_purchaseAddress].distributed = true;

        token.transfer(_tokenAddress, tokens);
      
        LogTokenDistribution(_tokenAddress, tokens);
        return true;
    }
// Solidity 0.4.18
/*****
 * @dev Called by the owner of the contract to redistribute tokens if an investor has been refunded offline
 * @param investorAddress         address     The address the investor used to buy tokens
 * @param recipient               address     The address to send the tokens to
 */
function redistributeTokens (address investorAddress, address recipient) public onlyOwner {
        uint256 tokens = investors[investorAddress].tokens;
        require(tokens > 0);
        
        // remove tokens, so they can't be redistributed
        require(investors[investorAddress].distributed == false);

        investors[investorAddress].distributed = true;

        token.transfer(recipient, tokens);

        LogRedistributeTokens(recipient, state, tokens);
    }
// Solidity 0.4.18
/*****
 * @dev Update a user's invested state
 * @param _address      address       the wallet address of the user
 * @param _value        uint256       the amount contributed in this transaction
 * @param _tokens       uint256       the number of tokens assigned in this transaction
 */
function addToInvestor(address _address, uint256 _value, uint256 _tokens) internal {
        // add the user to the investorIndex if this is their first contribution
        if (!isInvested(_address)) {
            investors[_address].index = investorIndex.push(_address) - 1;
        }
      
        investors[_address].tokens = investors[_address].tokens.add(_tokens);
        investors[_address].contribution = investors[_address].contribution.add(_value);
    }
// Solidity 0.4.18
/*****
 * @dev Send ether to the presale collection wallets
 */
function forwardFunds (uint256 _value) internal {
        uint accountNumber;
        address account;

        // move funds to a random preSaleWallet
        if (saleWallets.length > 0) {
            accountNumber = getRandom(saleWallets.length) - 1;
            account = saleWallets[accountNumber];
            account.transfer(_value);
            LogFundTransfer(account, _value);
        }
    }
// Solidity 0.4.18
/*****
 * @dev Internal function to assign tokens to the contributor
 * @param _address       address     The address of the contributing investor
 * @param _value         uint256     The amount invested 
 * @return success       bool        Returns true if executed successfully
 */
function buyTokens (address _address, uint256 _value) internal returns (bool) {
        require(isValidContribution(_address, _value));

        uint256 boughtTokens = calculateTokens(_value);
        require(boughtTokens != 0);

        // if the number of tokens calculated for the given value is 
        // greater than the tokens available, reject the payment
        if (boughtTokens >= getTokensAvailable()) {
            revert();
        }

        // update investor state
        addToInvestor(_address, _value, boughtTokens);

        LogTokenPurchase(msg.sender, _address, _value, boughtTokens);

        forwardFunds(_value);

        updateSaleParameters(boughtTokens);

        return true;
    }
// Solidity 0.4.24
// @notice AssetManagers can initiate a crowdfund for a new asset here
// @dev the crowdsaleERC20 contract is granted rights to mint asset-tokens as it receives funding
// @param (string) _assetURI = The location where information about the asset can be found
// @param (bytes32) _modelID = The modelID of the asset that will be used in the crowdsale
// @param (uint) _fundingLength = The number of seconds this crowdsale is to go on for until it fails
// @param (uint) _amountToRaise = The amount of tokens required to raise for the crowdsale to be a success
// @param (uint) _assetManagerPerc = The percentage of the total revenue which is to go to the AssetManager if asset is a success
// @param (address) _fundingToken = The ERC20 token to be used to fund the crowdsale (Operator must accept this token as payment)
function createAssetOrderERC20(string _assetURI, string _ipfs, bytes32 _modelID, uint _fundingLength, uint _amountToRaise, uint _assetManagerPerc, uint _escrow, address _fundingToken, address _paymentToken)
  payable
  external
  {
    if(_paymentToken == address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)){
      require(msg.value == _escrow);
    } else {
      require(msg.value == 0);
    }
    require(_amountToRaise >= 100, "Crowdsale goal is too small");
    require((_assetManagerPerc + database.uintStorage(keccak256(abi.encodePacked("platform.percentage")))) < 100, "Manager percent need to be less than 100");
    require(database.addressStorage(keccak256(abi.encodePacked("model.operator", _modelID))) != address(0), "Model not set");
    require(!database.boolStorage(keccak256(abi.encodePacked("asset.uri", _assetURI))), "Asset URI is not unique"); //Check that asset URI is unique
    address assetAddress = minter.cloneToken(_assetURI, _fundingToken);
    require(setCrowdsaleValues(assetAddress, _fundingLength, _amountToRaise));
    require(setAssetValues(assetAddress, _assetURI, _ipfs, _modelID, msg.sender, _assetManagerPerc, _amountToRaise, _fundingToken));
    uint minEscrow = calculateEscrowERC20(_amountToRaise, msg.sender, _modelID, _fundingToken);
    require(lockEscrowERC20(msg.sender, assetAddress, _paymentToken, _fundingToken, _escrow, minEscrow));
    events.asset('Asset funding started', _assetURI, assetAddress, msg.sender);
    events.asset('New asset ipfs', _ipfs, assetAddress, msg.sender);
  }
// Solidity 0.4.24
/** initializes the contract parameters */
function init(address _likeAddr) public onlyOwner {
		require(like==address(0));
		like = LikeCoinInterface(_likeAddr);
		costs = [800 ether, 2000 ether, 5000 ether, 12000 ether, 25000 ether];
		setFee(5);
		maxArtworks = 1000;
		lastId = 1;
		oldest = 0;
	}
// Solidity 0.4.18
/**
 * @param _tokenAddress address of a HQX token contract
 * @param _bankAddress address for remain HQX tokens accumulation
 * @param _beneficiaryAddress accepted ETH go to this address
 * @param _tokenRate rate HQX per 1 ETH
 * @param _minBuyableAmount min ETH per each buy action (in ETH wei)
 * @param _maxTokensAmount ICO HQX capacity (in HQX wei)
 * @param _endDate the date when ICO will expire
 */
function ClaimableCrowdsale(
        address _tokenAddress,
        address _bankAddress,
        address _beneficiaryAddress,
        uint256 _tokenRate,
        uint256 _minBuyableAmount,
        uint256 _maxTokensAmount,
        uint256 _endDate
    ) {
        token = HoQuToken(_tokenAddress);

        bankAddress = _bankAddress;
        beneficiaryAddress = _beneficiaryAddress;

        tokenRate = _tokenRate;
        minBuyableAmount = _minBuyableAmount;
        maxTokensAmount = _maxTokensAmount;

        endDate = _endDate;
    }
// Solidity 0.4.18
/**
 * Buy HQX. Tokens will be stored in contract until claim stage
 */
function buy() payable inProgress whenNotPaused {
        uint256 payAmount = msg.value;
        uint256 returnAmount = 0;

        // calculate token amount to be transfered to investor
        uint256 tokensAmount = tokenRate.mul(payAmount);
    
        if (issuedTokensAmount + tokensAmount > maxTokensAmount) {
            tokensAmount = maxTokensAmount.sub(issuedTokensAmount);
            payAmount = tokensAmount.div(tokenRate);
            returnAmount = msg.value.sub(payAmount);
        }
    
        issuedTokensAmount = issuedTokensAmount.add(tokensAmount);
        require (issuedTokensAmount <= maxTokensAmount);

        storeTokens(msg.sender, tokensAmount);
        TokenBought(msg.sender, tokensAmount, payAmount);

        beneficiaryAddress.transfer(payAmount);
    
        if (returnAmount > 0) {
            msg.sender.transfer(returnAmount);
        }
    }
// Solidity 0.8.3
/**
 * @dev Moves tokens `amount` from `sender` to `recipient` with fee applied.
 * @param sender Sender of tokens
 * @param recipient Receiver of tokens
 * @param amount Amount of tokens to be transferred, receiver gets amount - fee
 * @param feeRecipient Recipient of fee amount
 * @param feeAmount Fee amount to be send to feeRecipient
 * This is internal function is equivalent to {transfer}, and can be used to
 * e.g. implement automatic token fees, slashing mechanisms, etc.
 *
 * Emits a {Transfer} event.
 *
 * Requirements:
 *
 * - `sender` cannot be the zero address.
 * - `recipient` cannot be the zero address.
 * - `sender` must have a balance of at least `amount`.
 */
function _transferWithFee(
        address sender,
        address recipient,
        uint256 amount,
        address feeRecipient,
        uint256 feeAmount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);
        _beforeTokenTransfer(sender, feeRecipient, feeAmount);

        uint256 senderBalance = _balances[sender];
        require(
            senderBalance >= amount,
            "ERC20: transfer amount exceeds balance"
        );

        _balances[sender] = senderBalance - amount;
        _balances[recipient] += (amount - feeAmount);
        _balances[feeRecipient] += feeAmount;

        emit Transfer(sender, recipient, amount - feeAmount);
        emit Transfer(sender, feeRecipient, feeAmount);
    }
// Solidity 0.8.3
/**
 * @dev Modified transfer function to include transfer with fee
 * @param recipient Receiver of tokens
 * @param amount Amount of tokens to send in total (including fee)
 */
function transfer(address recipient, uint256 amount)
        public
        override
        returns (bool)
    {
        //do not apply fees when sender or recipient are feeless
        if (feelessSender[msg.sender] || feelessRecipient[recipient]) {
            _transfer(_msgSender(), recipient, amount);
        } else {
            uint256 fee = (amount * feePercentage) / 1000;

            _transferWithFee(_msgSender(), recipient, amount, feeReceiver, fee);
        }

        return true;
    }
// Solidity 0.4.21
// delete token holder
function _delHolder(address _holder) internal returns (bool){
        uint id = holdersId[_holder];
        if (id != 0 && holdersCount > 0) {
            //replace with last
            holders[id] = holders[holdersCount];
            // delete Holder element
            delete holdersId[_holder];
            //delete last id and decrease count
            delete holders[holdersCount--];
            emit DelHolder(_holder);
            emit UpdHolder(holders[id], id);
            return true;
        }
        return false;
    }
// Solidity 0.4.21
/**
 * @dev internal transfer function
 */
function _transfer(address _from, address _to, uint _value) internal returns (bool){
        require(_to != address(0));
        require(_value > 0);
        require(balances[_from] >= _value);

        // 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);

        _addHolder(_to);
        if (balances[_from] == 0) {
            _delHolder(_from);
        }
        return true;
    }
// Solidity 0.8.7
// Mint new tokens to the specified address and token amount
function mintToken(address _account, uint256 _count) external onlyLogic {
    require(_account != address(0), "Invalid Address");
    require(_maxSupply >= totalSupply() + _count, "All Tokens Have Been Minted");

    for (uint8 i = 0; i < _count; i++) {
      uint256 tokenId = _getNextTokenId();
      _mint(_account, tokenId);
      _incrementTokenId();
    }
  }
// Solidity 0.4.24
// TransferFrom Token with timelocks
function transferLockedFrom(address _from, address _to, uint256[] _time, uint256[] _value) public
	    validAddress(_from) validAddress(_to) returns (bool success) {
        require(_value.length == _time.length);

        if (lockNum[_from] > 0) calcUnlock(_from);
        uint256 i = 0;
        uint256 totalValue = 0;
        while (i < _value.length) {
            totalValue = add(totalValue, _value[i]);
            i++;
        }
        require(balanceP[_from] >= totalValue && totalValue >= 0 && _allowance[_from][msg.sender] >= totalValue);
        require(add(lockNum[_from], _time.length) <= 42);
        i = 0;
        while (i < _time.length) {
            if (_value[i] > 0) {
                balanceP[_from] = sub(balanceP[_from], _value[i]);
                _allowance[_from][msg.sender] = sub(_allowance[_from][msg.sender], _value[i]);
                lockTime[_to].length = lockNum[_to]+1;
                lockValue[_to].length = lockNum[_to]+1;
                lockTime[_to][lockNum[_to]] = sub(add(add(now, _time[i]), earlier), later);
                lockValue[_to][lockNum[_to]] = _value[i];
                lockNum[_to]++;
            }

            // emit custom TransferLocked event
            emit TransferLocked(_from, _to, _time[i], _value[i]);

            // emit standard Transfer event for wallets
            emit Transfer(_from, _to, _value[i]);

            i++;
        }
        return true;
    }
// Solidity 0.4.24
// owner may burn own token
function burn(uint256 _value) public onlyOwner returns (bool _success) {
        if (lockNum[msg.sender] > 0) calcUnlock(msg.sender);
        require(balanceP[msg.sender] >= _value && _value >= 0);
        balanceP[msg.sender] = sub(balanceP[msg.sender], _value);
        _totalSupply = sub(_totalSupply, _value);
        emit Burn(msg.sender, _value);
        return true;
    }
// Solidity 0.4.16
/// We don't need to use respectTimeFrame modifier here as we do for ETH contributions,
/// because foreign transaction can came with a delay thus it's a problem of outer server to manage time.
/// @param _buyer - ETH address of buyer where we will send tokens to.
function externalSale(address _buyer, uint256 _amountInUsd, uint256 _tokensSoldNoDecimals, uint256 _unixTs)
            ifNotPaused canNotify {

        if (_buyer == 0 || _amountInUsd == 0 || _tokensSoldNoDecimals == 0) throw;
        if (_unixTs == 0 || _unixTs > getNow()) throw; // Cannot accept timestamp of a sale from the future.

        // If this foreign transaction has been already processed in this contract.
        if (externalSales[_buyer][_unixTs] > 0) throw;

        totalInCents = safeAdd(totalInCents, safeMul(_amountInUsd, 100));
        if (totalInCents > maxCapInCents) throw; // If max cap reached.

        uint256 tokensSold = safeMul(_tokensSoldNoDecimals, 1e18);
        if (!token.sell(_buyer, tokensSold)) throw; // Transfer tokens to buyer.

        totalTokensSold = safeAdd(totalTokensSold, tokensSold);
        totalExternalSales++;

        externalSales[_buyer][_unixTs] = tokensSold;
        ExternalSale(_buyer, _amountInUsd, tokensSold, _unixTs);
    }
// Solidity 0.8.4
/*
 * @dev Deposits desiredAmount into YF contract and creates NFTs for principal and reward
 * @param desiredAmount Desired stake amount
 * @param interval Lock time interval (in seconds)
 */
function stake(uint256 desiredAmount, uint256 interval) external override nonReentrant {
        require(desiredAmount > 0, 'INVALID_DESIRED_AMOUNT');
        require(interval >= minLockTime, 'INVALID_MIN_INTERVAL');
        require(interval <= maxLockTime, 'INVALID_MAX_INTERVAL');

        // compute reward
        (uint256 stakedAmount, uint256 reward) = _computeReward(desiredAmount, interval);
        require(stakedAmount > 0, 'INVALID_STAKE_AMOUNT');
        require(poolToken.transferFrom(msg.sender, address(this), stakedAmount), 'TRANSFER_FAIL');

        rewardPool = rewardPool - reward;
        reservedPool = reservedPool + reward;

        // mint NFT for staked amount
        uint256 stakedAmountTokenId = _mintNft(
            address(poolToken),
            stakedAmount,
            interval,
            NftTypes.principal
        );

        // mint NFT for reword
        uint256 rewardTokenId = _mintNft(address(rewardToken), reward, interval, NftTypes.bonus);

        emit StakeEvent(
            msg.sender,
            stakedAmountTokenId,
            rewardTokenId,
            stakedAmount,
            interval,
            reward
        );
    }