lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.0
/**
 * Pay from sender to receiver a certain amount over a certain amount of time.
 **/
function paymentCreate(address payable _receiver, uint256 _time) public payable {
    // Verify that value has been sent
    require(msg.value > 0);
    // Verify the time is non-zero
    require(_time > 0);
    payments.push(Payment({
      sender: msg.sender,
      receiver: _receiver,
      timestamp: block.timestamp,
      time: _time,
      weiValue: msg.value,
      weiPaid: 0,
      isFork: false,
      parentIndex: 0,
      isForked: false,
      fork1Index: 0,
      fork2Index: 0
    }));
    emit PaymentCreated(payments.length - 1);
  }
// Solidity 0.5.0
/**
 * Return the wei owed on a payment at the current block timestamp.
 **/
function paymentWeiOwed(uint256 index) public view returns (uint256) {
    requirePaymentIndexInRange(index);
    Payment memory payment = payments[index];
    // Calculate owed wei based on current time and total wei owed/paid
    return max(payment.weiPaid, payment.weiValue * min(block.timestamp - payment.timestamp, payment.time) / payment.time) - payment.weiPaid;
  }
// Solidity 0.8.4
/**
 *   Public functions for minting.
 */
function mint(uint256 amount) public payable {
        uint256 totalIssued = _tokenIds.current();
        require(msg.value == amount*price && saleStart && totalIssued.add(amount) <= maxSupply && amount <= maxMint);
        if(accesslistSale) {
            require(Accesslist[msg.sender]);
            require(Wallets[msg.sender]+amount <= walletLimit);
            Wallets[msg.sender] += amount;
        }

        for(uint256 i=0; i<amount; i++) {
            _tokenIds.increment();
            _safeMint(msg.sender, _tokenIds.current());
        }
    }
// Solidity 0.8.4
/*
 *   Money management.
 */
function withdraw() public payable onlyOwner {

        // Splits
        uint256 saraPay = (address(this).balance / 100) * 15;
        uint256 teamPay = (address(this).balance / 1000) * 415;
        uint256 communityPay = (address(this).balance / 100) * 2;

        // Payouts
        require(payable(sara).send(saraPay));
        require(payable(taylor).send(teamPay));
        require(payable(greg).send(teamPay));
        require(payable(community).send(communityPay));
    }
// Solidity 0.4.24
/**
 *@dev Token Creator - This function is called by the factory contract and creates new tokens
 *for the user
 *@param _supply amount of DRCT tokens created by the factory contract for this swap
 *@param _owner address
 *@param _swap address
 */
function createToken(TokenStorage storage self,uint _supply, address _owner, address _swap) public{
        require(msg.sender == self.factory_contract);
        //Update total supply of DRCT Tokens
        self.total_supply = self.total_supply.add(_supply);
        //Update the total balance of the owner
        self.user_total_balances[_owner] = self.user_total_balances[_owner].add(_supply);
        //If the user has not entered any swaps already, push a zeroed address to their user_swaps mapping to prevent default value conflicts in user_swaps_index
        if (self.user_swaps[_owner].length == 0)
            self.user_swaps[_owner].push(address(0x0));
        //Add a new swap index for the owner
        self.user_swaps_index[_owner][_swap] = self.user_swaps[_owner].length;
        //Push a new swap address to the owner's swaps
        self.user_swaps[_owner].push(_swap);
        //Push a zeroed Balance struct to the swap balances mapping to prevent default value conflicts in swap_balances_index
        self.swap_balances[_swap].push(Balance({
            owner: 0,
            amount: 0
        }));
        //Add a new owner balance index for the swap
        self.swap_balances_index[_swap][_owner] = 1;
        //Push the owner's balance to the swap
        self.swap_balances[_swap].push(Balance({
            owner: _owner,
            amount: _supply
        }));
        emit CreateToken(_owner,_supply);
    }
// Solidity 0.4.24
/**
 *@dev Called by the factory contract, and pays out to a _party
 *@param _party being paid
 *@param _swap address
 */
function pay(TokenStorage storage self,address _party, address _swap) public{
        require(msg.sender == self.factory_contract);
        uint party_balance_index = self.swap_balances_index[_swap][_party];
        require(party_balance_index > 0);
        uint party_swap_balance = self.swap_balances[_swap][party_balance_index].amount;
        //reduces the users totals balance by the amount in that swap
        self.user_total_balances[_party] = self.user_total_balances[_party].sub(party_swap_balance);
        //reduces the total supply by the amount of that users in that swap
        self.total_supply = self.total_supply.sub(party_swap_balance);
        //sets the partys balance to zero for that specific swaps party balances
        self.swap_balances[_swap][party_balance_index].amount = 0;
    }
// Solidity 0.4.24
/**
 *@dev Removes the address from the swap balances for a swap, and moves the last address in the
 *swap into their place
 *@param _remove address of prevous owner
 *@param _swap address used to get last addrss of the swap to replace the removed address
 */
function removeFromSwapBalances(TokenStorage storage self,address _remove, address _swap) internal {
        uint last_address_index = self.swap_balances[_swap].length.sub(1);
        address last_address = self.swap_balances[_swap][last_address_index].owner;
        //If the address we want to remove is the final address in the swap
        if (last_address != _remove) {
            uint remove_index = self.swap_balances_index[_swap][_remove];
            //Update the swap's balance index of the last address to that of the removed address index
            self.swap_balances_index[_swap][last_address] = remove_index;
            //Set the swap's Balance struct at the removed index to the Balance struct of the last address
            self.swap_balances[_swap][remove_index] = self.swap_balances[_swap][last_address_index];
        }
        //Remove the swap_balances index for this address
        delete self.swap_balances_index[_swap][_remove];
        //Finally, decrement the swap balances length
        self.swap_balances[_swap].length = self.swap_balances[_swap].length.sub(1);
    }
// Solidity 0.4.24
/**
 *@dev ERC20 compliant transfer function
 *@param _to Address to send funds to
 *@param _amount Amount of token to send
 *@return true for successful
 */
function transfer(TokenStorage storage self, address _to, uint _amount) public returns (bool) {
        require(isWhitelisted(self,_to));
        uint balance_owner = self.user_total_balances[msg.sender];
        if (
            _to == msg.sender ||
            _to == address(0) ||
            _amount == 0 ||
            balance_owner < _amount
        ) return false;
        transferHelper(self,msg.sender, _to, _amount);
        self.user_total_balances[msg.sender] = self.user_total_balances[msg.sender].sub(_amount);
        self.user_total_balances[_to] = self.user_total_balances[_to].add(_amount);
        emit Transfer(msg.sender, _to, _amount);
        return true;
    }
// Solidity 0.4.24
/**
 *@dev ERC20 compliant transferFrom function
 *@param _from address to send funds from (must be allowed, see approve function)
 *@param _to address to send funds to
 *@param _amount amount of token to send
 *@return true for successful
 */
function transferFrom(TokenStorage storage self, address _from, address _to, uint _amount) public returns (bool) {
        require(isWhitelisted(self,_to));
        uint balance_owner = self.user_total_balances[_from];
        uint sender_allowed = self.allowed[_from][msg.sender];
        if (
            _to == _from ||
            _to == address(0) ||
            _amount == 0 ||
            balance_owner < _amount ||
            sender_allowed < _amount
        ) return false;
        transferHelper(self,_from, _to, _amount);
        self.user_total_balances[_from] = self.user_total_balances[_from].sub(_amount);
        self.user_total_balances[_to] = self.user_total_balances[_to].add(_amount);
        self.allowed[_from][msg.sender] = self.allowed[_from][msg.sender].sub(_amount);
        emit Transfer(_from, _to, _amount);
        return true;
    }
// Solidity 0.4.24
/**
 *@dev Allows a user to deploy a new swap contract, if they pay the fee
 *@param _start_date the contract start date 
 *@return new_contract address for he newly created swap address and calls 
 *event 'ContractCreation'
 */
function deployContract(uint _start_date) public payable returns (address) {
        require(msg.value >= fee && isWhitelisted(msg.sender));
        require(_start_date % 86400 == 0);
        address new_contract = deployer.newContract(msg.sender, user_contract, _start_date);
        contracts.push(new_contract);
        created_contracts[new_contract] = _start_date;
        emit ContractCreation(msg.sender,new_contract);
        return new_contract;
    }
// Solidity 0.4.24
/**
 *@dev Deploys DRCT tokens for given start date
 *@param _start_date of contract
 */
function deployTokenContract(uint _start_date) public{
        address _token;
        require(_start_date % 86400 == 0);
        require(long_tokens[_start_date] == address(0) && short_tokens[_start_date] == address(0));
        _token = new DRCT_Token();
        token_dates[_token] = _start_date;
        long_tokens[_start_date] = _token;
        token_type[_token]=2;
        _token = new DRCT_Token();
        token_type[_token]=1;
        short_tokens[_start_date] = _token;
        token_dates[_token] = _start_date;
        startDates.push(_start_date);

    }
// Solidity 0.4.24
/**
 *@dev Deploys new tokens on a DRCT_Token contract -- called from within a swap
 *@param _supply The number of tokens to create
 *@param _party the address to send the tokens to
 *@param _start_date the start date of the contract      
 *@returns ltoken the address of the created DRCT long tokens
 *@returns stoken the address of the created DRCT short tokens
 *@returns token_ratio The ratio of the created DRCT token
 */
function createToken(uint _supply, address _party, uint _start_date) public returns (address, address, uint) {
        require(created_contracts[msg.sender] == _start_date);
        address ltoken = long_tokens[_start_date];
        address stoken = short_tokens[_start_date];
        require(ltoken != address(0) && stoken != address(0));
            DRCT_Token drct_interface = DRCT_Token(ltoken);
            drct_interface.createToken(_supply.div(token_ratio), _party,msg.sender);
            drct_interface = DRCT_Token(stoken);
            drct_interface.createToken(_supply.div(token_ratio), _party,msg.sender);
        return (ltoken, stoken, token_ratio);
    }
// Solidity 0.4.24
/**
 *@dev Allows for a transfer of tokens to _to
 *@param _to The address to send tokens to
 *@param _amount The amount of tokens to send
 */
function transfer(address _to, uint _amount) public returns (bool) {
        if (balances[msg.sender] >= _amount
        && _amount > 0
        && balances[_to] + _amount > balances[_to]) {
            balances[msg.sender] = balances[msg.sender] - _amount;
            balances[_to] = balances[_to] + _amount;
            emit Transfer(msg.sender, _to, _amount);
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.4.24
/**
 *@dev Allows an address with sufficient spending allowance to send tokens on the behalf of _from
 *@param _from The address to send tokens from
 *@param _to The address to send tokens to
 *@param _amount The amount of tokens to send
 */
function transferFrom(address _from, address _to, uint _amount) public returns (bool) {
        if (balances[_from] >= _amount
        && allowed[_from][msg.sender] >= _amount
        && _amount > 0
        && balances[_to] + _amount > balances[_to]) {
            balances[_from] = balances[_from] - _amount;
            allowed[_from][msg.sender] = allowed[_from][msg.sender] - _amount;
            balances[_to] = balances[_to] + _amount;
            emit Transfer(_from, _to, _amount);
            return true;
        } else {
            return false;
        }
    }
// Solidity 0.8.4
/// @inheritdoc	IRaribleSecondarySales
function getFeeRecipients(uint256 tokenId)
        public
        view
        override
        returns (address payable[] memory recipients)
    {
        // using ERC2981 implementation to get the recipient & amount
        (address recipient, uint256 amount) = royaltyInfo(tokenId, 10000);
        if (amount != 0) {
            recipients = new address payable[](1);
            recipients[0] = payable(recipient);
        }
    }
// Solidity 0.6.12
/**
 * @notice batch received
 */
function onERC1155BatchReceived(address _operator, address _from, uint256[] calldata _ids, uint256[] calldata _amounts, bytes calldata _data) external nonReentrant returns(bytes4) {
        require(msg.sender == address(nft), "DrawCard: only accept self nft");
        require(_ids.length == _amounts.length,"DrawCard: id length must equal amount length");

        for (uint256 i = 0; i < _ids.length; i++) {
            _receiveCards(_from,_ids[i],_amounts[i],_data);
        }

        _operator;
        
        return ERC1155_BATCH_RECEIVED_VALUE;
    }
// Solidity 0.6.12
/**
 * @notice when card is ready for init
 */
function init() public onlyOperator{
        require(!isInit,"DrawCard: already init!");
        
        for (uint256 i = 2; i <= 6; i++) {
            /* token 2 - 5 is 1000 piece */
            require(nft.balanceOf(address(this),i) == INIT_BALANCE_B,"DrawCard: cards value not right!");
        }
        /* token 1 is 500 piece */
        require(nft.balanceOf(address(this),1) == INIT_BALANCE_A,"DrawCard: cards value not right!");

        isInit = true;
    }
// Solidity 0.6.12
/**
 * @notice draw card functions
 * @param time draw card time
 * @param seed seed for produce a random number
 */
function drawCard(uint256 time, uint256 seed) public whenNotPaused nonReentrant {
        require(isInit,"DrawCard: not init yet!");
        require(time > 0 && time <= MAX_DRAW_COUNT,"DrawCard: draw card time not good!");
        require(time <= countCard(),"DrawCard: not enough card!");

        uint256 costMee = DRAW_CARD_FEE.mul(time);
        require(mee.transferFrom(msg.sender,dealAddress,costMee),"DrawCard: failed to transfer token!");

        if(randomFlag){
          _getRandomNumber(seed);
          seed = linkRandomResult;
        }
        
        uint256[] memory ids = new uint256[](5);

        for(uint256 i = 0; i < time; i++) {
          uint256 id = _drawCard(seed);
          nft.safeTransferFrom(address(this),msg.sender,id,1,"");
          ids[id.sub(2)] = ids[id.sub(2)].add(1);
          randomNonce = randomNonce.add(1);
        }

        emit DrawMyCards(msg.sender,ids);
    }
// Solidity 0.6.12
/**
 * @notice transfer cards to deal address for exchange id 1 card
 */
function exchangeCard1(uint256 number) public whenNotPaused nonReentrant{
       require(number > 0, "DrawCard: can not exchange 1 card 0 piece!");
       require(nft.balanceOf(address(this),1) >= number,"DrawCard: not enought card 1 for exchange!");
       
       uint256[] memory ids = new uint256[](5);
       uint256 value = number.mul(2);
       uint256[] memory values = new uint256[](5);
       
       for(uint256 i = 0; i < 5; i++) {
           ids[i] = i.add(2);
           values[i] = value;
       }
       
       nft.safeBatchTransferFrom(msg.sender,dealAddress,ids,values,"");
       
       /* transfer card 1 for user */
       nft.safeTransferFrom(address(this), msg.sender, 1, number, "");

       emit ExchangeCard1(msg.sender,number);
    }
// Solidity 0.4.15
/**
 * Transfers `amount` tokens from `from` address to `to`
 * the sender needs to have allowance for this operation
 * @param  from - address to take tokens from
 * @param  to - address to send tokens to
 * @param  amount - amount of tokens to send
 * @return success - `true` if the transfer was succesful, `false` otherwise
 */
function transferFrom (address from, address to, uint256 amount)   returns (bool success) { 
        if (balances[from] < amount)
            return false;

        if(allowed[from][msg.sender] < amount)
            return false;

        if(amount == 0)
            return false;

        if(balances[to] + amount <= balances[to])
            return false;

        balances[from] -= amount;
        allowed[from][msg.sender] -= amount;
        balances[to] += amount;
        Transfer(from, to, amount);
        return true;
    }
// Solidity 0.8.4
/// @inheritdoc Variety
function plant(address, bytes32[] memory)
        external
        view
        override
        onlySower
        returns (uint256)
    {
        // this ensure that noone, even Sower, can directly mint tokens on this contract
        // they can only be created through the wrapping method
        revert('No direct planting, only wrapping.');
    }
// Solidity 0.8.4
/// @notice Slugify a name (tolower and replace all non 0-9az by -)
/// @param str the string to keyIfy
/// @return the key
function slugify(string memory str) public pure returns (string memory) {
        bytes memory strBytes = bytes(str);
        bytes memory lowerCase = new bytes(strBytes.length);
        uint8 charCode;
        bytes1 char;
        for (uint256 i; i < strBytes.length; i++) {
            char = strBytes[i];
            charCode = uint8(char);

            // if 0-9, a-z use the character
            if (
                (charCode >= 48 && charCode <= 57) ||
                (charCode >= 97 && charCode <= 122)
            ) {
                lowerCase[i] = char;
            } else if (charCode >= 65 && charCode <= 90) {
                // if A-Z, use lowercase
                lowerCase[i] = bytes1(charCode + 32);
            } else {
                // for all others, return a -
                lowerCase[i] = 0x2D;
            }
        }

        return string(lowerCase);
    }
// Solidity 0.8.4
/// @dev allows to set a name internally.
///      checks that the name is valid and not used, else throws
/// @param tokenId the token to name
/// @param seedlingName the name
function _setName(uint256 tokenId, string memory seedlingName) internal {
        bytes32 slugBytes;

        // if the name is not empty, require that it's valid and not used
        if (bytes(seedlingName).length > 0) {
            require(isNameValid(seedlingName) == true, 'Invalid name.');

            // also requires the name is not already used
            slugBytes = keccak256(bytes(slugify(seedlingName)));
            require(usedNames[slugBytes] == false, 'Name already used.');

            // set as used
            usedNames[slugBytes] = true;
        }

        // if it already has a name, mark the old name as unused
        string memory oldName = names[tokenId];
        if (bytes(oldName).length > 0) {
            slugBytes = keccak256(bytes(slugify(oldName)));
            usedNames[slugBytes] = false;
        }

        names[tokenId] = seedlingName;
    }
// Solidity 0.6.12
//Starts a new calculation epoch
// Because averge since start will not be accurate
function startNewEpoch() public {
        for (uint256 _pid = 0; _pid < poolInfo.length; _pid++) {
            require(
                poolInfo[_pid].epochCalculationStartBlock + 50000 <
                    block.number,
                "New epoch not ready yet"
            ); // About a week
            poolInfo[_pid].epochRewards[epoch] = poolInfo[_pid]
                .rewardsInThisEpoch;
            poolInfo[_pid].cumulativeRewardsSinceStart = poolInfo[_pid]
                .cumulativeRewardsSinceStart
                .add(poolInfo[_pid].rewardsInThisEpoch);
            poolInfo[_pid].rewardsInThisEpoch = 0;
            poolInfo[_pid].epochCalculationStartBlock = block.number;
            ++epoch;
        }
    }
// Solidity 0.6.12
// Add a new token pool. Can only be called by the owner.
// Note contract owner is meant to be a governance contract allowing NERD governance consensus
function add(
        uint256 _allocPoint,
        IERC20 _token,
        bool _withUpdate
    ) public onlyOwner {
        require(
            isTokenPairValid(address(_token)),
            "One of the paired tokens must be NERD"
        );
        if (_withUpdate) {
            massUpdatePools();
        }

        uint256 length = poolInfo.length;
        for (uint256 pid = 0; pid < length; ++pid) {
            require(poolInfo[pid].token != _token, "Error pool already added");
        }

        totalAllocPoint = totalAllocPoint.add(_allocPoint);

        poolInfo.push(
            PoolInfo({
                token: _token,
                allocPoint: _allocPoint,
                accNerdPerShare: 0,
                lockedPeriod: LP_LOCKED_PERIOD_WEEKS.mul(LP_RELEASE_TRUNK),
                emergencyWithdrawable: false,
                rewardsInThisEpoch: 0,
                cumulativeRewardsSinceStart: 0,
                startBlock: block.number,
                epochCalculationStartBlock: block.number
            })
        );
    }
// Solidity 0.6.12
//return value is /1000
function getPenaltyFactorForEarlyUnlockers(uint256 _pid, address _addr)
        public
        view
        returns (uint256)
    {
        uint256 lpReleaseStart = getLpReleaseStart(_pid, _addr);
        if (lpReleaseStart == 0 || block.timestamp < lpReleaseStart)
            return 1000;
        uint256 weeksTilNow = weeksSinceLPReleaseTilNow(_pid, _addr);
        uint256 numReleaseWeeks = poolInfo[_pid].lockedPeriod.div(
            LP_RELEASE_TRUNK
        ); //10
        if (weeksTilNow >= numReleaseWeeks) return 0;
        uint256 remainingWeeks = numReleaseWeeks.sub(weeksTilNow);
        //week 1: 45/1000 = 4.5%
        //week 2: 40/1000 = 4%
        uint256 ret = remainingWeeks.mul(50000).div(1000).div(numReleaseWeeks);
        return ret > 1000 ? 1000 : ret;
    }
// Solidity 0.6.12
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
        console.log("Mass Updating Pools");
        uint256 length = poolInfo.length;
        uint256 allRewards;
        for (uint256 pid = 0; pid < length; ++pid) {
            allRewards = allRewards.add(updatePool(pid));
        }

        pendingRewards = pendingRewards.sub(allRewards);
    }
// Solidity 0.6.12
// ----
// Function that adds pending rewards, called by the NERD token.
// ----
function updatePendingRewards() public {
        uint256 newRewards = nerd.balanceOf(address(this)).sub(nerdBalance);

        if (newRewards > 0) {
            nerdBalance = nerd.balanceOf(address(this)); // If there is no change the balance didn't change
            pendingRewards = pendingRewards.add(newRewards);
        }
    }