Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add a contract that supports voting on economic contracts #5245

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/run-protocol/src/voting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// @ts-check

import '@agoric/governance/src/exported.js';
import '@agoric/zoe/exported.js';
import '@agoric/zoe/src/contracts/exported.js';

import { E } from '@endo/eventual-send';

/**
* @file
*
* This extremely quick and dirty contract simplifies the process of
* calling for votes on changes to the economy by gathering the governor creator
* facets in one place and invokes `voteOnParamChanges` and
* `voteOnApiInvocation` on each when requested. A cleaner version would
* validate parameters, constrain deadlines and probably split the ability to
* call for vote into separate capabilities for finer grain encapsulation.
*/

/**
* @param {ZCF<{binaryVoteCounterInstallation:Installation}>} zcf
* @param {{reserve:GovernedContractFacetAccess<unknown>, amm:GovernedCreatorFacet<unknown>, vaults:GovernedCreatorFacet<unknown>}} privateArgs
*/
export const start = async (zcf, privateArgs) => {
const { binaryVoteCounterInstallation: counter } = zcf.getTerms();
const { reserve, amm, vaults } = privateArgs;

const voteOnParamChanges = (
target,
params,
path = { paramPath: { key: 'governedApi' } },
deadline,
) => {
return E(target).voteOnParamChanges(counter, deadline, {
paramPath: path,
changes: params,
});
};

const voteOnApiInvocation = (contract, method, amounts, deadline) => {
return E(contract).voteOnApiInvocation(method, amounts, counter, deadline);
};

const makeNullInvitation = () => {
return zcf.makeInvitation(() => {},
'identifies the voting contract instance');
};

const publicFacet = harden({
voteOnAmmParamChanges: params => voteOnParamChanges(amm, params),
voteOnReserveParamChanges: params => voteOnParamChanges(reserve, params),
// vote on param changes for a vaultManager
voteOnVaultParamChanges: (params, brand) =>
voteOnParamChanges(vaults, params, { paramPath: { key: brand } }),
// vote on param changes across the vaultFactory
voteOnVaultFactoryParamChanges: params =>
voteOnParamChanges(vaults, params),
voteOnReserveApiInvocation: (amounts, deadline) =>
voteOnApiInvocation(reserve, 'addLiquidityToAmmPool', amounts, deadline),
makeNullInvitation,
});

return { publicFacet };
};