Search Apps Documentation Source Content File Folder Download Copy Actions Download

proposal_schedule_status.gno

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