-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support changes to governed APIs (#10822)
closes: #9990 ## Description When a contract is upgraded, we'll read the governed APIs afresh. ### Security Considerations Nothing special. The point of governed APIs is that contracts can make access to calling specific APIs legible in the sense used by governance. ### Scaling Considerations Not an issue. ### Documentation Considerations If we had detailed documentation on governance, this would be worth adding to the docs. ### Testing Considerations Added a bootstrap test showing that a contract can be upgraded and the new APIs will be available after upgrade. ### Upgrade Considerations AssetReserve, fluxAggregator, and VaultFactory use `apiGovernance` and might need this support if any governed APIs were added.
- Loading branch information
Showing
10 changed files
with
534 additions
and
21 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
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,85 @@ | ||
import { | ||
CONTRACT_ELECTORATE, | ||
ParamTypes, | ||
handleParamGovernance, | ||
} from '@agoric/governance'; | ||
import { prepareExoClassKit, provide } from '@agoric/vat-data'; | ||
|
||
/** | ||
* @import {GovernanceTerms} from '@agoric/governance/src/types.js'; | ||
* @import {Baggage} from '@agoric/vat-data'; | ||
*/ | ||
|
||
const MALLEABLE_NUMBER = 'MalleableNumber'; | ||
|
||
const makeTerms = (number, invitationAmount) => { | ||
return harden({ | ||
governedParams: { | ||
[MALLEABLE_NUMBER]: { type: ParamTypes.NAT, value: number }, | ||
[CONTRACT_ELECTORATE]: { | ||
type: ParamTypes.INVITATION, | ||
value: invitationAmount, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
/** | ||
* | ||
* @param {ZCF< | ||
* GovernanceTerms<{ | ||
* MalleableNumber: 'nat', | ||
* }>>} zcf | ||
* @param {{initialPoserInvitation: Invitation}} privateArgs | ||
* @param {Baggage} baggage | ||
*/ | ||
const start = async (zcf, privateArgs, baggage) => { | ||
const { makeDurableGovernorFacet, params } = await handleParamGovernance( | ||
zcf, | ||
privateArgs.initialPoserInvitation, | ||
{ | ||
[MALLEABLE_NUMBER]: ParamTypes.NAT, | ||
}, | ||
); | ||
|
||
const makeGoverned = prepareExoClassKit( | ||
baggage, | ||
'governed Public', | ||
undefined, | ||
() => | ||
harden({ | ||
governanceAPICalled: 0, | ||
}), | ||
{ | ||
public: { | ||
getNum() { | ||
return params.getMalleableNumber(); | ||
}, | ||
getApiCalled() { | ||
const { governanceAPICalled } = this.state; | ||
return governanceAPICalled; | ||
}, | ||
}, | ||
creator: {}, | ||
governed: { | ||
add1() { | ||
const { state } = this; | ||
state.governanceAPICalled += 1; | ||
}, | ||
}, | ||
}, | ||
); | ||
const facets = provide(baggage, 'theContract', () => makeGoverned()); | ||
|
||
const { governorFacet } = makeDurableGovernorFacet(baggage, facets.creator, { | ||
add1: () => facets.governed.add1(), | ||
}); | ||
|
||
return { publicFacet: facets.public, creatorFacet: governorFacet }; | ||
}; | ||
|
||
harden(start); | ||
harden(MALLEABLE_NUMBER); | ||
harden(makeTerms); | ||
|
||
export { start, MALLEABLE_NUMBER, makeTerms }; |
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,90 @@ | ||
import { | ||
CONTRACT_ELECTORATE, | ||
ParamTypes, | ||
handleParamGovernance, | ||
} from '@agoric/governance'; | ||
import { prepareExoClassKit, provide } from '@agoric/vat-data'; | ||
|
||
/** | ||
* @import {GovernanceTerms} from '@agoric/governance/src/types.js'; | ||
* @import {Baggage} from '@agoric/vat-data'; | ||
*/ | ||
|
||
const MALLEABLE_NUMBER = 'MalleableNumber'; | ||
|
||
const makeTerms = (number, invitationAmount) => { | ||
return harden({ | ||
governedParams: { | ||
[MALLEABLE_NUMBER]: { type: ParamTypes.NAT, value: number }, | ||
[CONTRACT_ELECTORATE]: { | ||
type: ParamTypes.INVITATION, | ||
value: invitationAmount, | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
/** | ||
* | ||
* @param {ZCF< | ||
* GovernanceTerms<{ | ||
* MalleableNumber: 'nat', | ||
* }>>} zcf | ||
* @param {{initialPoserInvitation: Invitation}} privateArgs | ||
* @param {Baggage} baggage | ||
*/ | ||
const start = async (zcf, privateArgs, baggage) => { | ||
const { makeDurableGovernorFacet, params } = await handleParamGovernance( | ||
zcf, | ||
privateArgs.initialPoserInvitation, | ||
{ | ||
[MALLEABLE_NUMBER]: ParamTypes.NAT, | ||
}, | ||
); | ||
|
||
const makeGoverned = prepareExoClassKit( | ||
baggage, | ||
'governed Public', | ||
undefined, | ||
() => | ||
harden({ | ||
governanceAPICalled: 0, | ||
}), | ||
{ | ||
public: { | ||
getNum() { | ||
return params.getMalleableNumber(); | ||
}, | ||
getApiCalled() { | ||
const { governanceAPICalled } = this.state; | ||
return governanceAPICalled; | ||
}, | ||
}, | ||
creator: {}, | ||
governed: { | ||
add1() { | ||
const { state } = this; | ||
state.governanceAPICalled += 1; | ||
}, | ||
add2() { | ||
const { state } = this; | ||
state.governanceAPICalled += 2; | ||
}, | ||
}, | ||
}, | ||
); | ||
const facets = provide(baggage, 'theContract', () => makeGoverned()); | ||
|
||
const { governorFacet } = makeDurableGovernorFacet(baggage, facets.creator, { | ||
add1: () => facets.governed.add1(), | ||
add2: () => facets.governed.add2(), | ||
}); | ||
|
||
return { publicFacet: facets.public, creatorFacet: governorFacet }; | ||
}; | ||
|
||
harden(start); | ||
harden(MALLEABLE_NUMBER); | ||
harden(makeTerms); | ||
|
||
export { start, MALLEABLE_NUMBER, makeTerms }; |
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
Oops, something went wrong.