Skip to content

Commit

Permalink
Merge pull request #737 from neutron-org/chore/better_lo_errors
Browse files Browse the repository at this point in the history
Chore: Add ErrNoLiquidity
  • Loading branch information
pr0n00gler authored Oct 7, 2024
2 parents d8f24d7 + 741447c commit 4563a15
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/dex/keeper/grpc_query_estimate_multi_hop_swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *DexTestSuite) TestEstimateMultiHopSwapInsufficientLiquiditySingleRoute(
// THEN estimate multihopswap fails
route := [][]string{{"TokenA", "TokenB", "TokenC", "TokenD"}}
s.aliceEstimatesMultiHopSwapFails(
types.ErrLimitPriceNotSatisfied,
types.ErrNoLiquidity,
route,
100,
math_utils.MustNewPrecDecFromStr("0.9"),
Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/integration_multihopswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (s *DexTestSuite) TestMultiHopSwapInsufficientLiquiditySingleRoute() {
// THEN alice multihopswap fails
route := [][]string{{"TokenA", "TokenB", "TokenC", "TokenD"}}
s.aliceMultiHopSwapFails(
types.ErrLimitPriceNotSatisfied,
types.ErrNoLiquidity,
route,
100,
math_utils.MustNewPrecDecFromStr("0.9"),
Expand Down
4 changes: 2 additions & 2 deletions x/dex/keeper/integration_placelimitorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (s *DexTestSuite) TestPlaceLimitOrderIoCNoLiq() {
s.fundAliceBalances(10, 0)
// GIVEN no liquidity
// Thenalice IoC limitOrder fails
s.assertAliceLimitSellFails(types.ErrLimitPriceNotSatisfied, "TokenA", 0, 10, types.LimitOrderType_IMMEDIATE_OR_CANCEL)
s.assertAliceLimitSellFails(types.ErrNoLiquidity, "TokenA", 0, 10, types.LimitOrderType_IMMEDIATE_OR_CANCEL)
}

func (s *DexTestSuite) TestPlaceLimitOrderIoCWithLPFills() {
Expand Down Expand Up @@ -571,7 +571,7 @@ func (s *DexTestSuite) TestPlaceLimitOrderIoCWithLPNoFill() {
// GIVEN LP of 5 tokenB at tick -1
s.bobDeposits(NewDeposit(0, 5, -1, 1))
// THEN alice IoC limitOrder for 10 tokenA below current 0To1 price fails
s.assertAliceLimitSellFails(types.ErrLimitPriceNotSatisfied, "TokenA", -1, 10, types.LimitOrderType_IMMEDIATE_OR_CANCEL)
s.assertAliceLimitSellFails(types.ErrNoLiquidity, "TokenA", -1, 10, types.LimitOrderType_IMMEDIATE_OR_CANCEL)
}

func (s *DexTestSuite) TestPlaceLimitOrderIoCTooSmallFails() {
Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (k Keeper) TakerLimitOrderSwap(
}

if totalInCoin.Amount.IsZero() {
return sdk.Coin{}, sdk.Coin{}, types.ErrLimitPriceNotSatisfied
return sdk.Coin{}, sdk.Coin{}, types.ErrNoLiquidity
}

truePrice := math_utils.NewPrecDecFromInt(totalOutCoin.Amount).QuoInt(totalInCoin.Amount)
Expand Down
2 changes: 1 addition & 1 deletion x/dex/keeper/multihop_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (k Keeper) SwapFullAmountIn(
return sdk.Coin{}, sdk.Coin{}, err
}
if !orderFilled {
return sdk.Coin{}, sdk.Coin{}, types.ErrLimitPriceNotSatisfied
return sdk.Coin{}, sdk.Coin{}, types.ErrNoLiquidity
}

dust = sdk.Coin.Sub(sdk.NewCoin(swapAmountTakerDenom.Denom, amountIn), swapAmountTakerDenom)
Expand Down
5 changes: 5 additions & 0 deletions x/dex/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,9 @@ var (
1163,
"Cannot convert price to int64 tick value",
)
ErrNoLiquidity = sdkerrors.Register(
ModuleName,
1164,
"No tradable liquidity below LimitSellPrice",
)
)

0 comments on commit 4563a15

Please sign in to comment.