lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.12
/**
 * @dev Internal make order
 * @param orderID Order ID.
 * @param specificTaker Address of a taker, if applies.
 * @param isComplete If this order can be filled partially, or can only been taken as a whole.
 * @param sellToken Address of the token to be sold in this order.
 * @param sellAmount Total amount of token that is planned to be sold in this order.
 * @param buyToken Address of the token to be purchased in this order.
 * @param buyAmount Total amount of token planned to be bought by the maker.
 */
function _makeOrder(
        bytes32 orderID,
        address specificTaker,
        address seller,
        bool isComplete,
        ISygnumToken sellToken,
        uint256 sellAmount,
        ISygnumToken buyToken,
        uint256 buyAmount
    ) private {
        require(!orders.exists(orderID), "Exchange: order id already exists");
        require(specificTaker != msg.sender, "Exchange: Cannot make an order for oneself");
        require(sellAmount > 0, "Exchange: sell amount cannot be empty");
        require(buyAmount > 0, "Exchange: buy amount cannot be empty");

        require(sellToken.balanceOf(seller) >= sellAmount, "Exchange: seller does not have enough balance");
        require(
            sellToken.allowance(seller, address(this)) >= sellAmount,
            "Exchange: sell amount is greater than allowance"
        );
        require(
            Whitelist(Whitelistable(address(buyToken)).getWhitelistContract()).isWhitelisted(seller),
            "Exchange: seller is not on buy token whitelist"
        );

        if (specificTaker != address(0)) {
            require(
                Whitelist(Whitelistable(address(sellToken)).getWhitelistContract()).isWhitelisted(specificTaker),
                "Exchange: specific taker is not on sell token whitelist"
            );
        }

        sellToken.block(seller, sellAmount);

        order[orderID] = Order({
            maker: seller,
            specificTaker: specificTaker,
            isComplete: isComplete,
            sellToken: sellToken,
            sellAmount: sellAmount,
            buyToken: buyToken,
            buyAmount: buyAmount
        });
        orders.insert(orderID);
        emit MadeOrder(orderID, sellToken, buyToken, seller, specificTaker, isComplete, sellAmount, buyAmount);
        emit MadeOrderParticipants(orderID, seller, specificTaker);
    }
// Solidity 0.4.24
/**
 * @dev Function to grant the amount of tokens that will be vested later.
 * @param _to The address which will own the tokens.
 * @param _amount The amount of tokens that will be vested later.
 * @param _start Token timestamp start.
 * @param _cliff Token timestamp release start.
 * @param _vesting Token timestamp release end.
 */
function grantToken(
        address _to,
        uint256 _amount,
        uint256 _start,
        uint256 _cliff,
        uint256 _vesting
    )
        public
        returns (bool success)
    {
        require(_to != address(0));
        require(_amount <= balances[msg.sender], "Not enough balance to grant token.");
        require(_amount > 0, "Nothing to transfer.");
        require((timeLocks[_to].amount.sub(timeLocks[_to].vestedAmount) == 0), "The previous vesting should be completed.");
        require(_cliff >= _start, "_cliff must be >= _start");
        require(_vesting > _start, "_vesting must be bigger than _start");
        require(_vesting > _cliff, "_vesting must be bigger than _cliff");

        balances[msg.sender] = balances[msg.sender].sub(_amount);
        timeLocks[_to] = TimeLock(_amount, 0, 0, _start, _cliff, _vesting, msg.sender);

        emit NewTokenGrant(msg.sender, _to, _amount, _start, _cliff, _vesting);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Function to calculate the amount of tokens that can be vested at this moment.
 * @param _to The address which will own the tokens.
 * @return amount - A uint256 specifying the amount of tokens available to be vested at this moment.
 * @return vestedMonths - A uint256 specifying the number of the vested months since the last vesting.
 * @return curTime - A uint256 specifying the current timestamp.
 */
function calcVestableToken(address _to)
        internal view
        returns (uint256 amount, uint256 vestedMonths, uint256 curTime)
    {
        uint256 vestTotalMonths;
        uint256 vestedAmount;
        uint256 vestPart;
        amount = 0;
        vestedMonths = 0;
        curTime = now;
        
        require(timeLocks[_to].amount > 0, "Nothing was granted to this address.");
        
        if (curTime <= timeLocks[_to].cliff) {
            return (0, 0, curTime);
        }

        vestedMonths = curTime.sub(timeLocks[_to].start) / MONTH;
        vestedMonths = vestedMonths.sub(timeLocks[_to].vestedMonths);

        if (curTime >= timeLocks[_to].vesting) {
            return (timeLocks[_to].amount.sub(timeLocks[_to].vestedAmount), vestedMonths, curTime);
        }

        if (vestedMonths > 0) {
            vestTotalMonths = timeLocks[_to].vesting.sub(timeLocks[_to].start) / MONTH;
            vestPart = timeLocks[_to].amount.div(vestTotalMonths);
            amount = vestedMonths.mul(vestPart);
            vestedAmount = timeLocks[_to].vestedAmount.add(amount);
            if (vestedAmount > timeLocks[_to].amount) {
                amount = timeLocks[_to].amount.sub(timeLocks[_to].vestedAmount);
            }
        }

        return (amount, vestedMonths, curTime);
    }
// Solidity 0.4.24
/**
 * @dev Function to redeem tokens that can be vested at this moment.
 * @param _to The address which will own the tokens.
 */
function redeemVestableToken(address _to)
        public
        returns (bool success)
    {
        require(_to != address(0));
        require(timeLocks[_to].amount > 0, "Nothing was granted to this address!");
        require(timeLocks[_to].vestedAmount < timeLocks[_to].amount, "All tokens were vested!");

        (uint256 amount, uint256 vestedMonths, uint256 curTime) = calcVestableToken(_to);
        require(amount > 0, "Nothing to redeem now.");

        TimeLock storage t = timeLocks[_to];
        balances[_to] = balances[_to].add(amount);
        t.vestedAmount = t.vestedAmount.add(amount);
        t.vestedMonths = t.vestedMonths + uint16(vestedMonths);
        t.cliff = curTime;

        emit VestedTokenRedeemed(_to, amount, vestedMonths);
        return true;
    }
// Solidity 0.4.24
/**
 * @dev Function to return granted token to the initial sender.
 * @param _amount - A uint256 specifying the amount of tokens to be returned.
 */
function returnGrantedToken(uint256 _amount)
        public
        returns (bool success)
    {
        address to = timeLocks[msg.sender].from;
        require(to != address(0));
        require(_amount > 0, "Nothing to transfer.");
        require(timeLocks[msg.sender].amount > 0, "Nothing to return.");
        require(_amount <= timeLocks[msg.sender].amount.sub(timeLocks[msg.sender].vestedAmount), "Not enough granted token to return.");

        timeLocks[msg.sender].amount = timeLocks[msg.sender].amount.sub(_amount);
        balances[to] = balances[to].add(_amount);

        emit GrantedTokenReturned(msg.sender, to, _amount);
        return true;
    }
// Solidity 0.8.9
/**
 * @notice Mints monster tokens during presale, optionally with discounts
 * @param _numberOfTokens Number of tokens to mint
 * @param _satsForDiscount Array of Satoshible IDs for discounted mints
 * @param _whitelistedTokens Account's total number of whitelisted tokens
 * @param _proof Merkle proof to be verified
 */
function mintTokensPresale(
        uint256 _numberOfTokens,
        uint256[] calldata _satsForDiscount,
        uint256 _whitelistedTokens,
        bytes32[] calldata _proof
    )
        external
        payable
    {
        require(
            publicSaleOpenedEarly == false,
            "Presale has ended"
        );

        require(
            belowMaximum(monsterIds.current(), _numberOfTokens,
                MAX_PRESALE_TOKEN_ID
            ) == true,
            "Would exceed presale size"
        );

        require(
            belowMaximum(whitelistMintsUsed[_msgSender()], _numberOfTokens,
                _whitelistedTokens
            ) == true,
            "Would exceed whitelisted count"
        );

        require(
            verifyWhitelisted(_msgSender(), _whitelistedTokens,
                _proof
            ) == true,
            "Invalid whitelist proof"
        );

        whitelistMintsUsed[_msgSender()] += _numberOfTokens;

        _doMintTokens(
            _numberOfTokens,
            _satsForDiscount
        );
    }
// Solidity 0.8.9
/**
 * @notice Mints monsters during public sale, optionally with discounts
 * @param _numberOfTokens Number of monster tokens to mint
 * @param _satsForDiscount Array of Satoshible IDs for discounted mints
 */
function mintTokensPublicSale(
        uint256 _numberOfTokens,
        uint256[] calldata _satsForDiscount
    )
        external
        payable
    {
        require(
            publicSaleOpened() == true,
            "Public sale has not started"
        );

        require(
            belowMaximum(monsterIds.current(), _numberOfTokens,
                MAX_SUPPLY
            ) == true,
            "Not enough tokens left"
        );

        _doMintTokens(
            _numberOfTokens,
            _satsForDiscount
        );
    }
// Solidity 0.8.9
/**
 * @notice Modifies the prices in case of major ETH price changes
 * @param _tokenPrice The new default token price
 * @param _discountPrice The new discount token price
 */
function updateTokenPrices(
        uint256 _tokenPrice,
        uint256 _discountPrice
    )
        external
        onlyOwner
    {
        require(
            _tokenPrice >= _discountPrice,
            "discountPrice cannot be larger"
        );

        require(
            saleIsActive == false,
            "Sale is active"
        );

        tokenPrice = _tokenPrice;
        discountPrice = _discountPrice;
    }
// Solidity 0.8.9
/**
 * @notice Checks which Satoshibles can still be used for a discounted mint
 * @dev Uses bitwise operators to find the bit representing each Satoshible
 * @param _satIds Array of original Satoshible token IDs
 * @return Token ID for each of the available _satIds, zero otherwise
 */
function satsAvailableForDiscountMint(
        uint256[] calldata _satIds
    )
        external
        view
        returns (uint256[] memory)
    {
        uint256[] memory satsAvailable = new uint256[](_satIds.length);

        unchecked {
            for (uint256 i = 0; i < _satIds.length; i++) {
                if (satIsAvailableForDiscountMint(_satIds[i])) {
                    satsAvailable[i] = _satIds[i];
                }
            }
        }

        return satsAvailable;
    }
// Solidity 0.8.9
/**
 * @notice Checks if a Satoshible can still be used for a discounted mint
 * @dev Uses bitwise operators to find the bit representing the Satoshible
 * @param _satId Original Satoshible token ID
 * @return isAvailable True if _satId can be used for a discounted mint
 */
function satIsAvailableForDiscountMint(
        uint256 _satId
    )
        public
        view
        returns (bool isAvailable)
    {
        unchecked {
            uint256 page = _satId / 256;
            uint256 shift = _satId % 256;
            isAvailable = satDiscountBitfields[page] >> shift & 1 == 1;
        }
    }
// Solidity 0.8.9
/**
 * @notice Verifies a merkle proof for a monster ID and its prime parts
 * @param _monsterId Monster token ID
 * @param _monsterPrimeParts Bitfield of the monster's prime parts
 * @param _proof Merkle proof be verified
 * @return isVerified True if the merkle proof is verified
 */
function verifyMonsterPrimeParts(
        uint256 _monsterId,
        uint256 _monsterPrimeParts,
        bytes32[] calldata _proof
    )
        public
        view
        returns (bool isVerified)
    {
        bytes32 node = keccak256(
            abi.encodePacked(
                _monsterId,
                _monsterPrimeParts
            )
        );

        isVerified = MerkleProof.verify(
            _proof,
            primePartsMerkleRoot,
            node
        );
    }
// Solidity 0.8.9
/**
 * @notice Verifies a merkle proof for an account's whitelisted tokens
 * @param _account Account to verify
 * @param _whitelistedTokens Number of whitelisted tokens for _account
 * @param _proof Merkle proof to be verified
 * @return isVerified True if the merkle proof is verified
 */
function verifyWhitelisted(
        address _account,
        uint256 _whitelistedTokens,
        bytes32[] calldata _proof
    )
        public
        pure
        returns (bool isVerified)
    {
        bytes32 node = keccak256(
            abi.encodePacked(
                _account,
                _whitelistedTokens
            )
        );

        isVerified = MerkleProof.verify(
            _proof,
            WHITELIST_MERKLE_ROOT,
            node
        );
    }
// Solidity 0.8.9
/**
 * @dev Base monster minting function, calculates price with discounts
 * @param _numberOfTokens Number of monster tokens to mint
 * @param _satsForDiscount Array of Satoshible IDs for discounted mints
 */
function _doMintTokens(
        uint256 _numberOfTokens,
        uint256[] calldata _satsForDiscount
    )
        private
    {
        require(
            saleIsActive == true,
            "Sale must be active"
        );

        require(
            _numberOfTokens >= 1,
            "Need at least 1 token"
        );

        require(
            _numberOfTokens <= 50,
            "Max 50 at a time"
        );

        require(
            _satsForDiscount.length <= _numberOfTokens,
            "Too many sats for discount"
        );

        unchecked {
            uint256 discountIndex;

            for (; discountIndex < _satsForDiscount.length; discountIndex++) {
                _useSatForDiscountMint(_satsForDiscount[discountIndex]);
            }

            uint256 totalPrice = tokenPrice * (_numberOfTokens - discountIndex)
                + discountPrice * discountIndex;

            require(
                totalPrice == msg.value,
                "Ether amount not correct"
            );
        }

        _mintTokens(
            _numberOfTokens
        );
    }
// Solidity 0.8.9
/**
 * @dev Marks a Satoshible ID as having been used for a discounted mint
 * @param _satId Satoshible ID that was used for a discounted mint
 */
function _useSatForDiscountMint(
        uint256 _satId
    )
        private
        onlySatHolder(_satId)
    {
        require(
            satIsAvailableForDiscountMint(_satId) == true,
            "Sat for discount already used"
        );

        unchecked {
            uint256 page = _satId / 256;
            uint256 shift = _satId % 256;
            satDiscountBitfields[page] &= ~(1 << shift);
        }
    }
// Solidity 0.8.9
/**
 * @dev Initializes prime token ID offsets
 */
function _initializePrimeIdOffsets()
        private
    {
        unchecked {
            primeIdOffset[FRANKENSTEIN] = ALPHA;
            primeIdOffset[WEREWOLF] = ALPHA + 166;
            primeIdOffset[VAMPIRE] = ALPHA + 332;
            primeIdOffset[ZOMBIE] = ALPHA + 498;
            primeIdOffset[INVALID] = ALPHA + 665;
        }
    }
// Solidity 0.5.3
// bCalled used to prevent reentrancy attack
function approveAndCall(
        address _spender,
        uint256 _value,
        bytes memory _data
    )
        public
        payable
        onlyNotBlacklisted
        whenNotPaused
        returns (bool)
    {
        require(bCalled == false);
        require(_spender != address(this));
        require(approve(_spender, _value));
        // solium-disable-next-line security/no-call-value
        bCalled = true;
        _spender.call.value(msg.value)(_data);
        bCalled = false;
        return true;
    }
// Solidity 0.4.22
/**
 * Constructor for Zigilua
 */
function Zigilua() public
    {
        balances[msg.sender] = 79700000000;
        totalSupply          = 79700000000;
        name                 = "ZigiLua";
        decimals             = 0;
        symbol               = "ZGL";
        zigWallet            = msg.sender;

        _crrStage            = 0;
        _minUSDrequired      = 200;
        _usd                 = 50000;
    }
// Solidity 0.4.22
/**
 * Allows to buy zigs (ZGL) from DApps
 *
 * @param wai {uint256} Desired amount, in wei
 *
 * @return {uint256[]} [wai, _usd, amount, owner balance, user balance] Useful for debugging purposes
 */
function buy(uint256 wai) public payable returns (uint256[5])
    {
        uint256 amount = ((wai * _usd * 10 * ZIGS_BY_STAGE[_crrStage]) / (1e18));

        require(balances[zigWallet] >= amount);
        require(amount >= (2000 * (1 / ZIGS_BY_STAGE[_crrStage])));

        balances[zigWallet]  = (balances[zigWallet] - amount);
        balances[msg.sender] = (balances[msg.sender] + amount);

        emit Transfer(zigWallet, msg.sender, amount);

        zigWallet.transfer(msg.value);

        return ([wai, _usd, amount, balances[zigWallet], balances[msg.sender]]);

    }
// Solidity 0.6.12
//This collateral function is needed to let everyone withraw the eventual staked voting tokens still held in the proposal and give back the to the BuidlersFund wallet
function withdraw(bool terminateFirst) public {
		//Terminate or withraw the Proposal
		if(terminateFirst) {
			IMVDFunctionalityProposal(PROPOSAL).terminate();
		} else {
			IMVDFunctionalityProposal(PROPOSAL).withdraw();
		}
		//Give back BUIDL Voting Tokens to the BuildersFund Wallet
		IERC20 token = IERC20(TOKEN);
		token.transfer(WALLET, token.balanceOf(address(this)));
	}
// Solidity 0.5.2
/**
 * Create a new subscription. Must be called by the subscriber's account.
 * First payment of `daiCents` is paid on creation.
 * Actual payment is made in Wrapped Ether (wETH) using currenct DAI-ETH conversion rate.
 * @param receiver address
 * @param daiCents subscription amount in hundredths of DAI
 * @param interval seconds between payments
 */
function subscribe(address receiver, uint daiCents, uint32 interval) external {
        uint weiAmount = daiCentsToEthWei(daiCents, ethPriceInDaiWad());
        uint64 existingIndex = subscriberReceiver[msg.sender][receiver];
        require(subscriptions[existingIndex].daiCents == 0, "Subscription exists");
        require(daiCents >= MIN_SUBSCRIPTION_DAI_CENTS, "Subsciption amount too low");
        require(interval >= 86400, "Interval must be at least 1 day");
        require(interval <= 31557600, "Interval must be at most 1 year");
        require(subscriberSubs[msg.sender].length < MAX_SUBSCRIPTION_PER_SUBSCRIBER,"Subscription count limit reached");

        // first payment
        require(wethContract.transferFrom(msg.sender, receiver, weiAmount), "wETH transferFrom() failed");

        // add to subscription mappings
        subscriptions[nextIndex] = Subscription(
            true,
            uint48(now.add(interval)),
            interval,
            msg.sender,
            receiver,
            daiCents
        );
        subscriberReceiver[msg.sender][receiver] = nextIndex;
        receiverSubs[receiver].push(nextIndex);
        subscriberSubs[msg.sender].push(nextIndex);

        emit NewSubscription(msg.sender, receiver, daiCents, interval);
        emit SubscriptionPaid(msg.sender, receiver, weiAmount, daiCents, uint48(now));

        nextIndex++;
    }
// Solidity 0.5.2
/**
 * Deactivate a subscription. Must be called by the subscriber's account.
 * Payments cannot be collected from deactivated subscriptons.
 * @param receiver address used to identify the unique subscriber-receiver pair.
 * @return success
 */
function deactivateSubscription(address receiver) external returns (bool) {
        uint64 index = subscriberReceiver[msg.sender][receiver];
        require(index != 0, "Subscription does not exist");

        Subscription storage sub = subscriptions[index];
        require(sub.isActive, "Subscription is already disabled");
        require(sub.daiCents > 0, "Subscription does not exist");

        sub.isActive = false;
        emit SubscriptionDeactivated(msg.sender, receiver);

        return true;
    }
// Solidity 0.5.2
/**
 * Reactivate a subscription. Must be called by the subscriber's account.
 * If less than one interval has passed since the last payment, no payment is collected now.
 * Otherwise it is treated as a new subscription starting now, and the first payment is collected.
 * No back-payments are collected.
 * @param receiver addres used to identify the unique subscriber-receiver pair.
 * @return success
 */
function reactivateSubscription(address receiver) external returns (bool) {
        uint64 index = subscriberReceiver[msg.sender][receiver];
        require(index != 0, "Subscription does not exist");

        Subscription storage sub = subscriptions[index];
        require(!sub.isActive, "Subscription is already active");

        sub.isActive = true;
        emit SubscriptionReactivated(msg.sender, receiver);

        if (calculateUnpaidIntervalsUntil(sub, now) > 0) {
            // only make a payment if at least one interval has lapsed since the last payment
            uint weiAmount = daiCentsToEthWei(sub.daiCents, ethPriceInDaiWad());
            require(wethContract.transferFrom(msg.sender, receiver, weiAmount), "Insufficient funds to reactivate subscription");
            emit SubscriptionPaid(msg.sender, receiver, weiAmount, sub.daiCents, uint48(now));
        }

        sub.nextPaymentTime = uint48(now.add(sub.interval));

        return true;
    }
// Solidity 0.5.2
/**
 * A read-only version of executeDebits()
 * Calculates uncollected *funded* payments for a receiver.
 * @param receiver address
 * @return total unclaimed value in wei
 */
function getTotalUnclaimedPayments(address receiver) external view returns (uint) {
        uint totalPayment = 0;
        uint ethPriceWad = ethPriceInDaiWad();

        for (uint i = 0; i < receiverSubs[receiver].length; i++) {
            Subscription storage sub = subscriptions[receiverSubs[receiver][i]];

            if (sub.isActive && sub.daiCents != 0) {
                uint wholeUnpaidIntervals = calculateUnpaidIntervalsUntil(sub, now);
                if (wholeUnpaidIntervals > 0) {
                    uint weiAmount = daiCentsToEthWei(sub.daiCents, ethPriceWad);
                    uint authorizedBalance = allowedBalance(sub.subscriber);

                    do {
                        if (authorizedBalance >= weiAmount) {
                            totalPayment = totalPayment.add(weiAmount);
                            authorizedBalance = authorizedBalance.sub(weiAmount);
                        }
                        wholeUnpaidIntervals = wholeUnpaidIntervals.sub(1);
                    } while (wholeUnpaidIntervals > 0);
                }
            }
        }

        return totalPayment;
    }
// Solidity 0.5.2
/**
 * Calculates a subscriber's total outstanding payments in daiCents
 * @param subscriber address
 * @param time in seconds. If `time` < `now`, then we simply use `now`
 * @return total amount owed at `time` in daiCents
 */
function outstandingBalanceUntil(address subscriber, uint time) external view returns (uint) {
        uint until = time <= now ? now : time;

        uint64[] memory subs = subscriberSubs[subscriber];

        uint totalDaiCents = 0;
        for (uint64 i = 0; i < subs.length; i++) {
            Subscription memory sub = subscriptions[subs[i]];
            if (sub.isActive) {
                totalDaiCents = totalDaiCents.add(sub.daiCents.mul(calculateUnpaidIntervalsUntil(sub, until)));
            }
        }

        return totalDaiCents;
    }