-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy patheconCommitteeCharter.js
132 lines (117 loc) · 3.91 KB
/
econCommitteeCharter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import '@agoric/governance/exported.js';
import { makeScalarMapStore, M, makeHeapFarInstance, fit } from '@agoric/store';
import '@agoric/zoe/exported.js';
import '@agoric/zoe/src/contracts/exported.js';
import { InstanceHandleShape } from '@agoric/zoe/src/typeGuards.js';
import { TimestampShape } from '@agoric/swingset-vat/src/vats/timer/typeGuards.js';
import { E } from '@endo/far';
/**
* @file
*
* This contract makes it possible for those who govern contracts to call for
* votes on changes. A more complete implementation would validate parameters,
* constrain deadlines and possibly split the ability to call for votes into
* separate capabilities for finer grain encapsulation.
*/
export const INVITATION_MAKERS_DESC = 'charter member invitation';
/**
* @typedef {object} ParamChangesOfferArgs
* @property {bigint} deadline
* @property {Instance} instance
* @property {Record<string, unknown>} params
* @property {{paramPath: { key: string }}} [path]
*/
const ParamChangesOfferArgsShape = harden(
M.split(
{
deadline: TimestampShape,
instance: InstanceHandleShape,
params: M.recordOf(M.string(), M.any()),
},
M.partial({
path: { paramPath: { key: M.any() } },
}),
),
);
/**
* @param {ZCF<{binaryVoteCounterInstallation:Installation}>} zcf
*/
export const start = async zcf => {
const { binaryVoteCounterInstallation: counter } = zcf.getTerms();
/** @type {MapStore<Instance,GovernedContractFacetAccess<{},{}>>} */
const instanceToGovernor = makeScalarMapStore();
const makeParamInvitation = () => {
/**
* @param {ZCFSeat} seat
* @param {ParamChangesOfferArgs} args
*/
const voteOnParamChanges = (seat, args) => {
fit(args, ParamChangesOfferArgsShape);
seat.exit();
const {
params,
instance,
deadline,
path = { paramPath: { key: 'governedApi' } },
} = args;
const governor = instanceToGovernor.get(instance);
return E(governor).voteOnParamChanges(counter, deadline, {
...path,
changes: params,
});
};
return zcf.makeInvitation(voteOnParamChanges, 'vote on param changes');
};
const makeOfferFilterInvitation = (instance, strings, deadline) => {
const voteOnOfferFilterHandler = seat => {
seat.exit();
const governor = instanceToGovernor.get(instance);
return E(governor).voteOnOfferFilter(counter, deadline, strings);
};
return zcf.makeInvitation(voteOnOfferFilterHandler, 'vote on offer filter');
};
const MakerShape = M.interface('Charter InvitationMakers', {
VoteOnParamChange: M.call().returns(M.promise()),
VoteOnPauseOffers: M.call(
InstanceHandleShape,
M.arrayOf(M.string()),
TimestampShape,
).returns(M.promise()),
});
const invitationMakers = makeHeapFarInstance(
'Charter Invitation Makers',
MakerShape,
{
VoteOnParamChange: makeParamInvitation,
VoteOnPauseOffers: makeOfferFilterInvitation,
},
);
const charterMemberHandler = seat => {
seat.exit();
return harden({ invitationMakers });
};
const charterCreatorI = M.interface('Charter creatorFacet', {
addInstance: M.call(InstanceHandleShape, M.any())
.optional(M.string())
.returns(),
makeCharterMemberInvitation: M.call().returns(M.promise()),
});
const creatorFacet = makeHeapFarInstance(
'Charter creatorFacet',
charterCreatorI,
{
/**
* @param {Instance} governedInstance
* @param {GovernedContractFacetAccess<{},{}>} governorFacet
* @param {string} [label] for diagnostic use only
*/
addInstance: (governedInstance, governorFacet, label) => {
console.log('charter: adding instance', label);
instanceToGovernor.init(governedInstance, governorFacet);
},
makeCharterMemberInvitation: () =>
zcf.makeInvitation(charterMemberHandler, INVITATION_MAKERS_DESC),
},
);
return harden({ creatorFacet });
};