Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: distribute PSM Charter Invitatitons #6166

Merged
merged 3 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 76 additions & 2 deletions packages/inter-protocol/src/proposals/startPSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import { makeRatio } from '@agoric/zoe/src/contractSupport/index.js';
import { E } from '@endo/far';
import { Stable } from '@agoric/vats/src/tokens.js';
import { deeplyFulfilledObject } from '@agoric/internal';
import { assert } from '@agoric/assert';
import { makeScalarMapStore } from '@agoric/vat-data';

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

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

const { values } = Object;

/**
* @param {EconomyBootstrapPowers & WellKnownSpaces} powers
* @param {object} [config]
Expand Down Expand Up @@ -339,6 +340,68 @@ 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: { zoe, namesByAddressAdmin, economicCommitteeCreatorFacet },
installation: {
consume: { binaryVoteCounter: counterP, psmCharter: psmCharterP },
},
},
{ options: { voterAddresses } },
) => {
/** @type {[Installation, Installation]} */
const [charterInstall, counterInstall] = await Promise.all([
psmCharterP,
counterP,
]);
const terms = await deeplyFulfilledObject(
harden({
binaryVoteCounterInstallation: counterInstall,
}),
);

const { creatorFacet } = E.get(
E(zoe).startInstance(charterInstall, undefined, terms),
);

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(creatorFacet).makeCharterMemberInvitation(),
]);
console.log('@@@sending charter, voting invitations to', addr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('@@@sending charter, voting invitations to', addr);
console.log('sending charter, voting invitations to', addr);

That @@@ thingy is my "I have to run to a meeting now; make sure I don't ship this half-baked code" marker. Let's take it out. Or we can drop the log message altogether, but I think maybe this is worth keeping.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

await reserveThenDeposit(
`econ committee member ${addr}`,
namesByAddressAdmin,
addr,
[voterInvitation, charterMemberInvitation],
);
console.log('@@@sent charter, voting invitations to', addr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('@@@sent charter, voting invitations to', addr);
console.log('sent charter, voting invitations to', addr);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}),
);
};

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

export const PSM_MANIFEST = harden({
[makeAnchorAsset.name]: {
consume: { agoricNamesAdmin: true, bankManager: 'bank', zoe: 'zoe' },
Expand Down Expand Up @@ -376,6 +439,17 @@ export const PSM_MANIFEST = harden({
consume: { AUSD: 'bank' },
},
},
[invitePSMCommitteeMembers.name]: {
consume: {
zoe: true,
namesByAddressAdmin: true,
economicCommitteeCreatorFacet: true,
psmFacets: true,
},
installation: {
consume: { binaryVoteCounter: true },
},
},
});

export const getManifestForPsm = (
Expand Down
11 changes: 8 additions & 3 deletions packages/vats/src/core/boot-psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
installGovAndPSMContracts,
makeAnchorAsset,
startPSM,
invitePSMCommitteeMembers,
PSM_MANIFEST,
PSM_GOV_MANIFEST,
startPSMCharter,
Expand Down Expand Up @@ -66,6 +67,7 @@ export const agoricNamesReserved = harden(
committee: 'committee electorate',
binaryVoteCounter: 'binary vote counter',
psm: 'Parity Stability Module',
psmCharter: 'Governance Charter for PSM',
},
instance: {
economicCommittee: 'Economic Committee',
Expand Down Expand Up @@ -99,8 +101,8 @@ const AnchorOptionsShape = M.split(
* logger?: (msg: string) => void
* }} vatPowers
* @param {{
* economicCommitteeAddresses: string[],
* anchorAssets: AnchorOptions[],
* economicCommitteeAddresses: Record<string, string>,
* anchorAssets: { denom: string, keyword?: string }[],
* }} vatParameters
*/
export const buildRootObject = (vatPowers, vatParameters) => {
Expand Down Expand Up @@ -173,10 +175,13 @@ export const buildRootObject = (vatPowers, vatParameters) => {
startEconomicCommittee(powersFor('startEconomicCommittee'), {
options: {
econCommitteeOptions: {
committeeSize: economicCommitteeAddresses.length,
committeeSize: Object.values(economicCommitteeAddresses).length,
},
},
}),
invitePSMCommitteeMembers(powersFor('invitePSMCommitteeMembers'), {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

options: { voterAddresses: economicCommitteeAddresses },
}),
...anchorAssets.map(anchorOptions =>
makeAnchorAsset(powersFor('makeAnchorAsset'), {
options: { anchorOptions },
Expand Down