{
    "Function": "swap",
    "File": "contracts/adapters/liquidity/CurveLPAdapter.sol",
    "Parent Contracts": [
        "contracts/adapters/BaseAdapter.sol",
        "contracts/interfaces/IBaseAdapter.sol"
    ],
    "High-Level Calls": [
        "ICurveRegistry",
        "ICurveRegistry",
        "ICurveRegistry",
        "ICurveRegistry",
        "ICurveAddressProvider",
        "ICurveRegistry",
        "IERC20",
        "SafeERC20",
        "ICurveRegistry",
        "SafeERC20"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "require(bool,string)",
        "_withdraw",
        "_deposit",
        "_withdraw",
        "_deposit",
        "_withdraw",
        "revert()",
        "_deposit"
    ],
    "Library Calls": [
        "safeTransferFrom",
        "safeTransfer"
    ],
    "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        if (from != address(this))\n            IERC20(tokenIn).safeTransferFrom(from, address(this), amount);\n\n        ICurveRegistry curveRegistry = ICurveRegistry(addressProvider.get_registry());\n        address poolIn = curveRegistry.get_pool_from_lp_token(tokenIn);\n        address poolOut = curveRegistry.get_pool_from_lp_token(tokenOut);\n        if (poolIn == address(0) && poolOut != address(0)) {\n            _deposit(amount, tokenIn, poolOut, curveRegistry.get_coins(poolOut));\n        } else if (poolIn != address(0) && poolOut == address(0)) {\n            _withdraw(amount, tokenIn, tokenOut, poolIn, curveRegistry.get_coins(poolIn));\n        } else if (poolIn != address(0) && poolOut != address(0)) { //Metapool\n            bool isDeposit;\n            address[8] memory depositCoins = curveRegistry.get_coins(poolOut);\n            for (uint256 i = 0; i < 8; i++) {\n                if (depositCoins[i] == address(0)) break;\n                if (depositCoins[i] == tokenIn) {\n                    isDeposit = true;\n                    break;\n                }\n            }\n            if (isDeposit) {\n                _deposit(amount, tokenIn, poolOut, depositCoins);\n            } else {\n                bool isWithdraw;\n                address[8] memory withdrawCoins = curveRegistry.get_coins(poolIn);\n                for (uint256 i = 0; i < 8; i++) {\n                    if (withdrawCoins[i] == address(0)) break;\n                    if (withdrawCoins[i] == tokenOut) {\n                        isWithdraw = true;\n                        break;\n                    }\n                }\n                if (isWithdraw) _withdraw(amount, tokenIn, tokenOut, poolIn, withdrawCoins);\n            }\n        } else if (tokenIn == TRICRYPTO2 || tokenOut == TRICRYPTO2) {\n            // tricrypto not in registry\n            address[8] memory coins;\n            coins[0] = USDT;\n            coins[1] = WBTC;\n            coins[2] = WETH;\n            if (tokenIn == TRICRYPTO2) _withdraw(amount, tokenIn, tokenOut, TRICRYPTO2_POOL, coins);\n            if (tokenOut == TRICRYPTO2) _deposit(amount, tokenIn, TRICRYPTO2_POOL, coins);\n        } else {\n            revert();\n        }\n        uint256 received = IERC20(tokenOut).balanceOf(address(this));\n        require(received >= expected, \"Insufficient tokenOut amount\");\n        if (to != address(this))\n            IERC20(tokenOut).safeTransfer(to, received);\n    }"
}