`BuyUSSDSellCollateral()` always sells 0 amount if need to sell part of collateral
Due to rounding error there is misbehaviour in `BuyUSSDSellCollateral()` function. It results in selling 0 amount of collateral.\\nSuppose the only collateral in protocol is 1 WBTC; 1 WBTC costs 30_000 USD; UniV3Pool DAI/ USSD has following liquidity: (3000e6 USSD, 2000e18 DAI) And also USSD is underpriced so call rebalance:\\n```\\n    function rebalance() override public {\\n      uint256 ownval = getOwnValuation(); // it low enough to dive into if statement (see line below) \\n      (uint256 USSDamount, uint256 DAIamount) = getSupplyProportion(); // (3000e6 USSD, 2000e18 DAI)\\n      if (ownval < 1e6 - threshold) {\\n        // peg-down recovery\\n        BuyUSSDSellCollateral((USSDamount - DAIamount / 1e12)/2); //  500 * 1e6     = (3000e6 - 2000e18 / 1e12) / 2\\n```\\n\\nTake a look into BuyUSSDSellCollateral (follow comments):\\n```\\n    function BuyUSSDSellCollateral(uint256 amountToBuy) internal { // 500e6\\n      CollateralInfo[] memory collateral = IUSSD(USSD).collateralList();\\n      //uint amountToBuyLeftUSD = amountToBuy * 1e12 * 1e6 / getOwnValuation();\\n      uint amountToBuyLeftUSD = amountToBuy * 1e12; // 500e18\\n      uint DAItosell = 0;\\n      // Sell collateral in order of collateral array\\n      for (uint256 i = 0; i < collateral.length; i++) {\\n        // 30_000e18 = 1e8 * 1e18 / 10**8 * 30_000e18 / 1e18\\n        uint256 collateralval = IERC20Upgradeable(collateral[i].token).balanceOf(USSD) * 1e18 / (10**IERC20MetadataUpgradeable(collateral[i].token).decimals()) * collateral[i].oracle.getPriceUSD() / 1e18;\\n        if (collateralval > amountToBuyLeftUSD) {\\n          // sell a portion of collateral and exit\\n          if (collateral[i].pathsell.length > 0) {\\n            uint256 amountBefore = IERC20Upgradeable(baseAsset).balanceOf(USSD); // 0\\n            // amountToSellUnits = 1e8 * ((500e18 * 1e18 / 30_000e18) / 1e18) / 1e18 = 1e8 * (0) / 1e18 = 0\\n            uint256 amountToSellUnits = IERC20Upgradeable(collateral[i].token).balanceOf(USSD) * ((amountToBuyLeftUSD * 1e18 / collateralval) / 1e18) / 1e18;\\n            // and finally executes trade of 0 WBTC\\n            IUSSD(USSD).UniV3SwapInput(collateral[i].pathsell, amountToSellUnits);\\n            amountToBuyLeftUSD -= (IERC20Upgradeable(baseAsset).balanceOf(USSD) - amountBefore); // 0 = 0 - 0\\n            DAItosell += (IERC20Upgradeable(baseAsset).balanceOf(USSD) - amountBefore); // 0 += 0\\n            // rest of code\\n```\\n\\nSo protocol will not buy DAI and will not sell DAI for USSD in UniswapV3Pool to support peg of USSD to DAI
Refactor formula of amountToSellUnits\\n```\\n// uint256 amountToSellUnits = (decimals of collateral) * (DAI amount to get for sell) / (price of 1 token of collateral)\\nuint256 amountToSellUnits = collateral[i].token).decimals() * amountToBuyLeftUSD / collateral[i].oracle.getPriceUSD()\\n```\\n
Protocol is not able of partial selling of collateral for token. It block algorithmic pegging of USSD to DAI
```\\n    function rebalance() override public {\\n      uint256 ownval = getOwnValuation(); // it low enough to dive into if statement (see line below) \\n      (uint256 USSDamount, uint256 DAIamount) = getSupplyProportion(); // (3000e6 USSD, 2000e18 DAI)\\n      if (ownval < 1e6 - threshold) {\\n        // peg-down recovery\\n        BuyUSSDSellCollateral((USSDamount - DAIamount / 1e12)/2); //  500 * 1e6     = (3000e6 - 2000e18 / 1e12) / 2\\n```\\n