Skip to content

Commit

Permalink
feat: distribute PSM Charter Invitatitons (#6166)
Browse files Browse the repository at this point in the history
* feat: distribute PSM Charter Invitaitons

* chore: cleanups from CI: addresses are a record; permit for Charter

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
Chris-Hibbert and mergify[bot] authored Sep 8, 2022
1 parent 76c17c7 commit 50cd3e2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
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);
await reserveThenDeposit(
`econ committee member ${addr}`,
namesByAddressAdmin,
addr,
[voterInvitation, charterMemberInvitation],
);
console.log('sent charter, voting invitations to', addr);
}),
);
};

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, psmCharter: true },
},
},
});

export const getManifestForPsm = (
Expand Down
2 changes: 1 addition & 1 deletion packages/smart-wallet/test/test-psm-integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const committeeAddress = 'psmTestAddress';
const makePsmTestSpace = async log => {
const psmParams = {
anchorAssets: [{ denom: 'ibc/usdc1234', keyword: 'AUSD' }],
economicCommitteeAddresses: [committeeAddress],
economicCommitteeAddresses: { aMember: committeeAddress },
argv: { bootMsg: {} },
};

Expand Down
13 changes: 9 additions & 4 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,16 +101,16 @@ 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) => {
const log = vatPowers.logger || console.info;

const { anchorAssets, economicCommitteeAddresses } = vatParameters;
fit(harden(anchorAssets), M.arrayOf(AnchorOptionsShape));
fit(harden(economicCommitteeAddresses), M.arrayOf(M.string()));
fit(harden(economicCommitteeAddresses), M.recordOf(M.string(), M.string()));

const { produce, consume } = makePromiseSpace(log);
const { agoricNames, agoricNamesAdmin, spaces } = makeAgoricNamesAccess(
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'), {
options: { voterAddresses: economicCommitteeAddresses },
}),
...anchorAssets.map(anchorOptions =>
makeAnchorAsset(powersFor('makeAnchorAsset'), {
options: { anchorOptions },
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/test/test-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ test('bootstrap provides a way to pass items to CORE_EVAL', async t => {

const psmParams = {
anchorAssets: [{ denom: 'ibc/toyusdc' }],
economicCommitteeAddresses: [],
economicCommitteeAddresses: {},
argv: { bootMsg: {} },
};

Expand Down

0 comments on commit 50cd3e2

Please sign in to comment.