Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

vesting.gno

0.86 Kb · 34 lines
 1// Package vesting computes cliff-then-linear token release.
 2package vesting
 3
 4import sm "gno.land/p/samcrew/launchpad/safemath/v1"
 5
 6type Schedule struct {
 7	Total    int64
 8	Start    int64 // unix seconds
 9	Cliff    int64 // seconds after Start before anything vests
10	Duration int64 // seconds after Start when everything has vested
11}
12
13func (s Schedule) Validate() {
14	if s.Total <= 0 || s.Start < 0 || s.Duration <= 0 || s.Cliff < 0 || s.Cliff > s.Duration {
15		panic("launchpad/vesting: invalid schedule")
16	}
17	sm.Add(s.Start, s.Duration)
18}
19
20func (s Schedule) VestedAt(now int64) int64 {
21	s.Validate()
22	if now < sm.Add(s.Start, s.Cliff) {
23		return 0
24	}
25	elapsed := now - s.Start
26	if elapsed >= s.Duration {
27		return s.Total
28	}
29	return sm.MulDiv(s.Total, elapsed, s.Duration)
30}
31
32func (s Schedule) Releasable(now, released int64) int64 {
33	return sm.Sub(s.VestedAt(now), released)
34}