Skip to content

Commit

Permalink
feat(run-protocol): runStake, PSM bootstrap
Browse files Browse the repository at this point in the history
 - refactor: prepare to break init-core into parts
 - separate proposal for startEconomicCommittee
 - separate core proposals for psm, runStake
 - avoid duplicate installation
 - omit PSM proposal unless ANCHOR_DENOM is set
 - makeAnchorAsset for PSM bootstrap
 - connect lienBridge to runStake
  • Loading branch information
dckc committed Apr 21, 2022
1 parent 5ed4df3 commit 840782a
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 68 deletions.
1 change: 1 addition & 0 deletions packages/run-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"scripts": {
"build": "yarn build:bundles",
"build:bundles": "node ./scripts/build-bundles.js",
"deploy:proposal": "agoric deploy ./scripts/init-core.js",
"test": "ava",
"test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js",
"test:xs": "exit 0",
Expand Down
218 changes: 165 additions & 53 deletions packages/run-protocol/scripts/init-core.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,169 @@
/* global process */
// @ts-check
import { makeHelpers } from '@agoric/deploy-script-support';

import {
getManifestForRunProtocol,
getManifestForEconCommittee,
getManifestForMain,
getManifestForRunStake,
getManifestForPSM,
} from '../src/core-proposal.js';

const { details: X } = assert;

/** @type {Record<string, Record<string, [string, string]>>} */
const installKeyGroups = {
econCommittee: {
contractGovernor: [
'@agoric/governance/src/contractGovernor.js',
'../bundles/bundle-contractGovernor.js',
],
committee: [
'@agoric/governance/src/committee.js',
'../bundles/bundle-committee.js',
],
binaryVoteCounter: [
'@agoric/governance/src/binaryVoteCounter.js',
'../bundles/bundle-binaryVoteCounter.js',
],
},
runStake: {
runStake: ['../src/runStake/runStake.js', '../bundles/bundle-runStake.js'],
},
main: {
amm: [
'../src/vpool-xyk-amm/multipoolMarketMaker.js',
'../bundles/bundle-amm.js',
],
vaultFactory: [
'../src/vaultFactory/vaultFactory.js',
'../bundles/bundle-vaultFactory.js',
],
liquidate: [
'../src/vaultFactory/liquidateMinimum.js',
'../bundles/bundle-liquidateMinimum.js',
],
reserve: ['../src/reserve/assetReserve.js', '../bundles/bundle-reserve.js'],
},
psm: {
psm: ['../src/psm/psm.js', '../bundles/bundle-psm.js'],
},
};

const { entries, fromEntries } = Object;

/** @type { <K extends string, T, U>(obj: Record<K, T>, f: (t: T) => U) => Record<K, U>} */
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),
),
);
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 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 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 },
});
};

// Build proposal for sim-chain etc.
export const defaultProposalBuilder = 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: [
'getManifestForRunProtocol',
getManifestForRunProtocol.name,
{
ROLE,
vaultFactoryControllerAddress: VAULT_FACTORY_CONTROLLER_ADDR,
installKeys: {
runStake: publishRef(
install(
'../src/runStake/runStake.js',
'../bundles/bundle-runStake.js',
),
),
amm: publishRef(
install(
'../src/vpool-xyk-amm/multipoolMarketMaker.js',
'../bundles/bundle-amm.js',
),
),
vaultFactory: publishRef(
install(
'../src/vaultFactory/vaultFactory.js',
'../bundles/bundle-vaultFactory.js',
),
),
liquidate: publishRef(
install(
'../src/vaultFactory/liquidateMinimum.js',
'../bundles/bundle-liquidateMinimum.js',
),
),
reserve: publishRef(
install(
'../src/reserve/assetReserve.js',
'../bundles/bundle-reserve.js',
),
),
psm: publishRef(
install('../src/psm/psm.js', '../bundles/bundle-psm.js'),
),
contractGovernor: publishRef(
install(
'@agoric/governance/src/contractGovernor.js',
'../bundles/bundle-contractGovernor.js',
),
),
committee: publishRef(
install(
'@agoric/governance/src/committee.js',
'../bundles/bundle-committee.js',
),
),
binaryVoteCounter: publishRef(
install(
'@agoric/governance/src/binaryVoteCounter.js',
'../bundles/bundle-binaryVoteCounter.js',
),
),
...publishGroup(installKeyGroups.econCommittee),
...publishGroup(installKeyGroups.runStake),
...publishGroup(installKeyGroups.main),
...publishGroup(installKeyGroups.psm),
},
},
],
Expand All @@ -71,5 +172,16 @@ export const defaultProposalBuilder = async ({ publishRef, install }) => {

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('gov-run-protocol', defaultProposalBuilder);

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

if (!process.env.ANCHOR_DENOM) {
console.warn('SKIP psm proposal: missing ANCHOR_DENOM');
return;
}
await writeCoreProposal('gov-psm', psmProposalBuilder);
};
Loading

0 comments on commit 840782a

Please sign in to comment.