From 0ece567c31a59791bd166a0fed886cb667b0f594 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 17 Apr 2024 00:35:01 +0200 Subject: [PATCH] lint --- x/auction/keeper/keeper.go | 7 ------- x/oracle/keeper/historic_price.go | 22 +++++++++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/x/auction/keeper/keeper.go b/x/auction/keeper/keeper.go index 493abe3bde..8bfbf56ed9 100644 --- a/x/auction/keeper/keeper.go +++ b/x/auction/keeper/keeper.go @@ -2,8 +2,6 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/store" - prefixstore "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -53,14 +51,9 @@ type Keeper struct { bank auction.BankKeeper ugov ugov.WithEmergencyGroup - // TODO: ctx should be removed when we migrate leverage and oracle ctx *sdk.Context } -func (k Keeper) prefixStore(prefix []byte) store.KVStore { - return prefixstore.NewStore(k.store, prefix) -} - func (k Keeper) sendCoins(from, to sdk.AccAddress, amount sdk.Coins) error { return k.bank.SendCoins(*k.ctx, from, to, amount) } diff --git a/x/oracle/keeper/historic_price.go b/x/oracle/keeper/historic_price.go index c09903dc0b..7ec47804a2 100644 --- a/x/oracle/keeper/historic_price.go +++ b/x/oracle/keeper/historic_price.go @@ -9,6 +9,10 @@ import ( "github.com/umee-network/umee/v6/x/oracle/types" ) +func wrapDenomError(err error, denom string) error { + return errors.Wrap(err, "denom: "+denom) +} + // HistoricMedians returns a list of a given denom's last numStamps medians. func (k Keeper) HistoricMedians( ctx sdk.Context, @@ -45,7 +49,7 @@ func (k Keeper) CalcAndSetHistoricMedian( median, err := decmath.Median(historicPrices) if err != nil { - return errors.Wrap(err, "denom: "+denom) + return wrapDenomError(err, denom) } block := uint64(ctx.BlockHeight()) @@ -75,7 +79,7 @@ func (k Keeper) HistoricMedianDeviation( blockNum := uint64(ctx.BlockHeight()) - blockDiff bz := store.Get(types.KeyMedianDeviation(denom, blockNum)) if bz == nil { - return types.Price{}, types.ErrNoMedianDeviation.Wrap("denom: " + denom) + return types.Price{}, wrapDenomError(types.ErrNoMedianDeviation, denom) } decProto := sdk.DecProto{} @@ -93,14 +97,14 @@ func (k Keeper) WithinHistoricMedianDeviation( // get latest median medians := k.HistoricMedians(ctx, denom, 1) if len(medians) == 0 { - return false, types.ErrNoMedian.Wrap("denom: " + denom) + return false, wrapDenomError(types.ErrNoMedian, denom) } median := medians[0].ExchangeRateTuple.ExchangeRate // get latest historic price prices := k.historicPrices(ctx, denom, 1) if len(prices) == 0 { - return false, types.ErrNoHistoricPrice.Wrap("denom: " + denom) + return false, wrapDenomError(types.ErrNoHistoricPrice, denom) } price := prices[0] @@ -122,7 +126,7 @@ func (k Keeper) calcAndSetHistoricMedianDeviation( ) error { medianDeviation, err := decmath.MedianDeviation(median, prices) if err != nil { - return errors.Wrap(err, "denom: "+denom) + return wrapDenomError(err, denom) } block := uint64(ctx.BlockHeight()) @@ -155,7 +159,7 @@ func (k Keeper) MedianOfHistoricMedians( } median, err := decmath.Median(medians.Decs()) if err != nil { - return sdk.ZeroDec(), 0, errors.Wrap(err, "denom: "+denom) + return sdk.ZeroDec(), 0, wrapDenomError(err, denom) } return median, uint32(len(medians)), nil @@ -175,7 +179,7 @@ func (k Keeper) AverageOfHistoricMedians( } average, err := decmath.Average(medians.Decs()) if err != nil { - return sdk.ZeroDec(), 0, errors.Wrap(err, "denom: "+denom) + return sdk.ZeroDec(), 0, wrapDenomError(err, denom) } return average, uint32(len(medians)), nil @@ -195,7 +199,7 @@ func (k Keeper) MaxOfHistoricMedians( } max, err := decmath.Max(medians.Decs()) if err != nil { - return sdk.ZeroDec(), 0, errors.Wrap(err, "denom: "+denom) + return sdk.ZeroDec(), 0, wrapDenomError(err, denom) } return max, uint32(len(medians)), nil @@ -215,7 +219,7 @@ func (k Keeper) MinOfHistoricMedians( } min, err := decmath.Min(medians.Decs()) if err != nil { - return sdk.ZeroDec(), 0, errors.Wrap(err, "denom: "+denom) + return sdk.ZeroDec(), 0, wrapDenomError(err, denom) } return min, uint32(len(medians)), nil