Skip to content

Commit

Permalink
remove use of BigIntMulSignedPpm in favor of BigMulPpm
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanChou committed May 28, 2024
1 parent 6f6ec38 commit 782cb94
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 16 deletions.
11 changes: 0 additions & 11 deletions protocol/lib/big_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion protocol/x/clob/keeper/mev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions protocol/x/clob/keeper/process_single_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion protocol/x/clob/types/pending_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion protocol/x/rewards/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 782cb94

Please sign in to comment.