Skip to content

Instantly share code, notes, and snippets.

@dckc
Last active January 27, 2023 16:38
Show Gist options
  • Save dckc/1230bf4a62530b049c53ec7740844033 to your computer and use it in GitHub Desktop.
Save dckc/1230bf4a62530b049c53ec7740844033 to your computer and use it in GitHub Desktop.
{
"consume": {
"board": true,
"chainStorage": true,
"zoe": true
},
"produce": {
"bakeSaleKit": true
},
"instance": {
"produce": {
"bakeSaleAgent": true
}
}
}
/**
* @file
*
* This is a script for use with swingset.CoreEval.
*
* It's a script, not a module, so we can't use `import`.
* But E, Far, etc. are in scope, provided by the
* `new Compartment(globals)` call in
* `bridgeCoreEval()` in packages/vats/src/core/chain-behaviors.js
*/
// @ts-check
// uncomment the following line to typecheck, for example, in vs-code.
// import { E } from '@endo/far';
const contractInfo = {
storagePath: 'bakeSales',
instanceName: 'bakeSaleAgent',
// see discussion of publish-bundle and bundleID
// from Dec 14 office hours
// https://github.com/Agoric/agoric-sdk/issues/6454#issuecomment-1351949397
bundleID:
'b1-392ae6656ae68bcfd8bd77a2a100ad4076e8b888808274796cce4c148fcb99d1f8b6c2f946bd6bc3e3c26c54c671c788890f3e9780464354fb2d30916e7be896',
};
const fail = reason => {
throw reason;
};
/**
* Execute a proposal to start a contract that publishes bake sales.
*
* See also:
* BLDer DAO governance using arbitrary code injection: swingset.CoreEval
* https://community.agoric.com/t/blder-dao-governance-using-arbitrary-code-injection-swingset-coreeval/99
*
* @param {BootstrapPowers} powers see the `behavior(powers)` call
* in `bridgeCoreEval()`
*/
const executeProposal = async powers => {
// Destructure the powers that we use.
// See also bakeSale-permit.json
const {
consume: { board, chainStorage, zoe },
// @ts-expect-error bakeSaleKit isn't declared in vats/src/core/types.js
produce: { bakeSaleKit },
instance: {
// @ts-expect-error bakeSaleKit isn't declared in vats/src/core/types.js
produce: { [contractInfo.instanceName]: produceInstance },
},
} = powers;
const chainStorageSettled =
(await chainStorage) || fail(Error('no chainStorage - sim chain?'));
const storageNode = E(chainStorageSettled).makeChildNode(
contractInfo.storagePath,
);
const marshaller = await E(board).getReadonlyMarshaller();
const privateArgs = harden({ storageNode, marshaller });
const installation = await E(zoe).installBundleID(contractInfo.bundleID);
const noIssuers = harden({});
const noTerms = harden({});
const facets = await E(zoe).startInstance(
installation,
noIssuers,
noTerms,
privateArgs,
);
// Share instance widely via E(agoricNames).lookup('instance', 'bakeSaleAgent')
produceInstance.resolve(facets.instance);
// Share the publicFacet, creatorFacet, and adminFacet in the bootstrap space
// for use by other CoreEval behaviors.
bakeSaleKit.resolve(facets);
};
harden(executeProposal);
// "export" the function as the script completion value
executeProposal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment