diff --git a/app/upgrades/README.md b/app/upgrades/README.md index 1f79eeb0f1..752a6fc3d3 100644 --- a/app/upgrades/README.md +++ b/app/upgrades/README.md @@ -124,7 +124,7 @@ func CreateUpgradeHandler( ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { if err := {module}migration.MigrateStore(ctx, {module}StoreKey, cdc); err != nil { - return vm, sdkerrors.Wrapf(err, "unable to migrate {module} store") + return vm, errorsmod.Wrapf(err, "unable to migrate {module} store") } vm[{moduleName}] = mm.GetVersionMap()[{moduleName}] return mm.RunMigrations(ctx, configurator, vm) diff --git a/app/upgrades/v5/upgrades.go b/app/upgrades/v5/upgrades.go index f917052aeb..a544bc0b78 100644 --- a/app/upgrades/v5/upgrades.go +++ b/app/upgrades/v5/upgrades.go @@ -6,7 +6,8 @@ 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" + + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/types/module" authz "github.com/cosmos/cosmos-sdk/x/authz" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" @@ -71,22 +72,22 @@ func CreateUpgradeHandler( // - stakeibc logModuleMigration(ctx, currentVersions, claimtypes.ModuleName) if err := claimmigration.MigrateStore(ctx, claimStoreKey, cdc); err != nil { - return vm, sdkerrors.Wrapf(err, "unable to migrate claim store") + return vm, errorsmod.Wrapf(err, "unable to migrate claim store") } logModuleMigration(ctx, currentVersions, icacallbacktypes.ModuleName) if err := icacallbacksmigration.MigrateStore(ctx, icacallbackStorekey, cdc); err != nil { - return vm, sdkerrors.Wrapf(err, "unable to migrate icacallbacks store") + return vm, errorsmod.Wrapf(err, "unable to migrate icacallbacks store") } logModuleMigration(ctx, currentVersions, recordtypes.ModuleName) if err := recordsmigration.MigrateStore(ctx, recordStoreKey, cdc); err != nil { - return vm, sdkerrors.Wrapf(err, "unable to migrate records store") + return vm, errorsmod.Wrapf(err, "unable to migrate records store") } logModuleMigration(ctx, currentVersions, stakeibctypes.ModuleName) if err := stakeibcmigration.MigrateStore(ctx, stakeibcStoreKey, cdc); err != nil { - return vm, sdkerrors.Wrapf(err, "unable to migrate stakeibc store") + return vm, errorsmod.Wrapf(err, "unable to migrate stakeibc store") } // `RunMigrations` (below) checks the old consensus version of each module (found in diff --git a/cmd/strided/config/config.go b/cmd/strided/config/config.go index e99db4c91b..f5cc6903f2 100644 --- a/cmd/strided/config/config.go +++ b/cmd/strided/config/config.go @@ -3,6 +3,8 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/version" ) @@ -74,16 +76,16 @@ func SetAddressPrefixes(config *sdk.Config) { // source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141 config.SetAddressVerifier(func(bytes []byte) error { if len(bytes) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty") + return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty") } if len(bytes) > address.MaxAddrLen { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes)) + return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes)) } // TODO: Do we want to allow addresses of lengths other than 20 and 32 bytes? if len(bytes) != 20 && len(bytes) != 32 { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes)) + return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes)) } return nil diff --git a/utils/utils.go b/utils/utils.go index 0f6642ef06..c2fa4cdce8 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/cosmos-sdk/types/bech32" + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -35,7 +36,7 @@ func Int64ToCoinString(amount int64, denom string) string { func ValidateAdminAddress(address string) error { if !Admins[address] { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator address (%s)", address)) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator address (%s)", address)) } return nil } @@ -106,11 +107,11 @@ func VerifyAddressFormat(bz []byte) error { } if len(bz) == 0 { - return sdkerrors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty") + return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty") } if len(bz) > address.MaxAddrLen { - return sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bz)) + return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bz)) } return nil diff --git a/x/claim/handler.go b/x/claim/handler.go index f1563d8c9f..8dbf2e84a3 100644 --- a/x/claim/handler.go +++ b/x/claim/handler.go @@ -3,6 +3,7 @@ package claim import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -31,7 +32,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { return sdk.WrapServiceResult(ctx, res, err) default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } } diff --git a/x/claim/keeper/claim.go b/x/claim/keeper/claim.go index 611c90fb07..11ffd11649 100644 --- a/x/claim/keeper/claim.go +++ b/x/claim/keeper/claim.go @@ -9,6 +9,8 @@ import ( sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authvestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -150,7 +152,7 @@ func (k Keeper) GetAirdropByIdentifier(ctx sdk.Context, airdropIdentifier string func (k Keeper) GetDistributorAccountBalance(ctx sdk.Context, airdropIdentifier string) (sdk.Coin, error) { airdrop := k.GetAirdropByIdentifier(ctx, airdropIdentifier) if airdrop == nil { - return sdk.Coin{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid airdrop identifier: GetDistributorAccountBalance") + return sdk.Coin{}, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid airdrop identifier: GetDistributorAccountBalance") } addr, err := k.GetAirdropDistributor(ctx, airdropIdentifier) @@ -331,7 +333,7 @@ func (k Keeper) SetClaimRecord(ctx sdk.Context, claimRecord types.ClaimRecord) e func (k Keeper) GetAirdropDistributor(ctx sdk.Context, airdropIdentifier string) (sdk.AccAddress, error) { airdrop := k.GetAirdropByIdentifier(ctx, airdropIdentifier) if airdrop == nil { - return sdk.AccAddress{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid airdrop identifier: GetAirdropDistributor") + return sdk.AccAddress{}, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid airdrop identifier: GetAirdropDistributor") } return sdk.AccAddressFromBech32(airdrop.DistributorAddress) } @@ -340,7 +342,7 @@ func (k Keeper) GetAirdropDistributor(ctx sdk.Context, airdropIdentifier string) func (k Keeper) GetAirdropClaimDenom(ctx sdk.Context, airdropIdentifier string) (string, error) { airdrop := k.GetAirdropByIdentifier(ctx, airdropIdentifier) if airdrop == nil { - return "", sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: GetAirdropClaimDenom") + return "", errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: GetAirdropClaimDenom") } return airdrop.ClaimDenom, nil } @@ -457,7 +459,7 @@ func (k Keeper) AfterClaim(ctx sdk.Context, airdropIdentifier string, claimAmoun // fetch the airdrop airdrop := k.GetAirdropByIdentifier(ctx, airdropIdentifier) if airdrop == nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: AfterClaim") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: AfterClaim") } // increment the claimed so far err := k.IncrementClaimedSoFar(ctx, airdropIdentifier, claimAmount) @@ -486,7 +488,7 @@ func (k Keeper) ClaimAllCoinsForAction(ctx sdk.Context, addr sdk.AccAddress, act func (k Keeper) ClaimCoinsForAction(ctx sdk.Context, addr sdk.AccAddress, action types.Action, airdropIdentifier string) (sdk.Coins, error) { isPassed := k.IsInitialPeriodPassed(ctx, airdropIdentifier) if airdropIdentifier == "" { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: ClaimCoinsForAction") + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: ClaimCoinsForAction") } claimableAmount, err := k.GetClaimableAmountForAction(ctx, addr, action, airdropIdentifier, false) @@ -519,7 +521,7 @@ func (k Keeper) ClaimCoinsForAction(ctx sdk.Context, addr sdk.AccAddress, action // Convert user account into stride veting account. baseAccount := k.accountKeeper.NewAccountWithAddress(ctx, addr) if _, ok := baseAccount.(*authtypes.BaseAccount); !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount) } periodLength := GetAirdropDurationForAction(action) @@ -562,7 +564,7 @@ func (k Keeper) ClaimCoinsForAction(ctx sdk.Context, addr sdk.AccAddress, action airdrop := k.GetAirdropByIdentifier(ctx, airdropIdentifier) if airdrop == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: ClaimCoinsForAction") + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid airdrop identifier: ClaimCoinsForAction") } err = k.AfterClaim(ctx, airdropIdentifier, claimableAmount.AmountOf(airdrop.ClaimDenom)) if err != nil { diff --git a/x/claim/keeper/msg_server.go b/x/claim/keeper/msg_server.go index 8b4682f65e..6da0be6157 100644 --- a/x/claim/keeper/msg_server.go +++ b/x/claim/keeper/msg_server.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/Stride-Labs/stride/v5/x/claim/types" @@ -41,7 +42,7 @@ func (server msgServer) SetAirdropAllocations(goCtx context.Context, msg *types. } if !addr.Equals(airdropDistributor) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address") + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address") } users, weights := server.keeper.GetUnallocatedUsers(ctx, msg.AirdropIdentifier, msg.Users, msg.Weights) @@ -117,7 +118,7 @@ func (server msgServer) DeleteAirdrop(goCtx context.Context, msg *types.MsgDelet } if !addr.Equals(distributor) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address") + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address") } err = server.keeper.DeleteAirdropAndEpoch(ctx, msg.Identifier) diff --git a/x/claim/keeper/query.go b/x/claim/keeper/query.go index 774dfd00e6..91e967285a 100644 --- a/x/claim/keeper/query.go +++ b/x/claim/keeper/query.go @@ -3,6 +3,8 @@ package keeper import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/Stride-Labs/stride/v5/x/claim/types" @@ -20,7 +22,7 @@ func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier { switch path[0] { default: - err = sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) + err = errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) } return res, err diff --git a/x/claim/migrations/v2/migrations.go b/x/claim/migrations/v2/migrations.go index 7fcc5761b6..1c5e63f588 100644 --- a/x/claim/migrations/v2/migrations.go +++ b/x/claim/migrations/v2/migrations.go @@ -4,7 +4,8 @@ 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" + + errorsmod "cosmossdk.io/errors" oldclaimtypes "github.com/Stride-Labs/stride/v5/x/claim/migrations/v2/types" claimtypes "github.com/Stride-Labs/stride/v5/x/claim/types" @@ -16,14 +17,14 @@ func migrateClaimParams(store sdk.KVStore, cdc codec.Codec) error { var oldParams oldclaimtypes.Params err := cdc.UnmarshalJSON(oldParamsBz, &oldParams) if err != nil { - return sdkerrors.Wrapf(err, "unable to unmarshal claims params using old data types") + return errorsmod.Wrapf(err, "unable to unmarshal claims params using old data types") } // Convert and serialize using the new type newParams := convertToNewClaimParams(oldParams) newParamsBz, err := cdc.MarshalJSON(&newParams) if err != nil { - return sdkerrors.Wrapf(err, "unable to marshal claims params using new data types") + return errorsmod.Wrapf(err, "unable to marshal claims params using new data types") } // Store new type diff --git a/x/claim/types/errors.go b/x/claim/types/errors.go index e90b22e756..7ced131f99 100644 --- a/x/claim/types/errors.go +++ b/x/claim/types/errors.go @@ -2,24 +2,22 @@ package types // DONTCOVER -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) +import errorsmod "cosmossdk.io/errors" // x/claim module sentinel errors var ( - ErrTotalWeightNotSet = sdkerrors.Register(ModuleName, 1101, + ErrTotalWeightNotSet = errorsmod.Register(ModuleName, 1101, "total weight not set") - ErrTotalWeightParse = sdkerrors.Register(ModuleName, 1102, + ErrTotalWeightParse = errorsmod.Register(ModuleName, 1102, "total weight parse error") - ErrFailedToGetTotalWeight = sdkerrors.Register(ModuleName, 1104, + ErrFailedToGetTotalWeight = errorsmod.Register(ModuleName, 1104, "failed to get total weight") - ErrFailedToParseDec = sdkerrors.Register(ModuleName, 1105, + ErrFailedToParseDec = errorsmod.Register(ModuleName, 1105, "failed to parse dec from str") - ErrAirdropAlreadyExists = sdkerrors.Register(ModuleName, 1106, + ErrAirdropAlreadyExists = errorsmod.Register(ModuleName, 1106, "airdrop with same identifier already exists") - ErrDistributorAlreadyExists = sdkerrors.Register(ModuleName, 1107, + ErrDistributorAlreadyExists = errorsmod.Register(ModuleName, 1107, "airdrop with same distributor already exists") - ErrInvalidAmount = sdkerrors.Register(ModuleName, 1108, + ErrInvalidAmount = errorsmod.Register(ModuleName, 1108, "cannot claim negative tokens") ) diff --git a/x/claim/types/msgs.go b/x/claim/types/msgs.go index acd1e45e05..24018212b7 100644 --- a/x/claim/types/msgs.go +++ b/x/claim/types/msgs.go @@ -1,6 +1,7 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -45,40 +46,40 @@ func (msg *MsgSetAirdropAllocations) GetSignBytes() []byte { func (msg *MsgSetAirdropAllocations) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Allocator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid allocator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid allocator address (%s)", err) } if msg.AirdropIdentifier == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop identifier not set") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop identifier not set") } if len(msg.Users) == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "empty users list") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "empty users list") } if len(msg.Weights) == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "empty weights list") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "empty weights list") } if len(msg.Users) != len(msg.Weights) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "different length") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "different length") } for _, user := range msg.Users { strideAddr := utils.ConvertAddressToStrideAddress(user) if strideAddr == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid bech32 address") + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid bech32 address") } _, err := sdk.AccAddressFromBech32(strideAddr) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid user address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid user address (%s)", err) } } for _, weight := range msg.Weights { if weight.Equal(sdk.NewDec(0)) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid user weight") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid user weight") } } @@ -121,7 +122,7 @@ func (msg *MsgClaimFreeAmount) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.User) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid user address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid user address (%s)", err) } return nil @@ -166,19 +167,19 @@ func (msg *MsgCreateAirdrop) GetSignBytes() []byte { func (msg *MsgCreateAirdrop) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Distributor) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address (%s)", err) } if msg.Identifier == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop identifier not set") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop identifier not set") } if msg.StartTime == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop start time not set") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop start time not set") } if msg.Duration == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop duration not set") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop duration not set") } return nil } @@ -219,11 +220,11 @@ func (msg *MsgDeleteAirdrop) GetSignBytes() []byte { func (msg *MsgDeleteAirdrop) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Distributor) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid distributor address (%s)", err) } if msg.Identifier == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop identifier not set") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "airdrop identifier not set") } return nil } diff --git a/x/claim/vesting/handler.go b/x/claim/vesting/handler.go index 889e9d1c24..7b618a21a4 100644 --- a/x/claim/vesting/handler.go +++ b/x/claim/vesting/handler.go @@ -1,6 +1,7 @@ package vesting import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/keeper" @@ -13,7 +14,7 @@ func NewHandler(ak keeper.AccountKeeper, bk types.BankKeeper) sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { switch msg := msg.(type) { default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) } } } diff --git a/x/epochs/handler.go b/x/epochs/handler.go index 7e14f4668f..6c752a2fa7 100644 --- a/x/epochs/handler.go +++ b/x/epochs/handler.go @@ -3,6 +3,7 @@ package epochs import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -14,6 +15,6 @@ import ( func NewHandler(k keeper.Keeper) sdk.Handler { return func(_ sdk.Context, msg sdk.Msg) (*sdk.Result, error) { errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } diff --git a/x/icacallbacks/handler.go b/x/icacallbacks/handler.go index 64d2d30fe3..2e5a1b1fae 100644 --- a/x/icacallbacks/handler.go +++ b/x/icacallbacks/handler.go @@ -3,6 +3,7 @@ package icacallbacks import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -22,7 +23,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { // this line is used by starport scaffolding # 1 default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } } diff --git a/x/icacallbacks/icacallbacks.go b/x/icacallbacks/icacallbacks.go index ab977fcec4..e8a58b80e9 100644 --- a/x/icacallbacks/icacallbacks.go +++ b/x/icacallbacks/icacallbacks.go @@ -3,6 +3,7 @@ package icacallbacks import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" @@ -20,7 +21,7 @@ import ( func ParseTxMsgData(acknowledgementResult []byte) ([][]byte, error) { txMsgData := &sdk.TxMsgData{} if err := proto.Unmarshal(acknowledgementResult, txMsgData); err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %s", err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 tx message data: %s", err.Error()) } // Unpack all the message responses based on the sdk version (determined from the length of txMsgData.Data) @@ -51,7 +52,7 @@ func UnpackAcknowledgementResponse(ctx sdk.Context, logger log.Logger, ack []byt // Unmarshal the raw ack response var acknowledgement channeltypes.Acknowledgement if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(ack, &acknowledgement); err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %s", err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %s", err.Error()) } // The ack can come back as either AcknowledgementResult or AcknowledgementError @@ -59,7 +60,7 @@ func UnpackAcknowledgementResponse(ctx sdk.Context, logger log.Logger, ack []byt switch response := acknowledgement.Response.(type) { case *channeltypes.Acknowledgement_Result: if len(response.Result) == 0 { - return nil, sdkerrors.Wrapf(channeltypes.ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") + return nil, errorsmod.Wrapf(channeltypes.ErrInvalidAcknowledgement, "acknowledgement result cannot be empty") } // If this is an ack from a non-ICA transaction (e.g. an IBC transfer), there is no need to decode the data field @@ -71,7 +72,7 @@ func UnpackAcknowledgementResponse(ctx sdk.Context, logger log.Logger, ack []byt // Otherwise, if this ack is from an ICA, unmarshal the message data from within the ack msgResponses, err := ParseTxMsgData(acknowledgement.GetResult()) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot parse TxMsgData from ICA acknowledgement packet: %s", err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot parse TxMsgData from ICA acknowledgement packet: %s", err.Error()) } return &types.AcknowledgementResponse{Status: types.AckResponseStatus_SUCCESS, MsgResponses: msgResponses}, nil @@ -79,6 +80,6 @@ func UnpackAcknowledgementResponse(ctx sdk.Context, logger log.Logger, ack []byt logger.Error(fmt.Sprintf("acknowledgement error: %s", response.Error)) return &types.AcknowledgementResponse{Status: types.AckResponseStatus_FAILURE, Error: response.Error}, nil default: - return nil, sdkerrors.Wrapf(channeltypes.ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", response) + return nil, errorsmod.Wrapf(channeltypes.ErrInvalidAcknowledgement, "unsupported acknowledgement response field type %T", response) } } diff --git a/x/icacallbacks/keeper/keeper.go b/x/icacallbacks/keeper/keeper.go index 428060f271..11ee5664da 100644 --- a/x/icacallbacks/keeper/keeper.go +++ b/x/icacallbacks/keeper/keeper.go @@ -7,7 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + errorsmod "cosmossdk.io/errors" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" @@ -118,7 +119,7 @@ func (k Keeper) GetICACallbackHandlerFromPacket(ctx sdk.Context, modulePacket ch // fetch the callback function callbackHandler, err := k.GetICACallbackHandler(module) if err != nil { - return nil, sdkerrors.Wrapf(types.ErrCallbackHandlerNotFound, "Callback handler does not exist for module %s | err: %s", module, err.Error()) + return nil, errorsmod.Wrapf(types.ErrCallbackHandlerNotFound, "Callback handler does not exist for module %s | err: %s", module, err.Error()) } return &callbackHandler, nil } @@ -143,7 +144,7 @@ func (k Keeper) CallRegisteredICACallback(ctx sdk.Context, modulePacket channelt if err != nil { errMsg := fmt.Sprintf("Error occured while calling ICACallback (%s) | err: %s", callbackData.CallbackId, err.Error()) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(types.ErrCallbackFailed, errMsg) + return errorsmod.Wrapf(types.ErrCallbackFailed, errMsg) } } else { k.Logger(ctx).Error(fmt.Sprintf("Callback %v has no associated callback", callbackData)) diff --git a/x/icacallbacks/migrations/v2/convert.go b/x/icacallbacks/migrations/v2/convert.go index f2af975ffb..018fd7ccaa 100644 --- a/x/icacallbacks/migrations/v2/convert.go +++ b/x/icacallbacks/migrations/v2/convert.go @@ -1,8 +1,8 @@ package v2 import ( + errorsmod "cosmossdk.io/errors" sdkmath "cosmossdk.io/math" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/golang/protobuf/proto" //nolint:staticcheck icacallbacktypes "github.com/Stride-Labs/stride/v5/x/icacallbacks/types" @@ -74,14 +74,14 @@ func convertCallbackData(oldCallbackData icacallbacktypes.CallbackData) (icacall // Deserialize the callback args with the old DelegateCallback type oldDelegateCallback := oldstakeibctypes.DelegateCallback{} if err := proto.Unmarshal(oldCallbackData.CallbackArgs, &oldDelegateCallback); err != nil { - return icacallbacktypes.CallbackData{}, sdkerrors.Wrapf(stakeibctypes.ErrUnmarshalFailure, err.Error()) + return icacallbacktypes.CallbackData{}, errorsmod.Wrapf(stakeibctypes.ErrUnmarshalFailure, err.Error()) } // Convert and serialize with the new DelegateCallback type newDelegateCallback := convertDelegateCallback(oldDelegateCallback) newDelegateCallbackBz, err := proto.Marshal(&newDelegateCallback) if err != nil { - return icacallbacktypes.CallbackData{}, sdkerrors.Wrapf(stakeibctypes.ErrMarshalFailure, err.Error()) + return icacallbacktypes.CallbackData{}, errorsmod.Wrapf(stakeibctypes.ErrMarshalFailure, err.Error()) } // Update the CallbackData with the new args @@ -91,14 +91,14 @@ func convertCallbackData(oldCallbackData icacallbacktypes.CallbackData) (icacall // Deserialize the callback args with the old UndelegateCallback type oldUndelegateCallback := oldstakeibctypes.UndelegateCallback{} if err := proto.Unmarshal(oldCallbackData.CallbackArgs, &oldUndelegateCallback); err != nil { - return icacallbacktypes.CallbackData{}, sdkerrors.Wrapf(stakeibctypes.ErrUnmarshalFailure, err.Error()) + return icacallbacktypes.CallbackData{}, errorsmod.Wrapf(stakeibctypes.ErrUnmarshalFailure, err.Error()) } // Convert and serialize with the new UndelegateCallback type newUndelegateCallback := convertUndelegateCallback(oldUndelegateCallback) newUndelegateCallbackBz, err := proto.Marshal(&newUndelegateCallback) if err != nil { - return icacallbacktypes.CallbackData{}, sdkerrors.Wrapf(stakeibctypes.ErrMarshalFailure, err.Error()) + return icacallbacktypes.CallbackData{}, errorsmod.Wrapf(stakeibctypes.ErrMarshalFailure, err.Error()) } // Update the CallbackData with the new args @@ -108,14 +108,14 @@ func convertCallbackData(oldCallbackData icacallbacktypes.CallbackData) (icacall // Deserialize the callback args with the old RebalanceCallback type oldRebalanceCallback := oldstakeibctypes.RebalanceCallback{} if err := proto.Unmarshal(oldCallbackData.CallbackArgs, &oldRebalanceCallback); err != nil { - return icacallbacktypes.CallbackData{}, sdkerrors.Wrapf(stakeibctypes.ErrUnmarshalFailure, err.Error()) + return icacallbacktypes.CallbackData{}, errorsmod.Wrapf(stakeibctypes.ErrUnmarshalFailure, err.Error()) } // Convert and serialize with the new RebalanceCallback type newRebalanceCallback := convertRebalanceCallback(oldRebalanceCallback) newRebalanceCallbackBz, err := proto.Marshal(&newRebalanceCallback) if err != nil { - return icacallbacktypes.CallbackData{}, sdkerrors.Wrapf(stakeibctypes.ErrMarshalFailure, err.Error()) + return icacallbacktypes.CallbackData{}, errorsmod.Wrapf(stakeibctypes.ErrMarshalFailure, err.Error()) } // Update the CallbackData with the new args diff --git a/x/icacallbacks/migrations/v2/migrations.go b/x/icacallbacks/migrations/v2/migrations.go index a0787ef49a..08bb490f8e 100644 --- a/x/icacallbacks/migrations/v2/migrations.go +++ b/x/icacallbacks/migrations/v2/migrations.go @@ -5,7 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + errorsmod "cosmossdk.io/errors" icacallbacktypes "github.com/Stride-Labs/stride/v5/x/icacallbacks/types" ) @@ -22,18 +23,18 @@ func migrateCallbacks(store sdk.KVStore, cdc codec.BinaryCodec) error { var oldCallbackData icacallbacktypes.CallbackData err := cdc.Unmarshal(iter.Value(), &oldCallbackData) if err != nil { - return sdkerrors.Wrapf(err, "unable to unmarshal callback data") + return errorsmod.Wrapf(err, "unable to unmarshal callback data") } // Convert the callback data // This will only convert the callback data args, of which the serialization has changed newCallbackData, err := convertCallbackData(oldCallbackData) if err != nil { - return sdkerrors.Wrapf(err, "unable to convert callback data to new schema") + return errorsmod.Wrapf(err, "unable to convert callback data to new schema") } newCallbackDataBz, err := cdc.Marshal(&newCallbackData) if err != nil { - return sdkerrors.Wrapf(err, "unable to marshal callback data") + return errorsmod.Wrapf(err, "unable to marshal callback data") } // Set new value on store. diff --git a/x/icacallbacks/types/errors.go b/x/icacallbacks/types/errors.go index d1c6a264c8..3c5abf81c7 100644 --- a/x/icacallbacks/types/errors.go +++ b/x/icacallbacks/types/errors.go @@ -2,19 +2,17 @@ package types // DONTCOVER -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) +import errorsmod "cosmossdk.io/errors" // x/icacallbacks module sentinel errors var ( - ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error") - ErrInvalidPacketTimeout = sdkerrors.Register(ModuleName, 1500, "invalid packet timeout") - ErrInvalidVersion = sdkerrors.Register(ModuleName, 1501, "invalid version") - ErrCallbackHandlerNotFound = sdkerrors.Register(ModuleName, 1502, "icacallback handler not found") - ErrCallbackIdNotFound = sdkerrors.Register(ModuleName, 1503, "icacallback ID not found") - ErrCallbackFailed = sdkerrors.Register(ModuleName, 1504, "icacallback failed") - ErrCallbackDataNotFound = sdkerrors.Register(ModuleName, 1505, "icacallback data not found") - ErrTxMsgData = sdkerrors.Register(ModuleName, 1506, "txMsgData fetch failed") - ErrInvalidAcknowledgement = sdkerrors.Register(ModuleName, 1507, "invalid acknowledgement") + ErrSample = errorsmod.Register(ModuleName, 1100, "sample error") + ErrInvalidPacketTimeout = errorsmod.Register(ModuleName, 1500, "invalid packet timeout") + ErrInvalidVersion = errorsmod.Register(ModuleName, 1501, "invalid version") + ErrCallbackHandlerNotFound = errorsmod.Register(ModuleName, 1502, "icacallback handler not found") + ErrCallbackIdNotFound = errorsmod.Register(ModuleName, 1503, "icacallback ID not found") + ErrCallbackFailed = errorsmod.Register(ModuleName, 1504, "icacallback failed") + ErrCallbackDataNotFound = errorsmod.Register(ModuleName, 1505, "icacallback data not found") + ErrTxMsgData = errorsmod.Register(ModuleName, 1506, "txMsgData fetch failed") + ErrInvalidAcknowledgement = errorsmod.Register(ModuleName, 1507, "invalid acknowledgement") ) diff --git a/x/interchainquery/handler.go b/x/interchainquery/handler.go index 7e6b4f615d..bb27c594f8 100644 --- a/x/interchainquery/handler.go +++ b/x/interchainquery/handler.go @@ -3,6 +3,7 @@ package interchainquery import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -14,6 +15,6 @@ import ( func NewHandler(k keeper.Keeper) sdk.Handler { return func(_ sdk.Context, msg sdk.Msg) (*sdk.Result, error) { errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } diff --git a/x/interchainquery/keeper/keeper.go b/x/interchainquery/keeper/keeper.go index c9db6f7278..a05e4ba5af 100644 --- a/x/interchainquery/keeper/keeper.go +++ b/x/interchainquery/keeper/keeper.go @@ -6,6 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" "github.com/tendermint/tendermint/libs/log" @@ -56,17 +58,17 @@ func (k *Keeper) MakeRequest(ctx sdk.Context, module string, callbackId string, if connectionId == "" { errMsg := "[ICQ Validation Check] Failed! connection id cannot be empty" k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) } if !strings.HasPrefix(connectionId, "connection") { errMsg := "[ICQ Validation Check] Failed! connection id must begin with 'connection'" k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) } if chainId == "" { errMsg := "[ICQ Validation Check] Failed! chain_id cannot be empty" k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) } // Confirm the module and callbackId exist @@ -74,12 +76,12 @@ func (k *Keeper) MakeRequest(ctx sdk.Context, module string, callbackId string, if _, exists := k.callbacks[module]; !exists { err := fmt.Errorf("no callback handler registered for module %s", module) k.Logger(ctx).Error(err.Error()) - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "no callback handler registered for module") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "no callback handler registered for module") } if exists := k.callbacks[module].HasICQCallback(callbackId); !exists { err := fmt.Errorf("no callback %s registered for module %s", callbackId, module) k.Logger(ctx).Error(err.Error()) - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "no callback handler registered for module") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "no callback handler registered for module") } } diff --git a/x/interchainquery/keeper/msg_server.go b/x/interchainquery/keeper/msg_server.go index 92d1a765ee..c743482ba5 100644 --- a/x/interchainquery/keeper/msg_server.go +++ b/x/interchainquery/keeper/msg_server.go @@ -6,8 +6,8 @@ import ( "sort" "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v5/modules/core/23-commitment/types" tmclienttypes "github.com/cosmos/ibc-go/v5/modules/light-clients/07-tendermint/types" @@ -40,7 +40,7 @@ func (k Keeper) VerifyKeyProof(ctx sdk.Context, msg *types.MsgSubmitQueryRespons // If the query is a "key" proof query, verify the results are valid by checking the poof if msg.ProofOps == nil { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "Unable to validate proof. No proof submitted") + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to validate proof. No proof submitted") } // Get the client consensus state at the height 1 block above the message height @@ -53,39 +53,39 @@ func (k Keeper) VerifyKeyProof(ctx sdk.Context, msg *types.MsgSubmitQueryRespons // Get the client state and consensus state from the connection Id connection, found := k.IBCKeeper.ConnectionKeeper.GetConnection(ctx, query.ConnectionId) if !found { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "ConnectionId %s does not exist", query.ConnectionId) + return errorsmod.Wrapf(types.ErrInvalidICQProof, "ConnectionId %s does not exist", query.ConnectionId) } consensusState, found := k.IBCKeeper.ClientKeeper.GetClientConsensusState(ctx, connection.ClientId, height) if !found { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "Consensus state not found for client %s and height %d", connection.ClientId, height) + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Consensus state not found for client %s and height %d", connection.ClientId, height) } clientState, found := k.IBCKeeper.ClientKeeper.GetClientState(ctx, connection.ClientId) if !found { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "Unable to fetch client state for client %s", connection.ClientId) + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to fetch client state for client %s", connection.ClientId) } tmClientState, ok := clientState.(*tmclienttypes.ClientState) if !ok { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "Client state is not tendermint") + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Client state is not tendermint") } // Get the merkle path and merkle proof path := commitmenttypes.NewMerklePath([]string{pathParts[1], url.PathEscape(string(query.Request))}...) merkleProof, err := commitmenttypes.ConvertProofs(msg.ProofOps) if err != nil { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "Error converting proofs: %s", err.Error()) + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Error converting proofs: %s", err.Error()) } // If we got a non-nil response, verify inclusion proof if len(msg.Result) != 0 { if err := merkleProof.VerifyMembership(tmClientState.ProofSpecs, consensusState.GetRoot(), path, msg.Result); err != nil { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "Unable to verify membership proof: %s", err.Error()) + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to verify membership proof: %s", err.Error()) } k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(query.ChainId, query.CallbackId, "Inclusion proof validated - QueryId %s", query.Id)) } else { // if we got a nil query response, verify non inclusion proof. if err := merkleProof.VerifyNonMembership(tmClientState.ProofSpecs, consensusState.GetRoot(), path); err != nil { - return sdkerrors.Wrapf(types.ErrInvalidICQProof, "Unable to verify non-membership proof: %s", err.Error()) + return errorsmod.Wrapf(types.ErrInvalidICQProof, "Unable to verify non-membership proof: %s", err.Error()) } k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(query.ChainId, query.CallbackId, "Non-inclusion proof validated - QueryId %s", query.Id)) } diff --git a/x/interchainquery/types/msgs.go b/x/interchainquery/types/msgs.go index 3c2feecfc3..055a7c71bc 100644 --- a/x/interchainquery/types/msgs.go +++ b/x/interchainquery/types/msgs.go @@ -1,6 +1,7 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -23,11 +24,11 @@ func (msg MsgSubmitQueryResponse) ValidateBasic() error { // check from address _, err := sdk.AccAddressFromBech32(msg.FromAddress) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid fromAddress in ICQ response (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid fromAddress in ICQ response (%s)", err) } // check chain_id is not empty if msg.ChainId == "" { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "chain_id cannot be empty in ICQ response") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "chain_id cannot be empty in ICQ response") } return nil diff --git a/x/mint/keeper/keeper.go b/x/mint/keeper/keeper.go index bb98a3d511..971fa1e8f4 100644 --- a/x/mint/keeper/keeper.go +++ b/x/mint/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/cast" "github.com/tendermint/tendermint/libs/log" + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -166,7 +167,7 @@ func (k Keeper) DistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin) error if err != nil { errMsg := fmt.Sprintf("invalid strategic reserve address: %s", StrategicReserveAddress) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, errMsg) } strategicReserveProportion := k.GetProportions(ctx, mintedCoin, proportions.StrategicReserve) strategicReserveCoins := sdk.NewCoins(strategicReserveProportion) @@ -197,7 +198,7 @@ func (k Keeper) DistributeMintedCoin(ctx sdk.Context, mintedCoin sdk.Coin) error if sdk.NewDecFromInt(remainingBal).Quo(sdk.NewDecFromInt(mintedCoin.Amount)).GT(thresh) { errMsg := fmt.Sprintf("Failed to divvy up mint module rewards fully -- remaining coins should be LT 5pct of total, instead are %#v/%#v", remainingCoins, remainingBal) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, errMsg) + return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, errMsg) } err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, stakingIncentivesCoins) diff --git a/x/records/handler.go b/x/records/handler.go index 9fa7369888..907d9ec09f 100644 --- a/x/records/handler.go +++ b/x/records/handler.go @@ -3,6 +3,7 @@ package records import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -22,7 +23,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { // this line is used by starport scaffolding # 1 default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } } diff --git a/x/records/keeper/callback_transfer.go b/x/records/keeper/callback_transfer.go index 96cd65d5c0..8c96f99c51 100644 --- a/x/records/keeper/callback_transfer.go +++ b/x/records/keeper/callback_transfer.go @@ -8,6 +8,7 @@ import ( icacallbackstypes "github.com/Stride-Labs/stride/v5/x/icacallbacks/types" "github.com/Stride-Labs/stride/v5/x/records/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -38,13 +39,13 @@ func TransferCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ack // deserialize the args transferCallbackData, err := k.UnmarshalTransferCallbackArgs(ctx, args) if err != nil { - return sdkerrors.Wrapf(types.ErrUnmarshalFailure, "cannot unmarshal transfer callback args: %s", err.Error()) + return errorsmod.Wrapf(types.ErrUnmarshalFailure, "cannot unmarshal transfer callback args: %s", err.Error()) } k.Logger(ctx).Info(fmt.Sprintf("TransferCallback %v", transferCallbackData)) depositRecord, found := k.GetDepositRecord(ctx, transferCallbackData.DepositRecordId) if !found { k.Logger(ctx).Error(fmt.Sprintf("TransferCallback deposit record not found, packet %v", packet)) - return sdkerrors.Wrapf(types.ErrUnknownDepositRecord, "deposit record not found %d", transferCallbackData.DepositRecordId) + return errorsmod.Wrapf(types.ErrUnknownDepositRecord, "deposit record not found %d", transferCallbackData.DepositRecordId) } if ackResponse.Status == icacallbackstypes.AckResponseStatus_TIMEOUT { @@ -68,7 +69,7 @@ func TransferCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ack var data ibctransfertypes.FungibleTokenPacketData if err := ibctransfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { k.Logger(ctx).Error(fmt.Sprintf("Error unmarshalling packet %v", err.Error())) - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error()) } k.Logger(ctx).Info(fmt.Sprintf("TransferCallback unmarshalled FungibleTokenPacketData %v", data)) diff --git a/x/records/keeper/epoch_unbonding_record.go b/x/records/keeper/epoch_unbonding_record.go index a0bb7e316a..5424153cdf 100644 --- a/x/records/keeper/epoch_unbonding_record.go +++ b/x/records/keeper/epoch_unbonding_record.go @@ -6,7 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + errorsmod "cosmossdk.io/errors" stakeibctypes "github.com/Stride-Labs/stride/v5/x/stakeibc/types" @@ -129,7 +130,7 @@ func (k Keeper) SetHostZoneUnbondings(ctx sdk.Context, chainId string, epochUnbo if !found { errMsg := fmt.Sprintf("Error fetching host zone unbonding record for epoch: %d, host zone: %s", epochUnbondingRecordId, chainId) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(stakeibctypes.ErrHostZoneNotFound, errMsg) + return errorsmod.Wrapf(stakeibctypes.ErrHostZoneNotFound, errMsg) } hostZoneUnbonding.Status = status // save the updated hzu on the epoch unbonding record @@ -137,7 +138,7 @@ func (k Keeper) SetHostZoneUnbondings(ctx sdk.Context, chainId string, epochUnbo if !success { errMsg := fmt.Sprintf("Error adding host zone unbonding record to epoch unbonding record: %d, host zone: %s", epochUnbondingRecordId, chainId) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrap(types.ErrAddingHostZone, errMsg) + return errorsmod.Wrap(types.ErrAddingHostZone, errMsg) } k.SetEpochUnbondingRecord(ctx, *updatedRecord) } diff --git a/x/records/keeper/grpc_query_deposit_record.go b/x/records/keeper/grpc_query_deposit_record.go index 6a6dc578ed..fa0c477576 100644 --- a/x/records/keeper/grpc_query_deposit_record.go +++ b/x/records/keeper/grpc_query_deposit_record.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" diff --git a/x/records/keeper/grpc_query_epoch_unbonding_record.go b/x/records/keeper/grpc_query_epoch_unbonding_record.go index 833d0879be..645fa9657c 100644 --- a/x/records/keeper/grpc_query_epoch_unbonding_record.go +++ b/x/records/keeper/grpc_query_epoch_unbonding_record.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" diff --git a/x/records/keeper/grpc_query_user_redemption_record.go b/x/records/keeper/grpc_query_user_redemption_record.go index 04957713d6..f0735d199f 100644 --- a/x/records/keeper/grpc_query_user_redemption_record.go +++ b/x/records/keeper/grpc_query_user_redemption_record.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" diff --git a/x/records/keeper/grpc_query_user_redemption_record_for_user.go b/x/records/keeper/grpc_query_user_redemption_record_for_user.go index 8a860d1c9b..cbe5d6d65c 100644 --- a/x/records/keeper/grpc_query_user_redemption_record_for_user.go +++ b/x/records/keeper/grpc_query_user_redemption_record_for_user.go @@ -3,6 +3,7 @@ package keeper import ( "context" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "google.golang.org/grpc/codes" @@ -19,7 +20,7 @@ func (k Keeper) UserRedemptionRecordForUser(c context.Context, req *types.QueryA // validate the address _, err := sdk.AccAddressFromBech32(req.Address) if err != nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, req.Address) + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, req.Address) } var userRedemptionRecords []types.UserRedemptionRecord diff --git a/x/records/migrations/v2/migrations.go b/x/records/migrations/v2/migrations.go index 13a019c8b1..751a32ddc4 100644 --- a/x/records/migrations/v2/migrations.go +++ b/x/records/migrations/v2/migrations.go @@ -5,7 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + errorsmod "cosmossdk.io/errors" oldrecordtypes "github.com/Stride-Labs/stride/v5/x/records/migrations/v2/types" recordtypes "github.com/Stride-Labs/stride/v5/x/records/types" @@ -22,14 +23,14 @@ func migrateDepositRecord(store sdk.KVStore, cdc codec.BinaryCodec) error { var oldDepositRecord oldrecordtypes.DepositRecord err := cdc.Unmarshal(iterator.Value(), &oldDepositRecord) if err != nil { - return sdkerrors.Wrapf(err, "unable to unmarshal deposit record (%v) using old data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to unmarshal deposit record (%v) using old data type", iterator.Key()) } // Convert and serialize using the new type newDepositRecord := convertToNewDepositRecord(oldDepositRecord) newDepositRecordBz, err := cdc.Marshal(&newDepositRecord) if err != nil { - return sdkerrors.Wrapf(err, "unable to marshal deposit record (%v) using new data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to marshal deposit record (%v) using new data type", iterator.Key()) } // Store the new type @@ -50,14 +51,14 @@ func migrateUserRedemptionRecord(store sdk.KVStore, cdc codec.BinaryCodec) error var oldRedemptionRecord oldrecordtypes.UserRedemptionRecord err := cdc.Unmarshal(iterator.Value(), &oldRedemptionRecord) if err != nil { - return sdkerrors.Wrapf(err, "unable to unmarshal redemption record (%v) using old data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to unmarshal redemption record (%v) using old data type", iterator.Key()) } // Convert and serialize using the new type newRedemptionRecord := convertToNewUserRedemptionRecord(oldRedemptionRecord) newRedemptionRecordBz, err := cdc.Marshal(&newRedemptionRecord) if err != nil { - return sdkerrors.Wrapf(err, "unable to marshal redemption record (%v) using new data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to marshal redemption record (%v) using new data type", iterator.Key()) } // Store the new type @@ -78,14 +79,14 @@ func migrateEpochUnbondingRecord(store sdk.KVStore, cdc codec.BinaryCodec) error var oldEpochUnbondingRecord oldrecordtypes.EpochUnbondingRecord err := cdc.Unmarshal(iterator.Value(), &oldEpochUnbondingRecord) if err != nil { - return sdkerrors.Wrapf(err, "unable to unmarshal epoch unbonding record (%v) using old data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to unmarshal epoch unbonding record (%v) using old data type", iterator.Key()) } // Convert and serialize using the new type newEpochUnbondingRecord := convertToNewEpochUnbondingRecord(oldEpochUnbondingRecord) newEpochUnbondingRecordBz, err := cdc.Marshal(&newEpochUnbondingRecord) if err != nil { - return sdkerrors.Wrapf(err, "unable to marshal epoch unbonding record (%v) using new data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to marshal epoch unbonding record (%v) using new data type", iterator.Key()) } // Store the new type diff --git a/x/records/module_ibc.go b/x/records/module_ibc.go index d1a4d94aaf..1be2b1f9cb 100644 --- a/x/records/module_ibc.go +++ b/x/records/module_ibc.go @@ -3,6 +3,7 @@ package records import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" @@ -173,7 +174,7 @@ func (im IBCModule) OnAcknowledgementPacket( errMsg := fmt.Sprintf("Unable to unpack message data from acknowledgement, Sequence %d, from %s %s, to %s %s: %s", packet.Sequence, packet.SourceChannel, packet.SourcePort, packet.DestinationChannel, packet.DestinationPort, err.Error()) im.keeper.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(icacallbacktypes.ErrInvalidAcknowledgement, errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrInvalidAcknowledgement, errMsg) } // Custom ack logic only applies to ibc transfers initiated from the `stakeibc` module account @@ -183,7 +184,7 @@ func (im IBCModule) OnAcknowledgementPacket( errMsg := fmt.Sprintf("Unable to call registered callback from records OnAcknowledgePacket | Sequence %d, from %s %s, to %s %s | Error %s", packet.Sequence, packet.SourceChannel, packet.SourcePort, packet.DestinationChannel, packet.DestinationPort, err.Error()) im.keeper.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(icacallbacktypes.ErrCallbackFailed, errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrCallbackFailed, errMsg) } return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer) @@ -244,7 +245,7 @@ func (am AppModule) OnChanOpenInit( counterparty channeltypes.Counterparty, version string, ) (string, error) { - return "", sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") + return "", errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") } // OnChanOpenTry implements the IBCModule interface @@ -259,7 +260,7 @@ func (am AppModule) OnChanOpenTry( version, counterpartyVersion string, ) error { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") } // OnChanOpenAck implements the IBCModule interface @@ -269,7 +270,7 @@ func (am AppModule) OnChanOpenAck( channelID string, counterpartyVersion string, ) error { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") } // OnChanOpenConfirm implements the IBCModule interface @@ -278,7 +279,7 @@ func (am AppModule) OnChanOpenConfirm( portID, channelID string, ) error { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") } // OnChanCloseInit implements the IBCModule interface @@ -288,7 +289,7 @@ func (am AppModule) OnChanCloseInit( channelID string, ) error { // Disallow user-initiated channel closing for channels - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "user cannot close channel") } // OnChanCloseConfirm implements the IBCModule interface @@ -297,7 +298,7 @@ func (am AppModule) OnChanCloseConfirm( portID, channelID string, ) error { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") } // OnRecvPacket implements the IBCModule interface @@ -317,7 +318,7 @@ func (am AppModule) OnAcknowledgementPacket( acknowledgement []byte, relayer sdk.AccAddress, ) error { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "UNIMPLEMENTED") } // OnTimeoutPacket implements the IBCModule interface diff --git a/x/records/types/errors.go b/x/records/types/errors.go index 76b4d4a241..12326a6404 100644 --- a/x/records/types/errors.go +++ b/x/records/types/errors.go @@ -2,16 +2,14 @@ package types // DONTCOVER -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) +import errorsmod "cosmossdk.io/errors" // x/records module sentinel errors var ( - ErrInvalidVersion = sdkerrors.Register(ModuleName, 1501, "invalid version") - ErrRedemptionAlreadyExists = sdkerrors.Register(ModuleName, 1502, "redemption record already exists") - ErrEpochUnbondingRecordNotFound = sdkerrors.Register(ModuleName, 1503, "epoch unbonding record not found") - ErrUnknownDepositRecord = sdkerrors.Register(ModuleName, 1504, "unknown deposit record") - ErrUnmarshalFailure = sdkerrors.Register(ModuleName, 1505, "cannot unmarshal") - ErrAddingHostZone = sdkerrors.Register(ModuleName, 1506, "could not add hzu to epoch unbonding record") + ErrInvalidVersion = errorsmod.Register(ModuleName, 1501, "invalid version") + ErrRedemptionAlreadyExists = errorsmod.Register(ModuleName, 1502, "redemption record already exists") + ErrEpochUnbondingRecordNotFound = errorsmod.Register(ModuleName, 1503, "epoch unbonding record not found") + ErrUnknownDepositRecord = errorsmod.Register(ModuleName, 1504, "unknown deposit record") + ErrUnmarshalFailure = errorsmod.Register(ModuleName, 1505, "cannot unmarshal") + ErrAddingHostZone = errorsmod.Register(ModuleName, 1506, "could not add hzu to epoch unbonding record") ) diff --git a/x/stakeibc/client/cli/tx_add_validator_proposal.go b/x/stakeibc/client/cli/tx_add_validator_proposal.go index 464633113e..308bf0d0da 100644 --- a/x/stakeibc/client/cli/tx_add_validator_proposal.go +++ b/x/stakeibc/client/cli/tx_add_validator_proposal.go @@ -10,6 +10,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/version" govcli "github.com/cosmos/cosmos-sdk/x/gov/client/cli" @@ -94,7 +96,7 @@ Where proposal.json contains: } if len(deposit) != 1 || deposit.GetDenomByIndex(0) != strideDenom { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "Deposit token denom must be %s", strideDenom) + return errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "Deposit token denom must be %s", strideDenom) } msg, err := govtypes.NewMsgSubmitProposal(&proposal, deposit, from) diff --git a/x/stakeibc/client/cli/tx_clear_balance.go b/x/stakeibc/client/cli/tx_clear_balance.go index c71dc38602..b65ffca184 100644 --- a/x/stakeibc/client/cli/tx_clear_balance.go +++ b/x/stakeibc/client/cli/tx_clear_balance.go @@ -7,6 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cobra" @@ -24,7 +26,7 @@ func CmdClearBalance() *cobra.Command { argChainId := args[0] argAmount, found := sdk.NewIntFromString(args[1]) if !found { - return sdkerrors.Wrap(sdkerrors.ErrInvalidType, "can not convert string to int") + return errorsmod.Wrap(sdkerrors.ErrInvalidType, "can not convert string to int") } argChannelId := args[2] diff --git a/x/stakeibc/client/cli/tx_liquid_stake.go b/x/stakeibc/client/cli/tx_liquid_stake.go index 204eb0b61d..14d81a4912 100644 --- a/x/stakeibc/client/cli/tx_liquid_stake.go +++ b/x/stakeibc/client/cli/tx_liquid_stake.go @@ -7,6 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cobra" @@ -23,7 +25,7 @@ func CmdLiquidStake() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) (err error) { argAmount, found := sdk.NewIntFromString(args[0]) if !found { - return sdkerrors.Wrap(sdkerrors.ErrInvalidType, "can not convert string to int") + return errorsmod.Wrap(sdkerrors.ErrInvalidType, "can not convert string to int") } argHostDenom := args[1] diff --git a/x/stakeibc/client/cli/tx_redeem_stake.go b/x/stakeibc/client/cli/tx_redeem_stake.go index 10cea52c5c..29839e1611 100644 --- a/x/stakeibc/client/cli/tx_redeem_stake.go +++ b/x/stakeibc/client/cli/tx_redeem_stake.go @@ -7,6 +7,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cobra" @@ -23,7 +25,7 @@ func CmdRedeemStake() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { argAmount, found := sdk.NewIntFromString(args[0]) if !found { - return sdkerrors.Wrap(sdkerrors.ErrInvalidType, "can not convert string to int") + return errorsmod.Wrap(sdkerrors.ErrInvalidType, "can not convert string to int") } hostZoneID := args[1] diff --git a/x/stakeibc/handler.go b/x/stakeibc/handler.go index 716d86a992..7d3b008d71 100644 --- a/x/stakeibc/handler.go +++ b/x/stakeibc/handler.go @@ -3,6 +3,7 @@ package stakeibc import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -57,7 +58,7 @@ func NewHandler(k keeper.Keeper) sdk.Handler { // this line is used by starport scaffolding # 1 default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, errorsmod.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } } @@ -81,7 +82,7 @@ func NewAddValidatorProposalHandler(k keeper.Keeper) govtypes.Handler { return nil default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized addValidator proposal content type: %T", c) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized addValidator proposal content type: %T", c) } } } diff --git a/x/stakeibc/keeper/grpc_query_host_zone.go b/x/stakeibc/keeper/grpc_query_host_zone.go index a266bc6cc7..ddf5ff4cce 100644 --- a/x/stakeibc/keeper/grpc_query_host_zone.go +++ b/x/stakeibc/keeper/grpc_query_host_zone.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" "google.golang.org/grpc/codes" diff --git a/x/stakeibc/keeper/host_zone.go b/x/stakeibc/keeper/host_zone.go index 2ac840db64..458334ee5c 100644 --- a/x/stakeibc/keeper/host_zone.go +++ b/x/stakeibc/keeper/host_zone.go @@ -9,6 +9,8 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/Stride-Labs/stride/v5/utils" @@ -46,7 +48,7 @@ func (k Keeper) GetHostZoneFromHostDenom(ctx sdk.Context, denom string) (*types. if matchZone.ChainId != "" { return &matchZone, nil } - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "No HostZone for %s found", denom) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "No HostZone for %s found", denom) } // RemoveHostZone removes a hostZone from the store @@ -104,13 +106,13 @@ func (k Keeper) AddValidatorToHostZone(ctx sdk.Context, msg *types.MsgAddValidat if !found { errMsg := fmt.Sprintf("Host Zone (%s) not found", msg.HostZone) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrap(types.ErrHostZoneNotFound, errMsg) + return errorsmod.Wrap(types.ErrHostZoneNotFound, errMsg) } // Get max number of validators and confirm we won't exceed it err := k.ConfirmValSetHasSpace(ctx, hostZone.Validators) if err != nil { - return sdkerrors.Wrap(types.ErrMaxNumValidators, "cannot add validator on host zone") + return errorsmod.Wrap(types.ErrMaxNumValidators, "cannot add validator on host zone") } // Check that we don't already have this validator @@ -120,12 +122,12 @@ func (k Keeper) AddValidatorToHostZone(ctx sdk.Context, msg *types.MsgAddValidat if validator.Address == msg.Address { errMsg := fmt.Sprintf("Validator address (%s) already exists on Host Zone (%s)", msg.Address, msg.HostZone) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrap(types.ErrValidatorAlreadyExists, errMsg) + return errorsmod.Wrap(types.ErrValidatorAlreadyExists, errMsg) } if validator.Name == msg.Name { errMsg := fmt.Sprintf("Validator name (%s) already exists on Host Zone (%s)", msg.Name, msg.HostZone) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrap(types.ErrValidatorAlreadyExists, errMsg) + return errorsmod.Wrap(types.ErrValidatorAlreadyExists, errMsg) } // Store the min weight to assign to new validator added through governance (ignore zero-weight validators) if validator.Weight < minWeight && validator.Weight > 0 { @@ -161,7 +163,7 @@ func (k Keeper) RemoveValidatorFromHostZone(ctx sdk.Context, chainId string, val if !found { errMsg := fmt.Sprintf("HostZone (%s) not found", chainId) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(types.ErrHostZoneNotFound, errMsg) + return errorsmod.Wrapf(types.ErrHostZoneNotFound, errMsg) } for i, val := range hostZone.Validators { if val.GetAddress() == validatorAddress { @@ -177,7 +179,7 @@ func (k Keeper) RemoveValidatorFromHostZone(ctx sdk.Context, chainId string, val } errMsg := fmt.Sprintf("Validator address (%s) not found on host zone (%s)", validatorAddress, chainId) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(types.ErrValidatorNotFound, errMsg) + return errorsmod.Wrapf(types.ErrValidatorNotFound, errMsg) } // Get a validator and its index from a list of validators, by address @@ -203,7 +205,7 @@ func (k Keeper) GetHostZoneFromIBCDenom(ctx sdk.Context, denom string) (*types.H if matchZone.ChainId != "" { return &matchZone, nil } - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "No HostZone for %s found", denom) + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "No HostZone for %s found", denom) } // IterateHostZones iterates zones diff --git a/x/stakeibc/keeper/icacallbacks_claim.go b/x/stakeibc/keeper/icacallbacks_claim.go index bf29f02c81..45a12c9f88 100644 --- a/x/stakeibc/keeper/icacallbacks_claim.go +++ b/x/stakeibc/keeper/icacallbacks_claim.go @@ -8,8 +8,8 @@ import ( recordstypes "github.com/Stride-Labs/stride/v5/x/records/types" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" "github.com/golang/protobuf/proto" //nolint:staticcheck ) @@ -43,7 +43,7 @@ func ClaimCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackRes // Fetch callback args claimCallback, err := k.UnmarshalClaimCallbackArgs(ctx, args) if err != nil { - return sdkerrors.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal claim callback args: %s", err.Error())) + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal claim callback args: %s", err.Error())) } chainId := claimCallback.ChainId k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Claim, @@ -52,7 +52,7 @@ func ClaimCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ackRes // Grab the associated user redemption record userRedemptionRecord, found := k.RecordsKeeper.GetUserRedemptionRecord(ctx, claimCallback.GetUserRedemptionRecordId()) if !found { - return sdkerrors.Wrapf(types.ErrRecordNotFound, "user redemption record not found %s", claimCallback.GetUserRedemptionRecordId()) + return errorsmod.Wrapf(types.ErrRecordNotFound, "user redemption record not found %s", claimCallback.GetUserRedemptionRecordId()) } // Check for a timeout @@ -98,7 +98,7 @@ func (k Keeper) DecrementHostZoneUnbonding(ctx sdk.Context, userRedemptionRecord // fetch the hzu associated with the user unbonding record hostZoneUnbonding, found := k.RecordsKeeper.GetHostZoneUnbondingByChainId(ctx, callbackArgs.EpochNumber, callbackArgs.ChainId) if !found { - return sdkerrors.Wrapf(types.ErrRecordNotFound, "host zone unbonding not found %s", callbackArgs.ChainId) + return errorsmod.Wrapf(types.ErrRecordNotFound, "host zone unbonding not found %s", callbackArgs.ChainId) } // decrement the hzu by the amount claimed @@ -107,7 +107,7 @@ func (k Keeper) DecrementHostZoneUnbonding(ctx sdk.Context, userRedemptionRecord // save the updated hzu on the epoch unbonding record epochUnbondingRecord, success := k.RecordsKeeper.AddHostZoneToEpochUnbondingRecord(ctx, callbackArgs.EpochNumber, callbackArgs.ChainId, hostZoneUnbonding) if !success { - return sdkerrors.Wrapf(types.ErrRecordNotFound, "epoch unbonding record not found %s", callbackArgs.ChainId) + return errorsmod.Wrapf(types.ErrRecordNotFound, "epoch unbonding record not found %s", callbackArgs.ChainId) } k.RecordsKeeper.SetEpochUnbondingRecord(ctx, *epochUnbondingRecord) return nil diff --git a/x/stakeibc/keeper/icacallbacks_delegate.go b/x/stakeibc/keeper/icacallbacks_delegate.go index 96c1955bc1..5a6c77f0ff 100644 --- a/x/stakeibc/keeper/icacallbacks_delegate.go +++ b/x/stakeibc/keeper/icacallbacks_delegate.go @@ -11,6 +11,7 @@ import ( icacallbackstypes "github.com/Stride-Labs/stride/v5/x/icacallbacks/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -48,7 +49,7 @@ func DelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ack // Deserialize the callback args delegateCallback, err := k.UnmarshalDelegateCallbackArgs(ctx, args) if err != nil { - return sdkerrors.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal delegate callback args: %s", err.Error())) + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal delegate callback args: %s", err.Error())) } chainId := delegateCallback.HostZoneId k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Delegate, @@ -57,12 +58,12 @@ func DelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ack // Confirm chainId and deposit record Id exist hostZone, found := k.GetHostZone(ctx, chainId) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "host zone not found %s", chainId) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "host zone not found %s", chainId) } recordId := delegateCallback.DepositRecordId depositRecord, found := k.RecordsKeeper.GetDepositRecord(ctx, recordId) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "deposit record not found %d", recordId) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "deposit record not found %d", recordId) } // Check for timeout (ack nil) @@ -93,7 +94,7 @@ func DelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ack hostZone.StakedBal = hostZone.StakedBal.Add(splitDelegation.Amount) success := k.AddDelegationToValidator(ctx, hostZone, splitDelegation.Validator, splitDelegation.Amount, ICACallbackID_Delegate) if !success { - return sdkerrors.Wrapf(types.ErrValidatorDelegationChg, "Failed to add delegation to validator") + return errorsmod.Wrapf(types.ErrValidatorDelegationChg, "Failed to add delegation to validator") } k.SetHostZone(ctx, hostZone) } diff --git a/x/stakeibc/keeper/icacallbacks_rebalance.go b/x/stakeibc/keeper/icacallbacks_rebalance.go index 370406c89f..bad0641262 100644 --- a/x/stakeibc/keeper/icacallbacks_rebalance.go +++ b/x/stakeibc/keeper/icacallbacks_rebalance.go @@ -7,6 +7,7 @@ import ( icacallbackstypes "github.com/Stride-Labs/stride/v5/x/icacallbacks/types" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -42,7 +43,7 @@ func RebalanceCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ac // Fetch callback args rebalanceCallback, err := k.UnmarshalRebalanceCallbackArgs(ctx, args) if err != nil { - return sdkerrors.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal rebalance callback args: %s", err.Error())) + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal rebalance callback args: %s", err.Error())) } chainId := rebalanceCallback.HostZoneId k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Rebalance, "Starting rebalance callback")) @@ -69,7 +70,7 @@ func RebalanceCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ac // Confirm the host zone exists hostZone, found := k.GetHostZone(ctx, chainId) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "host zone not found %s", chainId) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "host zone not found %s", chainId) } // Assemble a map from validatorAddress -> validator @@ -87,14 +88,14 @@ func RebalanceCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ac if _, valFound := valAddrMap[srcValidator]; valFound { valAddrMap[srcValidator].DelegationAmt = valAddrMap[srcValidator].DelegationAmt.Sub(rebalancing.Amt) } else { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "validator not found %s", srcValidator) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "validator not found %s", srcValidator) } // Increment the total delegation for the destination validator if _, valFound := valAddrMap[dstValidator]; valFound { valAddrMap[dstValidator].DelegationAmt = valAddrMap[dstValidator].DelegationAmt.Add(rebalancing.Amt) } else { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "validator not found %s", dstValidator) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "validator not found %s", dstValidator) } } k.SetHostZone(ctx, hostZone) diff --git a/x/stakeibc/keeper/icacallbacks_redemption.go b/x/stakeibc/keeper/icacallbacks_redemption.go index a57cb8a576..ff17142d22 100644 --- a/x/stakeibc/keeper/icacallbacks_redemption.go +++ b/x/stakeibc/keeper/icacallbacks_redemption.go @@ -8,6 +8,7 @@ import ( recordstypes "github.com/Stride-Labs/stride/v5/x/records/types" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -45,7 +46,7 @@ func RedemptionCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, a // Fetch callback args redemptionCallback, err := k.UnmarshalRedemptionCallbackArgs(ctx, args) if err != nil { - return sdkerrors.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal redemption callback args: %s", err.Error())) + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal redemption callback args: %s", err.Error())) } chainId := redemptionCallback.HostZoneId k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Redemption, @@ -79,7 +80,7 @@ func RedemptionCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, a // Confirm host zone exists _, found := k.GetHostZone(ctx, chainId) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, "Host zone not found: %s", chainId) + return errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "Host zone not found: %s", chainId) } // Upon success, update the unbonding record status to CLAIMABLE diff --git a/x/stakeibc/keeper/icacallbacks_reinvest.go b/x/stakeibc/keeper/icacallbacks_reinvest.go index 890abc924e..456e4861d1 100644 --- a/x/stakeibc/keeper/icacallbacks_reinvest.go +++ b/x/stakeibc/keeper/icacallbacks_reinvest.go @@ -9,8 +9,8 @@ import ( recordstypes "github.com/Stride-Labs/stride/v5/x/records/types" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" "github.com/golang/protobuf/proto" //nolint:staticcheck ) @@ -44,7 +44,7 @@ func ReinvestCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ack // Fetch callback args reinvestCallback, err := k.UnmarshalReinvestCallbackArgs(ctx, args) if err != nil { - return sdkerrors.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal reinvest callback args: %s", err.Error())) + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal reinvest callback args: %s", err.Error())) } chainId := reinvestCallback.HostZoneId k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Reinvest, "Starting reinvest callback")) @@ -72,7 +72,7 @@ func ReinvestCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, ack strideEpochTracker, found := k.GetEpochTracker(ctx, epochtypes.STRIDE_EPOCH) if !found { k.Logger(ctx).Error("failed to find epoch") - return sdkerrors.Wrapf(types.ErrInvalidLengthEpochTracker, "no number for epoch (%s)", epochtypes.STRIDE_EPOCH) + return errorsmod.Wrapf(types.ErrInvalidLengthEpochTracker, "no number for epoch (%s)", epochtypes.STRIDE_EPOCH) } // Create a new deposit record so that rewards are reinvested diff --git a/x/stakeibc/keeper/icacallbacks_undelegate.go b/x/stakeibc/keeper/icacallbacks_undelegate.go index 9d9b13aa32..868ac500ed 100644 --- a/x/stakeibc/keeper/icacallbacks_undelegate.go +++ b/x/stakeibc/keeper/icacallbacks_undelegate.go @@ -12,6 +12,7 @@ import ( recordstypes "github.com/Stride-Labs/stride/v5/x/records/types" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -52,7 +53,7 @@ func UndelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, a // Fetch callback args undelegateCallback, err := k.UnmarshalUndelegateCallbackArgs(ctx, args) if err != nil { - return sdkerrors.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal undelegate callback args: %s", err.Error())) + return errorsmod.Wrapf(types.ErrUnmarshalFailure, fmt.Sprintf("Unable to unmarshal undelegate callback args: %s", err.Error())) } chainId := undelegateCallback.HostZoneId k.Logger(ctx).Info(utils.LogICACallbackWithHostZone(chainId, ICACallbackID_Undelegate, @@ -86,7 +87,7 @@ func UndelegateCallback(k Keeper, ctx sdk.Context, packet channeltypes.Packet, a // Update delegation balances hostZone, found := k.GetHostZone(ctx, undelegateCallback.HostZoneId) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, "Host zone not found: %s", undelegateCallback.HostZoneId) + return errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, "Host zone not found: %s", undelegateCallback.HostZoneId) } err = k.UpdateDelegationBalances(ctx, hostZone, undelegateCallback) if err != nil { @@ -128,13 +129,13 @@ func (k Keeper) UpdateDelegationBalances(ctx sdk.Context, zone types.HostZone, u for _, undelegation := range undelegateCallback.SplitDelegations { success := k.AddDelegationToValidator(ctx, zone, undelegation.Validator, undelegation.Amount.Neg(), ICACallbackID_Undelegate) if !success { - return sdkerrors.Wrapf(types.ErrValidatorDelegationChg, "Failed to remove delegation to validator") + return errorsmod.Wrapf(types.ErrValidatorDelegationChg, "Failed to remove delegation to validator") } if undelegation.Amount.GT(zone.StakedBal) { // handle incoming underflow // Once we add a killswitch, we should also stop liquid staking on the zone here - return sdkerrors.Wrapf(types.ErrUndelegationAmount, "undelegation.Amount > zone.StakedBal, undelegation.Amount: %v, zone.StakedBal %v", undelegation.Amount, zone.StakedBal) + return errorsmod.Wrapf(types.ErrUndelegationAmount, "undelegation.Amount > zone.StakedBal, undelegation.Amount: %v, zone.StakedBal %v", undelegation.Amount, zone.StakedBal) } else { zone.StakedBal = zone.StakedBal.Sub(undelegation.Amount) } @@ -154,7 +155,7 @@ func (k Keeper) GetLatestCompletionTime(ctx sdk.Context, msgResponses [][]byte) var undelegateResponse stakingtypes.MsgUndelegateResponse err := proto.Unmarshal(msgResponse, &undelegateResponse) if err != nil { - return nil, sdkerrors.Wrapf(types.ErrUnmarshalFailure, "Unable to unmarshal undelegation tx response: %s", err.Error()) + return nil, errorsmod.Wrapf(types.ErrUnmarshalFailure, "Unable to unmarshal undelegation tx response: %s", err.Error()) } if undelegateResponse.CompletionTime.After(latestCompletionTime) { latestCompletionTime = undelegateResponse.CompletionTime @@ -162,7 +163,7 @@ func (k Keeper) GetLatestCompletionTime(ctx sdk.Context, msgResponses [][]byte) } if latestCompletionTime.IsZero() { - return nil, sdkerrors.Wrapf(types.ErrInvalidPacketCompletionTime, "Invalid completion time (%s) from txMsg", latestCompletionTime.String()) + return nil, errorsmod.Wrapf(types.ErrInvalidPacketCompletionTime, "Invalid completion time (%s) from txMsg", latestCompletionTime.String()) } return &latestCompletionTime, nil } @@ -182,13 +183,13 @@ func (k Keeper) UpdateHostZoneUnbondings( if !found { errMsg := fmt.Sprintf("Unable to find epoch unbonding record for epoch: %d", epochNumber) k.Logger(ctx).Error(errMsg) - return sdkmath.ZeroInt(), sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, errMsg) + return sdkmath.ZeroInt(), errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, errMsg) } hostZoneUnbonding, found := k.RecordsKeeper.GetHostZoneUnbondingByChainId(ctx, epochUnbondingRecord.EpochNumber, chainId) if !found { errMsg := fmt.Sprintf("Host zone unbonding not found (%s) in epoch unbonding record: %d", chainId, epochNumber) k.Logger(ctx).Error(errMsg) - return sdkmath.ZeroInt(), sdkerrors.Wrapf(sdkerrors.ErrKeyNotFound, errMsg) + return sdkmath.ZeroInt(), errorsmod.Wrapf(sdkerrors.ErrKeyNotFound, errMsg) } // Keep track of the stTokens that need to be burned @@ -202,7 +203,7 @@ func (k Keeper) UpdateHostZoneUnbondings( if !success { k.Logger(ctx).Error(fmt.Sprintf("Failed to set host zone epoch unbonding record: epochNumber %d, chainId %s, hostZoneUnbonding %+v", epochUnbondingRecord.EpochNumber, chainId, hostZoneUnbonding)) - return sdkmath.ZeroInt(), sdkerrors.Wrapf(types.ErrEpochNotFound, "couldn't set host zone epoch unbonding record. err: %s", err.Error()) + return sdkmath.ZeroInt(), errorsmod.Wrapf(types.ErrEpochNotFound, "couldn't set host zone epoch unbonding record. err: %s", err.Error()) } k.RecordsKeeper.SetEpochUnbondingRecord(ctx, *updatedEpochUnbondingRecord) @@ -219,7 +220,7 @@ func (k Keeper) BurnTokens(ctx sdk.Context, hostZone types.HostZone, stTokenBurn stCoinString := stTokenBurnAmount.String() + stCoinDenom stCoin, err := sdk.ParseCoinNormalized(stCoinString) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "could not parse burnCoin: %s. err: %s", stCoinString, err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "could not parse burnCoin: %s. err: %s", stCoinString, err.Error()) } // Send the stTokens from the host zone module account to the stakeibc module account @@ -236,7 +237,7 @@ func (k Keeper) BurnTokens(ctx sdk.Context, hostZone types.HostZone, stTokenBurn err = k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(stCoin)) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("Failed to burn stAssets upon successful unbonding %s", err.Error())) - return sdkerrors.Wrapf(types.ErrInsufficientFunds, "couldn't burn %v%s tokens in module account. err: %s", stTokenBurnAmount, stCoinDenom, err.Error()) + return errorsmod.Wrapf(types.ErrInsufficientFunds, "couldn't burn %v%s tokens in module account. err: %s", stTokenBurnAmount, stCoinDenom, err.Error()) } k.Logger(ctx).Info(fmt.Sprintf("Total supply %s", k.bankKeeper.GetSupply(ctx, stCoinDenom))) return nil diff --git a/x/stakeibc/keeper/icqcallbacks_delegator_shares.go b/x/stakeibc/keeper/icqcallbacks_delegator_shares.go index eefaefc9cf..6b58fee85b 100644 --- a/x/stakeibc/keeper/icqcallbacks_delegator_shares.go +++ b/x/stakeibc/keeper/icqcallbacks_delegator_shares.go @@ -1,6 +1,7 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cast" @@ -32,14 +33,14 @@ func DelegatorSharesCallback(k Keeper, ctx sdk.Context, args []byte, query icqty chainId := query.ChainId hostZone, found := k.GetHostZone(ctx, chainId) if !found { - return sdkerrors.Wrapf(types.ErrHostZoneNotFound, "no registered zone for queried chain ID (%s)", chainId) + return errorsmod.Wrapf(types.ErrHostZoneNotFound, "no registered zone for queried chain ID (%s)", chainId) } // Unmarshal the query response which returns a delegation object for the delegator/validator pair queriedDelgation := stakingtypes.Delegation{} err := k.cdc.Unmarshal(args, &queriedDelgation) if err != nil { - return sdkerrors.Wrapf(types.ErrMarshalFailure, "unable to unmarshal query response into Delegation type, err: %s", err.Error()) + return errorsmod.Wrapf(types.ErrMarshalFailure, "unable to unmarshal query response into Delegation type, err: %s", err.Error()) } k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_Delegation, "Query response - Delegator: %s, Validator: %s, Shares: %v", queriedDelgation.DelegatorAddress, queriedDelgation.ValidatorAddress, queriedDelgation.Shares)) @@ -47,25 +48,25 @@ func DelegatorSharesCallback(k Keeper, ctx sdk.Context, args []byte, query icqty // Ensure ICQ can be issued now, else fail the callback withinBufferWindow, err := k.IsWithinBufferWindow(ctx) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) } if !withinBufferWindow { - return sdkerrors.Wrapf(types.ErrOutsideIcqWindow, "callback is outside ICQ window") + return errorsmod.Wrapf(types.ErrOutsideIcqWindow, "callback is outside ICQ window") } // Grab the validator object from the hostZone using the address returned from the query validator, valIndex, found := GetValidatorFromAddress(hostZone.Validators, queriedDelgation.ValidatorAddress) if !found { - return sdkerrors.Wrapf(types.ErrValidatorNotFound, "no registered validator for address (%s)", queriedDelgation.ValidatorAddress) + return errorsmod.Wrapf(types.ErrValidatorNotFound, "no registered validator for address (%s)", queriedDelgation.ValidatorAddress) } // Get the validator's internal exchange rate, aborting if it hasn't been updated this epoch strideEpochTracker, found := k.GetEpochTracker(ctx, epochtypes.STRIDE_EPOCH) if !found { - return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "unable to get epoch tracker for epoch (%s)", epochtypes.STRIDE_EPOCH) + return errorsmod.Wrapf(sdkerrors.ErrNotFound, "unable to get epoch tracker for epoch (%s)", epochtypes.STRIDE_EPOCH) } if validator.InternalExchangeRate.EpochNumber != strideEpochTracker.EpochNumber { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "validator (%s) internal exchange rate has not been updated this epoch (epoch #%d)", validator.Address, strideEpochTracker.EpochNumber) } @@ -81,7 +82,7 @@ func DelegatorSharesCallback(k Keeper, ctx sdk.Context, args []byte, query icqty return nil } if delegatedTokens.GT(validator.DelegationAmt) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Validator (%s) tokens returned from query is greater than the DelegationAmt", validator.Address) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Validator (%s) tokens returned from query is greater than the DelegationAmt", validator.Address) } // TODO(TESTS-171) add some safety checks here (e.g. we could query the slashing module to confirm the decr in tokens was due to slash) @@ -102,14 +103,14 @@ func DelegatorSharesCallback(k Keeper, ctx sdk.Context, args []byte, query icqty } slashThresholdDecimal := sdk.NewDec(slashThreshold).Quo(sdk.NewDec(100)) if slashPct.GT(slashThresholdDecimal) { - return sdkerrors.Wrapf(types.ErrSlashExceedsSafetyThreshold, + return errorsmod.Wrapf(types.ErrSlashExceedsSafetyThreshold, "Validator slashed but ABORTING update, slash (%v) is greater than safety threshold (%v)", slashPct, slashThresholdDecimal) } // Update the validator weight and delegation reflect to reflect the slash weight, err := cast.ToInt64E(validator.Weight) if err != nil { - return sdkerrors.Wrapf(types.ErrIntCast, "unable to convert validator weight to int64, err: %s", err.Error()) + return errorsmod.Wrapf(types.ErrIntCast, "unable to convert validator weight to int64, err: %s", err.Error()) } weightAdjustment := sdk.NewDecFromInt(delegatedTokens).Quo(sdk.NewDecFromInt(validator.DelegationAmt)) diff --git a/x/stakeibc/keeper/icqcallbacks_validator_exchange_rate.go b/x/stakeibc/keeper/icqcallbacks_validator_exchange_rate.go index 8a13eca053..e832e66232 100644 --- a/x/stakeibc/keeper/icqcallbacks_validator_exchange_rate.go +++ b/x/stakeibc/keeper/icqcallbacks_validator_exchange_rate.go @@ -1,6 +1,7 @@ package keeper import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -29,14 +30,14 @@ func ValidatorExchangeRateCallback(k Keeper, ctx sdk.Context, args []byte, query chainId := query.ChainId hostZone, found := k.GetHostZone(ctx, query.ChainId) if !found { - return sdkerrors.Wrapf(types.ErrHostZoneNotFound, "no registered zone for queried chain ID (%s)", chainId) + return errorsmod.Wrapf(types.ErrHostZoneNotFound, "no registered zone for queried chain ID (%s)", chainId) } // Unmarshal the query response args into a Validator struct queriedValidator := stakingtypes.Validator{} err := k.cdc.Unmarshal(args, &queriedValidator) if err != nil { - return sdkerrors.Wrapf(types.ErrMarshalFailure, "unable to unmarshal query response into Validator type, err: %s", err.Error()) + return errorsmod.Wrapf(types.ErrMarshalFailure, "unable to unmarshal query response into Validator type, err: %s", err.Error()) } k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_Validator, "Query response - Validator: %s, Jailed: %v, Tokens: %v, Shares: %v", queriedValidator.OperatorAddress, queriedValidator.Jailed, queriedValidator.Tokens, queriedValidator.DelegatorShares)) @@ -44,29 +45,29 @@ func ValidatorExchangeRateCallback(k Keeper, ctx sdk.Context, args []byte, query // Ensure ICQ can be issued now, else fail the callback withinBufferWindow, err := k.IsWithinBufferWindow(ctx) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) } if !withinBufferWindow { - return sdkerrors.Wrapf(types.ErrOutsideIcqWindow, "callback is outside ICQ window") + return errorsmod.Wrapf(types.ErrOutsideIcqWindow, "callback is outside ICQ window") } // Get the validator from the host zone validator, valIndex, found := GetValidatorFromAddress(hostZone.Validators, queriedValidator.OperatorAddress) if !found { - return sdkerrors.Wrapf(types.ErrValidatorNotFound, "no registered validator for address (%s)", queriedValidator.OperatorAddress) + return errorsmod.Wrapf(types.ErrValidatorNotFound, "no registered validator for address (%s)", queriedValidator.OperatorAddress) } // Get the stride epoch number strideEpochTracker, found := k.GetEpochTracker(ctx, epochtypes.STRIDE_EPOCH) if !found { k.Logger(ctx).Error("failed to find stride epoch") - return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "no epoch number for epoch (%s)", epochtypes.STRIDE_EPOCH) + return errorsmod.Wrapf(sdkerrors.ErrNotFound, "no epoch number for epoch (%s)", epochtypes.STRIDE_EPOCH) } // If the validator's delegation shares is 0, we'll get a division by zero error when trying to get the exchange rate // because `validator.TokensFromShares` uses delegation shares in the denominator if queriedValidator.DelegatorShares.IsZero() { - return sdkerrors.Wrapf(types.ErrDivisionByZero, + return errorsmod.Wrapf(types.ErrDivisionByZero, "can't calculate validator internal exchange rate because delegation amount is 0 (validator: %s)", validator.Address) } @@ -87,7 +88,7 @@ func ValidatorExchangeRateCallback(k Keeper, ctx sdk.Context, args []byte, query // Armed with the exch rate, we can now query the (validator,delegator) delegation if err := k.QueryDelegationsIcq(ctx, hostZone, queriedValidator.OperatorAddress); err != nil { - return sdkerrors.Wrapf(types.ErrICQFailed, "Failed to query delegations, err: %s", err.Error()) + return errorsmod.Wrapf(types.ErrICQFailed, "Failed to query delegations, err: %s", err.Error()) } return nil diff --git a/x/stakeibc/keeper/icqcallbacks_withdrawal_balance.go b/x/stakeibc/keeper/icqcallbacks_withdrawal_balance.go index 5ec28160db..fd0c8541c7 100644 --- a/x/stakeibc/keeper/icqcallbacks_withdrawal_balance.go +++ b/x/stakeibc/keeper/icqcallbacks_withdrawal_balance.go @@ -6,6 +6,8 @@ import ( sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/spf13/cast" @@ -28,13 +30,13 @@ func WithdrawalBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icq chainId := query.ChainId hostZone, found := k.GetHostZone(ctx, chainId) if !found { - return sdkerrors.Wrapf(types.ErrHostZoneNotFound, "no registered zone for queried chain ID (%s)", chainId) + return errorsmod.Wrapf(types.ErrHostZoneNotFound, "no registered zone for queried chain ID (%s)", chainId) } // Unmarshal the query response args to determine the balance withdrawalBalanceAmount, err := UnmarshalAmountFromBalanceQuery(k.cdc, args) if err != nil { - return sdkerrors.Wrap(err, "unable to determine balance from query response") + return errorsmod.Wrap(err, "unable to determine balance from query response") } k.Logger(ctx).Info(utils.LogICQCallbackWithHostZone(chainId, ICQCallbackID_WithdrawalBalance, "Query response - Withdrawal Balance: %v %s", withdrawalBalanceAmount, hostZone.HostDenom)) @@ -49,15 +51,15 @@ func WithdrawalBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icq // Get the host zone's ICA accounts withdrawalAccount := hostZone.WithdrawalAccount if withdrawalAccount == nil || withdrawalAccount.Address == "" { - return sdkerrors.Wrapf(types.ErrICAAccountNotFound, "no withdrawal account found for %s", chainId) + return errorsmod.Wrapf(types.ErrICAAccountNotFound, "no withdrawal account found for %s", chainId) } delegationAccount := hostZone.DelegationAccount if delegationAccount == nil || delegationAccount.Address == "" { - return sdkerrors.Wrapf(types.ErrICAAccountNotFound, "no delegation account found for %s", chainId) + return errorsmod.Wrapf(types.ErrICAAccountNotFound, "no delegation account found for %s", chainId) } feeAccount := hostZone.FeeAccount if feeAccount == nil || feeAccount.Address == "" { - return sdkerrors.Wrapf(types.ErrICAAccountNotFound, "no fee account found for %s", chainId) + return errorsmod.Wrapf(types.ErrICAAccountNotFound, "no fee account found for %s", chainId) } // Determine the stride commission rate to the relevant portion can be sent to the fee account @@ -70,7 +72,7 @@ func WithdrawalBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icq // check that stride commission is between 0 and 1 strideCommission := sdk.NewDec(strideCommissionInt).Quo(sdk.NewDec(100)) if strideCommission.LT(sdk.ZeroDec()) || strideCommission.GT(sdk.OneDec()) { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Aborting withdrawal balance callback -- Stride commission must be between 0 and 1!") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Aborting withdrawal balance callback -- Stride commission must be between 0 and 1!") } // Split out the reinvestment amount from the fee amount @@ -80,7 +82,7 @@ func WithdrawalBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icq // Safety check, balances should add to original amount if !feeAmount.Add(reinvestAmount).Equal(withdrawalBalanceAmount) { k.Logger(ctx).Error(fmt.Sprintf("Error with withdraw logic: %v, Fee Portion: %v, Reinvest Portion %v", withdrawalBalanceAmount, feeAmount, reinvestAmount)) - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Failed to subdivide rewards to feeAccount and delegationAccount") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Failed to subdivide rewards to feeAccount and delegationAccount") } // Prepare MsgSends from the withdrawal account @@ -121,7 +123,7 @@ func WithdrawalBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icq // Send the transaction through SubmitTx _, err = k.SubmitTxsStrideEpoch(ctx, hostZone.ConnectionId, msgs, *withdrawalAccount, ICACallbackID_Reinvest, marshalledCallbackArgs) if err != nil { - return sdkerrors.Wrapf(types.ErrICATxFailed, "Failed to SubmitTxs, Messages: %v, err: %s", msgs, err.Error()) + return errorsmod.Wrapf(types.ErrICATxFailed, "Failed to SubmitTxs, Messages: %v, err: %s", msgs, err.Error()) } ctx.EventManager().EmitEvent( @@ -141,7 +143,7 @@ func WithdrawalBalanceCallback(k Keeper, ctx sdk.Context, args []byte, query icq func UnmarshalAmountFromBalanceQuery(cdc codec.BinaryCodec, queryResponseBz []byte) (amount sdkmath.Int, err error) { // An nil should not be possible, exit immediately if it occurs if queryResponseBz == nil { - return sdkmath.Int{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "query response is nil") + return sdkmath.Int{}, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "query response is nil") } // If the query response is empty, that means the account was never registed (and thus has a 0 balance) @@ -166,6 +168,6 @@ func UnmarshalAmountFromBalanceQuery(cdc codec.BinaryCodec, queryResponseBz []by } // If it failed unmarshaling with either data structure, return an error with the failure messages combined - return sdkmath.Int{}, sdkerrors.Wrapf(types.ErrUnmarshalFailure, + return sdkmath.Int{}, errorsmod.Wrapf(types.ErrUnmarshalFailure, "unable to unmarshal balance query response %v as sdkmath.Int (err: %s) or sdk.Coin (err: %s)", queryResponseBz, intError.Error(), coinError.Error()) } diff --git a/x/stakeibc/keeper/keeper.go b/x/stakeibc/keeper/keeper.go index 5f8e710bdc..40144926e6 100644 --- a/x/stakeibc/keeper/keeper.go +++ b/x/stakeibc/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "fmt" + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cast" "github.com/tendermint/tendermint/libs/log" @@ -174,7 +175,7 @@ func (k Keeper) GetStrideEpochElapsedShare(ctx sdk.Context) (sdk.Dec, error) { if !found { errMsg := fmt.Sprintf("Failed to get epoch tracker for %s", epochstypes.STRIDE_EPOCH) k.Logger(ctx).Error(errMsg) - return sdk.ZeroDec(), sdkerrors.Wrapf(sdkerrors.ErrNotFound, errMsg) + return sdk.ZeroDec(), errorsmod.Wrapf(sdkerrors.ErrNotFound, errMsg) } // Get epoch start time, end time, and duration @@ -182,13 +183,13 @@ func (k Keeper) GetStrideEpochElapsedShare(ctx sdk.Context) (sdk.Dec, error) { if err != nil { errMsg := fmt.Sprintf("unable to convert epoch duration to int64, err: %s", err.Error()) k.Logger(ctx).Error(errMsg) - return sdk.ZeroDec(), sdkerrors.Wrapf(types.ErrIntCast, errMsg) + return sdk.ZeroDec(), errorsmod.Wrapf(types.ErrIntCast, errMsg) } epochEndTime, err := cast.ToInt64E(epochTracker.NextEpochStartTime) if err != nil { errMsg := fmt.Sprintf("unable to convert next epoch start time to int64, err: %s", err.Error()) k.Logger(ctx).Error(errMsg) - return sdk.ZeroDec(), sdkerrors.Wrapf(types.ErrIntCast, errMsg) + return sdk.ZeroDec(), errorsmod.Wrapf(types.ErrIntCast, errMsg) } epochStartTime := epochEndTime - epochDuration @@ -197,7 +198,7 @@ func (k Keeper) GetStrideEpochElapsedShare(ctx sdk.Context) (sdk.Dec, error) { if currBlockTime < epochStartTime || currBlockTime > epochEndTime { errMsg := fmt.Sprintf("current block time %d is not within current epoch (ending at %d)", currBlockTime, epochTracker.NextEpochStartTime) k.Logger(ctx).Error(errMsg) - return sdk.ZeroDec(), sdkerrors.Wrapf(types.ErrInvalidEpoch, errMsg) + return sdk.ZeroDec(), errorsmod.Wrapf(types.ErrInvalidEpoch, errMsg) } // Get elapsed share @@ -206,7 +207,7 @@ func (k Keeper) GetStrideEpochElapsedShare(ctx sdk.Context) (sdk.Dec, error) { if elapsedShare.LT(sdk.ZeroDec()) || elapsedShare.GT(sdk.OneDec()) { errMsg := fmt.Sprintf("elapsed share (%s) for epoch is not between 0 and 1", elapsedShare) k.Logger(ctx).Error(errMsg) - return sdk.ZeroDec(), sdkerrors.Wrapf(types.ErrInvalidEpoch, errMsg) + return sdk.ZeroDec(), errorsmod.Wrapf(types.ErrInvalidEpoch, errMsg) } k.Logger(ctx).Info(fmt.Sprintf("Epoch elapsed share: %v (Block Time: %d, Epoch End Time: %d)", elapsedShare, currBlockTime, epochEndTime)) @@ -236,7 +237,7 @@ func (k Keeper) GetICATimeoutNanos(ctx sdk.Context, epochType string) (uint64, e epochTracker, found := k.GetEpochTracker(ctx, epochType) if !found { k.Logger(ctx).Error(fmt.Sprintf("Failed to get epoch tracker for %s", epochType)) - return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to get epoch tracker for %s", epochType) + return 0, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to get epoch tracker for %s", epochType) } // BUFFER by 5% of the epoch length bufferSizeParam := k.GetParam(ctx, types.KeyBufferSize) @@ -244,13 +245,13 @@ func (k Keeper) GetICATimeoutNanos(ctx sdk.Context, epochType string) (uint64, e // buffer size should not be negative or longer than the epoch duration if bufferSize > epochTracker.Duration { k.Logger(ctx).Error(fmt.Sprintf("Invalid buffer size %d", bufferSize)) - return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Invalid buffer size %d", bufferSize) + return 0, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Invalid buffer size %d", bufferSize) } timeoutNanos := epochTracker.NextEpochStartTime - bufferSize timeoutNanosUint64, err := cast.ToUint64E(timeoutNanos) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("Failed to convert timeoutNanos to uint64, error: %s", err.Error())) - return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to convert timeoutNanos to uint64, error: %s", err.Error()) + return 0, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to convert timeoutNanos to uint64, error: %s", err.Error()) } return timeoutNanosUint64, nil } @@ -268,7 +269,7 @@ func (k Keeper) IsRedemptionRateWithinSafetyBounds(ctx sdk.Context, zone types.H if redemptionRate.LT(minSafetyThreshold) || redemptionRate.GT(maxSafetyThreshold) { errMsg := fmt.Sprintf("IsRedemptionRateWithinSafetyBounds check failed %s is outside safety bounds [%s, %s]", redemptionRate.String(), minSafetyThreshold.String(), maxSafetyThreshold.String()) k.Logger(ctx).Error(errMsg) - return false, sdkerrors.Wrapf(types.ErrRedemptionRateOutsideSafetyBounds, errMsg) + return false, errorsmod.Wrapf(types.ErrRedemptionRateOutsideSafetyBounds, errMsg) } return true, nil } @@ -284,7 +285,7 @@ func (k Keeper) ConfirmValSetHasSpace(ctx sdk.Context, validators []*types.Valid if err != nil { errMsg := fmt.Sprintf("Error getting safety max num validators | err: %s", err.Error()) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrap(types.ErrMaxNumValidators, errMsg) + return errorsmod.Wrap(types.ErrMaxNumValidators, errMsg) } // count up the number of validators with non-zero weights @@ -299,7 +300,7 @@ func (k Keeper) ConfirmValSetHasSpace(ctx sdk.Context, validators []*types.Valid if numNonzeroWgtValidators >= maxNumVals { errMsg := fmt.Sprintf("Attempting to add new validator but already reached max number of validators (%d)", maxNumVals) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrap(types.ErrMaxNumValidators, errMsg) + return errorsmod.Wrap(types.ErrMaxNumValidators, errMsg) } return nil diff --git a/x/stakeibc/keeper/msg_server_change_validator_weight.go b/x/stakeibc/keeper/msg_server_change_validator_weight.go index 3436183d58..447adc7820 100644 --- a/x/stakeibc/keeper/msg_server_change_validator_weight.go +++ b/x/stakeibc/keeper/msg_server_change_validator_weight.go @@ -4,8 +4,8 @@ import ( "context" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" ) @@ -27,7 +27,7 @@ func (k msgServer) ChangeValidatorWeight(goCtx context.Context, msg *types.MsgCh if validator.Weight == 0 && msg.Weight > 0 { err := k.ConfirmValSetHasSpace(ctx, validators) if err != nil { - return nil, sdkerrors.Wrap(types.ErrMaxNumValidators, "cannot set val weight from zero to nonzero on host zone") + return nil, errorsmod.Wrap(types.ErrMaxNumValidators, "cannot set val weight from zero to nonzero on host zone") } } validator.Weight = msg.Weight diff --git a/x/stakeibc/keeper/msg_server_claim_undelegated_tokens.go b/x/stakeibc/keeper/msg_server_claim_undelegated_tokens.go index fd585c4476..e761933b9e 100644 --- a/x/stakeibc/keeper/msg_server_claim_undelegated_tokens.go +++ b/x/stakeibc/keeper/msg_server_claim_undelegated_tokens.go @@ -6,8 +6,8 @@ import ( recordstypes "github.com/Stride-Labs/stride/v5/x/records/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" epochstypes "github.com/Stride-Labs/stride/v5/x/epochs/types" @@ -28,12 +28,12 @@ func (k msgServer) ClaimUndelegatedTokens(goCtx context.Context, msg *types.MsgC if err != nil { errMsg := fmt.Sprintf("unable to find claimable redemption record for msg: %v, error %s", msg, err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrap(types.ErrRecordNotFound, errMsg) + return nil, errorsmod.Wrap(types.ErrRecordNotFound, errMsg) } icaTx, err := k.GetRedemptionTransferMsg(ctx, userRedemptionRecord, msg.HostZoneId) if err != nil { - return nil, sdkerrors.Wrap(err, "unable to build redemption transfer message") + return nil, errorsmod.Wrap(err, "unable to build redemption transfer message") } // add callback data @@ -44,12 +44,12 @@ func (k msgServer) ClaimUndelegatedTokens(goCtx context.Context, msg *types.MsgC } marshalledCallbackArgs, err := k.MarshalClaimCallbackArgs(ctx, claimCallback) if err != nil { - return nil, sdkerrors.Wrap(err, "unable to marshal claim callback args") + return nil, errorsmod.Wrap(err, "unable to marshal claim callback args") } _, err = k.SubmitTxs(ctx, icaTx.ConnectionId, icaTx.Msgs, icaTx.Account, icaTx.Timeout, ICACallbackID_Claim, marshalledCallbackArgs) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("Submit tx error: %s", err.Error())) - return nil, sdkerrors.Wrap(err, "unable to submit ICA redemption tx") + return nil, errorsmod.Wrap(err, "unable to submit ICA redemption tx") } // Set claimIsPending to true, so that the record can't be double claimed @@ -66,7 +66,7 @@ func (k Keeper) GetClaimableRedemptionRecord(ctx sdk.Context, msg *types.MsgClai if !found { errMsg := fmt.Sprintf("User redemption record %s not found on host zone %s", userRedemptionRecordKey, msg.HostZoneId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrap(types.ErrInvalidUserRedemptionRecord, errMsg) + return nil, errorsmod.Wrap(types.ErrInvalidUserRedemptionRecord, errMsg) } // check that the record is claimable @@ -74,19 +74,19 @@ func (k Keeper) GetClaimableRedemptionRecord(ctx sdk.Context, msg *types.MsgClai if !found { errMsg := fmt.Sprintf("Host zone unbonding record %s not found on host zone %s", userRedemptionRecordKey, msg.HostZoneId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrInvalidUserRedemptionRecord, errMsg) + return nil, errorsmod.Wrapf(types.ErrInvalidUserRedemptionRecord, errMsg) } // records associated with host zone unbondings are claimable after the host zone unbonding tokens have been CLAIMABLE to the redemption account if hostZoneUnbonding.Status != recordstypes.HostZoneUnbonding_CLAIMABLE { errMsg := fmt.Sprintf("User redemption record %s is not claimable, host zone unbonding has status: %s, requires status CLAIMABLE", userRedemptionRecord.Id, hostZoneUnbonding.Status) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrInvalidUserRedemptionRecord, errMsg) + return nil, errorsmod.Wrapf(types.ErrInvalidUserRedemptionRecord, errMsg) } // records that have claimIsPending set to True have already been claimed (and are pending an ack) if userRedemptionRecord.ClaimIsPending { errMsg := fmt.Sprintf("User redemption record %s is not claimable, pending ack", userRedemptionRecord.Id) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrInvalidUserRedemptionRecord, errMsg) + return nil, errorsmod.Wrapf(types.ErrInvalidUserRedemptionRecord, errMsg) } return &userRedemptionRecord, nil } @@ -97,13 +97,13 @@ func (k Keeper) GetRedemptionTransferMsg(ctx sdk.Context, userRedemptionRecord * if !found { errMsg := fmt.Sprintf("Host zone %s not found", hostZoneId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrap(types.ErrInvalidHostZone, errMsg) + return nil, errorsmod.Wrap(types.ErrInvalidHostZone, errMsg) } redemptionAccount, found := k.GetRedemptionAccount(ctx, hostZone) if !found { errMsg := fmt.Sprintf("Redemption account not found for host zone %s", hostZoneId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrap(types.ErrInvalidHostZone, errMsg) + return nil, errorsmod.Wrap(types.ErrInvalidHostZone, errMsg) } var msgs []sdk.Msg @@ -119,7 +119,7 @@ func (k Keeper) GetRedemptionTransferMsg(ctx sdk.Context, userRedemptionRecord * if !found { errMsg := fmt.Sprintf("Epoch tracker not found for epoch %s", epochstypes.STRIDE_EPOCH) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrap(types.ErrEpochNotFound, errMsg) + return nil, errorsmod.Wrap(types.ErrEpochNotFound, errMsg) } icaTimeOutNanos := k.GetParam(ctx, types.KeyICATimeoutNanos) nextEpochStarttime := epochTracker.NextEpochStartTime diff --git a/x/stakeibc/keeper/msg_server_clear_balance.go b/x/stakeibc/keeper/msg_server_clear_balance.go index de3f3f3f2a..acb541183f 100644 --- a/x/stakeibc/keeper/msg_server_clear_balance.go +++ b/x/stakeibc/keeper/msg_server_clear_balance.go @@ -4,8 +4,8 @@ import ( "context" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" "github.com/spf13/cast" @@ -17,11 +17,11 @@ func (k msgServer) ClearBalance(goCtx context.Context, msg *types.MsgClearBalanc zone, found := k.GetHostZone(ctx, msg.ChainId) if !found { - return nil, sdkerrors.Wrapf(types.ErrInvalidHostZone, "chainId: %s", msg.ChainId) + return nil, errorsmod.Wrapf(types.ErrInvalidHostZone, "chainId: %s", msg.ChainId) } feeAccount := zone.GetFeeAccount() if feeAccount == nil { - return nil, sdkerrors.Wrapf(types.ErrFeeAccountNotRegistered, "chainId: %s", msg.ChainId) + return nil, errorsmod.Wrapf(types.ErrFeeAccountNotRegistered, "chainId: %s", msg.ChainId) } sourcePort := ibctransfertypes.PortID @@ -32,7 +32,7 @@ func (k msgServer) ClearBalance(goCtx context.Context, msg *types.MsgClearBalanc tokens, err := sdk.ParseCoinNormalized(coinString) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("failed to parse coin (%s)", coinString)) - return nil, sdkerrors.Wrapf(err, "failed to parse coin (%s)", coinString) + return nil, errorsmod.Wrapf(err, "failed to parse coin (%s)", coinString) } sender := feeAccount.GetAddress() // KeyICATimeoutNanos are for our Stride ICA calls, KeyFeeTransferTimeoutNanos is for the IBC transfer @@ -56,7 +56,7 @@ func (k msgServer) ClearBalance(goCtx context.Context, msg *types.MsgClearBalanc _, err = k.SubmitTxs(ctx, connectionId, msgs, *feeAccount, icaTimeoutNanos, "", nil) if err != nil { - return nil, sdkerrors.Wrapf(err, "failed to submit txs") + return nil, errorsmod.Wrapf(err, "failed to submit txs") } return &types.MsgClearBalanceResponse{}, nil } diff --git a/x/stakeibc/keeper/msg_server_delete_validator.go b/x/stakeibc/keeper/msg_server_delete_validator.go index 5fcb389a43..585e5565f3 100644 --- a/x/stakeibc/keeper/msg_server_delete_validator.go +++ b/x/stakeibc/keeper/msg_server_delete_validator.go @@ -4,8 +4,8 @@ import ( "context" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" ) @@ -17,7 +17,7 @@ func (k msgServer) DeleteValidator(goCtx context.Context, msg *types.MsgDeleteVa if err != nil { errMsg := fmt.Sprintf("Validator (%s) not removed from host zone (%s) | err: %s", msg.ValAddr, msg.HostZone, err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrValidatorNotRemoved, errMsg) + return nil, errorsmod.Wrapf(types.ErrValidatorNotRemoved, errMsg) } return &types.MsgDeleteValidatorResponse{}, nil diff --git a/x/stakeibc/keeper/msg_server_liquid_stake.go b/x/stakeibc/keeper/msg_server_liquid_stake.go index 3acda9cd2f..6161d968f8 100644 --- a/x/stakeibc/keeper/msg_server_liquid_stake.go +++ b/x/stakeibc/keeper/msg_server_liquid_stake.go @@ -6,6 +6,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" epochtypes "github.com/Stride-Labs/stride/v5/x/epochs/types" @@ -24,7 +26,7 @@ func (k msgServer) LiquidStake(goCtx context.Context, msg *types.MsgLiquidStake) hostZone, err := k.GetHostZoneFromHostDenom(ctx, msg.HostDenom) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("Host Zone not found for denom (%s)", msg.HostDenom)) - return nil, sdkerrors.Wrapf(types.ErrInvalidHostZone, "no host zone found for denom (%s)", msg.HostDenom) + return nil, errorsmod.Wrapf(types.ErrInvalidHostZone, "no host zone found for denom (%s)", msg.HostDenom) } // get the sender address sender, _ := sdk.AccAddressFromBech32(msg.Creator) @@ -35,27 +37,27 @@ func (k msgServer) LiquidStake(goCtx context.Context, msg *types.MsgLiquidStake) inCoin, err := sdk.ParseCoinNormalized(coinString) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("failed to parse coin (%s)", coinString)) - return nil, sdkerrors.Wrapf(err, "failed to parse coin (%s)", coinString) + return nil, errorsmod.Wrapf(err, "failed to parse coin (%s)", coinString) } // Creator owns at least "amount" of inCoin balance := k.bankKeeper.GetBalance(ctx, sender, ibcDenom) if balance.IsLT(inCoin) { k.Logger(ctx).Error(fmt.Sprintf("balance is lower than staking amount. staking amount: %v, balance: %v", msg.Amount, balance.Amount)) - return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "balance is lower than staking amount. staking amount: %v, balance: %v", msg.Amount, balance.Amount) + return nil, errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, "balance is lower than staking amount. staking amount: %v, balance: %v", msg.Amount, balance.Amount) } // check that the token is an IBC token isIbcToken := types.IsIBCToken(ibcDenom) if !isIbcToken { k.Logger(ctx).Error("invalid token denom - denom is not an IBC token (%s)", ibcDenom) - return nil, sdkerrors.Wrapf(types.ErrInvalidToken, "denom is not an IBC token (%s)", ibcDenom) + return nil, errorsmod.Wrapf(types.ErrInvalidToken, "denom is not an IBC token (%s)", ibcDenom) } // safety check: redemption rate must be above safety threshold rateIsSafe, err := k.IsRedemptionRateWithinSafetyBounds(ctx, *hostZone) if !rateIsSafe || (err != nil) { errMsg := fmt.Sprintf("IsRedemptionRateWithinSafetyBounds check failed. hostZone: %s, err: %s", hostZone.String(), err.Error()) - return nil, sdkerrors.Wrapf(types.ErrRedemptionRateOutsideSafetyBounds, errMsg) + return nil, errorsmod.Wrapf(types.ErrRedemptionRateOutsideSafetyBounds, errMsg) } bech32ZoneAddress, err := sdk.AccAddressFromBech32(hostZone.Address) @@ -65,27 +67,27 @@ func (k msgServer) LiquidStake(goCtx context.Context, msg *types.MsgLiquidStake) err = k.bankKeeper.SendCoins(ctx, sender, bech32ZoneAddress, sdk.NewCoins(inCoin)) if err != nil { k.Logger(ctx).Error("failed to send tokens from Account to Module") - return nil, sdkerrors.Wrap(err, "failed to send tokens from Account to Module") + return nil, errorsmod.Wrap(err, "failed to send tokens from Account to Module") } // mint user `amount` of the corresponding stAsset // NOTE: We should ensure that denoms are unique - we don't want anyone spoofing denoms err = k.MintStAssetAndTransfer(ctx, sender, msg.Amount, msg.HostDenom) if err != nil { k.Logger(ctx).Error("failed to send tokens from Account to Module") - return nil, sdkerrors.Wrapf(err, "failed to mint %s stAssets to user", msg.HostDenom) + return nil, errorsmod.Wrapf(err, "failed to mint %s stAssets to user", msg.HostDenom) } // create a deposit record of these tokens (pending transfer) strideEpochTracker, found := k.GetEpochTracker(ctx, epochtypes.STRIDE_EPOCH) if !found { k.Logger(ctx).Error("failed to find stride epoch") - return nil, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "no epoch number for epoch (%s)", epochtypes.STRIDE_EPOCH) + return nil, errorsmod.Wrapf(sdkerrors.ErrNotFound, "no epoch number for epoch (%s)", epochtypes.STRIDE_EPOCH) } // Does this use too much gas? depositRecord, found := k.RecordsKeeper.GetDepositRecordByEpochAndChain(ctx, strideEpochTracker.EpochNumber, hostZone.ChainId) if !found { k.Logger(ctx).Error("failed to find deposit record") - return nil, sdkerrors.Wrapf(sdkerrors.ErrNotFound, fmt.Sprintf("no deposit record for epoch (%d)", strideEpochTracker.EpochNumber)) + return nil, errorsmod.Wrapf(sdkerrors.ErrNotFound, fmt.Sprintf("no deposit record for epoch (%d)", strideEpochTracker.EpochNumber)) } depositRecord.Amount = depositRecord.Amount.Add(msg.Amount) k.RecordsKeeper.SetDepositRecord(ctx, *depositRecord) @@ -105,7 +107,7 @@ func (k msgServer) MintStAssetAndTransfer(ctx sdk.Context, sender sdk.AccAddress stCoins, err := sdk.ParseCoinsNormalized(coinString) if err != nil { k.Logger(ctx).Error("Failed to parse coins") - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to parse coins %s", coinString) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to parse coins %s", coinString) } // Mints coins to the module account, will error if the module account does not exist or is unauthorized. @@ -113,14 +115,14 @@ func (k msgServer) MintStAssetAndTransfer(ctx sdk.Context, sender sdk.AccAddress err = k.bankKeeper.MintCoins(ctx, types.ModuleName, stCoins) if err != nil { k.Logger(ctx).Error("Failed to mint coins") - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to mint coins") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to mint coins") } // transfer those coins to the user err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, stCoins) if err != nil { k.Logger(ctx).Error("Failed to send coins from module to account") - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to send %s from module to account", stCoins.GetDenomByIndex(0)) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to send %s from module to account", stCoins.GetDenomByIndex(0)) } k.Logger(ctx).Info(fmt.Sprintf("[MINT ST ASSET] success on %s.", hz.GetChainId())) diff --git a/x/stakeibc/keeper/msg_server_rebalance_validators.go b/x/stakeibc/keeper/msg_server_rebalance_validators.go index 99e715d1b5..f166ced180 100644 --- a/x/stakeibc/keeper/msg_server_rebalance_validators.go +++ b/x/stakeibc/keeper/msg_server_rebalance_validators.go @@ -7,6 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/spf13/cast" @@ -63,7 +65,7 @@ func (k msgServer) RebalanceValidators(goCtx context.Context, msg *types.MsgReba // check if there is a large enough rebalance, if not, just exit total_delegation := k.GetTotalValidatorDelegations(hostZone) if total_delegation.IsZero() { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "no validator delegations found for Host Zone %s, cannot rebalance 0 delegations!", hostZone.ChainId) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "no validator delegations found for Host Zone %s, cannot rebalance 0 delegations!", hostZone.ChainId) } overweight_delta := sdk.NewDecFromInt(valDeltaList[overWeightIndex].deltaAmt).Quo(sdk.NewDecFromInt(total_delegation)) @@ -79,7 +81,7 @@ func (k msgServer) RebalanceValidators(goCtx context.Context, msg *types.MsgReba delegationIca := hostZone.GetDelegationAccount() if delegationIca == nil || delegationIca.GetAddress() == "" { k.Logger(ctx).Error(fmt.Sprintf("Zone %s is missing a delegation address!", hostZone.ChainId)) - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid delegation account") + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid delegation account") } delegatorAddress := delegationIca.GetAddress() @@ -160,7 +162,7 @@ func (k msgServer) RebalanceValidators(goCtx context.Context, msg *types.MsgReba connectionId := hostZone.GetConnectionId() _, err = k.SubmitTxsStrideEpoch(ctx, connectionId, msgs, *hostZone.GetDelegationAccount(), ICACallbackID_Rebalance, marshalledCallbackArgs) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s, %s", connectionId, hostZone.ChainId, msgs, err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s, %s", connectionId, hostZone.ChainId, msgs, err.Error()) } return &types.MsgRebalanceValidatorsResponse{}, nil diff --git a/x/stakeibc/keeper/msg_server_redeem_stake.go b/x/stakeibc/keeper/msg_server_redeem_stake.go index 569efe02dd..e3f63eb676 100644 --- a/x/stakeibc/keeper/msg_server_redeem_stake.go +++ b/x/stakeibc/keeper/msg_server_redeem_stake.go @@ -7,6 +7,7 @@ import ( recordstypes "github.com/Stride-Labs/stride/v5/x/records/types" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -20,30 +21,30 @@ func (k msgServer) RedeemStake(goCtx context.Context, msg *types.MsgRedeemStake) // get our addresses, make sure they're valid sender, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "creator address is invalid: %s. err: %s", msg.Creator, err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "creator address is invalid: %s. err: %s", msg.Creator, err.Error()) } // then make sure host zone is valid hostZone, found := k.GetHostZone(ctx, msg.HostZone) if !found { - return nil, sdkerrors.Wrapf(types.ErrInvalidHostZone, "host zone is invalid: %s", msg.HostZone) + return nil, errorsmod.Wrapf(types.ErrInvalidHostZone, "host zone is invalid: %s", msg.HostZone) } // first construct a user redemption record epochTracker, found := k.GetEpochTracker(ctx, "day") if !found { - return nil, sdkerrors.Wrapf(types.ErrEpochNotFound, "epoch tracker found: %s", "day") + return nil, errorsmod.Wrapf(types.ErrEpochNotFound, "epoch tracker found: %s", "day") } senderAddr := sender.String() redemptionId := recordstypes.UserRedemptionRecordKeyFormatter(hostZone.ChainId, epochTracker.EpochNumber, senderAddr) _, found = k.RecordsKeeper.GetUserRedemptionRecord(ctx, redemptionId) if found { - return nil, sdkerrors.Wrapf(recordstypes.ErrRedemptionAlreadyExists, "user already redeemed this epoch: %s", redemptionId) + return nil, errorsmod.Wrapf(recordstypes.ErrRedemptionAlreadyExists, "user already redeemed this epoch: %s", redemptionId) } // ensure the recipient address is a valid bech32 address on the hostZone // TODO(TEST-112) do we need to check the hostZone before this check? Would need access to keeper _, err = utils.AccAddressFromBech32(msg.Receiver, hostZone.Bech32Prefix) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid receiver address (%s)", err) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid receiver address (%s)", err) } // construct desired unstaking amount from host zone @@ -51,33 +52,33 @@ func (k msgServer) RedeemStake(goCtx context.Context, msg *types.MsgRedeemStake) nativeAmount := sdk.NewDecFromInt(msg.Amount).Mul(hostZone.RedemptionRate).RoundInt() if nativeAmount.GT(hostZone.StakedBal) { - return nil, sdkerrors.Wrapf(types.ErrInvalidAmount, "cannot unstake an amount g.t. staked balance on host zone: %v", msg.Amount) + return nil, errorsmod.Wrapf(types.ErrInvalidAmount, "cannot unstake an amount g.t. staked balance on host zone: %v", msg.Amount) } // safety check: redemption rate must be within safety bounds rateIsSafe, err := k.IsRedemptionRateWithinSafetyBounds(ctx, hostZone) if !rateIsSafe || (err != nil) { errMsg := fmt.Sprintf("IsRedemptionRateWithinSafetyBounds check failed. hostZone: %s, err: %s", hostZone.String(), err.Error()) - return nil, sdkerrors.Wrapf(types.ErrRedemptionRateOutsideSafetyBounds, errMsg) + return nil, errorsmod.Wrapf(types.ErrRedemptionRateOutsideSafetyBounds, errMsg) } // TODO(TEST-112) bigint safety coinString := nativeAmount.String() + stDenom inCoin, err := sdk.ParseCoinNormalized(coinString) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "could not parse inCoin: %s. err: %s", coinString, err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "could not parse inCoin: %s. err: %s", coinString, err.Error()) } // safety checks on the coin // - Redemption amount must be positive if !nativeAmount.IsPositive() { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "amount must be greater than 0. found: %v", msg.Amount) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "amount must be greater than 0. found: %v", msg.Amount) } // - Creator owns at least "amount" stAssets balance := k.bankKeeper.GetBalance(ctx, sender, stDenom) k.Logger(ctx).Info(fmt.Sprintf("Redemption issuer IBCDenom balance: %v%s", balance.Amount, balance.Denom)) k.Logger(ctx).Info(fmt.Sprintf("Redemption requested redemotion amount: %v%s", inCoin.Amount, inCoin.Denom)) if balance.Amount.LT(msg.Amount) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "balance is lower than redemption amount. redemption amount: %v, balance %v: ", msg.Amount, balance.Amount) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidCoins, "balance is lower than redemption amount. redemption amount: %v, balance %v: ", msg.Amount, balance.Amount) } // UNBONDING RECORD KEEPING userRedemptionRecord := recordstypes.UserRedemptionRecord{ @@ -96,12 +97,12 @@ func (k msgServer) RedeemStake(goCtx context.Context, msg *types.MsgRedeemStake) epochUnbondingRecord, found := k.RecordsKeeper.GetEpochUnbondingRecord(ctx, epochTracker.EpochNumber) if !found { k.Logger(ctx).Error("latest epoch unbonding record not found") - return nil, sdkerrors.Wrapf(recordstypes.ErrEpochUnbondingRecordNotFound, "latest epoch unbonding record not found") + return nil, errorsmod.Wrapf(recordstypes.ErrEpochUnbondingRecordNotFound, "latest epoch unbonding record not found") } // get relevant host zone on this epoch unbonding record hostZoneUnbonding, found := k.RecordsKeeper.GetHostZoneUnbondingByChainId(ctx, epochUnbondingRecord.EpochNumber, hostZone.ChainId) if !found { - return nil, sdkerrors.Wrapf(types.ErrInvalidHostZone, "host zone not found in unbondings: %s", hostZone.ChainId) + return nil, errorsmod.Wrapf(types.ErrInvalidHostZone, "host zone not found in unbondings: %s", hostZone.ChainId) } hostZoneUnbonding.NativeTokenAmount = hostZoneUnbonding.NativeTokenAmount.Add(nativeAmount) hostZoneUnbonding.UserRedemptionRecords = append(hostZoneUnbonding.UserRedemptionRecords, userRedemptionRecord.Id) @@ -115,7 +116,7 @@ func (k msgServer) RedeemStake(goCtx context.Context, msg *types.MsgRedeemStake) err = k.bankKeeper.SendCoins(ctx, sender, bech32ZoneAddress, redeemCoin) if err != nil { k.Logger(ctx).Error("Failed to send sdk.NewCoins(inCoins) from account to module") - return nil, sdkerrors.Wrapf(types.ErrInsufficientFunds, "couldn't send %v derivative %s tokens to module account. err: %s", msg.Amount, hostZone.HostDenom, err.Error()) + return nil, errorsmod.Wrapf(types.ErrInsufficientFunds, "couldn't send %v derivative %s tokens to module account. err: %s", msg.Amount, hostZone.HostDenom, err.Error()) } // record the number of stAssets that should be burned after unbonding @@ -133,7 +134,7 @@ func (k msgServer) RedeemStake(goCtx context.Context, msg *types.MsgRedeemStake) updatedEpochUnbondingRecord, success := k.RecordsKeeper.AddHostZoneToEpochUnbondingRecord(ctx, epochUnbondingRecord.EpochNumber, hostZone.ChainId, hostZoneUnbonding) if !success { k.Logger(ctx).Error(fmt.Sprintf("Failed to set host zone epoch unbonding record: epochNumber %d, chainId %s, hostZoneUnbonding %v", epochUnbondingRecord.EpochNumber, hostZone.ChainId, hostZoneUnbonding)) - return nil, sdkerrors.Wrapf(types.ErrEpochNotFound, "couldn't set host zone epoch unbonding record. err: %s", err.Error()) + return nil, errorsmod.Wrapf(types.ErrEpochNotFound, "couldn't set host zone epoch unbonding record. err: %s", err.Error()) } k.RecordsKeeper.SetEpochUnbondingRecord(ctx, *updatedEpochUnbondingRecord) diff --git a/x/stakeibc/keeper/msg_server_register_host_zone.go b/x/stakeibc/keeper/msg_server_register_host_zone.go index 403a490246..7446dfe7db 100644 --- a/x/stakeibc/keeper/msg_server_register_host_zone.go +++ b/x/stakeibc/keeper/msg_server_register_host_zone.go @@ -12,8 +12,8 @@ import ( recordstypes "github.com/Stride-Labs/stride/v5/x/records/types" "github.com/Stride-Labs/stride/v5/x/stakeibc/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegisterHostZone) (*types.MsgRegisterHostZoneResponse, error) { @@ -24,7 +24,7 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if !found { errMsg := fmt.Sprintf("invalid connection id, %s not found", msg.ConnectionId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } counterpartyConnection := connectionEnd.Counterparty @@ -33,7 +33,7 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if err != nil { errMsg := fmt.Sprintf("unable to obtain chain id from connection %s, err: %s", msg.ConnectionId, err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } // get zone @@ -41,7 +41,7 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if found { errMsg := fmt.Sprintf("invalid chain id, zone for %s already registered", chainId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } // check the denom is not already registered @@ -50,17 +50,17 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if hostZone.HostDenom == msg.HostDenom { errMsg := fmt.Sprintf("host denom %s already registered", msg.HostDenom) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } if hostZone.ConnectionId == msg.ConnectionId { errMsg := fmt.Sprintf("connectionId %s already registered", msg.ConnectionId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } if hostZone.Bech32Prefix == msg.Bech32Prefix { errMsg := fmt.Sprintf("bech32prefix %s already registered", msg.Bech32Prefix) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } } @@ -106,7 +106,7 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, zone.ConnectionId, delegateAccount, appVersion); err != nil { errMsg := fmt.Sprintf("unable to register delegation account, err: %s", err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } // generate fee account @@ -114,7 +114,7 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, zone.ConnectionId, feeAccount, appVersion); err != nil { errMsg := fmt.Sprintf("unable to register fee account, err: %s", err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } // generate withdrawal account @@ -122,7 +122,7 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, zone.ConnectionId, withdrawalAccount, appVersion); err != nil { errMsg := fmt.Sprintf("unable to register withdrawal account, err: %s", err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } // generate redemption account @@ -130,20 +130,20 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste if err := k.ICAControllerKeeper.RegisterInterchainAccount(ctx, zone.ConnectionId, redemptionAccount, appVersion); err != nil { errMsg := fmt.Sprintf("unable to register redemption account, err: %s", err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) + return nil, errorsmod.Wrapf(types.ErrFailedToRegisterHostZone, errMsg) } // add this host zone to unbonding hostZones, otherwise users won't be able to unbond // for this host zone until the following day dayEpochTracker, found := k.GetEpochTracker(ctx, epochtypes.DAY_EPOCH) if !found { - return nil, sdkerrors.Wrapf(types.ErrEpochNotFound, "epoch tracker (%s) not found", epochtypes.DAY_EPOCH) + return nil, errorsmod.Wrapf(types.ErrEpochNotFound, "epoch tracker (%s) not found", epochtypes.DAY_EPOCH) } epochUnbondingRecord, found := k.RecordsKeeper.GetEpochUnbondingRecord(ctx, dayEpochTracker.EpochNumber) if !found { errMsg := "unable to find latest epoch unbonding record" k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(recordstypes.ErrEpochUnbondingRecordNotFound, errMsg) + return nil, errorsmod.Wrapf(recordstypes.ErrEpochUnbondingRecordNotFound, errMsg) } hostZoneUnbonding := &recordstypes.HostZoneUnbonding{ NativeTokenAmount: sdkmath.ZeroInt(), @@ -157,14 +157,14 @@ func (k msgServer) RegisterHostZone(goCtx context.Context, msg *types.MsgRegiste errMsg := fmt.Sprintf("Failed to set host zone epoch unbonding record: epochNumber %d, chainId %s, hostZoneUnbonding %v. Err: %s", epochUnbondingRecord.EpochNumber, chainId, hostZoneUnbonding, err.Error()) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrEpochNotFound, errMsg) + return nil, errorsmod.Wrapf(types.ErrEpochNotFound, errMsg) } k.RecordsKeeper.SetEpochUnbondingRecord(ctx, *updatedEpochUnbondingRecord) // create an empty deposit record for the host zone strideEpochTracker, found := k.GetEpochTracker(ctx, epochtypes.STRIDE_EPOCH) if !found { - return nil, sdkerrors.Wrapf(types.ErrEpochNotFound, "epoch tracker (%s) not found", epochtypes.STRIDE_EPOCH) + return nil, errorsmod.Wrapf(types.ErrEpochNotFound, "epoch tracker (%s) not found", epochtypes.STRIDE_EPOCH) } depositRecord := recordstypes.DepositRecord{ Id: 0, diff --git a/x/stakeibc/keeper/msg_server_restore_interchain_account.go b/x/stakeibc/keeper/msg_server_restore_interchain_account.go index ee981f67b2..c45e4fa69c 100644 --- a/x/stakeibc/keeper/msg_server_restore_interchain_account.go +++ b/x/stakeibc/keeper/msg_server_restore_interchain_account.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" @@ -27,7 +28,7 @@ func (k msgServer) RestoreInterchainAccount(goCtx context.Context, msg *types.Ms if !found { errMsg := fmt.Sprintf("invalid connection id from host %s, %s not found", msg.ChainId, hostZone.ConnectionId) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, errMsg) } counterpartyConnection := connectionEnd.Counterparty @@ -43,7 +44,7 @@ func (k msgServer) RestoreInterchainAccount(goCtx context.Context, msg *types.Ms if !exists { errMsg := fmt.Sprintf("ICA controller account address not found: %s", owner) k.Logger(ctx).Error(errMsg) - return nil, sdkerrors.Wrapf(types.ErrInvalidInterchainAccountAddress, errMsg) + return nil, errorsmod.Wrapf(types.ErrInvalidInterchainAccountAddress, errMsg) } appVersion := string(icatypes.ModuleCdc.MustMarshalJSON(&icatypes.Metadata{ diff --git a/x/stakeibc/keeper/msg_server_submit_tx.go b/x/stakeibc/keeper/msg_server_submit_tx.go index a38ad37f65..599292afe3 100644 --- a/x/stakeibc/keeper/msg_server_submit_tx.go +++ b/x/stakeibc/keeper/msg_server_submit_tx.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/types/bech32" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/spf13/cast" @@ -34,18 +35,18 @@ func (k Keeper) DelegateOnHost(ctx sdk.Context, hostZone types.HostZone, amt sdk owner := types.FormatICAAccountOwner(hostZone.ChainId, types.ICAAccountType_DELEGATION) portID, err := icatypes.NewControllerPortID(owner) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s has no associated portId", owner) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "%s has no associated portId", owner) } connectionId, err := k.GetConnectionId(ctx, portID) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidChainID, "%s has no associated connection", portID) + return errorsmod.Wrapf(sdkerrors.ErrInvalidChainID, "%s has no associated connection", portID) } // Fetch the relevant ICA delegationAccount := hostZone.DelegationAccount if delegationAccount == nil || delegationAccount.Address == "" { k.Logger(ctx).Error(fmt.Sprintf("Zone %s is missing a delegation address!", hostZone.ChainId)) - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid delegation account") + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid delegation account") } // Construct the transaction @@ -88,7 +89,7 @@ func (k Keeper) DelegateOnHost(ctx sdk.Context, hostZone types.HostZone, amt sdk // Send the transaction through SubmitTx _, err = k.SubmitTxsStrideEpoch(ctx, connectionId, msgs, *delegationAccount, ICACallbackID_Delegate, marshalledCallbackArgs) if err != nil { - return sdkerrors.Wrapf(err, "Failed to SubmitTxs for connectionId %s on %s. Messages: %s", connectionId, hostZone.ChainId, msgs) + return errorsmod.Wrapf(err, "Failed to SubmitTxs for connectionId %s on %s. Messages: %s", connectionId, hostZone.ChainId, msgs) } k.Logger(ctx).Info(utils.LogWithHostZone(hostZone.ChainId, "ICA MsgDelegates Successfully Sent")) @@ -104,11 +105,11 @@ func (k Keeper) SetWithdrawalAddressOnHost(ctx sdk.Context, hostZone types.HostZ owner := types.FormatICAAccountOwner(hostZone.ChainId, types.ICAAccountType_DELEGATION) portID, err := icatypes.NewControllerPortID(owner) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "%s has no associated portId", owner) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "%s has no associated portId", owner) } connectionId, err := k.GetConnectionId(ctx, portID) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidChainID, "%s has no associated connection", portID) + return errorsmod.Wrapf(sdkerrors.ErrInvalidChainID, "%s has no associated connection", portID) } // Fetch the relevant ICA @@ -134,7 +135,7 @@ func (k Keeper) SetWithdrawalAddressOnHost(ctx sdk.Context, hostZone types.HostZ } _, err = k.SubmitTxsStrideEpoch(ctx, connectionId, msgs, *delegationAccount, "", nil) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s", connectionId, hostZone.ChainId, msgs) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to SubmitTxs for %s, %s, %s", connectionId, hostZone.ChainId, msgs) } return nil @@ -147,21 +148,21 @@ func (k Keeper) UpdateWithdrawalBalance(ctx sdk.Context, hostZone types.HostZone // Get the withdrawal account address from the host zone withdrawalAccount := hostZone.WithdrawalAccount if withdrawalAccount == nil || withdrawalAccount.Address == "" { - return sdkerrors.Wrapf(types.ErrICAAccountNotFound, "no withdrawal account found for %s", hostZone.ChainId) + return errorsmod.Wrapf(types.ErrICAAccountNotFound, "no withdrawal account found for %s", hostZone.ChainId) } // Encode the withdrawal account address for the query request // The query request consists of the withdrawal account address and denom _, withdrawalAddressBz, err := bech32.DecodeAndConvert(withdrawalAccount.Address) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid withdrawal account address, could not decode (%s)", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid withdrawal account address, could not decode (%s)", err.Error()) } queryData := append(bankTypes.CreateAccountBalancesPrefix(withdrawalAddressBz), []byte(hostZone.HostDenom)...) // The query should timeout at the end of the ICA buffer window ttl, err := k.GetICATimeoutNanos(ctx, epochstypes.STRIDE_EPOCH) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to get ICA timeout nanos for epochType %s using param, error: %s", epochstypes.STRIDE_EPOCH, err.Error()) } @@ -190,7 +191,7 @@ func (k Keeper) GetStartTimeNextEpoch(ctx sdk.Context, epochType string) (uint64 epochTracker, found := k.GetEpochTracker(ctx, epochType) if !found { k.Logger(ctx).Error(fmt.Sprintf("Failed to get epoch tracker for %s", epochType)) - return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to get epoch tracker for %s", epochType) + return 0, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to get epoch tracker for %s", epochType) } return epochTracker.NextEpochStartTime, nil } @@ -237,7 +238,7 @@ func (k Keeper) SubmitTxsEpoch( timeoutNanosUint64, err := k.GetICATimeoutNanos(ctx, epochType) if err != nil { k.Logger(ctx).Error(fmt.Sprintf("Failed to get ICA timeout nanos for epochType %s using param, error: %s", epochType, err.Error())) - return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to convert timeoutNanos to uint64, error: %s", err.Error()) + return 0, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "Failed to convert timeoutNanos to uint64, error: %s", err.Error()) } sequence, err := k.SubmitTxs(ctx, connectionId, msgs, account, timeoutNanosUint64, callbackId, callbackArgs) if err != nil { @@ -273,12 +274,12 @@ func (k Keeper) SubmitTxs( channelID, found := k.ICAControllerKeeper.GetActiveChannelID(ctx, connectionId, portID) if !found { - return 0, sdkerrors.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) + return 0, errorsmod.Wrapf(icatypes.ErrActiveChannelNotFound, "failed to retrieve active channel for port %s", portID) } chanCap, found := k.scopedKeeper.GetCapability(ctx, host.ChannelCapabilityPath(portID, channelID)) if !found { - return 0, sdkerrors.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") + return 0, errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") } data, err := icatypes.SerializeCosmosTx(k.cdc, msgs) @@ -364,33 +365,33 @@ func (k Keeper) QueryValidatorExchangeRate(ctx sdk.Context, msg *types.MsgUpdate // Ensure ICQ can be issued now! else fail the callback withinBufferWindow, err := k.IsWithinBufferWindow(ctx) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) } else if !withinBufferWindow { - return nil, sdkerrors.Wrapf(types.ErrOutsideIcqWindow, "outside the buffer time during which ICQs are allowed (%s)", msg.ChainId) + return nil, errorsmod.Wrapf(types.ErrOutsideIcqWindow, "outside the buffer time during which ICQs are allowed (%s)", msg.ChainId) } // Confirm the host zone exists hostZone, found := k.GetHostZone(ctx, msg.ChainId) if !found { - return nil, sdkerrors.Wrapf(types.ErrInvalidHostZone, "Host zone not found (%s)", msg.ChainId) + return nil, errorsmod.Wrapf(types.ErrInvalidHostZone, "Host zone not found (%s)", msg.ChainId) } // check that the validator address matches the bech32 prefix of the hz if !strings.Contains(msg.Valoper, hostZone.Bech32Prefix) { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "validator operator address must match the host zone bech32 prefix") + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "validator operator address must match the host zone bech32 prefix") } // Encode the validator address to form the query request _, validatorAddressBz, err := bech32.DecodeAndConvert(msg.Valoper) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid validator operator address, could not decode (%s)", err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid validator operator address, could not decode (%s)", err.Error()) } queryData := stakingtypes.GetValidatorKey(validatorAddressBz) // The query should timeout at the start of the next epoch ttl, err := k.GetStartTimeNextEpoch(ctx, epochstypes.STRIDE_EPOCH) if err != nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "could not get start time for next epoch: %s", err.Error()) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "could not get start time for next epoch: %s", err.Error()) } // Submit validator exchange rate ICQ @@ -420,30 +421,30 @@ func (k Keeper) QueryDelegationsIcq(ctx sdk.Context, hostZone types.HostZone, va // Ensure ICQ can be issued now! else fail the callback valid, err := k.IsWithinBufferWindow(ctx) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unable to determine if ICQ callback is inside buffer window, err: %s", err.Error()) } else if !valid { - return sdkerrors.Wrapf(types.ErrOutsideIcqWindow, "outside the buffer time during which ICQs are allowed (%s)", hostZone.HostDenom) + return errorsmod.Wrapf(types.ErrOutsideIcqWindow, "outside the buffer time during which ICQs are allowed (%s)", hostZone.HostDenom) } // Get the validator and delegator encoded addresses to form the query request delegationAccount := hostZone.DelegationAccount if delegationAccount == nil || delegationAccount.Address == "" { - return sdkerrors.Wrapf(types.ErrICAAccountNotFound, "no delegation address found for %s", hostZone.ChainId) + return errorsmod.Wrapf(types.ErrICAAccountNotFound, "no delegation address found for %s", hostZone.ChainId) } _, validatorAddressBz, err := bech32.DecodeAndConvert(valoper) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid validator address, could not decode (%s)", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid validator address, could not decode (%s)", err.Error()) } _, delegatorAddressBz, err := bech32.DecodeAndConvert(delegationAccount.Address) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid delegator address, could not decode (%s)", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid delegator address, could not decode (%s)", err.Error()) } queryData := stakingtypes.GetDelegationKey(delegatorAddressBz, validatorAddressBz) // The query should timeout at the start of the next epoch ttl, err := k.GetStartTimeNextEpoch(ctx, epochstypes.STRIDE_EPOCH) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "could not get start time for next epoch: %s", err.Error()) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "could not get start time for next epoch: %s", err.Error()) } // Submit delegator shares ICQ diff --git a/x/stakeibc/keeper/unbonding_records.go b/x/stakeibc/keeper/unbonding_records.go index ce59100dfb..4df61871ac 100644 --- a/x/stakeibc/keeper/unbonding_records.go +++ b/x/stakeibc/keeper/unbonding_records.go @@ -5,6 +5,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -79,7 +81,7 @@ func (k Keeper) GetHostZoneUnbondingMsgs(ctx sdk.Context, hostZone types.HostZon if err != nil { errMsg := fmt.Sprintf("Error getting target val amts for host zone %s %v: %s", hostZone.ChainId, totalAmountToUnbond, err) k.Logger(ctx).Error(errMsg) - return nil, sdkmath.ZeroInt(), nil, nil, sdkerrors.Wrap(types.ErrNoValidatorAmts, errMsg) + return nil, sdkmath.ZeroInt(), nil, nil, errorsmod.Wrap(types.ErrNoValidatorAmts, errMsg) } // Check if each validator has enough current delegations to cover the target unbonded amount @@ -132,7 +134,7 @@ func (k Keeper) GetHostZoneUnbondingMsgs(ctx sdk.Context, hostZone types.HostZon errMsg := fmt.Sprintf("Could not unbond %v on Host Zone %s, unable to balance the unbond amount across validators", totalAmountToUnbond, hostZone.ChainId) k.Logger(ctx).Error(errMsg) - return nil, sdkmath.ZeroInt(), nil, nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, errMsg) + return nil, sdkmath.ZeroInt(), nil, nil, errorsmod.Wrap(sdkerrors.ErrNotFound, errMsg) } // Get the delegation account @@ -140,7 +142,7 @@ func (k Keeper) GetHostZoneUnbondingMsgs(ctx sdk.Context, hostZone types.HostZon if delegationAccount == nil || delegationAccount.Address == "" { errMsg := fmt.Sprintf("Zone %s is missing a delegation address!", hostZone.ChainId) k.Logger(ctx).Error(errMsg) - return nil, sdkmath.ZeroInt(), nil, nil, sdkerrors.Wrap(types.ErrHostZoneICAAccountNotFound, errMsg) + return nil, sdkmath.ZeroInt(), nil, nil, errorsmod.Wrap(types.ErrHostZoneICAAccountNotFound, errMsg) } // Construct the MsgUndelegate transaction @@ -169,7 +171,7 @@ func (k Keeper) GetHostZoneUnbondingMsgs(ctx sdk.Context, hostZone types.HostZon // Shouldn't be possible, but if all the validator's had a target unbonding of zero, do not send an ICA if len(msgs) == 0 { - return nil, sdkmath.ZeroInt(), nil, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Target unbonded amount was 0 for each validator") + return nil, sdkmath.ZeroInt(), nil, nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Target unbonded amount was 0 for each validator") } // Store the callback data @@ -182,7 +184,7 @@ func (k Keeper) GetHostZoneUnbondingMsgs(ctx sdk.Context, hostZone types.HostZon marshalledCallbackArgs, err = k.MarshalUndelegateCallbackArgs(ctx, undelegateCallback) if err != nil { k.Logger(ctx).Error(err.Error()) - return nil, sdkmath.ZeroInt(), nil, nil, sdkerrors.Wrap(sdkerrors.ErrNotFound, err.Error()) + return nil, sdkmath.ZeroInt(), nil, nil, errorsmod.Wrap(sdkerrors.ErrNotFound, err.Error()) } return msgs, totalAmountToUnbond, marshalledCallbackArgs, epochUnbondingRecordIds, nil @@ -194,14 +196,14 @@ func (k Keeper) SubmitHostZoneUnbondingMsg(ctx sdk.Context, msgs []sdk.Msg, tota // safety check: if msgs is nil, error if msgs == nil { - return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "no msgs to submit for host zone unbondings") + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "no msgs to submit for host zone unbondings") } _, err := k.SubmitTxsDayEpoch(ctx, hostZone.GetConnectionId(), msgs, *delegationAccount, ICACallbackID_Undelegate, marshalledCallbackArgs) if err != nil { errMsg := fmt.Sprintf("Error submitting unbonding tx: %s", err) k.Logger(ctx).Error(errMsg) - return sdkerrors.Wrap(sdkerrors.ErrNotFound, errMsg) + return errorsmod.Wrap(sdkerrors.ErrNotFound, errMsg) } ctx.EventManager().EmitEvent( diff --git a/x/stakeibc/migrations/v2/migrations.go b/x/stakeibc/migrations/v2/migrations.go index f4e3704a65..de10f581f6 100644 --- a/x/stakeibc/migrations/v2/migrations.go +++ b/x/stakeibc/migrations/v2/migrations.go @@ -5,8 +5,8 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" storetypes "github.com/cosmos/cosmos-sdk/store/types" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" oldstakeibctypes "github.com/Stride-Labs/stride/v5/x/stakeibc/migrations/v2/types" stakeibctypes "github.com/Stride-Labs/stride/v5/x/stakeibc/types" @@ -23,14 +23,14 @@ func migrateHostZone(store sdk.KVStore, cdc codec.BinaryCodec) error { var oldHostZone oldstakeibctypes.HostZone err := cdc.Unmarshal(iterator.Value(), &oldHostZone) if err != nil { - return sdkerrors.Wrapf(err, "unable to unmarshal host zone (%v) using old data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to unmarshal host zone (%v) using old data type", iterator.Key()) } // Convert and serialize using the new type newHostZone := convertToNewHostZone(oldHostZone) newHostZoneBz, err := cdc.Marshal(&newHostZone) if err != nil { - return sdkerrors.Wrapf(err, "unable to marshal host zone (%v) using new data type", iterator.Key()) + return errorsmod.Wrapf(err, "unable to marshal host zone (%v) using new data type", iterator.Key()) } // Store new type diff --git a/x/stakeibc/module_ibc.go b/x/stakeibc/module_ibc.go index 37b68629d8..48b60ca38b 100644 --- a/x/stakeibc/module_ibc.go +++ b/x/stakeibc/module_ibc.go @@ -3,8 +3,8 @@ package stakeibc import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" icatypes "github.com/cosmos/ibc-go/v5/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -140,7 +140,7 @@ func (im IBCModule) OnAcknowledgementPacket( errMsg := fmt.Sprintf("Unable to unpack message data from acknowledgement, Sequence %d, from %s %s, to %s %s: %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort, err.Error()) im.keeper.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(icacallbacktypes.ErrInvalidAcknowledgement, errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrInvalidAcknowledgement, errMsg) } ackInfo := fmt.Sprintf("sequence #%d, from %s %s, to %s %s", @@ -161,7 +161,7 @@ func (im IBCModule) OnAcknowledgementPacket( errMsg := fmt.Sprintf("Unable to call registered callback from stakeibc OnAcknowledgePacket | Sequence %d, from %s %s, to %s %s", modulePacket.Sequence, modulePacket.SourceChannel, modulePacket.SourcePort, modulePacket.DestinationChannel, modulePacket.DestinationPort) im.keeper.Logger(ctx).Error(errMsg) - return sdkerrors.Wrapf(icacallbacktypes.ErrCallbackFailed, errMsg) + return errorsmod.Wrapf(icacallbacktypes.ErrCallbackFailed, errMsg) } return nil } diff --git a/x/stakeibc/proposal_handler.go b/x/stakeibc/proposal_handler.go index 3011514507..aeb6b26c48 100644 --- a/x/stakeibc/proposal_handler.go +++ b/x/stakeibc/proposal_handler.go @@ -1,6 +1,7 @@ package stakeibc import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -17,7 +18,7 @@ func NewStakeibcProposalHandler(k keeper.Keeper) govtypes.Handler { return handleAddValidatorProposal(ctx, k, c) default: - return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized stakeibc proposal content type: %T", c) + return errorsmod.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized stakeibc proposal content type: %T", c) } } } diff --git a/x/stakeibc/types/errors.go b/x/stakeibc/types/errors.go index 6b7a3ff3fb..387cbe6818 100644 --- a/x/stakeibc/types/errors.go +++ b/x/stakeibc/types/errors.go @@ -2,50 +2,48 @@ package types // DONTCOVER -import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) +import errorsmod "cosmossdk.io/errors" // x/stakeibc module sentinel errors var ( - ErrInvalidVersion = sdkerrors.Register(ModuleName, 1501, "invalid version") - ErrInvalidToken = sdkerrors.Register(ModuleName, 1502, "invalid token denom") - ErrInvalidHostZone = sdkerrors.Register(ModuleName, 1503, "host zone not registered") - ErrICAStake = sdkerrors.Register(ModuleName, 1504, "ICA stake failed") - ErrEpochNotFound = sdkerrors.Register(ModuleName, 1505, "epoch not found") - ErrRecordNotFound = sdkerrors.Register(ModuleName, 1506, "record not found") - ErrInvalidAmount = sdkerrors.Register(ModuleName, 1507, "invalid amount") - ErrValidatorAlreadyExists = sdkerrors.Register(ModuleName, 1508, "validator already exists") - ErrNoValidatorWeights = sdkerrors.Register(ModuleName, 1509, "no non-zero validator weights") - ErrValidatorNotFound = sdkerrors.Register(ModuleName, 1510, "validator not found") - ErrWeightsNotDifferent = sdkerrors.Register(ModuleName, 1511, "validator weights haven't changed") - ErrValidatorDelegationChg = sdkerrors.Register(ModuleName, 1512, "can't change delegation on validator") - ErrAcctNotScopedForFunc = sdkerrors.Register(ModuleName, 1513, "this account can't call this function") - ErrInsufficientFunds = sdkerrors.Register(ModuleName, 1514, "balance is insufficient") - ErrInvalidUserRedemptionRecord = sdkerrors.Register(ModuleName, 1515, "user redemption record error") - ErrRequiredFieldEmpty = sdkerrors.Register(ModuleName, 1516, "required field is missing") - ErrInvalidNumValidator = sdkerrors.Register(ModuleName, 1517, "invalid number of validators") - ErrValidatorNotRemoved = sdkerrors.Register(ModuleName, 1518, "validator not removed") - ErrHostZoneNotFound = sdkerrors.Register(ModuleName, 1519, "host zone not found") - ErrOutsideIcqWindow = sdkerrors.Register(ModuleName, 1520, "outside time window that accepts icqs") - ErrParamNotFound = sdkerrors.Register(ModuleName, 1521, "param not found") - ErrUnmarshalFailure = sdkerrors.Register(ModuleName, 1522, "unable to unmarshal data structure") - ErrMarshalFailure = sdkerrors.Register(ModuleName, 1523, "unable to marshal data structure") - ErrInvalidPacketCompletionTime = sdkerrors.Register(ModuleName, 1524, "invalid packet completion time") - ErrIntCast = sdkerrors.Register(ModuleName, 1525, "unable to cast to safe cast int") - ErrFeeAccountNotRegistered = sdkerrors.Register(ModuleName, 1526, "fee account is not registered") - ErrRedemptionRateOutsideSafetyBounds = sdkerrors.Register(ModuleName, 1527, "redemption rate outside safety bounds") - ErrTxMsgDataInvalid = sdkerrors.Register(ModuleName, 1528, "TxMsgData invalid") - ErrFailedToRegisterHostZone = sdkerrors.Register(ModuleName, 1529, "failed to register host zone") - ErrInvalidInterchainAccountAddress = sdkerrors.Register(ModuleName, 1530, "invalid interchain account address") - ErrICAAccountNotFound = sdkerrors.Register(ModuleName, 1531, "ICA acccount not found on host zone") - ErrICATxFailed = sdkerrors.Register(ModuleName, 1532, "failed to submit ICA transaction") - ErrICQFailed = sdkerrors.Register(ModuleName, 1533, "failed to submit ICQ") - ErrDivisionByZero = sdkerrors.Register(ModuleName, 1534, "division by zero") - ErrSlashExceedsSafetyThreshold = sdkerrors.Register(ModuleName, 1535, "slash is greater than safety threshold") - ErrInvalidEpoch = sdkerrors.Register(ModuleName, 1536, "invalid epoch tracker") - ErrHostZoneICAAccountNotFound = sdkerrors.Register(ModuleName, 1537, "host zone's ICA account not found") - ErrNoValidatorAmts = sdkerrors.Register(ModuleName, 1538, "could not fetch validator amts") - ErrMaxNumValidators = sdkerrors.Register(ModuleName, 1539, "max number of validators reached") - ErrUndelegationAmount = sdkerrors.Register(ModuleName, 1540, "Undelegation amount is greater than stakedBal") + ErrInvalidVersion = errorsmod.Register(ModuleName, 1501, "invalid version") + ErrInvalidToken = errorsmod.Register(ModuleName, 1502, "invalid token denom") + ErrInvalidHostZone = errorsmod.Register(ModuleName, 1503, "host zone not registered") + ErrICAStake = errorsmod.Register(ModuleName, 1504, "ICA stake failed") + ErrEpochNotFound = errorsmod.Register(ModuleName, 1505, "epoch not found") + ErrRecordNotFound = errorsmod.Register(ModuleName, 1506, "record not found") + ErrInvalidAmount = errorsmod.Register(ModuleName, 1507, "invalid amount") + ErrValidatorAlreadyExists = errorsmod.Register(ModuleName, 1508, "validator already exists") + ErrNoValidatorWeights = errorsmod.Register(ModuleName, 1509, "no non-zero validator weights") + ErrValidatorNotFound = errorsmod.Register(ModuleName, 1510, "validator not found") + ErrWeightsNotDifferent = errorsmod.Register(ModuleName, 1511, "validator weights haven't changed") + ErrValidatorDelegationChg = errorsmod.Register(ModuleName, 1512, "can't change delegation on validator") + ErrAcctNotScopedForFunc = errorsmod.Register(ModuleName, 1513, "this account can't call this function") + ErrInsufficientFunds = errorsmod.Register(ModuleName, 1514, "balance is insufficient") + ErrInvalidUserRedemptionRecord = errorsmod.Register(ModuleName, 1515, "user redemption record error") + ErrRequiredFieldEmpty = errorsmod.Register(ModuleName, 1516, "required field is missing") + ErrInvalidNumValidator = errorsmod.Register(ModuleName, 1517, "invalid number of validators") + ErrValidatorNotRemoved = errorsmod.Register(ModuleName, 1518, "validator not removed") + ErrHostZoneNotFound = errorsmod.Register(ModuleName, 1519, "host zone not found") + ErrOutsideIcqWindow = errorsmod.Register(ModuleName, 1520, "outside time window that accepts icqs") + ErrParamNotFound = errorsmod.Register(ModuleName, 1521, "param not found") + ErrUnmarshalFailure = errorsmod.Register(ModuleName, 1522, "unable to unmarshal data structure") + ErrMarshalFailure = errorsmod.Register(ModuleName, 1523, "unable to marshal data structure") + ErrInvalidPacketCompletionTime = errorsmod.Register(ModuleName, 1524, "invalid packet completion time") + ErrIntCast = errorsmod.Register(ModuleName, 1525, "unable to cast to safe cast int") + ErrFeeAccountNotRegistered = errorsmod.Register(ModuleName, 1526, "fee account is not registered") + ErrRedemptionRateOutsideSafetyBounds = errorsmod.Register(ModuleName, 1527, "redemption rate outside safety bounds") + ErrTxMsgDataInvalid = errorsmod.Register(ModuleName, 1528, "TxMsgData invalid") + ErrFailedToRegisterHostZone = errorsmod.Register(ModuleName, 1529, "failed to register host zone") + ErrInvalidInterchainAccountAddress = errorsmod.Register(ModuleName, 1530, "invalid interchain account address") + ErrICAAccountNotFound = errorsmod.Register(ModuleName, 1531, "ICA acccount not found on host zone") + ErrICATxFailed = errorsmod.Register(ModuleName, 1532, "failed to submit ICA transaction") + ErrICQFailed = errorsmod.Register(ModuleName, 1533, "failed to submit ICQ") + ErrDivisionByZero = errorsmod.Register(ModuleName, 1534, "division by zero") + ErrSlashExceedsSafetyThreshold = errorsmod.Register(ModuleName, 1535, "slash is greater than safety threshold") + ErrInvalidEpoch = errorsmod.Register(ModuleName, 1536, "invalid epoch tracker") + ErrHostZoneICAAccountNotFound = errorsmod.Register(ModuleName, 1537, "host zone's ICA account not found") + ErrNoValidatorAmts = errorsmod.Register(ModuleName, 1538, "could not fetch validator amts") + ErrMaxNumValidators = errorsmod.Register(ModuleName, 1539, "max number of validators reached") + ErrUndelegationAmount = errorsmod.Register(ModuleName, 1540, "Undelegation amount is greater than stakedBal") ) diff --git a/x/stakeibc/types/message_add_validator.go b/x/stakeibc/types/message_add_validator.go index 07138fb5aa..2fdf98ebf5 100644 --- a/x/stakeibc/types/message_add_validator.go +++ b/x/stakeibc/types/message_add_validator.go @@ -3,6 +3,7 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -48,18 +49,18 @@ func (msg *MsgAddValidator) GetSignBytes() []byte { func (msg *MsgAddValidator) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := utils.ValidateAdminAddress(msg.Creator); err != nil { return err } // name validation if len(strings.TrimSpace(msg.Name)) == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "name is required") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "name is required") } // commission validation if msg.Commission > 100 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "commission must be between 0 and 100") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "commission must be between 0 and 100") } return nil diff --git a/x/stakeibc/types/message_change_validator_weight.go b/x/stakeibc/types/message_change_validator_weight.go index ba47935d25..1ff60dde67 100644 --- a/x/stakeibc/types/message_change_validator_weight.go +++ b/x/stakeibc/types/message_change_validator_weight.go @@ -1,6 +1,7 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -44,7 +45,7 @@ func (msg *MsgChangeValidatorWeight) GetSignBytes() []byte { func (msg *MsgChangeValidatorWeight) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := utils.ValidateAdminAddress(msg.Creator); err != nil { return err diff --git a/x/stakeibc/types/message_claim_undelegated_tokens.go b/x/stakeibc/types/message_claim_undelegated_tokens.go index 981771fe99..ea798c38da 100644 --- a/x/stakeibc/types/message_claim_undelegated_tokens.go +++ b/x/stakeibc/types/message_claim_undelegated_tokens.go @@ -1,6 +1,7 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -44,19 +45,19 @@ func (msg *MsgClaimUndelegatedTokens) GetSignBytes() []byte { func (msg *MsgClaimUndelegatedTokens) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } // sender must be a valid stride address _, err = utils.AccAddressFromBech32(msg.Sender, "stride") if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err) } // validate host denom is not empty if msg.HostZoneId == "" { - return sdkerrors.Wrapf(ErrRequiredFieldEmpty, "host zone id cannot be empty") + return errorsmod.Wrapf(ErrRequiredFieldEmpty, "host zone id cannot be empty") } if !(msg.Epoch < (1<<63 - 1)) { - return sdkerrors.Wrapf(ErrInvalidAmount, "epoch must be less than math.MaxInt64 %d", 1<<63-1) + return errorsmod.Wrapf(ErrInvalidAmount, "epoch must be less than math.MaxInt64 %d", 1<<63-1) } return nil } diff --git a/x/stakeibc/types/message_clear_balance.go b/x/stakeibc/types/message_clear_balance.go index 6d0f55f33d..6073e5e359 100644 --- a/x/stakeibc/types/message_clear_balance.go +++ b/x/stakeibc/types/message_clear_balance.go @@ -3,6 +3,8 @@ package types import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -46,21 +48,21 @@ func (msg *MsgClearBalance) GetSignBytes() []byte { func (msg *MsgClearBalance) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := utils.ValidateAdminAddress(msg.Creator); err != nil { return err } // basic checks on host denom if len(msg.ChainId) == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "chainid is required") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "chainid is required") } if msg.Amount.LTE(sdkmath.ZeroInt()) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "amount must be greater than 0") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "amount must be greater than 0") } if isValid := channeltypes.IsValidChannelID(msg.Channel); !isValid { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "channel is invalid") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "channel is invalid") } return nil } diff --git a/x/stakeibc/types/message_delete_validator.go b/x/stakeibc/types/message_delete_validator.go index f2c72671e0..800485127b 100644 --- a/x/stakeibc/types/message_delete_validator.go +++ b/x/stakeibc/types/message_delete_validator.go @@ -1,6 +1,7 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -43,7 +44,7 @@ func (msg *MsgDeleteValidator) GetSignBytes() []byte { func (msg *MsgDeleteValidator) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := utils.ValidateAdminAddress(msg.Creator); err != nil { return err diff --git a/x/stakeibc/types/message_liquid_stake.go b/x/stakeibc/types/message_liquid_stake.go index 6817370551..6174eee00b 100644 --- a/x/stakeibc/types/message_liquid_stake.go +++ b/x/stakeibc/types/message_liquid_stake.go @@ -5,6 +5,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -54,15 +56,15 @@ func (msg *MsgLiquidStake) GetSignBytes() []byte { func (msg *MsgLiquidStake) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } // validate amount is positive nonzero if msg.Amount.LTE(sdkmath.ZeroInt()) { - return sdkerrors.Wrapf(ErrInvalidAmount, "amount liquid staked must be positive and nonzero") + return errorsmod.Wrapf(ErrInvalidAmount, "amount liquid staked must be positive and nonzero") } // validate host denom is not empty if msg.HostDenom == "" { - return sdkerrors.Wrapf(ErrRequiredFieldEmpty, "host denom cannot be empty") + return errorsmod.Wrapf(ErrRequiredFieldEmpty, "host denom cannot be empty") } // host denom must be a valid asset denom if err := sdk.ValidateDenom(msg.HostDenom); err != nil { diff --git a/x/stakeibc/types/message_rebalance_validators.go b/x/stakeibc/types/message_rebalance_validators.go index 1d4726b377..1db275e47c 100644 --- a/x/stakeibc/types/message_rebalance_validators.go +++ b/x/stakeibc/types/message_rebalance_validators.go @@ -3,6 +3,7 @@ package types import ( fmt "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -45,13 +46,13 @@ func (msg *MsgRebalanceValidators) GetSignBytes() []byte { func (msg *MsgRebalanceValidators) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := utils.ValidateAdminAddress(msg.Creator); err != nil { return err } if (msg.NumRebalance < 1) || (msg.NumRebalance > 10) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, fmt.Sprintf("invalid number of validators to rebalance (%d)", msg.NumRebalance)) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, fmt.Sprintf("invalid number of validators to rebalance (%d)", msg.NumRebalance)) } return nil } diff --git a/x/stakeibc/types/message_redeem_stake.go b/x/stakeibc/types/message_redeem_stake.go index bbcd92ee2a..89c7142391 100644 --- a/x/stakeibc/types/message_redeem_stake.go +++ b/x/stakeibc/types/message_redeem_stake.go @@ -3,6 +3,8 @@ package types import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -44,20 +46,20 @@ func (msg *MsgRedeemStake) ValidateBasic() error { // check valid creator address _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } // validate host zone is not empty // we check validity in the RedeemState function if msg.Receiver == "" { - return sdkerrors.Wrapf(ErrRequiredFieldEmpty, "receiver cannot be empty") + return errorsmod.Wrapf(ErrRequiredFieldEmpty, "receiver cannot be empty") } // ensure amount is a nonzero positive integer if msg.Amount.LTE(sdkmath.ZeroInt()) { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid amount (%v)", msg.Amount) + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid amount (%v)", msg.Amount) } // validate host zone is not empty if msg.HostZone == "" { - return sdkerrors.Wrapf(ErrRequiredFieldEmpty, "host zone cannot be empty") + return errorsmod.Wrapf(ErrRequiredFieldEmpty, "host zone cannot be empty") } return nil } diff --git a/x/stakeibc/types/message_register_host_zone.go b/x/stakeibc/types/message_register_host_zone.go index c849cd27c3..072058daf5 100644 --- a/x/stakeibc/types/message_register_host_zone.go +++ b/x/stakeibc/types/message_register_host_zone.go @@ -5,6 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" + + errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types" @@ -52,7 +54,7 @@ func (msg *MsgRegisterHostZone) GetSignBytes() []byte { func (msg *MsgRegisterHostZone) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := utils.ValidateAdminAddress(msg.Creator); err != nil { return err @@ -60,7 +62,7 @@ func (msg *MsgRegisterHostZone) ValidateBasic() error { // VALIDATE DENOMS // host denom cannot be empty if msg.HostDenom == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "host denom cannot be empty") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "host denom cannot be empty") } // host denom must be a valid asset denom if err := sdk.ValidateDenom(msg.HostDenom); err != nil { @@ -69,10 +71,10 @@ func (msg *MsgRegisterHostZone) ValidateBasic() error { // ibc denom cannot be empty and must begin with "ibc" if msg.IbcDenom == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "ibc denom cannot be empty") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "ibc denom cannot be empty") } if !strings.HasPrefix(msg.IbcDenom, "ibc") { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "ibc denom must begin with 'ibc'") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "ibc denom must begin with 'ibc'") } // ibc denom must be valid err = ibctransfertypes.ValidateIBCDenom(msg.IbcDenom) @@ -81,26 +83,26 @@ func (msg *MsgRegisterHostZone) ValidateBasic() error { } // bech32 prefix must be non-empty (we validate it fully in msg_server) if strings.TrimSpace(msg.Bech32Prefix) == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "bech32 prefix must be non-empty") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "bech32 prefix must be non-empty") } // connection id cannot be empty and must begin with "connection" if msg.ConnectionId == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "connection id cannot be empty") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "connection id cannot be empty") } if !strings.HasPrefix(msg.ConnectionId, "connection") { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "connection id must begin with 'connection'") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "connection id must begin with 'connection'") } // transfer channel id cannot be empty if msg.TransferChannelId == "" { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "transfer channel id cannot be empty") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "transfer channel id cannot be empty") } // transfer channel id must begin with "channel" if !strings.HasPrefix(msg.TransferChannelId, "channel") { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "transfer channel id must begin with 'channel'") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "transfer channel id must begin with 'channel'") } // unbonding frequency must be positive nonzero if msg.UnbondingFrequency < 1 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "unbonding frequency must be greater than zero") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unbonding frequency must be greater than zero") } return nil diff --git a/x/stakeibc/types/message_restore_interchain_account.go b/x/stakeibc/types/message_restore_interchain_account.go index 634cbe60c9..344dd04aa8 100644 --- a/x/stakeibc/types/message_restore_interchain_account.go +++ b/x/stakeibc/types/message_restore_interchain_account.go @@ -1,6 +1,7 @@ package types import ( + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -41,7 +42,7 @@ func (msg *MsgRestoreInterchainAccount) GetSignBytes() []byte { func (msg *MsgRestoreInterchainAccount) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } return nil } diff --git a/x/stakeibc/types/message_update_delegation.go b/x/stakeibc/types/message_update_delegation.go index ddfa892c6d..1642bb6a83 100644 --- a/x/stakeibc/types/message_update_delegation.go +++ b/x/stakeibc/types/message_update_delegation.go @@ -3,6 +3,7 @@ package types import ( "strings" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -45,21 +46,21 @@ func (msg *MsgUpdateValidatorSharesExchRate) GetSignBytes() []byte { func (msg *MsgUpdateValidatorSharesExchRate) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } if err := utils.ValidateAdminAddress(msg.Creator); err != nil { return err } // basic checks on host denom if len(msg.ChainId) == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "chainid is required") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "chainid is required") } // basic checks on host zone if len(msg.Valoper) == 0 { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "valoper is required") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "valoper is required") } if !strings.Contains(msg.Valoper, "valoper") { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "validator operator address must contrain 'valoper'") + return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "validator operator address must contrain 'valoper'") } return nil