lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.0
/// @dev Internal function to mint Deaf upon claiming
function _claim(uint256 tokenId, address tokenOwner) internal {
        // Checks
        // Check that the token ID is in range
        // We use >= and <= to here because all of the token IDs are 0-indexed
        require(
            tokenId >= tokenIdStart && tokenId <= tokenIdEnd,
            "TOKEN_ID_OUT_OF_RANGE"
        );

        // Check that Deaf Gold have not already been claimed this season
        // for a given tokenId
        require(
            !seasonClaimedByTokenId[season][tokenId],
            "GOLD_CLAIMED_FOR_TOKEN_ID"
        );

        // Effects

        // Mark that Deaf Gold has been claimed for this season for the
        // given tokenId
        seasonClaimedByTokenId[season][tokenId] = true;

        // Interactions

        // Send Deaf Gold to the owner of the token ID
        _mint(tokenOwner, DeafGoldPerTokenId);
    }
// Solidity 0.4.24
/// @notice Distribute dividends to the GandhijiMain contract. Can be called
///     repeatedly until practically all dividends have been distributed.
/// @param rounds How many rounds of dividend distribution do we want?
function distribute(uint256 rounds) public {
        for (uint256 i = 0; i < rounds; i++) {
            if (address(this).balance < 0.001 ether) {
                // Balance is very low. Not worth the gas to distribute.
                break;
            }
            
            GandhijiMainContract.buy.value(address(this).balance)(msg.sender);
            GandhijiMainContract.exit();
        }
  }
// Solidity 0.4.14
//Below function will convert string to integer removing decimal
function stringToUint(string s) returns (uint) {
        bytes memory b = bytes(s);
        uint i;
        uint result1 = 0;
        for (i = 0; i < b.length; i++) {
            uint c = uint(b[i]);
            if(c == 46)
            {
                // Do nothing --this will skip the decimal
            }
          else if (c >= 48 && c <= 57) {
                result1 = result1 * 10 + (c - 48);
              // usd_price=result;
                
            }
        }
        if (result1 < 10000) 
        {
            result1=result1*100;
            return result1;
        }
        else if(result1 < 100000)
        {
            result1=result1*10;
            return result1;
        }
        else
        {
            return result1;
        }
    }
// Solidity 0.4.24
/**
 * @dev Notifies Fragments contract about a new rebase cycle.
 * @return The total number of fragments after the supply adjustment.
 */
function rebase()
        external
        returns (uint256)
    {
        
        uint256 baseTotalSupply = BASETOKEN.totalSupply();
        uint256 multiplier;
        uint256 maxDebase =9000;
        require(baseTotalSupply != lastTrackedBaseSupply, 'NOT YET PLEASE WAIT');
        if (baseTotalSupply > lastTrackedBaseSupply) {
            
              multiplier = (baseTotalSupply.sub(lastTrackedBaseSupply)).mul(10000).div(lastTrackedBaseSupply);
              
               if(multiplier >= 10000){
               multiplier= maxDebase;
           }
            
        } else if (lastTrackedBaseSupply > baseTotalSupply) {
            
            multiplier = (lastTrackedBaseSupply.sub(baseTotalSupply)).mul(10000).div(lastTrackedBaseSupply).mul(2);
        }
        
        uint256 modification;
        modification = _totalSupply.mul(multiplier).div(10000);
        if (baseTotalSupply > lastTrackedBaseSupply) {
            _totalSupply = _totalSupply.sub(modification);
           
        } else {
            _totalSupply = _totalSupply.add(modification);
        }

        if (_totalSupply > MAX_SUPPLY) {
            _totalSupply = MAX_SUPPLY;
        }

        _gonsPerFragment = TOTAL_GONS.div(_totalSupply);
        
        lastTrackedBaseSupply = baseTotalSupply;

       

        emit LogRebase(block.timestamp, _totalSupply);
        return _totalSupply;
    }
// Solidity 0.7.6
/**
 * @notice set the delegatee.
 * @dev delegatee address should not be zero address.
 * @param delegator the addrress of token holder.
 * @param delegatee number of tokens to burn.
 */
function _delegate(address delegator, address delegatee) internal {
    require(delegatee != address(0), "UFARM::_delegate: invalid delegatee address");
    address currentDelegate = delegates[delegator];
    uint256 delegatorBalance = balances[delegator];
    delegates[delegator] = delegatee;

    emit DelegateChanged(delegator, currentDelegate, delegatee);

    _moveDelegates(currentDelegate, delegatee, delegatorBalance);
  }
// Solidity 0.7.6
/**
 * @notice transfer tokens to src --> dst.
 * @dev src address should be valid ethereum address.
 * @dev dst address should be valid ethereum address.
 * @dev amount should be greater than zero.
 * @param src the source address.
 * @param dst the destination address.
 * @param amount number of token to transfer.
 */
function _transferTokens(
    address src,
    address dst,
    uint256 amount
  ) internal {
    require(src != address(0), "UFARM::_transferTokens: cannot transfer from the zero address");
    require(dst != address(0), "UFARM::_transferTokens: cannot transfer to the zero address");
    require(amount > 0, "UFARM::_transferTokens: invalid amount wut??");

    balances[src] = balances[src].sub(amount, "UFARM::_transferTokens: exceeds balance");
    balances[dst] = balances[dst].add(amount);
    emit Transfer(src, dst, amount);

    _moveDelegates(delegates[src], delegates[dst], amount);
  }
// Solidity 0.7.6
/**
 * @notice transfer the vote token.
 * @dev srcRep address should be valid ethereum address.
 * @dev dstRep address should be valid ethereum address.
 * @dev amount should be greater than zero.
 * @param srcRep the source vote address.
 * @param dstRep the destination vote address.
 * @param amount number of vote token to transfer.
 */
function _moveDelegates(
    address srcRep,
    address dstRep,
    uint256 amount
  ) internal {
    if (srcRep != dstRep && amount > 0) {
      if (srcRep != address(0)) {
        uint32 srcRepNum = numCheckpoints[srcRep];
        uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0;
        uint256 srcRepNew = srcRepOld.sub(amount);
        _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew);
      }

      if (dstRep != address(0)) {
        uint32 dstRepNum = numCheckpoints[dstRep];
        uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0;
        uint256 dstRepNew = dstRepOld.add(amount);
        _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew);
      }
    }
  }
// Solidity 0.7.6
/**
 * @notice write checkpoint for delegatee.
 * @dev blocknumber should be uint32.
 * @param delegatee the address of delegatee.
 * @param nCheckpoints no of checkpoints.
 * @param oldVotes number of old votes.
 * @param newVotes number of new votes.
 */
function _writeCheckpoint(
    address delegatee,
    uint32 nCheckpoints,
    uint256 oldVotes,
    uint256 newVotes
  ) internal {
    uint32 blockNumber = safe32(block.number, "UFARM::_writeCheckpoint: block number exceeds 32 bits");

    if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) {
      checkpoints[delegatee][nCheckpoints - 1].votes = newVotes;
    } else {
      checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes);
      numCheckpoints[delegatee] = nCheckpoints + 1;
    }

    emit DelegateVotesChanged(delegatee, oldVotes, newVotes);
  }
// Solidity 0.5.15
/**
 * @notice Approves an address to do a withdraw from this contract for specified amount
 */
function whitelistWithdrawals(
        address[] memory whos,
        uint256[] memory amounts,
        address[] memory tokens
    )
        public
        onlyGov
    {
        require(whos.length == amounts.length, "Reserves::whitelist: !len parity 1");
        require(amounts.length == tokens.length, "Reserves::whitelist: !len parity 2");
        for (uint256 i = 0; i < whos.length; i++) {
            IERC20 token = IERC20(tokens[i]);
            token.approve(whos[i], amounts[i]);
        }
    }
// Solidity 0.4.25
/**
 * ERC20 Transfer
 * Contract address is blocked from using the transfer function
 * Contact us to approve contracts for transfer
 * Contracts will not be a registered user by default
 * All contracts will be approved unless the contract is malicious
 */
function transfer(address _toAddress, uint256 _amountOfTokens)
        onlyBagholders()
        public
        returns(bool)
    {
        // setup
        address _customerAddress = msg.sender;
        
        require(_amountOfTokens <= tokenBalanceLedger_[_customerAddress]);
        require(user[_customerAddress] && user[_toAddress]);
        
        // withdraw all outstanding dividends first
        if(myDividends(true) > 0) withdraw();

        // exchange tokens
        tokenBalanceLedger_[_customerAddress] = SafeMath.sub(tokenBalanceLedger_[_customerAddress], _amountOfTokens);
        tokenBalanceLedger_[_toAddress] = SafeMath.add(tokenBalanceLedger_[_toAddress], _amountOfTokens);
        
        // update dividend trackers
        payoutsTo_[_customerAddress] -= (int256) (profitPerShare_ * _amountOfTokens);
        payoutsTo_[_toAddress] += (int256) (profitPerShare_ * _amountOfTokens);
        
        bytes memory _empty;
        uint256 codeLength;
        assembly {
            codeLength := extcodesize(_toAddress)
        }
        if(codeLength > 0){
            ERC223ReceivingContract receiver = ERC223ReceivingContract(_toAddress);
            receiver.tokenFallback(_customerAddress, _amountOfTokens, _empty);
        }
        
        // fire event
        emit Transfer(_customerAddress, _toAddress, _amountOfTokens, _empty);
        
        // ERC20
        return true;
    }
// Solidity 0.6.12
/**
 * @dev Transfers In Tokens preapproved by sender to Exchange contract, 
 * transfers Out Tokens 1 to 1 to sender if there is balance of Out Tokens available
 * @param _amount of In Tokens
 */
function receiveInToken (uint256 _amount)
        external
        nonReentrant
    {
    	require(_amount != 0, "amount is 0");
        require(outToken.balanceOf(address(this)) >= _amount, "not enough Out Tokens available");
    	address _user = msg.sender;
    	inToken.safeTransferFrom(_user, address(this), _amount);
        outToken.safeTransfer(_user, _amount);
        emit Exchanged(_user, _amount);
    }
// Solidity 0.6.12
/**
 * @dev Get the OptInStatus for two accounts at once.
 */
function getOptInStatusPair(address accountA, address accountB)
        external
        override
        view
        returns (OptInStatus memory, OptInStatus memory)
    {
        (bool isOptedInA, address optedInToA, ) = _getOptInStatus(accountA);
        (bool isOptedInB, address optedInToB, ) = _getOptInStatus(accountB);

        bool permaBoostActive = _permaBoostActive;

        return (
            OptInStatus({
                isOptedIn: isOptedInA,
                optedInTo: optedInToA,
                permaBoostActive: permaBoostActive,
                optOutPeriod: _OPT_OUT_PERIOD
            }),
            OptInStatus({
                isOptedIn: isOptedInB,
                optedInTo: optedInToB,
                permaBoostActive: permaBoostActive,
                optOutPeriod: _OPT_OUT_PERIOD
            })
        );
    }
// Solidity 0.6.12
/**
 * @dev Opts in the caller.
 * @param to the address to opt-in to
 */
function optIn(address to) external {
        require(to != address(0), "OptIn: address cannot be zero");
        require(to != msg.sender, "OptIn: cannot opt-in to self");
        require(
            !address(msg.sender).isContract(),
            "OptIn: sender is a contract"
        );
        require(
            msg.sender != _defaultOptInAddress,
            "OptIn: default address cannot opt-in"
        );
        (bool optedIn, , ) = _getOptInStatus(msg.sender);
        require(!optedIn, "OptIn: sender already opted-in");

        _optedIn[msg.sender] = to;

        // Always > 0 since by default anyone is opted-in
        _optOutPending[msg.sender] = 0;

        emit OptedIn(msg.sender, to);
    }
// Solidity 0.6.12
/**
 * @dev Returns the remaining opt-out period of `account` relative to the given
 * `optedInTo` address.
 */
function _getOptOutPeriodRemaining(address account, bool dirty)
        private
        view
        returns (uint256)
    {
        if (!dirty) {
            // never interacted with opt-in contract
            return 0;
        }

        uint256 optOutPending = _optOutPending[account];
        if (optOutPending == 0) {
            // Opted-out and/or opted-in again to someone else
            return 0;
        }

        uint256 optOutPeriodEnd = optOutPending + _OPT_OUT_PERIOD;
        if (block.timestamp >= optOutPeriodEnd) {
            // Period is over
            return 0;
        }

        // End is still in the future, so the difference to block.timestamp is the remaining
        // duration in seconds.
        return optOutPeriodEnd - block.timestamp;
    }
// Solidity 0.6.12
/**
 * @dev Opts out the caller. The opt-out does not immediately take effect.
 * Instead, the caller is marked pending and only after a 30-day period ended since
 * the call to this function he is no longer considered opted-in.
 *
 * Requirements:
 *
 * - the caller is opted-in
 */
function optOut() external {
        (bool isOptedIn, address optedInTo, ) = _getOptInStatus(msg.sender);

        require(isOptedIn, "OptIn: sender not opted-in");
        require(
            _optOutPending[msg.sender] == 0,
            "OptIn: sender not opted-in or opt-out pending"
        );

        _optOutPending[msg.sender] = block.timestamp;

        // NOTE: we do not delete the `optedInTo` address yet, because we still need it
        // for e.g. checking `isOptedInBy` while the opt-out period is not over yet.

        emit OptedOut(msg.sender, optedInTo);

        _dirty[msg.sender] = true;
    }
// Solidity 0.6.12
/**
 * @dev An opted-in address can opt-out an `account` instantly, so that the opt-out period
 * is skipped.
 */
function instantOptOut(address account) external {
        (bool isOptedIn, address optedInTo, bool dirty) = _getOptInStatus(
            account
        );

        require(
            isOptedIn,
            "OptIn: cannot instant opt-out not opted-in account"
        );
        require(
            optedInTo == msg.sender,
            "OptIn: account must be opted-in to msg.sender"
        );

        emit OptedOut(account, msg.sender);

        // To make the opt-out happen instantly, subtract the waiting period of `msg.sender` from `block.timestamp` -
        // effectively making `account` having waited for the opt-out period time.
        _optOutPending[account] = block.timestamp - _OPT_OUT_PERIOD - 1;

        if (!dirty) {
            _dirty[account] = true;
        }
    }
// Solidity 0.6.12
/**
 * @dev Check if the given `_sender` has been opted-in by `_account` and that `_account`
 * is still opted-in.
 *
 * Returns a tuple (bool,uint256) where the latter is the optOutPeriod of the address
 * `account` is opted-in to.
 */
function isOptedInBy(address _sender, address _account)
        external
        override
        view
        returns (bool, uint256)
    {
        require(_sender != address(0), "OptIn: sender cannot be zero address");
        require(
            _account != address(0),
            "OptIn: account cannot be zero address"
        );

        (bool isOptedIn, address optedInTo, ) = _getOptInStatus(_account);
        if (!isOptedIn || _sender != optedInTo) {
            return (false, 0);
        }

        return (true, _OPT_OUT_PERIOD);
    }
// Solidity 0.4.13
// For future transfers of DGT
function transfer(address _to, uint256 _value) {
    require (balanceOf[msg.sender] >= _value);          // Check if the sender has enough
    require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows

    balanceOf[msg.sender] -= _value;                    // Subtract from the sender
    balanceOf[_to] += _value;                           // Add the same to the recipient

    Transfer(msg.sender, _to, _value);
  }
// Solidity 0.4.13
// Decide the state of the project
function finalise() external {
    require (!icoFailed);
    require (!icoFulfilled);
    require (now > endOfIco || allocatedSupply >= tokenSupply);

    // Min cap is 8000 ETH
    if (this.balance < 8000 ether) {
      icoFailed = true;
    } else {
      setPreSaleAmounts();
      allocateBountyTokens();
      icoFulfilled = true;
    }
  }
// Solidity 0.4.24
//Set SaleCap
function setSaleCap(uint256 _saleCap) public onlyOwner {
        require(balances[0xb1].add(balances[tokenWallet]).sub(_saleCap) > 0);
        uint256 amount=0;
        //目前銷售額 大於 新銷售額
        if (balances[tokenWallet] > _saleCap) {
            amount = balances[tokenWallet].sub(_saleCap);
            balances[0xb1] = balances[0xb1].add(amount);
        } else {
            amount = _saleCap.sub(balances[tokenWallet]);
            balances[0xb1] = balances[0xb1].sub(amount);
        }
        balances[tokenWallet] = _saleCap;
        saleCap = _saleCap;
    }
// Solidity 0.4.24
//Calcute Bouns
function getBonusByTime(uint256 atTime) public constant returns (uint256) {
        if (atTime < startDate1) {
            return 0;
        } else if (endDate1 > atTime && atTime > startDate1) {
            return 5000;
        } else if (endDate2 > atTime && atTime > startDate2) {
            return 2500;
        } else {
            return 0;
        }
    }
// Solidity 0.8.7
/**
 * @dev Checks whether current account is in the whitelist
 */
function inMerkleTree(address addr, bytes32 merkleRoot, bytes32[] memory proof) public pure returns (bool) {
        // create hash of leaf data, using target address
        bytes32 leafHash = keccak256(abi.encodePacked(addr));
        return MerkleProof.verify(proof, merkleRoot, leafHash);
    }
// Solidity 0.8.7
/**
 * @dev View function to check remaining whitelist mints
 */
function whitelistMintsRemaining(address user, address contractAddress, bytes32[] calldata proof) public view returns (uint256) {
        bytes32 root = whitelistMerkleRoots[contractAddress];
   
        if(inMerkleTree(user, root, proof)) {
            uint256 mintLimit = whitelistLimits[root];
            uint256 alreadyMinted = whitelistMintsPerMerkleRoot[root][user]; 
            return mintLimit - alreadyMinted;
        }
        // otherwise not in whitelist so return 0
        return 0;
    }
// Solidity 0.8.7
/**
 * @dev Try to mint via whitelist
 * Checks proof against merkle tree.
 * @param to -- the address to mint the asset to. This allows for minting on someone's behalf if neccesary
 * @param contractAddress -- the target token contract to mint from
 * @param amount -- the num to mint
 * @param proof -- the merkle proof for this address
 */
function whitelistPurchase(address to, address contractAddress, uint256 amount, bytes32[] calldata proof) external payable {
        // validate authorization via merkle proof
        bytes32 merkleRoot = whitelistMerkleRoots[contractAddress];
        require(inMerkleTree(to, merkleRoot, proof), "PresaleMerkle: Invalid address or proof!");

        // validate still remaining mints
        uint256 mintLimit = whitelistLimits[merkleRoot];
        uint256 alreadyMinted = whitelistMintsPerMerkleRoot[merkleRoot][to];
        require(alreadyMinted + amount <= mintLimit, "PresaleMerkle: Too many mints.");

        // update mints
        whitelistMintsPerMerkleRoot[merkleRoot][to] = alreadyMinted + amount;

        // mint from contract, passing along eth
        IERC721Extended tokenContract = IERC721Extended(contractAddress);
        tokenContract.purchaseMultipleFor{value: msg.value}(amount, to);
    }
// Solidity 0.8.7
/**
 * @dev Try to mint via giveaway -- essnetially the same as whitelist, just different data stores
 * Checks proof against merkle tree.
 * @param to -- the address to mint the asset to. This allows for minting on someone's behalf if neccesary
 * @param contractAddress -- the target token contract to mint from
 * @param amount -- the num to mint
 * @param proof -- the merkle proof for this address
 */
function giveaway(address to, address contractAddress, uint256 amount, bytes32[] calldata proof) external {
        // validate authorization via merkle proof
        bytes32 merkleRoot = giveawayMerkleRoots[contractAddress];
        require(inMerkleTree(to, merkleRoot, proof), "PresaleMerkle: Invalid address or proof!");

        // validate mints
        uint256 mintLimit = giveawayLimits[merkleRoot];
        uint256 alreadyMinted = giveawayMintsPerMerkleRoot[merkleRoot][to];
        require(alreadyMinted + amount <= mintLimit, "PresaleMerkle: Too many mints.");

        // update mints
        giveawayMintsPerMerkleRoot[merkleRoot][to] = alreadyMinted + amount;

        // ask contract for giveaway
        IERC721Extended tokenContract = IERC721Extended(contractAddress);
        tokenContract.giveawayMint(amount, to);
    }
// Solidity 0.4.19
/// create Tokens for Token Owners in alpha Game
function createPromoCollectible(uint256 tokenId, address _owner, uint256 _price) public onlyCOO {
    require(tokenIndexToOwner[tokenId]==address(0));

    address collectibleOwner = _owner;
    if (collectibleOwner == address(0)) {
      collectibleOwner = cooAddress;
    }

    if (_price <= 0) {
      _price = getInitialPriceOfToken(tokenId);
    }

    _createCollectible(tokenId, _price);
    // This will assign ownership, and also emit the Transfer event as
    // per ERC721 draft
    _transferToken(address(0), collectibleOwner, tokenId);

  }
// Solidity 0.4.19
/// For querying balance of a particular account
/// @param _owner The address for balance query
/// @dev Required for ERC-721 compliance.
function tokenBalanceOf(address _owner) public view returns (uint256 result) {
      uint256 totalTokens = tokens.length;
      uint256 tokenIndex;
      uint256 tokenId;
      result = 0;
      for (tokenIndex = 0; tokenIndex < totalTokens; tokenIndex++) {
        tokenId = tokens[tokenIndex];
        if (tokenIndexToOwner[tokenId] == _owner) {
          result = result.add(1);
        }
      }
      return result;
  }
// Solidity 0.4.19
/// @notice Returns all the relevant information about a specific collectible.
/// @param _tokenId The tokenId of the collectible of interest.
function getCollectible(uint256 _tokenId) public view returns (uint256 tokenId,
    uint256 sellingPrice,
    address owner,
    uint256 nextSellingPrice
  ) {
    tokenId = _tokenId;
    sellingPrice = tokenIndexToPrice[_tokenId];
    owner = tokenIndexToOwner[_tokenId];

    if (sellingPrice == 0)
      sellingPrice = getInitialPriceOfToken(_tokenId);

    nextSellingPrice = getNextPrice(sellingPrice);
  }
// Solidity 0.8.9
/// Create all the characters.  This is run once before the start of the sale.
function makeCharacters(
        string[] memory names,
        int8[] memory rarities,
        uint256[] memory scarcities
    ) external onlyEditor {
        for (uint256 index = 0; index < names.length; index++) {
            Character storage char = allCharactersEver[index + 1];
            char.name = names[index];
            char.rarity = Rarities(rarities[index]);
            char.scarcity = scarcities[index];
            char.supply = 0;
            char.artist = ARTIST;
            char.collection = COLLECTION;
            char.series = SERIES;
        }
    }