fix incorrect vesting remainder behavior

also checks vesting schedule range when calculating
This commit is contained in:
2022-09-15 00:41:33 +00:00
parent f3ddfca045
commit 0e39e78a0f
2 changed files with 12 additions and 5 deletions

View File

@@ -2,7 +2,6 @@ package keeper
import (
"context"
"errors"
"fmt"
"math/big"
"time"
@@ -53,7 +52,10 @@ func (k msgServer) ClaimFunds(goCtx context.Context, msg *types.MsgClaimFunds) (
now := ctx.BlockTime()
subAmt, err := colinearmath.CalcAmountVestableLinear(total, remaining, now, leaseBegin, leaseEnd)
if err != nil {
return nil, errors.New("unable to calculate vestable amount")
return nil, fmt.Errorf("unable to calculate vestable amount: %s", err)
}
if subAmt.Cmp(big.NewInt(0)) == 0 {
return nil, fmt.Errorf("no claimable %s (calculated vesting amount is 0)", auction.Denom)
}
// pay from module to user account
@@ -65,7 +67,7 @@ func (k msgServer) ClaimFunds(goCtx context.Context, msg *types.MsgClaimFunds) (
// subtract paid amount off of remaining payout tally & commit to chain state
newRemaining := new(big.Int)
newRemaining.Sub(remaining, subAmt)
auction.Remaining = subAmt.String()
auction.Remaining = newRemaining.String()
k.Keeper.SetAuction(ctx, auction)
return &types.MsgClaimFundsResponse{}, nil