Skip to content

Commit

Permalink
fix: deprecated use of sdkerrors
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Feb 6, 2023
1 parent 618dac8 commit e74d73e
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 151 deletions.
8 changes: 4 additions & 4 deletions app/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package app

import (
"cosmossdk.io/errors"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/group"
Expand Down Expand Up @@ -131,7 +131,7 @@ func (app *UmeeApp) registerUpgrade3_0(upgradeInfo upgradetypes.Plan) {
ctx.Logger().Info("Running setupBech32ibcKeeper")
err := upgradev3.SetupBech32ibcKeeper(&app.bech32IbcKeeper, ctx)
if err != nil {
return nil, sdkerrors.Wrapf(
return nil, errors.Wrapf(
err, "%q Upgrade: Unable to upgrade, bech32ibc module not initialized", planName)
}

Expand All @@ -144,7 +144,7 @@ func (app *UmeeApp) registerUpgrade3_0(upgradeInfo upgradetypes.Plan) {
ctx.Logger().Info("Updating validator minimum commission rate param of staking module")
minCommissionRate, err := upgradev3.UpdateMinimumCommissionRateParam(ctx, app.StakingKeeper)
if err != nil {
return vm, sdkerrors.Wrapf(
return vm, errors.Wrapf(
err, "%q Upgrade: failed to update minimum commission rate param of staking module",
planName)
}
Expand All @@ -153,7 +153,7 @@ func (app *UmeeApp) registerUpgrade3_0(upgradeInfo upgradetypes.Plan) {
"name", planName)
err = upgradev3.SetMinimumCommissionRateToValidators(ctx, app.StakingKeeper, minCommissionRate)
if err != nil {
return vm, sdkerrors.Wrapf(
return vm, errors.Wrapf(
err, "%q Upgrade: failed to update minimum commission rate for validators",
planName)
}
Expand Down
8 changes: 8 additions & 0 deletions util/checkers/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -56,3 +57,10 @@ func ValidateProposal(title, description, authority string) error {

return nil
}

func ValidateAddr(addr, name string) error {
if _, err := sdk.AccAddressFromBech32(addr); err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid %s address: %s", name, err)
}
return nil
}
22 changes: 11 additions & 11 deletions x/incentive/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ package incentive
// DONTCOVER

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"cosmossdk.io/errors"
)

var (
// 0 = TODO
ErrNotImplemented = sdkerrors.Register(ModuleName, 0, "not implemented")
ErrNotImplemented = errors.Register(ModuleName, 0, "not implemented")

// 1XX = General
ErrInvalidProgramID = sdkerrors.Register(ModuleName, 100, "invalid program ID")
ErrNilAsset = sdkerrors.Register(ModuleName, 101, "nil asset")
ErrInvalidTier = sdkerrors.Register(ModuleName, 102, "invalid unbonding tier")
ErrEmptyAddress = sdkerrors.Register(ModuleName, 103, "empty address")
ErrInvalidProgramID = errors.Register(ModuleName, 100, "invalid program ID")
ErrNilAsset = errors.Register(ModuleName, 101, "nil asset")
ErrInvalidTier = errors.Register(ModuleName, 102, "invalid unbonding tier")
ErrEmptyAddress = errors.Register(ModuleName, 103, "empty address")

// 2XX = Params
ErrUnbondingTierOrder = sdkerrors.Register(ModuleName, 200, "unbonding tier lock durations out of order")
ErrUnbondingWeightOrder = sdkerrors.Register(ModuleName, 201, "unbonding tier weights out of order")
ErrUnbondingTierOrder = errors.Register(ModuleName, 200, "unbonding tier lock durations out of order")
ErrUnbondingWeightOrder = errors.Register(ModuleName, 201, "unbonding tier weights out of order")

// 3XX = Gov Proposal
ErrNonzeroRemainingRewards = sdkerrors.Register(ModuleName, 300, "remaining rewards must be zero in proposal")
ErrNonzeroFundedRewards = sdkerrors.Register(ModuleName, 301, "funded rewards must be zero in proposal")
ErrEmptyProposal = sdkerrors.Register(ModuleName, 302, "proposal contains no incentive programs")
ErrNonzeroRemainingRewards = errors.Register(ModuleName, 300, "remaining rewards must be zero in proposal")
ErrNonzeroFundedRewards = errors.Register(ModuleName, 301, "funded rewards must be zero in proposal")
ErrEmptyProposal = errors.Register(ModuleName, 302, "proposal contains no incentive programs")
)
4 changes: 2 additions & 2 deletions x/incentive/msgs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package incentive

import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/umee-network/umee/v4/util/checkers"
leveragetypes "github.com/umee-network/umee/v4/x/leverage/types"
Expand Down Expand Up @@ -249,7 +249,7 @@ func (ip IncentiveProgram) Validate() error {
}
if !leveragetypes.HasUTokenPrefix(ip.Denom) {
// only allow uToken denoms
return sdkerrors.Wrap(leveragetypes.ErrNotUToken, ip.Denom)
return errors.Wrap(leveragetypes.ErrNotUToken, ip.Denom)
}

// TODO #1749: Finish validate logic
Expand Down
5 changes: 2 additions & 3 deletions x/leverage/keeper/exchange_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/umee-network/umee/v4/x/leverage/types"
)
Expand All @@ -16,7 +15,7 @@ func (k Keeper) ExchangeToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error)

uTokenDenom := types.ToUTokenDenom(token.Denom)
if uTokenDenom == "" {
return sdk.Coin{}, sdkerrors.Wrap(types.ErrUToken, token.Denom)
return sdk.Coin{}, types.ErrUToken.Wrap(token.Denom)
}

exchangeRate := k.DeriveExchangeRate(ctx, token.Denom)
Expand All @@ -34,7 +33,7 @@ func (k Keeper) ExchangeUToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, erro

tokenDenom := types.ToTokenDenom(uToken.Denom)
if tokenDenom == "" {
return sdk.Coin{}, sdkerrors.Wrap(types.ErrNotUToken, uToken.Denom)
return sdk.Coin{}, types.ErrNotUToken.Wrap(uToken.Denom)
}

exchangeRate := k.DeriveExchangeRate(ctx, tokenDenom)
Expand Down
3 changes: 1 addition & 2 deletions x/leverage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -126,7 +125,7 @@ func (k Keeper) Withdraw(ctx sdk.Context, supplierAddr sdk.AccAddress, uToken sd
// Ensure module account has sufficient unreserved tokens to withdraw
availableAmount := k.AvailableLiquidity(ctx, token.Denom)
if token.Amount.GT(availableAmount) {
return sdk.Coin{}, sdkerrors.Wrap(types.ErrLendingPoolInsufficient, token.String())
return sdk.Coin{}, types.ErrLendingPoolInsufficient.Wrap(token.String())
}

// Withdraw will first attempt to use any uTokens in the supplier's wallet
Expand Down
11 changes: 5 additions & 6 deletions x/leverage/keeper/oracle.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package keeper

import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/umee-network/umee/v4/util/sdkutil"
oracletypes "github.com/umee-network/umee/v4/x/oracle/types"

"github.com/umee-network/umee/v4/x/leverage/types"
oracletypes "github.com/umee-network/umee/v4/x/oracle/types"
)

var ten = sdk.MustNewDecFromStr("10")
Expand All @@ -34,7 +33,7 @@ func (k Keeper) TokenPrice(ctx sdk.Context, baseDenom string, mode types.PriceMo
// spot price is required for modes other than historic
spotPrice, err = k.oracleKeeper.GetExchangeRate(ctx, t.SymbolDenom)
if err != nil {
return sdk.ZeroDec(), t.Exponent, sdkerrors.Wrap(err, "oracle")
return sdk.ZeroDec(), t.Exponent, errors.Wrap(err, "oracle")
}
}
if mode != types.PriceModeSpot {
Expand All @@ -43,7 +42,7 @@ func (k Keeper) TokenPrice(ctx sdk.Context, baseDenom string, mode types.PriceMo
historicPrice, numStamps, err = k.oracleKeeper.MedianOfHistoricMedians(
ctx, t.SymbolDenom, uint64(t.HistoricMedians))
if err != nil {
return sdk.ZeroDec(), t.Exponent, sdkerrors.Wrap(err, "oracle")
return sdk.ZeroDec(), t.Exponent, errors.Wrap(err, "oracle")
}
if numStamps < t.HistoricMedians {
return sdk.ZeroDec(), t.Exponent, types.ErrNoHistoricMedians.Wrapf(
Expand All @@ -68,7 +67,7 @@ func (k Keeper) TokenPrice(ctx sdk.Context, baseDenom string, mode types.PriceMo
}

if price.IsNil() || !price.IsPositive() {
return sdk.ZeroDec(), t.Exponent, sdkerrors.Wrap(types.ErrInvalidOraclePrice, baseDenom)
return sdk.ZeroDec(), t.Exponent, types.ErrInvalidOraclePrice.Wrap(baseDenom)
}

return price, t.Exponent, nil
Expand Down
3 changes: 1 addition & 2 deletions x/leverage/keeper/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/umee-network/umee/v4/x/leverage/types"
)

Expand Down Expand Up @@ -33,7 +32,7 @@ func (k Keeper) GetTokenSettings(ctx sdk.Context, denom string) (types.Token, er
token := types.Token{}
bz := store.Get(tokenKey)
if len(bz) == 0 {
return token, sdkerrors.Wrap(types.ErrNotRegisteredToken, denom)
return token, types.ErrNotRegisteredToken.Wrap(denom)
}

err := k.cdc.Unmarshal(bz, &token)
Expand Down
72 changes: 36 additions & 36 deletions x/leverage/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,57 @@ package types
// DONTCOVER

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"cosmossdk.io/errors"
)

var (
// 1XX = General Validation
ErrEmptyAddress = sdkerrors.Register(ModuleName, 100, "empty address")
ErrNilAsset = sdkerrors.Register(ModuleName, 101, "nil asset")
ErrGetAmount = sdkerrors.Register(ModuleName, 102, "retrieved invalid amount")
ErrSetAmount = sdkerrors.Register(ModuleName, 103, "cannot set invalid amount")
ErrInvalidPriceMode = sdkerrors.Register(ModuleName, 104, "invalid price mode")
ErrEmptyAddress = errors.Register(ModuleName, 100, "empty address")
ErrNilAsset = errors.Register(ModuleName, 101, "nil asset")
ErrGetAmount = errors.Register(ModuleName, 102, "retrieved invalid amount")
ErrSetAmount = errors.Register(ModuleName, 103, "cannot set invalid amount")
ErrInvalidPriceMode = errors.Register(ModuleName, 104, "invalid price mode")

// 2XX = Token Registry
ErrNotRegisteredToken = sdkerrors.Register(ModuleName, 200, "not a registered Token")
ErrUToken = sdkerrors.Register(ModuleName, 201, "denom should not be a uToken")
ErrNotUToken = sdkerrors.Register(ModuleName, 202, "denom should be a uToken")
ErrSupplyNotAllowed = sdkerrors.Register(ModuleName, 203, "supplying of Token disabled")
ErrBorrowNotAllowed = sdkerrors.Register(ModuleName, 204, "borrowing of Token disabled")
ErrBlacklisted = sdkerrors.Register(ModuleName, 205, "blacklisted Token")
ErrDuplicateToken = sdkerrors.Register(ModuleName, 207, "duplicate token")
ErrCollateralWeightZero = sdkerrors.Register(ModuleName, 206,
ErrNotRegisteredToken = errors.Register(ModuleName, 200, "not a registered Token")
ErrUToken = errors.Register(ModuleName, 201, "denom should not be a uToken")
ErrNotUToken = errors.Register(ModuleName, 202, "denom should be a uToken")
ErrSupplyNotAllowed = errors.Register(ModuleName, 203, "supplying of Token disabled")
ErrBorrowNotAllowed = errors.Register(ModuleName, 204, "borrowing of Token disabled")
ErrBlacklisted = errors.Register(ModuleName, 205, "blacklisted Token")
ErrDuplicateToken = errors.Register(ModuleName, 207, "duplicate token")
ErrCollateralWeightZero = errors.Register(ModuleName, 206,
"collateral weight of Token is zero: can't be used as a collateral")

// 3XX = User Positions
ErrInsufficientBalance = sdkerrors.Register(ModuleName, 300, "insufficient balance")
ErrInsufficientCollateral = sdkerrors.Register(ModuleName, 301, "insufficient collateral")
ErrLiquidationRepayZero = sdkerrors.Register(ModuleName, 303, "liquidation would repay zero tokens")
ErrInsufficientBalance = errors.Register(ModuleName, 300, "insufficient balance")
ErrInsufficientCollateral = errors.Register(ModuleName, 301, "insufficient collateral")
ErrLiquidationRepayZero = errors.Register(ModuleName, 303, "liquidation would repay zero tokens")

// 4XX = Price Sensitive
ErrBadValue = sdkerrors.Register(ModuleName, 400, "bad USD value")
ErrInvalidOraclePrice = sdkerrors.Register(ModuleName, 401, "invalid oracle price")
ErrUndercollaterized = sdkerrors.Register(ModuleName, 402, "borrow positions are undercollaterized")
ErrLiquidationIneligible = sdkerrors.Register(ModuleName, 403, "borrower not eligible for liquidation")
ErrNoHistoricMedians = sdkerrors.Register(ModuleName, 405, "insufficient historic medians available")
ErrBadValue = errors.Register(ModuleName, 400, "bad USD value")
ErrInvalidOraclePrice = errors.Register(ModuleName, 401, "invalid oracle price")
ErrUndercollaterized = errors.Register(ModuleName, 402, "borrow positions are undercollaterized")
ErrLiquidationIneligible = errors.Register(ModuleName, 403, "borrower not eligible for liquidation")
ErrNoHistoricMedians = errors.Register(ModuleName, 405, "insufficient historic medians available")

// 5XX = Market Conditions
ErrLendingPoolInsufficient = sdkerrors.Register(ModuleName, 500, "lending pool insufficient")
ErrMaxSupplyUtilization = sdkerrors.Register(ModuleName, 501, "market would exceed MaxSupplyUtilization")
ErrMinCollateralLiquidity = sdkerrors.Register(ModuleName, 502, "market would fall below MinCollateralLiquidity")
ErrMaxCollateralShare = sdkerrors.Register(ModuleName, 503, "market would exceed MaxCollateralShare")
ErrMaxSupply = sdkerrors.Register(ModuleName, 504, "market would exceed MaxSupply")
ErrLendingPoolInsufficient = errors.Register(ModuleName, 500, "lending pool insufficient")
ErrMaxSupplyUtilization = errors.Register(ModuleName, 501, "market would exceed MaxSupplyUtilization")
ErrMinCollateralLiquidity = errors.Register(ModuleName, 502, "market would fall below MinCollateralLiquidity")
ErrMaxCollateralShare = errors.Register(ModuleName, 503, "market would exceed MaxCollateralShare")
ErrMaxSupply = errors.Register(ModuleName, 504, "market would exceed MaxSupply")

// 6XX = Internal Failsafes
ErrInvalidUtilization = sdkerrors.Register(ModuleName, 600, "invalid token utilization")
ErrNegativeTotalBorrowed = sdkerrors.Register(ModuleName, 601, "total borrowed was negative")
ErrNegativeAPY = sdkerrors.Register(ModuleName, 602, "negative APY")
ErrNegativeTimeElapsed = sdkerrors.Register(ModuleName, 603, "negative time elapsed since last interest time")
ErrInvalidExchangeRate = sdkerrors.Register(ModuleName, 604, "exchange rate less than one")
ErrInconsistentTotalBorrow = sdkerrors.Register(ModuleName, 605, "total adjusted borrow inconsistency")
ErrExcessiveTimeElapsed = sdkerrors.Register(ModuleName, 606, "excessive time elapsed since last interest time")
ErrInvalidUtilization = errors.Register(ModuleName, 600, "invalid token utilization")
ErrNegativeTotalBorrowed = errors.Register(ModuleName, 601, "total borrowed was negative")
ErrNegativeAPY = errors.Register(ModuleName, 602, "negative APY")
ErrNegativeTimeElapsed = errors.Register(ModuleName, 603, "negative time elapsed since last interest time")
ErrInvalidExchangeRate = errors.Register(ModuleName, 604, "exchange rate less than one")
ErrInconsistentTotalBorrow = errors.Register(ModuleName, 605, "total adjusted borrow inconsistency")
ErrExcessiveTimeElapsed = errors.Register(ModuleName, 606, "excessive time elapsed since last interest time")

// 7XX = Disabled Functionality
ErrNotLiquidatorNode = sdkerrors.Register(ModuleName, 700, "node has disabled liquidator queries")
ErrNotImplemented = sdkerrors.Register(ModuleName, 701, "not implemented")
ErrNotLiquidatorNode = errors.Register(ModuleName, 700, "node has disabled liquidator queries")
ErrNotImplemented = errors.Register(ModuleName, 701, "not implemented")
)
3 changes: 1 addition & 2 deletions x/leverage/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// NewGenesisState creates a new GenesisState object
Expand Down Expand Up @@ -95,7 +94,7 @@ func (gs GenesisState) Validate() error {
}

if rate.Scalar.LT(sdk.OneDec()) {
return sdkerrors.Wrap(ErrInvalidExchangeRate, rate.String())
return ErrInvalidExchangeRate.Wrap(rate.String())
}
}

Expand Down
8 changes: 4 additions & 4 deletions x/leverage/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package types

import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/umee-network/umee/v4/util/checkers"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -42,7 +42,7 @@ func (msg MsgGovUpdateRegistry) ValidateBasic() error {

for _, token := range msg.AddTokens {
if err := token.Validate(); err != nil {
return sdkerrors.Wrap(err, "token")
return errors.Wrap(err, "token")
}
}

Expand All @@ -52,7 +52,7 @@ func (msg MsgGovUpdateRegistry) ValidateBasic() error {

for _, token := range msg.UpdateTokens {
if err := token.Validate(); err != nil {
return sdkerrors.Wrap(err, "token")
return errors.Wrap(err, "token")
}
}

Expand All @@ -75,7 +75,7 @@ func validateRegistryTokenDenoms(tokens []Token) error {
tokenDenoms := map[string]bool{}
for _, token := range tokens {
if _, ok := tokenDenoms[token.BaseDenom]; ok {
return sdkerrors.Wrapf(ErrDuplicateToken, "duplicate token with baseDenom %s", token.BaseDenom)
return ErrDuplicateToken.Wrapf("duplicate token with baseDenom %s", token.BaseDenom)
}
tokenDenoms[token.BaseDenom] = true
}
Expand Down
6 changes: 3 additions & 3 deletions x/leverage/types/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,23 @@ func (t Token) Validate() error {
// AssertSupplyEnabled returns an error if a Token cannot be supplied.
func (t Token) AssertSupplyEnabled() error {
if !t.EnableMsgSupply {
return sdkerrors.Wrap(ErrSupplyNotAllowed, t.BaseDenom)
return ErrSupplyNotAllowed.Wrap(t.BaseDenom)
}
return nil
}

// AssertBorrowEnabled returns an error if a Token cannot be borrowed.
func (t Token) AssertBorrowEnabled() error {
if !t.EnableMsgBorrow {
return sdkerrors.Wrap(ErrBorrowNotAllowed, t.BaseDenom)
return ErrBorrowNotAllowed.Wrap(t.BaseDenom)
}
return nil
}

// AssertNotBlacklisted returns an error if a Token is blacklisted.
func (t Token) AssertNotBlacklisted() error {
if t.Blacklist {
return sdkerrors.Wrap(ErrBlacklisted, t.BaseDenom)
return ErrBlacklisted.Wrap(t.BaseDenom)
}
return nil
}
Expand Down
Loading

0 comments on commit e74d73e

Please sign in to comment.