diff --git a/packages/governance/src/typeGuards.js b/packages/governance/src/typeGuards.js new file mode 100644 index 000000000000..80c4e0240223 --- /dev/null +++ b/packages/governance/src/typeGuards.js @@ -0,0 +1,101 @@ +// @ts-check + +import { M } from '@agoric/store'; +import { TimestampShape } from '../../SwingSet/src/vats/timer/typeGuards'; + +export const ChoiceMethodShape = M.or('unranked', 'order'); +export const QuorumRuleShape = M.or('majority', 'no_quorum', 'all'); +export const ElectionTypeShape = M.or( + 'param_change', + 'election', + 'survey', + 'api_invocation', + 'offer_filter', +); + +export const TimerShape = M.handle('timer'); +export const InstanceShape = M.handle('instance'); + +export const ClosingRuleShape = harden({ + timer: M.eref(TimerShape), + deadline: TimestampShape, +}); + +export const YesOfferFilterPositionShape = M.arrayOf(M.string()); +export const NoOfferFilterPositionShape = harden({ + dontUpdate: M.arrayOf(M.string()), +}); +export const OfferFilterPositionsShape = [ + YesOfferFilterPositionShape, + NoOfferFilterPositionShape, +]; +export const OfferFilterIssueShape = harden({ + strings: M.arrayOf(M.string()), +}); +export const OfferFilterQuestionSpecShape = harden({ + method: ChoiceMethodShape, + issue: OfferFilterIssueShape, + positions: OfferFilterPositionsShape, + electionType: ElectionTypeShape, + maxChoices: M.eq(1n), + closingRule: ClosingRuleShape, + quorumRule: QuorumRuleShape, + tieOutcome: NoOfferFilterPositionShape, +}); + +export const ParamChangesSpecShape = M.recordOf(M.string(), M.any()); +export const YesParamChangesPositionShape = ParamChangesSpecShape; +export const NoParamChangesPositionShape = harden({ + noChange: M.arrayOf(M.string()), +}); +export const ParamChangesPositionsShape = [ + YesParamChangesPositionShape, + NoParamChangesPositionShape, +]; +export const ParamChangesIssueShape = harden({ + spec: ParamChangesSpecShape, + contract: InstanceShape, +}); +export const ParamChangesQuestionSpecShape = harden({ + method: ChoiceMethodShape, + issue: ParamChangesIssueShape, + positions: ParamChangesPositionsShape, + electionType: ElectionTypeShape, + maxChoices: M.eq(1n), + closingRule: ClosingRuleShape, + quorumRule: QuorumRuleShape, + tieOutcome: NoParamChangesPositionShape, +}); + +const ApiInvocationSpecShape = harden({ + apiMethodName: M.string(), + methodArgs: M.string(), +}); +export const YesApiInvocationPositionShape = ApiInvocationSpecShape; +export const NoApiInvocationPositionShape = harden({ + dontInvoke: M.arrayOf(M.string()), +}); +export const ApiInvocationPositionsShape = [ + YesApiInvocationPositionShape, + NoApiInvocationPositionShape, +]; +export const ApiInvocationIssueShape = harden({ + spec: ApiInvocationSpecShape, +}); +export const ApiInvocationQuestionSpecShape = harden({ + method: 'unranked', + issue: ApiInvocationIssueShape, + positions: ApiInvocationPositionsShape, + electionType: 'api_invocation', + maxChoices: M.bigint(), + closingRule: ClosingRuleShape, + quorumRule: QuorumRuleShape, + tieOutcome: NoApiInvocationPositionShape, +}); + +export const QuestionShape = M.or( + ApiInvocationQuestionSpecShape, + OfferFilterQuestionSpecShape, + ParamChangesQuestionSpecShape, + // SimpleQuestionSpecShape, // unused +);