lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.4.24
/* returns maximum borrowable token amount allowed by LTD params */
function getMaxLoanAmountAllowedByLtd() public view returns(uint maxLoanByLtd) {
        uint allowedByLtdDifferencePt = totalLockedAmount.mul(ltdParams.loanDifferenceLimit.add(PERCENT_100))
                                            .div(PERCENT_100);
        allowedByLtdDifferencePt = totalLoanAmount >= allowedByLtdDifferencePt ?
                                        0 : allowedByLtdDifferencePt.sub(totalLoanAmount);

        uint allowedByLtdDifferenceAmount =
            totalLoanAmount >= totalLockedAmount.add(ltdParams.allowedDifferenceAmount) ?
                0 : totalLockedAmount.add(ltdParams.allowedDifferenceAmount).sub(totalLoanAmount);

        maxLoanByLtd = allowedByLtdDifferencePt > allowedByLtdDifferenceAmount ?
                                        allowedByLtdDifferencePt : allowedByLtdDifferenceAmount;
    }
// Solidity 0.4.24
// returns CHUNK_SIZE loan products starting from some offset:
// [ productId, minDisbursedAmount, term, discountRate, collateralRatio, defaultingFeePt, maxLoanAmount, isActive ]
function getProducts(uint offset) external view returns (uint[8][CHUNK_SIZE] response) {

        for (uint16 i = 0; i < CHUNK_SIZE; i++) {

            if (offset + i >= products.length) { break; }

            LoanProduct storage product = products[offset + i];

            response[i] = [offset + i, product.minDisbursedAmount, product.term, product.discountRate,
                            product.collateralRatio, product.defaultingFeePt,
                            monetarySupervisor.getMaxLoanAmount(product.minDisbursedAmount), product.isActive ? 1 : 0 ];
        }
    }
// Solidity 0.4.24
/* returns CHUNK_SIZE loans starting from some offset. Loans data encoded as:
 [loanId, collateralAmount, repaymentAmount, borrower, productId, state, maturity, disbursementTime,
 loanAmount, interestAmount ]   */
function getLoans(uint offset) external view returns (uint[10][CHUNK_SIZE] response) {

        for (uint16 i = 0; i < CHUNK_SIZE; i++) {

            if (offset + i >= loans.length) { break; }

            response[i] = getLoanTuple(offset + i);
        }
    }
// Solidity 0.4.24
/* internal function, assuming repayment amount already transfered  */
function _repayLoan(uint loanId, uint repaymentAmount) internal {
        require(loanId < loans.length, "invalid loanId"); // next line would revert but require to emit reason
        LoanData storage loan = loans[loanId];
        require(loan.state == LoanState.Open, "loan state must be Open");
        require(repaymentAmount == loan.repaymentAmount, "repaymentAmount must be equal to tokens sent");
        require(now <= loan.maturity, "current time must be earlier than maturity");

        LoanProduct storage product = products[loan.productId];
        uint loanAmount;
        uint interestAmount;
        (loanAmount, interestAmount) = calculateLoanValues(product, loan.repaymentAmount);

        loans[loanId].state = LoanState.Repaid;

        if (interestAmount > 0) {
            augmintToken.transfer(monetarySupervisor.interestEarnedAccount(), interestAmount);
            augmintToken.burn(loanAmount);
        } else {
            // negative or zero interest (i.e. discountRate >= 0)
            augmintToken.burn(repaymentAmount);
        }

        monetarySupervisor.loanRepaymentNotification(loanAmount); // update KPIs

        loan.borrower.transfer(loan.collateralAmount); // send back ETH collateral

        emit LoanRepayed(loanId, loan.borrower);
    }
// Solidity 0.4.22
/**
 * @dev method to updated allowedTransfers for an address
 * @param _address that needs to be updated
 * @param _allowedTransfers indicating if transfers are allowed or not
 * @return boolean indicating function success.
 */
function updateAllowedTransfers(address _address, bool _allowedTransfers)
  external
  onlyOwner
  returns (bool)
  {
    // don't allow owner to change this for themselves
    // otherwise whenNotPaused will not work as expected for owner,
    // therefore prohibiting them from calling pause/unpause.
    require(_address != owner);

    allowedTransfers[_address] = _allowedTransfers;
    return true;
  }
// Solidity 0.8.9
// All tokens are minted using the random offset.
// Tokens can only be minted once, even if burned.
function mint(uint256 breedIndex, address to_) public onlyOwner {
    require(_randomnessHasBeenSet, "Randomness must be set before minting");
    require(mintedTotalSupply() < maxSupply, "Max supply minted");
    require(
      mintedBreedSupply(breedIndex) < maxSupplyPerBreed,
      "Max supply for breed minted"
    );

    uint256 indexToMint = calculateIndexToMint(breedIndex);

    // It's the responsibility of the minting script to select an even distribution of breeds for these special allocations.
    // The special allocations are automatically subject to the random offset.
    // The first developerAllocation tokens must be given to developerAddress.
    if (mintedTotalSupply() < developerAllocation) {
      require(to_ == developerAddress, "First batch for developer");
    }

    _safeMint(to_, indexToMint);
    _mintedBreedCounter[breedIndex].increment();
    _mintedTotalSupplyCounter.increment();
  }
// Solidity 0.8.9
// Provide an array of addresses and a corresponding array of quantities.
function mintBatch(
    uint256[] calldata breedIndexes,
    address[] calldata addresses,
    uint256[] calldata quantities
  ) external onlyOwner {
    require(
      breedIndexes.length == addresses.length &&
        addresses.length == quantities.length,
      "Input array lengths not equal"
    );
    for (uint256 i = 0; i < addresses.length; i++) {
      for (uint256 j = 0; j < quantities[i]; j++) {
        mint(breedIndexes[i], addresses[i]);
      }
    }
  }
// Solidity 0.4.20
// 0xCcdFbB32697c3733fC4DC693579cc567834A0E73
// This is a constructor function 
// which means the following function name has to match the contract name declared above
function STELLARFORK() {
        balances[msg.sender] =  10000000000000000000000000000000;               // 
        totalSupply =  10000000000000000000000000000000;                        // 
        name = "STELLARFORK";                                   // Set the name for display purposes (CHANGE THIS)
        decimals = 18;                                               // Amount of decimals for display purposes (CHANGE THIS)
        symbol = "FORK";                                             // Set the symbol for display purposes (CHANGE THIS)
        unitsOneEthCanBuy = 16000;                                      // Set the price of your token for the ICO (CHANGE THIS)
        fundsWallet = msg.sender;                                    // The owner of the contract gets ETH
    }
// Solidity 0.8.7
/**
 * @dev Mints `tokenId` and transfers it to `to`.
 *
 *
 * Requirements:
 *
 * - `tokenId` must not exist.
 * - `to` cannot be the zero address.
 *
 * Emits a {Transfer} event.
 */
function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);
    }
// Solidity 0.4.21
/**
 	 * accepts deposits for an arbitrary address.
 	 * retrieves tokens from the message sender and adds them to the balance of the specified address.
 	 * edgeless tokens do not have any decimals, but are represented on this contract with decimals.
 	 * @param receiver  address of the receiver
 	 *        numTokens number of tokens to deposit (0 decimals)
 	 *				 chargeGas indicates if the gas cost is subtracted from the user's edgeless token balance
 	 **/
function deposit(address receiver, uint numTokens, bool chargeGas) public isAlive {
		require(numTokens > 0);
		uint value = safeMul(numTokens, oneEDG);
		uint gasCost;
		if (chargeGas) {
			gasCost = getGasCost();
			value = safeSub(value, gasCost);
			gasPayback = safeAdd(gasPayback, gasCost);
		}
		uint newBalance = safeAdd(balanceOf[receiver], value);
		require(newBalance <= maxDeposit);
		assert(edg.transferFrom(msg.sender, address(this), numTokens));
		balanceOf[receiver] = newBalance;
		playerBalance = safeAdd(playerBalance, value);
		emit Deposit(receiver, numTokens, gasCost);
	}
// Solidity 0.4.21
/**
 	 * withdraws an amount from the user balance if the waiting time passed since the request.
 	 * @param amount the amount of tokens to withdraw
 	 **/
function withdraw(uint amount) public keepAlive {
		require(amount <= maxWithdrawal);
		require(withdrawAfter[msg.sender] > 0 && now > withdrawAfter[msg.sender]);
		withdrawAfter[msg.sender] = 0;
		uint value = safeMul(amount, oneEDG);
		balanceOf[msg.sender] = safeSub(balanceOf[msg.sender], value);
		playerBalance = safeSub(playerBalance, value);
		assert(edg.transfer(msg.sender, amount));
		emit Withdrawal(msg.sender, msg.sender, amount, 0);
	}
// Solidity 0.4.21
/**
 	 * transfers an amount from the contract balance to the owner's wallet.
 	 * @param receiver the receiver address
 	 *				 amount   the amount of tokens to withdraw (0 decimals)
 	 *				 v,r,s 		the signature of the player
 	 **/
function withdrawFor(address receiver, uint amount, uint8 v, bytes32 r, bytes32 s) public onlyAuthorized keepAlive {
		address player = ecrecover(keccak256(receiver, amount, withdrawCount[receiver]), v, r, s);
		withdrawCount[receiver]++;
		uint gasCost = getGasCost();
		uint value = safeAdd(safeMul(amount, oneEDG), gasCost);
		gasPayback = safeAdd(gasPayback, gasCost);
		balanceOf[player] = safeSub(balanceOf[player], value);
		playerBalance = safeSub(playerBalance, value);
		assert(edg.transfer(receiver, amount));
		emit Withdrawal(player, receiver, amount, gasCost);
	}
// Solidity 0.4.21
/**
 	 * transfers the player's tokens directly to the new casino contract after an update.
 	 * @param newCasino the address of the new casino contract
 	 *		  v, r, s   the signature of the player
 	 *		  chargeGas indicates if the gas cost is payed by the player.
 	 * */
function transferToNewContract(address newCasino, uint8 v, bytes32 r, bytes32 s, bool chargeGas) public onlyAuthorized keepAlive {
		address player = ecrecover(keccak256(address(this), newCasino), v, r, s);
		uint gasCost = 0;
		if(chargeGas) gasCost = getGasCost();
		uint value = safeSub(balanceOf[player], gasCost);
		require(value > oneEDG);
		//fractions of one EDG cannot be withdrawn 
		value /= oneEDG;
		playerBalance = safeSub(playerBalance, balanceOf[player]);
		balanceOf[player] = 0;
		assert(edg.transfer(newCasino, value));
		emit Withdrawal(player, newCasino, value, gasCost);
		CasinoBank cb = CasinoBank(newCasino);
		assert(cb.credit(player, value));
	}
// Solidity 0.4.21
/**
 	 * receive a player balance from the predecessor contract.
 	 * @param player the address of the player to credit the value for
 	 *				value  the number of tokens to credit (0 decimals)
 	 * */
function credit(address player, uint value) public returns(bool) {
		require(msg.sender == predecessor);
		uint valueWithDecimals = safeMul(value, oneEDG);
		balanceOf[player] = safeAdd(balanceOf[player], valueWithDecimals);
		playerBalance = safeAdd(playerBalance, valueWithDecimals);
		emit Deposit(player, value, 0);
		return true;
	}
// Solidity 0.4.21
/**
 * internal method to perform the actual state update.
 * @param player the player address
 *        winBalance the player's win balance
 *        gameCount  the player's game count
 * */
function _updateState(address player, int128 winBalance,  uint128 gameCount, uint gasCost) internal {
    State storage last = lastState[player];
  	require(gameCount > last.count);
  	int difference = updatePlayerBalance(player, winBalance, last.winBalance, gasCost);
  	lastState[player] = State(gameCount, winBalance);
  	emit StateUpdate(player, gameCount, winBalance, difference, gasCost);
  }
// Solidity 0.4.21
/**
 * determines if the msg.sender or the signer of the passed signature is the player. returns the player's address
 * @param winBalance the current winBalance, used to calculate the msg hash
 *				gameCount  the current gameCount, used to calculate the msg.hash
 *				v, r, s    the signature of the non-sending party
 * */
function determinePlayer(int128 winBalance, uint128 gameCount, uint8 v, bytes32 r, bytes32 s) view internal returns(address){
  	if (authorized[msg.sender])//casino is the sender -> player is the signer
  		return ecrecover(keccak256(winBalance, gameCount), v, r, s);
  	else
  		return msg.sender;
  }
// Solidity 0.4.21
/**
 	 * computes the difference of the win balance relative to the last known state and adds it to the player's balance.
 	 * in case the casino is the sender, the gas cost in EDG gets subtracted from the player's balance.
 	 * @param player the address of the player
 	 *				winBalance the current win-balance
 	 *				lastWinBalance the win-balance of the last known state
 	 *				gasCost the gas cost of the tx
 	 * */
function updatePlayerBalance(address player, int128 winBalance, int128 lastWinBalance, uint gasCost) internal returns(int difference){
  	difference = safeSub(winBalance, lastWinBalance);
  	int outstanding = safeSub(difference, int(gasCost));
  	uint outs;
  	if(outstanding < 0){
  		outs = uint256(outstanding * (-1));
  		playerBalance = safeSub(playerBalance, outs);
  		balanceOf[player] = safeSub(balanceOf[player], outs);
  	}
  	else{
  		outs = uint256(outstanding);
  		assert(bankroll() * oneEDG > outs);
  	  playerBalance = safeAdd(playerBalance, outs);
  	  balanceOf[player] = safeAdd(balanceOf[player], outs);
  	}
  }
// Solidity 0.4.21
/**
 * logs some seeds and game results for players wishing to have their game history logged by the contract
 * @param serverSeeds array containing the server seeds
 *        clientSeeds array containing the client seeds
 *        results     array containing the results
 *        v, r, s     the signature of the non-sending party (to make sure the correct results are logged)
 * */
function logGameData(bytes32[] serverSeeds, bytes32[] clientSeeds, int[] results, uint8 v, bytes32 r, bytes32 s) public{
    address player = determinePlayer(serverSeeds, clientSeeds, results, v, r, s);
    uint gasCost;
    //charge gas in case the server is logging the results for the player
    if(player != msg.sender){
      gasCost = (57 + 768 * serverSeeds.length / 1000)*gasPrice;
      balanceOf[player] = safeSub(balanceOf[player], gasCost);
      playerBalance = safeSub(playerBalance, gasCost);
      gasPayback = safeAdd(gasPayback, gasCost);
    }
    emit GameData(player, serverSeeds, clientSeeds, results, gasCost);
  }
// Solidity 0.4.21
/**
 * determines if the msg.sender or the signer of the passed signature is the player. returns the player's address
 * @param serverSeeds array containing the server seeds
 *        clientSeeds array containing the client seeds
 *        results     array containing the results
 *				v, r, s    the signature of the non-sending party
 * */
function determinePlayer(bytes32[] serverSeeds, bytes32[] clientSeeds, int[] results, uint8 v, bytes32 r, bytes32 s) view internal returns(address){
  	address signer = ecrecover(keccak256(serverSeeds, clientSeeds, results), v, r, s);
  	if (authorized[msg.sender])//casino is the sender -> player is the signer
  		return signer;
  	else if (authorized[signer])
  		return msg.sender;
  	else 
  	  revert();
  }
// Solidity 0.8.7
/**
 * @dev Creates a new token for every address in `tos`. TokenIDs will be automatically assigned
 * @param tos owners of new tokens
 *
 * Requirements:
 *
 * - the caller must have the `MINTER_ROLE`.
 */
function privateMint(address[] memory tos) external onlyRole(MINTER_ROLE) {
        require(!luckyDrawActive, "PPTL: Lucky draw has begun");

        for (uint256 i = 0; i < tos.length; i++) {
            _mint(tos[i], totalSupply + 1 + i);
        }
        totalSupply += tos.length;
        require(totalSupply <= maxSupply, "PPTL: Exceed max supply");
    }
// Solidity 0.8.7
/**
 * @dev Creates lucky draw provenance and user tiers
 * @param provenance_ provenance of lucky draw token metadatas
 * @param userTierIds ids of user tiers in lucky draw
 * @param userTierStartTimes start times of user tiers in lucky draw
 * @param userTierDurations durations of user tiers in lucky draw
 * @param userTierTicketMaxNums max ticket numbers per user of user tiers in lucky draw
 * @param userTierTicketPrices ticket prices of user tiers in lucky draw
 *
 * Requirements:
 *
 * - the caller must have the `OPERATOR_ROLE`.
 */
function createLuckyDraw(
        bytes32 provenance_,
        uint256[] memory userTierIds,
        uint256[] memory userTierStartTimes,
        uint256[] memory userTierDurations,
        uint256[] memory userTierTicketMaxNums,
        uint256[] memory userTierTicketPrices
    ) external onlyRole(OPERATOR_ROLE) {
        require(!luckyDrawActive, "PPTL: Lucky draw has begun");

        require(
            userTierIds.length == userTierStartTimes.length &&
            userTierIds.length == userTierDurations.length &&
            userTierIds.length == userTierTicketMaxNums.length &&
            userTierIds.length == userTierTicketPrices.length,
            "PPTL: array length mismatch"
        );

        provenance = provenance_;

        for (uint256 i = 0; i < userTierIds.length; i++) {
            _userTiers[userTierIds[i]].startTime = userTierStartTimes[i];
            _userTiers[userTierIds[i]].duration = userTierDurations[i];
            _userTiers[userTierIds[i]].ticketMaxNum = userTierTicketMaxNums[i];
            _userTiers[userTierIds[i]].ticketPrice = userTierTicketPrices[i];
        }
    }
// Solidity 0.8.7
/**
 * @dev Creates new token(s) for valid caller. TokenID(s) will be automatically assigned
 * 
 * @param userTierId user tier id of caller belonged to
 * @param ticketNum number of tokens to create
 * @param signature signature from `_authority`
 */
function draw(uint256 userTierId, uint256 ticketNum, bytes memory signature) external payable {
        require(luckyDrawActive, "PPTL: Lucky draw inactive");

        uint256 startTime = _userTiers[userTierId].startTime;
        uint256 endTime = startTime + _userTiers[userTierId].duration * 1 seconds;
        require(block.timestamp >= startTime && block.timestamp < endTime, "PPTL: Invalid time");

        bytes32 data = keccak256(abi.encode(address(this), _msgSender(), userTierId));
        require(SignatureChecker.isValidSignatureNow(_authority, data, signature), "PPTL: Invalid signature");

        uint256 newSupply = totalSupply + ticketNum;
        require(newSupply <= maxSupply, "PPTL: Exceed max supply");

        uint256 newTicketNum = _userTiers[userTierId].users[_msgSender()] + ticketNum;
        require(newTicketNum <= _userTiers[userTierId].ticketMaxNum, "PPTL: Exceed max ticket num");
        _userTiers[userTierId].users[_msgSender()] = newTicketNum;

        require(msg.value == _userTiers[userTierId].ticketPrice * ticketNum, "PPTL: Incorrect payment");
        (bool sent, ) = _payee.call{value: msg.value}("");
        require(sent, "PPTL: Failed to send Ether");

        for (uint256 i = 0; i < ticketNum; i++) {
            _mint(_msgSender(), totalSupply + i + 1);
        }
        totalSupply = newSupply;
    }
// Solidity 0.8.7
/**
 * @dev Payouts contract balance
 * 
 * @param recipients addresses to receive Ether
 * @param fractions percentages of recipients receiving Ether
 *
 * Requirements:
 *
 * - the caller must have the `WITHDRAW_ROLE`.
 */
function payout(address[] memory recipients, uint96[] memory fractions) external onlyRole(WITHDRAW_ROLE) {
        require(recipients.length == fractions.length, "PPTL: Array length mismatch");
        uint256 balance = address(this).balance;
        require(balance > 0, "PPTL: Invalid contract balance to payout");

        uint256 counter = 0;
        for (uint256 i = 0; i < recipients.length; i++) {
            require(recipients[i] != address(0), "PPTL: Invalid payout recipient");
            counter += fractions[i];

            uint256 amount = balance * fractions[i] / 100;
            (bool success, ) = recipients[i].call{value: amount}("");
            require(success, "PPTL: Failed to send Ether");
            emit BalancePayout(recipients[i], amount);
        }
        require(counter <= 100, "PPTL: Invalid payout");
    }
// Solidity 0.5.9
/**
 * @notice Approve an operator to spend tokens on the sender behalf
 * @param sender The address giving the approval
 * @param operator The address receiving the approval
 * @param id The id of the token
 */
function approveFor(
        address sender,
        address operator,
        uint256 id
    ) external {
        address owner = _ownerOf(id);
        require(sender != address(0), "sender is zero address");
        require(
            msg.sender == sender ||
            _metaTransactionContracts[msg.sender] ||
            _superOperators[msg.sender] ||
            _operatorsForAll[sender][msg.sender],
            "not authorized to approve"
        );
        require(owner == sender, "owner != sender");
        _approveFor(owner, operator, id);
    }
// Solidity 0.5.9
/**
 * @notice Get the approved operator for a specific token
 * @param id The id of the token
 * @return The address of the operator
 */
function getApproved(uint256 id) external view returns (address) {
        (address owner, bool operatorEnabled) = _ownerAndOperatorEnabledOf(id);
        require(owner != address(0), "token does not exist");
        if (operatorEnabled) {
            return _operators[id];
        } else {
            return address(0);
        }
    }
// Solidity 0.5.9
/**
 * @notice Transfer a token between 2 addresses
 * @param from The sender of the token
 * @param to The recipient of the token
 * @param id The id of the token
 */
function transferFrom(address from, address to, uint256 id) external {
        bool metaTx = _checkTransfer(from, to, id);
        _transferFrom(from, to, id);
        if (to.isContract() && _checkInterfaceWith10000Gas(to, ERC721_MANDATORY_RECEIVER)) {
            require(
                _checkOnERC721Received(metaTx ? from : msg.sender, from, to, id, ""),
                "erc721 transfer rejected by to"
            );
        }
    }
// Solidity 0.5.9
/**
 * @notice Transfer a token between 2 addresses letting the receiver knows of the transfer
 * @param from The sender of the token
 * @param to The recipient of the token
 * @param id The id of the token
 * @param data Additional data
 */
function safeTransferFrom(address from, address to, uint256 id, bytes memory data) public {
        bool metaTx = _checkTransfer(from, to, id);
        _transferFrom(from, to, id);
        if (to.isContract()) {
            require(
                _checkOnERC721Received(metaTx ? from : msg.sender, from, to, id, data),
                "ERC721: transfer rejected by to"
            );
        }
    }
// Solidity 0.5.9
/**
 * @notice Set the approval for an operator to manage all the tokens of the sender
 * @param sender The address giving the approval
 * @param operator The address receiving the approval
 * @param approved The determination of the approval
 */
function setApprovalForAllFor(
        address sender,
        address operator,
        bool approved
    ) external {
        require(sender != address(0), "Invalid sender address");
        require(
            msg.sender == sender ||
            _metaTransactionContracts[msg.sender] ||
            _superOperators[msg.sender],
            "not authorized to approve for all"
        );

        _setApprovalForAll(sender, operator, approved);
    }