Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ start-contract-mint:
--eval src/platform-goals/board-aux.core.js \
--eval src/sell-concert-tickets.proposal.js


deploy-contract-mint:
yarn node scripts/deploy-contract.js \
--deploy ./src/sell-concert-tickets.contract.js

start-contract-swap:
yarn node scripts/deploy-contract.js \
--install src/swaparoo.contract.js \
Expand Down Expand Up @@ -97,3 +102,6 @@ bundles/deploy-swaparoo.js: src/swaparoo.proposal.js

clean:
@rm -rf bundles/

patch-bn:
cp ./patch-bn.js ../node_modules/bn.js/lib/bn.js
4 changes: 2 additions & 2 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
"@agoric/ertp": "^0.16.3-u14.0",
"@agoric/governance": "^0.10.4-u14.0",
"@agoric/inter-protocol": "0.16.2-u14.1",
"@agoric/vats": "0.15.2-u14.0",
"@agoric/vat-data": "0.5.3-u14.0",
"@agoric/vats": "0.15.2-u14.0",
"@agoric/zoe": "^0.26.3-u14.0",
"@endo/bundle-source": "^2.8.0",
"@endo/bundle-source": "https://github.com/endojs/endo.git#7277ef6ed47cc9bff0c1df5808c22cc17b4444ad2e25552740f3b7fdce5c5a81",
"@endo/far": "^0.2.22",
"@endo/init": "^0.5.60",
"@endo/marshal": "^0.8.9",
Expand Down
55 changes: 54 additions & 1 deletion contract/scripts/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const options = {
eval: { type: 'string', multiple: true },
service: { type: 'string', default: 'agd' },
workdir: { type: 'string', default: '/workspace/contract' },
deploy: { type: 'string', multiple: true },
};
/**
* @typedef {{
Expand All @@ -25,10 +26,12 @@ const options = {
* eval?: string[],
* service: string,
* workdir: string,
* deploy: string[],
* }} DeployOptions
*/

const Usage = `
//TODo make help test
const Usage = `
deploy-contract [options] [--install <contract>] [--eval <proposal>]...

Options:
Expand All @@ -54,13 +57,37 @@ const mockExecutionContext = () => {
};
};

//
// const redactImportDecls = txt =>
// txt.replace(/^\s*import\b\s*(.*)/gm, '// XMPORT: $1');

const hideImportExpr = txt => txt.replace(/\bimport\(/g, 'XMPORT(');

const generateDeployArtifact = async (path, name, { readFile, writeFile }) => {
// readtemplate
const template = await readFile('src/auto-deploy.template.js', 'utf-8');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! looks like this template file didn't get committed.

console.log(template);
console.log(process.cwd());
console.log(name);
// string replace for contract name
const finalFile = hideImportExpr(template.replace('_CONTRACT_NAME_', name));

//write result to bundles/deploy-name.js
return writeFile(`bundles/deploy-${name}.js`, finalFile);
};

const main = async (bundleDir = 'bundles') => {
const { argv } = process;
const { writeFile } = fsp;

const progress = (...args) => console.warn(...args); // stderr

const bundleCache = await makeNodeBundleCache(bundleDir, {}, s => import(s));
const deployBundleCache = await makeNodeBundleCache(
bundleDir,
{ format: 'endoScript' },
s => import(s),
);

/** @type {{ values: DeployOptions }} */
// @ts-expect-error options config ensures type
Expand Down Expand Up @@ -88,10 +115,36 @@ const main = async (bundleDir = 'bundles') => {
setTimeout,
writeFile,
bundleDir,
deployBundleCache,
});

const stem = path => basename(path).replace(/\..*/, '');

// deploy in one step
if (flags.deploy) {
for await (const contractEntry of flags.deploy) {
const name = stem(contractEntry);
await tools.installBundles({ [name]: contractEntry }, progress);

const generatedCoreEval = `bundles/deploy-${name}-entry.js`;
// TODO: fix
await generateDeployArtifact(generatedCoreEval, name, fsp);
console.log({ contractEntry });
// handle paths without .
const { meta } = await import(`../${contractEntry}`);
console.log('meta: ', meta);

const result = await tools.runCoreEval({
name,
entryFile: generatedCoreEval, // put core eval
permit: meta.permit,
});

progress(result);
}
return;
}

if (flags.install) {
const name = stem(flags.install);

Expand Down
18 changes: 18 additions & 0 deletions contract/src/sell-concert-tickets.contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,26 @@ const InventoryShape = M.recordOf(M.string(), {
* }} SellConcertTicketsTerms
*/

const contractName = 'sellConcertTickets';
export const meta = harden({
contractName,
customTermsShape: { inventory: InventoryShape },
/** @type { import("@agoric/vats/src/core/lib-boot.js").BootstrapManifestPermit } */
permit: harden({
consume: {
agoricNames: true,
brandAuxPublisher: true,
startUpgradable: true, // to start contract and save adminFacet
zoe: true, // to get contract terms, including issuer/brand
},
installation: {
consume: { [contractName]: true },
produce: { [contractName]: true },
},
instance: { produce: { [contractName]: true } },
issuer: { consume: { IST: true }, produce: { Ticket: true } },
brand: { consume: { IST: true }, produce: { Ticket: true } },
}),
});
// compatibility with an earlier contract metadata API
export const customTermsShape = meta.customTermsShape;
Expand Down
20 changes: 18 additions & 2 deletions contract/tools/e2e-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ const runCoreEval = async (
* @param {string} [io.apiAddress]
* @param {typeof import('fs/promises').writeFile} io.writeFile
* @param {(...parts: string[]) => string} [io.join]
* @param {import('../test/mintStable.js').BundleCache} [io.deployBundleCache]
*/
export const makeE2ETools = (
t,
Expand All @@ -437,6 +438,7 @@ export const makeE2ETools = (
rpcAddress = 'http://localhost:26657',
apiAddress = 'http://localhost:1317',
join = (...parts) => parts.join('/'),
deployBundleCache = bundleCache, // XXX is this a good default arg name
},
) => {
const agd = makeAgd({ execFileSync }).withOpts({ keyringBackend: 'test' });
Expand Down Expand Up @@ -530,12 +532,14 @@ export const makeE2ETools = (
return harden(bundles);
};

/** @import {BootstrapManifestPermit} from "@agoric/vats/src/core/lib-boot.js" */
/**
* @param {{
* name: string,
* title?: string,
* description?: string,
* config?: unknown,
* permit?: BootstrapManifestPermit
* } & {
* behavior?: Function,
* } & ({ builderPath: string } | { entryFile: string })
Expand All @@ -545,11 +549,21 @@ export const makeE2ETools = (
if ('builderPath' in info) {
throw Error('@@TODO: agoric run style');
}
const { name, title = name, description = title, entryFile } = info;
const { name, title = name, description = title, entryFile, permit } = info;

const eval0 = {
code: `bundles/deploy-${name}.js`,
permit: `bundles/deploy-${name}-permit.json`,
};
const loadResult = await deployBundleCache.load(
entryFile,
name,
console.log,
);
console.log('loadResult', loadResult);
throw 1;
await writeFile(eval0.code, loadResult);
await writeFile(eval0.permit, JSON.stringify(permit, null, 2));
await null;
try {
const todo = await runMake(`${eval0.code}.done`);
Expand All @@ -568,7 +582,9 @@ export const makeE2ETools = (
// not yet bundled
}
const detail = { evals: [eval0], title, description };
await runPackageScript('build:deployer', entryFile);

// await runPackageScript('build:deployer', entryFile);

const proposal = await runCoreEval(t, detail, { agd, blockTool });
await writeFile(
`${eval0.code}.done`,
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.5'

services:
agd:
# cf. https://github.com/Agoric/agoric-3-proposals
Expand Down
Loading