lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.6
/**************************************************************************************
 * Cancel orders
 **************************************************************************************/
function cancelSell(bytes32 orderId) external accrueByTime distribute ifRunning {
        SellOrder storage o = sellOrder[orderId];
        User storage u = userStruct[o.seller];
        require(o.seller == msg.sender, "Sender is not the seller.");
        u.balanceHodl = u.balanceHodl.add(o.volumeHodl);
        u.sellOrderIdFifo.remove(orderId);
        sellOrderIdFifo.remove(orderId);
        emit SellOrderCancelled(msg.sender, orderId);
    }
// Solidity 0.6.6
// Moves forward in 1-day steps to prevent overflow
function rates() public view returns(uint hodlUsd, uint dailyAccrualRate) {
        hodlUsd = HODL_USD;
        dailyAccrualRate = DAILY_ACCRUAL_RATE;
        uint startTime = BIRTHDAY.add(SLEEP_TIME);
        if(now > startTime) {
            uint daysFromStart = (now.sub(startTime)) / 1 days;
            uint daysUnprocessed = daysFromStart.sub(accrualDaysProcessed);
            if(daysUnprocessed > 0) {
                hodlUsd = HODL_USD.mul(DAILY_ACCRUAL_RATE).div(USD_PRECISION);
                dailyAccrualRate = DAILY_ACCRUAL_RATE.mul(DAILY_ACCRUAL_RATE_DECAY).div(USD_PRECISION);
            }
        }
    }
// Solidity 0.6.6
/**************************************************************************************
 * Initialization functions that support migration cannot be used after trading starts
 **************************************************************************************/
function initUser(address userAddr, uint hodl) external onlyOwner payable {
        User storage u = userStruct[userAddr];
        User storage r = userStruct[address(this)];
        u.balanceEth  = u.balanceEth.add(msg.value);
        u.balanceHodl = u.balanceHodl.add(hodl);
        r.balanceHodl = r.balanceHodl.sub(hodl);
        _makeHodler(userAddr);
        emit UserInitialized(msg.sender, userAddr, hodl, msg.value);
    }
// Solidity 0.6.12
/**
 * @dev Delegates execution to an implementation contract.
 * This is a low level function that doesn't return to its internal call site.
 * It will return to the external caller whatever the implementation returns.
 * @param implementation Address to delegate.
 */
function _delegate(address implementation) internal {
       assembly {
           // Copy msg.data. We take full control of memory in this inline assembly
           // block because it will not return to Solidity code. We overwrite the
           // Solidity scratch pad at memory position 0.
           calldatacopy(0, 0, calldatasize())

           // Call the implementation.
           // out and outsize are 0 because we don't know the size yet.
           let result := delegatecall(
               gas(),
               implementation,
               0,
               calldatasize(),
               0,
               0
           )

           // Copy the returned data.
           returndatacopy(0, 0, returndatasize())

           switch result
               // delegatecall returns 0 on error.
               case 0 {
                   revert(0, returndatasize())
               }
               default {
                   return(0, returndatasize())
               }
       }
   }
// Solidity 0.6.6
// Create a new staking event
function createStakingEvent(uint256[] memory _cardIdList, uint256 _cardAmountAny, uint256[] memory _cardAmountList, uint256 _cardRewardId,
        uint256 _blockStakeLength, uint256 _blockEventClose, uint256[] memory _toBurnIdList, uint256[] memory _toBurnAmountList) public onlyOwner {

        require(_cardIdList.length > 0, "Accepted card list is empty");
        require(_cardAmountAny > 0 || _cardAmountList.length > 0, "Card amount required not specified");
        require(_blockEventClose > block.number, "blockEventClose < current block");
        require(_toBurnIdList.length == _toBurnAmountList.length, "ToBurn arrays have different length");
        require(_cardAmountAny == 0 || _toBurnIdList.length == 0, "ToBurn not supported with anyEvent");

        stakingEvents.push(StakingEvent({
        cardIdList: _cardIdList,
        cardAmountAny: _cardAmountAny,
        cardAmountList: _cardAmountList,
        cardRewardId: _cardRewardId,
        blockStakeLength: _blockStakeLength,
        blockEventClose: _blockEventClose,
        toBurnIdList: _toBurnIdList,
        toBurnAmountList: _toBurnAmountList
        }));

        emit StakingEventCreated(stakingEvents.length - 1);
    }
// Solidity 0.6.6
// Stake cards into a staking event
function stakeAny(uint256 _eventId, uint256[] memory _cardIdList, uint256[] memory _cardAmountList) public {
        require(_cardIdList.length == _cardAmountList.length, "Arrays have different length");

        StakingEvent storage _event = stakingEvents[_eventId];
        UserInfo storage _userInfo = userInfo[msg.sender][_eventId];

        require(block.number <= _event.blockEventClose, "Event is closed");
        require(_userInfo.isCompleted == false, "Address already completed event");
        require(_userInfo.blockEnd == 0, "Address already staked for this event");
        require(_event.cardAmountAny > 0, "Not a stakeAny event");

        for (uint256 i = 0; i < _cardIdList.length; i++) {
            require(_isInArray(_cardIdList[i], _event.cardIdList), "Card not accepted");
        }

        uint256 total = 0;
        for (uint256 i = 0; i < _cardAmountList.length; i++) {
            total = total.add(_cardAmountList[i]);
        }

        require(total == _event.cardAmountAny, "Wrong card total");

        pepemonFactory.safeBatchTransferFrom(msg.sender, address(this), _cardIdList, _cardAmountList, "");

        // Save list cards staked in storage
        for (uint256 i = 0; i < _cardIdList.length; i++) {
            uint256 cardId = _cardIdList[i];
            uint256 amount = _cardAmountList[i];

            cardsStaked[msg.sender][_eventId][cardId] = amount;
        }

        _userInfo.blockEnd = block.number.add(_event.blockStakeLength);

        emit StakingEventEntered(msg.sender, _eventId);
    }
// Solidity 0.7.6
// Add a new token to the pool. Can only be called by the owner.
function add(
        uint256 _allocPoint,
        IERC20 _token,
        bool _withUpdate
    ) external onlyOwner {
        require(!isTokenAdded(_token), "add: token already added");

        if (_withUpdate) {
            massUpdatePools();
        }
        uint256 lastRewardBlock =
            block.number > startBlock ? block.number : startBlock;
        totalAllocPoint = totalAllocPoint.add(_allocPoint);

        uint256 pid = poolInfo.length;
        poolInfo.push(
            PoolInfo({
                token: _token,
                allocPoint: _allocPoint,
                lastRewardBlock: lastRewardBlock,
                accRewardPerShare: 0
            })
        );
        poolPidByAddress[address(_token)] = pid;

        emit TokenAdded(address(_token), pid, _allocPoint);
    }
// Solidity 0.7.6
// claim rewards
function claim() external{
        uint256 i;
        for (i = 0; i < poolInfo.length; ++i) {
            updatePool(i);
            accrueReward(i);
            UserPoolInfo storage userPool = userPoolInfo[i][msg.sender];
            userPool.accruedReward = calcReward(poolInfo[i], userPool);
        }
        uint256 unlocked = calcUnlocked(rewards[msg.sender]).sub(claimedRewards[msg.sender]);
        if (unlocked > 0) {
            _safeRewardTransfer(msg.sender, unlocked);
        }
        claimedRewards[msg.sender] = claimedRewards[msg.sender].add(unlocked);
        emit Claimed(msg.sender, unlocked);
    }
// Solidity 0.7.6
// Deposit tokens to liquidity mining for reward token allocation.
function deposit(uint256 _pid, uint256 _amount) external {
        require(block.number <= endBlock, "LP mining has ended.");
        updatePool(_pid);
        accrueReward(_pid);

        UserPoolInfo storage userPool = userPoolInfo[_pid][msg.sender];

        if (_amount > 0) {
            poolInfo[_pid].token.safeTransferFrom(
                address(msg.sender),
                address(this),
                _amount
            );

            userPool.amount = userPool.amount.add(_amount);
        }

        userPool.accruedReward = calcReward(poolInfo[_pid], userPoolInfo[_pid][msg.sender]);
        emit Deposited(msg.sender, _pid, _amount);
    }
// Solidity 0.7.6
// Set unlocks infos - block number and quota.
function setUnlocks(uint256[] calldata _blocks, uint256[] calldata _quotas) external onlyOwner {
        require(_blocks.length == _quotas.length, "Should be same length");
        for (uint256 i = 0; i < _blocks.length; ++i) {
            unlocks.push(UnlockInfo(_blocks[i], _quotas[i]));
            unlocksTotalQuotation = unlocksTotalQuotation.add(_quotas[i]);
        }
    }
// Solidity 0.7.6
// Withdraw tokens from rewardToken liquidity mining.
function withdraw(uint256 _pid, uint256 _amount) external {
        require(userPoolInfo[_pid][msg.sender].amount >= _amount, "withdraw: not enough amount");
        updatePool(_pid);
        accrueReward(_pid);
        UserPoolInfo storage userPool = userPoolInfo[_pid][msg.sender];
        if (_amount > 0) {
            userPool.amount = userPool.amount.sub(_amount);
            poolInfo[_pid].token.safeTransfer(address(msg.sender), _amount);
        }

        userPool.accruedReward = calcReward(poolInfo[_pid], userPoolInfo[_pid][msg.sender]);
        emit Withdrawn(msg.sender, _pid, _amount);
    }
// Solidity 0.8.7
// Withdraws amount specified (ETH) from balance of contract to owner account (owner-only)
function withdrawPartial(uint256 _amount)
    public
    onlyOwner
    {
        require(twoStage);
        // Check that amount is not more than total contract balance
        require(
        _amount > 0 && _amount <= address(this).balance,
        "Withdraw amount must be positive and not exceed total contract balance"
        );
        payable(msg.sender).transfer(_amount);
        twoStage = false;
    }
// Solidity 0.7.6
// Migrate token to another lp contract. Can be called by anyone.
function migrate(uint256 _pid) external {
        require(address(migrator) != address(0), "migrate: no migrator");
        PoolInfo storage pool = poolInfo[_pid];
        IERC20 token = pool.token;
        uint256 bal = token.balanceOf(address(this));
        token.safeApprove(address(migrator), bal);
        IERC20 newToken = migrator.migrate(token);
        require(bal == newToken.balanceOf(address(this)), "migrate: bad");
        pool.token = newToken;

        delete poolPidByAddress[address(token)];
        poolPidByAddress[address(newToken)] = _pid;

        emit TokenMigrated(address(token), address(newToken), _pid);
    }
// Solidity 0.8.4
/**
 * @dev Triggers a transfer to `account` of the amount of Ether they are owed, according to their percentage of the
 * total shares and their previous withdrawals.
 */
function release(address payable account) public virtual {
        require(_shares[account] > 0, "PaymentSplitter: account has no shares");

        uint256 totalReceived = address(this).balance + totalReleased();
        uint256 payment = _pendingPayment(account, totalReceived, released(account));

        require(payment != 0, "PaymentSplitter: account is not due payment");

        _released[account] += payment;
        _totalReleased += payment;

        AddressUpgradeable.sendValue(account, payment);
        emit PaymentReleased(account, payment);
    }
// Solidity 0.6.12
// function to get claimable amount for any user
function getClaimableAmount(address _user) external view returns(uint256) {
        LockInfo[] memory lockInfoArrayForUser = lockInfoByUser[_user];
        uint256 totalTransferableAmount = 0;
        uint i;
        for (i=latestCounterByUser[_user]; i<lockInfoArrayForUser.length; i++){
            uint256 lockingPeriodHere = lockingPeriod;
            if(lockInfoArrayForUser[i]._isDev){
                lockingPeriodHere = devLockingPeriod;
            }
            if(now >= (lockInfoArrayForUser[i]._timestamp.add(lockingPeriodHere))){
                totalTransferableAmount = totalTransferableAmount.add(lockInfoArrayForUser[i]._amount);
            } else {
                break;
            }
        }
        return totalTransferableAmount;
    }
// Solidity 0.8.4
/**
 * @dev Add a new payee to the contract.
 * @param account The address of the payee to add.
 * @param shares_ The number of shares owned by the payee.
 */
function _addPayee(address account, uint256 shares_) private {
        require(account != address(0), "PaymentSplitter: account is the zero address");
        require(shares_ > 0, "PaymentSplitter: shares are 0");
        require(_shares[account] == 0, "PaymentSplitter: account already has shares");

        _payees.push(account);
        _shares[account] = shares_;
        _totalShares = _totalShares + shares_;
        emit PayeeAdded(account, shares_);
    }
// Solidity 0.4.21
/**
 * Add new star
 */
function addStar(address owner, uint8 gid, uint8 zIndex, uint16 box, uint8 inbox, uint8 stype, uint8 color, uint256 price) internal returns(uint256) {
        Star memory _star = Star({
            owner: owner,
            gid: gid, zIndex: zIndex, box: box, inbox: inbox,
            stype: stype, color: color,
            price: price, sell: 0, deleted: false, name: "", message: ""
        });
        uint256 starId = stars.push(_star) - 1;
        placeStar(gid, zIndex, box, starId);
        return starId;
    }
// Solidity 0.4.21
/**
 * Get star by id
 */
function getStar(uint256 starId) external view returns(address owner, uint8 gid, uint8 zIndex, uint16 box, uint8 inbox,
                                                           uint8 stype, uint8 color,
                                                           uint256 price, uint256 sell, bool deleted,
                                                           string name, string message) {
        Star storage _star = stars[starId];
        owner      = _star.owner;
        gid        = _star.gid;
        zIndex     = _star.zIndex;
        box        = _star.box;
        inbox      = _star.inbox;
        stype      = _star.stype;
        color      = _star.color;
        price      = _star.price;
        sell       = _star.sell;
        deleted    = _star.deleted;
        name       = _star.name;
        message    = _star.message;
    }
// Solidity 0.4.21
/**
 * Set validation data
 */
function setValidationData(uint16 _zMin, uint16 _zMax, uint8 _lName, uint8 _lMessage, uint8 _maxCT, uint8 _maxIR, uint16 _boxSize) external onlyOwner {
        zMin       = _zMin;
        zMax       = _zMax;
        lName      = _lName;
        lMessage   = _lMessage;
        maxCT      = _maxCT;
        maxIRandom = _maxIR;
        boxSize    = _boxSize;
        inboxXY    = uint8((boxSize * boxSize) / 4);
    }
// Solidity 0.4.21
/**
 * Get random star position
 */
function getRandomPosition(uint8 gid, uint8 zIndex) internal returns(uint16 box, uint8 inbox) {
        uint16 boxCount = getBoxCountZIndex(zIndex);
        uint16 randBox  = 0;
        if (boxCount == 0) revert();

        uint8 ii   = maxIRandom;
        bool valid = false;
        while (!valid && ii > 0) {
            randBox = getRandom16(0, boxCount);
            valid   = isValidBox(gid, zIndex, randBox);
            ii--;
        }

        if (!valid) revert();
        return(randBox, getRandom8(0, inboxXY));
    }
// Solidity 0.4.21
/**
 * Create star
 */
function createStar(uint8 gid, uint16 z, string name, string message) external payable {
        // Check basic requires
        require(isValidGid(gid));
        require(isValidZ(z));
        require(isValidNameLength(name));
        require(isValidMessageLength(message));

        // Get zIndex
        uint8   zIndex    = getZIndex(z);
        uint256 starPrice = getCreatePrice(z, getZCount(gid, zIndex));
        require(isValidMsgValue(starPrice));

        // Create star (need to split method into two because solidity got error - to deep stack)
        uint256 starId = newStar(gid, zIndex, starPrice);
        setStarNameMessage(starId, name, message);

        // Event and returns data
        emit StarCreated(starId);
    }
// Solidity 0.4.21
/**
 * Update start method
 */
function updateStar(uint256 starId, string name, string message) external payable {
        // Exists and owned star
        require(starExists(starId));
        require(isStarOwner(starId, msg.sender));

        // Check basic requires
        require(isValidNameLength(name));
        require(isValidMessageLength(message));        

        // Get star update price
        uint256 commission = getCommission(stars[starId].price);
        require(isValidMsgValue(commission));

        // Update star
        setStarNameMessage(starId, name, message);
        emit StarUpdated(starId, 1);
    }
// Solidity 0.4.21
/**
 * Delete star
 */
function deleteStar(uint256 starId) external payable {
        // Exists and owned star
        require(starExists(starId));
        require(isStarOwner(starId, msg.sender));

        // Get star update price
        uint256 commission = getCommission(stars[starId].price);
        require(isValidMsgValue(commission));

        // Update star data
        setStarDeleted(starId);
        emit StarDeleted(starId, msg.sender);
    }
// Solidity 0.4.21
/**
 * Gift star
 */
function giftStar(uint256 starId, address recipient) external payable {
        // Check star exists owned
        require(starExists(starId));
        require(recipient != address(0));
        require(isStarOwner(starId, msg.sender));
        require(!isStarOwner(starId, recipient));

        // Get gift commission
        uint256 commission = getCommission(stars[starId].price);
        require(isValidMsgValue(commission));

        // Update star
        setStarNewOwner(starId, recipient);
        setStarSellPrice(starId, 0);
        emit StarGifted(starId, msg.sender, recipient);
        emit StarUpdated(starId, 3);
    }
// Solidity 0.4.21
/**
 * Buy star
 */
function buyStar(uint256 starId, string name, string message) external payable {
        // Exists and NOT owner
        require(starExists(starId));
        require(!isStarOwner(starId, msg.sender));
        require(stars[starId].sell > 0);

        // Get sell commission and check value
        uint256 commission = getCommission(stars[starId].price);
        uint256 starPrice  = stars[starId].sell;
        uint256 totalPrice = starPrice + commission;
        require(isValidMsgValue(totalPrice));

        // Transfer money to seller
        address seller = stars[starId].owner;
        seller.transfer(starPrice);

        // Update star data
        setStarNewOwner(starId, msg.sender);
        setStarSellPrice(starId, 0);
        setStarNameMessage(starId, name, message);
        emit StarSold(starId, seller, msg.sender, starPrice);
        emit StarUpdated(starId, 4);
    }
// Solidity 0.4.24
// Forward ERC20 methods to upgraded contract after the upgrade timestamp has been reached
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        if (now > upgradeTimestamp) {
            return UpgradedStandardToken(upgradeAddress).transferFromByLegacy(msg.sender, _from, _to, _value);
        } else {
            return super.transferFrom(_from, _to, _value);
        }
    }
// Solidity 0.6.12
// Deposit LP tokens to TopDog for BONE allocation.
function deposit(uint256 _pid, uint256 _amount) public nonReentrant {
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 pending = user.amount.mul(pool.accBonePerShare).div(1e12).sub(user.rewardDebt);
            if(pending > 0) {
                // safeBoneTransfer(msg.sender, pending);
                uint256 sendAmount = pending.mul(rewardMintPercent).div(100);
                safeBoneTransfer(msg.sender, sendAmount);
                if(rewardMintPercent != 100) {
                    safeBoneTransfer(address(boneLocker), pending.sub(sendAmount)); // Rest amount sent to Bone token contract
                    boneLocker.lock(msg.sender, pending.sub(sendAmount), false); //function called for token time-lock
                }
            }
        }
        if(_amount > 0) {
            pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
            user.amount = user.amount.add(_amount);
        }
        user.rewardDebt = user.amount.mul(pool.accBonePerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.4.24
/**
 * @notice Initiates a new rebase operation, provided the minimum time period has elapsed.
 *
 * @dev The supply adjustment equals (_totalSupply * DeviationFromTargetRate) / rebaseLag
 *      Where DeviationFromTargetRate is (MarketOracleRate - targetRate) / targetRate
 *      and targetRate is 1
 */
function rebase() external onlyOrchestrator {
        require(inRebaseWindow());

        // This comparison also ensures there is no reentrancy.
        require(lastRebaseTimestampSec.add(minRebaseTimeIntervalSec) < now);

        // Snap the rebase time to the start of this window.
        lastRebaseTimestampSec = now.sub(
            now.mod(minRebaseTimeIntervalSec)).add(rebaseWindowOffsetSec);

        epoch = epoch.add(1);

        uint256 targetRate = TARGET_RATE;

        uint256 exchangeRate;
        bool rateValid;
        (exchangeRate, rateValid) = marketOracle.getData();
        require(rateValid);

        if (exchangeRate > MAX_RATE) {
            exchangeRate = MAX_RATE;
        }

        int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);

        // Apply the Dampening factor.
        supplyDelta = supplyDelta.div(rebaseLag.toInt256Safe());

        if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
            supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
        }

        uint256 supplyAfterRebase = uFrags.rebase(epoch, supplyDelta);
        assert(supplyAfterRebase <= MAX_SUPPLY);
        emit LogRebase(epoch, exchangeRate, supplyDelta, now);
    }
// Solidity 0.8.7
// Method which is used to mint during the standard minting window
function mint(uint256 _amountMinted, address _recipient)
        public
        payable
        nonReentrant
    {
        if (owner() != _msgSender()) {
            require(
                saleTime != 0 && saleTime <= block.timestamp,
                "ERC721: Sale is paused..."
            );
        }
        require(totalSupply() < supplyCap, "ERC721: Sale is finished.");
        require(
            _amountMinted > 0 && _amountMinted <= perTxLimit,
            "ERC721: You may only mint up to 20 Empty Buns."
        );
        require(
            totalSupply() + _amountMinted < supplyCap,
            "ERC721: Transaction would exceed supply cap."
        );
        require(
            msg.value >= getTokenPrice(true) * _amountMinted,
            "ERC721: Incorrect value sent."
        );

        // Prevent nefarious contracts from bypassing limits
        require(
            tx.origin == _msgSender(),
            "ERC721: The caller is another contract."
        );

        for (uint256 i = 0; i < _amountMinted; i++) {
            _safeMint(_recipient, tokenCounter);
            tokenCounter++;
        }
    }