lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.6
//=========================================================================================================================================
//overriden _transfer to take Fees
function _transfer(address sender, address recipient, uint256 amount) internal override Trading_Possible {
        
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");
    
        //updates _balances
        setBalance(sender, balanceOf(sender).sub(amount, "ERC20: transfer amount exceeds balance"));

        //calculate net amounts and fee
        (uint256 toAmount, uint256 toFee) = calculateAmountAndFee(sender, amount);
        
        //Send Reward to Vault 1st
        if(toFee > 0 && Vault != address(0)){
            setBalance(Vault, balanceOf(Vault).add(toFee));
            IVault(Vault).updateRewards(); //updating the vault with rewards sent.
            emit Transfer(sender, Vault, toFee);
        }
        
        //transfer to recipient
        setBalance(recipient, balanceOf(recipient).add(toAmount));
        emit Transfer(sender, recipient, toAmount);

    }
// Solidity 0.5.7
/**
 * Bid on rebalancing a given quantity of sets held by a rebalancing token wrapping or unwrapping
 * any ETH involved. The tokens are returned to the user.
 *
 * @param  _rebalancingSetToken    Instance of the rebalancing token being bid on
 * @param  _quantity               Number of currentSets to rebalance
 * @param  _allowPartialFill       Set to true if want to partially fill bid when quantity
 is greater than currentRemainingSets
 */
function bidAndWithdrawWithEther(
        IRebalancingSetToken _rebalancingSetToken,
        uint256 _quantity,
        bool _allowPartialFill
    )
        external
        payable
        nonReentrant
    {
        // Wrap all Ether sent to the contract
        weth.deposit.value(msg.value)();

        // Get token addresses
        address[] memory combinedTokenArray = _rebalancingSetToken.getCombinedTokenArray();

        // Get inflow and outflow arrays for the given bid quantity
        uint256[] memory inflowArray;
        uint256[] memory outflowArray;
        (
            inflowArray,
            outflowArray
        ) = _rebalancingSetToken.getBidPrice(_quantity);

        // Ensure allowances and transfer non-weth tokens from user
        depositNonWethComponents(
            combinedTokenArray,
            inflowArray
        );

        // Bid in auction
        rebalanceAuctionModule.bidAndWithdraw(
            address(_rebalancingSetToken),
            _quantity,
            _allowPartialFill
        );

        // Withdraw non-weth tokens to user
        withdrawNonWethComponentsToSender(
            combinedTokenArray
        );

        // Unwrap all remaining Ether and transfer to user
        uint256 wethBalance = ERC20Wrapper.balanceOf(address(weth), address(this));
        if (wethBalance > 0) {
            weth.withdraw(wethBalance);
            msg.sender.transfer(wethBalance);
        }

        // Log bid placed with Eth event
        emit BidPlacedWithEth(
            address(_rebalancingSetToken),
            msg.sender
        );
    }
// Solidity 0.5.7
/**
 * Before bidding, calculate the required amount of inflow tokens and deposit token components
 * into this helper contract.
 *
 * @param  _combinedTokenArray            Array of token addresses
 * @param  _inflowArray                   Array of inflow token units
 */
function depositNonWethComponents(
        address[] memory _combinedTokenArray,
        uint256[] memory _inflowArray
    )
        private
    {
        // Loop through the combined token addresses array and deposit inflow amounts
        for (uint256 i = 0; i < _combinedTokenArray.length; i++) {
            address currentComponent = _combinedTokenArray[i];
            uint256 currentComponentQuantity = _inflowArray[i];

            // Check component inflow is greater than 0
            if (currentComponentQuantity > 0) {
                // Ensure allowance for components to transferProxy
                ERC20Wrapper.ensureAllowance(
                    address(currentComponent),
                    address(this),
                    address(transferProxy),
                    currentComponentQuantity
                );

                // If not WETH, transfer tokens from user to contract
                if (currentComponent != address(weth)) {
                    // Transfer tokens to contract
                    ERC20Wrapper.transferFrom(
                        address(currentComponent),
                        msg.sender,
                        address(this),
                        currentComponentQuantity
                    );
                }
            }
        }
    }
// Solidity 0.5.7
/**
 * After bidding, loop through token address array and transfer
 * token components except wrapped ether to the sender
 *
 * @param  _combinedTokenArray           Array of token addresses
 */
function withdrawNonWethComponentsToSender(
        address[] memory _combinedTokenArray
    )
        private
    {
        // Loop through the combined token addresses array and withdraw leftover amounts
        for (uint256 i = 0; i < _combinedTokenArray.length; i++) {
            address currentComponent = _combinedTokenArray[i];

            // Get balance of tokens in contract
            uint256 currentComponentBalance = ERC20Wrapper.balanceOf(
                currentComponent,
                address(this)
            );

            // Check component balance is greater than 0
            if (currentComponentBalance > 0 && currentComponent != address(weth)) {
                // Withdraw tokens from the contract and send to the user
                ERC20Wrapper.transfer(
                    address(currentComponent),
                    msg.sender,
                    currentComponentBalance
                );
            }
        }
    }
// Solidity 0.7.6
// modified Transfer Function to log times @ accts balances exceed minReqBal, for Sublimation Pool
// modified Transfer Function to safeguard Uniswap liquidity during token sale
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        
        if(allowUniswap == false && sender != _owner && recipient == UniswapPair ){
            revert("UNI_LIQ_PLAY_NOT_YET");
        } else {
            
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);
        
        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        
        bool isOverReq = false;

        if(_balances[recipient] >= _minBalReq){

            isOverReq = true;
        }
        
        _balances[recipient] = _balances[recipient].add(amount);
        
        if(_balances[recipient] >= _minBalReq && isOverReq == false){
            
                _timeExceeded[recipient] = uint32(block.timestamp);
            }
        
        emit Transfer(sender, recipient, amount);
        }
    }
// Solidity 0.7.6
/**
 * @notice Dispatch the message it to the destination domain & recipient
 * @dev Format the message, insert its hash into Merkle tree,
 * enqueue the new Merkle root, and emit `Dispatch` event with message information.
 * @param _destinationDomain Domain of destination chain
 * @param _recipientAddress Address of recipient on destination chain as bytes32
 * @param _messageBody Raw bytes content of message
 */
function dispatch(
        uint32 _destinationDomain,
        bytes32 _recipientAddress,
        bytes memory _messageBody
    ) external notFailed {
        require(_messageBody.length <= MAX_MESSAGE_BODY_BYTES, "msg too long");
        // get the next nonce for the destination domain, then increment it
        uint32 _nonce = nonces[_destinationDomain];
        nonces[_destinationDomain] = _nonce + 1;
        // format the message into packed bytes
        bytes memory _message = Message.formatMessage(
            localDomain,
            bytes32(uint256(uint160(msg.sender))),
            _nonce,
            _destinationDomain,
            _recipientAddress,
            _messageBody
        );
        // insert the hashed message into the Merkle tree
        bytes32 _messageHash = keccak256(_message);
        tree.insert(_messageHash);
        // enqueue the new Merkle root after inserting the message
        queue.enqueue(root());
        // Emit Dispatch event with message information
        // note: leafIndex is count() - 1 since new leaf has already been inserted
        emit Dispatch(
            _messageHash,
            count() - 1,
            _destinationAndNonce(_destinationDomain, _nonce),
            committedRoot,
            _message
        );
    }
// Solidity 0.7.6
/**
 * @notice Submit a signature from the Updater "notarizing" a root,
 * which updates the Home contract's `committedRoot`,
 * and publishes the signature which will be relayed to Replica contracts
 * @dev emits Update event
 * @dev If _newRoot is not contained in the queue,
 * the Update is a fraudulent Improper Update, so
 * the Updater is slashed & Home is set to FAILED state
 * @param _committedRoot Current updated merkle root which the update is building off of
 * @param _newRoot New merkle root to update the contract state to
 * @param _signature Updater signature on `_committedRoot` and `_newRoot`
 */
function update(
        bytes32 _committedRoot,
        bytes32 _newRoot,
        bytes memory _signature
    ) external notFailed {
        // check that the update is not fraudulent;
        // if fraud is detected, Updater is slashed & Home is set to FAILED state
        if (improperUpdate(_committedRoot, _newRoot, _signature)) return;
        // clear all of the intermediate roots contained in this update from the queue
        while (true) {
            bytes32 _next = queue.dequeue();
            if (_next == _newRoot) break;
        }
        // update the Home state with the latest signed root & emit event
        committedRoot = _newRoot;
        emit Update(localDomain, _committedRoot, _newRoot, _signature);
    }
// Solidity 0.7.6
/**
 * @notice Check if an Update is an Improper Update;
 * if so, slash the Updater and set the contract to FAILED state.
 *
 * An Improper Update is an update building off of the Home's `committedRoot`
 * for which the `_newRoot` does not currently exist in the Home's queue.
 * This would mean that message(s) that were not truly
 * dispatched on Home were falsely included in the signed root.
 *
 * An Improper Update will only be accepted as valid by the Replica
 * If an Improper Update is attempted on Home,
 * the Updater will be slashed immediately.
 * If an Improper Update is submitted to the Replica,
 * it should be relayed to the Home contract using this function
 * in order to slash the Updater with an Improper Update.
 *
 * An Improper Update submitted to the Replica is only valid
 * while the `_oldRoot` is still equal to the `committedRoot` on Home;
 * if the `committedRoot` on Home has already been updated with a valid Update,
 * then the Updater should be slashed with a Double Update.
 * @dev Reverts (and doesn't slash updater) if signature is invalid or
 * update not current
 * @param _oldRoot Old merkle tree root (should equal home's committedRoot)
 * @param _newRoot New merkle tree root
 * @param _signature Updater signature on `_oldRoot` and `_newRoot`
 * @return TRUE if update was an Improper Update (implying Updater was slashed)
 */
function improperUpdate(
        bytes32 _oldRoot,
        bytes32 _newRoot,
        bytes memory _signature
    ) public notFailed returns (bool) {
        require(
            _isUpdaterSignature(_oldRoot, _newRoot, _signature),
            "!updater sig"
        );
        require(_oldRoot == committedRoot, "not a current update");
        // if the _newRoot is not currently contained in the queue,
        // slash the Updater and set the contract to FAILED state
        if (!queue.contains(_newRoot)) {
            _fail();
            emit ImproperUpdate(_oldRoot, _newRoot, _signature);
            return true;
        }
        // if the _newRoot is contained in the queue,
        // this is not an improper update
        return false;
    }
// Solidity 0.4.8
// n form 1 <= to <= 32
function getBetValue(bytes32 values, uint8 n) private constant returns (uint256)
   {
        // bet in credits (1..256) 
        uint256 bet = uint256(values[32-n])+1;

         // check min bet
        uint8 minCredits = minCreditsOnBet[n];
        if (minCredits == 0) minCredits = defaultMinCreditsOnBet;
        if (bet < minCredits) throw;
        
        // bet in wei
        bet = currentMaxBet*bet/256;
        if (bet > currentMaxBet) throw;         

        return bet;        
   }
// Solidity 0.5.0
/**
 * @dev Private implementation of staking methods.
 * @param staker User address who deposits tokens to stake.
 * @param beneficiary User address who gains credit for this stake operation.
 * @param amount Number of deposit tokens to stake.
 */
function _stakeFor(address staker, address beneficiary, uint256 amount) private {
        require(amount > 0, 'SeigniorageMining: stake amount is zero');
        require(beneficiary != address(0), 'SeigniorageMining: beneficiary is zero address');
        require(totalStakingShares == 0 || totalStaked() > 0,
                'SeigniorageMining: Invalid state. Staking shares exist, but no staking tokens do');

        uint256 mintedStakingShares = (totalStakingShares > 0)
            ? totalStakingShares.mul(amount).div(totalStaked())
            : amount.mul(_initialSharesPerToken);
        require(mintedStakingShares > 0, 'SeigniorageMining: Stake amount is too small');

        updateAccounting();

        // 1. User Accounting
        UserTotals storage totals = _userTotals[beneficiary];
        totals.stakingShares = totals.stakingShares.add(mintedStakingShares);
        totals.lastAccountingTimestampSec = now;

        Stake memory newStake = Stake(mintedStakingShares, now);
        _userStakes[beneficiary].push(newStake);

        // 2. Global Accounting
        totalStakingShares = totalStakingShares.add(mintedStakingShares);
        // Already set in updateAccounting()
        // _lastAccountingTimestampSec = now;

        // interactions
        require(_stakingPool.token().transferFrom(staker, address(_stakingPool), amount),
            'SeigniorageMining: transfer into staking pool failed');

        emit Staked(beneficiary, amount, totalStakedFor(beneficiary), "");
    }
// Solidity 0.5.0
/**
 * @dev A globally callable function to update the accounting state of the system.
 *      Global state and state for the caller are updated.
 * @return [0] balance of the locked pool
 * @return [1] balance of the unlocked pool
 * @return [2] caller's staking share seconds
 * @return [3] global staking share seconds
 * @return [4] Rewards caller has accumulated
 * @return [5] Dollar Rewards caller has accumulated
 * @return [6] block timestamp
 */
function updateAccounting() public returns (
        uint256, uint256, uint256, uint256, uint256, uint256, uint256) {

        unlockTokens();

        // Global accounting
        uint256 newStakingShareSeconds =
            now
            .sub(_lastAccountingTimestampSec)
            .mul(totalStakingShares);
        _totalStakingShareSeconds = _totalStakingShareSeconds.add(newStakingShareSeconds);
        _lastAccountingTimestampSec = now;

        // User Accounting
        UserTotals storage totals = _userTotals[msg.sender];
        uint256 newUserStakingShareSeconds =
            now
            .sub(totals.lastAccountingTimestampSec)
            .mul(totals.stakingShares);
        totals.stakingShareSeconds =
            totals.stakingShareSeconds
            .add(newUserStakingShareSeconds);
        totals.lastAccountingTimestampSec = now;

        uint256 totalUserShareRewards = (_totalStakingShareSeconds > 0)
            ? totalUnlocked().mul(totals.stakingShareSeconds).div(_totalStakingShareSeconds)
            : 0;
    
        uint256 totalUserDollarRewards = (_totalStakingShareSeconds > 0)
            ? totalLockedDollars().mul(totals.stakingShareSeconds).div(_totalStakingShareSeconds)
            : 0;

        return (
            totalLocked(),
            totalUnlocked(),
            totals.stakingShareSeconds,
            _totalStakingShareSeconds,
            totalUserShareRewards,
            totalUserDollarRewards,
            now
        );
    }
// Solidity 0.5.0
/**
 * @dev This funcion allows the contract owner to add more locked distribution tokens, along
 *      with the associated "unlock schedule". These locked tokens immediately begin unlocking
 *      linearly over the duraction of durationSec timeframe.
 * @param amount Number of distribution tokens to lock. These are transferred from the caller.
 * @param durationSec Length of time to linear unlock the tokens.
 */
function lockTokens(uint256 amount, uint256 startTimeSec, uint256 durationSec) external onlyOwner {
        require(unlockSchedules.length < _maxUnlockSchedules,
            'SeigniorageMining: reached maximum unlock schedules');

        // Update lockedTokens amount before using it in computations after.
        updateAccounting();

        uint256 lockedTokens = totalLocked();
        uint256 mintedLockedShares = (lockedTokens > 0)
            ? totalLockedShares.mul(amount).div(lockedTokens)
            : amount.mul(_initialSharesPerToken);

        UnlockSchedule memory schedule;
        schedule.initialLockedShares = mintedLockedShares;
        schedule.lastUnlockTimestampSec = now;
        schedule.startAtSec = startTimeSec;
        schedule.endAtSec = startTimeSec.add(durationSec);
        schedule.durationSec = durationSec;
        unlockSchedules.push(schedule);

        totalLockedShares = totalLockedShares.add(mintedLockedShares);

        require(_lockedPool.shareToken().transferFrom(msg.sender, address(_lockedPool), amount),
            'SeigniorageMining: transfer into locked pool failed');
        emit TokensLocked(amount, durationSec, totalLocked());
    }
// Solidity 0.5.0
/**
 * @dev Moves distribution tokens from the locked pool to the unlocked pool, according to the
 *      previously defined unlock schedules. Publicly callable.
 * @return Number of newly unlocked distribution tokens.
 */
function unlockTokens() public returns (uint256) {
        uint256 unlockedShareTokens = 0;
        uint256 lockedShareTokens = totalLocked();

        uint256 unlockedDollars = 0;
        uint256 lockedDollars = totalLockedDollars();

        if (totalLockedShares == 0) {
            unlockedShareTokens = lockedShareTokens;
            unlockedDollars = lockedDollars;
        } else {
            uint256 unlockedShares = 0;
            for (uint256 s = 0; s < unlockSchedules.length; s++) {
                unlockedShares = unlockedShares.add(unlockScheduleShares(s));
            }
            unlockedShareTokens = unlockedShares.mul(lockedShareTokens).div(totalLockedShares);
            unlockedDollars = unlockedShares.mul(lockedDollars).div(totalLockedShares);
            totalLockedShares = totalLockedShares.sub(unlockedShares);
        }

        if (unlockedShareTokens > 0) {
            require(_lockedPool.shareTransfer(address(_unlockedPool), unlockedShareTokens),
                'SeigniorageMining: shareTransfer out of locked pool failed');
            require(_lockedPool.dollarTransfer(address(_unlockedPool), unlockedDollars),
                'SeigniorageMining: dollarTransfer out of locked pool failed');

            emit TokensUnlocked(unlockedShareTokens, totalLocked());
            emit DollarsUnlocked(unlockedDollars, totalLocked());
        }

        return unlockedShareTokens;
    }
// Solidity 0.5.0
/**
 * @dev Returns the number of unlockable shares from a given schedule. The returned value
 *      depends on the time since the last unlock. This function updates schedule accounting,
 *      but does not actually transfer any tokens.
 * @param s Index of the unlock schedule.
 * @return The number of unlocked shares.
 */
function unlockScheduleShares(uint256 s) private returns (uint256) {
        UnlockSchedule storage schedule = unlockSchedules[s];

        if(schedule.unlockedShares >= schedule.initialLockedShares) {
            return 0;
        }

        uint256 sharesToUnlock = 0;
        if (now < schedule.startAtSec) {
            // do nothing
        } else if (now >= schedule.endAtSec) { // Special case to handle any leftover dust from integer division
            sharesToUnlock = (schedule.initialLockedShares.sub(schedule.unlockedShares));
            schedule.lastUnlockTimestampSec = schedule.endAtSec;
        } else {
            sharesToUnlock = now.sub(schedule.lastUnlockTimestampSec)
                .mul(schedule.initialLockedShares)
                .div(schedule.durationSec);
            schedule.lastUnlockTimestampSec = now;
        }

        schedule.unlockedShares = schedule.unlockedShares.add(sharesToUnlock);
        return sharesToUnlock;
    }
// Solidity 0.4.13
// Get token creation rate
function getTokenCreationRate() constant returns (uint256) {
        require(!presaleFinalized || !saleFinalized);

        uint256 creationRate;

        if (!presaleFinalized) {
            //The rate on presales is constant
            creationRate = presaleTokenCreationRate;
        } else {
            //The rate on sale is changing lineral while time is passing. On sales start it is 1.66 and on end 1.0 
            uint256 rateRange = saleStartTokenCreationRate - saleEndTokenCreationRate;
            uint256 timeRange = saleEndTime - saleStartTime;
            creationRate = saleStartTokenCreationRate.sub(rateRange.mul(now.sub(saleStartTime)).div(timeRange));
        }

        return creationRate;
    }
// Solidity 0.4.13
// Buy presale tokens
function buyPresaleTokens(address _beneficiary) payable {
        require(!presaleFinalized);
        require(msg.value != 0);
        require(now <= presaleEndTime);
        require(now >= presaleStartTime);

        uint256 bbdTokens = msg.value.mul(getTokenCreationRate()).div(divisor);
        uint256 checkedSupply = totalSupply.add(bbdTokens);
        require(presaleTokenCreationCap >= checkedSupply);

        totalSupply = totalSupply.add(bbdTokens);
        balances[_beneficiary] = balances[_beneficiary].add(bbdTokens);

        raised += msg.value;
        TokenPurchase(msg.sender, _beneficiary, msg.value, bbdTokens);
    }
// Solidity 0.4.13
// Finalize presale
function finalizePresale() onlyOwner external {
        require(!presaleFinalized);
        require(now >= presaleEndTime || totalSupply == presaleTokenCreationCap);

        presaleFinalized = true;

        uint256 ethForCoreMember = this.balance.mul(500).div(divisor);

        coreTeamMemberOne.transfer(ethForCoreMember); // 5%
        coreTeamMemberTwo.transfer(ethForCoreMember); // 5%
        qtAccount.transfer(this.balance); // Quant Technology 90%
    }
// Solidity 0.4.13
// Buy sale tokens
function buySaleTokens(address _beneficiary) payable {
        require(!saleFinalized);
        require(msg.value != 0);
        require(now <= saleEndTime);
        require(now >= saleStartTime);

        uint256 bbdTokens = msg.value.mul(getTokenCreationRate()).div(divisor);
        uint256 checkedSupply = totalSupply.add(bbdTokens);
        require(totalTokenCreationCap >= checkedSupply);

        totalSupply = totalSupply.add(bbdTokens);
        balances[_beneficiary] = balances[_beneficiary].add(bbdTokens);

        raised += msg.value;
        TokenPurchase(msg.sender, _beneficiary, msg.value, bbdTokens);
    }