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

proposal_schedule_status.gno

3.65 Kb · 105 lines
  1package governance
  2
  3import (
  4	gnsmath "gno.land/p/gnoswap/gnsmath"
  5
  6	"gno.land/r/gnoswap/gov/governance"
  7)
  8
  9type ProposalScheduleStatusResolver struct {
 10	*governance.ProposalScheduleStatus
 11}
 12
 13func NewProposalScheduleStatusResolver(status *governance.ProposalScheduleStatus) *ProposalScheduleStatusResolver {
 14	return &ProposalScheduleStatusResolver{status}
 15}
 16
 17// IsPassedCreatedAt checks if the current time has passed the proposal creation time.
 18// This is always true once a proposal exists.
 19//
 20// Parameters:
 21//   - current: timestamp to check against
 22//
 23// Returns:
 24//   - bool: true if current time is at or after creation time
 25func (p *ProposalScheduleStatusResolver) IsPassedCreatedAt(current int64) bool {
 26	return p.CreateTime() <= current
 27}
 28
 29// IsPassedActiveAt checks if the current time has passed the voting start time.
 30// When true, the proposal enters its active voting period.
 31//
 32// Parameters:
 33//   - current: timestamp to check against
 34//
 35// Returns:
 36//   - bool: true if voting period has started
 37func (p *ProposalScheduleStatusResolver) IsPassedActiveAt(current int64) bool {
 38	return p.ActiveTime() <= current
 39}
 40
 41// IsPassedVotingEndedAt checks if the current time has passed the voting end time.
 42// When true, no more votes can be cast on the proposal.
 43//
 44// Parameters:
 45//   - current: timestamp to check against
 46//
 47// Returns:
 48//   - bool: true if voting period has ended
 49func (p *ProposalScheduleStatusResolver) IsPassedVotingEndedAt(current int64) bool {
 50	return p.VotingEndTime() <= current
 51}
 52
 53// IsPassedExecutableAt checks if the current time has passed the execution start time.
 54// When true, approved proposals can be executed (after execution delay).
 55//
 56// Parameters:
 57//   - current: timestamp to check against
 58//
 59// Returns:
 60//   - bool: true if execution window has started
 61func (p *ProposalScheduleStatusResolver) IsPassedExecutableAt(current int64) bool {
 62	return p.ExecutableTime() <= current
 63}
 64
 65// IsPassedExpiredAt checks if the current time has passed the execution expiration time.
 66// When true, the proposal can no longer be executed and has expired.
 67//
 68// Parameters:
 69//   - current: timestamp to check against
 70//
 71// Returns:
 72//   - bool: true if execution window has expired
 73func (p *ProposalScheduleStatusResolver) IsPassedExpiredAt(current int64) bool {
 74	return p.ExpiredTime() <= current
 75}
 76
 77// NewProposalScheduleStatus creates a new schedule status with calculated timestamps.
 78// This constructor takes the governance timing parameters and calculates all
 79// important timestamps for the proposal's lifecycle.
 80//
 81// Parameters:
 82//   - votingStartDelay: delay before voting starts (seconds)
 83//   - votingPeriod: duration of voting period (seconds)
 84//   - executionDelay: delay before execution can start (seconds)
 85//   - executionWindow: window during which execution is allowed (seconds)
 86//   - createdAt: timestamp when proposal was created
 87//
 88// Returns:
 89//   - *ProposalScheduleStatus: new schedule status with calculated times
 90func NewProposalScheduleStatus(
 91	votingStartDelay,
 92	votingPeriod,
 93	executionDelay,
 94	executionWindow,
 95	createdAt int64,
 96) *governance.ProposalScheduleStatus {
 97	// Calculate all phase timestamps based on creation time and configuration
 98	createTime := createdAt
 99	activeTime := gnsmath.SafeAddInt64(createTime, votingStartDelay)      // When voting can start
100	votingEndTime := gnsmath.SafeAddInt64(activeTime, votingPeriod)       // When voting ends
101	executableTime := gnsmath.SafeAddInt64(votingEndTime, executionDelay) // When execution can start
102	expiredTime := gnsmath.SafeAddInt64(executableTime, executionWindow)  // When execution window closes
103
104	return governance.NewProposalScheduleStatus(createTime, activeTime, votingEndTime, executableTime, expiredTime)
105}