From ddd0ac58e77eb5661f474df9f144392ddc58c2de Mon Sep 17 00:00:00 2001 From: Brendan Chou <3680392+BrendanChou@users.noreply.github.com> Date: Wed, 22 May 2024 15:04:46 -0400 Subject: [PATCH] Remove use of `big.Rat` from x/vest (#1565) --- protocol/x/vest/keeper/keeper.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/protocol/x/vest/keeper/keeper.go b/protocol/x/vest/keeper/keeper.go index 20fdf0716c..dc7d6aeeeb 100644 --- a/protocol/x/vest/keeper/keeper.go +++ b/protocol/x/vest/keeper/keeper.go @@ -2,7 +2,6 @@ package keeper import ( "fmt" - "math/big" "time" errorsmod "cosmossdk.io/errors" @@ -93,19 +92,18 @@ func (k Keeper) ProcessVesting(ctx sdk.Context) { // Given `block_time > prev_block_time` and `block_time > start_time` ===> `block_time > last_vest_time` // Given `end_time > prev_block_time` and `end_time > start_time` ===> `end_time > last_vest_time` // Therefore, both numerator and denominator are positive. - bigRatVestProportion := big.NewRat(blockTimeMilli-lastVestTimeMilli, endTimeMilli-lastVestTimeMilli) + timeNum := lib.BigI(blockTimeMilli - lastVestTimeMilli) + timeDen := lib.BigI(endTimeMilli - lastVestTimeMilli) // Get vester account remaining balance. vesterBalance := k.bankKeeper.GetBalance(ctx, authtypes.NewModuleAddress(entry.VesterAccount), entry.Denom) + + // Determine the vesting amount. vestAmount := vesterBalance.Amount - if bigRatVestProportion.Cmp(lib.BigRat1()) < 0 { + if timeNum.Cmp(timeDen) < 0 { // vestProportion < 1, so vest_amount = vester_balance * vestProportion - bigRatBalance := new(big.Rat).SetInt(vesterBalance.Amount.BigInt()) - bigRatVestAmount := new(big.Rat).Mul( - bigRatBalance, - bigRatVestProportion, - ) - vestAmount = sdkmath.NewIntFromBigInt(lib.BigRatRound(bigRatVestAmount, false)) + a := vesterBalance.Amount.BigInt() + vestAmount = sdkmath.NewIntFromBigInt(a.Mul(a, timeNum).Quo(a, timeDen)) } if !vestAmount.IsZero() {