diff --git a/protocol/app/upgrades/v5.0.0/upgrade.go b/protocol/app/upgrades/v5.0.0/upgrade.go index b7442debce..5935fa19f2 100644 --- a/protocol/app/upgrades/v5.0.0/upgrade.go +++ b/protocol/app/upgrades/v5.0.0/upgrade.go @@ -36,7 +36,7 @@ func perpetualsUpgrade( subaccounts := subaccountsKeeper.GetAllSubaccount(ctx) for _, sa := range subaccounts { for _, perpPosition := range sa.PerpetualPositions { - if perpPosition.Quantums.BigInt().Sign() <= 0 { + if perpPosition.Quantums.Sign() <= 0 { // Only record positive positions for total open interest. // Total negative position size should be equal to total positive position size. continue diff --git a/protocol/dtypes/serializable_int.go b/protocol/dtypes/serializable_int.go index befbcd1ebd..c187f17b1f 100644 --- a/protocol/dtypes/serializable_int.go +++ b/protocol/dtypes/serializable_int.go @@ -57,7 +57,7 @@ func (i SerializableInt) String() string { if i.IsNil() { return "nil" } - return i.BigInt().String() + return i.i.String() } // Cmp compares x and y and returns: @@ -77,7 +77,15 @@ func (i SerializableInt) Cmp(j SerializableInt) int { if j.IsNil() { return 1 } - return i.BigInt().Cmp(j.BigInt()) + return i.i.Cmp(j.i) +} + +// Sign returns zero if nil, otherwise returns the sign of the Int. +func (i SerializableInt) Sign() int { + if i.IsNil() { + return 0 + } + return i.i.Sign() } // Marshal implements the gogo proto custom type interface. diff --git a/protocol/x/clob/types/equity_tier_limit_config.go b/protocol/x/clob/types/equity_tier_limit_config.go index 34e48c22b0..1b5cfad722 100644 --- a/protocol/x/clob/types/equity_tier_limit_config.go +++ b/protocol/x/clob/types/equity_tier_limit_config.go @@ -86,7 +86,7 @@ func (l EquityTierLimit) validate(field string, maxOrders uint32) error { l, ) } - if l.UsdTncRequired.IsNil() || l.UsdTncRequired.BigInt().Sign() < 0 { + if l.UsdTncRequired.IsNil() || l.UsdTncRequired.Sign() < 0 { return errorsmod.Wrapf( ErrInvalidEquityTierLimitConfig, "%d is not a valid UsdTncRequired for %s equity tier limit %+v", diff --git a/protocol/x/govplus/types/tx.go b/protocol/x/govplus/types/tx.go index 430bde6276..e760284a09 100644 --- a/protocol/x/govplus/types/tx.go +++ b/protocol/x/govplus/types/tx.go @@ -2,7 +2,6 @@ package types import ( "fmt" - "math/big" errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" @@ -33,7 +32,7 @@ func (msg *MsgSlashValidator) ValidateBasic() error { ) } - if msg.TokensAtInfractionHeight.BigInt().Cmp(big.NewInt(0)) != 1 { + if msg.TokensAtInfractionHeight.Sign() <= 0 { return ErrInvalidTokensAtInfractionHeight } diff --git a/protocol/x/perpetuals/simulation/genesis_test.go b/protocol/x/perpetuals/simulation/genesis_test.go index 2b21cd89a2..982ebf3618 100644 --- a/protocol/x/perpetuals/simulation/genesis_test.go +++ b/protocol/x/perpetuals/simulation/genesis_test.go @@ -69,7 +69,7 @@ func TestRandomizedGenState(t *testing.T) { require.True(t, perp.Params.DefaultFundingPpm > -int32(lib.OneMillion)) require.True(t, perp.Params.DefaultFundingPpm < int32(lib.OneMillion)) - require.True(t, perp.FundingIndex.BigInt().Sign() == 0) + require.True(t, perp.FundingIndex.Sign() == 0) } } } diff --git a/protocol/x/ratelimit/types/params.go b/protocol/x/ratelimit/types/params.go index 4d3917a96f..291f5b64b6 100644 --- a/protocol/x/ratelimit/types/params.go +++ b/protocol/x/ratelimit/types/params.go @@ -57,7 +57,7 @@ func (p *LimitParams) Validate() error { return ErrInvalidRateLimitPeriod } - if limiter.BaselineMinimum.BigInt().Sign() <= 0 { + if limiter.BaselineMinimum.Sign() <= 0 { return ErrInvalidBaselineMinimum } diff --git a/protocol/x/rewards/keeper/keeper.go b/protocol/x/rewards/keeper/keeper.go index affbadee77..e3b9d67938 100644 --- a/protocol/x/rewards/keeper/keeper.go +++ b/protocol/x/rewards/keeper/keeper.go @@ -211,7 +211,7 @@ func (k Keeper) SetRewardShare( ctx sdk.Context, rewardShare types.RewardShare, ) error { - if rewardShare.Weight.BigInt().Cmp(lib.BigInt0()) <= 0 { + if rewardShare.Weight.Sign() <= 0 { return errorsmod.Wrapf( types.ErrNonpositiveWeight, "Invalid weight %v", diff --git a/protocol/x/subaccounts/keeper/subaccount_helper.go b/protocol/x/subaccounts/keeper/subaccount_helper.go index 79b14fbc2e..799704184a 100644 --- a/protocol/x/subaccounts/keeper/subaccount_helper.go +++ b/protocol/x/subaccounts/keeper/subaccount_helper.go @@ -189,7 +189,7 @@ func UpdateAssetPositions( ap.Quantums = dtypes.NewIntFromBigInt(newQuantums) // Handle the case where the position is now closed. - if ap.Quantums.BigInt().Sign() == 0 { + if ap.Quantums.Sign() == 0 { delete(assetPositionsMap, au.AssetId) } } else { diff --git a/protocol/x/subaccounts/types/position_size.go b/protocol/x/subaccounts/types/position_size.go index ccdad8100c..39688ae2eb 100644 --- a/protocol/x/subaccounts/types/position_size.go +++ b/protocol/x/subaccounts/types/position_size.go @@ -56,7 +56,7 @@ func (m *AssetPosition) GetBigQuantums() *big.Int { return new(big.Int) } - if m.Quantums.BigInt().Sign() == 0 { + if m.Quantums.Sign() == 0 { panic(errorsmod.Wrapf( ErrAssetPositionZeroQuantum, "asset position (asset Id: %v) has zero quantum", @@ -92,7 +92,7 @@ func (m *PerpetualPosition) GetBigQuantums() *big.Int { return new(big.Int) } - if m.Quantums.BigInt().Sign() == 0 { + if m.Quantums.Sign() == 0 { panic(errorsmod.Wrapf( ErrPerpPositionZeroQuantum, "perpetual position (perpetual Id: %v) has zero quantum", diff --git a/protocol/x/vault/keeper/orders.go b/protocol/x/vault/keeper/orders.go index 5d8054dcc5..2e17fd9c13 100644 --- a/protocol/x/vault/keeper/orders.go +++ b/protocol/x/vault/keeper/orders.go @@ -32,7 +32,7 @@ func (k Keeper) RefreshAllVaultOrders(ctx sdk.Context) { k.cdc.MustUnmarshal(totalSharesIterator.Value(), &totalShares) // Skip if TotalShares is non-positive. - if totalShares.NumShares.BigInt().Sign() <= 0 { + if totalShares.NumShares.Sign() <= 0 { continue } diff --git a/protocol/x/vault/keeper/shares.go b/protocol/x/vault/keeper/shares.go index 10f2460a6f..c9c7b6ada0 100644 --- a/protocol/x/vault/keeper/shares.go +++ b/protocol/x/vault/keeper/shares.go @@ -33,7 +33,7 @@ func (k Keeper) SetTotalShares( vaultId types.VaultId, totalShares types.NumShares, ) error { - if totalShares.NumShares.BigInt().Sign() < 0 { + if totalShares.NumShares.Sign() < 0 { return types.ErrNegativeShares } @@ -81,7 +81,7 @@ func (k Keeper) SetOwnerShares( owner string, ownerShares types.NumShares, ) error { - if ownerShares.NumShares.BigInt().Sign() < 0 { + if ownerShares.NumShares.Sign() < 0 { return types.ErrNegativeShares } diff --git a/protocol/x/vault/keeper/vault.go b/protocol/x/vault/keeper/vault.go index 6bcd3ceb75..1143ca6c1c 100644 --- a/protocol/x/vault/keeper/vault.go +++ b/protocol/x/vault/keeper/vault.go @@ -59,7 +59,7 @@ func (k Keeper) DecommissionNonPositiveEquityVaults( k.cdc.MustUnmarshal(totalSharesIterator.Value(), &totalShares) // Skip if TotalShares is non-positive. - if totalShares.NumShares.BigInt().Sign() <= 0 { + if totalShares.NumShares.Sign() <= 0 { continue } diff --git a/protocol/x/vault/types/params.go b/protocol/x/vault/types/params.go index 8d4a762947..46291f2ff4 100644 --- a/protocol/x/vault/types/params.go +++ b/protocol/x/vault/types/params.go @@ -38,7 +38,7 @@ func (p Params) Validate() error { return ErrInvalidOrderExpirationSeconds } // Activation threshold quote quantums must be non-negative. - if p.ActivationThresholdQuoteQuantums.BigInt().Sign() < 0 { + if p.ActivationThresholdQuoteQuantums.Sign() < 0 { return ErrInvalidActivationThresholdQuoteQuantums }