From 38bd33179b7e25ae29ffa68c05a108e12842339d Mon Sep 17 00:00:00 2001 From: Vishnu Kumavat Date: Fri, 22 Jul 2022 10:11:54 +0530 Subject: [PATCH 1/2] price range condition check removed --- x/liquidity/keeper/swap.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/x/liquidity/keeper/swap.go b/x/liquidity/keeper/swap.go index afcf8983d..1b0af5739 100644 --- a/x/liquidity/keeper/swap.go +++ b/x/liquidity/keeper/swap.go @@ -41,21 +41,24 @@ func (k Keeper) ValidateMsgLimitOrder(ctx sdk.Context, msg *types.MsgLimitOrder) return sdk.Coin{}, sdk.Coin{}, sdk.Dec{}, sdkerrors.Wrapf(sdkerrors.ErrNotFound, "pair %d not found", msg.PairId) } - var upperPriceLimit, lowerPriceLimit sdk.Dec - if pair.LastPrice != nil { - lastPrice := *pair.LastPrice - upperPriceLimit = lastPrice.Mul(sdk.OneDec().Add(params.MaxPriceLimitRatio)) - lowerPriceLimit = lastPrice.Mul(sdk.OneDec().Sub(params.MaxPriceLimitRatio)) - } else { - upperPriceLimit = amm.HighestTick(int(params.TickPrecision)) - lowerPriceLimit = amm.LowestTick(int(params.TickPrecision)) - } - switch { - case msg.Price.GT(upperPriceLimit): - return sdk.Coin{}, sdk.Coin{}, sdk.Dec{}, sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is higher than %s", msg.Price, upperPriceLimit) - case msg.Price.LT(lowerPriceLimit): - return sdk.Coin{}, sdk.Coin{}, sdk.Dec{}, sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is lower than %s", msg.Price, lowerPriceLimit) - } + // uncomment the below code if price range limitation needs to enabled, doing so can cause partial-mismatch order issue - + // for the normal swap in frontend. + + // var upperPriceLimit, lowerPriceLimit sdk.Dec + // if pair.LastPrice != nil { + // lastPrice := *pair.LastPrice + // upperPriceLimit = lastPrice.Mul(sdk.OneDec().Add(params.MaxPriceLimitRatio)) + // lowerPriceLimit = lastPrice.Mul(sdk.OneDec().Sub(params.MaxPriceLimitRatio)) + // } else { + // upperPriceLimit = amm.HighestTick(int(params.TickPrecision)) + // lowerPriceLimit = amm.LowestTick(int(params.TickPrecision)) + // } + // switch { + // case msg.Price.GT(upperPriceLimit): + // return sdk.Coin{}, sdk.Coin{}, sdk.Dec{}, sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is higher than %s", msg.Price, upperPriceLimit) + // case msg.Price.LT(lowerPriceLimit): + // return sdk.Coin{}, sdk.Coin{}, sdk.Dec{}, sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is lower than %s", msg.Price, lowerPriceLimit) + // } switch msg.Direction { case types.OrderDirectionBuy: From 31fcb617caeac33615ad144ceb5694d5b2c70f77 Mon Sep 17 00:00:00 2001 From: Vishnu Kumavat Date: Fri, 22 Jul 2022 10:21:54 +0530 Subject: [PATCH 2/2] testcase fixed --- x/liquidity/keeper/swap_test.go | 65 ++++++++++++++++----------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/x/liquidity/keeper/swap_test.go b/x/liquidity/keeper/swap_test.go index a44d7b732..ea48d6c39 100644 --- a/x/liquidity/keeper/swap_test.go +++ b/x/liquidity/keeper/swap_test.go @@ -5,7 +5,6 @@ import ( utils "github.com/comdex-official/comdex/types" "github.com/comdex-official/comdex/x/liquidity" - "github.com/comdex-official/comdex/x/liquidity/amm" "github.com/comdex-official/comdex/x/liquidity/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -79,38 +78,38 @@ func (s *KeeperTestSuite) TestLimitOrder() { ExpErr: sdkerrors.Wrapf(sdkerrors.ErrNotFound, "pair %d not found", 69), ExpResp: &types.Order{}, }, - { - Name: "error price higher than upper limit", - Msg: *types.NewMsgLimitOrder( - appID1, - addr1, - pair.Id, - types.OrderDirectionBuy, - utils.ParseCoin("10030000uasset2"), - asset1.Denom, - amm.HighestTick(int(params.TickPrecision+1)), - newInt(10000000), - time.Second*10, - ), - ExpErr: sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is higher than %s", amm.HighestTick(int(params.TickPrecision+1)), amm.HighestTick(int(params.TickPrecision))), - ExpResp: &types.Order{}, - }, - { - Name: "error price lower than lower limit", - Msg: *types.NewMsgLimitOrder( - appID1, - addr1, - pair.Id, - types.OrderDirectionBuy, - utils.ParseCoin("10030000uasset2"), - asset1.Denom, - amm.LowestTick(int(params.TickPrecision-1)), - newInt(10000000), - time.Second*10, - ), - ExpErr: sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is lower than %s", amm.LowestTick(int(params.TickPrecision-1)), amm.LowestTick(int(params.TickPrecision))), - ExpResp: &types.Order{}, - }, + // { + // Name: "error price higher than upper limit", + // Msg: *types.NewMsgLimitOrder( + // appID1, + // addr1, + // pair.Id, + // types.OrderDirectionBuy, + // utils.ParseCoin("10030000uasset2"), + // asset1.Denom, + // amm.HighestTick(int(params.TickPrecision+1)), + // newInt(10000000), + // time.Second*10, + // ), + // ExpErr: sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is higher than %s", amm.HighestTick(int(params.TickPrecision+1)), amm.HighestTick(int(params.TickPrecision))), + // ExpResp: &types.Order{}, + // }, + // { + // Name: "error price lower than lower limit", + // Msg: *types.NewMsgLimitOrder( + // appID1, + // addr1, + // pair.Id, + // types.OrderDirectionBuy, + // utils.ParseCoin("10030000uasset2"), + // asset1.Denom, + // amm.LowestTick(int(params.TickPrecision-1)), + // newInt(10000000), + // time.Second*10, + // ), + // ExpErr: sdkerrors.Wrapf(types.ErrPriceOutOfRange, "%s is lower than %s", amm.LowestTick(int(params.TickPrecision-1)), amm.LowestTick(int(params.TickPrecision))), + // ExpResp: &types.Order{}, + // }, { Name: "error invalid denom pair buy direction", Msg: *types.NewMsgLimitOrder(