lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/** @dev Return amount of locked tokens from `account`
 *
 */
function getLockedAmount(address account) public view returns (uint256) {
      uint256 res = 0;
      for (uint i = 0; i < lockupAccount.length; i++) {
        if (lockupAccount[i].account == account) {
          res = lockupAccount[i].amount;
          break;
        }
      }
      return res;
    }
// Solidity 0.8.0
// dev team mint
function devMint(uint256 _mintAmount) public onlyEOA onlyOwner {
    require(!paused); // contract is not paused
    uint256 supply = totalSupply(); // get current mintedAmount
    require(
      supply + _mintAmount <= maxSupply,
      "SHOGUN: total mint amount exceeded supply, try lowering amount"
    );
    for (uint256 i = 1; i <= _mintAmount; i++) {
      _safeMint(msg.sender, supply + i);
    }
  }
// Solidity 0.8.6
/**
 * @dev External function to purchase tokens.
 * @param _amount Token amount to buy
 */
function purchase(uint256 _amount) external payable {
    require(price > 0, "BattleRoyale: Token price is zero");
    require(
      battleState == BATTLE_STATE.STANDBY,
      "BattleRoyale: Current battle state is not ready to purchase tokens"
    );
    require(
      maxSupply > 0 && totalSupply < maxSupply,
      "BattleRoyale: The NFTs you attempted to purchase is now sold out"
    );
    require(block.timestamp >= startingTime, "BattleRoyale: Not time to purchase");

    if (msg.sender != owner()) {
      require(
        _amount <= maxSupply - totalSupply && _amount > 0 && _amount <= unitsPerTransaction,
        "BattleRoyale: Out range of token amount"
      );
      require(bytes(defaultTokenURI).length > 0, "BattleRoyale: Default token URI is not set");
      require(
        msg.value >= (price * _amount),
        "BattleRoyale: Caller hasn't got enough ETH for buying tokens"
      );
    }

    for (uint256 i = 0; i < _amount; i++) {
      uint256 tokenId = totalSupply + i + 1;

      _safeMint(msg.sender, tokenId);

      string memory tokenURI = string(abi.encodePacked(baseURI, defaultTokenURI));

      _setTokenURI(tokenId, tokenURI);

      inPlay.push(uint32(tokenId));
    }

    totalSupply += _amount;

    emit Purchased(msg.sender, _amount, totalSupply);
  }
// Solidity 0.8.6
/**
 * @dev External function to end the battle. This function can be called only by owner.
 * @param _winnerTokenId Winner token Id in battle
 */
function endBattle(uint256 _winnerTokenId) external onlyOwner {
    require(battleState == BATTLE_STATE.RUNNING, "BattleRoyale: Battle is not started");
    battleState = BATTLE_STATE.ENDED;

    uint256 tokenId = totalSupply + 1;

    address winnerAddress = ownerOf(_winnerTokenId);
    _safeMint(winnerAddress, tokenId);

    string memory tokenURI = string(abi.encodePacked(baseURI, prizeTokenURI));
    _setTokenURI(tokenId, tokenURI);

    emit BattleEnded(address(this), tokenId, prizeTokenURI);
  }
// Solidity 0.8.7
/// @notice Transfers tokens from the targeted address to the given destination
/// @notice Errors with 'STF' if transfer fails
/// @param token The contract address of the token to be transferred
/// @param from The originating address from which the tokens will be transferred
/// @param to The destination address of the transfer
/// @param value The amount to be transferred
function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) =
            token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }
// Solidity 0.8.7
/// @notice Transfers NFT from the targeted address to the given destination
/// @notice Errors with 'STF' if transfer fails
/// @param token The contract address of the token to be transferred
/// @param from The originating address from which the tokens will be transferred
/// @param to The destination address of the transfer
/// @param tokenId the id of the token need to be transfered
function safeTransferNFTFrom(
        address token,
        address from,
        address to,
        uint256 tokenId
    ) internal {
        (bool success, bytes memory data) =
            token.call(abi.encodeWithSelector(IERC721.transferFrom.selector, from, to, tokenId));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }
// Solidity 0.8.9
/**
 * @dev Calls multiple functions on the contract deployed in `target` address. Only callable by owner of BatchRelayer.
 * @param target the destination contract.
 * @param data encoded method calls with arguments.
 * @return results of the method calls.
 */
function relay(address target, bytes[] calldata data) external onlyOwner() returns (bytes[] memory results) {
    results = new bytes[](data.length);
    for (uint256 i = 0; i < data.length; i++) {
        results[i] = Address.functionCall(target, data[i]);
    }
    return results;
  }
// Solidity 0.8.0
/**
 * Mint CMoons
 */
function mintCMoons(uint256 numberOfTokens) public payable {
        require(saleIsActive, "Sorry, but the minting is not available now.");
        require(
            numberOfTokens <= MAX_PURCHASE,
            "Sorry, but you can only mint 5 tokens total."
        );
        require(
            totalSupply().add(numberOfTokens) <= MAX_TOKENS,
            "Sorry, but we don't have that many Moons left."
        );
        require(
            CURRENT_PRICE.mul(numberOfTokens) <= msg.value,
            "Sorry, but the value is inaccurate. Please take the number of Moons times 0.05"
        );
        uint256 first_encounter = block.timestamp;
        uint256 tokenId;

        for (uint256 i = 1; i <= numberOfTokens; i++) {
            tokenId = totalSupply().add(1);
            if (tokenId <= MAX_TOKENS) {
                _safeMint(msg.sender, tokenId);
                _cMoonsDetails[tokenId] = CMoonsDetail(first_encounter);
                emit TokenMinted(tokenId, msg.sender, first_encounter);
            }
        }

        if(tokenId > 2869 && tokenId <= MAX_TOKENS){
            LOTTERY_ADDRESS.transfer(0.05 ether);
        }
    }
// Solidity 0.5.16
/**
 * registe a pool
 */
function addPool(address poolAddr, address rewardToken)
    external
    {
        require(msg.sender == _governance || msg.sender == factoryAddress, "not governance or factory");
        require( _pools[poolAddr] == address(0), "derp, that pool already been registered");

        _pools[poolAddr] = rewardToken;
        _refer1RewardRate[poolAddr] = 700;
        _refer2RewardRate[poolAddr] = 300;

        _poolOwner[poolAddr] = tx.origin;
        _allpools.push(poolAddr);

        emit eveAddPool(poolAddr);
    }
// Solidity 0.5.16
/**
 * @dev set refer reward rate
 */
function setReferRewardRate(address poolAddr, uint256 refer1Rate, uint256 refer2Rate ) public
    {
        require(msg.sender == _governance || msg.sender == _poolOwner[poolAddr], "not governance or owner");

        require(_pools[poolAddr] != address(0),"invalid pool address!");

        _refer1RewardRate[poolAddr] = refer1Rate;
        _refer2RewardRate[poolAddr] = refer2Rate;
    }
// Solidity 0.4.18
/**
 * @notice Transfer tokens from one address to another  or sell them if _to is this contract or zero address
 * @param _from address The address which you want to send tokens from
 * @param _to address The address which you want to transfer to
 * @param _value uint256 the amout of tokens to be transfered
 */
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
        if( (_to == address(this)) || (_to == 0) ){
            var _allowance = allowed[_from][msg.sender];
            require (_value <= _allowance);
            allowed[_from][msg.sender] = _allowance.sub(_value);
            return sell(_from, _value);
        }else{
            return super.transferFrom(_from, _to, _value);
        }
    }
// Solidity 0.4.18
/**
 * @dev Fuction called when somebody is buying tokens
 * @param who The address of buyer (who will own bought tokens)
 * @param amount The amount to be transferred.
 */
function buy(address who, uint256 amount) canBuyAndSell internal returns(bool){
        require(amount >= minBuyAmount);
        currentPeriodEtherCollected = currentPeriodEtherCollected.add(amount);
        receivedEther[who] = receivedEther[who].add(amount);  //if this is first operation from this address, initial value of receivedEther[to] == 0
        Sale(who, amount);
        return true;
    }
// Solidity 0.4.18
/**
 * @dev Fuction called when somebody is selling his tokens
 * @param who The address of seller (whose tokens are sold)
 * @param amount The amount to be transferred.
 */
function sell(address who, uint256 amount) canBuyAndSell internal returns(bool){
        require(amount >= minSellAmount);
        currentPeriodTokenCollected = currentPeriodTokenCollected.add(amount);
        soldTokens[who] = soldTokens[who].add(amount);  //if this is first operation from this address, initial value of soldTokens[to] == 0
        totalSupply = totalSupply.sub(amount);
        Redemption(who, amount);
        Transfer(who, address(0), amount);
        return true;
    }
// Solidity 0.4.18
/**
 * @notice Start distribution phase
 * @param _currentPeriodRate exchange rate for current distribution
 */
function startDistribution(uint256 _currentPeriodRate) onlyOwner public {
        require(currentState != State.Distribution);    //owner should not be able to change rate after distribution is started, ensures that everyone have the same rate
        require(_currentPeriodRate != 0);                //something has to be distributed!
        //require(now >= currentPeriodEndTimestamp)     //DO NOT require period end timestamp passed, because there can be some situations when it is neede to end it sooner. But this should be done with extremal care, because of possible race condition between new sales/purshases and currentPeriodRate definition

        currentState = State.Distribution;
        currentPeriodRate = _currentPeriodRate;
    }
// Solidity 0.4.18
/**
 * @notice Distribute tokens to buyers
 * @param buyers an array of addresses to pay tokens for their ether. Should be composed from outside by reading Sale events 
 */
function distributeTokens(address[] buyers) onlyOwner public {
        require(currentState == State.Distribution);
        require(currentPeriodRate > 0);
        for(uint256 i=0; i < buyers.length; i++){
            address buyer = buyers[i];
            require(buyer != address(0));
            uint256 etherAmount = receivedEther[buyer];
            if(etherAmount == 0) continue; //buyer not found or already paid
            uint256 tokenAmount = etherAmount.mul(currentPeriodRate);
            uint256 fee = tokenAmount.mul(buyFeeMilliPercent).div(MILLI_PERCENT_DIVIDER);
            tokenAmount = tokenAmount.sub(fee);
            
            receivedEther[buyer] = 0;
            currentPeriodEtherCollected = currentPeriodEtherCollected.sub(etherAmount);
            //mint tokens
            totalSupply = totalSupply.add(tokenAmount);
            balances[buyer] = balances[buyer].add(tokenAmount);
            Transfer(address(0), buyer, tokenAmount);
        }
    }
// Solidity 0.4.18
/**
 * @notice Distribute ether to sellers
 * If not enough ether is available on contract ballance
 * @param sellers an array of addresses to pay ether for their tokens. Should be composed from outside by reading Redemption events 
 */
function distributeEther(address[] sellers) onlyOwner payable public {
        require(currentState == State.Distribution);
        require(currentPeriodRate > 0);
        for(uint256 i=0; i < sellers.length; i++){
            address seller = sellers[i];
            require(seller != address(0));
            uint256 tokenAmount = soldTokens[seller];
            if(tokenAmount == 0) continue; //seller not found or already paid
            uint256 etherAmount = tokenAmount.div(currentPeriodRate);
            uint256 fee = etherAmount.mul(sellFeeMilliPercent).div(MILLI_PERCENT_DIVIDER);
            etherAmount = etherAmount.sub(fee);
            
            soldTokens[seller] = 0;
            currentPeriodTokenCollected = currentPeriodTokenCollected.sub(tokenAmount);
            if(!seller.send(etherAmount)){
                //in this case we can only log error and let owner to handle it manually
                DistributionError(seller, etherAmount);
                owner.transfer(etherAmount); //assume this should not fail..., overwise - change owner
            }
        }
    }
// Solidity 0.8.9
/**
 * Accepts required payment and mints a specified number of tokens to an address.
 * This method also checks if direct purchase is enabled.
 */
function purchase(uint256 count) public payable nonReentrant {
      require(!msg.sender.isContract(), 'BASE_COLLECTION/CONTRACT_CANNOT_CALL');
      requireMintingConditions(msg.sender, count);

      require(isPurchaseEnabled, 'BASE_COLLECTION/PURCHASE_DISABLED');

      require(
        (_publicSaleTime != 0 && _publicSaleTime < block.timestamp) || (isPreSaleActive && _preSaleAllowList[msg.sender]),
        "BASE_COLLECTION/CANNOT_MINT"
      );

      // Sent value matches required ETH amount
      require(PRICE * count <= msg.value, 'BASE_COLLECTION/INSUFFICIENT_ETH_AMOUNT');

      for (uint256 i = 0; i < count; i++) {
        uint256 newTokenId = _getNextTokenId();
        _safeMint(msg.sender, newTokenId);
        _incrementTokenId();
      }
    }
// Solidity 0.8.7
/// @inheritdoc IHistoryERC721
function eventData(uint eventId) external view override returns(
        uint totalMintFee,
        string memory _name,
        string memory contentHash,
        string memory contentDomain,
        uint firstMintTime
    ){
        EventMeta memory meta = eventMeta[eventId];
        totalMintFee = meta.totalMintFee;
        _name = eventName[eventId];
        contentDomain = allowedDomain[meta.domainId];
        contentHash = eventContentHash[eventId];
        firstMintTime = meta.firstMintTime;
    }
// Solidity 0.8.7
/// @inheritdoc IERC721Metadata
function tokenURI(uint256 tokenId) public view override(IERC721Metadata, ERC721) returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
        (uint evtId, uint reportId) = _tokenIdSplit(tokenId);
        EventMeta memory meta = eventMeta[evtId];
        string memory contentDomain = allowedDomain[meta.domainId];
        string memory head = meta.sslOn ? "https://" : "http://";
        string memory contentUrl = string(abi.encodePacked(head, contentDomain, eventContentHash[evtId]));
        string memory name = string(abi.encodePacked(eventName[evtId]," #",reportId.toString()));
        string memory description = string(abi.encodePacked(
            "History V1 NFT of event ",
            evtId.toString(),
            " : ",
            eventName[evtId],
            ", report id is ",
            reportId.toString(),
            "."
        ));

        return
            string(
                abi.encodePacked(
                    'data:application/json;base64,',
                    Base64.encode(
                        bytes(
                            abi.encodePacked(
                                '{"name":"',
                                name,
                                '", "description":"',
                                description,
                                '", "content": "',
                                contentUrl,
                                '"}'
                            )
                        )
                    )
                )
            );
    }
// Solidity 0.6.12
/// @notice Checks if the join address is one of the Ether coll. types
/// @param _joinAddr Join address to check
function isEthJoinAddr(address _joinAddr) internal view returns (bool) {
        // if it's dai_join_addr don't check gem() it will fail
        if (_joinAddr == 0x9759A6Ac90977b93B58547b4A71c78317f391A28) return false;

        // if coll is weth it's and eth type coll
        if (address(Join(_joinAddr).gem()) == 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) {
            return true;
        }

        return false;
    }
// Solidity 0.6.12
/// @notice Takes a src amount of tokens and converts it into the dest token
/// @dev Takes fee from the _srcAmount before the exchange
/// @param exData [srcAddr, destAddr, srcAmount, destAmount, minPrice, exchangeType, exchangeAddr, callData, price0x]
/// @param _user User address who called the exchange
function sell(ExchangeData memory exData, address payable _user) public payable burnGas(burnAmount) {

        exData.dfsFeeDivider = SERVICE_FEE;
        exData.user = _user;

        // Perform the exchange
        (address wrapper, uint destAmount) = _sell(exData);

        // send back any leftover ether or tokens
        sendLeftover(exData.srcAddr, exData.destAddr, _user);

        // log the event
        logger.Log(address(this), msg.sender, "ExchangeSell", abi.encode(wrapper, exData.srcAddr, exData.destAddr, exData.srcAmount, destAmount));
    }
// Solidity 0.6.12
/// @notice Takes a dest amount of tokens and converts it from the src token
/// @dev Send always more than needed for the swap, extra will be returned
/// @param exData [srcAddr, destAddr, srcAmount, destAmount, minPrice, exchangeType, exchangeAddr, callData, price0x]
/// @param _user User address who called the exchange
function buy(ExchangeData memory exData, address payable _user) public payable burnGas(burnAmount){

        exData.dfsFeeDivider = SERVICE_FEE;
        exData.user = _user;

        // Perform the exchange
        (address wrapper, uint srcAmount) = _buy(exData);

        // send back any leftover ether or tokens
        sendLeftover(exData.srcAddr, exData.destAddr, _user);

        // log the event
        logger.Log(address(this), msg.sender, "ExchangeBuy", abi.encode(wrapper, exData.srcAddr, exData.destAddr, srcAmount, exData.destAmount));

    }
// Solidity 0.6.12
/// @notice User deposits tokens to the Aave protocol
/// @dev User needs to approve the DSProxy to pull the _tokenAddr tokens
/// @param _tokenAddr The address of the token to be deposited
/// @param _amount Amount of tokens to be deposited
function deposit(address _tokenAddr, uint256 _amount) public burnGas(5) payable {
        address lendingPoolCore = ILendingPoolAddressesProvider(AAVE_LENDING_POOL_ADDRESSES).getLendingPoolCore();
        address lendingPool = ILendingPoolAddressesProvider(AAVE_LENDING_POOL_ADDRESSES).getLendingPool();

        uint ethValue = _amount;

        if (_tokenAddr != ETH_ADDR) {
            ERC20(_tokenAddr).safeTransferFrom(msg.sender, address(this), _amount);
            approveToken(_tokenAddr, lendingPoolCore);
            ethValue = 0;
        }

        ILendingPool(lendingPool).deposit{value: ethValue}(_tokenAddr, _amount, AAVE_REFERRAL_CODE);

        setUserUseReserveAsCollateralIfNeeded(_tokenAddr);
    }
// Solidity 0.6.12
/// @dev User needs to approve the DSProxy to pull the _tokenAddr tokens
/// @notice User paybacks tokens to the Aave protocol
/// @param _tokenAddr The address of the token to be paybacked
/// @param _aTokenAddr ATokens to be paybacked
/// @param _amount Amount of tokens to be payed back
/// @param _wholeDebt If true the _amount will be set to the whole amount of the debt
function payback(address _tokenAddr, address _aTokenAddr, uint256 _amount, bool _wholeDebt) public burnGas(3) payable {
        address lendingPoolCore = ILendingPoolAddressesProvider(AAVE_LENDING_POOL_ADDRESSES).getLendingPoolCore();
        address lendingPool = ILendingPoolAddressesProvider(AAVE_LENDING_POOL_ADDRESSES).getLendingPool();

        uint256 amount = _amount;

        (,uint256 borrowAmount,,,,,uint256 originationFee,,,) = ILendingPool(lendingPool).getUserReserveData(_tokenAddr, address(this));

        if (_wholeDebt) {
            amount = borrowAmount + originationFee;
        }

        if (_tokenAddr != ETH_ADDR) {
            ERC20(_tokenAddr).safeTransferFrom(msg.sender, address(this), amount);
            approveToken(_tokenAddr, lendingPoolCore);
        }

        ILendingPool(lendingPool).repay{value: msg.value}(_tokenAddr, amount, payable(address(this)));

        withdrawTokens(_tokenAddr);
    }
// Solidity 0.6.12
/// @notice Helper method to withdraw tokens from the DSProxy
/// @param _tokenAddr Address of the token to be withdrawn
function withdrawTokens(address _tokenAddr) public {
        uint256 amount = _tokenAddr == ETH_ADDR ? address(this).balance : ERC20(_tokenAddr).balanceOf(address(this));

        if (amount > 0) {
            if (_tokenAddr != ETH_ADDR) {
                ERC20(_tokenAddr).safeTransfer(msg.sender, amount);
            } else {
                msg.sender.transfer(amount);
            }
        }
    }
// Solidity 0.6.12
/// @notice Withdraws collateral, converts to borrowed token and repays debt
/// @dev Called through the DSProxy
/// @param _exData Exchange data
/// @param _cAddresses Coll/Debt addresses [cCollAddress, cBorrowAddress]
/// @param _gasCost Gas cost for specific transaction
function repay(
        ExchangeData memory _exData,
        address[2] memory _cAddresses, // cCollAddress, cBorrowAddress
        uint256 _gasCost
    ) public payable {
        enterMarket(_cAddresses[0], _cAddresses[1]);

        address payable user = payable(getUserAddress());

        uint maxColl = getMaxCollateral(_cAddresses[0], address(this));

        uint collAmount = (_exData.srcAmount > maxColl) ? maxColl : _exData.srcAmount;

        require(CTokenInterface(_cAddresses[0]).redeemUnderlying(collAmount) == 0);

        address collToken = getUnderlyingAddr(_cAddresses[0]);
        address borrowToken = getUnderlyingAddr(_cAddresses[1]);

        uint swapAmount = 0;

        if (collToken != borrowToken) {
            _exData.srcAmount = collAmount;
            _exData.dfsFeeDivider = isAutomation() ? AUTOMATIC_SERVICE_FEE : MANUAL_SERVICE_FEE;
            _exData.user = user;

            (, swapAmount) = _sell(_exData);
            swapAmount -= getGasCost(swapAmount, _gasCost, _cAddresses[1]);
        } else {
            swapAmount = collAmount;
            swapAmount -= getGasCost(swapAmount, _gasCost, _cAddresses[1]);
        }

        paybackDebt(swapAmount, _cAddresses[1], borrowToken, user);

        // handle 0x fee
        tx.origin.transfer(address(this).balance);

        // log amount, collToken, borrowToken
        logger.Log(address(this), msg.sender, "CompoundRepay", abi.encode(_exData.srcAmount, swapAmount, collToken, borrowToken));
    }