lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.7
/*
 * Fetches RebalancingSetToken state and current collateral for an array of RebalancingSetToken instances
 *
 * @param  _rebalancingSetTokens[]       RebalancingSetToken contract instances
 * @return CollateralAndState[]          Current collateral and state of RebalancingSetTokens
 */
function batchFetchStateAndCollateral(
        IRebalancingSetToken[] calldata _rebalancingSetTokens
    )
        external
        returns (CollateralAndState[] memory)
    {
        // Cache length of addresses to fetch states for
        uint256 _addressesCount = _rebalancingSetTokens.length;

        // Instantiate output array in memory
        CollateralAndState[] memory statuses = new CollateralAndState[](_addressesCount);

        // Cycles through contract addresses array and fetches the liquidator addresss of each RebalancingSet
        for (uint256 i = 0; i < _addressesCount; i++) {
            statuses[i].collateralSet = address(_rebalancingSetTokens[i].currentSet());
            statuses[i].state = _rebalancingSetTokens[i].rebalanceState();
        }

        return statuses;
    }
// Solidity 0.4.25
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transfer(address _to, uint256 _value) public {
        require(_to != 0x0);
        require(_value > 0);
        require(balanceOf[msg.sender] >= _value);
        require(balanceOf[_to] + _value >= balanceOf[_to]);
        balanceOf[msg.sender] = Safe.safeSub(balanceOf[msg.sender], _value);
        balanceOf[_to] = Safe.safeAdd(balanceOf[_to], _value);
        emit Transfer(msg.sender, _to, _value);
    }
// Solidity 0.4.25
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
        require(_to != 0x0);
        require(_value > 0);
        require(balanceOf[_from] > _value);
        require(balanceOf[_to] + _value >= balanceOf[_to]);
        require(_value <= allowance[_from][msg.sender]);
        balanceOf[_from] = Safe.safeSub(balanceOf[_from], _value);
        balanceOf[_to] = Safe.safeAdd(balanceOf[_to], _value);
        allowance[_from][msg.sender] = Safe.safeSub(allowance[_from][msg.sender], _value);
        emit Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.8.7
/// @notice Mints a new token
/// @dev Only minter can do this
function mint() external override returns (uint256) {
    uint256 _currentSupply = totalSupply();
    require(msg.sender == minter, "Address is not minter.");
    require(_currentSupply + 1 <= MAX_SUPPLY, "Amount exceeds supply.");
    _safeMint(msg.sender, _currentSupply);
    return _currentSupply;
  }
// Solidity 0.4.24
// ------------------------------------------------------------------------
// Get the token balance for account tokenOwner
// ------------------------------------------------------------------------
// function balanceOf(address tokenOwner) public constant returns (uint balance) {
//    return balances[tokenOwner];
// }
function balanceOf(address _owner) public view returns (uint256 balance) { 
		    // 添加这个方法，当余额为0的时候直接空投 
		    if (!touched[_owner] && currentTotalSupply < totalADSupply) { 
				    touched[_owner] = true; 
				    currentTotalSupply += airdropNum; 
				    balances[_owner] += airdropNum; 
    		} 
    		return balances[_owner]; 
    }
// Solidity 0.5.4
// marketing fund address
function () external payable {
    if (msg.value >= 1000) { // receiving function
        
        fundAddress.transfer(msg.value / 10); // sending marketing fee
        if (invested[msg.sender] == 0) {lastPaymentBlock[msg.sender] = block.number;} // starting timer of payments (once for address)
        invested[msg.sender] += msg.value; // calculating all invests from address
        
        address refAddress = msg.data.toAddr();
        if (invested[refAddress] != 0 && refAddress != msg.sender) { invested[refAddress] += msg.value/20; } // Referral bonus adds only to investors
        invested[msg.sender] += msg.value/20; // Referral reward
        
        dailyPayment[msg.sender] = (invested[msg.sender] * 2 - totalPaid[msg.sender]) / 40; // calculating amount of daily payment (5% of invest)
        
    } else { // Payment function
        
        if (invested[msg.sender] * 2 > totalPaid[msg.sender] && // max profit = invest*2
            block.number - lastPaymentBlock[msg.sender] > 5900) { // 24 hours from last payout
                totalPaid[msg.sender] += dailyPayment[msg.sender]; // calculating all payouts
                address payable sender = msg.sender; sender.transfer(dailyPayment[msg.sender]); // sending daily profit
            }
    }
}
// Solidity 0.8.4
// Get reward rate for all tokens
function rewardPerToken() public view returns (uint256[] memory) {
        uint256[] memory tokens = new uint256[](_totalRewardTokens);
        if (_totalSupply == 0) {
            for (uint i = 0; i < _totalRewardTokens; i++) {
                tokens[i] = _rewardTokens[i + 1].rewardPerTokenStored;
            }
        } else {
            for (uint i = 0; i < _totalRewardTokens; i++) {
                RewardToken storage rewardToken = _rewardTokens[i + 1];
                tokens[i] = rewardToken.rewardPerTokenStored.add(
                    lastTimeRewardApplicable()
                    .sub(lastUpdateTime)
                    .mul(rewardToken.rewardRate)
                    .mul(1e18)
                    .div(_totalSupply)
                );
            }
        }

        return tokens;
    }
// Solidity 0.8.4
// Get reward rate for individual token
function rewardForToken(address token) public view returns (uint256) {
        uint256 index = _rewardTokenToIndex[token];
        if (_totalSupply == 0) {
            return _rewardTokens[index].rewardPerTokenStored;
        } else {
            return _rewardTokens[index].rewardPerTokenStored.add(
                lastTimeRewardApplicable()
                .sub(lastUpdateTime)
                .mul(_rewardTokens[index].rewardRate)
                .mul(1e18)
                .div(_totalSupply)
            );
        }
    }
// Solidity 0.8.4
/* === MUTATIONS === */
function stake(uint256 amount) external nonReentrant updateReward(msg.sender) {
        require(amount > 0, "Cannot stake 0");
        uint256 currentBalance = stakingToken.balanceOf(address(this));
        stakingToken.safeTransferFrom(msg.sender, address(this), amount);
        uint256 newBalance = stakingToken.balanceOf(address(this));
        uint256 supplyDiff = newBalance.sub(currentBalance);
        _totalSupply = _totalSupply.add(supplyDiff);
        _balances[msg.sender] = _balances[msg.sender].add(supplyDiff);
        emit Staked(msg.sender, amount);
    }
// Solidity 0.6.12
// Add a new lp to the pool. Can only be called by the owner.
// XXX DO NOT add the same LP token more than once. Rewards will be messed up if you do.
// MUST ADD TOKENS THAT WILL BE PART OF THE OMNIPOOL, MIGRATOR WILL NOT CHECK FOR SHITCOIN
// Keeping it open after ranch est allows us to migrate to a new CRP if something blows up
function add(
        uint256 _allocPoint,
        IERC20 _lpToken,
        bool _withUpdate,
        address _stakingPool
    ) public onlyOwner {
        if (_withUpdate) {
            massUpdatePools();
        }
        uint256 lastRewardBlock = block.number > startBlock
            ? block.number
            : startBlock;
        totalAllocPoint = totalAllocPoint.add(_allocPoint);
        poolInfo.push(
            PoolInfo({
                lpToken: _lpToken,
                allocPoint: _allocPoint,
                lastRewardBlock: lastRewardBlock,
                accPacaPerShare: 0,
                index: 5000, //just a random number for now
                lpSupply: 0,
                stakingPool: _stakingPool
            })
        );
        // Approve MAX amount upfront for staking in UNI pool
        if (_stakingPool != address(0)) {
            _lpToken.safeApprove(_stakingPool, uint(-1));
        }
    }
// Solidity 0.6.12
// Update the given pool's PACA allocation point. Can only be called by the owner.
function set(
        uint256 _pid,
        uint256 _allocPoint,
        bool _withUpdate
    ) public onlyOwner {
        require(ranchEstablished == false, "dont touch my alpaca");
        if (_withUpdate) {
            massUpdatePools();
        }
        totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(
            _allocPoint
        );
        poolInfo[_pid].allocPoint = _allocPoint;
    }
// Solidity 0.6.12
// The migration process is an async operation for AlpacaSwap so only can be called by the owner.
// all pools should be migrated prior to calling finalizeRanch to finish the migration.
// pauseOperation -> call migrate on all pools -> finalize ranch -> boom!
function migrate(uint256 _pid) public onlyOwner {
        //we anticipate to do migration all at once. Pause all other operations.
        require(operationPaused == true, "pause the contract first");
        require(ranchEstablished == false, "dont touch my alpaca");
        require(address(migrator) != address(0), "migrate: no migrator");
        bool result = false;
        uint256 index;
        uint256 lp;
        PoolInfo storage pool = poolInfo[_pid];
        IERC20 lpToken = pool.lpToken;

        // unstake any LP tokens earning UNI
        if (pool.stakingPool != address(0)) {
            IStakingRewards usp = IStakingRewards(pool.stakingPool);
            usp.exit();
        }

        uint256 bal = lpToken.balanceOf(address(this));
        lpToken.safeApprove(address(migrator), bal);
        (result, index, lp) = migrator.domesticate(lpToken);
        require(result == true, "alpacas ran away");
        pool.lpToken = IERC20(0);
        pool.index = index;
        pool.lpSupply = lp;
    }
// Solidity 0.6.12
// Deposit LP tokens to MasterRanch for PACA allocation.
function deposit(uint256 _pid, uint256 _amount) public {
        require(operationPaused == false, "establishing ranch, relax");
        require(_pid < poolInfo.length, "learn how array works");
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);
        if (user.amount > 0) {
            uint256 pending = user
                .amount
                .mul(pool.accPacaPerShare)
                .div(1e12)
                .sub(user.rewardDebt);
            if (pending > 0) {
                safePacaTransfer(msg.sender, pending);
            }
        }
        if (_amount > 0) {
            // if they try to deposit pools beside ALP past migration this won't work and will be reverted
            // since pool.lpToken is set to IERC20(0) in migrate()
            pool.lpToken.safeTransferFrom(
                address(msg.sender),
                address(this),
                _amount
            );
            user.amount = user.amount.add(_amount);
            // stake _amount to UNI pool to earn $$
            if (pool.stakingPool != address(0)) {
                IStakingRewards usp = IStakingRewards(pool.stakingPool);
                usp.stake(_amount);
            }
        }
        user.rewardDebt = user.amount.mul(pool.accPacaPerShare).div(1e12);

        // If depositing ALP shares to earn PACA after migration
        if (ranchEstablished == true) {
            totalAllocPoint = totalAllocPoint.add(_amount);
            pool.allocPoint = pool.allocPoint.add(_amount);
        }
        emit Deposit(msg.sender, _pid, _amount);
    }
// Solidity 0.6.12
// Function for Uniswap LP depositers to redeem AlpacaPool LP tokens
function redeem(uint256 _pid) public {
        require(operationPaused == false, "establishing ranch, relax");
        require(ranchEstablished == true, "use withdraw");
        require(_pid != ranchPid, "use withdraw");

        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(user.amount > 0, "lol wut?");
        updatePool(_pid);
        uint256 pending = user.amount.mul(pool.accPacaPerShare).div(1e12).sub(
            user.rewardDebt
        );
        if (pending > 0) {
            safePacaTransfer(msg.sender, pending);
        }
        //based on user amount we send back ALP LP tokens.
        uint256 sharesToTransfer = pool.allocPoint.mul(user.amount).div(
            pool.lpSupply
        );
        pool.allocPoint = pool.allocPoint.sub(sharesToTransfer);
        totalAllocPoint = totalAllocPoint.sub(sharesToTransfer);
        poolInfo[ranchPid].lpToken.safeTransfer(
            address(msg.sender),
                sharesToTransfer
        );
        user.rewardDebt = 0;
        pool.lpSupply = pool.lpSupply.sub(user.amount);
        user.amount = 0;
        emit Redeem(msg.sender, _pid, user.amount);
    }
// Solidity 0.6.12
// Withdraw without caring about rewards. EMERGENCY ONLY.
// Or if you are a rat and want to withdraw before the migration
function emergencyWithdraw(uint256 _pid) public {
        require(!withdrawLock, "withdrawals not allowed, change via governance");
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        pool.lpToken.safeTransfer(address(msg.sender), user.amount);
        emit EmergencyWithdraw(msg.sender, _pid, user.amount);
        user.amount = 0;
        user.rewardDebt = 0;
    }
// Solidity 0.6.12
// Unstake all UNI staking pools so the LP tokens can be withdrawn in an emergency
function emergencyUnstake() public {
        require(msg.sender == devaddr, "dev: wut?");
        uint256 length = poolInfo.length;
        for (uint256 pid = 0; pid < length; ++pid) {
            PoolInfo storage pool = poolInfo[pid];
            // exit (withdraw all) from UNI pool
            if (pool.stakingPool != address(0)) {
                IStakingRewards usp = IStakingRewards(pool.stakingPool);
                usp.exit();
            }
        }
    }
// Solidity 0.8.6
/**
 * Safety function to remove bad names.
 */
function removeName(uint256 tokenId) external onlyOwner {
        require(tokenId < totalSupply(), "The token ID is not valid");
        // We will keep the name in the disallow list to prevent it
        // from been used again.
        sdogNames[tokenId] = "";
    }
// Solidity 0.8.6
/**
 * Converts the given string to lower case.
 */
function toLower(string memory str) private pure returns (string memory) {
        bytes memory bStr = bytes(str);
        bytes memory bLower = new bytes(bStr.length);
        for (uint256 i = 0; i < bStr.length; i++) {
            if ((uint8(bStr[i]) >= 65) && (uint8(bStr[i]) <= 90)) {
                bLower[i] = bytes1(uint8(bStr[i]) + 32);
            } else {
                bLower[i] = bStr[i];
            }
        }
        return string(bLower);
    }
// Solidity 0.8.6
/**
 * Returns the HODLer token IDs which we plan to use for web3 stuff in the future.
 */
function getMemberTokenIDs(address member) external view returns(uint256[] memory) {
        uint tokenCount = balanceOf(member);

        uint256[] memory tokensIDs = new uint256[](tokenCount);
        for (uint i = 0; i < tokenCount; i++) {
            // Store the token indices.
            tokensIDs[i] = tokenOfOwnerByIndex(member, i);
        }

        return tokensIDs;
    }
// Solidity 0.8.6
/**
 * Set SDOG Name function.
 */
function setSDogName(uint256 tokenId, string memory name) external {
        require(FIRST_BLOCK != 0, "The reveal has not happened");
        require(msg.sender == ownerOf(tokenId), "This token does not belong to the requesting address");
        require(isValidName(name) == true, "This is not a valid name");
        require(isNameUsed(name) == false, "The name has already been used");
        // Release the old name.
        if (bytes(sdogNames[tokenId]).length > 0) {
            usedNames[toLower(sdogNames[tokenId])] = false;
        }
        usedNames[toLower(name)] = true;
        sdogNames[tokenId] = name;
        emit Named(tokenId, name);
    }
// Solidity 0.8.6
/**
 * Mints SDOGs
 */
function mintSDOG(uint tokenAmount) external payable {
        require(!saleLock, "The sale is closed");
        require(totalSupply() < MAX_SUPPLY, "The sale has ended");
        require(totalSupply() + tokenAmount <= MAX_SUPPLY, "Transaction exceeds max supply");        
        require(tokenAmount <= MAX_IN_ONE_GO, "Token Amount exceeded the max allowed per transaction (20)");
        require(msg.value >= tokenAmount * MINT_ETH_COST, "Value sent is below total cost");

        for (uint i = 0; i < tokenAmount; i++) {
            // Double check that we are not trying to mint more than the max supply.
            if (totalSupply() < MAX_SUPPLY) {                
                _safeMint(msg.sender, totalSupply());
            }
        }
        // Set the First Block if ready (if it's time).
        setFirstIfReady();
        // Perform accounting.
        updateAccounting();
    }
// Solidity 0.8.6
// Delegates the current call to IMPL
// This function does not return to its internall call site, it will return directly to the external caller.
// From https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.2.0/contracts/proxy/Proxy.sol
function _delegate() private {
        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(), IMPL, 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.8.6
/**
 * Tries to mint NFTs during the Trove Auction Phase (Equalized Dutch Auction)
 * Based on the price of last mint, extra credits should be refunded when the auction is over
 * Any extra funds will be transferred back to the sender's address
 */
function auctionMint(uint256 quantity) external payable callerIsUser {
        require(auctionSaleStartTime != 0 && block.timestamp >= auctionSaleStartTime, "Sale has not started yet");
        require(totalSupply() + quantity <= RESERVED_OR_AUCTION_PLANETS, "Not enough remaining reserved for auction to support desired mint amount");
        require(numberMinted(msg.sender) + quantity <= MAX_MINT_PER_ADDRESS, "Can not mint this many");

        lastAuctionSalePrice = getAuctionPrice();
        uint256 totalCost = lastAuctionSalePrice * quantity;

        if (lastAuctionSalePrice > AUCTION_END_PRICE) {
            _creditOwners.add(msg.sender);

            credits[msg.sender] += totalCost;
            creditCount[msg.sender] += quantity;

            _totalCredits += totalCost;
            _totalCreditCount += quantity;
        }

        NFTContract.Mint(msg.sender, quantity);
        refundIfOver(totalCost);
    }
// Solidity 0.8.6
/**
 * Tries to mint NFTs during the whitelist phase
 * Any extra funds will be transferred back to the sender's address
 */
function whitelistMint(uint256 quantity) external payable callerIsUser {
        require(whitelistPrice != 0, "Whitelist sale has not begun yet");
        require(whitelist[msg.sender] > 0, "Not eligible for whitelist mint");
        require(whitelist[msg.sender] >= quantity, "Can not mint this many");
        require(totalSupply() + quantity <= TOTAL_PLANETS, "Reached max supply");

        whitelist[msg.sender] -= quantity;
        NFTContract.Mint(msg.sender, quantity);
        refundIfOver(whitelistPrice * quantity);
    }
// Solidity 0.8.6
/**
 * Calculates the auction price 
 */
function getAuctionPrice() public view returns (uint256) {
        if (block.timestamp < auctionSaleStartTime) {
            return AUCTION_START_PRICE;
        }
        
        if (block.timestamp - auctionSaleStartTime >= AUCTION_PRICE_CURVE_LENGTH) {
            return AUCTION_END_PRICE;
        } else {
            uint256 steps = (block.timestamp - auctionSaleStartTime) / AUCTION_DROP_INTERVAL;
            return AUCTION_START_PRICE - (steps * AUCTION_DROP_PER_STEP);
        }
    }
// Solidity 0.8.6
/**
 * @notice Refunds the remaining credits after the auction phase
 */
function refundRemainingCredits() external nonReentrant {
        require(isAuctionPriceFinalized(), "Auction price is not finalized yet!");
        require(_creditOwners.contains(msg.sender), "Not a credit owner!");
        
        uint256 remainingCredits = credits[msg.sender];
        uint256 remainingCreditCount = creditCount[msg.sender];
        uint256 toSendCredits = remainingCredits - lastAuctionSalePrice * remainingCreditCount;

        require(toSendCredits > 0, "No credits to refund!");

        delete credits[msg.sender];
        delete creditCount[msg.sender];

        _creditOwners.remove(msg.sender);

        _totalCredits -= remainingCredits;
        _totalCreditCount -= remainingCreditCount;

        emit CreditRefunded(msg.sender, toSendCredits);

        require(payable(msg.sender).send(toSendCredits));
    }
// Solidity 0.8.6
/**
 * Refunds the remaining credits for not yet refunded addresses
 */
function refundAllRemainingCreditsByCount(uint256 count) external onlyOwner {
        require(isAuctionPriceFinalized(), "Auction price is not finalized yet!");
        
        address toSendWallet;
        uint256 toSendCredits;
        uint256 remainingCredits;
        uint256 remainingCreditCount;
        
        uint256 j = 0;
        while (_creditOwners.length() > 0 && j < count) {
            toSendWallet = _creditOwners.at(0);
            
            remainingCredits = credits[toSendWallet];
            remainingCreditCount = creditCount[toSendWallet];
            toSendCredits = remainingCredits - lastAuctionSalePrice * remainingCreditCount;
            
            delete credits[toSendWallet];
            delete creditCount[toSendWallet];
            _creditOwners.remove(toSendWallet);

            if (toSendCredits > 0) {
                require(payable(toSendWallet).send(toSendCredits));
                emit CreditRefunded(toSendWallet, toSendCredits);

                _totalCredits -= toSendCredits;
                _totalCreditCount -= remainingCreditCount;
            }
            j++;
        }
    }
// Solidity 0.8.4
/// Pre-Reserve
/// @notice Pre-reserve tokens during Pre-Reserve phase if whitelisted. Max 2 per address. Must pay mint fee
/// @param merkleProof Merkle proof for your address in the whitelist
/// @param _count Number of tokens to reserve
function preReserve(bytes32[] memory merkleProof, uint8 _count) external payable{
        require(!paused,"paused");
        require(phase() == Phase.PreReserve,"phase");
        require(msg.value >= PRICE_MINT * _count,"PRICE_MINT");
        require(whitelistReserveCount[msg.sender] + _count <= WHITELIST_RESERVE_LIMIT,"whitelistReserveCount");
        require(presaleCount + _count < PRESALE_LIMIT,"PRESALE_LIMIT");
        require(GBAWhitelist(whitelist).isWhitelisted(merkleProof,msg.sender),"whitelist");

        whitelistReserveCount[msg.sender] += _count;
        presaleCount += _count;
        _reserve(_count,msg.sender,true);
    }