From bcc4bd95b957d1d2ef11dc6a97aa6e504163a5dc Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Thu, 1 Sep 2022 17:15:27 -0700 Subject: [PATCH] chore: basic types for governance --- packages/governance/src/typeGuards.js | 103 ++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 packages/governance/src/typeGuards.js diff --git a/packages/governance/src/typeGuards.js b/packages/governance/src/typeGuards.js new file mode 100644 index 000000000000..7e42739ed212 --- /dev/null +++ b/packages/governance/src/typeGuards.js @@ -0,0 +1,103 @@ +// @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, +}); + +// all the strings that will be in the filter after passing +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, +}); + +// keys are parameter names, values are proposed values +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.eq(1), + closingRule: ClosingRuleShape, + quorumRule: QuorumRuleShape, + tieOutcome: NoApiInvocationPositionShape, +}); + +export const QuestionShape = M.or( + ApiInvocationQuestionSpecShape, + OfferFilterQuestionSpecShape, + ParamChangesQuestionSpecShape, + // SimpleQuestionSpecShape, // unused +);