From a11b8b6f36b1cfa762129e1c06cab78d1a050da4 Mon Sep 17 00:00:00 2001 From: Chenyao Yu <4844716+chenyaoy@users.noreply.github.com> Date: Fri, 13 Dec 2024 06:47:22 -0500 Subject: [PATCH] lint --- protocol/app/ante/replay_protection.go | 2 +- .../pricefeed/client/price_function/exchange_error.go | 3 ++- protocol/x/clob/keeper/process_operations.go | 2 +- protocol/x/delaymsg/keeper/delayed_message.go | 2 +- protocol/x/prices/keeper/market.go | 10 +++++----- protocol/x/prices/keeper/market_param.go | 6 +++--- protocol/x/prices/keeper/market_param_test.go | 2 +- protocol/x/vault/keeper/orders.go | 2 +- protocol/x/vest/types/vest_entry.go | 4 ++-- 9 files changed, 17 insertions(+), 16 deletions(-) diff --git a/protocol/app/ante/replay_protection.go b/protocol/app/ante/replay_protection.go index d2fb6a25bd..0514e62e6e 100644 --- a/protocol/app/ante/replay_protection.go +++ b/protocol/app/ante/replay_protection.go @@ -86,7 +86,7 @@ func (rpd ReplayProtectionDecorator) AnteHandle( 1, []gometrics.Label{metrics.GetLabelForIntValue(metrics.ExecMode, int(ctx.ExecMode()))}, ) - return ctx, errorsmod.Wrapf(sdkerrors.ErrWrongSequence, err.Error()) + return ctx, errorsmod.Wrap(sdkerrors.ErrWrongSequence, err.Error()) } telemetry.IncrCounterWithLabels( []string{metrics.TimestampNonce, metrics.Valid, metrics.Count}, diff --git a/protocol/daemons/pricefeed/client/price_function/exchange_error.go b/protocol/daemons/pricefeed/client/price_function/exchange_error.go index 2bbce0aad2..cc605465d9 100644 --- a/protocol/daemons/pricefeed/client/price_function/exchange_error.go +++ b/protocol/daemons/pricefeed/client/price_function/exchange_error.go @@ -2,6 +2,7 @@ package price_function import ( "fmt" + "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/client/types" ) @@ -35,6 +36,6 @@ func (e *ExchangeErrorImpl) GetExchangeId() types.ExchangeId { func NewExchangeError(exchangeId types.ExchangeId, msg string) ExchangeError { return &ExchangeErrorImpl{ exchangeId: exchangeId, - err: fmt.Errorf(msg), + err: fmt.Errorf("%s", msg), } } diff --git a/protocol/x/clob/keeper/process_operations.go b/protocol/x/clob/keeper/process_operations.go index 86808afb5d..057256554e 100644 --- a/protocol/x/clob/keeper/process_operations.go +++ b/protocol/x/clob/keeper/process_operations.go @@ -752,7 +752,7 @@ func (k Keeper) PersistMatchDeleveragingToState( // negative TNC subaccount was seen. if len(matchDeleveraging.GetFills()) == 0 { if !shouldDeleverageAtBankruptcyPrice { - return errorsmod.Wrapf( + return errorsmod.Wrap( types.ErrZeroFillDeleveragingForNonNegativeTncSubaccount, fmt.Sprintf( "PersistMatchDeleveragingToState: zero-fill deleveraging operation included for subaccount %+v"+ diff --git a/protocol/x/delaymsg/keeper/delayed_message.go b/protocol/x/delaymsg/keeper/delayed_message.go index a89f2ea788..23afda663f 100644 --- a/protocol/x/delaymsg/keeper/delayed_message.go +++ b/protocol/x/delaymsg/keeper/delayed_message.go @@ -201,7 +201,7 @@ func (k Keeper) ValidateMsg(msg sdk.Msg, signers [][]byte) error { handler := k.router.Handler(msg) // If the message type is not routable, return an error. if handler == nil { - return errorsmod.Wrapf( + return errorsmod.Wrap( types.ErrMsgIsUnroutable, sdk.MsgTypeURL(msg), ) diff --git a/protocol/x/prices/keeper/market.go b/protocol/x/prices/keeper/market.go index d5c76cc310..1bea1371f9 100644 --- a/protocol/x/prices/keeper/market.go +++ b/protocol/x/prices/keeper/market.go @@ -42,7 +42,7 @@ func (k Keeper) CreateMarket( // Stateful Validation for _, market := range k.GetAllMarketParams(ctx) { if market.Pair == marketParam.Pair { - return types.MarketParam{}, errorsmod.Wrapf( + return types.MarketParam{}, errorsmod.Wrap( types.ErrMarketParamPairAlreadyExists, marketParam.Pair, ) @@ -51,7 +51,7 @@ func (k Keeper) CreateMarket( // check that the market exists in market map currencyPair, err := slinky.MarketPairToCurrencyPair(marketParam.Pair) if err != nil { - return types.MarketParam{}, errorsmod.Wrapf( + return types.MarketParam{}, errorsmod.Wrap( types.ErrMarketPairConversionFailed, marketParam.Pair, ) @@ -59,7 +59,7 @@ func (k Keeper) CreateMarket( currencyPairStr := currencyPair.String() marketMapDetails, err := k.MarketMapKeeper.GetMarket(ctx, currencyPairStr) if err != nil { - return types.MarketParam{}, errorsmod.Wrapf( + return types.MarketParam{}, errorsmod.Wrap( types.ErrTickerNotFoundInMarketMap, currencyPairStr, ) @@ -67,7 +67,7 @@ func (k Keeper) CreateMarket( // Check that the exponent of market price is the negation of the decimals value in the market map if marketPrice.Exponent != int32(marketMapDetails.Ticker.Decimals)*-1 { - return types.MarketParam{}, errorsmod.Wrapf( + return types.MarketParam{}, errorsmod.Wrap( types.ErrInvalidMarketPriceExponent, currencyPairStr, ) @@ -130,7 +130,7 @@ func (k Keeper) GetExponent(ctx sdk.Context, ticker string) (int32, error) { marketMapDetails, err := k.MarketMapKeeper.GetMarket(ctx, currencyPair.String()) if err != nil { - return 0, errorsmod.Wrapf( + return 0, errorsmod.Wrap( types.ErrTickerNotFoundInMarketMap, ticker, ) diff --git a/protocol/x/prices/keeper/market_param.go b/protocol/x/prices/keeper/market_param.go index e62f92fc88..e364e3fcec 100644 --- a/protocol/x/prices/keeper/market_param.go +++ b/protocol/x/prices/keeper/market_param.go @@ -42,17 +42,17 @@ func (k Keeper) ModifyMarketParam( // Validate update is permitted. for _, market := range k.GetAllMarketParams(ctx) { if market.Pair == updatedMarketParam.Pair && market.Id != updatedMarketParam.Id { - return types.MarketParam{}, errorsmod.Wrapf(types.ErrMarketParamPairAlreadyExists, updatedMarketParam.Pair) + return types.MarketParam{}, errorsmod.Wrap(types.ErrMarketParamPairAlreadyExists, updatedMarketParam.Pair) } } // Validate that modified market param has a corresponding ticker in MarketMap cp, err := slinky.MarketPairToCurrencyPair(updatedMarketParam.Pair) if err != nil { - return types.MarketParam{}, errorsmod.Wrapf(types.ErrMarketPairConversionFailed, updatedMarketParam.Pair) + return types.MarketParam{}, errorsmod.Wrap(types.ErrMarketPairConversionFailed, updatedMarketParam.Pair) } if _, err := k.MarketMapKeeper.GetMarket(ctx, cp.String()); err != nil { - return types.MarketParam{}, errorsmod.Wrapf(types.ErrTickerNotFoundInMarketMap, cp.String()) + return types.MarketParam{}, errorsmod.Wrap(types.ErrTickerNotFoundInMarketMap, cp.String()) } // Store the modified market param. diff --git a/protocol/x/prices/keeper/market_param_test.go b/protocol/x/prices/keeper/market_param_test.go index 25c24d31a4..f74f07f18e 100644 --- a/protocol/x/prices/keeper/market_param_test.go +++ b/protocol/x/prices/keeper/market_param_test.go @@ -239,7 +239,7 @@ func TestModifyMarketParam_Errors(t *testing.T) { minExchanges: uint32(1), minPriceChangePpm: uint32(50), exchangeConfigJson: validExchangeConfigJson, - expectedErr: errorsmod.Wrapf( + expectedErr: errorsmod.Wrap( types.ErrTickerNotFoundInMarketMap, invalidUpdateCurrencyPair.String(), ).Error(), diff --git a/protocol/x/vault/keeper/orders.go b/protocol/x/vault/keeper/orders.go index 311bbbbe38..1129bb4651 100644 --- a/protocol/x/vault/keeper/orders.go +++ b/protocol/x/vault/keeper/orders.go @@ -45,7 +45,7 @@ func (k Keeper) RefreshAllVaultOrders(ctx sdk.Context) { vaultParams.QuotingParams = &defaultQuotingParams } vault := k.subaccountsKeeper.GetSubaccount(ctx, *vaultId.ToSubaccountId()) - if vault.PerpetualPositions == nil || len(vault.PerpetualPositions) == 0 { + if len(vault.PerpetualPositions) == 0 { if vault.GetUsdcPosition().Cmp(vaultParams.QuotingParams.ActivationThresholdQuoteQuantums.BigInt()) == -1 { continue } diff --git a/protocol/x/vest/types/vest_entry.go b/protocol/x/vest/types/vest_entry.go index b091be3aa5..2f6b4b4d2f 100644 --- a/protocol/x/vest/types/vest_entry.go +++ b/protocol/x/vest/types/vest_entry.go @@ -15,7 +15,7 @@ func (entry VestEntry) Validate() error { } if err := sdk.ValidateDenom(entry.Denom); err != nil { - return errorsmod.Wrapf(ErrInvalidDenom, err.Error()) + return errorsmod.Wrap(ErrInvalidDenom, err.Error()) } if !entry.StartTime.Before(entry.EndTime) { @@ -27,7 +27,7 @@ func (entry VestEntry) Validate() error { } if entry.EndTime.Location().String() != "UTC" { - return errorsmod.Wrapf(ErrInvalidTimeZone, "start_time must be in UTC") + return errorsmod.Wrapf(ErrInvalidTimeZone, "end_time must be in UTC") } return nil }