mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-23 23:05:18 +00:00
Fix Ineffectual if statements (#568)
* fix exhibits 19,20,28,32 ineffectual if statements * Apply suggestions from code review * Apply suggestions from code review * Update x/cdp/keeper/cdp.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
547c651c95
commit
44467569af
@ -116,21 +116,13 @@ func (k Keeper) SetCdpAndCollateralRatioIndex(ctx sdk.Context, cdp types.CDP, ra
|
||||
// MintDebtCoins mints debt coins in the cdp module account
|
||||
func (k Keeper) MintDebtCoins(ctx sdk.Context, moduleAccount string, denom string, principalCoins sdk.Coin) error {
|
||||
debtCoins := sdk.NewCoins(sdk.NewCoin(denom, principalCoins.Amount))
|
||||
err := k.supplyKeeper.MintCoins(ctx, moduleAccount, debtCoins)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k.supplyKeeper.MintCoins(ctx, moduleAccount, debtCoins)
|
||||
}
|
||||
|
||||
// BurnDebtCoins burns debt coins from the cdp module account
|
||||
func (k Keeper) BurnDebtCoins(ctx sdk.Context, moduleAccount string, denom string, paymentCoins sdk.Coin) error {
|
||||
debtCoins := sdk.NewCoins(sdk.NewCoin(denom, paymentCoins.Amount))
|
||||
err := k.supplyKeeper.BurnCoins(ctx, moduleAccount, debtCoins)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k.supplyKeeper.BurnCoins(ctx, moduleAccount, debtCoins)
|
||||
}
|
||||
|
||||
// GetCdpID returns the id of the cdp corresponding to a specific owner and collateral denom
|
||||
|
@ -47,11 +47,7 @@ func (k Keeper) DepositCollateral(ctx sdk.Context, owner, depositor sdk.AccAddre
|
||||
|
||||
cdp.Collateral = cdp.Collateral.Add(collateral)
|
||||
collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
|
||||
err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
}
|
||||
|
||||
// WithdrawCollateral removes collateral from a cdp if it does not put the cdp below the liquidation ratio
|
||||
|
@ -68,11 +68,7 @@ func (k Keeper) AddPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom string
|
||||
|
||||
// set cdp state and indexes in the store
|
||||
collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
|
||||
err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
}
|
||||
|
||||
// RepayPrincipal removes debt from the cdp
|
||||
@ -164,11 +160,7 @@ func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom stri
|
||||
|
||||
// set cdp state and update indexes
|
||||
collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
|
||||
err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
|
||||
}
|
||||
|
||||
// ValidatePaymentCoins validates that the input coins are valid for repaying debt
|
||||
|
Loading…
Reference in New Issue
Block a user