Skip to content

Commit

Permalink
chore: restore using type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Sep 20, 2024
1 parent f9f6bb7 commit 189a18e
Showing 1 changed file with 35 additions and 65 deletions.
100 changes: 35 additions & 65 deletions packages/inter-protocol/test/psm/gov-replace-committee.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* global E */
// @ts-check
/// <reference types="@agoric/vats/src/core/core-eval-env" />
/// <reference types="@agoric/vats/src/core/core-eval-env"/>
/// <reference types="@agoric/vats/src/core/types-ambient"/>

/**
* @import {NameAdmin} from '@agoric/vats';
*/

/**
* @file Script to replace the econ governance committee in a SwingSet Core Eval
Expand All @@ -25,7 +30,15 @@ const { values } = Object;
/** @type {<X, Y>(xs: X[], ys: Y[]) => [X, Y][]} */
const zip = (xs, ys) => xs.map((x, i) => [x, ys[i]]);

/**
* @param {NameAdmin} nameAdmin
* @param {string[][]} paths
*/
const reserveThenGetNamePaths = async (nameAdmin, paths) => {
/**
* @param {NameAdmin} nextAdmin
* @param {string[]} path
*/
const nextPath = async (nextAdmin, path) => {
const [nextName, ...rest] = path;
assert.typeof(nextName, 'string');
Expand Down Expand Up @@ -86,21 +99,22 @@ const invitePSMCommitteeMembers = async (
).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(E.get(econCharterKit).creatorFacet).makeCharterMemberInvitation(),
]);
console.log('sending charter, voting invitations to', addr);
trace('sending charter, voting invitations to', addr);
await reserveThenDeposit(
`econ committee member ${addr}`,
namesByAddressAdmin,
addr,
[voterInvitation, charterMemberInvitation],
);
console.log('sent charter, voting invitations to', addr);
trace('sent charter, voting invitations to', addr);
}),
);
};
Expand All @@ -109,6 +123,15 @@ const invitePSMCommitteeMembers = async (
};
harden(invitePSMCommitteeMembers);

/**
* Convenience function for returning a storage node at or under its input,
* falling back to an inert object with the correct interface (but incomplete
* behavior) when that is unavailable.
*
* @param {ERef<StorageNode>} storageNodeRef
* @param {string} childName
* @returns {Promise<StorageNode>}
*/
async function makeStorageNodeChild(storageNodeRef, childName) {
return E(storageNodeRef).makeChildNode(childName);
}
Expand Down Expand Up @@ -146,8 +169,6 @@ const startNewEconomicCommittee = async ({
produce: { economicCommittee },
},
}) => {
console.log('fraz startNewEconomicCommittee');

const COMMITTEES_ROOT = 'committees';
trace('startNewEconomicCommittee');
const { committeeName } = runConfig;
Expand All @@ -166,8 +187,9 @@ const startNewEconomicCommittee = async ({
// NB: committee must only publish what it intended to be public
const marshaller = await E(board).getPublishingMarshaller();

trace('Starting new EC Committee Instance');
const { instance, creatorFacet } = await E(zoe).startInstance(
committee, // aka electorate
committee,
{},
{ committeeName, committeeSize },
{
Expand All @@ -176,13 +198,13 @@ const startNewEconomicCommittee = async ({
},
'economicCommittee',
);
trace('Started new EC Committee Instance Successfully');

const newPoserInvitationP = E(creatorFacet).getPoserInvitation();

economicCommittee.reset();
economicCommittee.resolve(instance);

// reset because it's already been resolved
economicCommitteeCreatorFacet.reset();
economicCommitteeCreatorFacet.resolve(creatorFacet);
return newPoserInvitationP;
Expand All @@ -207,95 +229,43 @@ const startNewEconCharter = async ({
binaryVoteCounterInstallation: counterInstall,
});

const startResult = E(zoe).startInstance(
trace('Starting new EC Charter Instance');
const startResult = await E(zoe).startInstance(
charterInstall,
undefined,
terms,
undefined,
'econCommitteeCharter',
);
trace('Started new EC Charter Instance Successfully');

instanceP.resolve(E.get(startResult).instance);
econCharterKit.resolve(startResult);
};
harden(startNewEconCharter);

const clearAll = async ({ consume: { econCharterKit } }) => {
console.log('fraz clearAll');
await E(E.get(econCharterKit).creatorFacet).clearInstances();
console.log('fraz after clearing instances');
};
harden(clearAll);

const addGovernorsToEconCharter = async ({
consume: { reserveKit, vaultFactoryKit, econCharterKit, auctioneerKit },
instance: {
consume: { reserve, VaultFactory, auctioneer },
},
}) => {
const { creatorFacet } = E.get(econCharterKit);

await Promise.all(
[
{
label: 'reserve',
instanceP: reserve,
facetP: E.get(reserveKit).governorCreatorFacet,
},
{
label: 'VaultFactory',
instanceP: VaultFactory,
facetP: E.get(vaultFactoryKit).governorCreatorFacet,
},
{
label: 'auctioneer',
instanceP: auctioneer,
facetP: E.get(auctioneerKit).governorCreatorFacet,
},
].map(async ({ label, instanceP, facetP }) => {
const [instance, govFacet] = await Promise.all([instanceP, facetP]);

return E(creatorFacet).addInstance(instance, govFacet, label);
}),
);
};

harden(addGovernorsToEconCharter);

const main = async permittedPowers => {
// console.log("fraz in main")
// await addGovernorsToEconCharter(permittedPowers)
console.log('fraz before startNewEconomicCommittee');
const newElectoratePoser = await startNewEconomicCommittee(permittedPowers);

await startNewEconCharter(permittedPowers);
/*
* put the new economic committee into agoricNames
*/

/*
* tell all the PSM contracts about it
*/
const psmKitMap = await permittedPowers.consume.psmKit;
// TODO make sure new PSMs get this committee (using ".reset" in the space?)
const replacements = [...psmKitMap.values()].map(psmKit =>
E(psmKit.psmGovernorCreatorFacet).replaceElectorate(newElectoratePoser),
);
await Promise.all(replacements);

/*
* use economicCommitteeCreatorFacet in the space to invite those commitee members
*/
await invitePSMCommitteeMembers(permittedPowers, {
options: { voterAddresses: runConfig.economicCommitteeAddresses },
});

// somethign with the PSM charter?

/*
* tell the provisionPool contract about it
*/

// done
console.log('installed new economic committee');
trace('Installed New Economic Committee');
};

/**
Expand Down

0 comments on commit 189a18e

Please sign in to comment.