{
    "Function": "switchStrategy",
    "File": "contracts/SavingsAccount/SavingsAccount.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/utils/ReentrancyGuard.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol",
        "node_modules/@openzeppelin/contracts-upgradeable/proxy/Initializable.sol",
        "contracts/interfaces/ISavingsAccount.sol"
    ],
    "High-Level Calls": [
        "SafeMath",
        "IYield",
        "SafeERC20",
        "IYield",
        "IYield",
        "IStrategyRegistry",
        "SafeMath"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "require(bool,string)",
        "nonReentrant",
        "require(bool,string)"
    ],
    "Library Calls": [
        "sub",
        "add",
        "safeApprove"
    ],
    "Low-Level Calls": [],
    "Code": "function switchStrategy(\n        uint256 _amount,\n        address _token,\n        address _currentStrategy,\n        address _newStrategy\n    ) external override nonReentrant {\n        require(_currentStrategy != _newStrategy, 'SavingsAccount::switchStrategy Same strategy');\n        require(IStrategyRegistry(strategyRegistry).registry(_newStrategy), 'SavingsAccount::_newStrategy do not exist');\n        require(_amount != 0, 'SavingsAccount::switchStrategy Amount must be greater than zero');\n\n        _amount = IYield(_currentStrategy).getSharesForTokens(_amount, _token);\n\n        balanceInShares[msg.sender][_token][_currentStrategy] = balanceInShares[msg.sender][_token][_currentStrategy].sub(\n            _amount,\n            'SavingsAccount::switchStrategy Insufficient balance'\n        );\n\n        uint256 _tokensReceived = IYield(_currentStrategy).unlockTokens(_token, _amount);\n\n        uint256 _ethValue;\n        if (_token != address(0)) {\n            IERC20(_token).safeApprove(_newStrategy, _tokensReceived);\n        } else {\n            _ethValue = _tokensReceived;\n        }\n        _amount = _tokensReceived;\n        \n        uint256 _sharesReceived = IYield(_newStrategy).lockTokens{value: _ethValue}(address(this), _token, _tokensReceived);\n\n        balanceInShares[msg.sender][_token][_newStrategy] = balanceInShares[msg.sender][_token][_newStrategy].add(_sharesReceived);\n        emit StrategySwitched(msg.sender, _token, _amount, _sharesReceived, _currentStrategy, _newStrategy);\n    }"
}