Skip to content

Commit

Permalink
chore(provisionPool): allow overriding governed parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge-Lopes committed Dec 6, 2024
1 parent f564aab commit 266d256
Showing 1 changed file with 55 additions and 26 deletions.
81 changes: 55 additions & 26 deletions packages/inter-protocol/src/provisionPool.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -53,6 +55,7 @@ harden(meta);
* storageNode: StorageNode;
* marshaller: Marshal<any>;
* metricsOverride?: import('./provisionPoolKit.js').MetricsNotification;
* governedParamOverrides?: Record<string, Amount | undefined>;
* }} privateArgs
* @param {import('@agoric/vat-data').Baggage} baggage
*/
Expand All @@ -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<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 zone = makeDurableZone(baggage);

Expand Down Expand Up @@ -107,22 +115,43 @@ 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),
getInvitationAmount: M.call().returns(M.promise()),
}),
{
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(),
getInvitationAmount: paramManager.getInvitationAmount,
},
);

/** @type {Record<string, (...any) => unknown>} */
const governedApis = {};

const creatorFacet = prepareExo(
baggage,
'governorFacet',
M.interface('governorFacet', GovernorFacetShape),
{
getParamMgrRetriever: () =>
Far('paramRetriever', { get: () => paramManager }),
getInvitation: name => paramManager.getInternalParamValue(name),
getLimitedCreatorFacet: () => provisionPoolKit.machine,
/** @type {() => GovernedApis} */
getGovernedApis: () => Far('governedAPIs', governedApis),
getGovernedApiNames: () => Object.keys({}),
setOfferFilter: strings => zcf.setOfferFilter(strings),
},
);

return harden({
creatorFacet: makeDurableGovernorFacet(baggage, provisionPoolKit.machine)
.governorFacet,
creatorFacet,
publicFacet,
});
};
Expand Down

0 comments on commit 266d256

Please sign in to comment.