mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-23 23:05:18 +00:00
fix: prevent cdp sim from attempting to draw too much debt (#438)
* fix: account for all fees when drawing more debt
This commit is contained in:
parent
55b73e36ee
commit
4cde3ba577
@ -122,8 +122,10 @@ func SimulateMsgCdp(ak auth.AccountKeeper, k cdp.Keeper, pfk pricefeed.Keeper) s
|
||||
if shouldDraw(r) {
|
||||
collateralShifted := ShiftDec(sdk.NewDecFromInt(existingCDP.Collateral.AmountOf(randCollateralParam.Denom)), randCollateralParam.ConversionFactor.Neg())
|
||||
collateralValue := collateralShifted.Mul(priceShifted)
|
||||
newFeesAccumulated := k.CalculateFees(ctx, existingCDP.Principal, sdk.NewInt(ctx.BlockTime().Unix()-existingCDP.FeesUpdated.Unix()), randCollateralParam.Denom).AmountOf(randDebtParam.Denom)
|
||||
totalFees := existingCDP.AccumulatedFees.AmountOf(randCollateralParam.Denom).Add(newFeesAccumulated)
|
||||
// given the current collateral value, calculate how much debt we could add while maintaining a valid liquidation ratio
|
||||
debt := (existingCDP.Principal.Add(existingCDP.AccumulatedFees)).AmountOf(randDebtParam.Denom)
|
||||
debt := existingCDP.Principal.AmountOf(randDebtParam.Denom).Add(totalFees)
|
||||
maxTotalDebt := collateralValue.Quo(randCollateralParam.LiquidationRatio)
|
||||
maxDebt := maxTotalDebt.Sub(sdk.NewDecFromInt(debt)).TruncateInt()
|
||||
if maxDebt.LTE(sdk.OneInt()) {
|
||||
|
Loading…
Reference in New Issue
Block a user