Calculation B0 meets devision 0 error when a token has small decimal and high price with a small kBid
Here is poc\\n```\\n   function testQueryFail() public {\\n        token1ChainLinkOracle.feedData(30647 * 1e18);\\n        token2ChainLinkOracle.feedData(1 * 1e18);\\n        vm.startPrank(maker);\\n        uint32[] memory tokenKs = new uint32[](2);\\n        tokenKs[0] = 0;\\n        tokenKs[1] = (1<< 16) +1;\\n        address[] memory tokens = new address[](2);\\n        tokens[0] = address(token2);\\n        tokens[1] = address(token1);\\n        address[] memory slotIndex = new address[](2);\\n        slotIndex[0] = address(token1);\\n        slotIndex[1] = address(token2);\\n        uint80[] memory priceSlot = new uint80[](2);\\n        priceSlot[0] = 2191925019632266903652;\\n        priceSlot[1] = 720435765840878108682;\\n\\n        uint64[] memory amountslot = new uint64[](2);\\n        amountslot[0] = stickAmount(10,8, 400000, 18);\\n        amountslot[1] = stickAmount(400000, 18, 400000, 18);\\n        d3MakerWithPool.setTokensKs(tokens, tokenKs);\\n        d3MakerWithPool.setTokensPrice(slotIndex, priceSlot);\\n        d3MakerWithPool.setTokensAmounts(slotIndex, amountslot);\\n        vm.stopPrank();\\n\\n        (uint256 askDownPrice, uint256 askUpPrice, uint256 bidDownPrice, uint256 bidUpPrice, uint256 swapFee) =\\n            d3MM.getTokenMMPriceInfoForRead(address(token1));\\n        assertEq(askDownPrice, 304555028000000000000000000000000);\\n        assertEq(askUpPrice, 307231900000000000000000000000000);\\n        assertEq(bidDownPrice, 3291);\\n        assertEq(bidUpPrice, 3320);\\n        assertEq(swapFee, 1200000000000000);\\n\\n        //console.log(askDownPrice);\\n        //console.log(askUpPrice);\\n        //console.log(bidDownPrice);\\n        //console.log(bidUpPrice);\\n        //console.log(swapFee);\\n\\n        (,,uint kask, uint kbid,,) = d3MM.getTokenMMOtherInfoForRead(address(token1));\\n        assertEq(kask, 1e14);\\n        assertEq(kbid, 1e14);\\n\\n        (askDownPrice, askUpPrice, bidDownPrice, bidUpPrice, swapFee) =\\n            d3MM.getTokenMMPriceInfoForRead(address(token2));\\n        assertEq(askDownPrice, 999999960000000000);\\n        assertEq(askUpPrice, 1000799800000000000);\\n        assertEq(bidDownPrice, 1000400120032008002);\\n        assertEq(bidUpPrice, 1001201241249250852);\\n        assertEq(swapFee, 200000000000000);\\n\\n        (,,kask, kbid,,) = d3MM.getTokenMMOtherInfoForRead(address(token2));\\n        assertEq(kask, 0);\\n        assertEq(kbid, 0);\\n\\n        //console.log(askDownPrice);\\n        //console.log(askUpPrice);\\n        //console.log(bidDownPrice);\\n        //console.log(bidUpPrice);\\n        //console.log(swapFee);\\n        //console.log(kask);\\n        //console.log(kbid);\\n\\n        SwapCallbackData memory swapData;\\n        swapData.data = "";\\n        swapData.payer = user1;\\n\\n        //uint256 gasleft1 = gasleft();\\n        uint256 receiveToToken = d3Proxy.sellTokens(\\n            address(d3MM),\\n            user1,\\n            address(token1),\\n            address(token2),\\n            1000000,\\n            0,\\n            abi.encode(swapData),\\n            block.timestamp + 1000\\n        );\\n```\\n\\nIt will revert. In this example, wbtc price is 30445, and k = 0.0001, suppose maker contains rules, but model is invalid.
Fix formula for this corner case, like making temp2 = 1\\nImprove calculation accuracy by consistently using precision 18 for calculations and converting to real decimal when processing amounts.
Maker sets right parameters but traders can't swap. It will make swap model invalid.\\nTool Used\\nManual Review
```\\n   function testQueryFail() public {\\n        token1ChainLinkOracle.feedData(30647 * 1e18);\\n        token2ChainLinkOracle.feedData(1 * 1e18);\\n        vm.startPrank(maker);\\n        uint32[] memory tokenKs = new uint32[](2);\\n        tokenKs[0] = 0;\\n        tokenKs[1] = (1<< 16) +1;\\n        address[] memory tokens = new address[](2);\\n        tokens[0] = address(token2);\\n        tokens[1] = address(token1);\\n        address[] memory slotIndex = new address[](2);\\n        slotIndex[0] = address(token1);\\n        slotIndex[1] = address(token2);\\n        uint80[] memory priceSlot = new uint80[](2);\\n        priceSlot[0] = 2191925019632266903652;\\n        priceSlot[1] = 720435765840878108682;\\n\\n        uint64[] memory amountslot = new uint64[](2);\\n        amountslot[0] = stickAmount(10,8, 400000, 18);\\n        amountslot[1] = stickAmount(400000, 18, 400000, 18);\\n        d3MakerWithPool.setTokensKs(tokens, tokenKs);\\n        d3MakerWithPool.setTokensPrice(slotIndex, priceSlot);\\n        d3MakerWithPool.setTokensAmounts(slotIndex, amountslot);\\n        vm.stopPrank();\\n\\n        (uint256 askDownPrice, uint256 askUpPrice, uint256 bidDownPrice, uint256 bidUpPrice, uint256 swapFee) =\\n            d3MM.getTokenMMPriceInfoForRead(address(token1));\\n        assertEq(askDownPrice, 304555028000000000000000000000000);\\n        assertEq(askUpPrice, 307231900000000000000000000000000);\\n        assertEq(bidDownPrice, 3291);\\n        assertEq(bidUpPrice, 3320);\\n        assertEq(swapFee, 1200000000000000);\\n\\n        //console.log(askDownPrice);\\n        //console.log(askUpPrice);\\n        //console.log(bidDownPrice);\\n        //console.log(bidUpPrice);\\n        //console.log(swapFee);\\n\\n        (,,uint kask, uint kbid,,) = d3MM.getTokenMMOtherInfoForRead(address(token1));\\n        assertEq(kask, 1e14);\\n        assertEq(kbid, 1e14);\\n\\n        (askDownPrice, askUpPrice, bidDownPrice, bidUpPrice, swapFee) =\\n            d3MM.getTokenMMPriceInfoForRead(address(token2));\\n        assertEq(askDownPrice, 999999960000000000);\\n        assertEq(askUpPrice, 1000799800000000000);\\n        assertEq(bidDownPrice, 1000400120032008002);\\n        assertEq(bidUpPrice, 1001201241249250852);\\n        assertEq(swapFee, 200000000000000);\\n\\n        (,,kask, kbid,,) = d3MM.getTokenMMOtherInfoForRead(address(token2));\\n        assertEq(kask, 0);\\n        assertEq(kbid, 0);\\n\\n        //console.log(askDownPrice);\\n        //console.log(askUpPrice);\\n        //console.log(bidDownPrice);\\n        //console.log(bidUpPrice);\\n        //console.log(swapFee);\\n        //console.log(kask);\\n        //console.log(kbid);\\n\\n        SwapCallbackData memory swapData;\\n        swapData.data = "";\\n        swapData.payer = user1;\\n\\n        //uint256 gasleft1 = gasleft();\\n        uint256 receiveToToken = d3Proxy.sellTokens(\\n            address(d3MM),\\n            user1,\\n            address(token1),\\n            address(token2),\\n            1000000,\\n            0,\\n            abi.encode(swapData),\\n            block.timestamp + 1000\\n        );\\n```\\n