lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.12
/// @notice A seller/maker calls this function to cancel an existing order
///  that they have posted to this contract.
/// @dev Unlike the other Order functions, this function can be called even
///  if the contract is paused, so that users can clear out their orderbook
///  if they would like.
/// @param _wizardId  The tokenId for the seller's wizard. This is the
///  wizard that will relinquish its power if an order is fulfilled.
/// @param _basicTournamentAddress  The address of the tournament that this
///  order pertains to. Note that each Wizard has an independent power
///  value for each tournament, and call sell each one separately, so
///  orders can exist simultaneously for the same wizard for different
///  tournaments.
function cancelSellOrder(uint256 _wizardId, address _basicTournamentAddress) external nonReentrant {
        require(WizardGuild(wizardGuildAddress).ownerOf(_wizardId) == msg.sender, 'only the owner of the wizard can cancel a sell order');

        // Wait until after emitting event to delete order so that event data
        // can be pulled from soon-to-be-deleted order
        Order memory order = orderForWizardIdAndTournamentAddress[_basicTournamentAddress][_wizardId];
        emit CancelSellOrder(
            uint256(order.wizardId),
            uint256(order.pricePerPower),
            msg.sender,
            _basicTournamentAddress,
            uint256(order.savedSuccessfulTradeFeeInBasisPoints)
        );

        // Delete order
        delete orderForWizardIdAndTournamentAddress[_basicTournamentAddress][_wizardId];
    }
// Solidity 0.5.12
/// @notice A convenience function providing the caller with the current
///  amount needed (in wei) to fulfill this order.
/// @param _wizardId The id of the wizard NFT whose order we would like to
///  see the details of.
/// @param _basicTournamentAddress The address of the tournament that this
///  order pertains to. Note that each Wizard has an independent power
///  value for each tournament, and call sell each one separately.
/// @return The amount needed (in wei) to fulfill this order
function getCurrentPriceForOrder(uint256 _wizardId, address _basicTournamentAddress) external view returns (uint256){
        Order memory order = orderForWizardIdAndTournamentAddress[_basicTournamentAddress][_wizardId];
        uint256 power;
        ( , power, , , , , , , ) = BasicTournament(_basicTournamentAddress).getWizard(_wizardId);
        uint256 price = (power.div(10**12)).mul(uint256(order.pricePerPower));
        return price;
    }
// Solidity 0.5.12
/// @notice A convenience function checking whether the order is currently
///  valid. Note that an order can become invalid for a period of time, but
///  then become valid again (for example, during the time that a wizard
///  is dueling).
/// @param _wizardId The id of the wizard NFT whose order we would like to
///  see the details of.
/// @param _basicTournamentAddress The address of the tournament that this
///  order pertains to. Note that each Wizard has an independent power
///  value for each tournament, and call sell each one separately.
/// @return Whether the order is currently valid or not.
function getIsOrderCurrentlyValid(uint256 _wizardId, address _basicTournamentAddress) external view returns (bool){
        Order memory order = orderForWizardIdAndTournamentAddress[_basicTournamentAddress][_wizardId];
        if(order.makerAddress == address(0)){
            // Order is not valid if order does not exist
            return false;
        } else {

            if(WizardGuild(wizardGuildAddress).ownerOf(_wizardId) != order.makerAddress){
                // Order is not valid if order's creator no longer owns wizard
                return false;
            }
            bool molded;
            bool ready;
            ( , , , , , , , molded, ready) = BasicTournament(_basicTournamentAddress).getWizard(_wizardId);
            if(molded == true || ready == false){
                // Order is not valid if makerWizard is molded or is dueling
                return false;
            } else {
                return true;
            }
        }
    }
// Solidity 0.4.18
/// @notice Manual payout for site users
/// @param _user Ethereum address of the user
/// @param _amount The mount of CMA tokens in wei to send
function singlePayout(address _user, uint256 _amount)
        public
        onlyAdmin
        returns (bool paid)
    {
        require(!tokenTransfersFrozen);
        require(_amount > 0);
        require(transferCheck(owner, _user, _amount));
        if (!userRegistered[_user]) {
            registerUser(_user);
        }
        balances[_user] = balances[_user].add(_amount);
        balances[owner] = balances[owner].add(_amount);
        Transfer(owner, _user, _amount);
        return true;
    }
// Solidity 0.4.18
/// @dev low-level minting function not accessible externally
function tokenMint(address _invoker, uint256 _amount) 
        private
        returns (bool raised)
    {
        require(balances[owner].add(_amount) > balances[owner]);
        require(balances[owner].add(_amount) > 0);
        require(totalSupply.add(_amount) > 0);
        require(totalSupply.add(_amount) > totalSupply);
        totalSupply = totalSupply.add(_amount);
        balances[owner] = balances[owner].add(_amount);
        MintTokens(_invoker, _amount, true);
        return true;
    }
// Solidity 0.4.18
/// @notice Used to burn tokens
/// @param _amount The amount of CMA tokens in wei to burn
function tokenBurn(uint256 _amount)
        public
        onlyAdmin
        returns (bool burned)
    {
        require(_amount > 0);
        require(_amount < totalSupply);
        require(balances[owner] > _amount);
        require(balances[owner].sub(_amount) >= 0);
        require(totalSupply.sub(_amount) >= 0);
        balances[owner] = balances[owner].sub(_amount);
        totalSupply = totalSupply.sub(_amount);
        TokenBurn(msg.sender, _amount, true);
        return true;
    }
// Solidity 0.4.18
/// @notice Used to transfer funds on behalf of one person
/// @param _owner Person you are allowed to spend funds on behalf of
/// @param _receiver Person to receive the funds
/// @param _amount Amoun of CMA tokens in wei to send
function transferFrom(address _owner, address _receiver, uint256 _amount)
        public
        returns (bool _transferredFrom)
    {
        require(!tokenTransfersFrozen);
        require(allowance[_owner][msg.sender].sub(_amount) >= 0);
        require(transferCheck(_owner, _receiver, _amount));
        balances[_owner] = balances[_owner].sub(_amount);
        balances[_receiver] = balances[_receiver].add(_amount);
        allowance[_owner][msg.sender] = allowance[_owner][msg.sender].sub(_amount);
        Transfer(_owner, _receiver, _amount);
        return true;
    }
// Solidity 0.7.6
/**
 * @inheritdoc iOVM_StateCommitmentChain
 */
function appendStateBatch(
        bytes32[] memory _batch,
        uint256 _shouldStartAtElement
    )
        override
        public
    {
        // Fail fast in to make sure our batch roots aren't accidentally made fraudulent by the
        // publication of batches by some other user.
        require(
            _shouldStartAtElement == getTotalElements(),
            "Actual batch start index does not match expected start index."
        );

        // Proposers must have previously staked at the BondManager
        require(
            iOVM_BondManager(resolve("OVM_BondManager")).isCollateralized(msg.sender),
            "Proposer does not have enough collateral posted"
        );

        require(
            _batch.length > 0,
            "Cannot submit an empty state batch."
        );

        require(
            getTotalElements() + _batch.length <=
                iOVM_CanonicalTransactionChain(resolve("OVM_CanonicalTransactionChain"))
                .getTotalElements(),
            "Number of state roots cannot exceed the number of canonical transactions."
        );

        // Pass the block's timestamp and the publisher of the data
        // to be used in the fraud proofs
        _appendBatch(
            _batch,
            abi.encode(block.timestamp, msg.sender)
        );
    }
// Solidity 0.7.6
/**
 * Parses the batch context from the extra data.
 * @return Total number of elements submitted.
 * @return Timestamp of the last batch submitted by the sequencer.
 */
function _getBatchExtraData()
        internal
        view
        returns (
            uint40,
            uint40
        )
    {
        bytes27 extraData = batches().getGlobalMetadata();

        // solhint-disable max-line-length
        uint40 totalElements;
        uint40 lastSequencerTimestamp;
        assembly {
            extraData              := shr(40, extraData)
            totalElements          :=         and(extraData, 0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF)
            lastSequencerTimestamp := shr(40, and(extraData, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000))
        }
        // solhint-enable max-line-length

        return (
            totalElements,
            lastSequencerTimestamp
        );
    }
// Solidity 0.7.6
/**
 * Removes a batch and all subsequent batches from the chain.
 * @param _batchHeader Header of the batch to remove.
 */
function _deleteBatch(
        Lib_OVMCodec.ChainBatchHeader memory _batchHeader
    )
        internal
    {
        require(
            _batchHeader.batchIndex < batches().length(),
            "Invalid batch index."
        );

        require(
            _isValidBatchHeader(_batchHeader),
            "Invalid batch header."
        );

        batches().deleteElementsAfterInclusive(
            _batchHeader.batchIndex,
            _makeBatchExtraData(
                uint40(_batchHeader.prevTotalElements),
                0
            )
        );

        emit StateBatchDeleted(
            _batchHeader.batchIndex,
            _batchHeader.batchRoot
        );
    }
// Solidity 0.7.1
/**
 * Transfer functions
 */
function transfer(address _to, uint256 _value) public {
        require(_to != address(this));
        require(_to != address(0), "Cannot use zero address");
        require(_value > 0, "Cannot use zero value");

        require (balanceOf[msg.sender] >= _value, "Balance not enough");         // Check if the sender has enough
        require (balanceOf[_to] + _value >= balanceOf[_to], "Overflow" );        // Check for overflows
        
        uint previousBalances = balanceOf[msg.sender] + balanceOf[_to];          
        
        balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
        balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value);               // Add the same to the recipient
        
        emit Transfer(msg.sender, _to, _value);                                  // Notify anyone listening that this transfer took place
        
        assert(balanceOf[msg.sender] + balanceOf[_to] == previousBalances);
    }
// Solidity 0.5.16
/**
 *  Requirements:
 *  `rewardAmount` rewards to be added to the staking contract
 *  @dev to add rewards to the staking contract
 *  once the allowance is given to this contract for 'rewardAmount' by the user
 */
function addReward(uint256 rewardAmount, address tokenAddress)
        external
        _validTokenAddress(tokenAddress)
        _hasAllowance(msg.sender, rewardAmount, tokenAddress)
        returns (bool)
    {
        require(rewardAmount > 0, "Reward must be positive");
        address from = msg.sender;

        if (!_payMe(from, rewardAmount, tokenAddress)) {
            return false;
        }

        if (tokenAddress == tokenAddressA) {
            totalRewardA = totalRewardA.add(rewardAmount);
            rewardBalanceA = rewardBalanceA.add(rewardAmount);
        } else {
            totalRewardB = totalRewardB.add(rewardAmount);
            rewardBalanceB = rewardBalanceB.add(rewardAmount);
        }

        return true;
    }
// Solidity 0.5.16
/**
 *  Requirements:
 *  `amount` Amount to be staked
 *  `tokenAddress` Token address to stake
 /**
 *  @dev to stake 'amount' value of tokens 
 *  once the user has given allowance to the staking contract
 */
function stake(uint256 amount, address tokenAddress)
        public
        _validTokenAddress(tokenAddress)
        _hasAllowance(msg.sender, amount, tokenAddress)
        returns (bool)
    {
        require(amount > 0, "Can't stake 0 amount");
        require(
            amount <= userCap[tokenAddress],
            "Amount is greater than limit"
        );
        uint256 poolRemaining;
        if (tokenAddress == tokenAddressA) {
            poolRemaining = poolCap[tokenAddress].sub(stakedTotalA);
        } else {
            poolRemaining = poolCap[tokenAddress].sub(stakedTotalB);
        }
        require(poolRemaining > 0, "Pool limit reached");
        if (amount > poolRemaining) {
            amount = poolRemaining;
        }
        address from = msg.sender;
        require(!hasStaked[from][tokenAddress], "Already Staked");
        return (_stake(from, amount, tokenAddress));
    }
// Solidity 0.6.12
/**
 * @notice Mints the given amount of LPToken to the recipient. During the guarded release phase, the total supply
 * and the maximum number of the tokens that a single account can mint are limited.
 * @dev only owner can call this mint function
 * @param recipient address of account to receive the tokens
 * @param amount amount of tokens to mint
 * @param merkleProof the bytes32 array data that is used to prove recipient's address exists in the merkle tree
 * stored in the allowlist contract. If the pool is not guarded, this parameter is ignored.
 */
function mint(
        address recipient,
        uint256 amount,
        bytes32[] calldata merkleProof
    ) external onlyOwner {
        require(amount != 0, "amount == 0");

        // If the pool is in the guarded launch phase, the following checks are done to restrict deposits.
        //   1. Check if the given merkleProof corresponds to the recipient's address in the merkle tree stored in the
        //      allowlist contract. If the account has been already verified, merkleProof is ignored.
        //   2. Limit the total number of this LPToken minted to recipient as defined by the allowlist contract.
        //   3. Limit the total supply of this LPToken as defined by the allowlist contract.
        if (swap.isGuarded()) {
            IAllowlist allowlist = swap.getAllowlist();
            require(
                allowlist.verifyAddress(recipient, merkleProof),
                "Invalid merkle proof"
            );
            uint256 totalMinted = mintedAmounts[recipient].add(amount);
            require(
                totalMinted <= allowlist.getPoolAccountLimit(address(swap)),
                "account deposit limit"
            );
            require(
                totalSupply().add(amount) <=
                    allowlist.getPoolCap(address(swap)),
                "pool total supply limit"
            );
            mintedAmounts[recipient] = totalMinted;
        }
        _mint(recipient, amount);
    }
// Solidity 0.8.4
/**
 * @dev                 mints to multiple addresses arbitrary units of tokens of ONE token id per address
 * @notice              example: mint 3 units of tokenId 1 to alice and 4 units of tokenId 2 to bob
 * @param accounts      list of beneficiary addresses
 * @param tokenIds      list of token ids (aka tiers)
 * @param amounts       list of mint amounts
 */
function mintToMultiple(
        address[] calldata accounts,
        uint256[] calldata tokenIds,
        uint256[] calldata amounts
    ) public onlyOwner isSameLength(accounts, tokenIds, amounts) {
        bytes memory data;

        for (uint256 i = 0; i < accounts.length; i++) {
            require(
                tokenTiers[tokenIds[i]].boxToken == address(0),
                "Can mint only general tokens"
            );
            _mint(accounts[i], tokenIds[i], amounts[i], data);
        }
    }
// Solidity 0.8.4
/**
 * @dev                 burns from multiple addresses arbitrary units of tokens of ONE token id per address
 *                      example: burn 3 units of tokenId 1 from alice and 4 units of tokenId 2 froms bob
 * @param accounts      list of token holder addresses
 * @param tokenIds      list of token ids (aka tiers)
 * @param amounts       list of burn amounts
 */
function burnFromMultiple(
        address[] calldata accounts,
        uint256[] calldata tokenIds,
        uint256[] calldata amounts
    ) public onlyOwner isSameLength(accounts, tokenIds, amounts) {
        for (uint256 i = 0; i < accounts.length; i++) {
            require(
                tokenTiers[tokenIds[i]].boxToken == address(0),
                "Can burn only general tokens"
            );
            _burn(accounts[i], tokenIds[i], amounts[i]);
        }
    }
// Solidity 0.8.4
/**
 * @dev                 transfers tokens from one address to another allowing custom data parameter
 * @notice              this is the standard transfer interface for ERC1155 tokens which contracts expect
 * @param from          address from which token will be transferred
 * @param to            recipient of address
 * @param id            id of token to be transferred
 * @param amount        amount of token to be transferred
 */
function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public override {
        require(
            owner() == _msgSender() ||
                from == _msgSender() ||
                isApprovedForAll(from, _msgSender()),
            "Unauthorized"
        );
        _safeTransferFrom(from, to, id, amount, data);
    }
// Solidity 0.8.4
/**
 * @dev                 creates a new token tier
 * @param tokenId       identifier for the new token tier
 * @param uriId         identifier that is appended to the baseUri together forming the uri where the metadata lives
 * @param transferable  determines if tokens from specific tier should be transferable or not
 */
function createTokenTier(
        uint256 tokenId,
        string memory uriId,
        bool transferable,
        address boxToken
    ) public onlyOwner isValidString(uriId) {
        require(
            _isEmptyString(tokenTiers[tokenId].uriId),
            "Tier already exists for tokenId"
        );

        tokenTiers[tokenId] = TokenTier(uriId, transferable, boxToken);
        emit TierChange(tokenId, uriId, transferable);
    }
// Solidity 0.8.4
/**
 * @dev                 update uri identifiers for multiple token ids (tiers)
 * @param tokenIds      tokenIds for which the uri should be updated (must be in same order as uriIds)
 * @param uriIds        identifiers that are appended to the baseUri together forming the uri where the metadata lives (must be in same order ass tokenIds)
 */
function updateMultipleUriIdentifiers(
        uint256[] calldata tokenIds,
        string[] calldata uriIds
    ) public onlyOwner {
        require(tokenIds.length == uriIds.length, "Input array mismatch");

        for (uint8 i = 0; i < tokenIds.length; i++) {
            _updateUriIdentifier(tokenIds[i], uriIds[i]);
        }
    }
// Solidity 0.6.12
/**
 * @notice Initializes this Swap contract with the given parameters.
 * This will also clone a LPToken contract that represents users'
 * LP positions. The owner of LPToken will be this contract - which means
 * only this contract is allowed to mint/burn tokens.
 *
 * @param _pooledTokens an array of ERC20s this pool will accept
 * @param decimals the decimals to use for each pooled token,
 * eg 8 for WBTC. Cannot be larger than POOL_PRECISION_DECIMALS
 * @param lpTokenName the long-form name of the token to be deployed
 * @param lpTokenSymbol the short symbol for the token to be deployed
 * @param _a the amplification coefficient * n * (n - 1). See the
 * StableSwap paper for details
 * @param _fee default swap fee to be initialized with
 * @param _adminFee default adminFee to be initialized with
 * @param _withdrawFee default withdrawFee to be initialized with
 * @param lpTokenTargetAddress the address of an existing LPToken contract to use as a target
 */
function initialize(
        IERC20[] memory _pooledTokens,
        uint8[] memory decimals,
        string memory lpTokenName,
        string memory lpTokenSymbol,
        uint256 _a,
        uint256 _fee,
        uint256 _adminFee,
        uint256 _withdrawFee,
        address lpTokenTargetAddress
    ) public virtual override initializer {
        SwapV1.initialize(
            _pooledTokens,
            decimals,
            lpTokenName,
            lpTokenSymbol,
            _a,
            _fee,
            _adminFee,
            _withdrawFee,
            lpTokenTargetAddress
        );
        flashLoanFeeBPS = 8; // 8 bps
        protocolFeeShareBPS = 0; // 0 bps
    }
// Solidity 0.6.12
/**
 * @notice Borrow the specified token from this pool for this transaction only. This function will call
 * `IFlashLoanReceiver(receiver).executeOperation` and the `receiver` must return the full amount of the token
 * and the associated fee by the end of the callback transaction. If the conditions are not met, this call
 * is reverted.
 * @param receiver the address of the receiver of the token. This address must implement the IFlashLoanReceiver
 * interface and the callback function `executeOperation`.
 * @param token the protocol fee in bps to be applied on the total flash loan fee
 * @param amount the total amount to borrow in this transaction
 * @param params optional data to pass along to the callback function
 */
function flashLoan(
        address receiver,
        IERC20 token,
        uint256 amount,
        bytes memory params
    ) external nonReentrant {
        uint8 tokenIndex = getTokenIndex(address(token));
        uint256 availableLiquidityBefore = token.balanceOf(address(this));
        uint256 protocolBalanceBefore = availableLiquidityBefore.sub(
            swapStorage.balances[tokenIndex]
        );
        require(
            amount > 0 && availableLiquidityBefore >= amount,
            "invalid amount"
        );

        // Calculate the additional amount of tokens the pool should end up with
        uint256 amountFee = amount.mul(flashLoanFeeBPS).div(10000);
        // Calculate the portion of the fee that will go to the protocol
        uint256 protocolFee = amountFee.mul(protocolFeeShareBPS).div(10000);
        require(amountFee > 0, "amount is small for a flashLoan");

        // Transfer the requested amount of tokens
        token.safeTransfer(receiver, amount);

        // Execute callback function on receiver
        IFlashLoanReceiver(receiver).executeOperation(
            address(this),
            address(token),
            amount,
            amountFee,
            params
        );

        uint256 availableLiquidityAfter = token.balanceOf(address(this));
        require(
            availableLiquidityAfter >= availableLiquidityBefore.add(amountFee),
            "flashLoan fee is not met"
        );

        swapStorage.balances[tokenIndex] = availableLiquidityAfter
            .sub(protocolBalanceBefore)
            .sub(protocolFee);
        emit FlashLoan(receiver, tokenIndex, amount, amountFee, protocolFee);
    }
// Solidity 0.6.12
/**
 * @notice Updates the flash loan fee parameters. This function can only be called by the owner.
 * @param newFlashLoanFeeBPS the total fee in bps to be applied on future flash loans
 * @param newProtocolFeeShareBPS the protocol fee in bps to be applied on the total flash loan fee
 */
function setFlashLoanFees(
        uint256 newFlashLoanFeeBPS,
        uint256 newProtocolFeeShareBPS
    ) external onlyOwner {
        require(
            newFlashLoanFeeBPS > 0 &&
                newFlashLoanFeeBPS <= MAX_BPS &&
                newProtocolFeeShareBPS <= MAX_BPS,
            "fees are not in valid range"
        );
        flashLoanFeeBPS = newFlashLoanFeeBPS;
        protocolFeeShareBPS = newProtocolFeeShareBPS;
    }