lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/**
 * @notice Creates a new token for `creator`. Its token ID will be automatically
 * assigned (and available on the emitted {IERC721-Transfer} event), and the token
 * URI autogenerated based on the base URI passed at construction.
 *
 * See {ERC721-_safeMint}.
 *
 * On mint, also set the sha256 hashes of the content and its metadata for integrity
 * checks, along with the initial URIs to point to the content and metadata. Attribute
 * the token ID to the creator, mark the content hash as used, and set the bid shares for
 * the media's market.
 *
 * Note that although the content hash must be unique for future mints to prevent duplicate media,
 * metadata has no such requirement.
 */
function _mintForCreator(
        address creator,
        MediaData memory data,
        IMarket.BidShares memory bidShares
    ) internal onlyValidURI(data.tokenURI) onlyValidURI(data.metadataURI) {
        require(data.contentHash != 0, "Media: content hash must be non-zero");
        require(
            _contentHashes[data.contentHash] == false,
            "Media: a token has already been created with this content hash"
        );
        require(
            data.metadataHash != 0,
            "Media: metadata hash must be non-zero"
        );

        uint256 tokenId = _tokenIdTracker.current();

        _safeMint(creator, tokenId);
        _tokenIdTracker.increment();
        _setTokenContentHash(tokenId, data.contentHash);
        _setTokenMetadataHash(tokenId, data.metadataHash);
        _setTokenMetadataURI(tokenId, data.metadataURI);
        _setTokenURI(tokenId, data.tokenURI);
        _creatorTokens[creator].add(tokenId);
        _contentHashes[data.contentHash] = true;

        tokenCreators[tokenId] = creator;
        previousTokenOwners[tokenId] = creator;
        IMarket(marketContract).setBidShares(tokenId, bidShares);
    }
// Solidity 0.6.12
/**
 * @dev Calculates EIP712 DOMAIN_SEPARATOR based on the current contract and chain ID.
 */
function _calculateDomainSeparator() internal view returns (bytes32) {
        uint256 chainID;
        /* solium-disable-next-line */
        assembly {
            chainID := chainid()
        }

        return
            keccak256(
                abi.encode(
                    keccak256(
                        "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
                    ),
                    keccak256(bytes("Arto")),
                    keccak256(bytes("1")),
                    chainID,
                    address(this)
                )
            );
    }
// Solidity 0.7.4
/**
 * @dev Withdraw ERC-20 token of this contract
 */
function withdrawToken(address tokenAddress) external onlyOwner contractActive{
        require(tokenAddress != address(0), "Contract address is zero address");
        require(tokenAddress != address(this), "Can not transfer self token");
        
        IERC20Token tokenContract = IERC20Token(tokenAddress);
        uint tokenBalance = tokenContract.balanceOf(address(this));
        require(tokenBalance > 0, "Balance is zero");
        
        tokenContract.transfer(owner, tokenBalance);
    }
// Solidity 0.7.6
// Withdraw LP tokens or claim rewrads if amount is 0
function withdraw(uint256 _pid, uint256 _amount) public {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(user.amount >= _amount, "withdraw: not good");
        updatePool(_pid);
        uint256 pending = user.amount.mul(pool.accSheeshaPerShare).div(1e12).sub(user.rewardDebt);
        safeSheeshaTransfer(msg.sender, pending);
        if(_amount > 0) {
            uint256 feePercent = 4;
            //2 years
            if(block.timestamp <= user.checkpoint.add(730 days)) {
                //4-> unstake fee interval
                feePercent = uint256(100).sub(getElapsedMonthsCount(user.checkpoint).mul(4));
            }
            uint256 fees = _amount.mul(feePercent).div(100);
            user.amount = user.amount.sub(_amount);
            pool.lpToken.safeTransfer(feeWallet, fees);
            pool.lpToken.safeTransfer(address(msg.sender), _amount.sub(fees));
        }
        user.rewardDebt = user.amount.mul(pool.accSheeshaPerShare).div(1e12);
        emit Withdraw(msg.sender, _pid, _amount);
    }
// Solidity 0.4.24
/**
 * @dev Internal function to remove a token ID from the list of a given address
 * Note that this function is left internal to make ERC721Enumerable possible, but is not
 * intended to be called by custom derived contracts: in particular, it emits no Transfer event,
 * and doesn't clear approvals.
 * @param from address representing the previous owner of the given token ID
 * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
 */
function _removeTokenFrom(address from, uint256 tokenId) internal {
    require(ownerOf(tokenId) == from);
    _ownedTokensCount[from] = _ownedTokensCount[from].sub(1);
    _tokenOwner[tokenId] = address(0);
    // To prevent a gap in the array, we store the last token in the index of the token to delete, and
    // then delete the last slot.
    uint256 tokenIndex = _ownedTokensIndex[tokenId];
    uint256 lastTokenIndex = _ownedTokens[from].length.sub(1);
    uint256 lastToken = _ownedTokens[from][lastTokenIndex];

    _ownedTokens[from][tokenIndex] = lastToken;
    // This also deletes the contents at the last position of the array
    _ownedTokens[from].length--;

    // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
    // be zero. Then we can make sure that we will remove tokenId from the ownedTokens list since we are first swapping
    // the lastToken to the first position, and then dropping the element placed in the last position of the list

    _ownedTokensIndex[tokenId] = 0;
    _ownedTokensIndex[lastToken] = tokenIndex;
  }
// Solidity 0.8.4
///
/// Giveaway
///
function giveaway(address _to, uint256 _amount) external onlyOwner {
        require(tokenCount + _amount <= supply, "Not enough supply");
        require(_amount < giveawaySupply, "Giving away too many NFTs");
        require(_amount > 0, "Amount must be greater than zero");

        _mintPrivate(_to, _amount);
    }
// Solidity 0.6.0
/**
 * @dev burn : To decrease total supply of tokens
 */
function burn(uint256 _amount) public onlyOwner returns (bool) {
        require(_amount >= 0, "Invalid amount");
        require(_amount <= balances[msg.sender], "Insufficient Balance");
        _totalSupply = safeSub(_totalSupply, _amount);
        balances[owner] = safeSub(balances[owner], _amount);
        emit Transfer(owner, address(0), _amount);
        return true;
    }
// Solidity 0.5.17
// deploy a staking reward contract for the staking token, and store the reward amount
// the reward will be distributed to the staking reward contract no sooner than the genesis
function deploy(address stakingToken, address collectionAddress, uint rewardAmount) public onlyOwner {
        StakingRewardsInfo storage info = stakingRewardsInfoByStakingToken[stakingToken];
        require(info.stakingRewards == address(0), 'StakingRewardsFactory::deploy: already deployed');

        info.stakingRewards = address(new StakingRewards(/*_rewardsDistribution=*/ address(this), rewardsToken, stakingToken, collectionAddress));
        info.rewardAmount = rewardAmount;
//        info.collectionAddress = collectionAddress;
        stakingTokens.push(stakingToken);
    }
// Solidity 0.5.17
// notify reward amount for an individual staking token.
// this is a fallback in case the notifyRewardAmounts costs too much gas to call for all contracts
function notifyRewardAmount(address stakingToken) public {
        require(block.timestamp >= stakingRewardsGenesis, 'StakingRewardsFactory::notifyRewardAmount: not ready');

        StakingRewardsInfo storage info = stakingRewardsInfoByStakingToken[stakingToken];
        require(info.stakingRewards != address(0), 'StakingRewardsFactory::notifyRewardAmount: not deployed');

        if (info.rewardAmount > 0) {
            uint rewardAmount = info.rewardAmount;
            info.rewardAmount = 0;

            require(
                IERC20(rewardsToken).transfer(info.stakingRewards, rewardAmount),
                'StakingRewardsFactory::notifyRewardAmount: transfer failed'
            );
            StakingRewards(info.stakingRewards).notifyRewardAmount(rewardAmount);
        }
    }
// Solidity 0.6.12
// calculate price based on pair reserves
function getUSDValue() public view returns(uint256)
    {
     IUniswapV2Pair pair = IUniswapV2Pair(usdPair);

     if(pair.token0() != WETH){
       (uint Res0, uint Res1,) = pair.getReserves();
       // decimals
       uint res1 = Res1 * 1 ether;
       return( res1 / Res0 ); // return amount of token0 needed to buy token1
     }
     else{
       (uint Res1, uint Res0,) = pair.getReserves();
       uint res1 = Res1 * 1 ether;
       return( res1 / Res0 ); // return amount of token0 needed to buy token1
     }
    }
// Solidity 0.5.9
/**
 * @dev Creates an upgradeable proxy
 * @param version representing the first version to be set for the proxy
 * @return address of the new proxy created
 */
function createProxy(
        uint256 version,
        address _primaryOwner,
        address _systemAddress,
        address _authorityAddress,
        address _registryaddress
    ) public onlyOneOfOnwer() returns (address) {
        require(proxyAddress == address(0), "ERR_PROXY_ALREADY_CREATED");

        UpgradeabilityProxy proxy = new UpgradeabilityProxy(version);

        VaultProxyInitializeInterface(address(proxy)).initialize(
            _primaryOwner,
            _systemAddress,
            _authorityAddress,
            _registryaddress
        );

        currentVersion = version;
        proxyAddress = address(proxy);
        emit ProxyCreated(address(proxy));
        return address(proxy);
    }
// Solidity 0.6.9
// ============ DVM Functions (create & add liquidity) ============
function createDODOVendingMachine(
        address baseToken,
        address quoteToken,
        uint256 baseInAmount,
        uint256 quoteInAmount,
        uint256 lpFeeRate,
        uint256 i,
        uint256 k,
        bool isOpenTWAP,
        uint256 deadLine
    )
        external
        override
        payable
        preventReentrant
        judgeExpired(deadLine)
        returns (address newVendingMachine, uint256 shares)
    {
        {
            address _baseToken = baseToken == _ETH_ADDRESS_ ? _WETH_ : baseToken;
            address _quoteToken = quoteToken == _ETH_ADDRESS_ ? _WETH_ : quoteToken;
            newVendingMachine = IDODOV2(_DVM_FACTORY_).createDODOVendingMachine(
                _baseToken,
                _quoteToken,
                lpFeeRate,
                i,
                k,
                isOpenTWAP
            );
        }

        {
            address _baseToken = baseToken;
            address _quoteToken = quoteToken;
            _deposit(
                msg.sender,
                newVendingMachine,
                _baseToken,
                baseInAmount,
                _baseToken == _ETH_ADDRESS_
            );
            _deposit(
                msg.sender,
                newVendingMachine,
                _quoteToken,
                quoteInAmount,
                _quoteToken == _ETH_ADDRESS_
            );
        }

        (shares, , ) = IDODOV2(newVendingMachine).buyShares(msg.sender);
    }
// Solidity 0.4.17
/*
 1 - if the funding of the project Failed, allows investors to claim their locked ether back.
 2 - if the Investor votes NO to a Development Milestone Completion Proposal, where the majority
 also votes NO allows investors to claim their locked ether back.
 3 - project owner misses to set the time for a Development Milestone Completion Meeting allows investors
 to claim their locked ether back.
 */
function canCashBack() public view requireInitialised returns (bool) {

        // case 1
        if(checkFundingStateFailed()) {
            return true;
        }
        // case 2
        if(checkMilestoneStateInvestorVotedNoVotingEndedNo()) {
            return true;
        }
        // case 3
        if(checkOwnerFailedToSetTimeOnMeeting()) {
            return true;
        }

        return false;
    }
// Solidity 0.7.6
/**
 * Sunrise
 **/
function sunrise() external {
        require(!paused(), "Season: Paused.");
        require(seasonTime() > season(), "Season: Still current Season.");

        (
            Decimal.D256 memory beanPrice,
            Decimal.D256 memory usdcPrice
        ) = IOracle(address(this)).capture();
        uint256 price = beanPrice.mul(1e18).div(usdcPrice).asUint256();

        stepGovernance();
        stepSeason();
        snapshotSeason(price);
        stepWeather(price, s.f.soil);
        uint256 increase = stepSun(beanPrice, usdcPrice);
        stepSilo(increase);
        incentivize(msg.sender, C.getAdvanceIncentive());

        LibCheck.balanceCheck();

        emit Sunrise(season());
    }
// Solidity 0.4.24
/**
 * @notice Initialize tap
 * @param _controller                 The address of the controller contract
 * @param _reserve                    The address of the reserve [pool] contract
 * @param _beneficiary                The address of the beneficiary [to whom funds are to be withdrawn]
 * @param _batchBlocks                The number of blocks batches are to last
 * @param _maximumTapRateIncreasePct  The maximum tap rate increase percentage allowed [in PCT_BASE]
 * @param _maximumTapFloorDecreasePct The maximum tap floor decrease percentage allowed [in PCT_BASE]
 */
function initialize(
        IAragonFundraisingController _controller,
        Vault                        _reserve,
        address                      _beneficiary,
        uint256                      _batchBlocks,
        uint256                      _maximumTapRateIncreasePct,
        uint256                      _maximumTapFloorDecreasePct
    )
        external
        onlyInit
    {
        require(isContract(_controller),                                         ERROR_CONTRACT_IS_EOA);
        require(isContract(_reserve),                                            ERROR_CONTRACT_IS_EOA);
        require(_beneficiaryIsValid(_beneficiary),                               ERROR_INVALID_BENEFICIARY);
        require(_batchBlocks != 0,                                               ERROR_INVALID_BATCH_BLOCKS);
        require(_maximumTapFloorDecreasePctIsValid(_maximumTapFloorDecreasePct), ERROR_INVALID_FLOOR_DECREASE_PCT);

        initialized();

        controller = _controller;
        reserve = _reserve;
        beneficiary = _beneficiary;
        batchBlocks = _batchBlocks;
        maximumTapRateIncreasePct = _maximumTapRateIncreasePct;
        maximumTapFloorDecreasePct = _maximumTapFloorDecreasePct;
    }
// Solidity 0.8.4
/**
 * @dev Transfers tokens from sender to the contract.
 * User calls this function when he wants to transfer tokens to another blockchain.
 * @notice User must have approved tokenInAmount of tokenIn
 */
function swapTokensToOtherBlockchain(swapToParams memory params)
        external
        payable
        whenNotPaused
        TransferTo(params, msg.value)
    {
        IERC20 tokenIn = IERC20(params.firstPath[0]);
        if (params.firstPath.length > 1) {
            require(
                tokenIn.transferFrom(
                    msg.sender,
                    address(this),
                    params.tokenInAmount
                ),
                "swapContract: Transfer tokens from sender failed"
            );
            require(
                tokenIn.approve(
                    address(blockchainRouter),
                    params.tokenInAmount
                ),
                "swapContract: tokeinIn approve failed."
            );
            uint256[] memory amounts = blockchainRouter
                .swapTokensForExactTokens(
                    params.exactRBCtokenOut,
                    params.tokenInAmount,
                    params.firstPath,
                    blockchainPool,
                    block.timestamp
                );
            tokenIn.transfer(_msgSender(), params.tokenInAmount - amounts[0]);
            params.tokenInAmount = amounts[0];
        } else {
            require(
                tokenIn.transferFrom(
                    msg.sender,
                    blockchainPool,
                    params.exactRBCtokenOut
                ),
                "swapContract: Transfer tokens from sender failed"
            );
        }
    }
// Solidity 0.8.4
/**
 * @dev Transfers tokens to end user in current blockchain
 */
function swapTokensToUserWithFee(swapFromParams memory params)
        external
        onlyRelayer
        whenNotPaused
        TransferFrom(params)
    {
        uint256 amountWithoutFee = FullMath.mulDiv(
            params.amountWithFee,
            1e6 - feeAmountOfBlockchain[numOfThisBlockchain],
            1e6
        );

        IERC20 RBCToken = IERC20(params.path[0]);

        if (params.path.length == 1) {
            require(
                RBCToken.transferFrom(
                    blockchainPool,
                    params.user,
                    amountWithoutFee
                ),
                "swapContract: transfer from pool failed"
            );
            require(
                RBCToken.transferFrom(
                    blockchainPool,
                    blockchainFeeAddress,
                    params.amountWithFee - amountWithoutFee
                ),
                "swapContract: fee transfer failed"
            );
        } else {
            require(
                RBCToken.transferFrom(
                    blockchainPool,
                    address(this),
                    amountWithoutFee
                ),
                "swapContract: transfer from pool failed"
            );
            require(
                RBCToken.transferFrom(
                    blockchainPool,
                    blockchainFeeAddress,
                    params.amountWithFee - amountWithoutFee
                ),
                "swapContract: fee transfer failed"
            );
            blockchainRouter.swapExactTokensForTokens(
                amountWithoutFee,
                params.amountOutMin,
                params.path,
                params.user,
                block.timestamp
            );
        }
        emit TransferFromOtherBlockchain(
            params.user,
            params.amountWithFee,
            amountWithoutFee,
            params.originalTxHash
        );
    }
// Solidity 0.8.4
/**
 * @dev Swaps RBC from pool to initially spent by user tokens and transfers him
 * @notice There is used the same structure as in other similar functions but amountOutMin should be
 * equal to the amount of tokens initially spent by user (we are refunding them), AmountWithFee should
 * be equal to the amount of RBC tokens that the pool got after the first swap (RBCAmountIn in the event)
 * hashedParams of this originalTxHash
 */
function refundTokensToUser(swapFromParams memory params)
        external
        onlyRelayer
        whenNotPaused
        TransferFrom(params)
    {
        IERC20 RBCToken = IERC20(params.path[0]);

        if (params.path.length == 1) {
            require(
                RBCToken.transferFrom(
                    blockchainPool,
                    params.user,
                    params.amountOutMin
                ),
                "swapContract: transfer from pool failed"
            );
            emit userRefunded(
                params.user,
                params.amountOutMin,
                params.amountOutMin,
                params.originalTxHash
            );
        } else {
            uint256 amountIn = FullMath.mulDiv(
                params.amountWithFee,
                1e6 + refundSlippage,
                1e6
            );

            require(
                RBCToken.transferFrom(blockchainPool, address(this), amountIn),
                "swapContract: transfer from pool failed"
            );

            uint256 RBCSpent = blockchainRouter.swapTokensForExactTokens(
                params.amountOutMin,
                amountIn,
                params.path,
                params.user,
                block.timestamp
            )[0];

            require(
                RBCToken.transfer(blockchainPool, amountIn - RBCSpent),
                "swapContract: remaining RBC transfer to pool failed"
            );
            emit userRefunded(
                params.user,
                RBCSpent,
                RBCSpent,
                params.originalTxHash
            );
        }
    }
// Solidity 0.8.4
/**
 * @dev Registers another blockchain for availability to swap
 * @param numOfOtherBlockchain number of blockchain
 */
function addOtherBlockchain(uint128 numOfOtherBlockchain)
        external
        onlyOwner
    {
        require(
            numOfOtherBlockchain != numOfThisBlockchain,
            "swapContract: Cannot add this blockchain to array of other blockchains"
        );
        require(
            !existingOtherBlockchain[numOfOtherBlockchain],
            "swapContract: This blockchain is already added"
        );
        existingOtherBlockchain[numOfOtherBlockchain] = true;
    }
// Solidity 0.8.4
/**
 * @dev Change existing blockchain id
 * @param oldNumOfOtherBlockchain number of existing blockchain
 * @param newNumOfOtherBlockchain number of new blockchain
 */
function changeOtherBlockchain(
        uint128 oldNumOfOtherBlockchain,
        uint128 newNumOfOtherBlockchain
    ) external onlyOwner {
        require(
            oldNumOfOtherBlockchain != newNumOfOtherBlockchain,
            "swapContract: Cannot change blockchains with same number"
        );
        require(
            newNumOfOtherBlockchain != numOfThisBlockchain,
            "swapContract: Cannot add this blockchain to array of other blockchains"
        );
        require(
            existingOtherBlockchain[oldNumOfOtherBlockchain],
            "swapContract: This blockchain was not added"
        );
        require(
            !existingOtherBlockchain[newNumOfOtherBlockchain],
            "swapContract: This blockchain is already added"
        );

        existingOtherBlockchain[oldNumOfOtherBlockchain] = false;
        existingOtherBlockchain[newNumOfOtherBlockchain] = true;
    }
// Solidity 0.8.4
/**
 * @dev Transfers permissions of contract ownership.
 * Will setup new owner and one manager on contract.
 * Main purpose of this function is to transfer ownership from deployer account ot real owner
 * @param newOwner Address of new owner
 * @param newManager Address of new manager
 */
function transferOwnerAndSetManager(address newOwner, address newManager)
        external
        onlyOwner
    {
        require(
            newOwner != _msgSender(),
            "swapContract: New owner must be different than current"
        );
        require(
            newOwner != address(0x0),
            "swapContract: Owner cannot be zero address"
        );
        require(
            newManager != address(0x0),
            "swapContract: Owner cannot be zero address"
        );
        _setupRole(DEFAULT_ADMIN_ROLE, newOwner);
        _setupRole(OWNER_ROLE, newOwner);
        _setupRole(MANAGER_ROLE, newManager);
        renounceRole(OWNER_ROLE, _msgSender());
        renounceRole(DEFAULT_ADMIN_ROLE, _msgSender());
    }