Skip to content

Commit

Permalink
Remove use of big.Rat from x/vest (#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanChou authored May 22, 2024
1 parent 011b9c2 commit ddd0ac5
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions protocol/x/vest/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"fmt"
"math/big"
"time"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit ddd0ac5

Please sign in to comment.