Skip to content

Commit

Permalink
feat(inter-protocol): separate inviteCommitteMembers from inviteToCha…
Browse files Browse the repository at this point in the history
…rter
  • Loading branch information
michaelfig committed Nov 29, 2022
1 parent bcde647 commit 06c2df6
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 91 deletions.
89 changes: 52 additions & 37 deletions packages/inter-protocol/src/proposals/committee-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,45 @@ const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);
* @param {{ options: { voterAddresses: Record<string, string> }}} param1
*/
export const inviteCommitteeMembers = async (
{ consume: { namesByAddressAdmin, economicCommitteeCreatorFacet } },
{ options: { voterAddresses } },
) => {
const invitations = await E(
economicCommitteeCreatorFacet,
).getVoterInvitations();
assert.equal(invitations.length, values(voterAddresses).length);

/**
* @param {[string, Promise<Invitation>][]} addrInvitations
*/
const distributeInvitations = async addrInvitations => {
await Promise.all(
addrInvitations.map(async ([addr, invitationP]) => {
await reserveThenDeposit(
`econ committee member ${addr}`,
namesByAddressAdmin,
addr,
[invitationP],
);
}),
);
};

await distributeInvitations(zip(values(voterAddresses), invitations));
};

harden(inviteCommitteeMembers);

/**
* @param {import('./econ-behaviors').EconomyBootstrapPowers} powers
* @param {{ options: { voterAddresses: Record<string, string> }}} param1
*/
export const inviteToEconCharter = async (
{
consume: {
zoe,
agoricNames,
namesByAddressAdmin,
psmCharterCreatorFacet,
economicCommitteeCreatorFacet,
reserveGovernorCreatorFacet,
ammGovernorCreatorFacet,
vaultFactoryGovernorCreator,
Expand All @@ -39,49 +71,31 @@ export const inviteCommitteeMembers = async (
binaryVoteCounterInstallation: counterInstall,
}),
);
// TODO: Add these facets dynamically when they are instantiated.
// TODO: Follow PSM continuing invitation charter style.
const privateFacets = {
reserve: reserveGovernorCreatorFacet,
amm: ammGovernorCreatorFacet,
vaults: vaultFactoryGovernorCreator,
psm: psmCharterCreatorFacet,
};
const { publicFacet: votingAPI } = E.get(
// TODO(6034): be sure to save the result of startInstance, especially adminFacet
const { publicFacet: charterAPI } = E.get(
E(zoe).startInstance(charterInstall, undefined, terms, privateFacets),
);

const invitations = await E(
economicCommitteeCreatorFacet,
).getVoterInvitations();
assert.equal(invitations.length, values(voterAddresses).length);

/**
* @param {[string, Promise<Invitation>][]} addrInvitations
*/
const distributeInvitations = async addrInvitations => {
await Promise.all(
addrInvitations.map(async ([addr, invitationP]) => {
await reserveThenDeposit(
`econ committee member ${addr}`,
namesByAddressAdmin,
addr,
[
invitationP,
// TODO(#6598): This null invitation is used just to identify the
// closely-held economy charter instance handle. Instead, the
// economy charter should use continuing invitations like the PSM
// charter does for compatibility with the smart wallet.
E(votingAPI).makeNullInvitation(),
E(psmCharterCreatorFacet).makeCharterMemberInvitation(),
],
);
}),
);
};

await distributeInvitations(zip(values(voterAddresses), invitations));
await Promise.all(
values(voterAddresses).map(async addr =>
reserveThenDeposit(
`econ charter member ${addr}`,
namesByAddressAdmin,
addr,
[E(charterAPI).makeNullInvitation()],
),
),
);
};

harden(inviteCommitteeMembers);
harden(inviteToEconCharter);

export const getManifestForInviteCommittee = async (
{ restoreRef },
Expand All @@ -91,13 +105,14 @@ export const getManifestForInviteCommittee = async (
return {
manifest: {
[inviteCommitteeMembers.name]: {
consume: { namesByAddressAdmin: t, economicCommitteeCreatorFacet: t },
},
[inviteToEconCharter.name]: {
consume: {
zoe: t,
agoricNames: t,
namesByAddressAdmin: t,
economicCommitteeCreatorFacet: t,
reserveGovernorCreatorFacet: t,
psmCharterCreatorFacet: t,
ammGovernorCreatorFacet: t,
vaultFactoryGovernorCreator: t,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/inter-protocol/src/proposals/core-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export * from './econ-behaviors.js';
export * from './sim-behaviors.js';
// @ts-expect-error Module './econ-behaviors.js' has already exported a member
// named 'EconomyBootstrapPowers'.
export * from './startPSM.js';
export * from './startEconCommittee.js';
export * from './startPSM.js'; // eslint-disable-line import/export
export * from './startEconCommittee.js'; // eslint-disable-line import/export

/** @type {import('@agoric/vats/src/core/manifest.js').BootstrapManifest} */
const SHARED_MAIN_MANIFEST = harden({
Expand Down
86 changes: 36 additions & 50 deletions packages/inter-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import { makeScalarMapStore } from '@agoric/vat-data';

import { reserveThenDeposit, reserveThenGetNamePaths } from './utils.js';

import { inviteCommitteeMembers } from './committee-proposal.js';

const BASIS_POINTS = 10000n;
const { details: X } = assert;

const { values } = Object;

export { inviteCommitteeMembers };

/**
* @param {EconomyBootstrapPowers & WellKnownSpaces} powers
* @param {object} [config]
Expand Down Expand Up @@ -366,64 +370,46 @@ export const PSM_GOV_MANIFEST = {
},
};

/** @type { <X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);

/**
* @param {import('./econ-behaviors').EconomyBootstrapPowers} powers
* @param {{ options: { voterAddresses: Record<string, string> }}} param1
*/
export const invitePSMCommitteeMembers = async (
{
consume: {
namesByAddressAdmin,
economicCommitteeCreatorFacet,
psmCharterCreatorFacet,
},
},
export const inviteToPSMCharter = async (
{ consume: { namesByAddressAdmin, psmCharterCreatorFacet } },
{ options: { voterAddresses = {} } },
) => {
const invitations = await E(
economicCommitteeCreatorFacet,
).getVoterInvitations();
assert.equal(invitations.length, values(voterAddresses).length);

/**
* @param {[string, Promise<Invitation>][]} addrInvitations
*/
const distributeInvitations = async addrInvitations => {
await Promise.all(
addrInvitations.map(async ([addr, invitationP]) => {
const [voterInvitation, charterMemberInvitation] = await Promise.all([
invitationP,
E(psmCharterCreatorFacet).makeCharterMemberInvitation(),
]);
console.log('sending charter, voting invitations to', addr);
await reserveThenDeposit(
`econ committee member ${addr}`,
namesByAddressAdmin,
addr,
[voterInvitation, charterMemberInvitation],
);
console.log('sent charter, voting invitations to', addr);
}),
);
};

await distributeInvitations(zip(values(voterAddresses), invitations));
await Promise.all(
values(voterAddresses).map(async addr => {
console.log('sending charter, voting invitations to', addr);
await reserveThenDeposit(
`psm charter member ${addr}`,
namesByAddressAdmin,
addr,
[E(psmCharterCreatorFacet).makeCharterMemberInvitation()],
);
console.log('sent charter, voting invitations to', addr);
}),
);
};
harden(invitePSMCommitteeMembers);

/** @type {import('@agoric/vats/src/core/manifest.js').BootstrapManifest} */
export const INVITE_PSM_COMMITTEE_MANIFEST = harden({
[invitePSMCommitteeMembers.name]: {
consume: {
namesByAddressAdmin: true,
economicCommitteeCreatorFacet: true,
psmCharterCreatorFacet: true,
harden(inviteToPSMCharter);

export const INVITE_PSM_COMMITTEE_MANIFEST = harden(
/** @type {import('@agoric/vats/src/core/manifest.js').BootstrapManifest} */
({
[inviteCommitteeMembers.name]: {
consume: {
namesByAddressAdmin: true,
economicCommitteeCreatorFacet: true,
},
},
},
});
[inviteToPSMCharter.name]: {
consume: {
namesByAddressAdmin: true,
psmCharterCreatorFacet: true,
},
},
}),
);

/** @type {import('@agoric/vats/src/core/manifest.js').BootstrapManifest} */
export const PSM_MANIFEST = harden({
Expand Down
8 changes: 6 additions & 2 deletions packages/vats/src/core/boot-psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
installGovAndPSMContracts,
makeAnchorAsset,
startPSM,
invitePSMCommitteeMembers,
inviteToPSMCharter,
inviteCommitteeMembers,
PSM_MANIFEST,
PSM_GOV_MANIFEST,
startPSMCharter,
Expand Down Expand Up @@ -194,7 +195,10 @@ export const buildRootObject = (vatPowers, vatParameters) => {
},
},
}),
invitePSMCommitteeMembers(powersFor('invitePSMCommitteeMembers'), {
inviteCommitteeMembers(powersFor('inviteCommitteeMembers'), {
options: { voterAddresses: economicCommitteeAddresses },
}),
inviteToPSMCharter(powersFor('inviteToPSMCharter'), {
options: { voterAddresses: economicCommitteeAddresses },
}),
...anchorAssets.map(anchorOptions =>
Expand Down

0 comments on commit 06c2df6

Please sign in to comment.