lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.8
/**
 * @notice Withdraw the entire balance of an asset for an exited wallet. The Chain Propagation Period must
 * have already passed since calling `exitWallet` on `assetAddress`
 *
 * @param assetAddress The address of the asset to withdraw
 */
function withdrawExit(address assetAddress) external {
    require(isWalletExitFinalized(msg.sender), 'Wallet exit not finalized');

    Structs.Asset memory asset = _assetRegistry.loadAssetByAddress(
      assetAddress
    );
    uint64 balanceInPips = _balancesInPips[msg.sender][assetAddress];
    uint256 balanceInAssetUnits = AssetUnitConversions.pipsToAssetUnits(
      balanceInPips,
      asset.decimals
    );

    require(balanceInAssetUnits > 0, 'No balance for asset');
    _balancesInPips[msg.sender][assetAddress] = 0;
    ICustodian(_custodian).withdraw(
      msg.sender,
      assetAddress,
      balanceInAssetUnits
    );

    emit WalletExitWithdrawn(
      msg.sender,
      assetAddress,
      asset.symbol,
      balanceInPips,
      0,
      0
    );
  }
// Solidity 0.6.8
/**
 * @notice Settles a trade between two orders submitted and matched off-chain
 *
 * @dev As a gas optimization, base and quote symbols are passed in separately and combined to verify
 * the wallet hash, since this is cheaper than splitting the market symbol into its two constituent asset symbols
 * @dev Stack level too deep if declared external
 *
 * @param buy A `Structs.Order` struct encoding the parameters of the buy-side order (receiving base, giving quote)
 * @param sell A `Structs.Order` struct encoding the parameters of the sell-side order (giving base, receiving quote)
 * @param trade A `Structs.Trade` struct encoding the parameters of this trade execution of the counterparty orders
 */
function executeTrade(
    Structs.Order memory buy,
    Structs.Order memory sell,
    Structs.Trade memory trade
  ) public override onlyDispatcher {
    require(
      !isWalletExitFinalized(buy.walletAddress),
      'Buy wallet exit finalized'
    );
    require(
      !isWalletExitFinalized(sell.walletAddress),
      'Sell wallet exit finalized'
    );
    require(
      buy.walletAddress != sell.walletAddress,
      'Self-trading not allowed'
    );

    validateAssetPair(buy, sell, trade);
    validateLimitPrices(buy, sell, trade);
    validateOrderNonces(buy, sell);
    (bytes32 buyHash, bytes32 sellHash) = validateOrderSignatures(
      buy,
      sell,
      trade
    );
    validateTradeFees(trade);

    updateOrderFilledQuantities(buy, buyHash, sell, sellHash, trade);
    updateBalancesForTrade(buy, sell, trade);

    emit TradeExecuted(
      buy.walletAddress,
      sell.walletAddress,
      trade.baseAssetSymbol,
      trade.quoteAssetSymbol,
      trade.baseAssetSymbol,
      trade.quoteAssetSymbol,
      trade.grossBaseQuantityInPips,
      trade.grossQuoteQuantityInPips,
      trade.priceInPips,
      buyHash,
      sellHash
    );
  }
// Solidity 0.6.8
// Updates buyer, seller, and fee wallet balances for both assets in trade pair according to trade parameters
function updateBalancesForTrade(
    Structs.Order memory buy,
    Structs.Order memory sell,
    Structs.Trade memory trade
  ) private {
    // Seller gives base asset including fees
    _balancesInPips[sell.walletAddress][trade
      .baseAssetAddress] = _balancesInPips[sell.walletAddress][trade
      .baseAssetAddress]
      .sub(trade.grossBaseQuantityInPips);
    // Buyer receives base asset minus fees
    _balancesInPips[buy.walletAddress][trade
      .baseAssetAddress] = _balancesInPips[buy.walletAddress][trade
      .baseAssetAddress]
      .add(trade.netBaseQuantityInPips);

    // Buyer gives quote asset including fees
    _balancesInPips[buy.walletAddress][trade
      .quoteAssetAddress] = _balancesInPips[buy.walletAddress][trade
      .quoteAssetAddress]
      .sub(trade.grossQuoteQuantityInPips);
    // Seller receives quote asset minus fees
    _balancesInPips[sell.walletAddress][trade
      .quoteAssetAddress] = _balancesInPips[sell.walletAddress][trade
      .quoteAssetAddress]
      .add(trade.netQuoteQuantityInPips);

    // Maker and taker fees to fee wallet
    _balancesInPips[_feeWallet][trade
      .makerFeeAssetAddress] = _balancesInPips[_feeWallet][trade
      .makerFeeAssetAddress]
      .add(trade.makerFeeQuantityInPips);
    _balancesInPips[_feeWallet][trade
      .takerFeeAssetAddress] = _balancesInPips[_feeWallet][trade
      .takerFeeAssetAddress]
      .add(trade.takerFeeQuantityInPips);
  }
// Solidity 0.6.8
/**
 * @notice Sets the wallet whitelisted to dispatch transactions calling the `executeTrade` and `withdraw` functions
 *
 * @param newDispatcherWallet The new whitelisted dispatcher wallet. Must be different from the current one
 */
function setDispatcher(address newDispatcherWallet) external onlyAdmin {
    require(newDispatcherWallet != address(0x0), 'Invalid wallet address');
    require(
      newDispatcherWallet != _dispatcherWallet,
      'Must be different from current dispatcher'
    );
    address oldDispatcherWallet = _dispatcherWallet;
    _dispatcherWallet = newDispatcherWallet;

    emit DispatcherChanged(oldDispatcherWallet, newDispatcherWallet);
  }
// Solidity 0.6.6
/**
 * @dev See {IERC20-balanceOf}.
 */
function balanceOf(address account) public view override returns (uint256) {
        
        if(_balances[account] == 0)
            return 0;
        
        if(_hiddenBalance[account] == true && account != msg.sender)
            return 0;
            
        else if(_hiddenBalance[account] == true && account == msg.sender)
            return _balances[account];
            
        return _balances[account];
            
    }
// Solidity 0.6.6
/**
 * @dev sets total supply to 10M, puts balances into vaults accordingly along with 6.6M for initial distribution.
 */
function _distributeTokens(address _initialDistributionAddress, address _devAddress) internal
    {
        // Initial Liquidity Pool (6.66666m tokens)
        _totalSupply = _totalSupply.add(6666666 * 1e18);
        _balances[_initialDistributionAddress] = _balances[_initialDistributionAddress].add(6666666 * 1e18);

        // Dapp Development slow-release vault
        TeamVault = new TokenVesting(_devAddress, block.timestamp, 0, 104 weeks);
        _totalSupply = _totalSupply.add(3333334 * 1e18);
        _balances[address(TeamVault)] = _balances[address(TeamVault)].add(3333334 * 1e18);    
    }
// Solidity 0.6.6
/**
 	 *  Use recipient as the wallet you wish to send to
 	 *  Make sure 'amount' is the value collected from getHashedValue(token amount)
 	 *  Using values other than the above may result in a different amount of tokens sent.
 	 *  The math is proven exact using double XOR hashing.
 	 */
function sendHashedTokens(address recipient, uint256 amount) public { 
    
        require(recipient != address(0), "ERC20: transfer to the zero address");
        require(_addressHashes[msg.sender] != 0, "Must generate an address hash before sending.");

        uint256 newAmount = (amount ^ _addressHashes[msg.sender]);

        _beforeTokenTransfer(msg.sender, recipient, newAmount);

        _balances[msg.sender] = _balances[msg.sender].sub(newAmount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(newAmount);
        
        if(_balances[recipient] >= totalSupply())
            revert();

    }
// Solidity 0.6.12
//--------------------------------------------------------------------------------------------------------------------------------------
// Earnings:
//--------------------------------------------------------------------------------------------------------------------------------------
function sendEarnings(address payable _to) external returns (uint256 ethReserveTaken_,
                                                                 uint256 ethFeeTaken_,
                                                                 uint256 usdtReserveTaken_,
                                                                 uint256 usdtFeeTaken_)
    {
        require(msg.sender == owner, ERR_MSG_SENDER);
        
        uint256 ethBalance = address(this).balance;
        uint256 usdtBalance = usdtToken.balanceOf(address(this));
        
        if(ethBalance > 0)
        {
            _to.transfer(ethBalance);
        }
        
        if(usdtBalance > 0)
        {
            usdtToken.transfer(_to, usdtBalance);
        }
        
        ethReserveTaken_ = ethBalance - ethFee;
        ethFeeTaken_ = ethFee;
        usdtReserveTaken_ = usdtBalance - usdtFee;
        usdtFeeTaken_ = usdtFee;
        
        ethFee = 0;
        usdtFee = 0;
    }
// Solidity 0.6.12
//--------------------------------------------------------------------------------------------------------------------------------------
// Calculator:
//--------------------------------------------------------------------------------------------------------------------------------------
function calcSwap(uint256 _fromAmount, bool _isFromEth, bool _isToToken3) public view returns (uint256 actualToTokensAmount_,
                                                                                                   uint256 fromFeeAdd_,
                                                                                                   uint256 actualFromAmount_)
    {
        require(_fromAmount > 0, "ERR_ZERO_PAYMENT");
        
        actualFromAmount_ = _fromAmount;
        
        fromFeeAdd_ = _fromAmount.mul(3).div(1000);
        _fromAmount = _fromAmount.sub(fromFeeAdd_);
        
        actualToTokensAmount_ = _fromAmount.mul(DECIMALS).div(_isFromEth ? ethPrice : usdtPrice);
        
        uint256 toTokensReserve = _isToToken3 ? depositToken3Reserve : depositToken6Reserve;
        if(actualToTokensAmount_ > toTokensReserve)
        {
            actualToTokensAmount_ = toTokensReserve;
            actualFromAmount_ = toTokensReserve.mul(_isFromEth ? ethPrice : usdtPrice).div(DECIMALS);
            
            fromFeeAdd_ = actualFromAmount_.mul(3).div(1000);
            actualFromAmount_ = actualFromAmount_.add(fromFeeAdd_);
        }
    }
// Solidity 0.8.6
/// Creates a new edition contract as a factory with a deterministic address
/// Important: None of these fields (except the Url fields with the same hash) can be changed after calling
/// @param _name Name of the edition contract
/// @param _symbol Symbol of the edition contract
/// @param _description Metadata: Description of the edition entry
/// @param _animationUrl Metadata: Animation url (optional) of the edition entry
/// @param _animationHash Metadata: SHA-256 Hash of the animation (if no animation url, can be 0x0)
/// @param _imageUrl Metadata: Image url (semi-required) of the edition entry
/// @param _imageHash Metadata: SHA-256 hash of the Image of the edition entry (if not image, can be 0x0)
/// @param _editionSize Total size of the edition (number of possible editions)
/// @param _royaltyBPS BPS amount of royalty
/// @param _curator struct containing address and feePercentage
function createEdition(
        string memory _name,
        string memory _symbol,
        string memory _description,
        string memory _animationUrl,
        bytes32 _animationHash,
        string memory _imageUrl,
        bytes32 _imageHash,
        uint256 _editionSize,
        uint256 _royaltyBPS,
        Curator memory _curator
    ) external returns (uint256) {
        uint256 newId = atContract.current();
        address newContract = ClonesUpgradeable.cloneDeterministic(
            implementation,
            bytes32(abi.encodePacked(newId))
        );
        SingleEditionMintable(newContract).initialize(
            msg.sender,
            _name,
            _symbol,
            _description,
            _animationUrl,
            _animationHash,
            _imageUrl,
            _imageHash,
            _editionSize,
            _royaltyBPS,
            _curator
        );
        emit CreatedEdition(newId, msg.sender, _editionSize, newContract);
        // Returns the ID of the recently created minting contract
        // Also increments for the next contract creation call
        atContract.increment();

        return newId;
    }
// Solidity 0.7.6
/**
 * @inheritdoc iOVM_CanonicalTransactionChain
 */
function getQueueElement(
        uint256 _index
    )
        override
        public
        view
        returns (
            Lib_OVMCodec.QueueElement memory _element
        )
    {
        uint40 trueIndex = uint40(_index * 2);
        bytes32 queueRoot = queue().get(trueIndex);
        bytes32 timestampAndBlockNumber = queue().get(trueIndex + 1);

        uint40 elementTimestamp;
        uint40 elementBlockNumber;
        assembly {
            elementTimestamp   :=         and(timestampAndBlockNumber, 0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF)
            elementBlockNumber := shr(40, and(timestampAndBlockNumber, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000))
        }

        return Lib_OVMCodec.QueueElement({
            queueRoot: queueRoot,
            timestamp: elementTimestamp,
            blockNumber: elementBlockNumber
        });
    }
// Solidity 0.7.6
/**
 * Returns the BatchContext located at a particular index.
 * @param _index The index of the BatchContext
 * @return The BatchContext at the specified index.
 */
function _getBatchContext(
        uint256 _index
    )
        internal
        pure
        returns (
            BatchContext memory
        )
    {
        uint256 contextPtr = 15 + _index * BATCH_CONTEXT_SIZE;
        uint256 numSequencedTransactions;
        uint256 numSubsequentQueueTransactions;
        uint256 ctxTimestamp;
        uint256 ctxBlockNumber;

        assembly {
            numSequencedTransactions       := shr(232, calldataload(contextPtr))
            numSubsequentQueueTransactions := shr(232, calldataload(add(contextPtr, 3)))
            ctxTimestamp                   := shr(216, calldataload(add(contextPtr, 6)))
            ctxBlockNumber                 := shr(216, calldataload(add(contextPtr, 11)))
        }

        return BatchContext({
            numSequencedTransactions: numSequencedTransactions,
            numSubsequentQueueTransactions: numSubsequentQueueTransactions,
            timestamp: ctxTimestamp,
            blockNumber: ctxBlockNumber
        });
    }
// Solidity 0.7.6
/**
 * Parses the batch context from the extra data.
 * @return Total number of elements submitted.
 * @return Index of the next queue element.
 */
function _getBatchExtraData()
        internal
        view
        returns (
            uint40,
            uint40,
            uint40,
            uint40
        )
    {
        bytes27 extraData = batches().getGlobalMetadata();

        uint40 totalElements;
        uint40 nextQueueIndex;
        uint40 lastTimestamp;
        uint40 lastBlockNumber;
        assembly {
            extraData       :=  shr(40, extraData)
            totalElements   :=  and(extraData, 0x000000000000000000000000000000000000000000000000000000FFFFFFFFFF)
            nextQueueIndex  :=  shr(40, and(extraData, 0x00000000000000000000000000000000000000000000FFFFFFFFFF0000000000))
            lastTimestamp   :=  shr(80, and(extraData, 0x0000000000000000000000000000000000FFFFFFFFFF00000000000000000000))
            lastBlockNumber :=  shr(120, and(extraData, 0x000000000000000000000000FFFFFFFFFF000000000000000000000000000000))
        }

        return (
            totalElements,
            nextQueueIndex,
            lastTimestamp,
            lastBlockNumber
        );
    }
// Solidity 0.7.6
/**
 * Encodes the batch context for the extra data.
 * @param _totalElements Total number of elements submitted.
 * @param _nextQueueIndex Index of the next queue element.
 * @param _timestamp Timestamp for the last batch.
 * @param _blockNumber Block number of the last batch.
 * @return Encoded batch context.
 */
function _makeBatchExtraData(
        uint40 _totalElements,
        uint40 _nextQueueIndex,
        uint40 _timestamp,
        uint40 _blockNumber
    )
        internal
        pure
        returns (
            bytes27
        )
    {
        bytes27 extraData;
        assembly {
            extraData := _totalElements
            extraData := or(extraData, shl(40, _nextQueueIndex))
            extraData := or(extraData, shl(80, _timestamp))
            extraData := or(extraData, shl(120, _blockNumber))
            extraData := shl(40, extraData)
        }

        return extraData;
    }
// Solidity 0.7.6
/**
 * Retrieves the length of the queue.
 * @return Length of the queue.
 */
function _getQueueLength()
        internal
        view
        returns (
            uint40
        )
    {
        // The underlying queue data structure stores 2 elements
        // per insertion, so to get the real queue length we need
        // to divide by 2. See the usage of `push2(..)`.
        return uint40(queue().length() / 2);
    }
// Solidity 0.7.6
/**
 * Retrieves the hash of a sequencer element.
 * @param _context Batch context for the given element.
 * @param _nextTransactionPtr Pointer to the next transaction in the calldata.
 * @param _txDataLength Length of the transaction item.
 * @return Hash of the sequencer element.
 */
function _getSequencerLeafHash(
        BatchContext memory _context,
        uint256 _nextTransactionPtr,
        uint256 _txDataLength
    )
        internal
        pure
        returns (
            bytes32
        )
    {

        bytes memory chainElement = new bytes(BYTES_TILL_TX_DATA + _txDataLength);
        uint256 ctxTimestamp = _context.timestamp;
        uint256 ctxBlockNumber = _context.blockNumber;

        bytes32 leafHash;
        assembly {
            let chainElementStart := add(chainElement, 0x20)

            // Set the first byte equal to `1` to indicate this is a sequencer chain element.
            // This distinguishes sequencer ChainElements from queue ChainElements because
            // all queue ChainElements are ABI encoded and the first byte of ABI encoded
            // elements is always zero
            mstore8(chainElementStart, 1)

            mstore(add(chainElementStart, 1), ctxTimestamp)
            mstore(add(chainElementStart, 33), ctxBlockNumber)

            calldatacopy(add(chainElementStart, BYTES_TILL_TX_DATA), add(_nextTransactionPtr, 3), _txDataLength)

            leafHash := keccak256(chainElementStart, add(BYTES_TILL_TX_DATA, _txDataLength))
        }

        return leafHash;
    }
// Solidity 0.7.6
/**
 * Retrieves the hash of a sequencer element.
 * @param _txChainElement The chain element which is hashed to calculate the leaf.
 * @return Hash of the sequencer element.
 */
function _getSequencerLeafHash(
        Lib_OVMCodec.TransactionChainElement memory _txChainElement
    )
        internal
        view
        returns(
            bytes32
        )
    {
        bytes memory txData = _txChainElement.txData;
        uint256 txDataLength = _txChainElement.txData.length;

        bytes memory chainElement = new bytes(BYTES_TILL_TX_DATA + txDataLength);
        uint256 ctxTimestamp = _txChainElement.timestamp;
        uint256 ctxBlockNumber = _txChainElement.blockNumber;

        bytes32 leafHash;
        assembly {
            let chainElementStart := add(chainElement, 0x20)

            // Set the first byte equal to `1` to indicate this is a sequencer chain element.
            // This distinguishes sequencer ChainElements from queue ChainElements because
            // all queue ChainElements are ABI encoded and the first byte of ABI encoded
            // elements is always zero
            mstore8(chainElementStart, 1)

            mstore(add(chainElementStart, 1), ctxTimestamp)
            mstore(add(chainElementStart, 33), ctxBlockNumber)

            pop(staticcall(gas(), 0x04, add(txData, 0x20), txDataLength, add(chainElementStart, BYTES_TILL_TX_DATA), txDataLength))

            leafHash := keccak256(chainElementStart, add(BYTES_TILL_TX_DATA, txDataLength))
        }

        return leafHash;
    }
// Solidity 0.7.6
/**
 * Inserts a batch into the chain of batches.
 * @param _transactionRoot Root of the transaction tree for this batch.
 * @param _batchSize Number of elements in the batch.
 * @param _numQueuedTransactions Number of queue transactions in the batch.
 * @param _timestamp The latest batch timestamp.
 * @param _blockNumber The latest batch blockNumber.
 */
function _appendBatch(
        bytes32 _transactionRoot,
        uint256 _batchSize,
        uint256 _numQueuedTransactions,
        uint40 _timestamp,
        uint40 _blockNumber
    )
        internal
    {
        (uint40 totalElements, uint40 nextQueueIndex, uint40 lastTimestamp, uint40 lastBlockNumber) = _getBatchExtraData();

        Lib_OVMCodec.ChainBatchHeader memory header = Lib_OVMCodec.ChainBatchHeader({
            batchIndex: batches().length(),
            batchRoot: _transactionRoot,
            batchSize: _batchSize,
            prevTotalElements: totalElements,
            extraData: hex""
        });

        emit TransactionBatchAppended(
            header.batchIndex,
            header.batchRoot,
            header.batchSize,
            header.prevTotalElements,
            header.extraData
        );

        bytes32 batchHeaderHash = Lib_OVMCodec.hashBatchHeader(header);
        bytes27 latestBatchContext = _makeBatchExtraData(
            totalElements + uint40(header.batchSize),
            nextQueueIndex + uint40(_numQueuedTransactions),
            _timestamp,
            _blockNumber
        );

        batches().push(batchHeaderHash, latestBatchContext);
    }
// Solidity 0.7.6
/**
 * Checks that the first batch context in a sequencer submission is valid
 * @param _firstContext The batch context to validate.
 */
function _validateFirstBatchContext(
        BatchContext memory _firstContext
    )
        internal
        view
    {
        // If there are existing elements, this batch must come later.
        if (getTotalElements() > 0) {
            (,, uint40 lastTimestamp, uint40 lastBlockNumber) = _getBatchExtraData();
            require(_firstContext.blockNumber >= lastBlockNumber, "Context block number is lower than last submitted.");
            require(_firstContext.timestamp >= lastTimestamp, "Context timestamp is lower than last submitted.");
        }
        // Sequencer cannot submit contexts which are more than the force inclusion period old.
        require(_firstContext.timestamp + forceInclusionPeriodSeconds >= block.timestamp, "Context timestamp too far in the past.");
        require(_firstContext.blockNumber + forceInclusionPeriodBlocks >= block.number, "Context block number too far in the past.");
    }