@agoric/deploy-script-support 0.10.4-dev-f04cf72.0 → 0.10.4-dev-9a2121d.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agoric/deploy-script-support",
3
- "version": "0.10.4-dev-f04cf72.0+f04cf72",
3
+ "version": "0.10.4-dev-9a2121d.0+9a2121d",
4
4
  "description": "Helpers and other support for writing deploy scripts",
5
5
  "type": "module",
6
6
  "main": "src/helpers.js",
@@ -38,6 +38,7 @@
38
38
  "@agoric/import-manager": "workspace:*",
39
39
  "@agoric/internal": "workspace:*",
40
40
  "@agoric/notifier": "workspace:*",
41
+ "@agoric/pola-io": "workspace:*",
41
42
  "@agoric/store": "workspace:*",
42
43
  "@agoric/time": "workspace:*",
43
44
  "@agoric/zoe": "workspace:*",
@@ -74,5 +75,5 @@
74
75
  "typeCoverage": {
75
76
  "atLeast": 83.92
76
77
  },
77
- "gitHead": "f04cf725b3b98261b2fdcd978d44c584930c9c2f"
78
+ "gitHead": "9a2121d97ae4452d59f2eeae2d9c000ccb193566"
78
79
  }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * @file support for Contract Deployment Process
3
+ *
4
+ * 1. `agoric run XYZ.build.js` produces:
5
+ * - `b1-123.json` bundle x 2: contract, aux
6
+ * - `XYZ-permit.json`, `XYZ.js` script
7
+ * 2. Install bundles
8
+ * - permissionless with per-byte fee in IST
9
+ * 3. Submit CoreEval proposal to BLD stakers
10
+ * - `XYZ-permit.json`, `XYZ.js`
11
+ *
12
+ * @see {runBuilder}
13
+ * @see {installBundles}
14
+ * @see {submitCoreEval}
15
+ */
16
+ import { flags } from '@agoric/pola-io';
17
+
18
+ /**
19
+ * @import {CmdRunner} from '@agoric/pola-io';
20
+ * @import {FileRd} from '@agoric/pola-io';
21
+ */
22
+
23
+ /**
24
+ *
25
+ * TODO: builder should be a FileRd
26
+ * TODO: parameterize dest dir
27
+ *
28
+ * @example
29
+ * to use npx to find `agoric` in node_modules/.bin:
30
+ * const execP = promisify(childProcess.execFile)
31
+ * const agoric = makeCmdRunner('npx', { execFile: execP }).subCommand('agoric');
32
+ *
33
+ * XXX use a different name from execFile since the meaning is different
34
+ *
35
+ * @param {CmdRunner} agoric
36
+ * @param {FileRd} builder
37
+ * @param {Record<string, string | string[]>} [builderOpts]
38
+ * @param {{cwd?: FileRd}} [io]
39
+ *
40
+ * @returns {Promise<Plan>}
41
+ *
42
+ * @typedef {{
43
+ * name: string,
44
+ * script: string,
45
+ * permit: string,
46
+ * bundles: { entrypoint:string, bundleID:string, fileName:string}[];
47
+ * }} Plan
48
+ */
49
+ export const runBuilder = async (
50
+ agoric,
51
+ builder,
52
+ builderOpts = {},
53
+ { cwd = builder.join('../../') } = {},
54
+ ) => {
55
+ const cmd = agoric.withFlags(...(builderOpts ? flags(builderOpts) : []));
56
+ const { stdout } = await cmd.exec(['run', String(builder)]);
57
+ const match = stdout?.match(/ (?<name>[-\w]+)-permit.json/);
58
+ if (!(match && match.groups)) {
59
+ throw Error('no permit found');
60
+ }
61
+ /** @type {Plan} */
62
+ const plan = await cwd.join(`${match.groups.name}-plan.json`).readJSON();
63
+ return plan;
64
+ };
65
+
66
+ export const txFlags = ({
67
+ node,
68
+ from,
69
+ chainId,
70
+ keyringBackend = 'test',
71
+ broadcastMode = 'block',
72
+ }) => ({
73
+ node,
74
+ from,
75
+ 'chain-id': chainId,
76
+ 'keyring-backend': keyringBackend,
77
+ 'broadcast-mode': broadcastMode,
78
+ // TODO: parameterize these?
79
+ gas: 'auto',
80
+ 'gas-adjustment': '1.4',
81
+ });
82
+
83
+ /**
84
+ * @param {CmdRunner} agd
85
+ * @param {number} n
86
+ */
87
+ export const waitForBlock = async (agd, n = 1) => {
88
+ const getHeight = async () => {
89
+ const { stdout } = await agd.exec(['status']);
90
+ const { latest_block_height: height } = JSON.parse(stdout).SyncInfo;
91
+ return height;
92
+ };
93
+ const initialHeight = await getHeight();
94
+ const SEC = 1000;
95
+ let currentHeight;
96
+ do {
97
+ await new Promise(resolve => setTimeout(resolve, 1 * SEC)); // XXX ambient
98
+ currentHeight = await getHeight();
99
+ } while (currentHeight - initialHeight < n);
100
+ console.log('block height:', initialHeight, currentHeight);
101
+ };
102
+
103
+ /**
104
+ * @param {CmdRunner} agd - agd with --from etc.
105
+ * @param {string[]} txArgs
106
+ */
107
+ export const runTx = async (agd, txArgs) => {
108
+ const { stdout } = await agd.withFlags('-o', 'json').exec(['tx', ...txArgs]);
109
+ const result = JSON.parse(stdout);
110
+ if (result.code !== 0) {
111
+ throw Object.assign(Error(result.raw_log), result);
112
+ }
113
+ return result;
114
+ };
115
+
116
+ /**
117
+ * @param {CmdRunner} agd
118
+ * @param {FileRd} bundle
119
+ */
120
+ export const installBundle = async (agd, bundle) =>
121
+ runTx(agd, ['swingset', 'install-bundle', `@${bundle}`]);
122
+
123
+ export const txAbbr = tx => {
124
+ const { txhash, code, height, gas_used: g } = tx;
125
+
126
+ return { txhash, code, height, gas_used: g };
127
+ };
128
+
129
+ /**
130
+ * @param {CmdRunner} agd
131
+ * @param {Plan['bundles']} bundles
132
+ * @param {FileRd} files
133
+ */
134
+ export const installBundles = (agd, bundles, files) => {
135
+ const ps = bundles.map(b =>
136
+ installBundle(agd, files.join(files.relative(b.fileName))),
137
+ );
138
+ return Promise.all(ps);
139
+ };
140
+
141
+ /**
142
+ * @param {CmdRunner} agd
143
+ * @param {Pick<Plan, 'permit' | 'script'>[]} evals
144
+ * @param {object} [opts]
145
+ * @param {string} [opts.title]
146
+ * @param {string} [opts.description]
147
+ * @param {object} [opts.depositOpts]
148
+ * @param {string} [opts.depositOpts.denom]
149
+ * @param {number} [opts.depositOpts.unit]
150
+ * @param {number} [opts.depositOpts.qty]
151
+ * @param {string} [opts.deposit]
152
+ */
153
+ export const submitCoreEval = async (
154
+ agd,
155
+ evals,
156
+ {
157
+ title = evals[0].script,
158
+ description = title,
159
+ depositOpts: { denom = 'ubld', unit = 1_000_000, qty = 1 } = {},
160
+ deposit = `${qty * unit}${denom}`,
161
+ } = {},
162
+ ) =>
163
+ runTx(agd, [
164
+ ...'gov submit-proposal swingset-core-eval'.split(' '),
165
+ ...evals.map(e => [e.permit, e.script]).flat(),
166
+ ...flags({ title, description, deposit }),
167
+ ]);