Skip to content

Commit

Permalink
chore(run-protocol): write 2 proposals: econ-committee, main
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Apr 25, 2022
1 parent 0bce9e3 commit 9e7e729
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 120 deletions.
217 changes: 119 additions & 98 deletions packages/run-protocol/scripts/init-core.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
/* global process */
// @ts-check
import { E } from '@endo/far';
import { makeHelpers } from '@agoric/deploy-script-support';

import { getCopyMapEntries, makeCopyMap } from '@agoric/store';
import {
getManifestForRunProtocol,
getManifestForEconCommittee,
getManifestForMain,
getManifestForRunStake,
getManifestForPSM,
} from '../src/core-proposal.js';

const { details: X } = assert;
/** @type {<T>(store: any, key: string, make: () => T) => Promise<T>} */
const provide = async (store, key, make) => {
const found = await E(store).get(key);
if (found) {
return found;
}
const value = make();
await E(store).set(key, value);
return value;
};

/** @type {Record<string, Record<string, [string, string]>>} */
const installKeyGroups = {
econCommittee: {
contractGovernor: [
'@agoric/governance/src/contractGovernor.js',
'../bundles/bundle-contractGovernor.js',
'../../governance/bundles/bundle-contractGovernor.js',
],
committee: [
'@agoric/governance/src/committee.js',
'../bundles/bundle-committee.js',
'../../governance/bundles/bundle-committee.js',
],
binaryVoteCounter: [
'@agoric/governance/src/binaryVoteCounter.js',
'../bundles/bundle-binaryVoteCounter.js',
'../../governance/bundles/bundle-binaryVoteCounter.js',
],
},
runStake: {
Expand All @@ -48,6 +57,10 @@ const installKeyGroups = {
},
psm: {
psm: ['../src/psm/psm.js', '../bundles/bundle-psm.js'],
mintHolder: [
'@agoric/vats/src/mintHolder.js',
'../../vats/bundles/bundle-mintHolder.js',
],
},
};

Expand All @@ -58,95 +71,107 @@ const mapValues = (obj, f) =>
// @ts-ignore entries() loses the K type
harden(fromEntries(entries(obj).map(([p, v]) => [p, f(v)])));

const committeeProposalBuilder = async ({ publishRef, install }) => {
const { ROLE = 'chain' } = process.env;

// preload ERTP, marshal, store, etc.
const [mod0, bundle0] = installKeyGroups.econCommittee.binaryVoteCounter;
const install0 = await install(mod0, bundle0, { persist: true });

/** @param { Record<string, [string, string]> } group */
const publishGroup = group =>
mapValues(group, ([mod, bundle]) =>
publishRef(
mod === mod0 && bundle === bundle0 ? install0 : install(mod, bundle),
),
const makeTool = async (homeP, installCacheKey = 'installCache') => {
/** @type {CopyMap<string, {installation: Installation, boardId: string, path?: string}>} */
const initial = await provide(E.get(homeP).scratch, installCacheKey, () =>
makeCopyMap([]),
);
// ISSUE: getCopyMapEntries of CopyMap<K, V> loses K, V.
/** @type {Map<string, {installation: Installation, boardId: string, path?: string}>} */
const working = new Map(getCopyMapEntries(initial));

const saveCache = async () => {
const final = makeCopyMap(working);
assert.equal(final.payload.keys.length, working.size);
await E(E.get(homeP).scratch).set('installCache', final);
console.log({
initial: initial.payload.keys.length,
total: working.size,
});
};

const wrapInstall = install => async (mPath, bPath, opts) => {
const { endoZipBase64Sha512: sha512 } = await import(bPath).then(
m => m.default,
);
return harden({
sourceSpec: '../src/core-proposal.js',
getManifestCall: [
getManifestForEconCommittee.name,
{
ROLE,
installKeys: {
...publishGroup(installKeyGroups.econCommittee),
},
},
],
});
};

const mainProposalBuilder = async ({ publishRef, install }) => {
const { ROLE = 'chain', VAULT_FACTORY_CONTROLLER_ADDR } = process.env;

/** @param { Record<string, [string, string]> } group */
const publishGroup = group =>
mapValues(group, ([mod, bundle]) => publishRef(install(mod, bundle)));
return harden({
sourceSpec: '../src/core-proposal.js',
getManifestCall: [
getManifestForMain.name,
{
ROLE,
vaultFactoryControllerAddress: VAULT_FACTORY_CONTROLLER_ADDR,
installKeys: {
...publishGroup(installKeyGroups.main),
const detail = await provide(working, sha512, () =>
install(mPath, bPath, opts).then(installation => ({
installation,
sha512,
path: bPath,
})),
);
return detail.installation;
};

const committeeProposalBuilder = async ({
publishRef,
install: install0,
}) => {
const { ROLE = 'chain' } = process.env;

const install = wrapInstall(install0);

/** @param { Record<string, [string, string]> } group */
const publishGroup = group =>
mapValues(group, ([mod, bundle]) =>
publishRef(install(mod, bundle, { persist: true })),
);
return harden({
sourceSpec: '../src/core-proposal.js',
getManifestCall: [
getManifestForEconCommittee.name,
{
ROLE,
installKeys: {
...publishGroup(installKeyGroups.econCommittee),
},
},
},
],
});
};

const runStakeProposalBuilder = async ({ publishRef, install }) => {
const [mod0, bundle0] = installKeyGroups.runStake.runStake;

return harden({
sourceSpec: '../src/core-proposal.js',
getManifestCall: [
getManifestForRunStake.name,
{
installKeys: {
runStake: publishRef(install(mod0, bundle0)),
],
});
};

const mainProposalBuilder = async ({ publishRef, install: install0 }) => {
const {
ROLE = 'chain',
VAULT_FACTORY_CONTROLLER_ADDR,
ANCHOR_DENOM,
} = process.env;

const install = wrapInstall(install0);

const persist = true;
/** @param { Record<string, [string, string]> } group */
const publishGroup = group =>
mapValues(group, ([mod, bundle]) =>
publishRef(install(mod, bundle, { persist })),
);
return harden({
sourceSpec: '../src/core-proposal.js',
getManifestCall: [
getManifestForMain.name,
{
ROLE,
vaultFactoryControllerAddress: VAULT_FACTORY_CONTROLLER_ADDR,
installKeys: {
...publishGroup(installKeyGroups.main),
...publishGroup(installKeyGroups.runStake),
...(ANCHOR_DENOM ? publishGroup(installKeyGroups.psm) : {}),
},
},
},
],
});
};

const psmProposalBuilder = async ({ publishRef, install }) => {
const { ROLE = 'chain', ANCHOR_DENOM } = process.env;

assert.typeof(ANCHOR_DENOM, 'string', X`missing ANCHOR_DENOM`);
const [mod0, bundle0] = installKeyGroups.psm.psm;

return harden({
sourceSpec: '../src/core-proposal.js',
getManifestCall: [
getManifestForPSM.name,
{
ROLE,
installKeys: {
psm: publishRef(install(mod0, bundle0)),
},
},
],
options: { denom: ANCHOR_DENOM },
});
],
});
};
return { committeeProposalBuilder, mainProposalBuilder, saveCache };
};

// Build proposal for sim-chain etc.
export const defaultProposalBuilder = async ({ publishRef, install }) => {
const { ROLE = 'chain', VAULT_FACTORY_CONTROLLER_ADDR } = process.env;
const {
ROLE = 'chain',
VAULT_FACTORY_CONTROLLER_ADDR,
ANCHOR_DENOM,
} = process.env;

/** @param { Record<string, [string, string]> } group */
const publishGroup = group =>
Expand All @@ -159,11 +184,12 @@ export const defaultProposalBuilder = async ({ publishRef, install }) => {
{
ROLE,
vaultFactoryControllerAddress: VAULT_FACTORY_CONTROLLER_ADDR,
anchorDenom: ANCHOR_DENOM,
installKeys: {
...publishGroup(installKeyGroups.econCommittee),
...publishGroup(installKeyGroups.runStake),
...publishGroup(installKeyGroups.main),
...publishGroup(installKeyGroups.psm),
...(ANCHOR_DENOM ? publishGroup(installKeyGroups.psm) : {}),
},
},
],
Expand All @@ -173,15 +199,10 @@ export const defaultProposalBuilder = async ({ publishRef, install }) => {
export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);

const tool = await makeTool(homeP);
await Promise.all([
writeCoreProposal('gov-econ-committee', committeeProposalBuilder),
writeCoreProposal('gov-runStake', runStakeProposalBuilder),
writeCoreProposal('gov-amm-vaults-etc', mainProposalBuilder),
writeCoreProposal('gov-econ-committee', tool.committeeProposalBuilder),
writeCoreProposal('gov-amm-vaults-etc', tool.mainProposalBuilder),
]);

if (!process.env.ANCHOR_DENOM) {
console.warn('SKIP psm proposal: missing ANCHOR_DENOM');
return;
}
await writeCoreProposal('gov-psm', psmProposalBuilder);
await tool.saveCache();
};
27 changes: 5 additions & 22 deletions packages/run-protocol/src/core-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const getManifestForEconCommittee = (

export const getManifestForMain = (
{ restoreRef },
{ installKeys, vaultFactoryControllerAddress },
{ installKeys, vaultFactoryControllerAddress, anchorDenom },
) => {
return {
manifest: MAIN_MANIFEST,
Expand All @@ -319,30 +319,13 @@ export const getManifestForMain = (
VaultFactory: restoreRef(installKeys.vaultFactory),
liquidate: restoreRef(installKeys.liquidate),
reserve: restoreRef(installKeys.reserve),
},
options: {
vaultFactoryControllerAddress,
},
};
};

export const getManifestForRunStake = ({ restoreRef }, { installKeys }) => {
return {
manifest: RUN_STAKE_MANIFEST,
installations: {
runStake: restoreRef(installKeys.runStake),
},
};
};

export const getManifestForPSM = ({ restoreRef }, { installKeys, denom }) => {
return {
manifest: PSM_MANIFEST,
installations: {
psm: restoreRef(installKeys.psm),
// psm: restoreRef(installKeys.psm),
// mintHolder: restoreRef(installKeys.mintHolder),
},
options: {
denom,
vaultFactoryControllerAddress,
denom: anchorDenom,
},
};
};

0 comments on commit 9e7e729

Please sign in to comment.