lohoz/Smart-Contract-MultiTask-Dataset huggingface dataset:
// Solidity 0.6.12
/// @dev Helper to execute a multiSwap() order
function __paraSwapV4MultiSwap(
        address _fromToken,
        uint256 _fromAmount,
        uint256 _toAmount,
        uint256 _expectedAmount,
        address payable _beneficiary,
        IParaSwapV4AugustusSwapper.Path[] memory _path
    ) internal {
        __approveAssetMaxAsNeeded(_fromToken, PARA_SWAP_V4_TOKEN_TRANSFER_PROXY, _fromAmount);

        IParaSwapV4AugustusSwapper.SellData memory sellData = IParaSwapV4AugustusSwapper.SellData({
            fromToken: _fromToken,
            fromAmount: _fromAmount,
            toAmount: _toAmount,
            expectedAmount: _expectedAmount,
            beneficiary: _beneficiary,
            referrer: REFERRER,
            useReduxToken: false,
            path: _path
        });

        IParaSwapV4AugustusSwapper(PARA_SWAP_V4_AUGUSTUS_SWAPPER).multiSwap(sellData);
    }
// Solidity 0.6.12
/// @notice Parses the expected assets to receive from a call on integration
/// @param _selector The function selector for the callOnIntegration
/// @param _encodedCallArgs The encoded parameters for the callOnIntegration
/// @return spendAssetsHandleType_ A type that dictates how to handle granting
/// the adapter access to spend assets (`None` by default)
/// @return spendAssets_ The assets to spend in the call
/// @return spendAssetAmounts_ The max asset amounts to spend in the call
/// @return incomingAssets_ The assets to receive in the call
/// @return minIncomingAssetAmounts_ The min asset amounts to receive in the call
function parseAssetsForMethod(bytes4 _selector, bytes calldata _encodedCallArgs)
        external
        view
        override
        returns (
            IIntegrationManager.SpendAssetsHandleType spendAssetsHandleType_,
            address[] memory spendAssets_,
            uint256[] memory spendAssetAmounts_,
            address[] memory incomingAssets_,
            uint256[] memory minIncomingAssetAmounts_
        )
    {
        require(_selector == TAKE_ORDER_SELECTOR, "parseAssetsForMethod: _selector invalid");

        (
            uint256 minIncomingAssetAmount,
            ,
            address outgoingAsset,
            uint256 outgoingAssetAmount,
            IParaSwapV4AugustusSwapper.Path[] memory paths
        ) = __decodeCallArgs(_encodedCallArgs);

        spendAssets_ = new address[](1);
        spendAssets_[0] = outgoingAsset;

        spendAssetAmounts_ = new uint256[](1);
        spendAssetAmounts_[0] = outgoingAssetAmount;

        incomingAssets_ = new address[](1);
        incomingAssets_[0] = paths[paths.length - 1].to;

        minIncomingAssetAmounts_ = new uint256[](1);
        minIncomingAssetAmounts_[0] = minIncomingAssetAmount;

        return (
            IIntegrationManager.SpendAssetsHandleType.Transfer,
            spendAssets_,
            spendAssetAmounts_,
            incomingAssets_,
            minIncomingAssetAmounts_
        );
    }
// Solidity 0.6.12
/// @notice Trades assets on ParaSwap
/// @param _vaultProxy The VaultProxy of the calling fund
/// @param _encodedCallArgs Encoded order parameters
/// @dev ParaSwap v4 completely uses entire outgoing asset balance and incoming asset
/// is sent directly to the beneficiary (the _vaultProxy)
function takeOrder(
        address _vaultProxy,
        bytes calldata _encodedCallArgs,
        bytes calldata
    ) external onlyIntegrationManager {
        (
            uint256 minIncomingAssetAmount,
            uint256 expectedIncomingAssetAmount,
            address outgoingAsset,
            uint256 outgoingAssetAmount,
            IParaSwapV4AugustusSwapper.Path[] memory paths
        ) = __decodeCallArgs(_encodedCallArgs);

        __paraSwapV4MultiSwap(
            outgoingAsset,
            outgoingAssetAmount,
            minIncomingAssetAmount,
            expectedIncomingAssetAmount,
            payable(_vaultProxy),
            paths
        );
    }
// Solidity 0.6.12
/// @dev Helper to decode the encoded callOnIntegration call arguments
function __decodeCallArgs(bytes memory _encodedCallArgs)
        private
        pure
        returns (
            uint256 minIncomingAssetAmount_,
            uint256 expectedIncomingAssetAmount_, // Passed as a courtesy to ParaSwap for analytics
            address outgoingAsset_,
            uint256 outgoingAssetAmount_,
            IParaSwapV4AugustusSwapper.Path[] memory paths_
        )
    {
        return
            abi.decode(
                _encodedCallArgs,
                (uint256, uint256, address, uint256, IParaSwapV4AugustusSwapper.Path[])
            );
    }
// Solidity 0.6.12
// Assumes that if _redeemSingleAsset is true, then
// "_minIncomingWethAmount > 0 XOR _minIncomingStethAmount > 0" has already been validated.
function __curveStethRedeem(
        uint256 _outgoingLPTokenAmount,
        uint256 _minIncomingWethAmount,
        uint256 _minIncomingStethAmount,
        bool _redeemSingleAsset
    ) internal {
        if (_redeemSingleAsset) {
            if (_minIncomingWethAmount > 0) {
                ICurveStableSwapSteth(CURVE_STETH_LIQUIDITY_POOL).remove_liquidity_one_coin(
                    _outgoingLPTokenAmount,
                    CURVE_STETH_POOL_INDEX_ETH,
                    _minIncomingWethAmount
                );

                IWETH(payable(CURVE_STETH_LIQUIDITY_WETH_TOKEN)).deposit{
                    value: payable(address(this)).balance
                }();
            } else {
                ICurveStableSwapSteth(CURVE_STETH_LIQUIDITY_POOL).remove_liquidity_one_coin(
                    _outgoingLPTokenAmount,
                    CURVE_STETH_POOL_INDEX_STETH,
                    _minIncomingStethAmount
                );
            }
        } else {
            ICurveStableSwapSteth(CURVE_STETH_LIQUIDITY_POOL).remove_liquidity(
                _outgoingLPTokenAmount,
                [_minIncomingWethAmount, _minIncomingStethAmount]
            );

            IWETH(payable(CURVE_STETH_LIQUIDITY_WETH_TOKEN)).deposit{
                value: payable(address(this)).balance
            }();
        }
    }
// Solidity 0.6.12
/// @dev Helper to get the balances of specified assets for a target
function __getAssetBalances(address _target, address[] memory _assets)
        internal
        view
        returns (uint256[] memory balances_)
    {
        balances_ = new uint256[](_assets.length);
        for (uint256 i; i < _assets.length; i++) {
            balances_[i] = ERC20(_assets[i]).balanceOf(_target);
        }

        return balances_;
    }
// Solidity 0.6.12
/// @dev Helper to transfer full asset balances from a target to the current contract.
/// Requires an adequate allowance for each asset granted to the current contract for the target.
function __pullFullAssetBalances(address _target, address[] memory _assets)
        internal
        returns (uint256[] memory amountsTransferred_)
    {
        amountsTransferred_ = new uint256[](_assets.length);
        for (uint256 i; i < _assets.length; i++) {
            ERC20 assetContract = ERC20(_assets[i]);
            amountsTransferred_[i] = assetContract.balanceOf(_target);
            if (amountsTransferred_[i] > 0) {
                assetContract.safeTransferFrom(_target, address(this), amountsTransferred_[i]);
            }
        }

        return amountsTransferred_;
    }
// Solidity 0.6.12
/// @dev Helper to transfer full asset balances from the current contract to a target
function __pushFullAssetBalances(address _target, address[] memory _assets)
        internal
        returns (uint256[] memory amountsTransferred_)
    {
        amountsTransferred_ = new uint256[](_assets.length);
        for (uint256 i; i < _assets.length; i++) {
            ERC20 assetContract = ERC20(_assets[i]);
            amountsTransferred_[i] = assetContract.balanceOf(address(this));
            if (amountsTransferred_[i] > 0) {
                assetContract.safeTransfer(_target, amountsTransferred_[i]);
            }
        }

        return amountsTransferred_;
    }
// Solidity 0.6.12
/// @dev Helper to claim all rewards, then pull only the newly claimed balances
/// of all rewards tokens into the current contract
function __curveGaugeV2ClaimRewardsAndPullClaimedBalances(address _gauge, address _target)
        internal
        returns (address[] memory rewardsTokens_, uint256[] memory rewardsTokenAmountsPulled_)
    {
        rewardsTokens_ = __curveGaugeV2GetRewardsTokensWithCrv(_gauge);

        uint256[] memory rewardsTokenPreClaimBalances = new uint256[](rewardsTokens_.length);
        for (uint256 i; i < rewardsTokens_.length; i++) {
            rewardsTokenPreClaimBalances[i] = ERC20(rewardsTokens_[i]).balanceOf(_target);
        }

        __curveGaugeV2ClaimAllRewards(_gauge, _target);

        rewardsTokenAmountsPulled_ = __pullPartialAssetBalances(
            _target,
            rewardsTokens_,
            rewardsTokenPreClaimBalances
        );

        return (rewardsTokens_, rewardsTokenAmountsPulled_);
    }
// Solidity 0.6.12
/// @dev Helper to get list of pool-specific rewards tokens
function __curveGaugeV2GetRewardsTokens(address _gauge)
        internal
        view
        returns (address[] memory rewardsTokens_)
    {
        address[] memory lpRewardsTokensWithEmpties = new address[](CURVE_GAUGE_V2_MAX_REWARDS);
        uint256 rewardsTokensCount;
        for (uint256 i; i < CURVE_GAUGE_V2_MAX_REWARDS; i++) {
            address rewardToken = ICurveLiquidityGaugeV2(_gauge).reward_tokens(i);
            if (rewardToken != address(0)) {
                lpRewardsTokensWithEmpties[i] = rewardToken;
                rewardsTokensCount++;
            } else {
                break;
            }
        }

        rewardsTokens_ = new address[](rewardsTokensCount);
        for (uint256 i; i < rewardsTokensCount; i++) {
            rewardsTokens_[i] = lpRewardsTokensWithEmpties[i];
        }

        return rewardsTokens_;
    }
// Solidity 0.8.6
// ============ Edition Methods ============
function createEditions(
        EditionTier[] memory tiers,
        // The account that should receive the revenue.
        address payable fundingRecipient,
        // The address (e.g. crowdfund proxy) that is allowed to mint
        // tokens in this edition.
        address minter
    ) external override {
        // Only the crowdfund factory can create editions.
        require(msg.sender == editionCreator);
        // Copy the next edition id, which we reference in the loop.
        uint256 firstEditionId = nextEditionId;
        // Update the next edition id to what we expect after the loop.
        nextEditionId += tiers.length;
        // Execute a loop that created editions.
        for (uint8 x = 0; x < tiers.length; x++) {
            uint256 id = firstEditionId + x;
            uint256 quantity = tiers[x].quantity;
            uint256 price = tiers[x].price;
            bytes32 contentHash = tiers[x].contentHash;

            editions[id] = Edition({
                quantity: quantity,
                price: price,
                fundingRecipient: fundingRecipient,
                numSold: 0,
                contentHash: contentHash
            });

            editionToMinter[id] = minter;

            emit EditionCreated(quantity, price, fundingRecipient, id);
        }
    }
// Solidity 0.8.6
// ============ NFT Methods ============
// Returns e.g. https://mirror-api.com/editions/[editionId]/[tokenId]
function tokenURI(uint256 tokenId)
        public
        view
        override
        returns (string memory)
    {
        // If the token does not map to an edition, it'll be 0.
        require(tokenToEdition[tokenId] > 0, "Token has not been sold yet");
        // Concatenate the components, baseURI, editionId and tokenId, to create URI.
        return
            string(
                abi.encodePacked(
                    baseURI,
                    _toString(tokenToEdition[tokenId]),
                    "/",
                    _toString(tokenId)
                )
            );
    }
// Solidity 0.8.6
// The hash of the given content for the NFT. Can be used
// for IPFS storage, verifying authenticity, etc.
function getContentHash(uint256 tokenId) public view returns (bytes32) {
        // If the token does not map to an edition, it'll be 0.
        require(tokenToEdition[tokenId] > 0, "Token has not been sold yet");
        // Concatenate the components, baseURI, editionId and tokenId, to create URI.
        return editions[tokenToEdition[tokenId]].contentHash;
    }
// Solidity 0.8.6
// ============ Private Methods ============
// From https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol
function _toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }
// Solidity 0.6.12
/// @dev Helper to remove liquidity from the pool.
/// if using _redeemSingleAsset, must pre-validate that one - and only one - asset
/// has a non-zero _orderedMinIncomingAssetAmounts value.
/// _orderedOutgoingAssetAmounts = [aDAI, aUSDC, aUSDT].
function __curveAaveRedeem(
        uint256 _outgoingLPTokenAmount,
        uint256[3] memory _orderedMinIncomingAssetAmounts,
        bool _redeemSingleAsset,
        bool _useUnderlyings
    ) internal {
        if (_redeemSingleAsset) {
            // Assume that one - and only one - asset has a non-zero min incoming asset amount
            for (uint256 i; i < _orderedMinIncomingAssetAmounts.length; i++) {
                if (_orderedMinIncomingAssetAmounts[i] > 0) {
                    ICurveStableSwapAave(CURVE_AAVE_LIQUIDITY_POOL).remove_liquidity_one_coin(
                        _outgoingLPTokenAmount,
                        int128(i),
                        _orderedMinIncomingAssetAmounts[i],
                        _useUnderlyings
                    );
                    return;
                }
            }
        } else {
            ICurveStableSwapAave(CURVE_AAVE_LIQUIDITY_POOL).remove_liquidity(
                _outgoingLPTokenAmount,
                _orderedMinIncomingAssetAmounts,
                _useUnderlyings
            );
        }
    }
// Solidity 0.4.24
/*
 ERC 20 compatible functions
 */
function transferFrom (address _from, address _to, uint256 _value) public returns (bool success) {
        if (allowances [_from][msg.sender] < _value) return false;
        if (balances [_from] < _value) return false;

        allowances [_from][msg.sender] = allowances [_from][msg.sender].sub(_value);

        if (_value > 0 && _from != _to) {
            balances [_from] = balances [_from].sub(_value);
            balances [_to] = balances [_to].add(_value);
            emit Transfer (_from, _to, _value);
        }

        return true;
    }
// Solidity 0.6.12
/// @notice Claims rewards and then compounds the rewards tokens back into the idleToken
/// @param _vaultProxy The VaultProxy of the calling fund
/// @param _encodedCallArgs Encoded order parameters
/// @param _encodedAssetTransferArgs Encoded args for expected assets to spend and receive
/// @dev The `useFullBalances` option indicates whether to use only the newly claimed balances of
/// rewards tokens, or whether to use the full balances of these assets in the vault.
/// If full asset balances are to be used, then this requires the adapter to be granted
/// an allowance of each reward token by the vault.
/// For supported assets (e.g., COMP), this must be done via the `approveAssets()` function in this adapter.
/// For unsupported assets (e.g., IDLE), this must be done via `ComptrollerProxy.vaultCallOnContract()`, if allowed.
function claimRewardsAndReinvest(
        address _vaultProxy,
        bytes calldata _encodedCallArgs,
        bytes calldata _encodedAssetTransferArgs
    )
        external
        onlyIntegrationManager
        // The idleToken is both the spend asset and the incoming asset in this case
        postActionSpendAssetsTransferHandler(_vaultProxy, _encodedAssetTransferArgs)
    {
        (, address idleToken, , bool useFullBalances) = __decodeClaimRewardsAndReinvestCallArgs(
            _encodedCallArgs
        );

        address underlying = __getUnderlyingForIdleToken(idleToken);
        require(underlying != address(0), "claimRewardsAndReinvest: Unsupported idleToken");

        (
            address[] memory rewardsTokens,
            uint256[] memory rewardsTokenAmountsToUse
        ) = __claimRewardsAndPullRewardsTokens(_vaultProxy, idleToken, useFullBalances);

        // Swap all reward tokens to the idleToken's underlying via UniswapV2,
        // using WETH as the intermediary where necessary
        __uniswapV2SwapManyToOne(
            address(this),
            rewardsTokens,
            rewardsTokenAmountsToUse,
            underlying,
            WETH_TOKEN
        );

        // Lend all received underlying asset for the idleToken
        uint256 underlyingBalance = ERC20(underlying).balanceOf(address(this));
        if (underlyingBalance > 0) {
            __idleV4Lend(idleToken, underlying, underlyingBalance);
        }
    }
// Solidity 0.6.12
/// @notice Claims rewards and then swaps the rewards tokens to the specified asset via UniswapV2
/// @param _vaultProxy The VaultProxy of the calling fund
/// @param _encodedCallArgs Encoded order parameters
/// @param _encodedAssetTransferArgs Encoded args for expected assets to spend and receive
/// @dev The `useFullBalances` option indicates whether to use only the newly claimed balances of
/// rewards tokens, or whether to use the full balances of these assets in the vault.
/// If full asset balances are to be used, then this requires the adapter to be granted
/// an allowance of each reward token by the vault.
/// For supported assets (e.g., COMP), this must be done via the `approveAssets()` function in this adapter.
/// For unsupported assets (e.g., IDLE), this must be done via `ComptrollerProxy.vaultCallOnContract()`, if allowed.
function claimRewardsAndSwap(
        address _vaultProxy,
        bytes calldata _encodedCallArgs,
        bytes calldata _encodedAssetTransferArgs
    )
        external
        onlyIntegrationManager
        postActionSpendAssetsTransferHandler(_vaultProxy, _encodedAssetTransferArgs)
    {
        (
            ,
            address idleToken,
            address incomingAsset,
            ,
            bool useFullBalances
        ) = __decodeClaimRewardsAndSwapCallArgs(_encodedCallArgs);

        (
            address[] memory rewardsTokens,
            uint256[] memory rewardsTokenAmountsToUse
        ) = __claimRewardsAndPullRewardsTokens(_vaultProxy, idleToken, useFullBalances);

        // Swap all reward tokens to the designated incomingAsset via UniswapV2,
        // using WETH as the intermediary where necessary
        __uniswapV2SwapManyToOne(
            _vaultProxy,
            rewardsTokens,
            rewardsTokenAmountsToUse,
            incomingAsset,
            WETH_TOKEN
        );
    }
// Solidity 0.6.12
/// @notice Lends an amount of a token for idleToken
/// @param _vaultProxy The VaultProxy of the calling fund
/// @param _encodedAssetTransferArgs Encoded args for expected assets to spend and receive
function lend(
        address _vaultProxy,
        bytes calldata,
        bytes calldata _encodedAssetTransferArgs
    )
        external
        onlyIntegrationManager
        postActionIncomingAssetsTransferHandler(_vaultProxy, _encodedAssetTransferArgs)
    {
        // More efficient to parse all from _encodedAssetTransferArgs
        (
            ,
            address[] memory spendAssets,
            uint256[] memory spendAssetAmounts,
            address[] memory incomingAssets
        ) = __decodeEncodedAssetTransferArgs(_encodedAssetTransferArgs);

        __idleV4Lend(incomingAssets[0], spendAssets[0], spendAssetAmounts[0]);
    }
// Solidity 0.6.12
/// @dev Helper to claim rewards and pull rewards tokens from the vault
/// to the current contract, as needed
function __claimRewardsAndPullRewardsTokens(
        address _vaultProxy,
        address _idleToken,
        bool _useFullBalances
    )
        private
        returns (address[] memory rewardsTokens_, uint256[] memory rewardsTokenAmountsToUse_)
    {
        __idleV4ClaimRewards(_idleToken);

        rewardsTokens_ = __idleV4GetRewardsTokens(_idleToken);
        if (_useFullBalances) {
            __pullFullAssetBalances(_vaultProxy, rewardsTokens_);
        }

        return (rewardsTokens_, __getAssetBalances(address(this), rewardsTokens_));
    }
// Solidity 0.6.12
/// @dev Helper function to parse spend and incoming assets from encoded call args
/// during approveAssets() calls
function __parseAssetsForApproveAssets(bytes calldata _encodedCallArgs)
        private
        view
        returns (
            IIntegrationManager.SpendAssetsHandleType spendAssetsHandleType_,
            address[] memory spendAssets_,
            uint256[] memory spendAssetAmounts_,
            address[] memory incomingAssets_,
            uint256[] memory minIncomingAssetAmounts_
        )
    {
        address idleToken;
        (idleToken, spendAssets_, spendAssetAmounts_) = __decodeApproveAssetsCallArgs(
            _encodedCallArgs
        );
        require(
            __getUnderlyingForIdleToken(idleToken) != address(0),
            "__parseAssetsForApproveAssets: Unsupported idleToken"
        );
        require(
            spendAssets_.length == spendAssetAmounts_.length,
            "__parseAssetsForApproveAssets: Unequal arrays"
        );

        // Validate that only rewards tokens are given allowances
        address[] memory rewardsTokens = __idleV4GetRewardsTokens(idleToken);
        for (uint256 i; i < spendAssets_.length; i++) {
            // Allow revoking approval for any asset
            if (spendAssetAmounts_[i] > 0) {
                require(
                    rewardsTokens.contains(spendAssets_[i]),
                    "__parseAssetsForApproveAssets: Invalid reward token"
                );
            }
        }

        return (
            IIntegrationManager.SpendAssetsHandleType.Approve,
            spendAssets_,
            spendAssetAmounts_,
            new address[](0),
            new uint256[](0)
        );
    }
// Solidity 0.6.12
/// @dev Helper function to parse spend and incoming assets from encoded call args
/// during claimRewards() calls
function __parseAssetsForClaimRewards(bytes calldata _encodedCallArgs)
        private
        view
        returns (
            IIntegrationManager.SpendAssetsHandleType spendAssetsHandleType_,
            address[] memory spendAssets_,
            uint256[] memory spendAssetAmounts_,
            address[] memory incomingAssets_,
            uint256[] memory minIncomingAssetAmounts_
        )
    {
        (address vaultProxy, address idleToken) = __decodeClaimRewardsCallArgs(_encodedCallArgs);

        require(
            __getUnderlyingForIdleToken(idleToken) != address(0),
            "__parseAssetsForClaimRewards: Unsupported idleToken"
        );

        (spendAssets_, spendAssetAmounts_) = __parseSpendAssetsForClaimRewardsCalls(
            vaultProxy,
            idleToken
        );

        return (
            IIntegrationManager.SpendAssetsHandleType.Transfer,
            spendAssets_,
            spendAssetAmounts_,
            new address[](0),
            new uint256[](0)
        );
    }