Skip to content

Commit

Permalink
(fix) Addressed comments in PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
abel committed Jan 16, 2024
1 parent 76b3f74 commit 091877c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
5 changes: 5 additions & 0 deletions client/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/x509"
"encoding/hex"
"fmt"
"github.com/shopspring/decimal"
"os"
"strings"

Expand Down Expand Up @@ -56,3 +57,7 @@ func MsgResponse(data []byte) []*chaintypes.TxResponseGenericMessage {
}
return response.Messages
}

func RemoveExtraDecimals(value decimal.Decimal, decimalsToRemove int32) decimal.Decimal {
return value.Div(decimal.New(1, decimalsToRemove))

Check warning on line 62 in client/common/util.go

View check run for this annotation

Codecov / codecov/patch

client/common/util.go#L61-L62

Added lines #L61 - L62 were not covered by tests
}
19 changes: 6 additions & 13 deletions client/core/market.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core

import (
"github.com/InjectiveLabs/sdk-go/client/common"
cosmtypes "github.com/cosmos/cosmos-sdk/types"
"github.com/shopspring/decimal"
)
Expand Down Expand Up @@ -47,15 +48,11 @@ func (spotMarket SpotMarket) PriceFromChainFormat(chainValue cosmtypes.Dec) deci
}

func (spotMarket SpotMarket) QuantityFromExtendedChainFormat(chainValue cosmtypes.Dec) decimal.Decimal {
return spotMarket.fromExtendedChainformat(spotMarket.QuantityFromChainFormat(chainValue))
return common.RemoveExtraDecimals(spotMarket.QuantityFromChainFormat(chainValue), AdditionalChainFormatDecimals)
}

func (spotMarket SpotMarket) PriceFromExtendedChainFormat(chainValue cosmtypes.Dec) decimal.Decimal {
return spotMarket.fromExtendedChainformat(spotMarket.PriceFromChainFormat(chainValue))
}

func (spotMarket SpotMarket) fromExtendedChainformat(chainValue decimal.Decimal) decimal.Decimal {
return chainValue.Div(decimal.New(1, AdditionalChainFormatDecimals))
return common.RemoveExtraDecimals(spotMarket.PriceFromChainFormat(chainValue), AdditionalChainFormatDecimals)
}

type DerivativeMarket struct {
Expand Down Expand Up @@ -130,17 +127,13 @@ func (derivativeMarket DerivativeMarket) MarginFromChainFormat(chainValue cosmty
}

func (derivativeMarket DerivativeMarket) QuantityFromExtendedChainFormat(chainValue cosmtypes.Dec) decimal.Decimal {
return derivativeMarket.fromExtendedChainformat(derivativeMarket.QuantityFromChainFormat(chainValue))
return common.RemoveExtraDecimals(derivativeMarket.QuantityFromChainFormat(chainValue), AdditionalChainFormatDecimals)
}

func (derivativeMarket DerivativeMarket) PriceFromExtendedChainFormat(chainValue cosmtypes.Dec) decimal.Decimal {
return derivativeMarket.fromExtendedChainformat(derivativeMarket.PriceFromChainFormat(chainValue))
return common.RemoveExtraDecimals(derivativeMarket.PriceFromChainFormat(chainValue), AdditionalChainFormatDecimals)
}

func (derivativeMarket DerivativeMarket) MarginFromExtendedChainFormat(chainValue cosmtypes.Dec) decimal.Decimal {
return derivativeMarket.fromExtendedChainformat(derivativeMarket.MarginFromChainFormat(chainValue))
}

func (derivativeMarket DerivativeMarket) fromExtendedChainformat(chainValue decimal.Decimal) decimal.Decimal {
return chainValue.Div(decimal.New(1, AdditionalChainFormatDecimals))
return common.RemoveExtraDecimals(derivativeMarket.MarginFromChainFormat(chainValue), AdditionalChainFormatDecimals)
}

0 comments on commit 091877c

Please sign in to comment.