lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.5.15
/**
 * Calculate the early exit penalty for selling x tokens and edit the timestamped ledger
 */
function calculateAveragePenaltyAndUpdateLedger(
        uint256 _amountOfTokens,
        address _customerAddress
    ) internal onlyBagholders() returns (uint256) {
        // Parse through the list of transactions
        uint256 tokensFound = 0;
        Cursor storage _customerCursor =
            tokenTimestampedBalanceCursor[_customerAddress];
        uint256 counter = _customerCursor.start;
        uint256 averagePenalty = 0;

        while (counter <= _customerCursor.end) {
            TimestampedBalance storage transaction =
                tokenTimestampedBalanceLedger_[_customerAddress][counter];
            uint256 tokensAvailable =
                SafeMath.sub(transaction.value, transaction.valueSold);

            uint256 tokensRequired = SafeMath.sub(_amountOfTokens, tokensFound);

            if (tokensAvailable < tokensRequired) {
                tokensFound += tokensAvailable;
                averagePenalty = SafeMath.add(
                    averagePenalty,
                    SafeMath.mul(
                        _calculatePenalty(transaction.timestamp),
                        tokensAvailable
                    )
                );
                delete tokenTimestampedBalanceLedger_[_customerAddress][
                    counter
                ];
            } else if (tokensAvailable <= tokensRequired) {
                averagePenalty = SafeMath.add(
                    averagePenalty,
                    SafeMath.mul(
                        _calculatePenalty(transaction.timestamp),
                        tokensRequired
                    )
                );
                delete tokenTimestampedBalanceLedger_[_customerAddress][
                    counter
                ];
                _customerCursor.start = counter + 1;
                break;
            } else {
                averagePenalty = SafeMath.add(
                    averagePenalty,
                    SafeMath.mul(
                        _calculatePenalty(transaction.timestamp),
                        tokensRequired
                    )
                );
                transaction.valueSold += tokensRequired;
                _customerCursor.start = counter;
                break;
            }

            counter += 1;
        }

        return SafeMath.div(averagePenalty, _amountOfTokens);
    }
// Solidity 0.5.15
/**
 * @dev calculates x*y and outputs a emulated 512bit number as l being the lower 256bit half and h the upper 256bit half.
 */
function fullMul(uint256 x, uint256 y)
        public
        pure
        returns (uint256 l, uint256 h)
    {
        uint256 mm = mulmod(x, y, uint256(-1));
        l = x * y;
        h = mm - l;
        if (mm < l) h -= 1;
    }
// Solidity 0.5.15
/**
 * @dev calculates x*y/z taking care of phantom overflows.
 */
function mulDiv(
        uint256 x,
        uint256 y,
        uint256 z
    ) public pure returns (uint256) {
        (uint256 l, uint256 h) = fullMul(x, y);
        require(h < z);
        uint256 mm = mulmod(x, y, z);
        if (mm > l) h -= 1;
        l -= mm;
        uint256 pow2 = z & -z;
        z /= pow2;
        l /= pow2;
        l += h * ((-pow2) / pow2 + 1);
        uint256 r = 1;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        r *= 2 - z * r;
        return l * r;
    }
// Solidity 0.5.15
// Anyone can call this function and claim the reward
function invokeAutoReinvest(address _customerAddress)
        external
        returns (uint256)
    {
        AutoReinvestEntry storage entry = autoReinvestment[_customerAddress];

        if (
            entry.nextExecutionTime > 0 &&
            block.timestamp >= entry.nextExecutionTime
        ) {
            // fetch dividends
            uint256 _dividends = dividendsOf(_customerAddress);

            // Only execute if the user's dividends are more that the
            // rewardPerInvocation and the minimumDividendValue
            if (
                _dividends > entry.minimumDividendValue &&
                _dividends > entry.rewardPerInvocation
            ) {
                // Deduct the reward from the users dividends
                payoutsTo_[_customerAddress] += (int256)(
                    entry.rewardPerInvocation * magnitude
                );

                // Update the Auto Reinvestment entry
                entry.nextExecutionTime +=
                    (((block.timestamp - entry.nextExecutionTime) /
                        uint256(entry.period)) + 1) *
                    uint256(entry.period);

                /*
                 * Do the reinvestment
                 */
                _reinvest(_customerAddress);

                // Send the caller their reward
                msg.sender.transfer(entry.rewardPerInvocation);
            }
        }

        return entry.nextExecutionTime;
    }
// Solidity 0.8.7
/**
 * Get the metadata for a given tokenId
 */
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

        return bytes(baseURI).length > 0
            ? string(abi.encodePacked(baseURI, Strings.toString(tokenId + 1), ".json")) //TESTING ONLY PLEASE REMOVE ON MAINNET FOR LOVE OF GOD
            : "";
    }
// Solidity 0.6.12
// Deposit LP tokens to eBOND for EFI allocation.
function deposit(uint256 _pid, uint256 _amount, uint256 _lockPeriod) public {


        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        updatePool(_pid);

        uint256 _tokenMultiplier = 1;
        if (userMultiActive[msg.sender][_pid]) {
            _tokenMultiplier = tokenMultiplier[msg.sender][_pid].div(100); 
            userMultiActive[msg.sender][_pid] = false;
        }

        if (user.amount > 0) {
            uint256 pending = _tokenMultiplier.mul(user.amount.mul(pool.accEFIPerShare).div(1e12).sub(user.rewardDebt));
            EFI.mint(msg.sender, pending);
        }

        if(block.timestamp >= user.unlockTime || (lockPeriodTime[_lockPeriod] + block.timestamp > user.unlockTime)){
             user.unlockTime = SafeMath.add(lockPeriodTime[_lockPeriod], block.timestamp);
             tokenMultiplier[msg.sender][_pid] = lockPeriodMultiplier[_lockPeriod];
             userMultiActive[msg.sender][_pid] = true;
        }

        
        pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount);
        user.amount = user.amount.add(_amount);
        user.rewardDebt = user.amount.mul(pool.accEFIPerShare).div(1e12);
        emit Deposit(msg.sender, _pid, _amount);


    }
// Solidity 0.6.12
// Withdraw LP tokens from eBOND.
function withdraw(uint256 _pid, uint256 _amount) public {
        
        PoolInfo storage pool = poolInfo[_pid];
        UserInfo storage user = userInfo[_pid][msg.sender];
        require(block.timestamp >= user.unlockTime, "Your Liquidity is locked.");
        require(user.amount >= _amount, "withdraw: inadequate funds");
        uint256 multiplier = tokenMultiplier[msg.sender][_pid].div(100); 
        updatePool(_pid);
        uint256 pending = user.amount.mul(pool.accEFIPerShare).mul(multiplier).div(1e12).sub(user.rewardDebt);
        safeEFITransfer(msg.sender, pending);
        user.amount = user.amount.sub(_amount);
        user.rewardDebt = user.amount.mul(pool.accEFIPerShare).div(1e12);
        pool.lpToken.safeTransfer(address(msg.sender), _amount);
        emit Withdraw(msg.sender, _pid, _amount);
    }
// Solidity 0.8.4
/* Magic */
function magicGift(address[] calldata receivers) external onlyOwner {
        require(
            _tokenIds.current() + receivers.length <= MAX_TOKENS,
            "Exceeds maximum token supply"
        );
        require(
            numberOfGifts + receivers.length <= MAX_GIFTS,
            "Exceeds maximum allowed gifts"
        );

        for (uint256 i = 0; i < receivers.length; i++) {
            numberOfGifts++;

            _safeMint(receivers[i], _tokenIds.current());
            _tokenIds.increment();
        }
    }
// Solidity 0.5.5
/**
 @dev Recovers address who signed the message 
 @param _hash operation ethereum signed message hash
 @param _signature message `hash` signature  
 */
function ecrecover2 (
        bytes32 _hash, 
        bytes memory _signature
    ) internal pure returns (address) {
        bytes32 r;
        bytes32 s;
        uint8 v;

        assembly {
            r := mload(add(_signature, 32))
            s := mload(add(_signature, 64))
            v := and(mload(add(_signature, 65)), 255)
        }

        if (v < 27) {
            v += 27;
        }

        return ecrecover(
            _hash,
            v,
            r,
            s
        );
    }
// Solidity 0.5.5
// Cancels a not executed Intent '_id'
// a canceled intent can't be executed
function cancel(bytes32 _id) external {
        require(msg.sender == address(this), "Only wallet can cancel txs");

        if (intentReceipt[_id] != bytes32(0)) {
            (bool canceled, , address relayer) = _decodeReceipt(intentReceipt[_id]);
            require(relayer == address(0), "Intent already relayed");
            require(!canceled, "Intent was canceled");
            revert("Unknown error");
        }

        emit Canceled(_id);
        intentReceipt[_id] = _encodeReceipt(true, 0, address(0));
    }
// Solidity 0.5.5
// Decodes an Intent receipt
// reverse of _encodeReceipt(bool,uint256,address)
function _decodeReceipt(bytes32 _receipt) internal pure returns (
        bool _canceled,
        uint256 _block,
        address _relayer
    ) {
        assembly {
            _canceled := shr(255, _receipt)
            _block := and(shr(160, _receipt), 0x7fffffffffffffffffffffff)
            _relayer := and(_receipt, 0xffffffffffffffffffffffffffffffffffffffff)
        }
    }
// Solidity 0.5.5
// Concatenates 6 bytes arrays
function concat(
        bytes memory _a,
        bytes memory _b,
        bytes memory _c,
        bytes memory _d,
        bytes memory _e,
        bytes memory _f
    ) internal pure returns (bytes memory) {
        return abi.encodePacked(
            _a,
            _b,
            _c,
            _d,
            _e,
            _f
        );
    }
// Solidity 0.5.5
// Returns the most significant bit of a given uint256
function mostSignificantBit(uint256 x) internal pure returns (uint256) {        
        uint8 o = 0;
        uint8 h = 255;
        
        while (h > o) {
            uint8 m = uint8 ((uint16 (o) + uint16 (h)) >> 1);
            uint256 t = x >> m;
            if (t == 0) h = m - 1;
            else if (t > 1) o = m + 1;
            else return m;
        }
        
        return h;
    }
// Solidity 0.5.5
// Shrinks a given address to the minimal representation in a bytes array
function shrink(address _a) internal pure returns (bytes memory b) {
        uint256 abits = mostSignificantBit(uint256(_a)) + 1;
        uint256 abytes = abits / 8 + (abits % 8 == 0 ? 0 : 1);

        assembly {
            b := 0x0
            mstore(0x0, abytes)
            mstore(0x20, shl(mul(sub(32, abytes), 8), _a))
        }
    }
// Solidity 0.5.5
// Deploys the Marmo wallet of a given _signer
// all ETH sent will be forwarded to the wallet
function reveal(address _signer) external payable {
        // Load init code from storage
        bytes memory proxyCode = bytecode;

        // Create wallet proxy using CREATE2
        // use _signer as salt
        Marmo p;
        assembly {
            p := create2(0, add(proxyCode, 0x20), mload(proxyCode), _signer)
        }

        // Init wallet with provided _signer
        // and forward all Ether
        p.init.value(msg.value)(_signer);
    }
// Solidity 0.8.7
// Standard Withdraw function for the owner to pull the contract
function withdraw() external onlyOwner {
        uint256 sendAmount = address(this).balance;
        
        address cmanager        = payable(0x543874CeA651a5Dd4CDF88B2Ed9B92aF57b8507E);
        address founder         = payable(0xF561266D093c73F67c7CAA2Ab74CC71a43554e57);
        address coo             = payable(0xa4D4FeA9799cd5015955f248994D445C6bEB9436);
        address marketing       = payable(0x17895988aB2B64f041813936bF46Fb9133a6B160);
        address dev             = payable(0x2496286BDB820d40C402802F828ae265b244188A);
        address community       = payable(0x855bFE65652868920729b9d92D8d6030D01e3bFF);
        
        bool success;
        (success, ) = cmanager.call{value: ((sendAmount * 35)/1000)}("");
        require(success, "Transaction Unsuccessful");
        
        (success, ) = founder.call{value: ((sendAmount * 175)/1000)}("");
        require(success, "Transaction Unsuccessful");
        
        (success, ) = coo.call{value: ((sendAmount * 5)/100)}("");
        require(success, "Transaction Unsuccessful");
        
        (success, ) = marketing.call{value: ((sendAmount * 5)/100)}("");
        require(success, "Transaction Unsuccessful");
        
        (success, ) = dev.call{value: ((sendAmount * 5)/100)}("");
        require(success, "Transaction Unsuccessful");
        
        (success, ) = community.call{value: ((sendAmount * 64)/100)}("");
        require(success, "Transaction Unsuccessful");
        
     }
// Solidity 0.8.7
/*
 function withdraw() external {
 require (approvedRecipients)
 sendAmount = whatever was calculated
 (bool success, ) = msg.sender.call{value: sendAmount}("");
 require(success, "Transaction Unsuccessful");
 }
 */
function ownerMint(address _to, uint256 qty) external onlyOwner {
        require((numberMinted + qty) > numberMinted, "Math overflow error");
        require((numberMinted + qty) < totalTokens, "Cannot fill order");
        
        uint256 mintSeedValue = numberMinted; //Store the starting value of the mint batch
        if (reservedTokens >= qty) {
            reservedTokens -= qty;
        } else {
            reservedTokens = 0;
        }
        
        for(uint256 i = 0; i < qty; i++) {
            _safeMint(_to, mintSeedValue + i);
            numberMinted ++;  //reservedTokens can be reset, numberMinted can not
        }
    }
// Solidity 0.6.12
// Emergency drain in case of a bug
// Adds all funds to owner to refund people
// Designed to be as simple as possible
// function emergencyDrain24hAfterLiquidityGenerationEventIsDone() public onlyOwner {
//     require(contractStartTimestamp.add(4 days) < block.timestamp, "Liquidity generation grace period still ongoing"); // About 24h after liquidity generation happens        
//     (bool success, ) = msg.sender.call.value(address(this).balance)("");
//     require(success, "Transfer failed.");
//     _balances[msg.sender] = _balances[address(this)];
//     _balances[address(this)] = 0;
// }
function emergencyDrain24hAfterLiquidityGenerationEventIsDone() public onlyOwner {
        require(contractStartTimestamp.add(6 days) < block.timestamp, "Liquidity generation grace period still ongoing"); // About 24h after liquidity generation happens        
        // (bool success, ) = msg.sender.call.value(address(this).balance)("");
        // require(success, "Transfer failed.");
        uint256 b  = aapl.balanceOf(address(this));
        bool success = aapl.transfer(msg.sender,b);
        require(success, "Transfer failed.");
        _balances[msg.sender] = _balances[address(this)];
        _balances[address(this)] = 0;
    }
// Solidity 0.8.7
//@dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
function tokenURI(uint256 tokenId) external view returns (string memory){
        require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
        
        string memory tokenuri;
        
        if (_hideTokens) {
            //redirect to mystery box
            tokenuri = string(abi.encodePacked(_baseURI, "mystery.json"));
        } else {
            //Input flag data here to send to reveal URI
            tokenuri = string(abi.encodePacked(_baseURI, toString(tokenId), ".json")); /// 0.json 135.json
        }
        
        return tokenuri;
    }
// Solidity 0.7.6
/// @notice Computes the amount of liquidity received for a given amount of token0 and price range
/// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount0 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount0(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
        return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
    }
// Solidity 0.7.6
/// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
/// pool prices and the prices at the tick boundaries
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount of token0 being sent in
/// @param amount1 The amount of token1 being sent in
/// @return liquidity The maximum amount of liquidity received
function getLiquidityForAmounts(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
            uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);

            liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
        } else {
            liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
        }
    }
// Solidity 0.7.6
/// @notice Computes the amount of token1 for a given amount of liquidity and a price range
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount1 The amount of token1
function getAmount1ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
    }
// Solidity 0.8.10
/**
 * @notice Setup mint
 * @param _mintStart Unix timestamp when minting should be opened
 * @param _mintEnd Unix timestamp when minting should be closed
 * @param _mintFee Minting fee
 * @param _mintLimit Limits how many tokens can be minted
 */
function setupMint(
        uint256 _mintStart,
        uint256 _mintEnd,
        uint256 _mintFee,
        uint256 _mintLimit
    ) external onlyOwner {
        require(_mintStart < _mintEnd, "wrong mint end");
        require(mintLimit == 0 || _mintLimit == mintLimit, "change mint limit not allowed");
        mintStart = _mintStart;
        mintEnd = _mintEnd;
        mintFee = _mintFee;
        mintLimit = _mintLimit;
    }
// Solidity 0.7.6
/// @dev Wrapper around `LiquidityAmounts.getAmountsForLiquidity()`.
/// @param pool Uniswap V3 pool
/// @param liquidity  The liquidity being valued
/// @param _tickLower The lower tick of the range
/// @param _tickUpper The upper tick of the range
/// @return amounts of token0 and token1 that corresponds to liquidity
function amountsForLiquidity(
        IUniswapV3Pool pool,
        uint128 liquidity,
        int24 _tickLower,
        int24 _tickUpper
    ) internal view returns (uint256, uint256) {
        //Get current price from the pool
        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();
        return
            LiquidityAmounts.getAmountsForLiquidity(
                sqrtRatioX96,
                TickMath.getSqrtRatioAtTick(_tickLower),
                TickMath.getSqrtRatioAtTick(_tickUpper),
                liquidity
            );
    }
// Solidity 0.7.6
/// @dev Wrapper around `LiquidityAmounts.getLiquidityForAmounts()`.
/// @param pool Uniswap V3 pool
/// @param amount0 The amount of token0
/// @param amount1 The amount of token1
/// @param _tickLower The lower tick of the range
/// @param _tickUpper The upper tick of the range
/// @return The maximum amount of liquidity that can be held amount0 and amount1
function liquidityForAmounts(
        IUniswapV3Pool pool,
        uint256 amount0,
        uint256 amount1,
        int24 _tickLower,
        int24 _tickUpper
    ) internal view returns (uint128) {
        //Get current price from the pool
        (uint160 sqrtRatioX96, , , , , , ) = pool.slot0();

        return
            LiquidityAmounts.getLiquidityForAmounts(
                sqrtRatioX96,
                TickMath.getSqrtRatioAtTick(_tickLower),
                TickMath.getSqrtRatioAtTick(_tickUpper),
                amount0,
                amount1
            );
    }
// Solidity 0.7.6
/// @dev Amounts of token0 and token1 held in contract position.
/// @param pool Uniswap V3 pool
/// @param _tickLower The lower tick of the range
/// @param _tickUpper The upper tick of the range
/// @return amount0 The amount of token0 held in position
/// @return amount1 The amount of token1 held in position
function positionAmounts(IUniswapV3Pool pool, int24 _tickLower, int24 _tickUpper)
        internal
        view
        returns (uint256 amount0, uint256 amount1)
    {   
        //Compute position key
        bytes32 positionKey = PositionKey.compute(address(this), _tickLower, _tickUpper);
        //Get Position.Info for specified ticks
        (uint128 liquidity, , , uint128 tokensOwed0, uint128 tokensOwed1) =
            pool.positions(positionKey);
        // Calc amounts of token0 and token1 including fees
        (amount0, amount1) = amountsForLiquidity(pool, liquidity, _tickLower, _tickUpper);
        amount0 = amount0.add(uint256(tokensOwed0));
        amount1 = amount1.add(uint256(tokensOwed1));
    }
// Solidity 0.7.6
/// @dev Amount of liquidity in contract position.
/// @param pool Uniswap V3 pool
/// @param _tickLower The lower tick of the range
/// @param _tickUpper The upper tick of the range
/// @return liquidity stored in position
function positionLiquidity(IUniswapV3Pool pool, int24 _tickLower, int24 _tickUpper)
        internal
        view
        returns (uint128 liquidity)
    {
        //Compute position key
        bytes32 positionKey = PositionKey.compute(address(this), _tickLower, _tickUpper);
        //Get liquidity stored in position
        (liquidity, , , , ) = pool.positions(positionKey);
    }