mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-04 09:57:27 +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
 | 
					// MintDebtCoins mints debt coins in the cdp module account
 | 
				
			||||||
func (k Keeper) MintDebtCoins(ctx sdk.Context, moduleAccount string, denom string, principalCoins sdk.Coin) error {
 | 
					func (k Keeper) MintDebtCoins(ctx sdk.Context, moduleAccount string, denom string, principalCoins sdk.Coin) error {
 | 
				
			||||||
	debtCoins := sdk.NewCoins(sdk.NewCoin(denom, principalCoins.Amount))
 | 
						debtCoins := sdk.NewCoins(sdk.NewCoin(denom, principalCoins.Amount))
 | 
				
			||||||
	err := k.supplyKeeper.MintCoins(ctx, moduleAccount, debtCoins)
 | 
						return k.supplyKeeper.MintCoins(ctx, moduleAccount, debtCoins)
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// BurnDebtCoins burns debt coins from the cdp module account
 | 
					// BurnDebtCoins burns debt coins from the cdp module account
 | 
				
			||||||
func (k Keeper) BurnDebtCoins(ctx sdk.Context, moduleAccount string, denom string, paymentCoins sdk.Coin) error {
 | 
					func (k Keeper) BurnDebtCoins(ctx sdk.Context, moduleAccount string, denom string, paymentCoins sdk.Coin) error {
 | 
				
			||||||
	debtCoins := sdk.NewCoins(sdk.NewCoin(denom, paymentCoins.Amount))
 | 
						debtCoins := sdk.NewCoins(sdk.NewCoin(denom, paymentCoins.Amount))
 | 
				
			||||||
	err := k.supplyKeeper.BurnCoins(ctx, moduleAccount, debtCoins)
 | 
						return k.supplyKeeper.BurnCoins(ctx, moduleAccount, debtCoins)
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// GetCdpID returns the id of the cdp corresponding to a specific owner and collateral denom
 | 
					// 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)
 | 
						cdp.Collateral = cdp.Collateral.Add(collateral)
 | 
				
			||||||
	collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
 | 
						collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
 | 
				
			||||||
	err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
 | 
						return k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// WithdrawCollateral removes collateral from a cdp if it does not put the cdp below the liquidation ratio
 | 
					// 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
 | 
						// set cdp state and indexes in the store
 | 
				
			||||||
	collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
 | 
						collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
 | 
				
			||||||
	err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
 | 
						return k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// RepayPrincipal removes debt from the cdp
 | 
					// 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
 | 
						// set cdp state and update indexes
 | 
				
			||||||
	collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
 | 
						collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees))
 | 
				
			||||||
	err = k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
 | 
						return k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return nil
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ValidatePaymentCoins validates that the input coins are valid for repaying debt
 | 
					// ValidatePaymentCoins validates that the input coins are valid for repaying debt
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user