@agoric/deploy-script-support 0.10.4-20230923T000433-dev-63b1fb6.0 → 0.10.4-calypso-dev-dabccdc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,139 +0,0 @@
1
- // @ts-check
2
- import fs from 'fs';
3
- import { E } from '@endo/far';
4
- import { deeplyFulfilled } from '@endo/marshal';
5
-
6
- import { createBundles } from '@agoric/internal/src/node/createBundles.js';
7
- import { defangAndTrim, mergePermits, stringify } from './code-gen.js';
8
- import { makeCoreProposalBehavior, permits } from './coreProposalBehavior.js';
9
-
10
- export const makeWriteCoreProposal = (
11
- homeP,
12
- endowments,
13
- {
14
- getBundlerMaker,
15
- getBundleSpec,
16
- log = console.log,
17
- writeFile = fs.promises.writeFile,
18
- },
19
- ) => {
20
- const { bundleSource, pathResolve } = endowments;
21
-
22
- let bundlerCache;
23
- const getBundler = () => {
24
- if (!bundlerCache) {
25
- bundlerCache = E(getBundlerMaker()).makeBundler({
26
- zoe: E.get(homeP).zoe,
27
- });
28
- }
29
- return bundlerCache;
30
- };
31
-
32
- const mergeProposalPermit = async (proposal, additionalPermits) => {
33
- const {
34
- sourceSpec,
35
- getManifestCall: [exportedGetManifest, ...manifestArgs],
36
- } = proposal;
37
-
38
- const manifestNs = await import(pathResolve(sourceSpec));
39
-
40
- // We only care about the manifest, not any restoreRef calls.
41
- const { manifest } = await manifestNs[exportedGetManifest](
42
- { restoreRef: x => `restoreRef:${x}` },
43
- ...manifestArgs,
44
- );
45
-
46
- const mergedPermits = mergePermits(manifest);
47
- return {
48
- manifest,
49
- permits: mergePermits({ mergedPermits, additionalPermits }),
50
- };
51
- };
52
-
53
- let mutex = Promise.resolve();
54
- const writeCoreProposal = async (filePrefix, proposalBuilder) => {
55
- const getBundle = async (entrypoint, bundlePath) => {
56
- if (!bundlePath) {
57
- return bundleSource(pathResolve(entrypoint));
58
- }
59
- const bundleCache = pathResolve(bundlePath);
60
- await createBundles([[pathResolve(entrypoint), bundleCache]]);
61
- const ns = await import(bundleCache);
62
- return ns.default;
63
- };
64
-
65
- // Install an entrypoint.
66
- const install = async (entrypoint, bundlePath, opts) => {
67
- const bundle = getBundle(entrypoint, bundlePath);
68
-
69
- // Serialise the installations.
70
- mutex = E.when(mutex, () => {
71
- // console.log('installing', { filePrefix, entrypoint, bundlePath });
72
- return getBundleSpec(bundle, getBundler, opts);
73
- });
74
- return mutex;
75
- };
76
-
77
- // Await a reference then publish to the board.
78
- const cmds = [];
79
- const publishRef = async refP => {
80
- const { fileName, ...ref } = await refP;
81
- if (fileName) {
82
- cmds.push(`agd tx swingset install-bundle @${fileName}`);
83
- }
84
-
85
- return harden(ref);
86
- };
87
-
88
- // Create the proposal structure.
89
- const proposal = await deeplyFulfilled(
90
- harden(proposalBuilder({ publishRef, install })),
91
- );
92
- const { sourceSpec, getManifestCall } = proposal;
93
- // console.log('created', { filePrefix, sourceSpec, getManifestCall });
94
-
95
- // Extract the top-level permit.
96
- const { permits: proposalPermit, manifest: overrideManifest } =
97
- await mergeProposalPermit(proposal, permits);
98
-
99
- // Get an install
100
- const manifestBundleRef = await publishRef(install(sourceSpec));
101
-
102
- // console.log('writing', { filePrefix, manifestBundleRef, sourceSpec });
103
- const code = `\
104
- // This is generated by writeCoreProposal; please edit!
105
- /* eslint-disable */
106
-
107
- const manifestBundleRef = ${stringify(manifestBundleRef)};
108
- const getManifestCall = harden(${stringify(getManifestCall, true)});
109
- const overrideManifest = ${stringify(overrideManifest, true)};
110
-
111
- // Make the behavior the completion value.
112
- (${makeCoreProposalBehavior})({ manifestBundleRef, getManifestCall, overrideManifest, E });
113
- `;
114
-
115
- const trimmed = defangAndTrim(code);
116
-
117
- const proposalPermitJsonFile = `${filePrefix}-permit.json`;
118
- log(`creating ${proposalPermitJsonFile}`);
119
- await writeFile(
120
- proposalPermitJsonFile,
121
- JSON.stringify(proposalPermit, null, 2),
122
- );
123
-
124
- const proposalJsFile = `${filePrefix}.js`;
125
- log(`creating ${proposalJsFile}`);
126
- await writeFile(proposalJsFile, trimmed);
127
-
128
- log(`\
129
- You can now run a governance submission command like:
130
- agd tx gov submit-proposal swingset-core-eval ${proposalPermitJsonFile} ${proposalJsFile} \\
131
- --title="Enable <something>" --description="Evaluate ${proposalJsFile}" --deposit=1000000ubld \\
132
- --gas=auto --gas-adjustment=1.2
133
- Remember to install bundles before submitting the proposal:
134
- ${cmds.join('\n ')}
135
- `);
136
- };
137
-
138
- return writeCoreProposal;
139
- };