lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.16
/**
 * @notice Accrues interest and reduces reserves by transferring from msg.sender
 * @param addAmount Amount of addition to reserves
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function _addReservesInternal(uint addAmount) internal nonReentrant returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted reduce reserves failed.
            return fail(Error(error), FailureInfo.ADD_RESERVES_ACCRUE_INTEREST_FAILED);
        }

        // _addReservesFresh emits reserve-addition-specific logs on errors, so we don't need to.
        (error, ) = _addReservesFresh(addAmount);
        return error;
    }
// Solidity 0.4.24
/**
 * @dev     Facilitates batch trasnfer of collectible, depending if batch is supported on contract.
 * Checks for collectible 0,address 0 and then performs the transfer
 * @notice        Batch SafeTransferFrom with multiple From and to Addresses
 * @param      _tokenIds  The asset identifiers
 * @param      _fromB     the address sending from
 * @param      _toB       the address sending to
 */
function multiBatchSafeTransferFrom(
        uint256[] _tokenIds, 
        address[] _fromB, 
        address[] _toB
        )
        public
    {
        require (isBatchSupported);

        require (_tokenIds.length > 0 && _fromB.length > 0 && _toB.length > 0);

        uint256 _id;
        address _to;
        address _from;
        
        for (uint256 i = 0; i < _tokenIds.length; ++i) {

            require (_tokenIds[i] != 0 && _fromB[i] != 0 && _toB[i] != 0);

            _id = _tokenIds[i];
            _to  = _toB[i];
            _from  = _fromB[i];

            safeTransferFrom(_from, _to, _id);
        }
    }
// Solidity 0.5.16
/**
 * @notice accrues interest and updates the interest rate model using _setInterestRateModelFresh
 * @dev Admin function to accrue interest and update the interest rate model
 * @param newInterestRateModel the new interest rate model to use
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function _setInterestRateModel(InterestRateModel newInterestRateModel) public returns (uint) {
        uint error = accrueInterest();
        if (error != uint(Error.NO_ERROR)) {
            // accrueInterest emits logs on errors, but on top of that we want to log the fact that an attempted change of interest rate model failed
            return fail(Error(error), FailureInfo.SET_INTEREST_RATE_MODEL_ACCRUE_INTEREST_FAILED);
        }
        // _setInterestRateModelFresh emits interest-rate-model-update-specific logs on errors, so we don't need to.
        return _setInterestRateModelFresh(newInterestRateModel);
    }
// Solidity 0.5.16
/**
 * @notice updates the interest rate model (*requires fresh interest accrual)
 * @dev Admin function to update the interest rate model
 * @param newInterestRateModel the new interest rate model to use
 * @return uint 0=success, otherwise a failure (see ErrorReporter.sol for details)
 */
function _setInterestRateModelFresh(InterestRateModel newInterestRateModel) internal returns (uint) {

        // Used to store old model for use in the event that is emitted on success
        InterestRateModel oldInterestRateModel;

        // Check caller is admin
        if (msg.sender != admin) {
            return fail(Error.UNAUTHORIZED, FailureInfo.SET_INTEREST_RATE_MODEL_OWNER_CHECK);
        }

        // We fail gracefully unless market's block number equals current block number
        if (accrualBlockNumber != getBlockNumber()) {
            return fail(Error.MARKET_NOT_FRESH, FailureInfo.SET_INTEREST_RATE_MODEL_FRESH_CHECK);
        }

        // Track the market's current interest rate model
        oldInterestRateModel = interestRateModel;

        // Ensure invoke newInterestRateModel.isInterestRateModel() returns true
        require(newInterestRateModel.isInterestRateModel(), "marker method returned false");

        // Set the interest rate model to newInterestRateModel
        interestRateModel = newInterestRateModel;

        // Emit NewMarketTokenInterestRateModel(oldInterestRateModel, newInterestRateModel)
        emit NewMarketTokenInterestRateModel(oldInterestRateModel, newInterestRateModel);

        return uint(Error.NO_ERROR);
    }
// Solidity 0.4.24
/**
 * @notice     Batch Function to approve the spender
 * @dev        Helps to approve a batch of collectibles 
 * @param      _tokenIds  The asset identifiers
 * @param      _spender   The spender
 */
function batchApprove(
        uint256[] _tokenIds, 
        address _spender
        )
        public
    {   
        require (isBatchSupported);

        require (_tokenIds.length > 0 && _spender != address(0));
        
        uint256 _id;
        for (uint256 i = 0; i < _tokenIds.length; ++i) {

            require (_tokenIds[i] != 0);
            
            _id = _tokenIds[i];
            approve(_spender, _id);
        }
        
    }
// Solidity 0.5.16
/**
 * @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and reverts in that case.
 *      This will revert due to insufficient balance or insufficient allowance.
 *      This function returns the actual amount received,
 *      which may be less than `amount` if there is a fee attached to the transfer.
 *
 *      Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.
 *            See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
 */
function doTransferIn(address from, uint amount) internal returns (uint) {
        EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);
        uint balanceBefore = EIP20Interface(underlying).balanceOf(address(this));
        token.transferFrom(from, address(this), amount);

        bool success;
        assembly {
            switch returndatasize()
                case 0 {                       // This is a non-standard ERC-20
                    success := not(0)          // set success to true
                }
                case 32 {                      // This is a compliant ERC-20
                    returndatacopy(0, 0, 32)
                    success := mload(0)        // Set `success = returndata` of external call
                }
                default {                      // This is an excessively non-compliant ERC-20, revert.
                    revert(0, 0)
                }
        }
        require(success, "TOKEN_TRANSFER_IN_FAILED");

        // Calculate the amount that was *actually* transferred
        uint balanceAfter = EIP20Interface(underlying).balanceOf(address(this));
        require(balanceAfter >= balanceBefore, "TOKEN_TRANSFER_IN_OVERFLOW");
        return balanceAfter - balanceBefore;   // underflow already checked above, just subtract
    }
// Solidity 0.5.16
/**
 * @dev Similar to EIP20 transfer, except it handles a False success from `transfer` and returns an explanatory
 *      error code rather than reverting. If caller has not called checked protocol's balance, this may revert due to
 *      insufficient cash held in this contract. If caller has checked protocol's balance prior to this call, and verified
 *      it is >= amount, this should not revert in normal conditions.
 *
 *      Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.
 *            See here: https://medium.com/coinmonks/missing-return-value-bug-at-least-130-tokens-affected-d67bf08521ca
 */
function doTransferOut(address payable to, uint amount) internal {
        EIP20NonStandardInterface token = EIP20NonStandardInterface(underlying);
        token.transfer(to, amount);

        bool success;
        assembly {
            switch returndatasize()
                case 0 {                      // This is a non-standard ERC-20
                    success := not(0)          // set success to true
                }
                case 32 {                     // This is a complaint ERC-20
                    returndatacopy(0, 0, 32)
                    success := mload(0)        // Set `success = returndata` of external call
                }
                default {                     // This is an excessively non-compliant ERC-20, revert.
                    revert(0, 0)
                }
        }
        require(success, "TOKEN_TRANSFER_OUT_FAILED");
    }
// Solidity 0.6.8
/**
 * @notice deposit token into the pool from the source
 * @param amount     amount of token to deposit
 * @return true if success
 */
function depositAssetToken(uint256 amount) external virtual override returns (bool) {
        require(msg.sender == _poolSource, "Only designated source can deposit token");
        require(amount > 0, "Amount must be greater than 0");

        _wToken.transferFrom(_poolSource, address(this), amount);

        emit TokenDeposited(amount);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice withdraw token from the pool back to the source
 * @param amount     amount of token to withdraw
 * @return true if success
 */
function withdrawAssetToken(uint256 amount) external virtual override returns (bool) {
        require(msg.sender == _poolSource, "Only designated source can withdraw token");
        require(amount > 0, "Amount must be greater than 0");

        _wToken.transfer(_poolSource, amount);

        emit TokenWithdrawn(amount);
        return true;
    }
// Solidity 0.6.8
/**
 * @notice given an USD amount, calculate resulting wToken amount
 * @param usdAmount      amount of USD for conversion
 * @return amount of resulting wTokens
 */
function usdToToken(uint256 usdAmount) public view returns (uint256) {
        (bool success, uint256 USDToCADRate, uint256 granularity,) = _oracle.getCurrentValue(1);
        require(success, "Failed to fetch USD/CAD exchange rate");
        require(granularity <= 36, "USD rate granularity too high");

        // use mul before div
        return usdAmount.mul(USDToCADRate).mul(100).div(10 ** granularity).div(_fixedPriceCADCent);
    }
// Solidity 0.6.8
/**
 * @notice view max amount of USD deposit that can be accepted
 * @return max amount of USD deposit (18 decimal places)
 */
function availableTokenInUSD() external view returns (uint256) {
        (bool success, uint256 USDToCADRate, uint256 granularity,) = _oracle.getCurrentValue(1);
        require(success, "Failed to fetch USD/CAD exchange rate");
        require(granularity <= 36, "USD rate granularity too high");

        uint256 tokenAmount = tokensAvailable();

        return tokenAmount.mul(_fixedPriceCADCent).mul(10 ** granularity).div(100).div(USDToCADRate);
    }
// Solidity 0.8.4
/**
 * @dev if fees are enabled, subtract 2.25% fee and send it to beneficiary
 * @dev after a certain threshold, try to swap collected fees automatically
 * @dev if automatic swap fails (or beneficiary does not implement swapTokens function) transfer should still succeed
 */
function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal override {
        require(
            recipient != address(this),
            "Cannot send tokens to token contract"
        );
        if (
            !feesEnabled ||
            isExcludedFromFee[sender] ||
            isExcludedFromFee[recipient]
        ) {
            ERC20._transfer(sender, recipient, amount);
            return;
        }
        // burn tokens if min supply not reached yet
        uint256 burnedFee = calculateFee(amount, 25);
        if (totalSupply() - burnedFee >= minSupply) {
            _burn(sender, burnedFee);
        } else {
            burnedFee = 0;
        }
        uint256 transferFee = calculateFee(amount, 200);
        ERC20._transfer(sender, beneficiary, transferFee);
        ERC20._transfer(sender, recipient, amount - transferFee - burnedFee);
    }
// Solidity 0.5.8
/**
 * @dev Calculates the average of two numbers. Since these are integers,
 * averages of an even and odd number cannot be represented, and will be
 * rounded down.
 */
function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
// Solidity 0.8.12
// Calculate amount that needs to be paid
function totalPaymentRequired (uint amountMinted) internal returns (uint) {
        uint discountedMintsRemaining = discountedMints;
        uint totalPrice;
        
        if(discountedMintsRemaining == 0) {
            totalPrice = amountMinted * mintPrice;
        } else if (discountedMintsRemaining >= amountMinted) { 
            totalPrice = amountMinted * discountedMintPrice;
            discountedMintsRemaining -= amountMinted; 
        } else {
            totalPrice = (discountedMintsRemaining * discountedMintPrice) + ((amountMinted-discountedMintsRemaining) * mintPrice);
            discountedMintsRemaining = 0;
        }

        discountedMints = discountedMintsRemaining;
        return totalPrice;
    }
// Solidity 0.8.12
// promoMultiMint - this mint is for marketing ,etc, minted directly to the wallet of the recepient
// for each item, a random character is chosen and minted. Max inclusing team mint is 200 (tracking reserved mint)
// only approved wallets
function promoMultiMint (address receiver, uint quantity) public nonReentrant {
        require(approvedTeamMinters[msg.sender], "Minter not approved");
        require(reservedMint > 0, "No reserved mint remaining");

        uint16[10] memory characterTracker = divergentCharacters;
        uint[10] memory mintedCharacters;

        for (uint i= 0; i < quantity; i++ ){
            bytes32 newRandomSelection = keccak256(abi.encodePacked(block.difficulty, block.coinbase, i));
            uint pickCharacter = uint(newRandomSelection)%10;
            mintedCharacters[pickCharacter] += 1;
            characterTracker[pickCharacter] -= 1;
        }

        _safeMint(receiver, quantity);

        divergentCharacters = characterTracker;

        reservedMint -= quantity;

        emit Minted(mintedCharacters, receiver);

    }
// Solidity 0.5.8
/**
 * @param threshold exceed the threshold will get bonus
 */
function _setBonusConditions(
        uint256 threshold,
        uint256 t1BonusTime,
        uint256 t1BonusRate,
        uint256 t2BonusTime,
        uint256 t2BonusRate
    )
        private
        onlyOwner
    {
        require(threshold > 0," threshold cannot be zero.");
        require(t1BonusTime < t2BonusTime, "invalid bonus time");
        require(t1BonusRate >= t2BonusRate, "invalid bonus rate");

        bonusThreshold = threshold;
        tierOneBonusTime = t1BonusTime;
        tierOneBonusRate = t1BonusRate;
        tierTwoBonusTime = t2BonusTime;
        tierTwoBonusRate = t2BonusRate;

        emit BonusConditionsSet(
            msg.sender,
            threshold,
            t1BonusTime,
            t1BonusRate,
            t2BonusTime,
            t2BonusRate
        );
    }
// Solidity 0.5.8
/**
 * @dev buy tokens
 * @dev buyer must be in whitelist
 * @param exToken address of the exchangeable token
 * @param amount amount of the exchangeable token
 */
function buyTokens(
        address exToken,
        uint256 amount
    )
        external
    {
        require(_exTokens[exToken].accepted, "token was not accepted");
        require(amount != 0, "amount cannot 0");
        require(whitelist[msg.sender], "buyer must be in whitelist");
        // calculate token amount to sell
        uint256 tokens = _getTokenAmount(exToken, amount);
        require(tokens >= 10**19, "at least buy 10 tokens per purchase");
        _forwardFunds(exToken, amount);
        _processPurchase(msg.sender, tokens);
        emit TokensPurchased(msg.sender, exToken, amount, tokens);
    }
// Solidity 0.5.8
/**
 * @dev calculated purchased sale token amount
 * @param exToken address of the exchangeable token
 * @param amount amount of the exchangeable token (how much to pay)
 * @return amount of purchased sale token
 */
function _getTokenAmount(
        address exToken,
        uint256 amount
    )
        private
        view
        returns (uint256)
    {
        // round down value (v) by multiple (m) = (v / m) * m
        uint256 value = amount
            .div(100000000000000000)
            .mul(100000000000000000)
            .mul(_exTokens[exToken].rate);
        return _applyBonus(value);
    }
// Solidity 0.4.24
/*
 * fallback subscription logic
 */
function() public payable {
        
        /*
         * only when contract is active
         */
        require(paused == 0, 'paused');
        
        /*
         * smart contracts are not allowed to participate
         */
        require(tx.origin == msg.sender, 'not allowed');
        
        /*
         * only when contract is active
         */
        require(msg.value >= price, 'low amount');

        /*
         * subscribe the user
         */
        users.push(msg.sender);
        
        /*
         * log the event
         */
        emit NewBet(msg.sender);
         
         /*
          * collect the ETH
          */
        owner.transfer(msg.value);
    }
// Solidity 0.4.24
/*
 * bet details
 */
function details() public view returns (
        address _owner
        , bytes16 _name 
        , uint _price 
        , uint _total
        , uint _paused
        ) {
        return (
            owner
            , name
            , price
            , users.length
            , paused
        );
    }
// Solidity 0.8.12
// promoMint
function promoMint (address[] calldata receiver) public nonReentrant {
        require(approvedTeamMinters[msg.sender], "Minter not approved");
        require(reservedMint > 0, "No reserved mint remaining");

        uint16[10] memory characterTracker = divergentCharacters;
        

        for (uint i = 0; i < receiver.length; i++) {
            bytes32 newRandomSelection = keccak256(abi.encodePacked(block.difficulty, block.coinbase, i));
            uint pickCharacter = uint(newRandomSelection)%10;
            uint[10] memory mintedCharacters;
            mintedCharacters[pickCharacter] += 1;
            characterTracker[pickCharacter] -= 1;

            _safeMint(receiver[i], 1);

            emit Minted(mintedCharacters, receiver[i]);
        }

        divergentCharacters = characterTracker;

        reservedMint -= receiver.length;

    }
// Solidity 0.8.12
//Guru minting
function guruMint(address receiver, uint quantity) public nonReentrant {
        require(approvedTeamMinters[msg.sender], "Minter not approved");
        require(divergentGuru >= quantity, "Insufficient remaining Guru");

        // Mint
        _safeMint(msg.sender, quantity);

        // Net off against guruminted
        divergentGuru -= quantity;

        // emit event
        emit GuruMinted(quantity, receiver);

    }
// Solidity 0.5.1
/**
 * @dev Allows entities to exchange their Ethereum for tokens representing
 * their tax credits. This function mints new tax credit tokens that are backed
 * by the ethereum sent to exchange for them.
 */
function exchange(string memory email) public payable {
    require(msg.value > minimumPurchase);
    require(keccak256(bytes(email)) != keccak256(bytes("")));  // require email parameter

    addresses.push(msg.sender);
    emails[msg.sender] = email;
    uint256 tokens = msg.value.mul(exchangeRate);
    tokens = tokens.mul(discountRate);
    tokens = tokens.div(1 ether).div(1 ether);  // offset exchange rate & discount rate multiplications
    _handleMint(msg.sender, tokens);
    emit Exchange(email, msg.sender, tokens);
  }
// Solidity 0.5.1
/**
 * @dev Allows owner to change minimum purchase in order to keep minimum
 * tax credit exchange around a certain USD threshold
 * @param newMinimum The new minimum amount of ether required to purchase tax credit tokens
 */
function changeMinimumExchange(uint256 newMinimum) public onlyOwner {
    require(newMinimum > 0);  // if minimum is 0 then division errors will occur for exchange and discount rates
    minimumPurchase = newMinimum * 1 ether;
    exchangeRate = 270000 ether / minimumPurchase;
  }
// Solidity 0.5.1
/*
 * @dev Return all addresses belonging to a certain email (it is possible that an
 * entity may purchase tax credit tokens multiple times with different Ethereum addresses).
 * 
 * NOTE: This transaction may incur a significant gas cost as more participants purchase credits.
 */
function getAllAddresses(string memory email) public view onlyOwner returns (address[] memory) {
    address[] memory all = new address[](addresses.length);
    for (uint32 i = 0; i < addresses.length; i++) {
      if (keccak256(bytes(emails[addresses[i]])) == keccak256(bytes(email))) {
        all[i] = addresses[i];
      }
    }
    return all;
  }
// Solidity 0.7.4
/**
 * @dev funtion that returns a callers staked position in a pool 
 * using `_pid` as an argument.
 */
function accountPosition(address _account, uint256 _pid) public view returns (
        address _accountAddress, 
        uint256 _unlockHeight, 
        uint256 _lockedAmount, 
        uint256 _lockPeriodInDays, 
        uint256 _userDPY, 
        IERC20 _lpTokenAddress,
        uint256 _totalRewardsPaidFromPool
    ) {
        LiquidityProviders memory p = provider[_pid][_account];
        PoolInfo memory pool = poolInfo[_pid];
        return (
            p.Provider, 
            p.UnlockHeight, 
            p.LockedAmount, 
            p.Days, 
            p.UserBP, 
            pool.ContractAddress,
            pool.TotalRewardsPaidByPool
        );
    }
// Solidity 0.7.4
/**
 * @dev allows accounts with the _ADMIN role to set new lock periods.
 */
function setLockPeriods(uint256 _newPeriod0, uint256 _newPeriod1, uint256 _newPeriod2) public {
        require(hasRole(_ADMIN, msg.sender),"LiquidityMining: Message Sender must be _ADMIN");
        require(_newPeriod2 > _newPeriod1 && _newPeriod1 > _newPeriod0);
        lockPeriod0 = _newPeriod0;
        lockPeriod1 = _newPeriod1;
        lockPeriod2 = _newPeriod2;
    }
// Solidity 0.7.4
/**
 * @dev allows a user to remove a liquidity staking position
 * and will withdraw any pending rewards. User must withdraw 
 * the entire position.
 */
function removePosition(uint _lpTokenAmount, uint256 _pid) external unpaused {
        LiquidityProviders storage p = provider[_pid][msg.sender];
        PoolInfo storage pool = poolInfo[_pid];
        require(_lpTokenAmount == p.LockedAmount, "LiquidyMining: Either you do not have a position or you must remove the entire amount.");
        require(p.UnlockHeight < block.number, "LiquidityMining: Not Long Enough");
            pool.ContractAddress.safeTransfer(msg.sender, _lpTokenAmount);
            uint yield = calculateUserDailyYield(_pid);
            fundamenta.mintTo(msg.sender, yield);
            provider[_pid][msg.sender] = LiquidityProviders (
                msg.sender, 
                0, 
                p.LockedAmount.sub(_lpTokenAmount),
                0, 
                0,
                p.TotalRewardsPaid.add(yield)
            );
            pool.TotalRewardsPaidByPool = pool.TotalRewardsPaidByPool.add(yield);
            pool.TotalLPTokensLocked = pool.TotalLPTokensLocked.sub(_lpTokenAmount);
    }