Skip to content

Commit

Permalink
[TRA-617] Fix calculation for atomic resolution (backport #2360) (#2433)
Browse files Browse the repository at this point in the history
Co-authored-by: shrenujb <[email protected]>
  • Loading branch information
mergify[bot] and shrenujb authored Oct 2, 2024
1 parent ea04085 commit b089c5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion protocol/x/listing/keeper/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions protocol/x/listing/keeper/listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b089c5d

Please sign in to comment.