-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add a helper for governedContracts
- Loading branch information
1 parent
6cacda9
commit fb4e312
Showing
7 changed files
with
122 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// @ts-check | ||
|
||
import { Far } from '@agoric/marshal'; | ||
import { assert, details as X, q } from '@agoric/assert'; | ||
import { sameStructure } from '@agoric/same-structure'; | ||
|
||
import { buildParamManager } from './paramManager.js'; | ||
|
||
/* | ||
* Helper for the 90% of contracts that will have only a single set of | ||
* parameters. In order to support managed parameters, a contract only has to | ||
* * define the parameter template, which includes name, type and value | ||
* * call handleParamGovernance() to get makePublicFacet and makeCreatorFacet | ||
* * add any methods needed in the public and creator facets. | ||
*/ | ||
const handleParamGovernance = (zcf, governedParamsTemplate) => { | ||
const terms = zcf.getTerms(); | ||
/** @type {ParamDescriptions} */ | ||
const governedParams = terms.main; | ||
const { electionManager } = terms; | ||
|
||
assert( | ||
sameStructure(governedParams, governedParamsTemplate), | ||
X`Terms must include ${q(governedParamsTemplate)}, but were ${q( | ||
governedParams, | ||
)}`, | ||
); | ||
const paramManager = buildParamManager(governedParams); | ||
|
||
const makePublicFacet = (originalPublicFacet = {}) => { | ||
return Far('publicFacet', { | ||
...originalPublicFacet, | ||
getSubscription: () => paramManager.getSubscription(), | ||
getContractGovernor: () => electionManager, | ||
getGovernedParamsValues: () => { | ||
return { main: paramManager.getParams() }; | ||
}, | ||
}); | ||
}; | ||
|
||
/** @type {LimitedCreatorFacet} */ | ||
const limitedCreatorFacet = Far('governedContract creator facet', { | ||
getContractGovernor: () => electionManager, | ||
}); | ||
|
||
const makeCreatorFacet = (originalCreatorFacet = Far('creatorFacet', {})) => { | ||
return Far('creatorFacet', { | ||
getParamMgrRetriever: () => { | ||
return Far('paramRetriever', { get: () => paramManager }); | ||
}, | ||
getInternalCreatorFacet: () => originalCreatorFacet, | ||
getLimitedCreatorFacet: () => limitedCreatorFacet, | ||
}); | ||
}; | ||
|
||
return harden({ | ||
makePublicFacet, | ||
makeCreatorFacet, | ||
}); | ||
}; | ||
harden(handleParamGovernance); | ||
export { handleParamGovernance }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters