{
    "Function": "swap",
    "File": "src/Libraries/LibSwap.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "LibAsset",
        "LibAsset",
        "LibAsset",
        "LibAsset",
        "LibAsset",
        "LibAsset",
        "LibUtil",
        "LibAsset"
    ],
    "Internal Calls": [
        "revert(string)"
    ],
    "Library Calls": [
        "getOwnBalance",
        "getOwnBalance",
        "transferFromERC20",
        "getOwnBalance",
        "approveERC20",
        "getRevertMsg",
        "isNativeAsset",
        "isNativeAsset"
    ],
    "Low-Level Calls": [
        "call"
    ],
    "Code": "function swap(bytes32 transactionId, SwapData calldata _swapData) internal {\n        uint256 fromAmount = _swapData.fromAmount;\n        uint256 toAmount = LibAsset.getOwnBalance(_swapData.receivingAssetId);\n        address fromAssetId = _swapData.sendingAssetId;\n        if (!LibAsset.isNativeAsset(fromAssetId) && LibAsset.getOwnBalance(fromAssetId) < fromAmount) {\n            LibAsset.transferFromERC20(fromAssetId, msg.sender, address(this), fromAmount);\n        }\n\n        if (!LibAsset.isNativeAsset(fromAssetId)) {\n            LibAsset.approveERC20(IERC20(fromAssetId), _swapData.approveTo, fromAmount);\n        }\n\n        // solhint-disable-next-line avoid-low-level-calls\n        (bool success, bytes memory res) = _swapData.callTo.call{ value: msg.value }(_swapData.callData);\n        if (!success) {\n            string memory reason = LibUtil.getRevertMsg(res);\n            revert(reason);\n        }\n\n        toAmount = LibAsset.getOwnBalance(_swapData.receivingAssetId) - toAmount;\n        emit AssetSwapped(\n            transactionId,\n            _swapData.callTo,\n            _swapData.sendingAssetId,\n            _swapData.receivingAssetId,\n            fromAmount,\n            toAmount,\n            block.timestamp\n        );\n    }"
}