lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.7.6
// GET ALL PUNKS OF A WALLET AS AN ARRAY OF STRINGS. WOULD BE BETTER MAYBE IF IT RETURNED A STRUCT WITH ID-NAME MATCH
function punkNamesOfOwner(address _owner) external view returns(string[] memory ) {
        uint256 tokenCount = balanceOf(_owner);
        if (tokenCount == 0) {
            // Return an empty array
            return new string[](0);
        } else {
            string[] memory result = new string[](tokenCount);
            uint256 index;
            for (index = 0; index < tokenCount; index++) {
                result[index] = punkNames[ tokenOfOwnerByIndex(_owner, index) ] ;
            }
            return result;
        }
    }
// Solidity 0.4.24
//  startPoll(): open a new poll, or re-open an old one
//
function startPoll(Poll storage _poll)
    internal
  {
    //  check that the poll has cooled down enough to be started again
    //
    //    for completely new polls, the values used will be zero
    //
    require( block.timestamp > ( _poll.start.add(
                                 _poll.duration.add(
                                 _poll.cooldown )) ) );

    //  set started poll state
    //
    _poll.start = block.timestamp;
    delete _poll.voted;
    _poll.yesVotes = 0;
    _poll.noVotes = 0;
    _poll.duration = pollDuration;
    _poll.cooldown = pollCooldown;
  }
// Solidity 0.4.25
/**
 * This one is easy, claim reserved ether for the team or advertisement
 */
function claim(uint amount) public {
        if (msg.sender == advertisementAddress) {
            require(amount > 0 && amount <= advertisement, "Can't claim more than was reserved");

            advertisement -= amount;
            msg.sender.transfer(amount);
        } else 
        if (msg.sender == teamAddress) {
            require(amount > 0 && amount <= address(this).balance, "Can't claim more than was reserved");

            team += amount;
            msg.sender.transfer(amount);
        }
    }
// Solidity 0.4.24
//  processVote(): record a vote from _as on the _poll
//
function processVote(Poll storage _poll, uint8 _as, bool _vote)
    internal
  {
    //  assist symbolic execution tools
    //
    assert(block.timestamp >= _poll.start);

    require( //  may only vote once
             //
             !_poll.voted[_as] &&
             //
             //  may only vote when the poll is open
             //
             (block.timestamp < _poll.start.add(_poll.duration)) );

    //  update poll state to account for the new vote
    //
    _poll.voted[_as] = true;
    if (_vote)
    {
      _poll.yesVotes = _poll.yesVotes.add(1);
    }
    else
    {
      _poll.noVotes = _poll.noVotes.add(1);
    }
  }
// Solidity 0.4.25
/**
 * @dev payable function which does:
 * If current state = ST_RASING - allows to send ETH for future tokens
 * If current state = ST_MONEY_BACK - will send back all ETH that msg.sender has on balance
 * If current state = ST_TOKEN_DISTRIBUTION - will reurn all ETH and Tokens that msg.sender has on balance
 * in case of ST_MONEY_BACK or ST_TOKEN_DISTRIBUTION all ETH sum will be sent back (sum to trigger this function)
 */
function () public payable {
    uint8 _state = getState_();
    if (_state == ST_RAISING){
      buyShare_(_state);
      return;
    }
    
    if (_state == ST_MONEY_BACK) {
      refundShare_(msg.sender, share[msg.sender]);
      if(msg.value > 0)
        msg.sender.transfer(msg.value);
      return;
    }
    
    if (_state == ST_TOKEN_DISTRIBUTION) {
      releaseEther_(msg.sender, getBalanceEtherOf_(msg.sender));
      releaseToken_(msg.sender, getBalanceTokenOf_(msg.sender));
      if(msg.value > 0)
        msg.sender.transfer(msg.value);
      return;
    }
    revert();
  }
// Solidity 0.4.25
/**
 * @dev Release amount of ETH to stakeholder by admin or paybot
 * @param _for stakeholder role (for example: 2)
 * @param _value amount of ETH in wei
 * @return result of operation, true if success
 */
function releaseEtherToStakeholderForce(uint8 _for, uint _value) external returns(bool) {
    uint8 _role = getRole_();
    require((_role==RL_ADMIN) || (_role==RL_PAYBOT));
    uint8 _state = getState_();
    require(!((_for == RL_ICO_MANAGER) && ((_state != ST_WAIT_FOR_ICO) || (tokenPrice > 0))));
    return releaseEtherToStakeholder_(_state, _for, _value);
  }
// Solidity 0.4.25
/**
 * @dev Release amount of ETH to person by admin or paybot
 * @param _for addresses of persons
 * @param _value amounts of ETH in wei
 * @return result of operation, true if success
 */
function releaseEtherForceMulti(address[] _for, uint[] _value) external returns(bool) {
    uint _sz = _for.length;
    require(_value.length == _sz);
    uint8 _role = getRole_();
    uint8 _state = getState_();
    require(_state == ST_TOKEN_DISTRIBUTION);
    require((_role==RL_ADMIN) || (_role==RL_PAYBOT));
    for (uint i = 0; i < _sz; i++){
      require(releaseEther_(_for[i], _value[i]));
    }
    return true;
  }
// Solidity 0.4.24
//  updateUpgradePoll(): check whether the _proposal has achieved
//                            majority, updating state, sending an event,
//                            and returning true if it has
//
function updateUpgradePoll(address _proposal)
    public
    onlyOwner
    returns (bool majority)
  {
    //  _proposal must not have achieved majority before
    //
    require(!upgradeHasAchievedMajority[_proposal]);

    //  check for majority in the poll
    //
    Poll storage poll = upgradePolls[_proposal];
    majority = checkPollMajority(poll);

    //  if majority was achieved, update the state and send an event
    //
    if (majority)
    {
      upgradeHasAchievedMajority[_proposal] = true;
      emit UpgradeMajority(_proposal);
    }
    return majority;
  }
// Solidity 0.4.25
/**
 * @dev Allow to return ETH back to person by admin or paybot if state Money back
 * @param _for address of person
 * @param _value amount of ETH in wei
 * @return result of operation, true if success
 */
function refundShareForce(address _for, uint _value) external returns(bool) {
    uint8 _state = getState_();
    uint8 _role = getRole_();
    require(_role == RL_ADMIN || _role == RL_PAYBOT);
    require (_state == ST_MONEY_BACK || _state == ST_RAISING);
    return refundShare_(_for, _value);
  }
// Solidity 0.8.4
/// Core functions
function stake(uint256 amount) public {
        // amount to stake and user's balance can not be 0
        require(
            amount > 0 &&
            formToken.balanceOf(msg.sender) >= amount, 
            "You cannot stake zero tokens");
        
        // if user is already staking, calculate up-to-date yield
        if(stakingBalance[msg.sender] > 0){
            uint256 yieldEarned = getUsersYieldAmount(msg.sender);
            yieldBalance[msg.sender] = yieldEarned;
        }

        formToken.transferFrom(msg.sender, address(this), amount); // add FORM tokens to the staking pool
        stakingBalance[msg.sender] += amount;
        startTime[msg.sender] = block.timestamp; // upserting the staking schedule whether user is already staking or not
        emit Stake(msg.sender, amount);
    }
// Solidity 0.4.24
//  updateDocumentPoll(): check whether the _proposal has achieved majority,
//                        updating the state and sending an event if it has
//
//    this can be called by anyone, because the ecliptic does not
//    need to be aware of the result
//
function updateDocumentPoll(bytes32 _proposal)
    public
    returns (bool majority)
  {
    //  _proposal must not have achieved majority before
    //
    require(!documentHasAchievedMajority[_proposal]);

    //  check for majority in the poll
    //
    Poll storage poll = documentPolls[_proposal];
    majority = checkPollMajority(poll);

    //  if majority was achieved, update state and send an event
    //
    if (majority)
    {
      documentHasAchievedMajority[_proposal] = true;
      documentMajorities.push(_proposal);
      emit DocumentMajority(_proposal);
    }
    return majority;
  }
// Solidity 0.6.12
// NOTE: Can override `tendTrigger` and `harvestTrigger` if necessary
function prepareMigration(address _newStrategy) internal override {
        uint256 balance3crv = IERC20(crv3).balanceOf(address(this));
        uint256 balanceYveCrv = IERC20(address(want)).balanceOf(address(this));
        if(balance3crv > 0){
            IERC20(crv3).safeTransfer(_newStrategy, balance3crv);
        }
        if(balanceYveCrv > 0){
            IERC20(address(want)).safeTransfer(_newStrategy, balanceYveCrv);
        }
        IERC20(crv).safeApprove(address(want), 0);
        IERC20(usdc).safeApprove(sushiswap, 0);
    }
// Solidity 0.6.12
// Here we determine if better to market-buy yvBOOST or mint it via backscratcher
function shouldMint(uint256 _amountIn) internal returns (bool) {
        // Using reserve ratios of swap pairs will allow us to compare whether it's more efficient to:
        //  1) Buy yvBOOST (unwrapped for yveCRV)
        //  2) Buy CRV (and use to mint yveCRV 1:1)
        address[] memory path = new address[](3);
        path[0] = usdc;
        path[1] = weth;
        path[2] = yvBoost;
        uint256[] memory amounts = ISwap(sushiswap).getAmountsOut(_amountIn, path);
        uint256 projectedYvBoost = amounts[2];
        // Convert yvBOOST to yveCRV
        uint256 projectedYveCrv = projectedYvBoost.mul(vault.pricePerShare()).div(1e18); // save some gas by hardcoding 1e18

        path = new address[](3);
        path[0] = usdc;
        path[1] = weth;
        path[2] = crv;
        amounts = ISwap(sushiswap).getAmountsOut(_amountIn, path);
        uint256 projectedCrv = amounts[2];

        // Here we favor minting by a % value defined by "vaultBuffer"
        bool shouldMint = projectedCrv.mul(DENOMINATOR.add(vaultBuffer)).div(DENOMINATOR) > projectedYveCrv;
        emit BuyOrMint(shouldMint, projectedYveCrv, projectedCrv);

        return shouldMint;
    }
// Solidity 0.4.24
/**
 * @dev OVERRIDE vestedAmount from PGOMonthlyInternalVault
 * Calculates the amount that has already vested, release 1/3 of token immediately.
 * @param beneficiary The address that will receive the vested tokens.
 */
function vestedAmount(address beneficiary) public view returns (uint256) {
        uint256 vested = 0;

        if (block.timestamp >= start) {
            // after start -> 1/3 released (fixed)
            vested = investments[beneficiary].totalBalance.div(3);
        }
        if (block.timestamp >= cliff && block.timestamp < end) {
            // after cliff -> 1/27 of totalBalance every month, must skip first 9 month 
            uint256 unlockedStartBalance = investments[beneficiary].totalBalance.div(3);
            uint256 totalBalance = investments[beneficiary].totalBalance;
            uint256 lockedBalance = totalBalance.sub(unlockedStartBalance);
            uint256 monthlyBalance = lockedBalance.div(VESTING_DIV_RATE);
            uint256 daysToSkip = 90 days;
            uint256 time = block.timestamp.sub(start).sub(daysToSkip);
            uint256 elapsedOffsets = time.div(VESTING_INTERVAL);
            vested = vested.add(elapsedOffsets.mul(monthlyBalance));
        }
        if (block.timestamp >= end) {
            // after end -> all vested
            vested = investments[beneficiary].totalBalance;
        }
        return vested;
    }
// Solidity 0.4.24
//  checkPollMajority(): returns true if the majority is in favor of
//                       the subject of the poll
//
function checkPollMajority(Poll _poll)
    internal
    view
    returns (bool majority)
  {
    return ( //  poll must have at least the minimum required yes-votes
             //
             (_poll.yesVotes >= (totalVoters / 4)) &&
             //
             //  and have a majority...
             //
             (_poll.yesVotes > _poll.noVotes) &&
             //
             //  ...that is indisputable
             //
             ( //  either because the poll has ended
               //
               (block.timestamp > _poll.start.add(_poll.duration)) ||
               //
               //  or there are more yes votes than there can be no votes
               //
               ( _poll.yesVotes > totalVoters.sub(_poll.yesVotes) ) ) );
  }
// Solidity 0.4.24
/**
 * @dev Sets the state of the internal monthly locked vault contract and mints tokens.
 * It will contains all TEAM, FOUNDER, ADVISOR and PARTNERS tokens.
 * All token are locked for the first 9 months and then unlocked monthly.
 * It will check that all internal token are correctly allocated.
 * So far, the internal monthly vault contract has been deployed and this function
 * needs to be called to set its investments and vesting conditions.
 * @param beneficiaries Array of the internal addresses to whom vested tokens are transferred.
 * @param balances Array of token amount per beneficiary.
 */
function initPGOMonthlyInternalVault(address[] beneficiaries, uint256[] balances)
        public
        onlyOwner
        equalLength(beneficiaries, balances)
    {
        uint256 totalInternalBalance = 0;
        uint256 balancesLength = balances.length;

        for (uint256 i = 0; i < balancesLength; i++) {
            totalInternalBalance = totalInternalBalance.add(balances[i]);
        }
        //check that all balances matches internal vault allocated Cap
        require(totalInternalBalance == MONTHLY_INTERNAL_VAULT_CAP);

        pgoMonthlyInternalVault.init(beneficiaries, balances, END_TIME, token);

        mintTokens(address(pgoMonthlyInternalVault), MONTHLY_INTERNAL_VAULT_CAP);
    }
// Solidity 0.4.24
/**
 * @dev Mint all token collected by second private presale (called reservation),
 * all KYC control are made outside contract under responsability of ParkinGO.
 * Also, updates tokensSold and availableTokens in the crowdsale contract,
 * it checks that sold token are less than reservation contract cap.
 * @param beneficiaries Array of the reservation user that bought tokens in private reservation sale.
 * @param balances Array of token amount per beneficiary.
 */
function mintReservation(address[] beneficiaries, uint256[] balances)
        public
        onlyOwner
        equalLength(beneficiaries, balances)
    {
        //require(tokensSold == 0);

        uint256 totalReservationBalance = 0;
        uint256 balancesLength = balances.length;

        for (uint256 i = 0; i < balancesLength; i++) {
            totalReservationBalance = totalReservationBalance.add(balances[i]);
            uint256 amount = balances[i];
            //update token sold of crowdsale contract
            tokensSold = tokensSold.add(amount);
            //update available token of crowdsale contract
            availableTokens = availableTokens.sub(amount);
            mintTokens(beneficiaries[i], amount);
        }

        require(totalReservationBalance <= RESERVATION_CAP);
    }
// Solidity 0.4.24
/**
 * @dev Allows the owner to unpause tokens, stop minting and transfer ownership of the token contract.
 */
function finalise() public onlyOwner {
        require(didOwnerEndCrowdsale || block.timestamp > end || capReached);

        token.finishMinting();
        token.unpause();

        // Token contract extends CanReclaimToken so the owner can recover
        // any ERC20 token received in this contract by mistake.
        // So far, the owner of the token contract is the crowdsale contract.
        // We transfer the ownership so the owner of the crowdsale is also the owner of the token.
        token.transferOwnership(owner);
    }
// Solidity 0.4.24
/**
 * @dev Implements the KYCBase releaseTokensTo function to mint tokens for an investor.
 * Called after the KYC process has passed.
 * @return A boolean that indicates if the operation was successful.
 */
function releaseTokensTo(address buyer) internal returns(bool) {
        require(validPurchase());

        uint256 overflowTokens;
        uint256 refundWeiAmount;

        uint256 weiAmount = msg.value;
        uint256 tokenAmount = weiAmount.mul(price());

        if (tokenAmount >= availableTokens) {
            capReached = true;
            overflowTokens = tokenAmount.sub(availableTokens);
            tokenAmount = tokenAmount.sub(overflowTokens);
            refundWeiAmount = overflowTokens.div(price());
            weiAmount = weiAmount.sub(refundWeiAmount);
            buyer.transfer(refundWeiAmount);
        }

        weiRaised = weiRaised.add(weiAmount);
        tokensSold = tokensSold.add(tokenAmount);
        availableTokens = availableTokens.sub(tokenAmount);
        mintTokens(buyer, tokenAmount);
        forwardFunds(weiAmount);

        return true;
    }
// Solidity 0.4.24
//  onUpgrade(): called by previous ecliptic when upgrading
//
//    in future ecliptics, this might perform more logic than
//    just simple checks and verifications.
//    when overriding this, make sure to call this original as well.
//
function onUpgrade()
    external
  {
    //  make sure this is the expected upgrade path,
    //  and that we have gotten the ownership we require
    //
    require( msg.sender == previousEcliptic &&
             this == azimuth.owner() &&
             this == polls.owner() );
  }
// Solidity 0.4.24
//  upgrade(): transfer ownership of the ecliptic data to the new
//             ecliptic contract, notify it, then self-destruct.
//
//    Note: any eth that have somehow ended up in this contract
//          are also sent to the new ecliptic.
//
function upgrade(EclipticBase _new)
    internal
  {
    //  transfer ownership of the data contracts
    //
    azimuth.transferOwnership(_new);
    polls.transferOwnership(_new);

    //  trigger upgrade logic on the target contract
    //
    _new.onUpgrade();

    //  emit event and destroy this contract
    //
    emit Upgraded(_new);
    selfdestruct(_new);
  }
// Solidity 0.8.4
/**
 * @dev Returns the maximum number of tokens currently claimable by `owner`.
 * @param owner The account to check the claimable balance of.
 * @return The number of tokens currently claimable.
 */
function claimableBalance(address owner) public view returns(uint256) {
        if(block.timestamp < unlockCliff) {
            return 0;
        }

        uint256 locked = lockedAmounts[owner];
        uint256 claimed = claimedAmounts[owner];
        if(block.timestamp >= unlockEnd) {
            return locked - claimed;
        }
        return (locked * (block.timestamp - unlockBegin)) / (unlockEnd - unlockBegin) - claimed;
    }
// Solidity 0.8.4
/**
 * @dev Claims the caller's tokens that have been unlocked, sending them to `recipient`.
 * @param recipient The account to transfer unlocked tokens to.
 * @param amount The amount to transfer. If greater than the claimable amount, the maximum is transferred.
 */
function claim(address recipient, uint256 amount) public {
        uint256 claimable = claimableBalance(msg.sender);
        if(amount > claimable) {
            amount = claimable;
        }
        claimedAmounts[msg.sender] += amount;
        require(token.transfer(recipient, amount), "TokenLock: Transfer failed");
        emit Claimed(msg.sender, recipient, amount);
    }
// Solidity 0.4.11
// transfer tokens to another address (owner)    
function transfer(address _to, uint256 _value) returns (bool success) {
        if (_to == 0x0 || balanceOf[msg.sender] < _value || balanceOf[_to] + _value < balanceOf[_to]) 
            return false; 
        balanceOf[msg.sender] -= _value;                     
        balanceOf[_to] += _value;                            
        Transfer(msg.sender, _to, _value);
        return true;
    }
// Solidity 0.4.11
// setting of availability of tokens transference for third party
function transferFrom(address _from, address _to, uint256 _value) 
        returns (bool success) {
        if(_to == 0x0 || balanceOf[_from] < _value || _value > allowance[_from][msg.sender]) 
            return false;                                
        balanceOf[_from] -= _value;                           
        balanceOf[_to] += _value;                             
        allowance[_from][msg.sender] -= _value;
        Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.7.6
/**
 * Only incaseof private market, check if caller has a minter role 
 */
function mint(uint256 supply, string memory uri, address creator, uint256 royaltyRatio) public returns(uint256 id) {
        require(supply > 0,"NFTBase/supply_is_0");
        require(!compareStrings(uri,""),"NFTBase/uri_is_empty");
        require(creator != address(0),"NFTBase/createor_is_0_address");
        require(_royaltyMinimum <= royaltyRatio && royaltyRatio <= _royaltyMaximum,"NFTBase/royalty_out_of_range");
        
        if(_isPrivate)
            require(hasRole(MINTER_ROLE,_msgSender()),"NFTBase/caller_has_not_minter_role");
        id = ++_currentTokenId;    
        
        _tokens[id].supply  = supply;
        _tokens[id].uri     = uri;
        _tokens[id].creator = creator;
        _tokens[id].royaltyRatio = royaltyRatio;
        
        ERC1155._mint(_msgSender(),id,supply,"");    // TransferSingle Event  

        emit Mint(id,supply,uri,creator,royaltyRatio);
    }
// Solidity 0.4.24
//  clearClaims(): unregister all of _point's claims
//
//    can also be called by the ecliptic during point transfer
//
function clearClaims(uint32 _point)
    external
  {
    //  both point owner and ecliptic may do this
    //
    //    We do not necessarily need to check for _point's active flag here,
    //    since inactive points cannot have claims set. Doing the check
    //    anyway would make this function slightly harder to think about due
    //    to its relation to Ecliptic's transferPoint().
    //
    require( azimuth.canManage(_point, msg.sender) ||
             ( msg.sender == azimuth.owner() ) );

    Claim[maxClaims] storage currClaims = claims[_point];

    //  clear out all claims
    //
    for (uint8 i = 0; i < maxClaims; i++)
    {
      delete currClaims[i];
    }
  }
// Solidity 0.6.12
// Converts WETH to Rigel
function _toRIGEL(uint256 amountIn) internal {
        IUniswapV2Pair pair = IUniswapV2Pair(factory.getPair(weth, rigel));
        // Choose WETH as input token
        (uint reserve0, uint reserve1,) = pair.getReserves();
        address token0 = pair.token0();
        (uint reserveIn, uint reserveOut) = token0 == weth ? (reserve0, reserve1) : (reserve1, reserve0);
        // Calculate information required to swap
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        uint amountOut = numerator / denominator;
        (uint amount0Out, uint amount1Out) = token0 == weth ? (uint(0), amountOut) : (amountOut, uint(0));
        // Swap WETH for Rigel
        pair.swap(amount0Out, amount1Out, orion, new bytes(0));
    }
// Solidity 0.4.24
//  findClaim(): find the index of the specified claim
//
//    returns 0 if not found, index + 1 otherwise
//
function findClaim(uint32 _whose, string _protocol, string _claim)
    public
    view
    returns (uint8 index)
  {
    //  we use hashes of the string because solidity can't do string
    //  comparison yet
    //
    bytes32 protocolHash = keccak256(bytes(_protocol));
    bytes32 claimHash = keccak256(bytes(_claim));
    Claim[maxClaims] storage theirClaims = claims[_whose];
    for (uint8 i = 0; i < maxClaims; i++)
    {
      Claim storage thisClaim = theirClaims[i];
      if ( ( protocolHash == keccak256(bytes(thisClaim.protocol)) ) &&
           ( claimHash == keccak256(bytes(thisClaim.claim)) ) )
      {
        return i+1;
      }
    }
    return 0;
  }
// Solidity 0.5.17
/* CertiK Smart Labelling, for more details visit: https://certik.org */
function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
    if (a == 0) {
      return 0;
    }
    c = a * b;
    assert(c / a == b);
    return c;
  }