53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package colinearmath
|
|
|
|
import (
|
|
"fmt"
|
|
"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,
|
|
now time.Time,
|
|
beginDate time.Time,
|
|
endDate time.Time,
|
|
) (*big.Int, error) {
|
|
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())
|
|
|
|
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))
|
|
// }
|