protocol-manager-contract.redeem_collateral is supposed to work on troves with ICR >= MCR, but in current implementation, troves(whose ICR < MCR) might be redeemed.
294// Get information about all assets in the system295 #[storage(read)]296fnget_all_assets_info() ->AssetInfo {...313while (i < length) {314let oracle =abi(Oracle, asset_contracts.get(i).unwrap().oracle.into());315let trove_manager =abi(TroveManager, asset_contracts.get(i).unwrap().trove_manager.into());316let asset = assets.get(i).unwrap();317let price = oracle.get_price();318letmut current_borrower = sorted_troves.get_last(asset);319letmut current_cr =u64::max();320if (current_borrower !=null_identity_address()) {321 current_cr = trove_manager.get_current_icr(current_borrower, price);322 }323 prices.push(price);324 system_debt.push(trove_manager.get_entire_system_debt());325 redemption_totals.push(RedemptionTotals::default());--->>> this code is used to find the first trove with ICR >= MCR326while (current_borrower !=null_identity_address() && current_cr < MCR) {327 current_borrower = sorted_troves.get_prev(current_borrower, asset);328 current_cr = trove_manager.get_current_icr(current_borrower, price);329 }330 current_borrowers.push(current_borrower);331 current_crs.push(current_cr);332 i +=1;333 }...343 }
However, in above code, there is a case that after the while loop inprotocol-manager-contractw#L326-L329, the last trove's icr might be less than MCR,in such case, the trove(icr <MCR) still will be added to current_borrowers, and later might be redeemed.
Impact Details
Please consider the following case:
a new asset(TokenA) is added to the protocol by calling protocol-manager-contract.register_asset
A few users start to borrow USDF using TokenA as collateral with icr a little higher than MCR
TokenA's price has fluctuated, all the troves become liquidatable(icr < MCR).
in such case, when redeem_collateral is called, the liquidatable troves will be redeemed.
As the above output shows, when the user open a trove, the collateral's price is 1e9, and the icr is 1368159203. And then the price is changed to 0.9e9, the icr is 1231343283, but the trove can still be redeem.
we define a new price function to support 0.9e9 as price
we add a new function to show icr and owners count