From 989a16b89f9c36571a6b7d06c7dc8599610f7efe Mon Sep 17 00:00:00 2001 From: Jorge-Lopes Date: Thu, 28 Nov 2024 12:21:47 +0000 Subject: [PATCH] fix(provisionPool): refactor contract to allow overriding governed parameter rel #10562 --- packages/inter-protocol/src/provisionPool.js | 83 ++++++++++++++------ 1 file changed, 58 insertions(+), 25 deletions(-) diff --git a/packages/inter-protocol/src/provisionPool.js b/packages/inter-protocol/src/provisionPool.js index 7eb37c61dd1..0086e8d374b 100644 --- a/packages/inter-protocol/src/provisionPool.js +++ b/packages/inter-protocol/src/provisionPool.js @@ -1,18 +1,19 @@ // @jessie-check // @ts-check +import { ParamTypes, publicMixinAPI } 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 { 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 { prepareProvisionPoolKit } from './provisionPoolKit.js'; +import { makeStoredPublisherKit, SubscriberShape } from '@agoric/notifier'; +import { makeParamManagerFromTerms } from '@agoric/governance/src/contractGovernance/typedParamManager.js'; /** @import {Marshal} from '@endo/marshal'; */ @@ -49,6 +50,7 @@ harden(meta); * storageNode: StorageNode; * marshaller: Marshal; * metricsOverride?: import('./provisionPoolKit.js').MetricsNotification; + * governedParamOverrides?: any; * }} privateArgs * @param {import('@agoric/vat-data').Baggage} baggage */ @@ -60,17 +62,23 @@ 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 makeProvisionPoolKit = prepareProvisionPoolKit(baggage, { makeRecorderKit, @@ -99,22 +107,47 @@ export const start = async (zcf, privateArgs, baggage) => { M.interface('ProvisionPool', { getMetrics: M.call().returns(M.remotable('MetricsSubscriber')), getPublicTopics: M.call().returns(TopicsRecordShape), + getElectorateSubscription: M.call().returns(SubscriberShape), ...publicMixinAPI, }), { - 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(), + getAmount: paramManager.getAmount, + getBrand: paramManager.getBrand, + getInstance: paramManager.getInstance, + getInstallation: paramManager.getInstallation, + getInvitationAmount: paramManager.getInvitationAmount, + getNat: paramManager.getNat, + getRatio: paramManager.getRatio, + getString: paramManager.getString, + getTimestamp: paramManager.getTimestamp, + getRelativeTime: paramManager.getRelativeTime, + getUnknown: paramManager.getUnknown, + }, + ); + + const governorFacet = 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: governorFacet, publicFacet, }); };