diff --git a/packages/inter-protocol/src/provisionPool.js b/packages/inter-protocol/src/provisionPool.js index de96cfabaab..010ba421981 100644 --- a/packages/inter-protocol/src/provisionPool.js +++ b/packages/inter-protocol/src/provisionPool.js @@ -1,18 +1,20 @@ // @jessie-check // @ts-check +import { ParamTypes } from '@agoric/governance'; import { - handleParamGovernance, - ParamTypes, - publicMixinAPI, -} from '@agoric/governance'; -import { InvitationShape } from '@agoric/governance/src/typeGuards.js'; + GovernorFacetShape, + InvitationShape, +} from '@agoric/governance/src/typeGuards.js'; +import { Far } from '@endo/marshal'; import { M } from '@agoric/store'; import { prepareExo } from '@agoric/vat-data'; import { provideSingleton } from '@agoric/zoe/src/contractSupport/durability.js'; import { prepareRecorderKitMakers } from '@agoric/zoe/src/contractSupport/recorder.js'; import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/topics.js'; import { makeDurableZone } from '@agoric/zone/durable.js'; +import { makeStoredPublisherKit, SubscriberShape } from '@agoric/notifier'; +import { makeParamManagerFromTerms } from '@agoric/governance/src/contractGovernance/typedParamManager.js'; import { prepareBridgeProvisionTool, prepareProvisionPoolKit, @@ -52,6 +54,7 @@ harden(meta); * initialPoserInvitation: Invitation; * storageNode: StorageNode; * marshaller: Marshal; + * governedParamOverrides?: Record; * metricsOverride?: import('./provisionPoolKit.js').MetricsNotification; * }} privateArgs * @param {import('@agoric/vat-data').Baggage} baggage @@ -64,17 +67,22 @@ export const start = async (zcf, privateArgs, baggage) => { privateArgs.marshaller, ); - // Governance - const { publicMixin, makeDurableGovernorFacet, params } = - await handleParamGovernance( - zcf, - privateArgs.initialPoserInvitation, - { - PerAccountInitialAmount: ParamTypes.AMOUNT, - }, - privateArgs.storageNode, - privateArgs.marshaller, - ); + /** @type {import('@agoric/notifier').StoredPublisherKit} */ + const publisherKit = makeStoredPublisherKit( + privateArgs.storageNode, + privateArgs.marshaller, + 'governance', + ); + const paramManager = makeParamManagerFromTerms( + publisherKit, + zcf, + { Electorate: privateArgs.initialPoserInvitation }, + { + PerAccountInitialAmount: ParamTypes.AMOUNT, + }, + privateArgs.governedParamOverrides, + ); + const params = paramManager.readonly(); const zone = makeDurableZone(baggage); @@ -107,22 +115,37 @@ export const start = async (zcf, privateArgs, baggage) => { M.interface('ProvisionPool', { getMetrics: M.call().returns(M.remotable('MetricsSubscriber')), getPublicTopics: M.call().returns(TopicsRecordShape), - ...publicMixinAPI, + getSubscription: M.call().returns(M.remotable('StoredSubscription')), + getGovernedParams: M.call().returns(M.or(M.record(), M.promise())), + getElectorateSubscription: M.call().returns(SubscriberShape), }), { - getMetrics() { - return provisionPoolKit.public.getPublicTopics().metrics.subscriber; - }, - getPublicTopics() { - return provisionPoolKit.public.getPublicTopics(); - }, - ...publicMixin, + getMetrics: () => + provisionPoolKit.public.getPublicTopics().metrics.subscriber, + getPublicTopics: () => provisionPoolKit.public.getPublicTopics(), + getSubscription: () => paramManager.getSubscription(), + getGovernedParams: () => paramManager.getParams(), + getElectorateSubscription: () => paramManager.getSubscription(), + }, + ); + + const creatorFacet = prepareExo( + baggage, + 'governorFacet', + M.interface('governorFacet', GovernorFacetShape), + { + getParamMgrRetriever: () => + Far('paramRetriever', { get: () => paramManager }), + getInvitation: name => paramManager.getInternalParamValue(name), + getLimitedCreatorFacet: () => provisionPoolKit.machine, + getGovernedApis: () => Far('governedAPIs', {}), + getGovernedApiNames: () => Object.keys({}), + setOfferFilter: strings => zcf.setOfferFilter(strings), }, ); return harden({ - creatorFacet: makeDurableGovernorFacet(baggage, provisionPoolKit.machine) - .governorFacet, + creatorFacet, publicFacet, }); }; diff --git a/packages/vats/src/proposals/upgrade-provisionPool-proposal.js b/packages/vats/src/proposals/upgrade-provisionPool-proposal.js index a94fd6ef418..498447eba3d 100644 --- a/packages/vats/src/proposals/upgrade-provisionPool-proposal.js +++ b/packages/vats/src/proposals/upgrade-provisionPool-proposal.js @@ -2,7 +2,7 @@ import { E } from '@endo/far'; import { deeplyFulfilled } from '@endo/marshal'; import { makeTracer } from '@agoric/internal'; -const tracer = makeTracer('UpgradeProvisionPool'); +const trace = makeTracer('UpgradeProvisionPool'); /** * @param {BootstrapPowers & { @@ -30,7 +30,7 @@ export const upgradeProvisionPool = async ( const { provisionPoolRef } = options.options; assert(provisionPoolRef.bundleID); - tracer(`PROVISION POOL BUNDLE ID: `, provisionPoolRef); + trace(`PROVISION POOL BUNDLE ID: `, provisionPoolRef); const [ provisionPoolStartResult, @@ -45,9 +45,11 @@ export const upgradeProvisionPool = async ( walletFactoryStartResultP, provisionWalletBridgeManagerP, ]); + const { adminFacet, instance, + publicFacet: ppPublicFacet, creatorFacet: ppCreatorFacet, } = provisionPoolStartResult; const { creatorFacet: wfCreatorFacet } = walletFactoryStartResult; @@ -59,9 +61,21 @@ export const upgradeProvisionPool = async ( E(electorateCreatorFacet).getPoserInvitation(), ]); + const readCurrentGovernedParams = async () => { + await null; + + const params = await E(ppPublicFacet).getGovernedParams(); + return harden({ + PerAccountInitialAmount: params.PerAccountInitialAmount.value, + }); + }; + const governedParamOverrides = await readCurrentGovernedParams(); + trace('governedParamOverrides: ', { governedParamOverrides }); + const newPrivateArgs = harden({ ...originalPrivateArgs, initialPoserInvitation: poserInvitation, + governedParamOverrides, }); const upgradeResult = await E(adminFacet).upgradeContract( @@ -69,7 +83,7 @@ export const upgradeProvisionPool = async ( newPrivateArgs, ); - tracer('ProvisionPool upgraded: ', upgradeResult); + trace('ProvisionPool upgraded: ', upgradeResult); const references = { bankManager, @@ -77,17 +91,17 @@ export const upgradeProvisionPool = async ( walletFactory: wfCreatorFacet, }; - tracer('Calling setReferences with: ', references); + trace('Calling setReferences with: ', references); await E(ppCreatorFacet).setReferences(references); - tracer('Creating bridgeHandler...'); + trace('Creating bridgeHandler...'); const bridgeHandler = await E(ppCreatorFacet).makeHandler(); - tracer('Setting new bridgeHandler...'); + trace('Setting new bridgeHandler...'); // @ts-expect-error casting await E(provisionWalletBridgeManager).setHandler(bridgeHandler); - tracer('Done.'); + trace('Done.'); }; export const getManifestForUpgradingProvisionPool = (