Skip to content

Commit

Permalink
chore: basic types for governance
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Sep 2, 2022
1 parent f341634 commit bcc4bd9
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions packages/governance/src/typeGuards.js
Original file line number Diff line number Diff line change
@@ -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
);

0 comments on commit bcc4bd9

Please sign in to comment.