Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of BigIntMulSignedPpm in favor of BigMulPpm #1589

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading