Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TRA-617] Fix calculation for atomic resolution #2360

Merged
merged 18 commits into from
Sep 26, 2024
Merged
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))
shrenujb marked this conversation as resolved.
Show resolved Hide resolved

// 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
Loading