Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

proposal_schedule_status.gno

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