lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.15
/**
 * Transfer the balance from owner's account to another account
 *
 * @param _to         target address
 * @param _amount     amount of tokens
 * @return            true on success
 */
function transfer(address _to, uint256 _amount) returns (bool success) {
        if (balanceOf[msg.sender] >= _amount                // User has balance
            && _amount > 0                                 // Non-zero transfer
            && balanceOf[_to] + _amount > balanceOf[_to]     // Overflow check
        ) {
            balanceOf[msg.sender] -= _amount;
            balanceOf[_to] += _amount;
            Transfer(msg.sender, _to, _amount);
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.4.15
/**
 * Spender of tokens transfer an amount of tokens from the token owner's
 * balance to the spender's account. The owner of the tokens must already
 * have approve(...)-d this transfer
 *
 * @param _from       spender address
 * @param _to         target address
 * @param _amount     amount of tokens
 * @return            true on success
 */
function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {
        if (balanceOf[_from] >= _amount                  // From a/c has balance
            && allowance[_from][msg.sender] >= _amount    // Transfer approved
            && _amount > 0                              // Non-zero transfer
            && balanceOf[_to] + _amount > balanceOf[_to]  // Overflow check
        ) {
            balanceOf[_from] -= _amount;
            allowance[_from][msg.sender] -= _amount;
            balanceOf[_to] += _amount;
            Transfer(_from, _to, _amount);
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.4.15
/**
 * EloPlayToken contract constructor
 *
 * @param _start_ts         crowdsale start timestamp (unix)
 * @param _end_ts           crowdsale end timestamp (unix)
 * @param _cap              crowdsale upper cap (in wei)
 * @param _target_address   multisignature wallet where Ethers will be sent to
 * @param _target_tokens_address   account where 30% of tokens will be sent to
 * @param _usdethrate       USD to ETH rate
 */
function EloPlayToken(uint256 _start_ts, uint256 _end_ts, uint256 _cap, address _target_address,  address _target_tokens_address, uint256 _usdethrate) {
        START_TS        = _start_ts;
        END_TS          = _end_ts;
        CAP             = _cap;
        USDETHRATE      = _usdethrate;
        TARGET_ADDRESS  = _target_address;
        TARGET_TOKENS_ADDRESS  = _target_tokens_address;
    }
// Solidity 0.4.15
/**
 * Get tokens per ETH for given date/time
 *
 * @param _at         timestamp (unix)
 * @return            tokens/ETH rate for given timestamp
 */
function buyPriceAt(uint256 _at) constant returns (uint256) {
        if (_at < START_TS) {
            return 0;
        } else if (_at < START_TS + 3600) {
            // 1st hour = 10000 + 20% = 12000
            return 12000;
        } else if (_at < START_TS + 3600 * 24) {
            // 1st day = 10000 + 15% = 11500
            return 11500;
        } else if (_at < START_TS + 3600 * 24 * 7) {
            // 1st week = 10000 + 10% = 11000
            return 11000;
        } else if (_at < START_TS + 3600 * 24 * 7 * 2) {
            // 2nd week = 10000 + 5% = 10500
            return 10500;
        } else if (_at <= END_TS) {
            // More than 2 weeks = 10000
            return 10000;
        } else {
            return 0;
        }
    }
// Solidity 0.4.15
/**
 * Owner to add precommitment funding token balance before the crowdsale commences
 * Used for pre-sale commitments, added manually
 *
 * @param _participant         address that will receive tokens
 * @param _balance             number of tokens
 * @param _ethers         Ethers value (needed for stats)
 *
 */
function addPrecommitment(address _participant, uint256 _balance, uint256 _ethers) onlyOwner {
        require(now < START_TS);
        // Minimum value = 1ELT
        // Since we are using 18 decimals for token
        require(_balance >= 1 ether);

        // To avoid overflow, first divide then multiply (to clearly show 70%+30%, result wasn't precalculated)
        uint additional_tokens = _balance / 70 * 30;

        balanceOf[_participant] = balanceOf[_participant].add(_balance);
        balanceOf[TARGET_TOKENS_ADDRESS] = balanceOf[TARGET_TOKENS_ADDRESS].add(additional_tokens);

        totalSupply = totalSupply.add(_balance);
        totalSupply = totalSupply.add(additional_tokens);

        // Add ETH raised to total
        totalEthers = totalEthers.add(_ethers);

        Transfer(0x0, _participant, _balance);
        Transfer(0x0, TARGET_TOKENS_ADDRESS, additional_tokens);
    }
// Solidity 0.4.15
/**
 * Transfer the balance from owner's account to another account, with a
 * check that the crowdsale is finalized
 *
 * @param _to                tokens receiver
 * @param _amount            tokens amount
 * @return                   true on success
 */
function transfer(address _to, uint _amount) returns (bool success) {
        // Cannot transfer before crowdsale ends or cap reached
        require(now > END_TS || totalEthers >= CAP);
        // Standard transfer
        return super.transfer(_to, _amount);
    }
// Solidity 0.4.15
/**
 * Spender of tokens transfer an amount of tokens from the token owner's
 * balance to another account, with a check that the crowdsale is
 * finalized
 *
 * @param _from              tokens sender
 * @param _to                tokens receiver
 * @param _amount            tokens amount
 * @return                   true on success
 */
function transferFrom(address _from, address _to, uint _amount)
            returns (bool success) {
        // Cannot transfer before crowdsale ends or cap reached
        require(now > END_TS || totalEthers >= CAP);
        // Standard transferFrom
        return super.transferFrom(_from, _to, _amount);
    }
// Solidity 0.8.4
// This function must be called after builder shop instance is created - it can be called again
// to change the split; call this once per nifty type to set up royalty payments properly
function initializeRoyalties(address splitterImplementation, uint256 niftyType, address[] calldata payees, uint256[] calldata shares_) external onlyValidSender {
        address previousReceiver = _getRoyaltyReceiverByNiftyType(niftyType);
        address newReceiver = address(0);
        if(payees.length == 1) {
            newReceiver = payees[0];
            _royaltyReceivers[niftyType] = newReceiver;
            delete _royaltySplitters[niftyType];
        } else {            
            delete _royaltyReceivers[niftyType];
            require(IERC165(splitterImplementation).supportsInterface(type(ICloneablePaymentSplitter).interfaceId), "Not a valid payment splitter");
            newReceiver = payable (Clones.clone(splitterImplementation));
            ICloneablePaymentSplitter(newReceiver).initialize(payees, shares_);
            _royaltySplitters[niftyType] = newReceiver;        
        }

        emit RoyaltyReceiverUpdated(niftyType, previousReceiver, newReceiver);        
    }
// Solidity 0.8.4
/**
 * @dev Create specified number of nifties en masse.
 * Once an NFT collection is spawned by the factory contract, we make calls to set the IPFS
 * hash (above) for each Nifty type in the collection.
 * Subsequently calls are issued to this function to mint the appropriate number of tokens
 * for the project.
 */
function mintNifty(uint256 niftyType, uint256 count) public onlyValidSender {
        require(!_getFinalized(niftyType), "NiftyBuilderInstance: minting concluded for nifty type");
            
        uint256 tokenNumber = _mintCount[niftyType] + 1;
        uint256 tokenId00 = _encodeTokenId(niftyType, tokenNumber);
        uint256 tokenId01 = tokenId00 + count - 1;
        
        for (uint256 tokenId = tokenId00; tokenId <= tokenId01; tokenId++) {
            _owners[tokenId] = _defaultOwner;
        }
        _mintCount[niftyType] += count;
        _balances[_defaultOwner] += count;

        emit ConsecutiveTransfer(tokenId00, tokenId01, address(0), _defaultOwner);
    }
// Solidity 0.7.6
/**
 @notice equivalent to `deposit` except logic is configured for
 ETH instead of ERC20 payments.
 @param amountDesired amount of ERC20 token desired by caller
 @param amountEthMin minimum amount of ETH desired by caller
 @param amountMin minimum amount of ERC20 token desired by caller
 @param recipient The address for which the liquidity will be created
 @param deadline Blocktimestamp that this must execute before
 @return shares
 @return amountEthIn how much ETH was actually deposited
 @return amountIn how much the ERC20 token was actually deposited
 */
function depositETH(
    uint256 amountDesired,
    uint256 amountEthMin,
    uint256 amountMin,
    address recipient,
    uint256 deadline
  )
    external
    payable
    override
    notExpired(deadline)
    returns (
      uint256 shares,
      uint256 amountEthIn,
      uint256 amountIn
    )
  {
    TOKEN _WETH_TOKEN = WETH_TOKEN;
    if (_WETH_TOKEN == TOKEN.ZERO) {
      (shares, amountEthIn, amountIn) = _depositETH(
        _WETH_TOKEN,
        msg.value,
        amountDesired,
        amountEthMin,
        amountMin,
        recipient,
        deadline
      );
    } else {
      (shares, amountIn, amountEthIn) = _depositETH(
        _WETH_TOKEN,
        amountDesired,
        msg.value,
        amountMin,
        amountEthMin,
        recipient,
        deadline
      );
    }
  }
// Solidity 0.7.6
/**
 @notice withdraws the desired shares from the vault
 @dev same as `withdraw` except this can be called from an `approve`d address
 @param withdrawer the address to withdraw from
 @param shares number of shares to withdraw
 @param amountEthMin amount of ETH desired by user
 @param amountMin Minimum amount of ERC20 token desired by user
 @param recipient address to recieve ETH and ERC20 withdrawals
 @param deadline blocktimestamp that this must execute by
 @return amountEthOut how much ETH was actually withdrawn
 @return amountOut how much ERC20 token was actually withdrawn
 */
function withdrawETHFrom(
    address withdrawer,
    uint256 shares,
    uint256 amountEthMin,
    uint256 amountMin,
    address payable recipient,
    uint256 deadline
  )
    external
    override
    canSpend(withdrawer, shares)
    returns (uint256 amountEthOut, uint256 amountOut)
  {
    TOKEN _WETH_TOKEN = WETH_TOKEN;
    uint256 amount0Min;
    uint256 amount1Min;
    if (_WETH_TOKEN == TOKEN.ZERO) {
      amount0Min = amountEthMin;
      amount1Min = amountMin;
      (amountEthOut, amountOut) = _withdrawETH(
        _WETH_TOKEN,
        withdrawer,
        shares,
        amount0Min,
        amount1Min,
        recipient,
        deadline
      );
    } else {
      amount0Min = amountMin;
      amount1Min = amountEthMin;
      (amountOut, amountEthOut) = _withdrawETH(
        _WETH_TOKEN,
        withdrawer,
        shares,
        amount0Min,
        amount1Min,
        recipient,
        deadline
      );
    }
  }
// Solidity 0.7.6
/**
 @notice withdraws the desired shares from the vault
 @param shares number of shares to withdraw
 @param amountEthMin amount of ETH desired by user
 @param amountMin Minimum amount of ERC20 token desired by user
 @param recipient address to recieve ETH and ERC20 withdrawals
 @param deadline blocktimestamp that this must execute by
 @return amountEthOut how much ETH was actually withdrawn
 @return amountOut how much ERC20 token was actually withdrawn
 */
function withdrawETH(
    uint256 shares,
    uint256 amountEthMin,
    uint256 amountMin,
    address payable recipient,
    uint256 deadline
  ) external override returns (uint256 amountEthOut, uint256 amountOut) {
    TOKEN _WETH_TOKEN = WETH_TOKEN;
    uint256 amount0Min;
    uint256 amount1Min;
    if (_WETH_TOKEN == TOKEN.ZERO) {
      amount0Min = amountEthMin;
      amount1Min = amountMin;
      (amountEthOut, amountOut) = _withdrawETH(
        _WETH_TOKEN,
        msg.sender,
        shares,
        amount0Min,
        amount1Min,
        recipient,
        deadline
      );
    } else {
      amount0Min = amountMin;
      amount1Min = amountEthMin;
      (amountOut, amountEthOut) = _withdrawETH(
        _WETH_TOKEN,
        msg.sender,
        shares,
        amount0Min,
        amount1Min,
        recipient,
        deadline
      );
    }
  }
// Solidity 0.6.12
/// @notice Selects a user using a random number.  The random number will be uniformly bounded to the ticket totalSupply.
/// @param randomNumber The random number to use to select a user.
/// @return The winner
function draw(uint256 randomNumber) external view override returns (address) {
    uint256 bound = totalSupply();
    address selected;
    if (bound == 0) {
      selected = address(0);
    } else {
      uint256 token = UniformRandomNumber.uniform(randomNumber, bound);
      selected = address(uint256(sortitionSumTrees.draw(TREE_KEY, token)));
    }
    return selected;
  }
// Solidity 0.6.12
/// @dev Controller hook to provide notifications & rule validations on token transfers to the controller.
/// This includes minting and burning.
/// May be overridden to provide more granular control over operator-burning
/// @param from Address of the account sending the tokens (address(0x0) on minting)
/// @param to Address of the account receiving the tokens (address(0x0) on burning)
/// @param amount Amount of tokens being transferred
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
    super._beforeTokenTransfer(from, to, amount);

    // optimize: ignore transfers to self
    if (from == to) {
      return;
    }

    if (from != address(0)) {
      uint256 fromBalance = balanceOf(from).sub(amount);
      sortitionSumTrees.set(TREE_KEY, fromBalance, bytes32(uint256(from)));
    }

    if (to != address(0)) {
      uint256 toBalance = balanceOf(to).add(amount);
      sortitionSumTrees.set(TREE_KEY, toBalance, bytes32(uint256(to)));
    }
  }
// Solidity 0.6.12
/// @notice Permits this contract to spend on a users behalf, and deposits into the prize pool.
/// @dev The Dai permit params match the Dai#permit function, but it expects the `spender` to be
/// the address of this contract.
/// @param holder The address spending the tokens
/// @param nonce The nonce of the tx.  Should be retrieved from the Dai token
/// @param expiry The timestamp at which the sig expires
/// @param allowed If true, then the spender is approving holder the max allowance.  False makes the allowance zero.
/// @param v The `v` portion of the signature.
/// @param r The `r` portion of the signature.
/// @param s The `s` portion of the signature.
/// @param prizePool The prize pool to deposit into
/// @param to The address that will receive the controlled tokens
/// @param amount The amount to deposit
/// @param controlledToken The type of token to be minted in exchange (i.e. tickets or sponsorship)
/// @param referrer The address that referred the deposit
function permitAndDepositTo(
    // --- Approve by signature ---
    address dai, address holder, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s,
    address prizePool, address to, uint256 amount, address controlledToken, address referrer
  ) external {
    require(msg.sender == holder, "PermitAndDepositDai/only-signer");
    DaiInterface(dai).permit(holder, address(this), nonce, expiry, allowed, v, r, s);
    _depositTo(dai, holder, prizePool, to, amount, controlledToken, referrer);
  }
// Solidity 0.5.8
//
// Buy a single ticket.
//
function buyOne() onlyUnpaused payable external {
        TournamentTicket ticket = getTicketContract();

        require(ticket.balanceOf(msg.sender) == 0, "You already have a ticket, and you only need one to participate!");
        require(pricePerTicket > 0, "The price per ticket needs to be more than 0!");
        require(msg.value == pricePerTicket, "The amout sent is not corresponding with the ticket price!");
        
        require(
            ticket.transferFrom(getTicketOwnerAddress(), msg.sender, 1000000000000000000),
            "Ticket transfer failed!"
        );
        
        getTicketOwnerAddress().transfer(msg.value);
    }
// Solidity 0.8.4
/**
 * @dev Internal function to mint a new token.
 * Reverts if the given token ID already exists.
 * @param sign struct combination of uint8, bytes32, bytes32 are v, r, s.
 * @param tokenURI string memory URI of the token to be minted.
 * @param fee uint256 royalty of the token to be minted.
 */
function createCollectible(string memory tokenURI, uint256 fee, Sign memory sign) public returns (uint256) {
        uint256 newItemId = tokenCounter;
        verifySign(tokenURI, sign);
        _safeMint(msg.sender, newItemId, fee);
        _setTokenURI(newItemId, tokenURI);
        tokenCounter = tokenCounter + 1;
        return newItemId;
    }
// Solidity 0.4.24
/**
 * @dev Burns a specific amount of tokens.
 * @param _account The account whose tokens will be burnt.
 * @param _value The amount of token to be burned.
 */
function burn(address _account, uint256 _value) onlyOwner public {
      require(_account != address(0));
      require(_enableActions);

      // SafeMath.sub will throw if there is not enough balance.
      _totalSupply = _totalSupply.sub(_value);
      _balances[_account] = _balances[_account].sub(_value);
      emit Transfer(_account, address(0), _value);
  }
// Solidity 0.4.18
/** Calculate the current price for buy in amount. */
function calculateTokenAmount(uint weiAmount, uint weiRaised) public view returns (uint tokenAmount) {
        if (weiAmount == 0) {
            return 0;
        }

        var (rate, index) = currentRate(weiRaised);
        tokenAmount = weiAmount.mul(rate);

        // if we crossed slot border, recalculate remaining tokens according to next slot price
        if (weiRaised.add(weiAmount) > limits[index]) {
            uint currentSlotWei = limits[index].sub(weiRaised);
            uint currentSlotTokens = currentSlotWei.mul(rate);
            uint remainingWei = weiAmount.sub(currentSlotWei);
            tokenAmount = currentSlotTokens.add(calculateTokenAmount(remainingWei, limits[index]));
        }
    }
// Solidity 0.5.11
// register new contract for state sync
function register(address sender, address receiver) public {
        require(
            isOwner() || registrations[receiver] == msg.sender,
            "StateSender.register: Not authorized to register"
        );
        registrations[receiver] = sender;
        if (registrations[receiver] == address(0)) {
            emit NewRegistration(msg.sender, sender, receiver);
        } else {
            emit RegistrationUpdated(msg.sender, sender, receiver);
        }
    }
// Solidity 0.4.23
/**
 *batch transfer token for a list of specified addresses
 * @param _toList The list of addresses to transfer to.
 * @param _tokensList The list of amount to be transferred.
 */
function batchTransfer(address[] _toList, uint256[] _tokensList) public  returns (bool) {
      require(_toList.length <= 100);
      require(_toList.length == _tokensList.length);
      
      uint256 sum = 0;
      for (uint32 index = 0; index < _tokensList.length; index++) {
          sum = sum.add(_tokensList[index]);
      }

      // if the sender doenst have enough balance then stop
      require (balances[msg.sender] >= sum);
        
      for (uint32 i = 0; i < _toList.length; i++) {
          transfer(_toList[i],_tokensList[i]);
      }
      return true;
  }
// Solidity 0.4.18
// get frozen balance
function frozenBalanceOf(address _owner) public constant returns (uint256 value) {
        for (uint i = 0; i < frozenBalanceCount; i++) {
            FrozenBalance storage frozenBalance = frozenBalances[i];
            if (_owner == frozenBalance.owner) {
                value = value.add(frozenBalance.value);
            }
        }
        return value;
    }
// Solidity 0.4.18
// unfreeze frozen amount
// everyone can call this function to unfreeze balance
function unfreeze() public returns (uint256 releaseAmount) {
        uint index = 0;
        while (index < frozenBalanceCount) {
            if (now >= frozenBalances[index].unfreezeTime) {
                releaseAmount += frozenBalances[index].value;
                unfreezeBalanceByIndex(index);
            } else {
                index++;
            }
        }
        return releaseAmount;
    }
// Solidity 0.4.18
// check is release record existed
// if existed return true, else return false
function checkIsReleaseRecordExist(uint256 timestamp) internal view returns(bool _exist) {
        bool exist = false;
        if (releaseRecordsCount > 0) {
            for (uint index = 0; index < releaseRecordsCount; index++) {
                if ((releaseRecords[index].releaseTime.parseTimestamp().year == timestamp.parseTimestamp().year)
                    && (releaseRecords[index].releaseTime.parseTimestamp().month == timestamp.parseTimestamp().month)
                    && (releaseRecords[index].releaseTime.parseTimestamp().day == timestamp.parseTimestamp().day)) {
                    exist = true;
                }
            }
        }
        return exist;
    }
// Solidity 0.4.18
// update release amount for single day
// according to dividend rule in https://coinhot.com
function updateReleaseAmount(uint256 timestamp) internal {
        uint256 timeElapse = timestamp.sub(createTime);
        uint256 cycles = timeElapse.div(180 days);
        if (cycles > 0) {
            if (cycles <= 10) {
                releaseAmountPerDay = standardReleaseAmount;
                for (uint index = 0; index < cycles; index++) {
                    releaseAmountPerDay = releaseAmountPerDay.div(2);
                }
            } else {
                releaseAmountPerDay = 0;
            }
        }
    }
// Solidity 0.8.7
/**
 * @dev Function for add arbitrary ERC20 collaterals
 *
 * @param _wrappedTokenId  NFT id from thgis contarct
 * @param _erc20 address of erc20 collateral for add
 * @param _amount amount erc20 collateral for add
 */
function addERC20Collateral(
        uint256 _wrappedTokenId, 
        address _erc20, 
        uint256 _amount
    ) 
        external
        nonReentrant 
    {
        require(ownerOf(_wrappedTokenId) != address(0));
        require(enabledForCollateral(_erc20), "This ERC20 is not enabled for collateral");
        require(
            IERC20(_erc20).balanceOf(msg.sender) >= _amount,
            "Low balance for add collateral"
        );
        require(
            IERC20(_erc20).allowance(msg.sender, address(this)) >= _amount,
            "Please approve first"
        );
        
        ERC20Collateral[] storage e = erc20Collateral[_wrappedTokenId];
        //If collateral  with this _erc20 already exist just update
        if (getERC20CollateralBalance(_wrappedTokenId, _erc20) > 0) {
            for (uint256 i = 0; i < e.length; i ++) {
                if (e[i].erc20Token == _erc20) {
                    e[i].amount += _amount;
                    break;
                }
            }    

        } else {
            //So if we are here hence there is NO that _erc20 in collateral yet 
            //We can add more tokens if limit NOT exccedd
            require(e.length < MAX_ERC20_COUNT, "To much ERC20 tokens in collatteral");
            e.push(ERC20Collateral({
              erc20Token: _erc20, 
              amount: _amount
            }));

        }

        //Move collateral to contract balance
        IERC20(_erc20).safeTransferFrom(msg.sender, address(this), _amount); 
    }