Skip to content

Commit

Permalink
reverse dex price calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Nov 6, 2023
1 parent 0c4dd72 commit cdddb33
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions x/move/ante/fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions x/move/types/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions x/move/types/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"
"testing"

"cosmossdk.io/math"
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -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) {
Expand Down

0 comments on commit cdddb33

Please sign in to comment.