fix incorrect vesting remainder behavior
also checks vesting schedule range when calculatingmaster
parent
f3ddfca045
commit
0e39e78a0f
|
@ -2,7 +2,6 @@ package keeper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
@ -53,7 +52,10 @@ func (k msgServer) ClaimFunds(goCtx context.Context, msg *types.MsgClaimFunds) (
|
||||||
now := ctx.BlockTime()
|
now := ctx.BlockTime()
|
||||||
subAmt, err := colinearmath.CalcAmountVestableLinear(total, remaining, now, leaseBegin, leaseEnd)
|
subAmt, err := colinearmath.CalcAmountVestableLinear(total, remaining, now, leaseBegin, leaseEnd)
|
||||||
if err != nil {
|
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
|
// 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
|
// subtract paid amount off of remaining payout tally & commit to chain state
|
||||||
newRemaining := new(big.Int)
|
newRemaining := new(big.Int)
|
||||||
newRemaining.Sub(remaining, subAmt)
|
newRemaining.Sub(remaining, subAmt)
|
||||||
auction.Remaining = subAmt.String()
|
auction.Remaining = newRemaining.String()
|
||||||
k.Keeper.SetAuction(ctx, auction)
|
k.Keeper.SetAuction(ctx, auction)
|
||||||
|
|
||||||
return &types.MsgClaimFundsResponse{}, nil
|
return &types.MsgClaimFundsResponse{}, nil
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package colinearmath
|
package colinearmath
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -11,11 +12,15 @@ import (
|
||||||
func CalcAmountVestableLinear(
|
func CalcAmountVestableLinear(
|
||||||
total *big.Int,
|
total *big.Int,
|
||||||
remaining *big.Int,
|
remaining *big.Int,
|
||||||
date time.Time,
|
now time.Time,
|
||||||
beginDate time.Time,
|
beginDate time.Time,
|
||||||
endDate time.Time,
|
endDate time.Time,
|
||||||
) (*big.Int, error) {
|
) (*big.Int, error) {
|
||||||
timePassed := big.NewInt(date.Unix() - beginDate.Unix())
|
timePassed := big.NewInt(now.Unix() - beginDate.Unix())
|
||||||
|
if timePassed.Cmp(big.NewInt(0)) == -1 {
|
||||||
|
return nil, fmt.Errorf("time %d is out of range (%d, %d)", now.Unix(), beginDate.Unix(), endDate.Unix())
|
||||||
|
}
|
||||||
|
|
||||||
totalTime := big.NewInt(endDate.Unix() - beginDate.Unix())
|
totalTime := big.NewInt(endDate.Unix() - beginDate.Unix())
|
||||||
|
|
||||||
taken := big.NewInt(0)
|
taken := big.NewInt(0)
|
||||||
|
|
Loading…
Reference in New Issue