Skip to content

Commit

Permalink
feat!: use contractGovernor to govern Treasury using ParamManager
Browse files Browse the repository at this point in the history
extract params to a separate file
integrate contract governance into treasury
swingset test for treasury governance

closes #3189
closes #3473
  • Loading branch information
Chris-Hibbert committed Oct 1, 2021
1 parent 59ebde2 commit 185ba61
Show file tree
Hide file tree
Showing 26 changed files with 1,589 additions and 615 deletions.
68 changes: 56 additions & 12 deletions packages/treasury/bundles/install-on-chain.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
// @ts-check
import { E } from '@agoric/eventual-send';

import '../../governance/exported';

import liquidateBundle from './bundle-liquidateMinimum.js';
import autoswapBundle from './bundle-multipoolAutoswap.js';
import stablecoinBundle from './bundle-stablecoinMachine.js';
import contractGovernorBundle from './bundle-contractGovernor.js';
import committeeBundle from './bundle-committee.js';
import binaryVoteCounterBundle from './bundle-binaryVoteCounter.js';
import { governedParameterTerms } from '../src/params';
import { Far } from '@agoric/marshal';

const SECONDS_PER_HOUR = 60n * 60n;
const SECONDS_PER_DAY = 24n * SECONDS_PER_HOUR;
Expand Down Expand Up @@ -58,11 +65,18 @@ export async function installOnChain({
['liquidate', liquidateBundle],
['autoswap', autoswapBundle],
['stablecoin', stablecoinBundle],
['contractGovernor', contractGovernorBundle],
['committee', committeeBundle],
['binaryCounter', binaryVoteCounterBundle],

];
const [
liquidationInstall,
autoswapInstall,
stablecoinMachineInstall,
contractGovernorInstall,
committeeInstall,
binaryCounterInstall,
] = await Promise.all(
nameBundles.map(async ([name, bundle]) => {
// Install the bundle in Zoe.
Expand All @@ -74,42 +88,65 @@ export async function installOnChain({
}),
);

const electorateTerms = { committeeName: 'TreasuryBoard', committeeSize: 5 };
// The electorateCreatorFacet has `getVoterInvitations()`, which returns
// invitations for the people who can vote on changes to the treasury. We
// don't currently hand those out to anyone, but that is not visible on chain.
const {
creatorFacet: electorateCreatorFacet,
instance: electorateInstance,
} = await E(zoeWPurse).startInstance(committeeInstall, {}, electorateTerms);

const loanParams = {
chargingPeriod: SECONDS_PER_HOUR,
recordingPeriod: SECONDS_PER_DAY,
poolFee,
protocolFee,
};

const terms = harden({
const treasuryTerms = harden({
autoswapInstall,
liquidationInstall,
priceAuthority,
loanParams,
timerService: chainTimerService,
governedParams: governedParameterTerms,
bootstrapPaymentValue,
});
const governorTerms = harden({
timer: chainTimerService,
electorateInstance,
governedContractInstallation: stablecoinMachineInstall,
governed: {
terms: treasuryTerms,
issuerKeywordRecord: {},
privateArgs: harden({ feeMintAccess }),
},
});

const privateArgs = harden({ feeMintAccess });

const { instance, creatorFacet } = await E(zoeWPurse).startInstance(
stablecoinMachineInstall,
const {
creatorFacet: governorCreatorFacet,
} = await E(zoeWPurse).startInstance(
contractGovernorInstall,
undefined,
terms,
privateArgs,
governorTerms,
harden({ electorateCreatorFacet }),
);

const treasuryInstance = await E(governorCreatorFacet).getInstance();
const [
ammInstance,
invitationIssuer,
{
issuers: { Governance: govIssuer, RUN: centralIssuer },
brands: { Governance: govBrand, RUN: centralBrand },
},
treasuryCreator,
] = await Promise.all([
E(creatorFacet).getAMM(),
E(E(governorCreatorFacet).getCreatorFacet()).getAMM(),
E(zoeWPurse).getInvitationIssuer(),
E(zoeWPurse).getTerms(instance),
E(zoeWPurse).getTerms(treasuryInstance),
E(governorCreatorFacet).getCreatorFacet()
]);

const treasuryUiDefaults = {
Expand All @@ -123,12 +160,15 @@ export async function installOnChain({

// Look up all the board IDs.
const boardIdValue = [
['INSTANCE_BOARD_ID', instance],
['INSTANCE_BOARD_ID', treasuryInstance],
['INSTALLATION_BOARD_ID', stablecoinMachineInstall],
['RUN_ISSUER_BOARD_ID', centralIssuer],
['RUN_BRAND_BOARD_ID', centralBrand],
['AMM_INSTALLATION_BOARD_ID', autoswapInstall],
['LIQ_INSTALLATION_BOARD_ID', liquidationInstall],
['BINARY_COUNTER_INSTALLATION_BOARD_ID', binaryCounterInstall],
['COMMITTEE_INSTALLATION_BOARD_ID', committeeInstall],
['CONTRACT_GOVERNOR_INSTALLATION_BOARD_ID', contractGovernorInstall],
['AMM_INSTANCE_BOARD_ID', ammInstance],
['INVITE_BRAND_BOARD_ID', E(invitationIssuer).getBrand()],
];
Expand All @@ -146,7 +186,7 @@ export async function installOnChain({
// Install the names in agoricNames.
const nameAdminUpdates = [
[uiConfigAdmin, treasuryUiDefaults.CONTRACT_NAME, treasuryUiDefaults],
[instanceAdmin, treasuryUiDefaults.CONTRACT_NAME, instance],
[instanceAdmin, treasuryUiDefaults.CONTRACT_NAME, treasuryInstance],
[instanceAdmin, treasuryUiDefaults.AMM_NAME, ammInstance],
[brandAdmin, 'TreasuryGovernance', govBrand],
[issuerAdmin, 'TreasuryGovernance', govIssuer],
Expand All @@ -159,5 +199,9 @@ export async function installOnChain({
),
);

return creatorFacet;
const voteCreator = Far('treasury vote creator', {
voteOnParamChange: E(governorCreatorFacet).voteOnParamChange,
});

return { treasuryCreator, voteCreator };
}
4 changes: 3 additions & 1 deletion packages/treasury/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"@agoric/promise-kit": "^0.2.27",
"@agoric/store": "^0.6.5",
"@agoric/swingset-vat": "^0.22.1",
"@agoric/zoe": "^0.19.1"
"@agoric/zoe": "^0.19.1",
"@agoric/governance": "^0.2.0",
"@agoric/same-structure": "^0.1.20"
},
"devDependencies": {
"@agoric/babel-standalone": "^7.14.3",
Expand Down
12 changes: 12 additions & 0 deletions packages/treasury/scripts/build-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ async function main() {
`@agoric/zoe/src/contracts/multipoolAutoswap/multipoolAutoswap.js`,
`${dirname}/../bundles/bundle-multipoolAutoswap.js`,
],
[
'@agoric/governance/src/contractGovernor.js',
`${dirname}/../bundles/bundle-contractGovernor.js`,
],
[
'@agoric/governance/src/committee.js',
`${dirname}/../bundles/bundle-committee.js`,
],
[
'@agoric/governance/src/binaryVoteCounter.js',
`${dirname}/../bundles/bundle-binaryVoteCounter.js`,
],
];
for (const [contractFilename, outputPath] of contractOutputs) {
// eslint-disable-next-line no-await-in-loop
Expand Down
84 changes: 84 additions & 0 deletions packages/treasury/src/params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// @ts-check

import { buildParamManager, ParamType } from '@agoric/governance';

export const POOL_FEE_KEY = 'PoolFee';
export const PROTOCOL_FEE_KEY = 'ProtocolFee';

export const CHARGING_PERIOD_KEY = 'ChargingPeriod';
export const RECORDING_PERIOD_KEY = 'RecordingPeriod';

export const INITIAL_MARGIN_KEY = 'InitialMargin';
export const LIQUIDATION_MARGIN_KEY = 'LiquidationMargin';
export const INTEREST_RATE_KEY = 'InterestRate';
export const LOAN_FEE_KEY = 'LoanFee';

export const governedParameterTerms = {
loanParams: [POOL_FEE_KEY, PROTOCOL_FEE_KEY],
poolParams: [
CHARGING_PERIOD_KEY,
RECORDING_PERIOD_KEY,
INITIAL_MARGIN_KEY,
LIQUIDATION_MARGIN_KEY,
INTEREST_RATE_KEY,
LOAN_FEE_KEY,
],
};

/** @type {{ FEE: 'fee', POOL: 'pool' }} */
export const ParamKey = {
FEE: 'fee',
POOL: 'pool',
};

export const makeFeeParamManager = loanParams => {
/** @type {FeeParamManager} */
return buildParamManager([
{
name: POOL_FEE_KEY,
value: loanParams.poolFee,
type: ParamType.NAT,
},
{
name: PROTOCOL_FEE_KEY,
value: loanParams.protocolFee,
type: ParamType.NAT,
},
]);
};

export const makePoolParamManager = (loanParams, rates) => {
/** @type {PoolParamManager} */
return buildParamManager([
{
name: CHARGING_PERIOD_KEY,
value: loanParams.chargingPeriod,
type: ParamType.NAT,
},
{
name: RECORDING_PERIOD_KEY,
value: loanParams.recordingPeriod,
type: ParamType.NAT,
},
{
name: INITIAL_MARGIN_KEY,
value: rates.initialMargin,
type: ParamType.RATIO,
},
{
name: LIQUIDATION_MARGIN_KEY,
value: rates.liquidationMargin,
type: ParamType.RATIO,
},
{
name: INTEREST_RATE_KEY,
value: rates.interestRate,
type: ParamType.RATIO,
},
{
name: LOAN_FEE_KEY,
value: rates.loanFee,
type: ParamType.RATIO,
},
]);
};
Loading

0 comments on commit 185ba61

Please sign in to comment.