lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.14
/**  @notice A distinct Uniform Resource Identifier (URI) for a given asset.
 * @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
 *  3986. The URI may point to a JSON file that conforms to the "ERC721
 *  Metadata JSON Schema".
 * https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md
 */
function tokenURI(
    uint256 _tokenId
  ) external
    view
    isKey(_tokenId)
    returns(string memory)
  {
    string memory URI;
    if(bytes(baseTokenURI).length == 0) {
      URI = unlockProtocol.globalBaseTokenURI();
    } else {
      URI = baseTokenURI;
    }

    return URI.strConcat(
      address(this).address2Str(),
      '/',
      _tokenId.uint2Str()
    );
  }
// Solidity 0.5.14
/**
 * Ensures that the msg.sender has paid at least the price stated.
 *
 * With ETH, this means the function originally called was `payable` and the
 * transaction included at least the amount requested.
 *
 * Security: be wary of re-entrancy when calling this function.
 */
function _chargeAtLeast(
    uint _price
  ) internal returns (uint)
  {
    if(_price > 0) {
      if(tokenAddress == address(0)) {
        require(msg.value >= _price, 'NOT_ENOUGH_FUNDS');
        return msg.value;
      } else {
        IERC20 token = IERC20(tokenAddress);
        token.safeTransferFrom(msg.sender, address(this), _price);
        return _price;
      }
    }
  }
// Solidity 0.5.14
/**
 * Transfers funds from the contract to the account provided.
 *
 * Security: be wary of re-entrancy when calling this function.
 */
function _transfer(
    address _tokenAddress,
    address _to,
    uint _amount
  ) internal
  {
    if(_amount > 0) {
      if(_tokenAddress == address(0)) {
        // https://diligence.consensys.net/blog/2019/09/stop-using-soliditys-transfer-now/
        address(uint160(_to)).sendValue(_amount);
      } else {
        IERC20 token = IERC20(_tokenAddress);
        token.safeTransfer(_to, _amount);
      }
    }
  }
// Solidity 0.8.6
/**
 * @notice Validate a transmission
 * @dev Must be called by either the `s_currentAggregator.target`, or the `s_proposedAggregator`.
 * If called by the `s_currentAggregator.target` this function passes the call on to the `s_currentValidator.target`
 * and the `s_proposedValidator`, if it is set.
 * If called by the `s_proposedAggregator` this function emits a `ProposedAggregatorValidateCall` to signal that
 * the call was received.
 * @dev To guard against external `validate` calls reverting, we use raw calls here.
 * We favour `call` over try-catch to ensure that failures are avoided even if the validator address is incorrectly
 * set as a non-contract address.
 * @dev If the `aggregator` and `validator` are the same contract or collude, this could exhibit reentrancy behavior.
 * However, since that contract would have to be explicitly written for reentrancy and that the `owner` would have
 * to configure this contract to use that malicious contract, we refrain from using mutex or check here.
 * @dev This does not perform any checks on any roundId, so it is possible that a validator receive different reports
 * for the same roundId at different points in time. Validator implementations should be aware of this.
 * @param previousRoundId uint256
 * @param previousAnswer int256
 * @param currentRoundId uint256
 * @param currentAnswer int256
 * @return bool
 */
function validate(
    uint256 previousRoundId,
    int256 previousAnswer,
    uint256 currentRoundId,
    int256 currentAnswer
  ) external override returns (bool) {
    address currentAggregator = s_currentAggregator.target;
    if (msg.sender != currentAggregator) {
      address proposedAggregator = s_proposedAggregator;
      require(msg.sender == proposedAggregator, "Not a configured aggregator");
      // If the aggregator is still in proposed state, emit an event and don't push to any validator.
      // This is to confirm that `validate` is being called prior to upgrade.
      emit ProposedAggregatorValidateCall(
        proposedAggregator,
        previousRoundId,
        previousAnswer,
        currentRoundId,
        currentAnswer
      );
      return true;
    }

    // Send the validate call to the current validator
    ValidatorConfiguration memory currentValidator = s_currentValidator;
    address currentValidatorAddress = address(currentValidator.target);
    require(currentValidatorAddress != address(0), "No validator set");
    currentValidatorAddress.call(
      abi.encodeWithSelector(
        AggregatorValidatorInterface.validate.selector,
        previousRoundId,
        previousAnswer,
        currentRoundId,
        currentAnswer
      )
    );
    // If there is a new proposed validator, send the validate call to that validator also
    if (currentValidator.hasNewProposal) {
      address(s_proposedValidator).call(
        abi.encodeWithSelector(
          AggregatorValidatorInterface.validate.selector,
          previousRoundId,
          previousAnswer,
          currentRoundId,
          currentAnswer
        )
      );
    }
    return true;
  }
// Solidity 0.8.6
/**
 * @notice Propose an aggregator
 * @dev A zero address can be used to unset the proposed aggregator. Only owner can call.
 * @param proposed address
 */
function proposeNewAggregator(address proposed) external onlyOwner {
    require(s_proposedAggregator != proposed && s_currentAggregator.target != proposed, "Invalid proposal");
    s_proposedAggregator = proposed;
    // If proposed is zero address, hasNewProposal = false
    s_currentAggregator.hasNewProposal = (proposed != address(0));
    emit AggregatorProposed(proposed);
  }
// Solidity 0.8.6
/**
 * @notice Upgrade the aggregator by setting the current aggregator as the proposed aggregator.
 * @dev Must have a proposed aggregator. Only owner can call.
 */
function upgradeAggregator() external onlyOwner {
    // Get configuration in memory
    AggregatorConfiguration memory current = s_currentAggregator;
    address previous = current.target;
    address proposed = s_proposedAggregator;

    // Perform the upgrade
    require(current.hasNewProposal, "No proposal");
    s_currentAggregator = AggregatorConfiguration({target: proposed, hasNewProposal: false});
    delete s_proposedAggregator;

    emit AggregatorUpgraded(previous, proposed);
  }
// Solidity 0.7.0
// Reserves 30 planets
function reservePlanets() public onlyOwner {        
        uint supply = totalSupply();
        uint i;
        for (i = 0; i < 30; i++) {
            _safeMint(msg.sender, supply + i);
            count += 1;
        }
        emit Increment(msg.sender);
    }
// Solidity 0.8.7
//public mint function
function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) {
        require(!paused, "The contract is paused!");
        require(!isWhiteListActive, "Whitelist minting is still active!");

        if(msg.sender != owner()) {
            require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTx, "Exceeded Allowed Amount per TX!");
            require(tokenAmountofWallet[msg.sender] + _mintAmount <= maxMintAmountPerWallet, "Exceeded Allowed Amount per Address!");
            require(msg.value >= cost * _mintAmount, "Insufficient funds!");
        }

        tokenAmountofWallet[msg.sender] += _mintAmount;
        _mintLoop(msg.sender, _mintAmount);
    }
// Solidity 0.8.7
// whitelist mint function
function whiteListMint(uint256 _mintAmount, bytes32[] calldata proof) public payable mintCompliance(_mintAmount) {
        require(!paused, "The contract is paused!");
        require(isWhiteListActive, "Whitelist minting isn't active anymore!");
        require(
            MerkleProof.verify(proof, merkleRoot, generateMerkleLeaf(msg.sender)),
            "User is not allowed to mint during this phase!"
        );

        if(msg.sender != owner()) {
            require(_mintAmount > 0 && _mintAmount <= maxMintAmountPerTxforWL, "Exceeded Allowed Amount per TX!");
            require(tokenAmountofWallet[msg.sender] + _mintAmount <= maxMintAmountPerWalletforWL, "Exceeded Allowed Amount per Address!");
            require(msg.value >= costWhitelist * _mintAmount, "Insufficient funds!");
        }

        tokenAmountofWallet[msg.sender] += _mintAmount;
        _mintLoop(msg.sender, _mintAmount);
    }
// Solidity 0.8.7
//call contract owner & id owner function
function walletOfOwner(address _owner)
        public
        view
        returns (uint256[] memory)
    {
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
        uint256 currentTokenId = 1;
        uint256 ownedTokenIndex = 0;

        while (ownedTokenIndex < ownerTokenCount && currentTokenId <= maxSupply) {
            address currentTokenOwner = ownerOf(currentTokenId);
                if (currentTokenOwner == _owner) {
                    ownedTokenIds[ownedTokenIndex] = currentTokenId;
                    ownedTokenIndex++;
                }

            currentTokenId++;
        }

        return ownedTokenIds;
    }
// Solidity 0.8.7
//call URL of token function
function tokenURI(uint256 _tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(
            _exists(_tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        if (revealed == false) {
            return hiddenMetadataUri;
        }

        string memory currentBaseURI = _baseURI();
            return bytes(currentBaseURI).length > 0
                ? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
                : "";
    }
// Solidity 0.8.7
//withdraw function
function withdraw() public onlyOwner {
        //50% goes to community wallet
        (bool hs, ) = payable(0xfc2f6C88Da2045846EbE84ede4dA3b3D9da1B87F).call{value: address(this).balance * 50 / 100}("");
        require(hs);
        //rest to team wallet
        (bool os, ) = payable(owner()).call{value: address(this).balance}("");
        require(os);
    }
// Solidity 0.7.6
/* pure functions */
function calculateTotalStakeUnits(StakeData[] memory stakes, uint256 timestamp)
        public
        pure
        override
        returns (uint256 totalStakeUnits)
    {
        for (uint256 index; index < stakes.length; index++) {
            // reference stake
            StakeData memory stakeData = stakes[index];
            // calculate stake units
            uint256 stakeUnits =
                calculateStakeUnits(stakeData.amount, stakeData.timestamp, timestamp);
            // add to running total
            totalStakeUnits = totalStakeUnits.add(stakeUnits);
        }
    }
// Solidity 0.7.6
/// @notice Add funds to the Hypervisor
/// access control: only admin
/// state machine:
///   - can be called multiple times
///   - only online
/// state scope:
///   - increase _hypervisor.rewardSharesOutstanding
///   - append to _hypervisor.rewardSchedules
/// token transfer: transfer staking tokens from msg.sender to reward pool
/// @param amount uint256 Amount of reward tokens to deposit
/// @param duration uint256 Duration over which to linearly unlock rewards
function fund(uint256 amount, uint256 duration) external onlyOwner onlyOnline {
        // validate duration
        require(duration != 0, "Hypervisor: invalid duration");

        // create new reward shares
        // if existing rewards on this Hypervisor
        //   mint new shares proportional to % change in rewards remaining
        //   newShares = remainingShares * newReward / remainingRewards
        // else
        //   mint new shares with BASE_SHARES_PER_WEI initial conversion rate
        //   store as fixed point number with same  of decimals as reward token
        uint256 newRewardShares;
        if (_hypervisor.rewardSharesOutstanding > 0) {
            uint256 remainingRewards = IERC20(_hypervisor.rewardToken).balanceOf(_hypervisor.rewardPool);
            newRewardShares = _hypervisor.rewardSharesOutstanding.mul(amount).div(remainingRewards);
        } else {
            newRewardShares = amount.mul(BASE_SHARES_PER_WEI);
        }

        // add reward shares to total
        _hypervisor.rewardSharesOutstanding = _hypervisor.rewardSharesOutstanding.add(newRewardShares);

        // store new reward schedule
        _hypervisor.rewardSchedules.push(RewardSchedule(duration, block.timestamp, newRewardShares));

        // transfer reward tokens to reward pool
        TransferHelper.safeTransferFrom(
            _hypervisor.rewardToken,
            msg.sender,
            _hypervisor.rewardPool,
            amount
        );

        // emit event
        emit HypervisorFunded(amount, duration);
    }
// Solidity 0.7.6
/// @notice Register bonus token for distribution
/// @dev use this function to enable distribution of any ERC20 held by the RewardPool contract
/// access control: only admin
/// state machine:
///   - can be called multiple times
///   - only online
/// state scope:
///   - append to _bonusTokenSet
/// token transfer: none
/// @param bonusToken address The address of the bonus token
function registerBonusToken(address bonusToken) external onlyOwner onlyOnline {
        // verify valid bonus token
        _validateAddress(bonusToken);

        // verify bonus token count
        require(_bonusTokenSet.length() < MAX_REWARD_TOKENS, "Hypervisor: max bonus tokens reached ");

        // add token to set
        assert(_bonusTokenSet.add(bonusToken));

        // emit event
        emit BonusTokenRegistered(bonusToken);
    }
// Solidity 0.7.6
/// @notice Rescue tokens from RewardPool
/// @dev use this function to rescue tokens from RewardPool contract
///      without distributing to stakers or triggering emergency shutdown
/// access control: only admin
/// state machine:
///   - can be called multiple times
///   - only online
/// state scope: none
/// token transfer: transfer requested token from RewardPool to recipient
/// @param token address The address of the token to rescue
/// @param recipient address The address of the recipient
/// @param amount uint256 The amount of tokens to rescue
function rescueTokensFromRewardPool(
        address token,
        address recipient,
        uint256 amount
    ) external onlyOwner onlyOnline {
        // verify recipient
        _validateAddress(recipient);

        // check not attempting to unstake reward token
        require(token != _hypervisor.rewardToken, "Hypervisor: invalid address");

        // check not attempting to wthdraw bonus token
        require(!_bonusTokenSet.contains(token), "Hypervisor: invalid address");

        // transfer tokens to recipient
        IRewardPool(_hypervisor.rewardPool).sendERC20(token, recipient, amount);
    }
// Solidity 0.7.6
/// @notice Stake tokens
/// @dev anyone can stake to any vault if they have valid permission
/// access control: anyone
/// state machine:
///   - can be called multiple times
///   - only online
///   - when vault exists on this Hypervisor
/// state scope:
///   - append to _vaults[vault].stakes
///   - increase _vaults[vault].totalStake
///   - increase _hypervisor.totalStake
///   - increase _hypervisor.totalStakeUnits
///   - increase _hypervisor.lastUpdate
/// token transfer: transfer staking tokens from msg.sender to vault
/// @param vault address The address of the vault to stake from
/// @param amount uint256 The amount of staking tokens to stake
function stake(
        address vault,
        uint256 amount,
        bytes calldata permission
    ) external override onlyOnline {
        // verify vault is valid
        require(isValidVault(vault), "Hypervisor: vault is not registered");

        // verify non-zero amount
        require(amount != 0, "Hypervisor: no amount staked");

        // fetch vault storage reference
        VaultData storage vaultData = _vaults[vault];

        // verify stakes boundary not reached
        require(
            vaultData.stakes.length < MAX_STAKES_PER_VAULT,
            "Hypervisor: MAX_STAKES_PER_VAULT reached"
        );

        // update cached sum of stake units across all vaults
        _updateTotalStakeUnits();

        // store amount and timestamp
        vaultData.stakes.push(StakeData(amount, block.timestamp));

        // update cached total vault and Hypervisor amounts
        vaultData.totalStake = vaultData.totalStake.add(amount);
        _hypervisor.totalStake = _hypervisor.totalStake.add(amount);

        // call lock on vault
        IUniversalVault(vault).lock(_hypervisor.stakingToken, amount, permission);

        // emit event
        emit Staked(vault, amount);
    }
// Solidity 0.7.6
/// @notice Exit Hypervisor without claiming reward
/// @dev This function should never revert when correctly called by the vault.
///      A max number of stakes per vault is set with MAX_STAKES_PER_VAULT to
///      place an upper bound on the for loop in calculateTotalStakeUnits().
/// access control: only callable by the vault directly
/// state machine:
///   - when vault exists on this Hypervisor
///   - when active stake from this vault
///   - any power state
/// state scope:
///   - decrease _hypervisor.totalStake
///   - increase _hypervisor.lastUpdate
///   - modify _hypervisor.totalStakeUnits
///   - delete _vaults[vault]
/// token transfer: none
function rageQuit() external override {
        // fetch vault storage reference
        VaultData storage _vaultData = _vaults[msg.sender];

        // revert if no active stakes
        require(_vaultData.stakes.length != 0, "Hypervisor: no stake");

        // update cached sum of stake units across all vaults
        _updateTotalStakeUnits();

        // emit event
        emit Unstaked(msg.sender, _vaultData.totalStake);

        // update cached totals
        _hypervisor.totalStake = _hypervisor.totalStake.sub(_vaultData.totalStake);
        _hypervisor.totalStakeUnits = _hypervisor.totalStakeUnits.sub(
            calculateTotalStakeUnits(_vaultData.stakes, block.timestamp)
        );

        // delete stake data
        delete _vaults[msg.sender];
    }
// Solidity 0.4.26
/**
 * @dev returns the expected target amount of converting one reserve to another along with the fee
 *
 * @param _sourceToken contract address of the source reserve token
 * @param _targetToken contract address of the target reserve token
 * @param _amount      amount of tokens received from the user
 *
 * @return expected target amount
 * @return expected fee
 */
function targetAmountAndFee(IERC20Token _sourceToken, IERC20Token _targetToken, uint256 _amount)
        public
        view
        active
        validReserve(_sourceToken)
        validReserve(_targetToken)
        returns (uint256, uint256)
    {
        // validate input
        require(_sourceToken != _targetToken, "ERR_SAME_SOURCE_TARGET");

        uint256 amount = IBancorFormula(addressOf(BANCOR_FORMULA)).crossReserveTargetAmount(
            reserveBalance(_sourceToken),
            reserves[_sourceToken].weight,
            reserveBalance(_targetToken),
            reserves[_targetToken].weight,
            _amount
        );

        // return the amount minus the conversion fee and the conversion fee
        uint256 fee = calculateFee(amount);
        return (amount - fee, fee);
    }
// Solidity 0.4.26
/**
 * @dev converts a specific amount of source tokens to target tokens
 * can only be called by the bancor network contract
 *
 * @param _sourceToken source ERC20 token
 * @param _targetToken target ERC20 token
 * @param _amount      amount of tokens to convert (in units of the source token)
 * @param _trader      address of the caller who executed the conversion
 * @param _beneficiary wallet to receive the conversion result
 *
 * @return amount of tokens received (in units of the target token)
 */
function doConvert(IERC20Token _sourceToken, IERC20Token _targetToken, uint256 _amount, address _trader, address _beneficiary)
        internal
        returns (uint256)
    {
        // get expected target amount and fee
        (uint256 amount, uint256 fee) = targetAmountAndFee(_sourceToken, _targetToken, _amount);

        // ensure that the trade gives something in return
        require(amount != 0, "ERR_ZERO_TARGET_AMOUNT");

        // ensure that the trade won't deplete the reserve balance
        uint256 targetReserveBalance = reserveBalance(_targetToken);
        assert(amount < targetReserveBalance);

        // ensure that the input amount was already deposited
        if (_sourceToken == ETH_RESERVE_ADDRESS)
            require(msg.value == _amount, "ERR_ETH_AMOUNT_MISMATCH");
        else
            require(msg.value == 0 && _sourceToken.balanceOf(this).sub(reserveBalance(_sourceToken)) >= _amount, "ERR_INVALID_AMOUNT");

        // sync the reserve balances
        syncReserveBalance(_sourceToken);
        reserves[_targetToken].balance = reserves[_targetToken].balance.sub(amount);

        // transfer funds to the beneficiary in the to reserve token
        if (_targetToken == ETH_RESERVE_ADDRESS)
            _beneficiary.transfer(amount);
        else
            safeTransfer(_targetToken, _beneficiary, amount);

        // dispatch the conversion event
        dispatchConversionEvent(_sourceToken, _targetToken, _trader, _amount, amount, fee);

        // dispatch rate updates
        dispatchRateEvents(_sourceToken, _targetToken);

        return amount;
    }
// Solidity 0.4.26
/**
 * @dev decreases the pool's liquidity and burns the caller's shares in the pool
 * note that prior to version 28, you should use 'liquidate' instead
 *
 * @param _amount                  token amount
 * @param _reserveTokens           address of each reserve token
 * @param _reserveMinReturnAmounts minimum return-amount of each reserve token
 */
function removeLiquidity(uint256 _amount, IERC20Token[] memory _reserveTokens, uint256[] memory _reserveMinReturnAmounts)
        public
        protected
        active
    {
        // verify the user input
        verifyLiquidityInput(_reserveTokens, _reserveMinReturnAmounts, _amount);

        // get the total supply BEFORE destroying the user tokens
        uint256 totalSupply = ISmartToken(anchor).totalSupply();

        // destroy the user tokens
        ISmartToken(anchor).destroy(msg.sender, _amount);

        // transfer to the user an equivalent amount of each one of the reserve tokens
        removeLiquidityFromPool(_reserveTokens, _reserveMinReturnAmounts, totalSupply, _amount);
    }
// Solidity 0.4.26
/**
 * @dev decreases the pool's liquidity and burns the caller's shares in the pool
 * for example, if the holder sells 10% of the supply,
 * then they will receive 10% of each reserve token balance in return
 * note that starting from version 28, you should use 'removeLiquidity' instead
 *
 * @param _amount  amount to liquidate (in the pool token)
 */
function liquidate(uint256 _amount) public protected {
        require(_amount > 0, "ERR_ZERO_AMOUNT");

        uint256 totalSupply = ISmartToken(anchor).totalSupply();
        ISmartToken(anchor).destroy(msg.sender, _amount);

        uint256[] memory reserveMinReturnAmounts = new uint256[](reserveTokens.length);
        for (uint256 i = 0; i < reserveMinReturnAmounts.length; i++)
            reserveMinReturnAmounts[i] = 1;

        removeLiquidityFromPool(reserveTokens, reserveMinReturnAmounts, totalSupply, _amount);
    }