lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.12
/**
 * @dev deposit in one tx, without waiting complete by dev
 * @return Returns amount of lpShares minted for user
 * @param amounts - user send amounts of stablecoins to deposit
 * @param pid - number of the pool to which the deposit goes
 */
function deposit(uint256[3] memory amounts, uint256 pid)
        external
        whenNotPaused
        startedPool(pid)
        returns (uint256)
    {
        IStrategy strategy = poolInfo[pid].strategy;
        uint256 holdings = totalHoldings();

        for (uint256 i = 0; i < amounts.length; i++) {
            if (amounts[i] > 0) {
                IERC20Metadata(tokens[i]).safeTransferFrom(
                    _msgSender(),
                    address(strategy),
                    amounts[i]
                );
            }
        }
        uint256 newDeposited = strategy.deposit(amounts);
        require(newDeposited > 0, 'Zunami: too low deposit!');

        uint256 lpShares = 0;
        if (totalSupply() == 0) {
            lpShares = newDeposited;
        } else {
            lpShares = (totalSupply() * newDeposited) / holdings;
        }
        _mint(_msgSender(), lpShares);
        poolInfo[pid].lpShares += lpShares;
        totalDeposited += newDeposited;

        emit Deposited(_msgSender(), amounts, lpShares);
        return lpShares;
    }
// Solidity 0.8.12
/**
 * @dev withdraw in one tx, without waiting complete by dev
 * @param lpShares - amount of ZLP for withdraw
 * @param minAmounts -  array of amounts stablecoins that user want minimum receive
 * @param pid - number of the pool from which the funds are withdrawn
 */
function withdraw(
        uint256 lpShares,
        uint256[3] memory minAmounts,
        uint256 pid
    ) external whenNotPaused startedPool(pid) {
        IStrategy strategy = poolInfo[pid].strategy;
        address userAddr = _msgSender();

        require(balanceOf(userAddr) >= lpShares, 'Zunami: not enough LP balance');
        require(
            strategy.withdraw(userAddr, lpShares, poolInfo[pid].lpShares, minAmounts),
            'Zunami: user lps share should be at least required'
        );

        uint256 userDeposit = (totalDeposited * lpShares) / totalSupply();
        _burn(userAddr, lpShares);
        poolInfo[pid].lpShares -= lpShares;

        totalDeposited -= userDeposit;

        emit Withdrawn(userAddr, minAmounts, lpShares);
    }
// Solidity 0.4.25
/**
 @notice Check if a certain address is whitelisted to read sensitive information in the storage layer
 @dev if the address is an account, it is allowed to read. If the address is a contract, it has to be in the whitelist
 */
function senderIsAllowedToRead()
        internal
        view
        returns (bool _senderIsAllowedToRead)
    {
        // msg.sender is allowed to read only if its an EOA or a whitelisted contract
        _senderIsAllowedToRead = (msg.sender == tx.origin) || daoWhitelistingStorage().whitelist(msg.sender);
    }
// Solidity 0.4.25
/**
 @notice Calculate the start of a specific milestone of a specific proposal.
 @dev This is calculated from the voting start of the voting round preceding the milestone
 This would throw if the voting start is 0 (the voting round has not started yet)
 Note that if the milestoneIndex is exactly the same as the number of milestones,
 This will just return the end of the last voting round.
 */
function startOfMilestone(bytes32 _proposalId, uint256 _milestoneIndex)
        internal
        view
        returns (uint256 _milestoneStart)
    {
        uint256 _startOfPrecedingVotingRound = daoStorage().readProposalVotingTime(_proposalId, _milestoneIndex);
        require(_startOfPrecedingVotingRound > 0);
        // the preceding voting round must have started

        if (_milestoneIndex == 0) { // This is the 1st milestone, which starts after voting round 0
            _milestoneStart =
                _startOfPrecedingVotingRound
                .add(getUintConfig(CONFIG_VOTING_PHASE_TOTAL));
        } else { // if its the n-th milestone, it starts after voting round n-th
            _milestoneStart =
                _startOfPrecedingVotingRound
                .add(getUintConfig(CONFIG_INTERIM_PHASE_TOTAL));
        }
    }
// Solidity 0.4.25
/**
 @notice Calculate the actual voting start for a voting round, given the tentative start
 @dev The tentative start is the ideal start. For example, when a proposer finish a milestone, it should be now
 However, sometimes the tentative start is too close to the end of the quarter, hence, the actual voting start should be pushed to the next quarter
 */
function getTimelineForNextVote(
        uint256 _index,
        uint256 _tentativeVotingStart
    )
        internal
        view
        returns (uint256 _actualVotingStart)
    {
        uint256 _timeLeftInQuarter = getTimeLeftInQuarter(_tentativeVotingStart);
        uint256 _votingDuration = getUintConfig(_index == 0 ? CONFIG_VOTING_PHASE_TOTAL : CONFIG_INTERIM_PHASE_TOTAL);
        _actualVotingStart = _tentativeVotingStart;
        if (timeInQuarter(_tentativeVotingStart) < getUintConfig(CONFIG_LOCKING_PHASE_DURATION)) { // if the tentative start is during a locking phase
            _actualVotingStart = _tentativeVotingStart.add(
                getUintConfig(CONFIG_LOCKING_PHASE_DURATION).sub(timeInQuarter(_tentativeVotingStart))
            );
        } else if (_timeLeftInQuarter < _votingDuration.add(getUintConfig(CONFIG_VOTE_CLAIMING_DEADLINE))) { // if the time left in quarter is not enough to vote and claim voting
            _actualVotingStart = _tentativeVotingStart.add(
                _timeLeftInQuarter.add(getUintConfig(CONFIG_LOCKING_PHASE_DURATION)).add(1)
            );
        }
    }
// Solidity 0.4.25
/**
 @notice Migrate this DAO to a new DAO contract
 @dev This is the second step of the 2-step migration
 Migration can only be done during the locking phase, after the global rewards for current quarter are set.
 This is to make sure that there is no rewards calculation pending before the DAO is migrated to new contracts
 The addresses of the new Dao contracts have to be provided again, and be double checked against the addresses that were set in setNewDaoContracts()
 @param _newDaoContract Address of the new DAO contract
 @param _newDaoFundingManager Address of the new DaoFundingManager contract, which would receive the remaining ETHs in this DaoFundingManager
 @param _newDaoRewardsManager Address of the new daoRewardsManager contract, which would receive the claimableDGXs from this daoRewardsManager
 */
function migrateToNewDao(
        address _newDaoContract,
        address _newDaoFundingManager,
        address _newDaoRewardsManager
    )
        public
        if_root()
        ifGlobalRewardsSet(currentQuarterNumber())
    {
        require(isLockingPhase());
        require(daoUpgradeStorage().isReplacedByNewDao() == false);
        require(
          (daoUpgradeStorage().newDaoContract() == _newDaoContract) &&
          (daoUpgradeStorage().newDaoFundingManager() == _newDaoFundingManager) &&
          (daoUpgradeStorage().newDaoRewardsManager() == _newDaoRewardsManager)
        );
        daoUpgradeStorage().updateForDaoMigration();
        daoFundingManager().moveFundsToNewDao(_newDaoFundingManager);
        daoRewardsManager().moveDGXsToNewDao(_newDaoRewardsManager);
        emit MigrateToNewDao(_newDaoContract, _newDaoFundingManager, _newDaoRewardsManager);
    }
// Solidity 0.4.25
/**
 @notice Submit a new preliminary idea / Pre-proposal
 @dev The proposer has to send in a collateral == getUintConfig(CONFIG_PREPROPOSAL_COLLATERAL)
 which he could claim back in these scenarios:
 - Before the proposal is finalized, by calling closeProposal()
 - After all milestones are done and the final voting round is passed
 
 @param _docIpfsHash Hash of the IPFS doc containing details of proposal
 @param _milestonesFundings Array of fundings of the proposal milestones (in wei)
 @param _finalReward Final reward asked by proposer at successful completion of all milestones of proposal
 */
function submitPreproposal(
        bytes32 _docIpfsHash,
        uint256[] _milestonesFundings,
        uint256 _finalReward
    )
        external
        payable
    {
        senderCanDoProposerOperations();
        bool _isFounder = is_founder();

        require(MathHelper.sumNumbers(_milestonesFundings).add(_finalReward) <= weiInDao());

        require(msg.value == getUintConfig(CONFIG_PREPROPOSAL_COLLATERAL));
        require(address(daoFundingManager()).call.gas(25000).value(msg.value)());

        checkNonDigixFundings(_milestonesFundings, _finalReward);

        daoStorage().addProposal(_docIpfsHash, msg.sender, _milestonesFundings, _finalReward, _isFounder);
        daoStorage().setProposalCollateralStatus(_docIpfsHash, COLLATERAL_STATUS_UNLOCKED);
        daoStorage().setProposalCollateralAmount(_docIpfsHash, msg.value);

        emit NewProposal(_docIpfsHash, msg.sender);
    }
// Solidity 0.4.25
/**
 @notice Modify a proposal (this can be done only before setting the final version)
 @param _proposalId Proposal ID (hash of IPFS doc of the first version of the proposal)
 @param _docIpfsHash Hash of IPFS doc of the modified version of the proposal
 @param _milestonesFundings Array of fundings of the modified version of the proposal (in wei)
 @param _finalReward Final reward on successful completion of all milestones of the modified version of proposal (in wei)
 */
function modifyProposal(
        bytes32 _proposalId,
        bytes32 _docIpfsHash,
        uint256[] _milestonesFundings,
        uint256 _finalReward
    )
        external
    {
        senderCanDoProposerOperations();
        require(isFromProposer(_proposalId));

        require(isEditable(_proposalId));
        bytes32 _currentState;
        (,,,_currentState,,,,,,) = daoStorage().readProposal(_proposalId);
        require(_currentState == PROPOSAL_STATE_PREPROPOSAL ||
          _currentState == PROPOSAL_STATE_DRAFT);

        checkNonDigixFundings(_milestonesFundings, _finalReward);

        daoStorage().editProposal(_proposalId, _docIpfsHash, _milestonesFundings, _finalReward);

        emit ModifyProposal(_proposalId, _docIpfsHash);
    }
// Solidity 0.4.25
/**
 @notice Finalize a proposal
 @dev After finalizing a proposal, no more proposal version can be added. Proposer will only be able to change fundings and add more docs
 Right after finalizing a proposal, the draft voting round starts. The proposer would also not be able to closeProposal() anymore
 (hence, cannot claim back the collateral anymore, until the final voting round passes)
 @param _proposalId ID of the proposal
 */
function finalizeProposal(bytes32 _proposalId)
        public
    {
        senderCanDoProposerOperations();
        require(isFromProposer(_proposalId));
        require(isEditable(_proposalId));
        checkNonDigixProposalLimit(_proposalId);

        // make sure we have reasonably enough time left in the quarter to conduct the Draft Voting.
        // Otherwise, the proposer must wait until the next quarter to finalize the proposal
        require(getTimeLeftInQuarter(now) > getUintConfig(CONFIG_DRAFT_VOTING_PHASE).add(getUintConfig(CONFIG_VOTE_CLAIMING_DEADLINE)));
        address _endorser;
        (,,_endorser,,,,,,,) = daoStorage().readProposal(_proposalId);
        require(_endorser != EMPTY_ADDRESS);
        daoStorage().finalizeProposal(_proposalId);
        daoStorage().setProposalDraftVotingTime(_proposalId, now);

        emit FinalizeProposal(_proposalId);
    }
// Solidity 0.4.25
/**
 @notice Function to set milestone to be completed
 @dev This can only be called in the Main Phase of DigixDAO by the proposer. It sets the
 voting time for the next milestone, which is immediately, for most of the times. If there is not enough time left in the current
 quarter, then the next voting is postponed to the start of next quarter
 @param _proposalId ID of the proposal
 @param _milestoneIndex Index of the milestone. Index starts from 0 (for the first milestone)
 */
function finishMilestone(bytes32 _proposalId, uint256 _milestoneIndex)
        public
    {
        senderCanDoProposerOperations();
        require(isFromProposer(_proposalId));

        uint256[] memory _currentFundings;
        (_currentFundings,) = daoStorage().readProposalFunding(_proposalId);

        // If there are N milestones, the milestone index must be < N. Otherwise, putting a milestone index of N will actually return a valid timestamp that is
        // right after the final voting round (voting round index N is the final voting round)
        // Which could be abused ( to "finish" a milestone even after the final voting round)
        require(_milestoneIndex < _currentFundings.length);

        // must be after the start of this milestone, and the milestone has not been finished yet (voting hasnt started)
        uint256 _startOfCurrentMilestone = startOfMilestone(_proposalId, _milestoneIndex);
        require(now > _startOfCurrentMilestone);
        require(daoStorage().readProposalVotingTime(_proposalId, _milestoneIndex.add(1)) == 0);

        daoStorage().setProposalVotingTime(
            _proposalId,
            _milestoneIndex.add(1),
            getTimelineForNextVote(_milestoneIndex.add(1), now)
        ); // set the voting time of next voting

        emit FinishMilestone(_proposalId, _milestoneIndex);
    }
// Solidity 0.4.25
/**
 @notice Function to update the PRL (regulatory status) status of a proposal
 @dev if a proposal is paused or stopped, the proposer wont be able to withdraw the funding
 @param _proposalId ID of the proposal
 @param _doc hash of IPFS uploaded document, containing details of PRL Action
 */
function updatePRL(
        bytes32 _proposalId,
        uint256 _action,
        bytes32 _doc
    )
        public
        if_prl()
    {
        require(_action == PRL_ACTION_STOP || _action == PRL_ACTION_PAUSE || _action == PRL_ACTION_UNPAUSE);
        daoStorage().updateProposalPRL(_proposalId, _action, _doc, now);

        emit PRLAction(_proposalId, _action, _doc);
    }
// Solidity 0.4.25
/**
 @notice Function to close proposal (also get back collateral)
 @dev Can only be closed if the proposal has not been finalized yet
 @param _proposalId ID of the proposal
 */
function closeProposal(bytes32 _proposalId)
        public
    {
        senderCanDoProposerOperations();
        require(isFromProposer(_proposalId));
        bytes32 _finalVersion;
        bytes32 _status;
        (,,,_status,,,,_finalVersion,,) = daoStorage().readProposal(_proposalId);
        require(_finalVersion == EMPTY_BYTES);
        require(_status != PROPOSAL_STATE_CLOSED);
        require(daoStorage().readProposalCollateralStatus(_proposalId) == COLLATERAL_STATUS_UNLOCKED);

        daoStorage().closeProposal(_proposalId);
        daoStorage().setProposalCollateralStatus(_proposalId, COLLATERAL_STATUS_CLAIMED);
        emit CloseProposal(_proposalId);
        require(daoFundingManager().refundCollateral(msg.sender, _proposalId));
    }
// Solidity 0.4.25
/**
 @notice Function for founders to close all the dead proposals
 @dev Dead proposals = all proposals who are not yet finalized, and been there for more than the threshold time
 The proposers of dead proposals will not get the collateral back
 @param _proposalIds Array of proposal IDs
 */
function founderCloseProposals(bytes32[] _proposalIds)
        external
        if_founder()
    {
        uint256 _length = _proposalIds.length;
        uint256 _timeCreated;
        bytes32 _finalVersion;
        bytes32 _currentState;
        for (uint256 _i = 0; _i < _length; _i++) {
            (,,,_currentState,_timeCreated,,,_finalVersion,,) = daoStorage().readProposal(_proposalIds[_i]);
            require(_finalVersion == EMPTY_BYTES);
            require(
                (_currentState == PROPOSAL_STATE_PREPROPOSAL) ||
                (_currentState == PROPOSAL_STATE_DRAFT)
            );
            require(now > _timeCreated.add(getUintConfig(CONFIG_PROPOSAL_DEAD_DURATION)));
            emit CloseProposal(_proposalIds[_i]);
            daoStorage().closeProposal(_proposalIds[_i]);
        }
    }
// Solidity 0.4.24
/**
 * @dev Execute multiple trades in a single transaction.
 * @param wrappers Addresses of exchange wrappers.
 * @param token Address of ERC20 token to receive in first trade.
 * @param trade1 Calldata of Ether => ERC20 trade.
 * @param trade2 Calldata of ERC20 => Ether trade.
 */
function trade(
        address[2] wrappers,
        address token,
        bytes trade1,
        bytes trade2
    )
        external
        payable
    {
        // Execute the first trade to get tokens
        require(execute(wrappers[0], msg.value, trade1));

        uint256 tokenBalance = IERC20(token).balanceOf(this);

        // Transfer tokens to the next exchange wrapper
        transfer(token, wrappers[1], tokenBalance);

        // Execute the second trade to get Ether
        require(execute(wrappers[1], 0, trade2));
        
        // Send the arbitrageur Ether
        msg.sender.transfer(address(this).balance);
    }
// Solidity 0.5.17
/**
 * @dev Transfer function to assign a token to another address
 * Reverts if the address already owns a token
 * @param from address the address that currently owns the token
 * @param to address the address to assign the token to
 * @param tokenId uint256 ID of the token to transfer
 */
function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public isValidAddress(to) isValidAddress(from) onlyOwner {
        require(tokenOwned[to] == 0, "Destination address already owns a token");
        require(ownerOf[tokenId] == from, "From address does not own token");

        tokenOwned[from] = 0;
        tokenOwned[to] = tokenId;

        ownerOf[tokenId] = to;

        emit Transfer(from, to, tokenId);
    }
// Solidity 0.5.17
/**
 * @dev Burn function to remove a given tokenId
 * Reverts if the token ID does not exist.
 * @param tokenId uint256 ID of the token to burn
 */
function burn(uint256 tokenId) public onlyOwner {
        address previousOwner = ownerOf[tokenId];
        require(previousOwner != address(0), "ERC721: token does not exist");

        delete tokenOwned[previousOwner];
        delete ownerOf[tokenId];

        for (uint256 i = 0; i < tokens.length; i++) {
            if (tokens[i] == tokenId) {
                tokens[i] = tokens[tokens.length - 1];
                break;
            }
        }

        tokens.pop();

        if (bytes(tokenURIs[tokenId]).length != 0) {
            delete tokenURIs[tokenId];
        }

        emit Burn(tokenId);
    }
// Solidity 0.8.4
/// @notice The actual mint function used for presale and public minting then. 
/// @param amount The number of tokens you're able to mint in one transaction.
function mint(uint256 amount) external payable {
        require(!saleIsClosed, "The sale is closed.");
        require(amount > 0 && amount <= 3, "Amount must be within [1;3].");

        if(whitelistSaleIsActive){ // check if we are in presale 
            require(hasRole(WHITELIST_ROLE, msg.sender), "You're not on the whitelist.");
            require(whitelistPasses[msg.sender] != 0 && (whitelistPasses[msg.sender] - amount) >= 0, "You are out of utility.");
            require(whitelistCurrentLimit > 0, "We're out of tokens.");
        }else{ // if not check if the public sale is active and we're in the limits
            require(saleIsActive, "Sale not active yet.");
            require(publicCurrentLimit > 0, "We're out of tokens.");
        }

        require((_tokenIdCounter.current() + amount) <= MAX_SUPPLY , "Out of tokens.");
        require(msg.value == (41000000000000000 * amount), "The amount of ether is wrong.");

        for(uint256 idx = 1; idx <= amount; idx++){

            if(hasRole(WHITELIST_ROLE, msg.sender)){ // make sure we reduce the amount of whitelistPasses left of the user and reduce the total limit
                whitelistPasses[msg.sender]--;
                whitelistCurrentLimit--;
            }else{
                publicCurrentLimit--;
            }

            _tokenIdCounter.increment();
            _safeMint(msg.sender, _tokenIdCounter.current());
            utilityState[_tokenIdCounter.current()] = 3;

        }

    }
// Solidity 0.8.4
/// @notice Admin mint function that is used for preminting NFTs. 
/// @param amount The amount of NFTs that can be minted in one transaction.
function adminMint(address receiver, uint256 amount) external onlyOwner{
        require(!saleIsClosed, "The sale is closed.");
        require(_tokenIdReserveCounter.current() < MAX_RESERVE , "Out of reserve tokens.");
        require(amount > 0 && amount <= 20, "Amount must be within [1;20].");

        for(uint256 idx = 1; idx <= amount; idx++){
            _tokenIdReserveCounter.increment();
            _tokenIdCounter.increment();

            _safeMint(receiver, _tokenIdCounter.current());
            utilityState[_tokenIdCounter.current()] = 3;
        }
    }
// Solidity 0.8.10
/// @dev claim tokenId mints with placeholder URI in batch 'phase'
function safeMint() external payable nonReentrant {
        // check mint is open
        require(mintOpen, 'CLOSED');
        // check whitelist, if flipped on
        if (whitelistOn) require(whitelist[msg.sender], 'NOT_WHITELISTED');
        // check if price attached
        require(msg.value == mintPrice, 'BAD_PRICE');
        // increment Id for mint (we want to match supply for ease)
        _tokenIdCounter.increment();
        // set tokenId
        uint256 tokenId = _tokenIdCounter.current();
        // check new Id doesn't pass mint limit for phase
        require(tokenId <= mintPhaseLimit, 'PHASE_LIMIT');
        // mint Id to caller
        _safeMint(msg.sender, tokenId);
        // set Id placeholder URI
        _setTokenURI(tokenId, placeholderURI);
        // forward ETH to contract owner
        _safeTransferETH(owner(), msg.value);
    }
// Solidity 0.8.10
/// **** MINT MGMT
/// @dev set next phase for minting (limit + price)
function setMintPhase(uint256 mintPhaseLimit_, uint256 mintPrice_) external onlyOwner {
        // ensure Id limit doesn't exceed cap
        require(mintPhaseLimit_ <= mintCap, 'CAPPED');
        // ensure Id limit is greater than current supply (increasing phase)
        require(mintPhaseLimit_ > totalSupply(), 'BAD_LIMIT');
        // set new minting limit under cap
        mintPhaseLimit = mintPhaseLimit_;
        // set new minting price
        mintPrice = mintPrice_;
        // increment phase for tracking
        mintPhase++;
    }
// Solidity 0.8.10
/// @dev update minted URIs
function setURIs(uint256[] calldata tokenIds, string[] calldata uris) external onlyOwner {
        require(tokenIds.length == uris.length, 'NO_ARRAY_PARITY');

        // this is reasonably safe from overflow because incrementing `i` loop beyond
        // 'type(uint256).max' is exceedingly unlikely compared to optimization benefits
        unchecked {
            for (uint256 i; i < tokenIds.length; i++) {
                _setTokenURI(tokenIds[i], uris[i]);
            }
        }
    }
// Solidity 0.8.10
/// @dev ETH tranfer helper - optimized in assembly:
function _safeTransferETH(address to, uint256 amount) internal {
        bool callStatus;

        assembly {
            // transfer the ETH and store if it succeeded or not
            callStatus := call(gas(), to, amount, 0, 0, 0, 0)
        }

        require(callStatus, 'ETH_TRANSFER_FAILED');
    }
// Solidity 0.7.6
/**
 * @dev Reserved for giveaways.
 */
function reserveGiveaway(uint256 numTokens) public onlyOwner {
        uint currentSupply = totalSupply();
        require(totalSupply() + numTokens <= 10, "10 mints for sale giveaways");
        uint256 index;
        // Reserved for people who helped this project and giveaways
        for (index = 0; index < numTokens; index++) {
            _safeMint(owner(), currentSupply + index);
        }
      }