Skip to content

Commit

Permalink
refactor: use restoreRef() in manifests to install bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris-Hibbert committed Oct 4, 2024
1 parent 5764b1e commit 7b9e75f
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 114 deletions.
17 changes: 17 additions & 0 deletions packages/boot/test/bootstrapTests/price-feed-replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ test.serial('setupVaults; run replace-price-feeds proposals', async t => {
const SOME_GUI = 'someGUIHASH';
await updateVaultDirectorParams(t, gd, SOME_GUI);

const { EV } = t.context.runUtils;
const agoricNames = await EV.vat('bootstrap').consumeItem('agoricNames');
const oldVaultInstallation = await EV(agoricNames).lookup(
'installation',
'VaultFactory',
);

t.log('building all relevant CoreEvals');
const coreEvals = await Promise.all([
buildProposal(priceFeedBuilder, ['UNRELEASED_main']),
Expand All @@ -99,6 +106,16 @@ test.serial('setupVaults; run replace-price-feeds proposals', async t => {
t.not(instancePre, instancePost);

await priceFeedDrivers[collateralBrandKey].refreshInvitations();

const newVaultInstallation = await EV(agoricNames).lookup(
'installation',
'VaultFactory',
);

t.notDeepEqual(
newVaultInstallation.getKref(),
oldVaultInstallation.getKref(),
);
});

test.serial('1. place bid', async t => {
Expand Down
14 changes: 13 additions & 1 deletion packages/boot/test/bootstrapTests/vaults-upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,16 @@ test.serial('restart vaultFactory', async t => {
const vaultFactoryKit =
await EV.vat('bootstrap').consumeItem('vaultFactoryKit');

const reserveKit = await EV.vat('bootstrap').consumeItem('reserveKit');
const bootstrapVat = EV.vat('bootstrap');
const reserveKit = await bootstrapVat.consumeItem('reserveKit');
const electorateCreatorFacet = await bootstrapVat.consumeItem(
'economicCommitteeCreatorFacet',
);
const agoricNames = await EV.vat('bootstrap').consumeItem('agoricNames');
const oldVaultInstallation = await EV(agoricNames).lookup(
'installation',
'VaultFactory',
);

const poserInvitation = await EV(electorateCreatorFacet).getPoserInvitation();
const creatorFacet1 = await EV.get(reserveKit).creatorFacet;
Expand Down Expand Up @@ -319,6 +324,13 @@ test.serial('restart vaultFactory', async t => {
const upgradeResult = await EV(vfAdminFacet).restartContract(privateArgs);
t.deepEqual(upgradeResult, { incarnationNumber: 1 });
t.like(readCollateralMetrics(0), keyMetrics); // unchanged

const newVaultInstallation = await EV(agoricNames).lookup(
'installation',
'VaultFactory',
);

t.notDeepEqual(newVaultInstallation, oldVaultInstallation);
});

test.serial('restart contractGovernor', async t => {
Expand Down
4 changes: 2 additions & 2 deletions packages/builders/scripts/vats/add-auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const defaultProposalBuilder = async ({ publishRef, install }) => {
getManifestCall: [
'getManifestForAddAuction',
{
auctionsRef: publishRef(
auctioneerRef: publishRef(
install(
'@agoric/inter-protocol/src/auction/auctioneer.js',
'../../inter-protocol/bundles/bundle-auctioneer.js',
),
),
governorRef: publishRef(
contractGovernorRef: publishRef(
install(
'@agoric/governance/src/contractGovernor.js',
'../bundles/bundle-contractGovernor.js',
Expand Down
4 changes: 2 additions & 2 deletions packages/builders/scripts/vats/upgradeVaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const defaultProposalBuilder = async ({ publishRef, install }) =>
getManifestCall: [
'getManifestForUpgradeVaults',
{
vaultsRef: publishRef(
VaultFactoryRef: publishRef(
install(
'@agoric/inter-protocol/src/vaultFactory/vaultFactory.js',
'../bundles/bundle-vaultFactory.js',
),
),
governorRef: publishRef(
contractGovernorRef: publishRef(
install(
'@agoric/governance/src/contractGovernor.js',
'../bundles/bundle-contractGovernor.js',
Expand Down
1 change: 1 addition & 0 deletions packages/deploy-script-support/src/coreProposalBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const makeCoreProposalBehavior = ({
const installAdmin = E(agoricNamesAdmin).lookupAdmin('installation');
await Promise.all(
installationEntries.map(([key, value]) => {
produceInstallations[key].reset();
produceInstallations[key].resolve(value);
return E(installAdmin).update(key, value);
}),
Expand Down
120 changes: 53 additions & 67 deletions packages/inter-protocol/src/proposals/add-auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,52 @@ const trace = makeTracer('NewAuction', true);
/**
* @param {import('./econ-behaviors.js').EconomyBootstrapPowers &
* interlockPowers} powers
* @param {{
* options: {
* auctionsRef: { bundleID: string };
* governorRef: { bundleID: string };
* };
* }} options
*/
export const addAuction = async (
{
export const addAuction = async ({
consume: {
agoricNamesAdmin,
auctioneerKit: legacyKitP,
board,
chainStorage,
chainTimerService,
economicCommitteeCreatorFacet: electorateCreatorFacet,
econCharterKit,
priceAuthority8400,
zoe,
},
produce: { auctioneerKit: produceAuctioneerKit, auctionUpgradeNewInstance },
instance: {
consume: { reserve: reserveInstance },
produce: { auctioneer: auctionInstance },
},
installation: {
consume: {
agoricNamesAdmin,
auctioneerKit: legacyKitP,
board,
chainStorage,
chainTimerService,
economicCommitteeCreatorFacet: electorateCreatorFacet,
econCharterKit,
priceAuthority8400,
zoe,
},
produce: { auctioneerKit: produceAuctioneerKit, auctionUpgradeNewInstance },
instance: {
consume: { reserve: reserveInstance },
produce: { auctioneer: auctionInstance },
},
installation: {
produce: {
auctioneer: produceAuctionInstallation,
contractGovernor: produceGovernorInstallation,
},
},
issuer: {
consume: { [Stable.symbol]: stableIssuerP },
auctioneer: auctioneerInstallationP,
contractGovernor: governorInstallationP,
},
},
{ options },
) => {
trace('addAuction start', options);
issuer: {
consume: { [Stable.symbol]: stableIssuerP },
},
}) => {
trace('addAuction start');
const STORAGE_PATH = 'auction';
const { auctionsRef, governorRef } = options;

const poserInvitationP = E(electorateCreatorFacet).getPoserInvitation();
const auctioneerBundleID = auctionsRef.bundleID;
const governorBundleID = governorRef.bundleID;
/**
* @type {Promise<
* Installation<import('../../src/auction/auctioneer.js')['start']>
* >}
*/
const auctioneerInstallationP = E(zoe).installBundleID(auctioneerBundleID);
const governorInstallationP = E(zoe).installBundleID(governorBundleID);
produceAuctionInstallation.reset();
produceAuctionInstallation.resolve(auctioneerInstallationP);
produceGovernorInstallation.reset();
produceGovernorInstallation.resolve(governorInstallationP);
const [
initialPoserInvitation,
electorateInvitationAmount,
stableIssuer,
legacyKit,
auctioneerInstallation,
governorInstallation,
] = await Promise.all([
poserInvitationP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
stableIssuerP,
legacyKitP,
auctioneerInstallationP,
governorInstallationP,
]);

// Each field has an extra layer of type + value:
Expand Down Expand Up @@ -114,11 +95,6 @@ export const addAuction = async (
},
);

const [auctioneerInstallation, governorInstallation] = await Promise.all([
auctioneerInstallationP,
governorInstallationP,
]);

const governorTerms = await deeplyFulfilledObject(
harden({
timer: chainTimerService,
Expand Down Expand Up @@ -149,12 +125,17 @@ export const addAuction = async (
'auctioneer.governor',
);

const [governedInstance, governedCreatorFacet, governedPublicFacet] =
await Promise.all([
E(governorStartResult.creatorFacet).getInstance(),
E(governorStartResult.creatorFacet).getCreatorFacet(),
E(governorStartResult.creatorFacet).getPublicFacet(),
]);
const [
governedInstance,
governedCreatorFacet,
governedPublicFacet,
governedAdminFacet,
] = await Promise.all([
E(governorStartResult.creatorFacet).getInstance(),
E(governorStartResult.creatorFacet).getCreatorFacet(),
E(governorStartResult.creatorFacet).getPublicFacet(),
E(governorStartResult.creatorFacet).getAdminFacet(),
]);

const allIssuers = await E(zoe).getIssuers(legacyKit.instance);
const { Bid: _istIssuer, ...auctionIssuers } = allIssuers;
Expand All @@ -170,7 +151,7 @@ export const addAuction = async (
const kit = harden({
label: 'auctioneer',
creatorFacet: governedCreatorFacet,
adminFacet: governorStartResult.adminFacet,
adminFacet: governedAdminFacet,
publicFacet: governedPublicFacet,
instance: governedInstance,

Expand Down Expand Up @@ -222,10 +203,7 @@ export const ADD_AUCTION_MANIFEST = harden({
produce: { auctioneer: true },
},
installation: {
consume: {
contractGovernor: true,
},
produce: { auctioneer: true },
consume: { contractGovernor: true, auctioneer: true },
},
issuer: {
consume: { [Stable.symbol]: true },
Expand All @@ -236,12 +214,20 @@ export const ADD_AUCTION_MANIFEST = harden({
/**
* Add a new auction to a chain that already has one.
*
* @param {object} _ign
* @param {object} utils
* @param {any} utils.restoreRef
* @param {any} addAuctionOptions
*/
export const getManifestForAddAuction = async (_ign, addAuctionOptions) => {
export const getManifestForAddAuction = async (
{ restoreRef },
{ auctioneerRef, contractGovernorRef },
) => {
return {
manifest: ADD_AUCTION_MANIFEST,
options: addAuctionOptions,
options: { auctioneerRef, contractGovernorRef },
installations: {
auctioneer: restoreRef(auctioneerRef),
contractGovernor: restoreRef(contractGovernorRef),
},
};
};
Loading

0 comments on commit 7b9e75f

Please sign in to comment.