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

types.gno

3.35 Kb · 121 lines
  1package halt
  2
  3// Halt levels define different states of system operation restriction.
  4const (
  5	HaltLevelNone      HaltLevel = "NONE"      // All operations enabled.
  6	HaltLevelSafeMode  HaltLevel = "SAFE_MODE" // All operations enabled except withdrawals.
  7	HaltLevelEmergency HaltLevel = "EMERGENCY" // Only governance and withdrawal operations enabled.
  8	HaltLevelComplete  HaltLevel = "COMPLETE"  // All operations disabled.
  9)
 10
 11// Operation types representing individual contracts.
 12const (
 13	OpTypePool          OpType = "pool"
 14	OpTypePosition      OpType = "position"
 15	OpTypeProtocolFee   OpType = "protocol_fee"
 16	OpTypeRouter        OpType = "router"
 17	OpTypeStaker        OpType = "staker"
 18	OpTypeLaunchpad     OpType = "launchpad"
 19	OpTypeGovernance    OpType = "governance"
 20	OpTypeGovStaker     OpType = "gov_staker"
 21	OpTypeXGns          OpType = "xgns"
 22	OpTypeCommunityPool OpType = "community_pool"
 23	OpTypeEmission      OpType = "emission"
 24	OpTypeWithdraw      OpType = "withdraw"
 25)
 26
 27// HaltLevel represents current system halt state.
 28type HaltLevel string
 29
 30// String returns the string representation of the halt level.
 31//
 32// Returns:
 33//   - text: exact string value represented by the halt level
 34func (h HaltLevel) String() string {
 35	return string(h)
 36}
 37
 38// Description returns a human-readable description of the halt level.
 39//
 40// Returns:
 41//   - description: human-readable policy description; "Unknown halt level" for
 42//     an unrecognized value
 43func (h HaltLevel) Description() string {
 44	haltLevelDescriptions := map[HaltLevel]string{
 45		HaltLevelNone:      "All operations enabled",
 46		HaltLevelSafeMode:  "All operations enabled except withdrawals",
 47		HaltLevelEmergency: "Only governance and withdrawal operations enabled",
 48		HaltLevelComplete:  "All operations disabled",
 49	}
 50
 51	desc, ok := haltLevelDescriptions[h]
 52	if !ok {
 53		return "Unknown halt level"
 54	}
 55
 56	return desc
 57}
 58
 59// IsValid returns true if the halt level is valid.
 60//
 61// Returns:
 62//   - valid: true for one of the defined halt levels; false otherwise
 63func (h HaltLevel) IsValid() bool {
 64	switch h {
 65	case HaltLevelNone, HaltLevelSafeMode, HaltLevelEmergency, HaltLevelComplete:
 66		return true
 67	default:
 68		return false
 69	}
 70}
 71
 72// OpType represents operation types that can be controlled independently.
 73type OpType string
 74
 75var opTypes = map[OpType]bool{
 76	OpTypePool:          true,
 77	OpTypePosition:      true,
 78	OpTypeProtocolFee:   true,
 79	OpTypeRouter:        true,
 80	OpTypeStaker:        true,
 81	OpTypeLaunchpad:     true,
 82	OpTypeGovernance:    true,
 83	OpTypeGovStaker:     true,
 84	OpTypeXGns:          true,
 85	OpTypeCommunityPool: true,
 86	OpTypeEmission:      true,
 87	OpTypeWithdraw:      true,
 88}
 89
 90// String returns the string representation of the operation type.
 91//
 92// Returns:
 93//   - text: exact string value represented by the operation type
 94func (o OpType) String() string {
 95	return string(o)
 96}
 97
 98// IsValid returns true if the operation type is valid.
 99//
100// Returns:
101//   - valid: true when the operation type is defined; false otherwise
102func (o OpType) IsValid() bool {
103	_, ok := opTypes[o]
104
105	return ok
106}
107
108// OpTypes returns all operation types currently supported by the halt
109// configuration.
110//
111// Returns:
112//   - operationTypes: slice containing each defined operation type in map iteration order
113func OpTypes() []OpType {
114	allOpTypes := make([]OpType, 0, len(opTypes))
115
116	for op := range opTypes {
117		allOpTypes = append(allOpTypes, op)
118	}
119
120	return allOpTypes
121}