diff --git a/protocol/lib/big_math.go b/protocol/lib/big_math.go index 35ee84f6cf..d9befbcf1d 100644 --- a/protocol/lib/big_math.go +++ b/protocol/lib/big_math.go @@ -74,17 +74,6 @@ func BigIntMulPpm(input *big.Int, ppm uint32) *big.Int { return result.Div(result, big.NewInt(int64(OneMillion))) } -// BigIntMulSignedPpm takes a `big.Int` and returns the result of `input * ppm / 1_000_000`. -func BigIntMulSignedPpm(input *big.Int, ppm int32, roundUp bool) *big.Int { - result := new(big.Rat) - result.Mul( - new(big.Rat).SetInt(input), - new(big.Rat).SetInt64(int64(ppm)), - ) - result.Quo(result, BigRatOneMillion()) - return BigRatRound(result, roundUp) -} - // BigMin takes two `big.Int` as parameters and returns the smaller one. func BigMin(a, b *big.Int) *big.Int { result := new(big.Int) diff --git a/protocol/x/clob/keeper/mev.go b/protocol/x/clob/keeper/mev.go index d9987425c5..4f6c592209 100644 --- a/protocol/x/clob/keeper/mev.go +++ b/protocol/x/clob/keeper/mev.go @@ -874,7 +874,7 @@ func (c *CumulativePnL) AddPnLForTradeWithFilledQuoteQuantums( } // Calculate fees. - bigFeeQuoteQuantums := lib.BigIntMulSignedPpm(filledQuoteQuantums, feePpm, true) + bigFeeQuoteQuantums := lib.BigMulPpm(filledQuoteQuantums, lib.BigI(feePpm), true) pnl.Sub(pnl, bigFeeQuoteQuantums) c.AddDeltaToSubaccount(subaccountId, pnl) diff --git a/protocol/x/clob/keeper/process_single_match.go b/protocol/x/clob/keeper/process_single_match.go index 7410bdd140..67b0cfddad 100644 --- a/protocol/x/clob/keeper/process_single_match.go +++ b/protocol/x/clob/keeper/process_single_match.go @@ -317,8 +317,8 @@ func (k Keeper) persistMatchedOrders( isTakerLiquidation := matchWithOrders.TakerOrder.IsLiquidation() // Taker fees and maker fees/rebates are rounded towards positive infinity. - bigTakerFeeQuoteQuantums := lib.BigIntMulSignedPpm(bigFillQuoteQuantums, takerFeePpm, true) - bigMakerFeeQuoteQuantums := lib.BigIntMulSignedPpm(bigFillQuoteQuantums, makerFeePpm, true) + bigTakerFeeQuoteQuantums := lib.BigMulPpm(bigFillQuoteQuantums, lib.BigI(takerFeePpm), true) + bigMakerFeeQuoteQuantums := lib.BigMulPpm(bigFillQuoteQuantums, lib.BigI(makerFeePpm), true) matchWithOrders.MakerFee = bigMakerFeeQuoteQuantums.Int64() // Liquidation orders pay the liquidation fee instead of the standard taker fee diff --git a/protocol/x/clob/types/pending_updates.go b/protocol/x/clob/types/pending_updates.go index 1838df709c..027d79056a 100644 --- a/protocol/x/clob/types/pending_updates.go +++ b/protocol/x/clob/types/pending_updates.go @@ -169,7 +169,7 @@ func (p *PendingUpdates) AddPerpetualFill( totalFee = big.NewInt(0) } - bigFeeQuoteQuantums := lib.BigIntMulSignedPpm(bigFillQuoteQuantums, feePpm, true) + bigFeeQuoteQuantums := lib.BigMulPpm(bigFillQuoteQuantums, lib.BigI(feePpm), true) totalFee.Add( totalFee, diff --git a/protocol/x/rewards/keeper/keeper.go b/protocol/x/rewards/keeper/keeper.go index 8d414f81ea..1fad0000ea 100644 --- a/protocol/x/rewards/keeper/keeper.go +++ b/protocol/x/rewards/keeper/keeper.go @@ -136,7 +136,7 @@ func (k Keeper) AddRewardSharesForFill( lowestMakerFee := k.feeTiersKeeper.GetLowestMakerFee(ctx) maxMakerRebatePpm := lib.Min(int32(0), lowestMakerFee) // Calculate quote_quantums * max_maker_rebate. Result is non-positive. - makerRebateMulTakerVolume := lib.BigIntMulSignedPpm(bigFillQuoteQuantums, maxMakerRebatePpm, false) + makerRebateMulTakerVolume := lib.BigMulPpm(bigFillQuoteQuantums, lib.BigI(maxMakerRebatePpm), false) takerWeight := new(big.Int).Add( bigTakerFeeQuoteQuantums, makerRebateMulTakerVolume,