{
    "Function": "convert",
    "File": "contracts/v3/converters/GeneralConverter.sol",
    "Parent Contracts": [
        "contracts/v3/interfaces/IConverter.sol"
    ],
    "High-Level Calls": [
        "ICurve3Pool",
        "IERC20",
        "SafeERC20",
        "SafeERC20",
        "ICurvePool",
        "ICurvePool",
        "SafeERC20",
        "IERC20",
        "IERC20",
        "IERC20",
        "SafeMath",
        "ICurve2Pool",
        "IERC20",
        "SafeMath"
    ],
    "Internal Calls": [
        "onlyAuthorized"
    ],
    "Library Calls": [
        "safeTransfer",
        "sub",
        "sub",
        "safeTransfer",
        "safeTransfer"
    ],
    "Low-Level Calls": [],
    "Code": "function convert(\n        address _input,\n        address _output,\n        uint256 _inputAmount,\n        uint256 _estimatedOutput\n    ) external override onlyAuthorized returns (uint256 _outputAmount) {\n        if (_output == address(tokenCRV)) {\n            // convert to CRV\n            for (uint8 i = 0; i < tokens.length; i++) {\n                if (_input == address(tokens[i])) {\n                    uint256 _before = tokenCRV.balanceOf(address(this));\n\n                    if (tokens.length == 2) {\n                        uint256[2] memory amounts;\n                        amounts[i] = _inputAmount;\n                        ICurve2Pool(address(swapPool)).add_liquidity(\n                            amounts,\n                            _estimatedOutput\n                        );\n                    } else {\n                        uint256[3] memory amounts;\n                        amounts[i] = _inputAmount;\n                        ICurve3Pool(address(swapPool)).add_liquidity(\n                            amounts,\n                            _estimatedOutput\n                        );\n                    }\n\n                    uint256 _after = tokenCRV.balanceOf(address(this));\n                    _outputAmount = _after.sub(_before);\n                    tokenCRV.safeTransfer(msg.sender, _outputAmount);\n                    return _outputAmount;\n                }\n            }\n        } else if (_input == address(tokenCRV)) {\n            // convert from CRV\n            for (uint8 i = 0; i < tokens.length; i++) {\n                if (_output == address(tokens[i])) {\n                    uint256 _before = tokens[i].balanceOf(address(this));\n                    swapPool.remove_liquidity_one_coin(_inputAmount, i, _estimatedOutput);\n                    uint256 _after = tokens[i].balanceOf(address(this));\n                    _outputAmount = _after.sub(_before);\n                    tokens[i].safeTransfer(msg.sender, _outputAmount);\n                    return _outputAmount;\n                }\n            }\n        } else {\n            swapPool.exchange(\n                indices[_input],\n                indices[_output],\n                _inputAmount,\n                _estimatedOutput\n            );\n            _outputAmount = IERC20(_output).balanceOf(address(this));\n            IERC20(_output).safeTransfer(msg.sender, _outputAmount);\n            return _outputAmount;\n        }\n        return 0;\n    }"
}