Skip to content

Commit

Permalink
remove legacy sdkerror
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Mar 4, 2024
1 parent 10fcd3a commit 05f8f91
Show file tree
Hide file tree
Showing 107 changed files with 741 additions and 652 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ lint: golangci-lint
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./lite/*/statik.go" -not -path "*.pb.go" | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./lite/*/statik.go" -not -path "*.pb.go" | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./lite/*/statik.go" -not -path "*.pb.go" | xargs goimports -w -local github.com/irisnet/irismod
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -path "./lite/*/statik.go" -not -path "*.pb.go" -not -path "*.pulsar.go" | xargs goimports -w -local github.com/irisnet/irismod

benchmark:
@go test -mod=readonly -bench=. ./...
2 changes: 1 addition & 1 deletion modules/coinswap/keeper/fees.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//nolint
// nolint
package keeper

import (
Expand Down
4 changes: 2 additions & 2 deletions modules/coinswap/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

errorsmod "cosmossdk.io/errors"
"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"

"github.com/irisnet/irismod/modules/coinswap/types"
Expand All @@ -28,7 +28,7 @@ func (k Keeper) LiquidityPool(
ctx := sdk.UnwrapSDKContext(c)
pool, exists := k.GetPoolByLptDenom(ctx, req.LptDenom)
if !exists {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
types.ErrReservePoolNotExists,
"liquidity pool token: %s",
req.LptDenom,
Expand Down
45 changes: 23 additions & 22 deletions modules/coinswap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdkmath "cosmossdk.io/math"
"github.com/cometbft/cometbft/libs/log"

errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -103,7 +104,7 @@ func (k Keeper) Swap(ctx sdk.Context, msg *types.MsgSwapOrder) error {
func (k Keeper) AddLiquidity(ctx sdk.Context, msg *types.MsgAddLiquidity) (sdk.Coin, error) {
standardDenom := k.GetStandardDenom(ctx)
if standardDenom == msg.MaxToken.Denom {
return sdk.Coin{}, sdkerrors.Wrapf(types.ErrInvalidDenom,
return sdk.Coin{}, errorsmod.Wrapf(types.ErrInvalidDenom,
"MaxToken: %s should not be StandardDenom", msg.MaxToken.String())
}

Expand Down Expand Up @@ -131,7 +132,7 @@ func (k Keeper) AddLiquidity(ctx sdk.Context, msg *types.MsgAddLiquidity) (sdk.C

mintLiquidityAmt = msg.ExactStandardAmt
if mintLiquidityAmt.LT(msg.MinLiquidity) {
return sdk.Coin{}, sdkerrors.Wrapf(
return sdk.Coin{}, errorsmod.Wrapf(
types.ErrConstraintNotMet,
"liquidity amount not met, user expected: no less than %s, actual: %s",
msg.MinLiquidity.String(),
Expand Down Expand Up @@ -160,7 +161,7 @@ func (k Keeper) AddLiquidity(ctx sdk.Context, msg *types.MsgAddLiquidity) (sdk.C
if balances == nil || balances.IsZero() {
mintLiquidityAmt = msg.ExactStandardAmt
if mintLiquidityAmt.LT(msg.MinLiquidity) {
return sdk.Coin{}, sdkerrors.Wrapf(
return sdk.Coin{}, errorsmod.Wrapf(
types.ErrConstraintNotMet,
"liquidity amount not met, user expected: no less than %s, actual: %s",
msg.MinLiquidity.String(),
Expand All @@ -185,12 +186,12 @@ func (k Keeper) AddLiquidity(ctx sdk.Context, msg *types.MsgAddLiquidity) (sdk.C
liquidity := k.bk.GetSupply(ctx, pool.LptDenom).Amount
if standardReserveAmt.IsZero() || tokenReserveAmt.IsZero() || liquidity.IsZero() {
return sdk.Coin{},
sdkerrors.Wrapf(types.ErrConstraintNotMet, "liquidity pool invalid")
errorsmod.Wrapf(types.ErrConstraintNotMet, "liquidity pool invalid")
}

mintLiquidityAmt = (liquidity.Mul(msg.ExactStandardAmt)).Quo(standardReserveAmt)
if mintLiquidityAmt.LT(msg.MinLiquidity) {
return sdk.Coin{}, sdkerrors.Wrapf(
return sdk.Coin{}, errorsmod.Wrapf(
types.ErrConstraintNotMet,
"liquidity amount not met, user expected: no less than %s, actual: %s",
msg.MinLiquidity.String(),
Expand All @@ -202,7 +203,7 @@ func (k Keeper) AddLiquidity(ctx sdk.Context, msg *types.MsgAddLiquidity) (sdk.C

if depositAmt.GT(msg.MaxToken.Amount) {
return sdk.Coin{},
sdkerrors.Wrapf(
errorsmod.Wrapf(
types.ErrConstraintNotMet,
"token amount not met, user expected: no more than %s, actual: %s",
msg.MaxToken.String(),
Expand Down Expand Up @@ -273,7 +274,7 @@ func (k Keeper) AddUnilateralLiquidity(
poolID := types.GetPoolId(msg.CounterpartyDenom)
pool, exist := k.GetPool(ctx, poolID)
if !exist {
return sdk.Coin{}, sdkerrors.Wrapf(
return sdk.Coin{}, errorsmod.Wrapf(
types.ErrReservePoolNotExists,
"liquidity pool: %s ",
poolID,
Expand All @@ -292,7 +293,7 @@ func (k Keeper) AddUnilateralLiquidity(

if msg.ExactToken.Denom != msg.CounterpartyDenom &&
msg.ExactToken.Denom != k.GetStandardDenom(ctx) {
return sdk.Coin{}, sdkerrors.Wrapf(
return sdk.Coin{}, errorsmod.Wrapf(
types.ErrInvalidDenom,
"liquidity pool %s has no %s",
poolID,
Expand All @@ -301,7 +302,7 @@ func (k Keeper) AddUnilateralLiquidity(
}

if balances == nil || balances.IsZero() {
return sdk.Coin{}, sdkerrors.Wrapf(
return sdk.Coin{}, errorsmod.Wrapf(
sdkerrors.ErrInvalidRequest,
"When the liquidity is empty, can not add unilateral liquidity",
)
Expand Down Expand Up @@ -329,7 +330,7 @@ func (k Keeper) AddUnilateralLiquidity(
mintLptAmt := sdkmath.NewIntFromBigInt(squareBigInt).Sub(lptBalanceAmt)

if mintLptAmt.LT(msg.MinLiquidity) {
return sdk.Coin{}, sdkerrors.Wrapf(
return sdk.Coin{}, errorsmod.Wrapf(
types.ErrConstraintNotMet,
"liquidity amount not met, user expected: no less than %s, actual: %s",
msg.MinLiquidity.String(),
Expand Down Expand Up @@ -394,7 +395,7 @@ func (k Keeper) RemoveLiquidity(ctx sdk.Context, msg *types.MsgRemoveLiquidity)

pool, exists := k.GetPoolByLptDenom(ctx, msg.WithdrawLiquidity.Denom)
if !exists {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
types.ErrReservePoolNotExists,
"liquidity pool token: %s",
msg.WithdrawLiquidity.Denom,
Expand All @@ -413,7 +414,7 @@ func (k Keeper) RemoveLiquidity(ctx sdk.Context, msg *types.MsgRemoveLiquidity)
tokenReserveAmt := balances.AmountOf(minTokenDenom)
liquidityReserve := k.bk.GetSupply(ctx, lptDenom).Amount
if standardReserveAmt.LT(msg.MinStandardAmt) {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
types.ErrInsufficientFunds,
"insufficient %s funds, user expected: %s, actual: %s",
standardDenom,
Expand All @@ -422,7 +423,7 @@ func (k Keeper) RemoveLiquidity(ctx sdk.Context, msg *types.MsgRemoveLiquidity)
)
}
if tokenReserveAmt.LT(msg.MinToken) {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
types.ErrInsufficientFunds,
"insufficient %s funds, user expected: %s, actual: %s",
minTokenDenom,
Expand All @@ -431,7 +432,7 @@ func (k Keeper) RemoveLiquidity(ctx sdk.Context, msg *types.MsgRemoveLiquidity)
)
}
if liquidityReserve.LT(msg.WithdrawLiquidity.Amount) {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
types.ErrInsufficientFunds,
"insufficient %s funds, user expected: %s, actual: %s",
lptDenom,
Expand All @@ -450,15 +451,15 @@ func (k Keeper) RemoveLiquidity(ctx sdk.Context, msg *types.MsgRemoveLiquidity)
deductUniCoin := msg.WithdrawLiquidity

if irisWithdrawCoin.Amount.LT(msg.MinStandardAmt) {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
types.ErrConstraintNotMet,
"iris amount not met, user expected: no less than %s, actual: %s",
sdk.NewCoin(standardDenom, msg.MinStandardAmt).String(),
irisWithdrawCoin.String(),
)
}
if tokenWithdrawCoin.Amount.LT(msg.MinToken) {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
types.ErrConstraintNotMet,
"token amount not met, user expected: no less than %s, actual: %s",
sdk.NewCoin(minTokenDenom, msg.MinToken).String(),
Expand Down Expand Up @@ -529,7 +530,7 @@ func (k Keeper) RemoveUnilateralLiquidity(
poolID := types.GetPoolId(msg.CounterpartyDenom)
pool, exist := k.GetPool(ctx, poolID)
if !exist {
return sdk.Coins{}, sdkerrors.Wrapf(
return sdk.Coins{}, errorsmod.Wrapf(
types.ErrReservePoolNotExists,
"liquidity pool: %s ",
poolID,
Expand All @@ -548,7 +549,7 @@ func (k Keeper) RemoveUnilateralLiquidity(

if msg.MinToken.Denom != msg.CounterpartyDenom &&
msg.MinToken.Denom != k.GetStandardDenom(ctx) {
return sdk.Coins{}, sdkerrors.Wrapf(types.ErrInvalidDenom,
return sdk.Coins{}, errorsmod.Wrapf(types.ErrInvalidDenom,
"liquidity pool %s has no %s", poolID, msg.MinToken.Denom)
}

Expand All @@ -559,21 +560,21 @@ func (k Keeper) RemoveUnilateralLiquidity(
lptBalanceAmt := k.bk.GetSupply(ctx, lptDenom).Amount

if lptBalanceAmt.LT(msg.ExactLiquidity) {
return sdk.Coins{}, sdkerrors.Wrapf(types.ErrInsufficientFunds,
return sdk.Coins{}, errorsmod.Wrapf(types.ErrInsufficientFunds,
"insufficient %s funds, user expected: %s, actual: %s",
lptDenom, msg.ExactLiquidity.String(), lptBalanceAmt.String())
}

if lptBalanceAmt.Equal(msg.ExactLiquidity) {
return sdk.Coins{}, sdkerrors.Wrapf(
return sdk.Coins{}, errorsmod.Wrapf(
types.ErrConstraintNotMet,
"forbid to withdraw all liquidity unilaterally, should be less than: %s",
lptBalanceAmt.String(),
)
}

if targetBalanceAmt.LT(msg.MinToken.Amount) {
return sdk.Coins{}, sdkerrors.Wrapf(types.ErrInsufficientFunds,
return sdk.Coins{}, errorsmod.Wrapf(types.ErrInsufficientFunds,
"insufficient %s funds, user expected: %s, actual: %s",
targetTokenDenom, msg.MinToken.Amount.String(), targetBalanceAmt.String())
}
Expand Down Expand Up @@ -603,7 +604,7 @@ func (k Keeper) RemoveUnilateralLiquidity(
targetTokenAmtAfterFee := targetTokenNumerator.Quo(targetTokenDenominator)

if targetTokenAmtAfterFee.LT(msg.MinToken.Amount) {
return nil, sdkerrors.Wrapf(types.ErrConstraintNotMet,
return nil, errorsmod.Wrapf(types.ErrConstraintNotMet,
"token withdrawn amount not met, user expected: no less than %s, actual: %s",
msg.MinToken.String(), sdk.NewCoin(targetTokenDenom, targetTokenAmtAfterFee).String())
}
Expand Down
2 changes: 1 addition & 1 deletion modules/coinswap/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (suite *TestSuite) TestLiquidity2() {
suite.Equal(
"14135062787267695755",
suite.app.BankKeeper.GetSupply(suite.ctx, pool.LptDenom).Amount.String(),
) // todo theoretical lpt ammount
) // todo theoretical lpt amount

// 2.2 poolBalances
expCoins = sdk.NewCoins(
Expand Down
15 changes: 8 additions & 7 deletions modules/coinswap/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"time"

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

Expand All @@ -29,7 +30,7 @@ func (m msgServer) AddLiquidity(
ctx := sdk.UnwrapSDKContext(goCtx)
// check that deadline has not passed
if ctx.BlockHeader().Time.After(time.Unix(msg.Deadline, 0)) {
return nil, sdkerrors.Wrap(
return nil, errorsmod.Wrap(
types.ErrInvalidDeadline,
"deadline has passed for MsgAddLiquidity",
)
Expand All @@ -52,7 +53,7 @@ func (m msgServer) AddUnilateralLiquidity(
ctx := sdk.UnwrapSDKContext(goCtx)
// check that deadline has not passed
if ctx.BlockHeader().Time.After(time.Unix(msg.Deadline, 0)) {
return nil, sdkerrors.Wrap(
return nil, errorsmod.Wrap(
types.ErrInvalidDeadline,
"deadline has passed for MsgAddUnilateralLiquidity",
)
Expand All @@ -75,7 +76,7 @@ func (m msgServer) RemoveLiquidity(
ctx := sdk.UnwrapSDKContext(goCtx)
// check that deadline has not passed
if ctx.BlockHeader().Time.After(time.Unix(msg.Deadline, 0)) {
return nil, sdkerrors.Wrap(
return nil, errorsmod.Wrap(
types.ErrInvalidDeadline,
"deadline has passed for MsgRemoveLiquidity",
)
Expand All @@ -96,7 +97,7 @@ func (m msgServer) RemoveUnilateralLiquidity(
ctx := sdk.UnwrapSDKContext(goCtx)
// check that deadline has not passed
if ctx.BlockHeader().Time.After(time.Unix(msg.Deadline, 0)) {
return nil, sdkerrors.Wrap(
return nil, errorsmod.Wrap(
types.ErrInvalidDeadline,
"deadline has passed for MsgRemoveLiquidity",
)
Expand All @@ -118,11 +119,11 @@ func (m msgServer) SwapCoin(
ctx := sdk.UnwrapSDKContext(goCtx)
// check that deadline has not passed
if ctx.BlockHeader().Time.After(time.Unix(msg.Deadline, 0)) {
return nil, sdkerrors.Wrap(types.ErrInvalidDeadline, "deadline has passed for MsgSwapOrder")
return nil, errorsmod.Wrap(types.ErrInvalidDeadline, "deadline has passed for MsgSwapOrder")
}

if m.k.blockedAddrs[msg.Output.Address] {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
"%s is not allowed to receive external funds",
msg.Output.Address,
Expand All @@ -140,7 +141,7 @@ func (m msgServer) UpdateParams(
msg *types.MsgUpdateParams,
) (*types.MsgUpdateParamsResponse, error) {
if m.k.authority != msg.Authority {
return nil, sdkerrors.Wrapf(
return nil, errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
"invalid authority; expected %s, got %s",
m.k.authority,
Expand Down
1 change: 1 addition & 0 deletions modules/coinswap/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
gogotypes "github.com/cosmos/gogoproto/types"

"github.com/irisnet/irismod/modules/coinswap/types"
)

Expand Down
12 changes: 6 additions & 6 deletions modules/coinswap/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

gogotypes "github.com/cosmos/gogoproto/types"

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

"github.com/irisnet/irismod/modules/coinswap/types"
)
Expand Down Expand Up @@ -84,7 +84,7 @@ func (k Keeper) GetPoolBalances(
}
acc := k.ak.GetAccount(ctx, address)
if acc == nil {
return nil, sdkerrors.Wrap(types.ErrReservePoolNotExists, escrowAddress)
return nil, errorsmod.Wrap(types.ErrReservePoolNotExists, escrowAddress)
}
return k.bk.GetAllBalances(ctx, acc.GetAddress()), nil
}
Expand All @@ -96,7 +96,7 @@ func (k Keeper) GetPoolBalancesByLptDenom(
address := types.GetReservePoolAddr(lptDenom)
acc := k.ak.GetAccount(ctx, address)
if acc == nil {
return nil, sdkerrors.Wrap(types.ErrReservePoolNotExists, address.String())
return nil, errorsmod.Wrap(types.ErrReservePoolNotExists, address.String())
}
return k.bk.GetAllBalances(ctx, acc.GetAddress()), nil
}
Expand All @@ -109,7 +109,7 @@ func (k Keeper) GetLptDenomFromDenoms(ctx sdk.Context, denom1, denom2 string) (s

standardDenom := k.GetStandardDenom(ctx)
if denom1 != standardDenom && denom2 != standardDenom {
return "", sdkerrors.Wrap(
return "", errorsmod.Wrap(
types.ErrNotContainStandardDenom,
fmt.Sprintf(
"standard denom: %s, denom1: %s, denom2: %s",
Expand All @@ -127,7 +127,7 @@ func (k Keeper) GetLptDenomFromDenoms(ctx sdk.Context, denom1, denom2 string) (s
poolId := types.GetPoolId(counterpartyDenom)
pool, has := k.GetPool(ctx, poolId)
if !has {
return "", sdkerrors.Wrapf(
return "", errorsmod.Wrapf(
types.ErrReservePoolNotExists,
"liquidity pool token: %s",
counterpartyDenom,
Expand All @@ -144,7 +144,7 @@ func (k Keeper) ValidatePool(ctx sdk.Context, lptDenom string) error {

pool, has := k.GetPoolByLptDenom(ctx, lptDenom)
if !has {
return sdkerrors.Wrapf(types.ErrReservePoolNotExists, "liquidity pool token: %s", lptDenom)
return errorsmod.Wrapf(types.ErrReservePoolNotExists, "liquidity pool token: %s", lptDenom)
}

_, err := k.GetPoolBalances(ctx, pool.EscrowAddress)
Expand Down
Loading

0 comments on commit 05f8f91

Please sign in to comment.