Skip to content

Commit

Permalink
feat(vats): start VaultFactory in core bootstrap
Browse files Browse the repository at this point in the history
 - keep governanceActions separate from bootstrapManifest
 - put board in the workspace
 - flesh out makeAddressNameHubs with agoricNames and such
  • Loading branch information
dckc authored and michaelfig committed Jan 16, 2022
1 parent 04372d9 commit 8d56eaf
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 23 deletions.
125 changes: 115 additions & 10 deletions packages/vats/src/bootstrap-behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import { E, Far } from '@agoric/far';
import { AssetKind } from '@agoric/ertp';
import { makeNotifierKit } from '@agoric/notifier';
import { installOnChain as installVaultFactoryOnChain } from '@agoric/run-protocol/bundles/install-on-chain.js';

import { makeStore } from '@agoric/store';
import { makeNameHubKit } from './nameHub';

const { entries, fromEntries } = Object;
Expand Down Expand Up @@ -33,10 +36,11 @@ export const bootstrapManifest = harden({
},
makeBoard: {
consume: { loadVat: true, client: true },
produce: { board: true },
},
makeAddressNameHubs: {
consume: { client: true },
produce: { agoricNamesAdmin: true },
produce: { agoricNames: true, agoricNamesAdmin: true, nameAdmins: true },
},
makeClientBanks: {
consume: {
Expand All @@ -48,6 +52,21 @@ export const bootstrapManifest = harden({
},
});

export const governanceActions = harden({
startVaultFactory: {
devices: { timer: true },
vats: { timer: true },
consume: {
agoricNames: true,
nameAdmins: true,
board: true,
loadVat: true,
zoe: true,
feeMintAccess: true,
},
},
});

/**
* @param {{
* vatPowers: { D: EProxy }, // D type is approximate
Expand Down Expand Up @@ -82,6 +101,7 @@ const makeVatsFromBundles = ({
const svc = E(vats.vatAdmin).createVatAdminService(devices.vatAdmin);
vatAdminSvc.resolve(svc);
// TODO: getVat? do we need to memoize this by name?
// TODO: rename loadVat to createVatByName?
loadVat.resolve(bundleName => {
console.info(`createVatByName(${bundleName})`);
const root = E(svc)
Expand Down Expand Up @@ -117,34 +137,65 @@ const buildZoe = async ({
};

/**
* TODO: rename this to getBoard?
*
* @param {{
* consume: { loadVat: ERef<VatLoader<BoardVat>>, client: ERef<ClientConfig> }
* consume: { loadVat: ERef<VatLoader<BoardVat>>, client: ERef<ClientConfig> },
* produce: { board: Producer<ERef<Board>> },
* }} powers
* @typedef {ERef<ReturnType<import('./vat-board').buildRootObject>>} BoardVat
*/
const makeBoard = async ({ consume: { loadVat, client } }) => {
const makeBoard = async ({
consume: { loadVat, client },
produce: {
board: { resolve: resolveBoard },
},
}) => {
const board = E(E(loadVat)('board')).getBoard();
resolveBoard(board);
return E(client).assignBundle({ board: _addr => board });
};

/**
* @param {{
* consume: { client: ERef<ClientConfig> },
* produce: { agoricNamesAdmin: Producer<NameAdmin> },
* produce: {
* agoricNames: Producer<NameHub>,
* agoricNamesAdmin: Producer<NameAdmin>,
* nameAdmins: Producer<Store<NameHub, NameAdmin>>,
* },
* }} powers
*/
const makeAddressNameHubs = async ({
consume: { client },
produce: { agoricNamesAdmin },
}) => {
const { nameHub: agoricNames, nameAdmin } = makeNameHubKit();
agoricNamesAdmin.resolve(nameAdmin);
const makeAddressNameHubs = async ({ consume: { client }, produce }) => {
const {
nameHub: agoricNames,
nameAdmin: agoricNamesAdmin,
} = makeNameHubKit();
produce.agoricNames.resolve(agoricNames);
produce.agoricNamesAdmin.resolve(agoricNamesAdmin);

const {
nameHub: namesByAddress,
nameAdmin: namesByAddressAdmin,
} = makeNameHubKit();

/** @type {Store<NameHub, NameAdmin>} */
const nameAdmins = makeStore('nameHub');
await Promise.all(
['brand', 'installation', 'issuer', 'instance', 'uiConfig'].map(
async nm => {
const { nameHub, nameAdmin } = makeNameHubKit();
await E(agoricNamesAdmin).update(nm, nameHub);
nameAdmins.init(nameHub, nameAdmin);
if (nm === 'uiConfig') {
// Reserve the Vault Factory's config until we've populated it.
nameAdmin.reserve('vaultFactory');
}
},
),
);
produce.nameAdmins.resolve(nameAdmins);

const perAddress = address => {
// Create a name hub for this address.
const {
Expand Down Expand Up @@ -234,6 +285,58 @@ const makeClientBanks = async ({
});
};

/**
* @param {{
* devices: { timer: unknown },
* vats: { timer: TimerVat },
* consume: {
* agoricNames: ERef<NameHub>,
* nameAdmins: ERef<Store<NameHub, NameAdmin>>,
* board: ERef<Board>,
* loadVat: ERef<VatLoader<unknown>>,
* zoe: ERef<ZoeService>,
* feeMintAccess: ERef<FeeMintAccess>,
* }
* }} powers
*/
const startVaultFactory = async ({
devices: { timer: timerDevice },
vats: { timer: timerVat },
consume: {
agoricNames,
nameAdmins: nameAdminsP,
board,
loadVat,
zoe,
feeMintAccess: feeMintAccessP,
},
}) => {
// TODO: Zoe should accept a promise, since the value is in that vat.
const [feeMintAccess, nameAdmins] = await Promise.all([
feeMintAccessP,
nameAdminsP,
]);

const chainTimerService = E(timerVat).createTimerService(timerDevice);

/** @typedef { any } PriceAuthorityVat todo */
const { priceAuthority, adminFacet: priceAuthorityAdmin } = await E(
/** @type { PriceAuthorityVat } */ (E(loadVat)('priceAuthority')),
).makePriceAuthority();

return installVaultFactoryOnChain({
agoricNames,
board,
centralName: CENTRAL_ISSUER_NAME,
chainTimerService,
nameAdmins,
priceAuthority,
zoe,
bootstrapPaymentValue: 0n, // TODO: this is obsolete, right?
feeMintAccess,
});
};

harden({
connectVattpWithMailbox,
makeVatsFromBundles,
Expand All @@ -242,6 +345,7 @@ harden({
makeAddressNameHubs,
installClientEgress,
makeClientBanks,
startVaultFactory,
});
export {
connectVattpWithMailbox,
Expand All @@ -251,4 +355,5 @@ export {
makeAddressNameHubs,
installClientEgress,
makeClientBanks,
startVaultFactory,
};
27 changes: 15 additions & 12 deletions packages/vats/src/bootstrap-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Far } from '@agoric/far';
import { makePromiseKit } from '@agoric/promise-kit';
// TODO: choose sim behaviors based on runtime config
import * as behaviors from './bootstrap-behaviors-sim.js';
import { governanceActions } from './bootstrap-behaviors.js';
import { simBootstrapManifest } from './bootstrap-behaviors-sim.js';

const { entries, fromEntries } = Object;
Expand Down Expand Up @@ -109,23 +110,25 @@ const buildRootObject = (vatPowers, vatParameters) => {
* @param {SwingsetVats} vats
* @param {SwingsetDevices} devices
*/
bootstrap: (vats, devices) =>
Promise.all(
entries(manifest).map(([name, permit]) =>
bootstrap: (vats, devices) => {
const powers = {
vatPowers,
vatParameters,
vats,
devices,
produce,
consume,
};
return Promise.all(
entries({ ...manifest, ...governanceActions }).map(([name, permit]) =>
Promise.resolve().then(() => {
const endowments = extract(permit, {
vatPowers,
vatParameters,
vats,
devices,
produce,
consume,
});
const endowments = extract(permit, powers);
console.info(`bootstrap: ${name}(${q(permit)})`);
return behaviors[name](endowments);
}),
),
),
);
},
});
};

Expand Down
3 changes: 2 additions & 1 deletion packages/vats/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@
* }>} CommsVatRoot
*
* @typedef {{
* vattp: VattpVat,
* comms: CommsVatRoot,
* timer: TimerVat,
* vatAdmin: VatAdminVat,
* vattp: VattpVat,
* }} SwingsetVats
* @typedef {{
* mailbox: MailboxDevice,
Expand Down

0 comments on commit 8d56eaf

Please sign in to comment.