Skip to content

Commit

Permalink
chore: progress on testing governance for KREAd
Browse files Browse the repository at this point in the history
The proposal passes, and the contract begins to run
  • Loading branch information
Chris-Hibbert committed Sep 20, 2023
1 parent 6f3697a commit fd7f247
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 64 deletions.
31 changes: 16 additions & 15 deletions agoric/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ KREAD_REPO =
EVAL_PERMIT =
EVAL_CODE =
EVAL_CLEAN =
PROP_DIR = contract/src/proposal
KR_AG_DIR =
PROP_DIR = $(KR_AG_DIR)/contract/src/proposal

include Makefile.paths.local

Expand Down Expand Up @@ -39,25 +40,25 @@ wallet1:
deploy:
agoric deploy contract/kread-deploy-contract.js api/kread-deploy-api.js

install-kread:
kread-committee:
agoric run contract/src/proposal/kread-committee-script.js | tee kread-committee.out
node contract/scripts/parseProposals.js < kread-committee.out | jq -r '.bundles[]' | sort -u > kread-committee-bundles.out
for b in `cat kread-committee-bundles.out` ; do \
agoric publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \
done
agd tx gov submit-proposal swingset-core-eval $(PROP_DIR)/powers.json $(PROP_DIR)/kread-committee-proposal.js \
--title="create KREAd committee" --description="Evaluate kread-committee-proposal.js" --deposit=1000000ubld \
--gas=auto --gas-adjustment=1.2
# agoric run contract/src/proposal/start-kread-script.js
# agd tx gov submit-proposal swingset-core-eval kread-invite-committee-permit.json kread-invite-committee.js \
# --title="Enable <something>" --description="Evaluate kread-invite-committee.js" --deposit=1000000ubld \
# --gas=auto --gas-adjustment=1.
#
# agoric run contract/src/proposal/start-kread-script.js | tee start-kread.out
# node contract/scripts/parseProposals.js < start-kread.out | jq -r '.bundles[]' | sort -u > kread-bundles.out
# for b in `cat kread-bundles.out` ; do \
# agoric publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \
# done
cd $(COSMIC_SWINGSET_PATH); \
make scenario2-core-eval EVAL_PERMIT=$(KR_AG_DIR)/kread-invite-committee-permit.json \
EVAL_CODE=$(KR_AG_DIR)/kread-invite-committee.js EVAL_CLEAN=$(KR_AG_DIR)/kread-invite-committee.js.t scenario2-vote VOTE_PROPOSAL=3 \

start-kread:
agoric run contract/src/proposal/start-kread-script.js | tee start-kread.out
node contract/scripts/parseProposals.js < start-kread.out | jq -r '.bundles[]' | sort -u > start-kread-bundles.out
for b in `cat start-kread-bundles.out` ; do \
agoric publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \
done
cd $(COSMIC_SWINGSET_PATH); \
make scenario2-core-eval EVAL_PERMIT=$(KR_AG_DIR)/start-kread-permit.json \
EVAL_CODE=$(KR_AG_DIR)/start-kread.js EVAL_CLEAN=$(KR_AG_DIR)/start-kread.js.t scenario2-vote VOTE_PROPOSAL=4 \

kread-bundle:
cd $(VATS_PATH); \
Expand Down
3 changes: 2 additions & 1 deletion agoric/Makefile.paths
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ KEPLR_ADDRESS2 = agoric1tq3v943uaycqp90qvuyaqzwdc3eh52xzrcl4p6
KREAD_REPO = /Users/carlostrigo/kryha/agoric/code/Agoric/agoric/contract/src/index.js
EVAL_PERMIT = /Users/carlostrigo/kryha/agoric/code/Agoric/agoric/contract/src/proposal/powers.json
EVAL_CODE = /Users/carlostrigo/kryha/agoric/code/Agoric/agoric/contract/src/proposal/chain-storage-proposal.js
EVAL_CLEAN = $(EVAL_CODE)-clean.js
EVAL_CLEAN = $(EVAL_CODE)-clean.js
KR_AG_DIR = /Users/carlostrigo/agoric-kread/agoric
5 changes: 3 additions & 2 deletions agoric/Makefile.paths.local
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ SDK_PATH =/Users/chris/agoric-sdk
COSMIC_SWINGSET_PATH =/Users/chris/agoric-sdk/packages/cosmic-swingset
VATS_PATH =/Users/chris/agoric-sdk/packages/vats
KEPLR_ADDRESS2 = agoric1tq3v943uaycqp90qvuyaqzwdc3eh52xzrcl4p6
KEPLR_ADDRESS = agoric1nymj7cmdrp9js6etrn3zu637zy02xrllsw02jn
KEPLR_ADDRESS = agoric16cnnlc60cgkp7mgwtj9htf5jlakel85lhvft96
KREAD_REPO = /Users/chris/agoric-kryha/agoric/code/Agoric/agoric/contract/src/index.js
EVAL_PERMIT = /Users/chris/agoric-kryha/agoric/code/Agoric/agoric/contract/src/proposal/powers.json
EVAL_CODE = /Users/chris/agoric-kryha/agoric/code/Agoric/agoric/contract/src/proposal/chain-storage-proposal.js
EVAL_CLEAN = $(EVAL_CODE)-clean.js
EVAL_CLEAN = $(EVAL_CODE)-clean.js
KR_AG_DIR = /Users/chris/agoric-kread/agoric
4 changes: 2 additions & 2 deletions agoric/contract/src/proposal/chain-storage-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// uncomment the following line to typecheck, for example, in vs-code.
// import { E } from '@endo/far';

const baseCharacters = [
export const baseCharacters = [
[
1,
{
Expand Down Expand Up @@ -86,7 +86,7 @@ const baseCharacters = [
],
];

const baseItems = [
export const baseItems = [
{
name: 'AirTox: Fairy Dust Elite',
category: 'perk1',
Expand Down
7 changes: 3 additions & 4 deletions agoric/contract/src/proposal/kread-committee-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ export const startKreadCommittee = async (
voterAddresses,
...rest
} = options;
const committeeSize = voterAddresses.length;
console.log(`KCP size`, committeeSize, voterAddresses.keys().length());
const committeeSize = Object.keys(voterAddresses).length;

const [storageNode, marshaller] = await Promise.all([
E(chainStorage).makeChildNode(COMMITTEES_ROOT).makeChildNode(
E(E(chainStorage).makeChildNode(COMMITTEES_ROOT)).makeChildNode(
sanitizePathSegment(committeeName)),
E(board).getPublishingMarshaller(),
]);
Expand Down Expand Up @@ -161,7 +160,7 @@ export const addGovernorToKreadCharter = async ({
consume: { kreadKit },
instance: { consume: { kread } },
}) => {
const { creatorFacet } = E.get(kreadCharterKit);
const { creatorFacet } = E.get(kreadKit);

await Promise.all(
[
Expand Down
2 changes: 1 addition & 1 deletion agoric/contract/src/proposal/kread-committee-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const defaultProposalBuilder = async (
kreadCommitteeCharterRef: publishRef(
install(
'../kreadCommitteeCharter.js',
'../bundles/bundle-kreadCommitteeCharter.js.js',
'../bundles/bundle-kreadCommitteeCharter.js',
{
persist: true,
},
Expand Down
89 changes: 53 additions & 36 deletions agoric/contract/src/proposal/start-kread-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
/** @file This is a module for use with swingset.CoreEval. */

import {E} from '@endo/far';
import { defaultCharacters, defaultItems } from './chain-storage-proposal.js';
import { baseCharacters, baseItems } from './chain-storage-proposal.js';

const KREAD_LABEL = 'KREAd';

const contractInfo = {
storagePath: 'kread',
Expand Down Expand Up @@ -31,43 +33,49 @@ const fail = (reason) => {
* @returns {Promise<GovernanceFacetKit<SF>>}
*/
const startGovernedInstance = async ({
zone,
consume: {
zoe,
timer,
contractGovernor,
chainTimerService: chainTimerServiceP,
chainStorage,
board,
kreadCommitteeCreatorFacet,
agoricNames,
},
produce: { kreadKit },
installation: { consume: { kreadKit: installP, contractGovernor: govP }}
}, { kreadConfig, }) => {
const poserInvitationP = E(kreadCommitteeCreatorFacet).getPoserInvitation();
const [initialPoserInvitation, electorateInvitationAmount] =
const [
initialPoserInvitation,
timer,
electorateInvitationAmount,
marshaller,
istIssuer,
chainStorageSettled,
kreadKitInstallation,
contractGovernor,
] =
await Promise.all([
poserInvitationP,
chainTimerServiceP,
E(E(zoe).getInvitationIssuer()).getAmountOf(poserInvitationP),
E(board).getReadonlyMarshaller(),
E(agoricNames).lookup('issuer', 'IST'),
chainStorage,
installP,
govP,
]);

const contractKits = zone.mapStore('KreadContractKits');

const chainStorageSettled =
(await chainStorage) || fail(Error('no chainStorage - sim chain?'));
chainStorageSettled || fail(Error('no chainStorage - sim chain?'));
const storageNode = E(chainStorageSettled).makeChildNode(
contractInfo.storagePath,
);
const marshaller = await E(board).getReadonlyMarshaller();
const kreadPowers = { storageNode, marshaller };
const clock = await E(chainTimerService).getClock();

const istIssuer = await E(agoricNames).lookup('issuer', 'IST');
const installation = await E(zoe).installBundleID(contractInfo.bundleID);

const governorTerms =
harden({
timer,
governedContractInstallation: installation,
governedContractInstallation: kreadKitInstallation,
governed: {
terms: {
governedParams: {
Expand All @@ -78,7 +86,7 @@ const startGovernedInstance = async ({
},
},
issuerKeywordRecord: harden({ Money: istIssuer }),
label: 'KREAd',
label: KREAD_LABEL,
},
},
);
Expand All @@ -90,13 +98,13 @@ const startGovernedInstance = async ({
{},
governorTerms,
harden({
committeeCreatorFacet,
committeeCreatorFacet: kreadCommitteeCreatorFacet,
governed: {
...privateArgs,
initialPoserInvitation,
},
}),
`${label}-governor`,
`${KREAD_LABEL}-governor`,
);

const [instance, publicFacet, creatorFacet, adminFacet] = await Promise.all([
Expand All @@ -108,7 +116,7 @@ const startGovernedInstance = async ({

kreadKit.resolve(
harden({
label: 'KREAd',
label: KREAD_LABEL,
instance,
publicFacet,
creatorFacet,
Expand All @@ -133,17 +141,17 @@ const startGovernedInstance = async ({
*
* @param {BootstrapPowers} powers
*/
const executeProposal = async powers => {
export const startKread = async powers => {
const {
consume: { board, agoricNamesAdmin },
consume: { board, agoricNamesAdmin, chainTimerService: clock },
instance: {
produce: { [contractInfo.instanceName]: kread },
},
} = powers;

const kreadConfig = harden({
defaultCharacters,
defaultItems,
baseCharacters,
baseItems,
clock,
seed: 303,
});
Expand Down Expand Up @@ -226,26 +234,35 @@ const executeProposal = async powers => {
console.log('ASSETS ADDED TO AGORIC NAMES');
// Share instance widely via E(agoricNames).lookup('instance', <instance name>)
};
harden(executeProposal);
harden(startKread);

export const getManifestForStartKread = async () => ({
export const getManifestForStartKread = async (
{ restoreRef },
{ kreadKitRef }
) => ({
manifest: {
[executeProposal.name]: {
zone: true,
[startKread.name]: {
consume: {
chainTimerService: true,
board: true,
chainStorage: true,
zoe: true,
agoricNamesAdmin: true,
agoricNames: true,
diagnostics: true,
zoe: true,
chainTimerService: true,
chainStorage: true,
kreadCommitteeCreatorFacet: true,
agoricNames: true,
},
produce: { kreadKit: true },
instance: {
produce: { kread: true }
produce: { [contractInfo.instanceName]: true },
},
}
}
installation: {
consume: {
kreadKit: true,
contractGovernor: true,
}},
produce: { kreadKit: true },
},
},
installations: {
kreadKit: restoreRef(kreadKitRef),
},
});
15 changes: 12 additions & 3 deletions agoric/contract/src/proposal/start-kread-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ import { getManifestForStartKread } from './start-kread-proposal.js';
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').ProposalBuilder} */
export const defaultProposalBuilder = async (
{ publishRef, install },
options = {},
) => {
return harden({
sourceSpec: './start-kread-proposal.js',
getManifestCall: [getManifestForStartKread.name, {}],
getManifestCall: [getManifestForStartKread.name, {
kreadKitRef: publishRef(
install(
'../index.js',
'../bundles/bundle-kreadKit.js',
{
persist: true,
},
),
),
}],
});
};

export default async (homeP, endowments) => {
const { writeCoreProposal } = await makeHelpers(homeP, endowments);
await writeCoreProposal('kread-invite-committee', defaultProposalBuilder);
await writeCoreProposal('start-kread', defaultProposalBuilder);
};

0 comments on commit fd7f247

Please sign in to comment.