Skip to content

Commit

Permalink
fix(provisionPool): refactor contract to allow overriding governed pa…
Browse files Browse the repository at this point in the history
…rameter

rel #10562
  • Loading branch information
Jorge-Lopes committed Nov 28, 2024
1 parent 1dd4589 commit 989a16b
Showing 1 changed file with 58 additions and 25 deletions.
83 changes: 58 additions & 25 deletions packages/inter-protocol/src/provisionPool.js
Original file line number Diff line number Diff line change
@@ -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'; */

Expand Down Expand Up @@ -49,6 +50,7 @@ harden(meta);
* storageNode: StorageNode;
* marshaller: Marshal<any>;
* metricsOverride?: import('./provisionPoolKit.js').MetricsNotification;
* governedParamOverrides?: any;
* }} privateArgs
* @param {import('@agoric/vat-data').Baggage} baggage
*/
Expand All @@ -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<GovernanceSubscriptionState>} */
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,
Expand Down Expand Up @@ -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,
});
};
Expand Down

0 comments on commit 989a16b

Please sign in to comment.