{
    "Function": "swap",
    "File": "contracts/adapters/vaults/YEarnV2Adapter.sol",
    "Parent Contracts": [
        "contracts/adapters/BaseAdapter.sol",
        "contracts/interfaces/IBaseAdapter.sol"
    ],
    "High-Level Calls": [
        "SafeERC20",
        "IYEarnV2Vault",
        "SafeERC20",
        "IYEarnV2Vault",
        "IYEarnV2Vault",
        "IYEarnV2Vault",
        "SafeERC20"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "_checkVault",
        "require(bool,string)"
    ],
    "Library Calls": [
        "safeTransfer",
        "safeTransferFrom",
        "safeApprove"
    ],
    "Low-Level Calls": [],
    "Code": "function swap(\n        uint256 amount,\n        uint256 expected,\n        address tokenIn,\n        address tokenOut,\n        address from,\n        address to\n    ) public override {\n        require(tokenIn != tokenOut, \"Tokens cannot match\");\n\n        if (from != address(this))\n            IERC20(tokenIn).safeTransferFrom(from, address(this), amount);\n        uint256 received;\n        if (_checkVault(tokenOut)) {\n            IYEarnV2Vault vault = IYEarnV2Vault(tokenOut);\n            require(address(vault.token()) == tokenIn, \"Incompatible\");\n            IERC20(tokenIn).safeApprove(tokenOut, amount);\n            received = vault.deposit(amount, address(this));\n        } else {\n            IYEarnV2Vault vault = IYEarnV2Vault(tokenIn);\n            require(address(vault.token()) == tokenOut, \"Incompatible\");\n            received = vault.withdraw(amount, address(this), 1); // Default maxLoss is 1\n        }\n\n        require(received >= expected, \"Insufficient tokenOut amount\");\n\n        if (to != address(this))\n            IERC20(tokenOut).safeTransfer(to, received);\n    }"
}