gpu-compute-chain/x/colinearcore/math/vesting.go

48 lines
1.2 KiB
Go

package colinearmath
import (
"math/big"
"time"
)
// Calculate amount due to provider assuming linear payout schedule.
//
// Does NOT account for anything out-of-bounds. This must be checked beforehand.
func CalcAmountVestableLinear(
total *big.Int,
remaining *big.Int,
date time.Time,
beginDate time.Time,
endDate time.Time,
) (*big.Int, error) {
timePassed := big.NewInt(date.Unix() - beginDate.Unix())
totalTime := big.NewInt(endDate.Unix() - beginDate.Unix())
taken := big.NewInt(0)
taken.Sub(total, remaining)
out := big.NewInt(0)
out.Mul(total, timePassed)
out.Div(out, totalTime)
out.Sub(out, taken)
return out, nil
}
// No longer using exponential - use linear distribution schedule
// because exponential rewards are a weak incentive for providers
// func CalcAmountVestableExponential(
// ctx sdk.Context,
// total big.Int,
// remaining big.Int,
// date time.Time,
// beginDate time.Time,
// endDate time.Time,
// ) big.Int {
// timescale := big.NewInt(endDate.Unix() - beginDate.Unix())
// timePassed := big.NewInt(date.Unix() - beginDate.Unix())
// expTerm := big.NewInt(1)
// expTerm.Exp(big.NewInt(2), timePassed, big.NewInt(1))
// }