The liquidated person can make the liquidator lose premium by adding collateral in advance
When the position with debtRatioE18 >= 1e18 or startLiqTimestamp ! = 0, the position can be liquidated. On liquidation, the liquidator needs to pay premium, but the profit is related to the position's health factor and deltaTime, and when discount == 0, the liquidator loses premium.\\n```\\n            uint deltaTime;\\n            // 1.1 check the amount of time since position is marked\\n            if (pos.startLiqTimestamp > 0) {\\n                 deltaTime = Math.max(deltaTime, block.timestamp - pos.startLiqTimestamp);\\n            }\\n            // 1.2 check the amount of time since position is past the deadline\\n             if (block.timestamp > pos.positionDeadline) {\\n                    deltaTime = Math.max(deltaTime, block.timestamp - pos.positionDeadline);\\n            }\\n            // 1.3 cap time-based discount, as configured\\n              uint timeDiscountMultiplierE18 = Math.max(\\n                IConfig(config).minLiquidateTimeDiscountMultiplierE18(),\\n                     ONE_E18 - deltaTime * IConfig(config).liquidateTimeDiscountGrowthRateE18()\\n            );\\n            // 2. calculate health-based discount factor\\n            uint curHealthFactorE18 = (ONE_E18 * ONE_E18) /\\n             getPositionDebtRatioE18(_positionManager, _user, _posId);\\n                 uint minDesiredHealthFactorE18 = IConfig(config).minDesiredHealthFactorE18s(strategy);\\n            // 2.1 interpolate linear health discount factor (according to the diagram in documentation)\\n            uint healthDiscountMultiplierE18 = ONE_E18;\\n             if (curHealthFactorE18 < ONE_E18) {\\n                 healthDiscountMultiplierE18 = curHealthFactorE18 > minDesiredHealthFactorE18\\n                     ? ((curHealthFactorE18 - minDesiredHealthFactorE18) * ONE_E18) /\\n            (ONE_E18 - minDesiredHealthFactorE18)\\n            : 0;\\n            }\\n            // 3. final liquidation discount = apply the two discount methods together\\n            liquidationDiscountMultiplierE18 =\\n            (timeDiscountMultiplierE18 * healthDiscountMultiplierE18) /\\n            ONE_E18;\\n```\\n\\nConsider the following scenario.\\nAlice notices Bob's position with debtRatioE18 >= 1e18 and calls `liquidatePosition()` to liquidate.\\nBob observes Alice's transaction, frontruns a call `markLiquidationStatus()` to make startLiqTimestamp == block.timestamp, and calls `adjustExtraColls()` to bring the position back to the health state.\\nAlice's transaction is executed, and since the startLiqTimestamp of Bob's position.startLiqTimestamp ! = 0, it can be liquidated, but since discount = 0, Alice loses premium. This breaks the protocol's liquidation mechanism and causes the liquidator not to launch liquidation for fear of losing assets, which will lead to more bad debts
Consider having the liquidated person bear the premium, or at least have the liquidator use the minDiscount parameter to set the minimum acceptable discount.
```\\n            uint deltaTime;\\n            // 1.1 check the amount of time since position is marked\\n            if (pos.startLiqTimestamp > 0) {\\n                 deltaTime = Math.max(deltaTime, block.timestamp - pos.startLiqTimestamp);\\n            }\\n            // 1.2 check the amount of time since position is past the deadline\\n             if (block.timestamp > pos.positionDeadline) {\\n                    deltaTime = Math.max(deltaTime, block.timestamp - pos.positionDeadline);\\n            }\\n            // 1.3 cap time-based discount, as configured\\n              uint timeDiscountMultiplierE18 = Math.max(\\n                IConfig(config).minLiquidateTimeDiscountMultiplierE18(),\\n                     ONE_E18 - deltaTime * IConfig(config).liquidateTimeDiscountGrowthRateE18()\\n            );\\n            // 2. calculate health-based discount factor\\n            uint curHealthFactorE18 = (ONE_E18 * ONE_E18) /\\n             getPositionDebtRatioE18(_positionManager, _user, _posId);\\n                 uint minDesiredHealthFactorE18 = IConfig(config).minDesiredHealthFactorE18s(strategy);\\n            // 2.1 interpolate linear health discount factor (according to the diagram in documentation)\\n            uint healthDiscountMultiplierE18 = ONE_E18;\\n             if (curHealthFactorE18 < ONE_E18) {\\n                 healthDiscountMultiplierE18 = curHealthFactorE18 > minDesiredHealthFactorE18\\n                     ? ((curHealthFactorE18 - minDesiredHealthFactorE18) * ONE_E18) /\\n            (ONE_E18 - minDesiredHealthFactorE18)\\n            : 0;\\n            }\\n            // 3. final liquidation discount = apply the two discount methods together\\n            liquidationDiscountMultiplierE18 =\\n            (timeDiscountMultiplierE18 * healthDiscountMultiplierE18) /\\n            ONE_E18;\\n```\\n