Skip to content

Commit

Permalink
refactor: make privateArgs in governed contracts be private (#5967)
Browse files Browse the repository at this point in the history
* refactor: make privateArgs in governed contracts be private

* docs: cleanup description

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
Chris-Hibbert and mergify[bot] committed Aug 16, 2022
1 parent c59f4ba commit 6b7b997
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 58 deletions.
10 changes: 5 additions & 5 deletions packages/governance/src/contractGovernor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ const validateQuestionFromCounter = async (zoe, electorate, voteCounter) => {
* the Installation to be started, as well as an issuerKeywordRecord or terms
* needed by the governed contract. Those details for the governed contract are
* included in this contract's terms as a "governed" record. If the contract
* expects privateArgs, those can be supplied as well.
* expects privateArgs, those will be provided in this contract's `privateArgs`
* under 'governed:'.
*
* terms = {
* timer,
* electorateInstance,
* governedContractInstallation,
* governed: { issuerKeywordRecord, terms, privateArgs, },
* governed: { issuerKeywordRecord, terms },
* };
*
* The governedContract is responsible for supplying getParamMgrRetriever() in
Expand Down Expand Up @@ -114,15 +115,14 @@ const validateQuestionFromCounter = async (zoe, electorate, voteCounter) => {
* }
* }>}
*/
const start = async zcf => {
const start = async (zcf, privateArgs) => {
const zoe = zcf.getZoeService();
const {
timer,
governedContractInstallation,
governed: {
issuerKeywordRecord: governedIssuerKeywordRecord,
terms: contractTerms,
privateArgs: privateContractArgs,
},
} = zcf.getTerms();

Expand All @@ -144,7 +144,7 @@ const start = async zcf => {
governedContractInstallation,
governedIssuerKeywordRecord,
augmentedTerms,
privateContractArgs,
privateArgs.governed,
);

/** @type {() => Promise<Instance>} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,16 @@ const makeBootstrap = (argv, cb, vatPowers) => async (vats, devices) => {
governed: {
issuerKeywordRecord: {},
terms,
privateArgs: { initialPoserInvitation },
},
};

const { creatorFacet: governor, instance: governorInstance } = await E(
zoe,
).startInstance(installations.contractGovernor, {}, governedContractTerms);
).startInstance(installations.contractGovernor, {}, governedContractTerms, {
governed: {
initialPoserInvitation,
},
});
const governedInstance = E(governor).getInstance();
const governedPF = E(governor).getPublicFacet();
await watchParams(zoe, governedInstance, log);
Expand Down
6 changes: 5 additions & 1 deletion packages/governance/test/unitTests/test-paramGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ const setUpGovernedContract = async (zoe, electorateTerms, timer) => {
governed: {
terms: governedTerms,
issuerKeywordRecord: {},
privateArgs: { initialPoserInvitation: poserInvitation },
},
};

const governorFacets = await E(zoe).startInstance(
governor,
{},
governorTerms,
{
governed: {
initialPoserInvitation: poserInvitation,
},
},
);

return { governorFacets, installs, invitationAmount, committeeCreator };
Expand Down
79 changes: 45 additions & 34 deletions packages/inter-protocol/src/proposals/econ-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ export const setupAmm = async (
governed: {
terms: ammTerms,
issuerKeywordRecord: { Central: centralIssuer },
privateArgs: {
initialPoserInvitation: poserInvitation,
storageNode,
marshaller,
},
},
}),
);
Expand All @@ -242,7 +237,14 @@ export const setupAmm = async (
governorInstallation,
{},
ammGovernorTerms,
{ electorateCreatorFacet: committeeCreator },
{
electorateCreatorFacet: committeeCreator,
governed: {
initialPoserInvitation: poserInvitation,
storageNode,
marshaller,
},
},
);

const [creatorFacet, ammPublicFacet, instance] = await Promise.all([
Expand Down Expand Up @@ -299,10 +301,12 @@ export const setupReserve = async ({
const STORAGE_PATH = 'reserve';
trace('setupReserve');
const poserInvitationP = E(committeeCreator).getPoserInvitation();
const [poserInvitation, poserInvitationAmount] = await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
]);
const [poserInvitation, poserInvitationAmount, feeMintAccess] =
await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
feeMintAccessP,
]);

const reserveTerms = makeReserveTerms(
poserInvitationAmount,
Expand All @@ -320,12 +324,6 @@ export const setupReserve = async ({
governed: {
terms: reserveTerms,
issuerKeywordRecord: { Central: centralIssuer },
privateArgs: {
feeMintAccess: feeMintAccessP,
initialPoserInvitation: poserInvitation,
marshaller,
storageNode,
},
},
}),
);
Expand All @@ -336,6 +334,12 @@ export const setupReserve = async ({
reserveGovernorTerms,
{
electorateCreatorFacet: committeeCreator,
governed: {
feeMintAccess,
initialPoserInvitation: poserInvitation,
marshaller,
storageNode,
},
},
);

Expand Down Expand Up @@ -377,7 +381,7 @@ export const startVaultFactory = async (
chainTimerService,
priceAuthority,
zoe,
feeMintAccess,
feeMintAccess: feeMintAccessP,
economicCommitteeCreatorFacet: electorateCreatorFacet,
reserveCreatorFacet,
},
Expand Down Expand Up @@ -421,12 +425,14 @@ export const startVaultFactory = async (
initialShortfallInvitation,
shortfallInvitationAmount,
liquidateInstallation,
feeMintAccess,
] = await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
shortfallInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(shortfallInvitationP),
liquidateInstallationP,
feeMintAccessP,
]);

const centralBrand = await centralBrandP;
Expand Down Expand Up @@ -461,13 +467,6 @@ export const startVaultFactory = async (
governed: {
terms: vaultFactoryTerms,
issuerKeywordRecord: {},
privateArgs: {
feeMintAccess,
initialPoserInvitation,
initialShortfallInvitation,
marshaller,
storageNode,
},
},
}),
);
Expand All @@ -477,7 +476,16 @@ export const startVaultFactory = async (
contractGovernorInstallation,
undefined,
governorTerms,
harden({ electorateCreatorFacet }),
harden({
electorateCreatorFacet,
governed: {
feeMintAccess,
initialPoserInvitation,
initialShortfallInvitation,
marshaller,
storageNode,
},
}),
);

const [vaultFactoryInstance, vaultFactoryCreator] = await Promise.all([
Expand Down Expand Up @@ -767,7 +775,7 @@ export const startStakeFactory = async (
consume: {
board,
zoe,
feeMintAccess,
feeMintAccess: feeMintAccessP,
lienBridge,
client,
chainTimerService,
Expand Down Expand Up @@ -811,10 +819,11 @@ export const startStakeFactory = async (
const poserInvitationP = E(
economicCommitteeCreatorFacet,
).getPoserInvitation();
const [initialPoserInvitation, electorateInvitationAmount] =
const [initialPoserInvitation, electorateInvitationAmount, feeMintAccess] =
await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
feeMintAccessP,
]);

const stakeFactoryTerms = makeStakeFactoryTerms(
Expand Down Expand Up @@ -848,13 +857,6 @@ export const startStakeFactory = async (
governed: {
terms: stakeFactoryTerms,
issuerKeywordRecord: { Stake: bldIssuer },
privateArgs: {
feeMintAccess,
initialPoserInvitation,
lienBridge,
storageNode,
marshaller,
},
},
}),
);
Expand All @@ -864,6 +866,15 @@ export const startStakeFactory = async (
contractGovernorInstallation,
{},
stakeTerms,
{
governed: {
feeMintAccess,
initialPoserInvitation,
lienBridge,
storageNode,
marshaller,
},
},
);
const governedInstance = await E(governorFacets.creatorFacet).getInstance();
const creatorFacet = E(governorFacets.creatorFacet).getCreatorFacet();
Expand Down
34 changes: 19 additions & 15 deletions packages/inter-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const startPSM = async (
agoricNamesAdmin,
board,
zoe,
feeMintAccess,
feeMintAccess: feeMintAccessP,
economicCommitteeCreatorFacet,
chainStorage,
chainTimerService,
Expand Down Expand Up @@ -58,13 +58,15 @@ export const startPSM = async (
'string',
X`anchorOptions.denom must be a string, not ${denom}`,
);
const [runBrand, [anchorBrand, anchorIssuer]] = await Promise.all([
runBrandP,
reserveThenGetNamePaths(agoricNamesAdmin, [
['brand', keyword],
['issuer', keyword],
]),
]);
const [runBrand, [anchorBrand, anchorIssuer], feeMintAccess] =
await Promise.all([
runBrandP,
reserveThenGetNamePaths(agoricNamesAdmin, [
['brand', keyword],
['issuer', keyword],
]),
feeMintAccessP,
]);

const poserInvitationP = E(
economicCommitteeCreatorFacet,
Expand Down Expand Up @@ -113,20 +115,22 @@ export const startPSM = async (
governed: {
terms,
issuerKeywordRecord: { [keyword]: anchorIssuer },
privateArgs: {
feeMintAccess,
initialPoserInvitation,
marshaller,
storageNode,
},
},
}),
);
const governorFacets = await E(zoe).startInstance(
contractGovernor,
{},
governorTerms,
harden({ economicCommitteeCreatorFacet }),
harden({
economicCommitteeCreatorFacet,
governed: {
feeMintAccess,
initialPoserInvitation,
marshaller,
storageNode,
},
}),
);

const governedInstance = await E(governorFacets.creatorFacet).getInstance();
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/test/swingsetTests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ const buildOwner = async (
governed: {
terms,
issuerKeywordRecord: {},
privateArgs: privateVaultFactoryArgs,
},
}),
{ governed: privateVaultFactoryArgs },
);

const governedInstance = await E(governorFacets.creatorFacet).getInstance();
Expand Down

0 comments on commit 6b7b997

Please sign in to comment.