From b0b9c52c9beab9c72dd3843101e5e3b4cd0b8d01 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:07:51 -0700 Subject: [PATCH 01/14] feat!: make quote trade limit ratio check in either direction --- x/vpool/keeper/keeper.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index effb52f91..ce521f879 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -176,8 +176,10 @@ func (k Keeper) SwapQuoteForBase( return sdk.Dec{}, err } - if dir == types.Direction_REMOVE_FROM_POOL && !pool.HasEnoughQuoteReserve(quoteAssetAmount) { - return sdk.Dec{}, types.ErrOverTradingLimit + // check trade limit ratio on quote in either direction + if !pool.HasEnoughQuoteReserve(quoteAssetAmount) { + return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( + "quote amount %s is over trading limit", quoteAssetAmount) } baseAssetAmount, err = pool.GetBaseAmountByQuoteAmount(dir, quoteAssetAmount) From 46b1eedb2842cbe9138825ec6fcf9553c16eee4e Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:08:06 -0700 Subject: [PATCH 02/14] feat!: add base trade limit check --- x/vpool/keeper/keeper.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index ce521f879..66f266600 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -187,6 +187,11 @@ func (k Keeper) SwapQuoteForBase( return sdk.Dec{}, err } + if dir == types.Direction_ADD_TO_POOL && !pool.HasEnoughBaseReserve(baseAssetAmount) { + return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( + "quote amount %s is over trading limit", quoteAssetAmount) + } + // check if base asset limit is violated if !baseAmountLimit.IsZero() { // if going long and the base amount retrieved from the pool is less than the limit From fbcb6c7a3429a2b007f9a402da42d583c1d1fed7 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:12:40 -0700 Subject: [PATCH 03/14] fix: check base trading limit ratio in both directions --- x/vpool/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index 66f266600..7a4f26f90 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -187,7 +187,7 @@ func (k Keeper) SwapQuoteForBase( return sdk.Dec{}, err } - if dir == types.Direction_ADD_TO_POOL && !pool.HasEnoughBaseReserve(baseAssetAmount) { + if !pool.HasEnoughBaseReserve(baseAssetAmount) { return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( "quote amount %s is over trading limit", quoteAssetAmount) } From b714a70d50a82b6c66f015c0c285862ae6a2503e Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:12:52 -0700 Subject: [PATCH 04/14] test: trading limit ratio --- x/vpool/keeper/keeper_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index e67a26c0e..9de5aa7ab 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -124,6 +124,26 @@ func TestSwapQuoteForBase(t *testing.T) { expectedErr: types.ErrOverFluctuationLimit, }, + { + name: "over trading limit when removing quote", + pair: common.PairBTCStable, + direction: types.Direction_REMOVE_FROM_POOL, + quoteAmount: sdk.NewDec(9_000_001), + baseLimit: sdk.ZeroDec(), + skipFluctuationLimitCheck: false, + + expectedErr: types.ErrOverTradingLimit, + }, + { + name: "over trading limit when adding quote", + pair: common.PairBTCStable, + direction: types.Direction_ADD_TO_POOL, + quoteAmount: sdk.NewDec(9_000_001), + baseLimit: sdk.ZeroDec(), + skipFluctuationLimitCheck: false, + + expectedErr: types.ErrOverTradingLimit, + }, { name: "over fluctuation limit allowed on add", pair: common.PairBTCStable, From e4ffe2da8851e105f6ff0399e819bb65e47d0c87 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:15:09 -0700 Subject: [PATCH 05/14] docs: clarify why base trading limit would never run --- x/vpool/keeper/keeper.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index 7a4f26f90..200780e1a 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -188,6 +188,12 @@ func (k Keeper) SwapQuoteForBase( } if !pool.HasEnoughBaseReserve(baseAssetAmount) { + // in reality, this if statement should never run because a perturbation in base reserve assets + // greater than trading limit ratio would have happened when checking for a perturbation in + // quote assets, due to x*y=k + // + // e.g. a 10% change in base asset reserves would have triggered a >10% change in + // quote asset reserves return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( "quote amount %s is over trading limit", quoteAssetAmount) } From 2708bdba52c46b0d7d1e4706347cffcfe5d8f8ce Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:15:37 -0700 Subject: [PATCH 06/14] feat!: trading limit ratio check in both directions --- x/vpool/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index 200780e1a..f71a84561 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -75,7 +75,7 @@ func (k Keeper) SwapBaseForQuote( return sdk.Dec{}, err } - if dir == types.Direction_REMOVE_FROM_POOL && !pool.HasEnoughBaseReserve(baseAssetAmount) { + if !pool.HasEnoughBaseReserve(baseAssetAmount) { return sdk.Dec{}, types.ErrOverTradingLimit } From d6ab428ae166c6701976bf393f8a8e87aebacc46 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:16:28 -0700 Subject: [PATCH 07/14] feat!: add quote trade limit check --- x/vpool/keeper/keeper.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index f71a84561..fed8e4ec4 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -84,6 +84,17 @@ func (k Keeper) SwapBaseForQuote( return sdk.Dec{}, err } + if !pool.HasEnoughQuoteReserve(quoteAssetAmount) { + // in reality, this if statement should never run because a perturbation in quote reserve assets + // greater than trading limit ratio would have happened when checking for a perturbation in + // base assets, due to x*y=k + // + // e.g. a 10% change in quote asset reserves would have triggered a >10% change in + // base asset reserves + return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( + "quote amount %s is over trading limit", quoteAssetAmount) + } + if !quoteAmountLimit.IsZero() { // if going long and the base amount retrieved from the pool is less than the limit if dir == types.Direction_ADD_TO_POOL && quoteAssetAmount.LT(quoteAmountLimit) { From 772792e7e0882bd36691a6aa164fa2e1cf1f5e8b Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:16:43 -0700 Subject: [PATCH 08/14] fix: error message --- x/vpool/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index fed8e4ec4..4ee05684c 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -206,7 +206,7 @@ func (k Keeper) SwapQuoteForBase( // e.g. a 10% change in base asset reserves would have triggered a >10% change in // quote asset reserves return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( - "quote amount %s is over trading limit", quoteAssetAmount) + "base amount %s is over trading limit", baseAssetAmount) } // check if base asset limit is violated From 5753ea0e0e5b343f806739a54ee56429c88e4a74 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:17:05 -0700 Subject: [PATCH 09/14] refactor: baseAssetAmount -> baseAmt --- x/vpool/keeper/keeper.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index 4ee05684c..26858a7e3 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -169,7 +169,7 @@ func (k Keeper) SwapQuoteForBase( quoteAssetAmount sdk.Dec, baseAmountLimit sdk.Dec, skipFluctuationLimitCheck bool, -) (baseAssetAmount sdk.Dec, err error) { +) (baseAmt sdk.Dec, err error) { if !k.ExistsPool(ctx, pair) { return sdk.Dec{}, types.ErrPairNotSupported } @@ -193,12 +193,12 @@ func (k Keeper) SwapQuoteForBase( "quote amount %s is over trading limit", quoteAssetAmount) } - baseAssetAmount, err = pool.GetBaseAmountByQuoteAmount(dir, quoteAssetAmount) + baseAmt, err = pool.GetBaseAmountByQuoteAmount(dir, quoteAssetAmount) if err != nil { return sdk.Dec{}, err } - if !pool.HasEnoughBaseReserve(baseAssetAmount) { + if !pool.HasEnoughBaseReserve(baseAmt) { // in reality, this if statement should never run because a perturbation in base reserve assets // greater than trading limit ratio would have happened when checking for a perturbation in // quote assets, due to x*y=k @@ -206,33 +206,33 @@ func (k Keeper) SwapQuoteForBase( // e.g. a 10% change in base asset reserves would have triggered a >10% change in // quote asset reserves return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( - "base amount %s is over trading limit", baseAssetAmount) + "base amount %s is over trading limit", baseAmt) } // check if base asset limit is violated if !baseAmountLimit.IsZero() { // if going long and the base amount retrieved from the pool is less than the limit - if dir == types.Direction_ADD_TO_POOL && baseAssetAmount.LT(baseAmountLimit) { + if dir == types.Direction_ADD_TO_POOL && baseAmt.LT(baseAmountLimit) { return sdk.Dec{}, types.ErrAssetFailsUserLimit.Wrapf( "base amount (%s) is less than selected limit (%s)", - baseAssetAmount.String(), + baseAmt.String(), baseAmountLimit.String(), ) // if going short and the base amount retrieved from the pool is greater than the limit - } else if dir == types.Direction_REMOVE_FROM_POOL && baseAssetAmount.GT(baseAmountLimit) { + } else if dir == types.Direction_REMOVE_FROM_POOL && baseAmt.GT(baseAmountLimit) { return sdk.Dec{}, types.ErrAssetFailsUserLimit.Wrapf( "base amount (%s) is greater than selected limit (%s)", - baseAssetAmount.String(), + baseAmt.String(), baseAmountLimit.String(), ) } } if dir == types.Direction_ADD_TO_POOL { - pool.DecreaseBaseAssetReserve(baseAssetAmount) + pool.DecreaseBaseAssetReserve(baseAmt) pool.IncreaseQuoteAssetReserve(quoteAssetAmount) } else if dir == types.Direction_REMOVE_FROM_POOL { - pool.IncreaseBaseAssetReserve(baseAssetAmount) + pool.IncreaseBaseAssetReserve(baseAmt) pool.DecreaseQuoteAssetReserve(quoteAssetAmount) } @@ -252,10 +252,10 @@ func (k Keeper) SwapQuoteForBase( return sdk.Dec{}, err } - return baseAssetAmount, ctx.EventManager().EmitTypedEvent(&types.SwapQuoteForBaseEvent{ + return baseAmt, ctx.EventManager().EmitTypedEvent(&types.SwapQuoteForBaseEvent{ Pair: pair.String(), QuoteAmount: quoteAssetAmount, - BaseAmount: baseAssetAmount, + BaseAmount: baseAmt, }) } From b02f049fdcc49cc7bb8d36bbe860fa9635069bfa Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:17:19 -0700 Subject: [PATCH 10/14] refactor: quoteAssetAmount -> quoteAmt --- x/vpool/keeper/keeper.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index 26858a7e3..b34bffb41 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -166,7 +166,7 @@ func (k Keeper) SwapQuoteForBase( ctx sdk.Context, pair common.AssetPair, dir types.Direction, - quoteAssetAmount sdk.Dec, + quoteAmt sdk.Dec, baseAmountLimit sdk.Dec, skipFluctuationLimitCheck bool, ) (baseAmt sdk.Dec, err error) { @@ -178,7 +178,7 @@ func (k Keeper) SwapQuoteForBase( return sdk.Dec{}, types.ErrNoValidPrice.Wrapf("%s", pair.String()) } - if quoteAssetAmount.IsZero() { + if quoteAmt.IsZero() { return sdk.ZeroDec(), nil } @@ -188,12 +188,12 @@ func (k Keeper) SwapQuoteForBase( } // check trade limit ratio on quote in either direction - if !pool.HasEnoughQuoteReserve(quoteAssetAmount) { + if !pool.HasEnoughQuoteReserve(quoteAmt) { return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( - "quote amount %s is over trading limit", quoteAssetAmount) + "quote amount %s is over trading limit", quoteAmt) } - baseAmt, err = pool.GetBaseAmountByQuoteAmount(dir, quoteAssetAmount) + baseAmt, err = pool.GetBaseAmountByQuoteAmount(dir, quoteAmt) if err != nil { return sdk.Dec{}, err } @@ -230,10 +230,10 @@ func (k Keeper) SwapQuoteForBase( if dir == types.Direction_ADD_TO_POOL { pool.DecreaseBaseAssetReserve(baseAmt) - pool.IncreaseQuoteAssetReserve(quoteAssetAmount) + pool.IncreaseQuoteAssetReserve(quoteAmt) } else if dir == types.Direction_REMOVE_FROM_POOL { pool.IncreaseBaseAssetReserve(baseAmt) - pool.DecreaseQuoteAssetReserve(quoteAssetAmount) + pool.DecreaseQuoteAssetReserve(quoteAmt) } if err = k.updatePool(ctx, pool, skipFluctuationLimitCheck); err != nil { @@ -254,7 +254,7 @@ func (k Keeper) SwapQuoteForBase( return baseAmt, ctx.EventManager().EmitTypedEvent(&types.SwapQuoteForBaseEvent{ Pair: pair.String(), - QuoteAmount: quoteAssetAmount, + QuoteAmount: quoteAmt, BaseAmount: baseAmt, }) } From 1fa9cb9906e903862d78a8db3c77e4bf903df0e7 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:18:47 -0700 Subject: [PATCH 11/14] refactor: shorten variable names --- x/vpool/keeper/keeper.go | 57 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/x/vpool/keeper/keeper.go b/x/vpool/keeper/keeper.go index b34bffb41..2200d6cb0 100644 --- a/x/vpool/keeper/keeper.go +++ b/x/vpool/keeper/keeper.go @@ -54,10 +54,10 @@ func (k Keeper) SwapBaseForQuote( ctx sdk.Context, pair common.AssetPair, dir types.Direction, - baseAssetAmount sdk.Dec, - quoteAmountLimit sdk.Dec, + baseAmt sdk.Dec, + quoteLimit sdk.Dec, skipFluctuationLimitCheck bool, -) (quoteAssetAmount sdk.Dec, err error) { +) (quoteAmt sdk.Dec, err error) { if !k.ExistsPool(ctx, pair) { return sdk.Dec{}, types.ErrPairNotSupported } @@ -66,7 +66,7 @@ func (k Keeper) SwapBaseForQuote( return sdk.Dec{}, types.ErrNoValidPrice.Wrapf("%s", pair.String()) } - if baseAssetAmount.IsZero() { + if baseAmt.IsZero() { return sdk.ZeroDec(), nil } @@ -75,16 +75,16 @@ func (k Keeper) SwapBaseForQuote( return sdk.Dec{}, err } - if !pool.HasEnoughBaseReserve(baseAssetAmount) { + if !pool.HasEnoughBaseReserve(baseAmt) { return sdk.Dec{}, types.ErrOverTradingLimit } - quoteAssetAmount, err = pool.GetQuoteAmountByBaseAmount(dir, baseAssetAmount) + quoteAmt, err = pool.GetQuoteAmountByBaseAmount(dir, baseAmt) if err != nil { return sdk.Dec{}, err } - if !pool.HasEnoughQuoteReserve(quoteAssetAmount) { + if !pool.HasEnoughQuoteReserve(quoteAmt) { // in reality, this if statement should never run because a perturbation in quote reserve assets // greater than trading limit ratio would have happened when checking for a perturbation in // base assets, due to x*y=k @@ -92,33 +92,33 @@ func (k Keeper) SwapBaseForQuote( // e.g. a 10% change in quote asset reserves would have triggered a >10% change in // base asset reserves return sdk.Dec{}, types.ErrOverTradingLimit.Wrapf( - "quote amount %s is over trading limit", quoteAssetAmount) + "quote amount %s is over trading limit", quoteAmt) } - if !quoteAmountLimit.IsZero() { + if !quoteLimit.IsZero() { // if going long and the base amount retrieved from the pool is less than the limit - if dir == types.Direction_ADD_TO_POOL && quoteAssetAmount.LT(quoteAmountLimit) { + if dir == types.Direction_ADD_TO_POOL && quoteAmt.LT(quoteLimit) { return sdk.Dec{}, types.ErrAssetFailsUserLimit.Wrapf( "quote amount (%s) is less than selected limit (%s)", - quoteAssetAmount.String(), - quoteAmountLimit.String(), + quoteAmt.String(), + quoteLimit.String(), ) // if going short and the base amount retrieved from the pool is greater than the limit - } else if dir == types.Direction_REMOVE_FROM_POOL && quoteAssetAmount.GT(quoteAmountLimit) { + } else if dir == types.Direction_REMOVE_FROM_POOL && quoteAmt.GT(quoteLimit) { return sdk.Dec{}, types.ErrAssetFailsUserLimit.Wrapf( "quote amount (%s) is greater than selected limit (%s)", - quoteAssetAmount.String(), - quoteAmountLimit.String(), + quoteAmt.String(), + quoteLimit.String(), ) } } if dir == types.Direction_ADD_TO_POOL { - pool.IncreaseBaseAssetReserve(baseAssetAmount) - pool.DecreaseQuoteAssetReserve(quoteAssetAmount) + pool.IncreaseBaseAssetReserve(baseAmt) + pool.DecreaseQuoteAssetReserve(quoteAmt) } else if dir == types.Direction_REMOVE_FROM_POOL { - pool.DecreaseBaseAssetReserve(baseAssetAmount) - pool.IncreaseQuoteAssetReserve(quoteAssetAmount) + pool.DecreaseBaseAssetReserve(baseAmt) + pool.IncreaseQuoteAssetReserve(quoteAmt) } if err = k.updatePool(ctx, pool, skipFluctuationLimitCheck); err != nil { @@ -138,10 +138,10 @@ func (k Keeper) SwapBaseForQuote( return sdk.Dec{}, err } - return quoteAssetAmount, ctx.EventManager().EmitTypedEvent(&types.SwapBaseForQuoteEvent{ + return quoteAmt, ctx.EventManager().EmitTypedEvent(&types.SwapBaseForQuoteEvent{ Pair: pair.String(), - QuoteAmount: quoteAssetAmount, - BaseAmount: baseAssetAmount, + QuoteAmount: quoteAmt, + BaseAmount: baseAmt, }) } @@ -167,7 +167,7 @@ func (k Keeper) SwapQuoteForBase( pair common.AssetPair, dir types.Direction, quoteAmt sdk.Dec, - baseAmountLimit sdk.Dec, + baseLimit sdk.Dec, skipFluctuationLimitCheck bool, ) (baseAmt sdk.Dec, err error) { if !k.ExistsPool(ctx, pair) { @@ -210,20 +210,20 @@ func (k Keeper) SwapQuoteForBase( } // check if base asset limit is violated - if !baseAmountLimit.IsZero() { + if !baseLimit.IsZero() { // if going long and the base amount retrieved from the pool is less than the limit - if dir == types.Direction_ADD_TO_POOL && baseAmt.LT(baseAmountLimit) { + if dir == types.Direction_ADD_TO_POOL && baseAmt.LT(baseLimit) { return sdk.Dec{}, types.ErrAssetFailsUserLimit.Wrapf( "base amount (%s) is less than selected limit (%s)", baseAmt.String(), - baseAmountLimit.String(), + baseLimit.String(), ) // if going short and the base amount retrieved from the pool is greater than the limit - } else if dir == types.Direction_REMOVE_FROM_POOL && baseAmt.GT(baseAmountLimit) { + } else if dir == types.Direction_REMOVE_FROM_POOL && baseAmt.GT(baseLimit) { return sdk.Dec{}, types.ErrAssetFailsUserLimit.Wrapf( "base amount (%s) is greater than selected limit (%s)", baseAmt.String(), - baseAmountLimit.String(), + baseLimit.String(), ) } } @@ -244,6 +244,7 @@ func (k Keeper) SwapQuoteForBase( if err != nil { return sdk.Dec{}, err } + if err := ctx.EventManager().EmitTypedEvent(&types.MarkPriceChanged{ Pair: pair.String(), Price: spotPrice, From bee0783c79d21ac4fe8154082c80c323db3350b6 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:20:39 -0700 Subject: [PATCH 12/14] Update CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eff52ad4..271c19081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,7 +39,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -[Unreleased] +## Unreleased + +### API Breaking + +* [#858](https://github.com/NibiruChain/nibiru/pull/858) - fix trading limit ratio check; checks in both directions on both quote and base assets ## v0.14.0 From 63a0030a4c64654c6cd24096f8aa5332ddb986c2 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:23:28 -0700 Subject: [PATCH 13/14] test: trading limit ratio check --- x/vpool/keeper/keeper_test.go | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index 9de5aa7ab..da930666c 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -95,11 +95,21 @@ func TestSwapQuoteForBase(t *testing.T) { expectedErr: types.ErrAssetFailsUserLimit, }, { - name: "quote input bigger than trade limit ratio", + name: "over trading limit when removing quote", pair: common.PairBTCStable, direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(10_000_000), - baseLimit: sdk.NewDec(10), + quoteAmount: sdk.NewDec(9_000_001), + baseLimit: sdk.ZeroDec(), + skipFluctuationLimitCheck: false, + + expectedErr: types.ErrOverTradingLimit, + }, + { + name: "over trading limit when adding quote", + pair: common.PairBTCStable, + direction: types.Direction_ADD_TO_POOL, + quoteAmount: sdk.NewDec(9_000_001), + baseLimit: sdk.ZeroDec(), skipFluctuationLimitCheck: false, expectedErr: types.ErrOverTradingLimit, @@ -124,26 +134,6 @@ func TestSwapQuoteForBase(t *testing.T) { expectedErr: types.ErrOverFluctuationLimit, }, - { - name: "over trading limit when removing quote", - pair: common.PairBTCStable, - direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(9_000_001), - baseLimit: sdk.ZeroDec(), - skipFluctuationLimitCheck: false, - - expectedErr: types.ErrOverTradingLimit, - }, - { - name: "over trading limit when adding quote", - pair: common.PairBTCStable, - direction: types.Direction_ADD_TO_POOL, - quoteAmount: sdk.NewDec(9_000_001), - baseLimit: sdk.ZeroDec(), - skipFluctuationLimitCheck: false, - - expectedErr: types.ErrOverTradingLimit, - }, { name: "over fluctuation limit allowed on add", pair: common.PairBTCStable, @@ -302,11 +292,21 @@ func TestSwapBaseForQuote(t *testing.T) { expectedErr: types.ErrAssetFailsUserLimit, }, { - name: "base input bigger than trade limit ratio", + name: "over trading limit when removing base", pair: common.PairBTCStable, direction: types.Direction_REMOVE_FROM_POOL, baseAmt: sdk.NewDec(4_500_001), - quoteLimit: sdk.NewDec(10), + quoteLimit: sdk.ZeroDec(), + skipFluctuationLimitCheck: false, + + expectedErr: types.ErrOverTradingLimit, + }, + { + name: "over trading limit when adding base", + pair: common.PairBTCStable, + direction: types.Direction_ADD_TO_POOL, + baseAmt: sdk.NewDec(4_500_001), + quoteLimit: sdk.ZeroDec(), skipFluctuationLimitCheck: false, expectedErr: types.ErrOverTradingLimit, From 1b620b7f0c0705802d1d7ffb70e259db107d5e36 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Thu, 25 Aug 2022 07:38:28 -0700 Subject: [PATCH 14/14] Update triggers for PR Lint --- .github/workflows/pr-title-lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-title-lint.yml b/.github/workflows/pr-title-lint.yml index 1475acf39..9cb426f2b 100644 --- a/.github/workflows/pr-title-lint.yml +++ b/.github/workflows/pr-title-lint.yml @@ -2,6 +2,7 @@ name: PR lint on: pull_request: + types: [opened, reopened, synchronize, edited] jobs: pr-lint: