From cdddb334c53da91105059801fe232b90206dd42f Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Mon, 6 Nov 2023 12:23:24 +0900 Subject: [PATCH] reverse dex price calculation --- x/move/ante/fee_test.go | 5 +++-- x/move/types/connector.go | 4 ++-- x/move/types/connector_test.go | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x/move/ante/fee_test.go b/x/move/ante/fee_test.go index e503b1e6..59d8d858 100644 --- a/x/move/ante/fee_test.go +++ b/x/move/ante/fee_test.go @@ -105,7 +105,8 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() { suite.Require().NoError(err) // Set high gas price so standard test fee fails - basePrice := sdk.NewDecCoinFromDec(baseDenom, sdk.NewDec(200).Quo(sdk.NewDec(100000))) + // gas price = 0.004 + basePrice := sdk.NewDecCoinFromDec(baseDenom, sdk.NewDecWithPrec(4, 3)) highGasPrice := []sdk.DecCoin{basePrice} suite.ctx = suite.ctx.WithMinGasPrices(highGasPrice) @@ -142,7 +143,7 @@ func (suite *AnteTestSuite) TestEnsureMempoolFees() { pools: dexPools, weights: dexWeights, baseDenom: baseDenom, - baseMinGasPrice: sdk.NewDec(200).Quo(sdk.NewDec(100000)), + baseMinGasPrice: sdk.NewDecWithPrec(4, 3), }) _, _, err = fc.CheckTxFeeWithMinGasPrices(suite.ctx, tx) diff --git a/x/move/types/connector.go b/x/move/types/connector.go index 2ef74016..91d8c377 100644 --- a/x/move/types/connector.go +++ b/x/move/types/connector.go @@ -409,8 +409,8 @@ func GetPoolSpotPrice( balanceBase, balanceQuote math.Int, weightBase, weightQuote sdk.Dec, ) sdk.Dec { - numerator := weightBase.MulInt(balanceQuote) - denominator := weightQuote.MulInt(balanceBase) + numerator := weightQuote.MulInt(balanceBase) + denominator := weightBase.MulInt(balanceQuote) return numerator.Quo(denominator) } diff --git a/x/move/types/connector_test.go b/x/move/types/connector_test.go index 8951e523..9ea0a739 100644 --- a/x/move/types/connector_test.go +++ b/x/move/types/connector_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "cosmossdk.io/math" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -30,12 +31,12 @@ func Test_GetDexWeight(t *testing.T) { func Test_GetPoolSpotPrice(t *testing.T) { price := types.GetPoolSpotPrice( sdk.NewInt(1_000_000), - sdk.NewInt(4_000_000), + sdk.NewInt(8_000_000), sdk.NewDecWithPrec(2, 1), sdk.NewDecWithPrec(8, 1), ) - require.Equal(t, sdk.OneDec(), price) + require.Equal(t, math.LegacyNewDecWithPrec(5, 1), price) } func Test_DeserializeUint128(t *testing.T) {