lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.8.9
/// @notice may mint up to 5 tokens per transaction at the public sale price.
function mint(uint quantity) external payable {
        require(isPublicSaleActive(), "PUBLIC_SALE_INACTIVE");
        require(quantity <= PUBLIC_LIMIT, "5_TOKEN_LIMIT");
        require(totalSupply() + quantity <= COLLECTION_SIZE, "EXCEEDS_COLLECTION_SIZE");
        uint cost;
        cost = quantity * PUBLIC_PRICE;
        require(msg.value >= cost, "VALUE_TOO_LOW");

        _safeMint(msg.sender, quantity);
    }
// Solidity 0.7.1
//Admin pays dev and management team.
function payToken() public onlyOwner {
        //check if it's past the next payperiod.  
        require(block.timestamp >= (time + locktime), "Period not reached yet. ");

        
        //Sends dev payment. 
        require(token.transfer(dev, devAmount) == true, "You don't have enough in balance. ");
        
        //sends management payments.
        require(token.transfer(safe, managementAmount) == true, "You don't have enough in balance. ");
        require(token.transfer(mike, managementAmount) == true, "You don't have enough in balance. ");
        require(token.transfer(ghost, managementAmount) == true, "You don't have enough in balance. ");
        
        time += locktime; 
        
    }
// Solidity 0.4.23
//human 0.1 standard. Just an arbitrary versioning scheme.
function BoxTrade(
        ) {
        balances[msg.sender] = 100000000000000000;
        totalSupply = 100000000000000000;
        name = "BoxTrade";                                   // Set the name for display purposes
        decimals = 5;                            // Amount of decimals for display purposes
        symbol = "BOXY";                               // Set the symbol for display purposes
    }
// Solidity 0.6.6
// **** ADD LIQUIDITY ****
function _addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin
    ) internal virtual returns (uint amountA, uint amountB) {
        // create the pair if it doesn't exist yet
        if (IUniswapV2Factory(factory).getPair(tokenA, tokenB) == address(0)) {
            IUniswapV2Factory(factory).createPair(tokenA, tokenB);
        }
        (uint reserveA, uint reserveB) = UniswapV2Library.getReserves(factory, tokenA, tokenB);
        if (reserveA == 0 && reserveB == 0) {
            (amountA, amountB) = (amountADesired, amountBDesired);
        } else {
            uint amountBOptimal = UniswapV2Library.quote(amountADesired, reserveA, reserveB);
            if (amountBOptimal <= amountBDesired) {
                require(amountBOptimal >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT');
                (amountA, amountB) = (amountADesired, amountBOptimal);
            } else {
                uint amountAOptimal = UniswapV2Library.quote(amountBDesired, reserveB, reserveA);
                assert(amountAOptimal <= amountADesired);
                require(amountAOptimal >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT');
                (amountA, amountB) = (amountAOptimal, amountBDesired);
            }
        }
    }
// Solidity 0.6.6
// **** REMOVE LIQUIDITY ****
function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) public virtual override ensure(deadline) returns (uint amountA, uint amountB) {
        address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB);
        IUniswapV2Pair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair
        (uint amount0, uint amount1) = IUniswapV2Pair(pair).burn(to);
        (address token0,) = UniswapV2Library.sortTokens(tokenA, tokenB);
        (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);
        require(amountA >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT');
        require(amountB >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT');
    }
// Solidity 0.6.6
// **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) ****
function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) public virtual override ensure(deadline) returns (uint amountETH) {
        (, amountETH) = removeLiquidity(
            token,
            WETH,
            liquidity,
            amountTokenMin,
            amountETHMin,
            address(this),
            deadline
        );
        TransferHelper.safeTransfer(token, to, IERC20(token).balanceOf(address(this)));
        IWETH(WETH).withdraw(amountETH);
        TransferHelper.safeTransferETH(to, amountETH);
    }
// Solidity 0.6.6
// **** SWAP ****
// requires the initial amount to have already been sent to the first pair
function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual {
        for (uint i; i < path.length - 1; i++) {
            (address input, address output) = (path[i], path[i + 1]);
            (address token0,) = UniswapV2Library.sortTokens(input, output);
            uint amountOut = amounts[i + 1];
            (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
            address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to;
            IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap(
                amount0Out, amount1Out, to, new bytes(0)
            );
        }
    }
// Solidity 0.6.7
// Deleverages until we're supplying <x> amount
// 1. Redeem <x> DAI
// 2. Repay <x> DAI
function deleverageUntil(uint256 _supplyAmount) public onlyKeepers {
        uint256 unleveragedSupply = getSuppliedUnleveraged();
        uint256 supplied = getSupplied();
        require(
            _supplyAmount >= unleveragedSupply && _supplyAmount <= supplied,
            "!deleverage"
        );

        // Since we're only leveraging on 1 asset
        // redeemable = borrowable
        uint256 _redeemAndRepay = getBorrowable();
        do {
            if (supplied.sub(_redeemAndRepay) < _supplyAmount) {
                _redeemAndRepay = supplied.sub(_supplyAmount);
            }

            require(
                ICToken(cdai).redeemUnderlying(_redeemAndRepay) == 0,
                "!redeem"
            );
            IERC20(dai).safeApprove(cdai, 0);
            IERC20(dai).safeApprove(cdai, _redeemAndRepay);
            require(ICToken(cdai).repayBorrow(_redeemAndRepay) == 0, "!repay");

            supplied = supplied.sub(_redeemAndRepay);
        } while (supplied > _supplyAmount);
    }
// Solidity 0.6.6
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
        require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
    }
// Solidity 0.6.6
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
        (address token0, address token1) = sortTokens(tokenA, tokenB);
        pair = address(uint(keccak256(abi.encodePacked(
                hex'ff',
                factory,
                keccak256(abi.encodePacked(token0, token1)),
                hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
            ))));
    }
// Solidity 0.6.6
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
        (address token0,) = sortTokens(tokenA, tokenB);
        (uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
        (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
    }
// Solidity 0.6.6
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
        require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
        require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        amountB = amountA.mul(reserveB) / reserveA;
    }
// Solidity 0.6.6
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }
// Solidity 0.5.7
/**
 * Get an account's summary for each market.
 *
 * @param  account  The account to query
 * @return          The following values:
 *                   - The ERC20 token address for each market
 *                   - The account's principal value for each market
 *                   - The account's (supplied or borrowed) number of tokens for each market
 */
function getAccountBalances(
        Account.Info memory account
    )
        public
        view
        returns (
            address[] memory,
            Types.Par[] memory,
            Types.Wei[] memory
        )
    {
        uint256 numMarkets = g_state.numMarkets;
        address[] memory tokens = new address[](numMarkets);
        Types.Par[] memory pars = new Types.Par[](numMarkets);
        Types.Wei[] memory weis = new Types.Wei[](numMarkets);

        for (uint256 m = 0; m < numMarkets; m++) {
            tokens[m] = getMarketTokenAddress(m);
            pars[m] = getAccountPar(account, m);
            weis[m] = getAccountWei(account, m);
        }

        return (
            tokens,
            pars,
            weis
        );
    }
// Solidity 0.6.6
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[0] = amountIn;
        for (uint i; i < path.length - 1; i++) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
            amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
        }
    }
// Solidity 0.5.7
/**
 * Private helper for getting the monetary values of an account.
 */
function getAccountValuesInternal(
        Account.Info memory account,
        bool adjustForLiquidity
    )
        private
        view
        returns (Monetary.Value memory, Monetary.Value memory)
    {
        uint256 numMarkets = g_state.numMarkets;

        // populate cache
        Cache.MarketCache memory cache = Cache.create(numMarkets);
        for (uint256 m = 0; m < numMarkets; m++) {
            if (!g_state.getPar(account, m).isZero()) {
                cache.addMarket(g_state, m);
            }
        }

        return g_state.getAccountValues(account, cache, adjustForLiquidity);
    }
// Solidity 0.4.24
// This function to be used if the target is a contract address
function transferToContract(address _to, uint256 _value, bytes _data) internal returns (bool) {
        require(balances[msg.sender] >= _value);
        require(vestingEnded(msg.sender));
        
        // This will override settings and allow contract owner to send to contract
        if(msg.sender != contractOwner){
            ERC223ReceivingContract _tokenReceiver = ERC223ReceivingContract(_to);
            _tokenReceiver.tokenFallback(msg.sender, _value, _data);
        }

        balances[msg.sender] = balances[msg.sender].sub(_value);
        balances[_to] = balances[_to].add(_value);

        emit Transfer(msg.sender, _to, _value);
        emit Transfer(msg.sender, _to, _value, _data);
        return true;
    }
// Solidity 0.8.7
/**
 * @dev set available traits and rarities at the same time
 * @dev example: [500, 500, 0, 100, 300, 600] sets two sequences separated by '0'
 *               [500, 500], [100, 300, 600] sequence 0 and 1, index is trait value is rarity
 */
function setTraits(uint16[] memory rarities) public onlyOwner {
        require(rarities.length > 0, "Rarities is empty, Use resetTraits() instead");
        resetTraits();
        uint16 trait = 0;
        sequences.push(trait);
        for(uint i; i < rarities.length; i++) {
            uint16 rarity = rarities[i];
            if (rarity == 0) {
                trait++;
                sequences.push(trait);
            } else {
                traits[trait].push(rarity);
                sequenceToRarityTotals[trait] += rarity;
            }
        }
    }
// Solidity 0.4.24
// ERC20 standard function
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success){
        require(_value <= allowed[_from][msg.sender]);
        require(_value <= balances[_from]);
        require(vestingEnded(_from));

        balances[_from] = balances[_from].sub(_value);
        balances[_to] = balances[_to].add(_value);
        allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);

        emit Transfer(_from, _to, _value);

        return true;
    }
// Solidity 0.4.24
// Burn the specified amount of tokens by the owner
function _burn(address _user, uint256 _value) internal ownerOnly {
        require(balances[_user] >= _value);

        balances[_user] = balances[_user].sub(_value);
        _totalSupply = _totalSupply.sub(_value);
        
        emit Burn(_user, _value);
        emit Transfer(_user, address(0), _value);

        bytes memory _empty;
        emit Transfer(_user, address(0), _value, _empty);
    }
// Solidity 0.6.2
/**
 * @dev Multiplies two numbers, reverts on overflow.
 * @param _factor1 Factor number.
 * @param _factor2 Factor number.
 * @return product The product of the two factors.
 */
function mul(
    uint256 _factor1,
    uint256 _factor2
  )
    internal
    pure
    returns (uint256 product)
  {
    // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
    // benefit is lost if 'b' is also tested.
    // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
    if (_factor1 == 0)
    {
      return 0;
    }

    product = _factor1 * _factor2;
    require(product / _factor1 == _factor2, OVERFLOW);
  }
// Solidity 0.6.2
/**
 * @dev Integer division of two numbers, truncating the quotient, reverts on division by zero.
 * @param _dividend Dividend number.
 * @param _divisor Divisor number.
 * @return quotient The quotient.
 */
function div(
    uint256 _dividend,
    uint256 _divisor
  )
    internal
    pure
    returns (uint256 quotient)
  {
    // Solidity automatically asserts when dividing by 0, using all gas.
    require(_divisor > 0, DIVISION_BY_ZERO);
    quotient = _dividend / _divisor;
    // assert(_dividend == _divisor * quotient + _dividend % _divisor); // There is no case in which this doesn't hold.
  }
// Solidity 0.8.6
/* ========== VIEWS ========== */
function showAllocations() public view returns (uint256[4] memory allocations) {
        // All numbers given are in FRAX unless otherwise stated

        // Unallocated FRAX
        allocations[0] = FRAX.balanceOf(address(this));

        // Unallocated Collateral Dollar Value (E18)
        allocations[1] = freeColDolVal();

        // Sum of Uni v3 Positions liquidity, if it was all in FRAX
        allocations[2] = TotalLiquidityFrax();

        // Total Value
        allocations[3] = allocations[0].add(allocations[1]).add(allocations[2]);
    }
// Solidity 0.8.6
// E18 Collateral dollar value
function freeColDolVal() public view returns (uint256) {
        uint256 value_tally_e18 = 0;
        for (uint i = 0; i < collateral_addresses.length; i++){
            ERC20 thisCollateral = ERC20(collateral_addresses[i]);
            uint256 missing_decs = uint256(18).sub(thisCollateral.decimals());
            uint256 col_bal_e18 = thisCollateral.balanceOf(address(this)).mul(10 ** missing_decs);
            uint256 col_usd_value_e18 = collatDolarValue(oracles[collateral_addresses[i]], col_bal_e18);
            value_tally_e18 = value_tally_e18.add(col_usd_value_e18);
        }
        return value_tally_e18;
    }
// Solidity 0.8.6
// Needed for the Frax contract to function
function collatDollarBalance() public view returns (uint256) {
        // Get the allocations
        uint256[4] memory allocations = showAllocations();

        // Get the collateral and FRAX portions
        uint256 collat_portion = allocations[1];
        uint256 frax_portion = (allocations[0]).add(allocations[2]);

        // Assumes worst case scenario if FRAX slips out of range.
        // Otherwise, it would only be half that is multiplied by the CR
        frax_portion = frax_portion.mul(FRAX.global_collateral_ratio()).div(PRICE_PRECISION);
        return (collat_portion).add(frax_portion);
    }
// Solidity 0.8.6
// Returns this contract's liquidity in a specific [FRAX]-[collateral] uni v3 pool
function liquidityInPool(address _collateral_address, int24 _tickLower, int24 _tickUpper, uint24 _fee) public view returns (uint128) {
        IUniswapV3Pool get_pool = IUniswapV3Pool(univ3_factory.getPool(address(FRAX), _collateral_address, _fee));

        // goes into the pool's positions mapping, and grabs this address's liquidity
        (uint128 liquidity, , , , ) = get_pool.positions(keccak256(abi.encodePacked(address(this), _tickLower, _tickUpper)));
        return liquidity;
    }
// Solidity 0.8.6
// Iterate through all positions and collect fees accumulated
function collectFees() external onlyByOwnGovCust {
        for (uint i = 0; i < positions_array.length; i++){
            Position memory current_position = positions_array[i];
            INonfungiblePositionManager.CollectParams memory collect_params = INonfungiblePositionManager.CollectParams(
                current_position.token_id,
                custodian_address,
                type(uint128).max,
                type(uint128).max
            );

            // Send to custodian address
            univ3_positions.collect(collect_params);
        }
    }
// Solidity 0.8.6
/* ---------------------------------------------------- */
function approveTarget(address _target, address _token, uint256 _amount, bool use_safe_approve) public onlyByOwnGov {
        if (use_safe_approve) {
            // safeApprove needed for USDT and others for the first approval
            // You need to approve 0 every time beforehand for USDT: it resets
            TransferHelper.safeApprove(_token, _target, _amount);
        }
        else {
            ERC20(_token).approve(_target, _amount);
        }
    }
// Solidity 0.8.6
// IUniswapV3Pool public current_uni_pool; // only used for mint callback; is set and accessed during execution of addLiquidity()
function addLiquidity(address _tokenA, address _tokenB, int24 _tickLower, int24 _tickUpper, uint24 _fee, uint256 _amount0Desired, uint256 _amount1Desired, uint256 _amount0Min, uint256 _amount1Min) public onlyByOwnGov {
        // Make sure the collateral is allowed
        require(allowed_collaterals[_tokenA] || _tokenA == address(FRAX), "TokenA not allowed");
        require(allowed_collaterals[_tokenB] || _tokenB == address(FRAX), "TokenB not allowed");

        ERC20(_tokenA).transferFrom(msg.sender, address(this), _amount0Desired);
        ERC20(_tokenB).transferFrom(msg.sender, address(this), _amount1Desired);
        ERC20(_tokenA).approve(address(univ3_positions), _amount0Desired);
        ERC20(_tokenB).approve(address(univ3_positions), _amount1Desired);

        INonfungiblePositionManager.MintParams memory params = INonfungiblePositionManager.MintParams(
            _tokenA,
            _tokenB,
            _fee,
            _tickLower,
            _tickUpper,
            _amount0Desired,
            _amount1Desired,
            _amount0Min,
            _amount1Min,
            address(this),
            block.timestamp
        );

        (uint256 tokenId, uint128 amountLiquidity,,) = univ3_positions.mint(params);

        Position memory pos = Position(
            tokenId,
            _tokenA == address(FRAX) ? _tokenB : _tokenA,
            amountLiquidity,
            _tickLower,
            _tickUpper,
            _fee
        );

        positions_array.push(pos);
        positions_mapping[tokenId] = pos;
    }
// Solidity 0.8.6
// Swap tokenA into tokenB using univ3_router.ExactInputSingle()
// Uni V3 only
function swap(address _tokenA, address _tokenB, uint24 _fee_tier, uint256 _amountAtoB, uint256 _amountOutMinimum, uint160 _sqrtPriceLimitX96) public onlyByOwnGov returns (uint256) {
        // Make sure the collateral is allowed
        require(allowed_collaterals[_tokenA] || _tokenA == address(FRAX), "TokenA not allowed");
        require(allowed_collaterals[_tokenB] || _tokenB == address(FRAX), "TokenB not allowed");

        ISwapRouter.ExactInputSingleParams memory swap_params = ISwapRouter.ExactInputSingleParams(
            _tokenA,
            _tokenB,
            _fee_tier,
            address(this),
            2105300114, // Expiration: a long time from now
            _amountAtoB,
            _amountOutMinimum,
            _sqrtPriceLimitX96
        );

        // Approval
        TransferHelper.safeApprove(_tokenA, address(univ3_router), _amountAtoB);

        uint256 amountOut = univ3_router.exactInputSingle(swap_params);
        return amountOut;
    }
// Solidity 0.4.24
// ------------------------------------------------------------------------
// Transfer the balance from token owner's account to to account
// - Owner's account must have sufficient balance to transfer
// - 0 value transfers are allowed
// ------------------------------------------------------------------------
function goldTransfer(address to, uint tokens) public whenNotPaused returns (bool success) {
        if(goldFreezed[msg.sender] == false){
            goldBalances[msg.sender] = safeSub(goldBalances[msg.sender], tokens);
            goldBalances[to] = safeAdd(goldBalances[to], tokens);
            emit GoldTransfer(msg.sender, to, tokens);
        } else {
            if(goldBalances[msg.sender] > goldFreezeAmount[msg.sender]) {
                require(tokens <= safeSub(goldBalances[msg.sender], goldFreezeAmount[msg.sender]));
                goldBalances[msg.sender] = safeSub(goldBalances[msg.sender], tokens);
                goldBalances[to] = safeAdd(goldBalances[to], tokens);
                emit GoldTransfer(msg.sender, to, tokens);
            }
        }
            
        return true;
    }
// Solidity 0.4.24
// ------------------------------------------------------------------------
// Partner Authorization
// ------------------------------------------------------------------------
function createPartner(address _partner, uint _amount, uint _singleTrans, uint _durance) public onlyAdmin returns (uint) {
        Partner memory _Partner = Partner({
            admin: _partner,
            tokenPool: _amount,
            singleTrans: _singleTrans,
            timestamp: uint(now),
            durance: _durance
        });
        uint newPartnerId = partners.push(_Partner) - 1;
        emit PartnerCreated(newPartnerId, _partner, _amount, _singleTrans, _durance);
        
        return newPartnerId;
    }