Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coinswap wrong verification #161

Merged
merged 4 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions modules/coinswap/client/rest/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func (s *IntegrationTestSuite) TestCoinswap() {
maxSupply := int64(200000000)
mintable := true
baseURL := val.APIAddress
uniKitty, err := coinswaptypes.GetUniDenomFromDenom(symbol)
s.Require().NoError(err)
uniKitty := coinswaptypes.GetUniDenomFromDenom(symbol)

//------test GetCmdIssueToken()-------------
args := []string{
Expand Down
6 changes: 1 addition & 5 deletions modules/coinswap/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ func removeLiquidityHandlerFn(cliCtx client.Context) http.HandlerFunc {
return
}

uniDenom, e := types.GetUniDenomFromDenom(denom)
if e != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, e.Error())
return
}
uniDenom := types.GetUniDenomFromDenom(denom)

msg := types.NewMsgRemoveLiquidity(
minToken, sdk.NewCoin(uniDenom, liquidityAmt), minStandard, deadline.Unix(), req.Sender,
Expand Down
5 changes: 1 addition & 4 deletions modules/coinswap/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ func (k Keeper) Liquidity(c context.Context, req *types.QueryLiquidityRequest) (
}

tokenDenom := req.Denom
uniDenom, err := types.GetUniDenomFromDenom(tokenDenom)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
}
uniDenom := types.GetUniDenomFromDenom(tokenDenom)

ctx := sdk.UnwrapSDKContext(c)
reservePool, err := k.GetReservePool(ctx, uniDenom)
Expand Down
7 changes: 4 additions & 3 deletions modules/coinswap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ func (k Keeper) Swap(ctx sdk.Context, msg *types.MsgSwapOrder) error {
// AddLiquidity adds liquidity to the specified pool
func (k Keeper) AddLiquidity(ctx sdk.Context, msg *types.MsgAddLiquidity) (sdk.Coin, error) {
standardDenom := k.GetStandardDenom(ctx)
uniDenom, err := types.GetUniDenomFromDenom(msg.MaxToken.Denom)
if err != nil {
return sdk.Coin{}, err
if standardDenom == msg.MaxToken.Denom {
return sdk.Coin{}, sdkerrors.Wrapf(types.ErrInvalidDenom,
"MaxToken: %s should not be StandardDenom", msg.MaxToken.String())
}
uniDenom := types.GetUniDenomFromDenom(msg.MaxToken.Denom)

liquidity := k.bk.GetSupply(ctx).GetTotal().AmountOf(uniDenom)

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 @@ -18,7 +18,7 @@ import (
)

const (
denomStandard = types.StandardDenom
denomStandard = sdk.DefaultBondDenom
denomBTC = "btc"
denomETH = "eth"
unidenomBTC = types.FormatUniABSPrefix + denomBTC
Expand Down
5 changes: 1 addition & 4 deletions modules/coinswap/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ func queryLiquidity(ctx sdk.Context, req abci.RequestQuery, k Keeper, legacyQuer
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}

uniDenom, err := types.GetUniDenomFromDenom(params.Denom)
if err != nil {
return nil, err
}
uniDenom := types.GetUniDenomFromDenom(params.Denom)

standardDenom := k.GetStandardDenom(ctx)
reservePool, err := k.GetReservePool(ctx, uniDenom)
Expand Down
5 changes: 2 additions & 3 deletions modules/coinswap/keeper/swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ func createReservePool(suite *TestSuite, denom string) (sdk.AccAddress, sdk.AccA
),
)

uniDenom, err := types.GetUniDenomFromDenom(denom)
suite.NoError(err)
uniDenom := types.GetUniDenomFromDenom(denom)
reservePoolAddr := types.GetReservePoolAddr(uniDenom)

depositAmt, _ := sdk.NewIntFromString("1000")
Expand All @@ -213,7 +212,7 @@ func createReservePool(suite *TestSuite, denom string) (sdk.AccAddress, sdk.AccA
minReward := sdk.NewInt(1)
deadline := time.Now().Add(1 * time.Minute)
msg := types.NewMsgAddLiquidity(depositCoin, standardAmt, minReward, deadline.Unix(), addrSender.String())
_, err = suite.app.CoinswapKeeper.AddLiquidity(suite.ctx, msg)
_, err := suite.app.CoinswapKeeper.AddLiquidity(suite.ctx, msg)
suite.NoError(err)

moduleAccountBalances := suite.app.BankKeeper.GetSupply(suite.ctx).GetTotal()
Expand Down
2 changes: 1 addition & 1 deletion modules/coinswap/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewGenesisState(params Params, denom string) *GenesisState {

// DefaultGenesisState creates a default GenesisState object
func DefaultGenesisState() *GenesisState {
return NewGenesisState(DefaultParams(), StandardDenom)
return NewGenesisState(DefaultParams(), sdk.DefaultBondDenom)
}

// ValidateGenesis validates the given genesis state
Expand Down
11 changes: 0 additions & 11 deletions modules/coinswap/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ func TestMsgAddLiquidity_ValidateBasic(t *testing.T) {
fields fields
wantErr bool
}{
{
name: "right test case",
wantErr: true,
fields: fields{
MaxToken: buildCoin("stake", 1000),
ExactStandardAmt: sdk.NewInt(100),
MinLiquidity: sdk.NewInt(100),
Deadline: 1611213344,
Sender: sender,
},
},
{
name: "invalid MaxToken denom",
wantErr: true,
Expand Down
5 changes: 0 additions & 5 deletions modules/coinswap/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

const (
// StandardDenom for coinswap
StandardDenom = sdk.DefaultBondDenom
)

// Parameter store keys
var (
KeyFee = []byte("Fee") // fee key
Expand Down
7 changes: 2 additions & 5 deletions modules/coinswap/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ func GetTokenPairByDenom(inputDenom, outputDenom string) string {
}

// GetUniDenomFromDenom returns the uni denom for the provided denomination.
func GetUniDenomFromDenom(denom string) (string, error) {
if denom == StandardDenom {
return "", ErrMustStandardDenom
}
return fmt.Sprintf(FormatUniDenom, denom), nil
func GetUniDenomFromDenom(denom string) string {
return fmt.Sprintf(FormatUniDenom, denom)
}

// GetCoinDenomFromUniDenom returns the token denom by uni denom
Expand Down
4 changes: 0 additions & 4 deletions modules/coinswap/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ func ValidateMaxToken(maxToken sdk.Coin) error {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "invalid maxToken (%s)", maxToken.String())
}

if maxToken.Denom == StandardDenom {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("max token must not be standard token: %s", StandardDenom))
}

if strings.HasPrefix(maxToken.Denom, FormatUniABSPrefix) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "max token must be non-liquidity token")
}
Expand Down