Skip to content

Commit

Permalink
chore: use errors.New to replace fmt.Errorf with no parameters (#1080)
Browse files Browse the repository at this point in the history
Signed-off-by: RiceChuan <[email protected]>
Co-authored-by: Abhinav Kumar <[email protected]>
  • Loading branch information
RiceChuan and avkr003 authored Dec 27, 2024
1 parent c2fdaba commit 0ffd48c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
6 changes: 3 additions & 3 deletions x/amm/types/genesis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package types

import (
"fmt"
"errors"
)

// DefaultIndex is the default global index
Expand All @@ -26,7 +26,7 @@ func (gs GenesisState) Validate() error {
for _, elem := range gs.PoolList {
index := string(PoolKey(elem.PoolId))
if _, ok := poolIndexMap[index]; ok {
return fmt.Errorf("duplicated index for pool")
return errors.New("duplicated index for pool")
}
poolIndexMap[index] = struct{}{}
}
Expand All @@ -36,7 +36,7 @@ func (gs GenesisState) Validate() error {
for _, elem := range gs.DenomLiquidityList {
index := string(DenomLiquidityKey(elem.Denom))
if _, ok := denomLiquidityIndexMap[index]; ok {
return fmt.Errorf("duplicated index for denomLiquidity")
return errors.New("duplicated index for denomLiquidity")
}
denomLiquidityIndexMap[index] = struct{}{}
}
Expand Down
6 changes: 3 additions & 3 deletions x/amm/types/message_feed_multiple_external_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

import (
errorsmod "cosmossdk.io/errors"
"fmt"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand All @@ -27,10 +27,10 @@ func (msg *MsgFeedMultipleExternalLiquidity) ValidateBasic() error {
return err
}
if depthInfo.Depth.IsNil() || depthInfo.Depth.IsNegative() {
return fmt.Errorf("depth cannot be negative or nil")
return errors.New("depth cannot be negative or nil")
}
if depthInfo.Amount.IsNil() || depthInfo.Amount.IsNegative() {
return fmt.Errorf("depth amount cannot be negative or nil")
return errors.New("depth amount cannot be negative or nil")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions x/amm/types/message_swap_by_denom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package types

import (
errorsmod "cosmossdk.io/errors"
"fmt"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down Expand Up @@ -41,7 +41,7 @@ func (msg *MsgSwapByDenom) ValidateBasic() error {
return err
}
if msg.DenomIn == msg.DenomOut {
return fmt.Errorf("demom in cannot be same as denom out")
return errors.New("demom in cannot be same as denom out")
}
return nil
}
23 changes: 12 additions & 11 deletions x/amm/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"cosmossdk.io/math"
"errors"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -35,7 +36,7 @@ func DefaultParams() Params {
// Validate validates the set of params
func (p Params) Validate() error {
if p.PoolCreationFee.IsNil() {
return fmt.Errorf("pool creation fee must not be empty")
return errors.New("pool creation fee must not be empty")
}
if p.PoolCreationFee.IsNegative() {
return fmt.Errorf("pool creation fee must be positive")
Expand All @@ -48,38 +49,38 @@ func (p Params) Validate() error {
}

if p.WeightBreakingFeeExponent.IsNil() {
return fmt.Errorf("weightBreakingFeeExponent must not be empty")
return errors.New("weightBreakingFeeExponent must not be empty")
}
if p.WeightBreakingFeeExponent.IsNegative() {
return fmt.Errorf("weightBreakingFeeExponent must be positive")
return errors.New("weightBreakingFeeExponent must be positive")
}

if p.WeightBreakingFeeMultiplier.IsNil() {
return fmt.Errorf("weightBreakingFeeMultiplier must not be empty")
return errors.New("weightBreakingFeeMultiplier must not be empty")
}
if p.WeightBreakingFeeMultiplier.IsNegative() {
return fmt.Errorf("weightBreakingFeeMultiplier must be positive")
return errors.New("weightBreakingFeeMultiplier must be positive")
}

if p.WeightBreakingFeePortion.IsNil() {
return fmt.Errorf("weightBreakingFeePortion must not be empty")
return errors.New("weightBreakingFeePortion must not be empty")
}
if p.WeightBreakingFeePortion.IsNegative() {
return fmt.Errorf("weightBreakingFeePortion must be positive")
return errors.New("weightBreakingFeePortion must be positive")
}

if p.WeightRecoveryFeePortion.IsNil() {
return fmt.Errorf("weightRecoveryFeePortion must not be empty")
return errors.New("weightRecoveryFeePortion must not be empty")
}
if p.WeightRecoveryFeePortion.IsNegative() {
return fmt.Errorf("weightRecoveryFeePortion must be positive")
return errors.New("weightRecoveryFeePortion must be positive")
}

if p.ThresholdWeightDifference.IsNil() {
return fmt.Errorf("thresholdWeightDifference must not be empty")
return errors.New("thresholdWeightDifference must not be empty")
}
if p.ThresholdWeightDifference.IsNegative() {
return fmt.Errorf("thresholdWeightDifference must be positive")
return errors.New("thresholdWeightDifference must be positive")
}
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions x/amm/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p *Pool) SetInitialPoolAssets(PoolAssets []PoolAsset) error {
// TODO: Refactor this into PoolAsset.validate()
for _, asset := range PoolAssets {
if asset.Token.Amount.LTE(sdkmath.ZeroInt()) {
return fmt.Errorf("can't add the zero or negative balance of token")
return errors.New("can't add the zero or negative balance of token")
}

err := asset.validateWeight()
Expand All @@ -113,7 +113,7 @@ func (p *Pool) SetInitialPoolAssets(PoolAssets []PoolAsset) error {
}

if exists[asset.Token.Denom] {
return fmt.Errorf("same PoolAsset already exists")
return errors.New("same PoolAsset already exists")
}
exists[asset.Token.Denom] = true

Expand Down Expand Up @@ -172,7 +172,7 @@ func (p *Pool) UpdatePoolAssetBalance(coin sdk.Coin) error {
}

if coin.Amount.LTE(sdkmath.ZeroInt()) {
return fmt.Errorf("can't set the pool's balance of a token to be zero or negative")
return errors.New("can't set the pool's balance of a token to be zero or negative")
}

// Update the supply of the asset
Expand Down Expand Up @@ -215,7 +215,7 @@ func (p Pool) GetTotalPoolLiquidity() sdk.Coins {
// Returns a pool asset, and its index. If err != nil, then the index will be valid.
func (p Pool) GetPoolAssetAndIndex(denom string) (int, PoolAsset, error) {
if denom == "" {
return -1, PoolAsset{}, fmt.Errorf("you tried to find the PoolAsset with empty denom")
return -1, PoolAsset{}, errors.New("you tried to find the PoolAsset with empty denom")
}

if len(p.PoolAssets) == 0 {
Expand Down Expand Up @@ -362,5 +362,5 @@ func (pool Pool) GetAssetExternalLiquidityRatio(asset string) (sdkmath.LegacyDec
return poolAsset.ExternalLiquidityRatio, nil
}
}
return sdkmath.LegacyZeroDec(), fmt.Errorf("asset not found in the pool")
return sdkmath.LegacyZeroDec(), errors.New("asset not found in the pool")
}

0 comments on commit 0ffd48c

Please sign in to comment.