From 782cb9437be91f9d9c912d52a8f9c0bc92f41eaf Mon Sep 17 00:00:00 2001 From: Brendan Chou <3680392+BrendanChou@users.noreply.github.com> Date: Tue, 28 May 2024 11:05:37 -0400 Subject: [PATCH] remove use of BigIntMulSignedPpm in favor of BigMulPpm --- protocol/lib/big_math.go | 11 ----------- protocol/x/clob/keeper/mev.go | 2 +- protocol/x/clob/keeper/process_single_match.go | 4 ++-- protocol/x/clob/types/pending_updates.go | 2 +- protocol/x/rewards/keeper/keeper.go | 2 +- 5 files changed, 5 insertions(+), 16 deletions(-) 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..9f8a4e6b2c 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, 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..d3201234aa 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, takerFeePpm, true) + bigMakerFeeQuoteQuantums := lib.BigMulPpm(bigFillQuoteQuantums, 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..d71015fc25 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, feePpm, true) totalFee.Add( totalFee, diff --git a/protocol/x/rewards/keeper/keeper.go b/protocol/x/rewards/keeper/keeper.go index 8d414f81ea..69fb522556 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, maxMakerRebatePpm, false) takerWeight := new(big.Int).Add( bigTakerFeeQuoteQuantums, makerRebateMulTakerVolume,