From 7b9e75f6b1bb3bcd271ab8c78786a03786748fd6 Mon Sep 17 00:00:00 2001 From: Chris Hibbert Date: Fri, 4 Oct 2024 10:25:02 -0700 Subject: [PATCH] refactor: use restoreRef() in manifests to install bundles --- .../bootstrapTests/price-feed-replace.test.ts | 17 +++ .../bootstrapTests/vaults-upgrade.test.ts | 14 +- packages/builders/scripts/vats/add-auction.js | 4 +- .../builders/scripts/vats/upgradeVaults.js | 4 +- .../src/coreProposalBehavior.js | 1 + .../src/proposals/add-auction.js | 120 ++++++++---------- .../src/proposals/upgrade-vaults.js | 76 +++++------ 7 files changed, 122 insertions(+), 114 deletions(-) diff --git a/packages/boot/test/bootstrapTests/price-feed-replace.test.ts b/packages/boot/test/bootstrapTests/price-feed-replace.test.ts index b4844fd984f5..df035b00fc90 100644 --- a/packages/boot/test/bootstrapTests/price-feed-replace.test.ts +++ b/packages/boot/test/bootstrapTests/price-feed-replace.test.ts @@ -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']), @@ -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 => { diff --git a/packages/boot/test/bootstrapTests/vaults-upgrade.test.ts b/packages/boot/test/bootstrapTests/vaults-upgrade.test.ts index 4af94865058e..b2de86528550 100644 --- a/packages/boot/test/bootstrapTests/vaults-upgrade.test.ts +++ b/packages/boot/test/bootstrapTests/vaults-upgrade.test.ts @@ -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; @@ -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 => { diff --git a/packages/builders/scripts/vats/add-auction.js b/packages/builders/scripts/vats/add-auction.js index 8616159208d0..034d95cab1b2 100644 --- a/packages/builders/scripts/vats/add-auction.js +++ b/packages/builders/scripts/vats/add-auction.js @@ -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', diff --git a/packages/builders/scripts/vats/upgradeVaults.js b/packages/builders/scripts/vats/upgradeVaults.js index 5b8731b72398..406a59907960 100644 --- a/packages/builders/scripts/vats/upgradeVaults.js +++ b/packages/builders/scripts/vats/upgradeVaults.js @@ -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', diff --git a/packages/deploy-script-support/src/coreProposalBehavior.js b/packages/deploy-script-support/src/coreProposalBehavior.js index 52cb76415416..73272a4f8ca0 100644 --- a/packages/deploy-script-support/src/coreProposalBehavior.js +++ b/packages/deploy-script-support/src/coreProposalBehavior.js @@ -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); }), diff --git a/packages/inter-protocol/src/proposals/add-auction.js b/packages/inter-protocol/src/proposals/add-auction.js index 2f376688f720..29f32c4c4777 100644 --- a/packages/inter-protocol/src/proposals/add-auction.js +++ b/packages/inter-protocol/src/proposals/add-auction.js @@ -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 - * >} - */ - 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: @@ -114,11 +95,6 @@ export const addAuction = async ( }, ); - const [auctioneerInstallation, governorInstallation] = await Promise.all([ - auctioneerInstallationP, - governorInstallationP, - ]); - const governorTerms = await deeplyFulfilledObject( harden({ timer: chainTimerService, @@ -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; @@ -170,7 +151,7 @@ export const addAuction = async ( const kit = harden({ label: 'auctioneer', creatorFacet: governedCreatorFacet, - adminFacet: governorStartResult.adminFacet, + adminFacet: governedAdminFacet, publicFacet: governedPublicFacet, instance: governedInstance, @@ -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 }, @@ -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), + }, }; }; diff --git a/packages/inter-protocol/src/proposals/upgrade-vaults.js b/packages/inter-protocol/src/proposals/upgrade-vaults.js index fa722f8561e6..09b17e436587 100644 --- a/packages/inter-protocol/src/proposals/upgrade-vaults.js +++ b/packages/inter-protocol/src/proposals/upgrade-vaults.js @@ -18,8 +18,8 @@ const trace = makeTracer('upgrade Vaults proposal'); * interlockPowers} powers * @param {{ * options: { - * vaultsRef: { bundleID: string }; - * governorRef: { bundleID: string }; + * VaultFactoryBundle: { bundleID: string }; + * contractGovernorBundle: { bundleID: string }; * }; * }} options */ @@ -35,16 +35,12 @@ export const upgradeVaults = async ( priceAuthority8400, }, produce: { auctionUpgradeNewInstance: auctionUpgradeNewInstanceProducer }, - installation: { - produce: { VaultFactory: produceVaultInstallation }, - }, instance: { consume: { auctioneer: auctioneerInstanceP }, }, }, - { options }, + { options: { VaultFactoryBundle, contractGovernorBundle } }, ) => { - const { vaultsRef, governorRef } = options; const kit = await vaultFactoryKit; const { instance: directorInstance } = kit; const allBrands = await E(zoe).getBrands(directorInstance); @@ -52,17 +48,6 @@ export const upgradeVaults = async ( await priceAuthority8400; - const bundleID = vaultsRef.bundleID; - console.log(`upgradeVaults: bundleId`, bundleID); - /** - * @type {Promise< - * Installation - * >} - */ - const installationP = E(zoe).installBundleID(bundleID); - produceVaultInstallation.reset(); - produceVaultInstallation.resolve(installationP); - const [auctionOldInstance, auctionNewInstance] = await Promise.all([ auctioneerInstanceP, auctionUpgradeNewInstance, @@ -154,7 +139,7 @@ export const upgradeVaults = async ( }); const upgradeResult = await E(kit.adminFacet).upgradeContract( - bundleID, + VaultFactoryBundle.bundleID, newPrivateArgs, ); @@ -169,7 +154,7 @@ export const upgradeVaults = async ( const ecf = await electorateCreatorFacet; // upgrade vaultFactory governor. Won't be needed next time: see #10063 await E(kit.governorAdminFacet).upgradeContract( - governorRef.bundleID, + contractGovernorBundle.bundleID, harden({ electorateCreatorFacet: ecf, governed: vaultFactoryPrivateArgs, @@ -183,30 +168,37 @@ const uV = 'upgradeVaults'; /** * Return the manifest, installations, and options for upgrading Vaults. * - * @param {object} _ign + * @param {object} utils + * @param {any} utils.restoreRef * @param {any} vaultUpgradeOptions */ export const getManifestForUpgradeVaults = async ( - _ign, - vaultUpgradeOptions, -) => ({ - manifest: { - [upgradeVaults.name]: { - consume: { - priceAuthority8400: uV, - auctionUpgradeNewInstance: uV, - chainTimerService: uV, - economicCommitteeCreatorFacet: uV, - reserveKit: uV, - vaultFactoryKit: uV, - zoe: uV, - }, - produce: { auctionUpgradeNewInstance: uV }, - installation: { - produce: { VaultFactory: true }, + { restoreRef }, + { VaultFactoryRef, contractGovernorRef }, +) => { + return { + manifest: { + [upgradeVaults.name]: { + consume: { + priceAuthority8400: uV, + auctionUpgradeNewInstance: uV, + chainTimerService: uV, + economicCommitteeCreatorFacet: uV, + reserveKit: uV, + vaultFactoryKit: uV, + zoe: uV, + }, + produce: { auctionUpgradeNewInstance: uV }, + instance: { consume: { auctioneer: uV } }, }, - instance: { consume: { auctioneer: true } }, }, - }, - options: { ...vaultUpgradeOptions }, -}); + installations: { + VaultFactory: restoreRef(VaultFactoryRef), + contractGovernor: restoreRef(contractGovernorRef), + }, + options: { + VaultFactoryBundle: VaultFactoryRef, + contractGovernorBundle: contractGovernorRef, + }, + }; +};