diff --git a/protocol/x/listing/keeper/listing.go b/protocol/x/listing/keeper/listing.go index 3141933630..82d190620d 100644 --- a/protocol/x/listing/keeper/listing.go +++ b/protocol/x/listing/keeper/listing.go @@ -148,7 +148,10 @@ func (k Keeper) CreatePerpetual( } // calculate atomic resolution from reference price - atomicResolution := types.ResolutionOffset - int32(math.Floor(math.Log10(float64(metadata.ReferencePrice)))) + // atomic resolution = -6 - (log10(referencePrice) - decimals) + atomicResolution := types.ResolutionOffset - + (int32(math.Floor(math.Log10(float64(metadata.ReferencePrice)))) - + int32(marketMapDetails.Ticker.Decimals)) // Create a new perpetual perpetual, err := k.PerpetualsKeeper.CreatePerpetual( diff --git a/protocol/x/listing/keeper/listing_test.go b/protocol/x/listing/keeper/listing_test.go index 4678a1bc7e..052172c0f0 100644 --- a/protocol/x/listing/keeper/listing_test.go +++ b/protocol/x/listing/keeper/listing_test.go @@ -152,7 +152,7 @@ func TestCreatePerpetual(t *testing.T) { market := marketmaptypes.Market{ Ticker: marketmaptypes.Ticker{ CurrencyPair: oracletypes.CurrencyPair{Base: "TEST", Quote: "USD"}, - Decimals: 6, + Decimals: 10, MinProviderCount: 2, Enabled: false, Metadata_JSON: string(dydxMetadata), @@ -185,8 +185,8 @@ func TestCreatePerpetual(t *testing.T) { require.Equal(t, uint32(10), perpetual.GetId()) require.Equal(t, marketId, perpetual.Params.MarketId) require.Equal(t, tc.ticker, perpetual.Params.Ticker) - // Expected resolution = -6 - Floor(log10(1000000000)) = -15 - require.Equal(t, int32(-15), perpetual.Params.AtomicResolution) + // Expected resolution = -6 - (Floor(log10(1000000000))-10) = -5 + require.Equal(t, int32(-5), perpetual.Params.AtomicResolution) require.Equal(t, int32(types.DefaultFundingPpm), perpetual.Params.DefaultFundingPpm) require.Equal(t, uint32(types.LiquidityTier_Isolated), perpetual.Params.LiquidityTier) require.Equal(